Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1642175
| From | Boris Ostrovsky <boris.ostrovsky@oracle.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 04/18] xen/pvcalls: xenbus state handling |
| Date | 2017-05-16 03:50 +0200 |
| Message-ID | <tHzMC-7sL-5@gated-at.bofh.it> (permalink) |
| References | <tHuWC-4t8-7@gated-at.bofh.it> <tHuWC-4t8-9@gated-at.bofh.it> <tHv6i-4wd-23@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On 05/15/2017 04:35 PM, Stefano Stabellini wrote:
> Introduce the code to handle xenbus state changes.
>
> Implement the probe function for the pvcalls backend. Write the
> supported versions, max-page-order and function-calls nodes to xenstore,
> as required by the protocol.
>
> Introduce stub functions for disconnecting/connecting to a frontend.
>
> Signed-off-by: Stefano Stabellini <stefano@aporeto.com>
> CC: boris.ostrovsky@oracle.com
> CC: jgross@suse.com
> ---
> drivers/xen/pvcalls-back.c | 133 +++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 133 insertions(+)
>
> diff --git a/drivers/xen/pvcalls-back.c b/drivers/xen/pvcalls-back.c
> index 46a889a..86eca19 100644
> --- a/drivers/xen/pvcalls-back.c
> +++ b/drivers/xen/pvcalls-back.c
> @@ -25,6 +25,9 @@
> #include <xen/xenbus.h>
> #include <xen/interface/io/pvcalls.h>
>
> +#define PVCALLS_VERSIONS "1"
> +#define MAX_RING_ORDER XENBUS_MAX_RING_GRANT_ORDER
> +
> struct pvcalls_ioworker {
> struct work_struct register_work;
> atomic_t io;
> @@ -45,15 +48,145 @@ static void pvcalls_back_ioworker(struct work_struct *work)
> {
> }
>
> +static int backend_connect(struct xenbus_device *dev)
> +{
> + return 0;
> +}
> +
> +static int backend_disconnect(struct xenbus_device *dev)
> +{
> + return 0;
> +}
> +
> static int pvcalls_back_probe(struct xenbus_device *dev,
> const struct xenbus_device_id *id)
> {
> + int err;
> +
> + err = xenbus_printf(XBT_NIL, dev->nodename, "versions", "%s",
> + PVCALLS_VERSIONS);
> + if (err) {
> + pr_warn("%s write out 'version' failed\n", __func__);
> + return -EINVAL;
Why not return err? (below too)
> + }
> +
> + err = xenbus_printf(XBT_NIL, dev->nodename, "max-page-order", "%u",
> + MAX_RING_ORDER);
> + if (err) {
> + pr_warn("%s write out 'max-page-order' failed\n", __func__);
> + return -EINVAL;
> + }
> +
> + /* "1" means socket, connect, release, bind, listen, accept and poll*/
> + err = xenbus_printf(XBT_NIL, dev->nodename, "function-calls", "1");
Should "1" be defined in the (public) header file?
> + if (err) {
> + pr_warn("%s write out 'function-calls' failed\n", __func__);
> + return -EINVAL;
> + }
> +
> + err = xenbus_switch_state(dev, XenbusStateInitWait);
> + if (err)
> + return err;
> +
> return 0;
> }
>
> +static void set_backend_state(struct xenbus_device *dev,
> + enum xenbus_state state)
> +{
> + while (dev->state != state) {
> + switch (dev->state) {
> + case XenbusStateClosed:
> + switch (state) {
> + case XenbusStateInitWait:
> + case XenbusStateConnected:
> + xenbus_switch_state(dev, XenbusStateInitWait);
> + break;
> + case XenbusStateClosing:
> + xenbus_switch_state(dev, XenbusStateClosing);
> + break;
> + default:
> + __WARN();
> + }
> + break;
> + case XenbusStateInitWait:
> + case XenbusStateInitialised:
> + switch (state) {
> + case XenbusStateConnected:
> + backend_connect(dev);
> + xenbus_switch_state(dev, XenbusStateConnected);
> + break;
> + case XenbusStateClosing:
> + case XenbusStateClosed:
> + xenbus_switch_state(dev, XenbusStateClosing);
> + break;
> + default:
> + __WARN();
> + }
> + break;
> + case XenbusStateConnected:
> + switch (state) {
> + case XenbusStateInitWait:
> + case XenbusStateClosing:
> + case XenbusStateClosed:
> + down_write(&pvcalls_back_global.privs_lock);
> + backend_disconnect(dev);
> + up_write(&pvcalls_back_global.privs_lock);
Unless you plan to have more stuff under the semaphore, I'd consider
putting them in backend_disconnect().
> + xenbus_switch_state(dev, XenbusStateClosing);
> + break;
> + default:
> + __WARN();
> + }
> + break;
> + case XenbusStateClosing:
> + switch (state) {
> + case XenbusStateInitWait:
> + case XenbusStateConnected:
> + case XenbusStateClosed:
> + xenbus_switch_state(dev, XenbusStateClosed);
> + break;
> + default:
> + __WARN();
> + }
> + break;
> + default:
> + __WARN();
> + }
> + }
> +}
> +
> static void pvcalls_back_changed(struct xenbus_device *dev,
> enum xenbus_state frontend_state)
> {
> + switch (frontend_state) {
> + case XenbusStateInitialising:
> + set_backend_state(dev, XenbusStateInitWait);
> + break;
> +
> + case XenbusStateInitialised:
> + case XenbusStateConnected:
> + set_backend_state(dev, XenbusStateConnected);
> + break;
> +
> + case XenbusStateClosing:
> + set_backend_state(dev, XenbusStateClosing);
> + break;
> +
> + case XenbusStateClosed:
> + set_backend_state(dev, XenbusStateClosed);
> + if (xenbus_dev_is_online(dev))
> + break;
> + /* fall through if not online */
> + case XenbusStateUnknown:
> + set_backend_state(dev, XenbusStateClosed);
You are setting XenbusStateClosed twice in case of fallthrough.
-boris
> + device_unregister(&dev->dev);
> + break;
> +
> + default:
> + xenbus_dev_fatal(dev, -EINVAL, "saw state %d at frontend",
> + frontend_state);
> + break;
> + }
> }
>
> static int pvcalls_back_remove(struct xenbus_device *dev)
>
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 01/18] xen: introduce the pvcalls interface header Stefano Stabellini <sstabellini@kernel.org> - 2017-05-15 22:40 +0200
[PATCH 14/18] xen/pvcalls: disconnect and module_exit Stefano Stabellini <sstabellini@kernel.org> - 2017-05-15 22:40 +0200
[PATCH 02/18] xen/pvcalls: introduce the pvcalls xenbus backend Stefano Stabellini <sstabellini@kernel.org> - 2017-05-15 22:40 +0200
[PATCH 15/18] xen/pvcalls: introduce the ioworker Stefano Stabellini <sstabellini@kernel.org> - 2017-05-15 22:40 +0200
[PATCH 09/18] xen/pvcalls: implement bind command Stefano Stabellini <sstabellini@kernel.org> - 2017-05-15 22:40 +0200
[PATCH 03/18] xen/pvcalls: initialize the module and register the xenbus backend Stefano Stabellini <sstabellini@kernel.org> - 2017-05-15 22:40 +0200
Re: [PATCH 03/18] xen/pvcalls: initialize the module and register the xenbus backend Boris Ostrovsky <boris.ostrovsky@oracle.com> - 2017-05-16 03:50 +0200
Re: [PATCH 03/18] xen/pvcalls: initialize the module and register the xenbus backend Stefano Stabellini <sstabellini@kernel.org> - 2017-05-16 22:10 +0200
Re: [PATCH 03/18] xen/pvcalls: initialize the module and register the xenbus backend Stefano Stabellini <sstabellini@kernel.org> - 2017-05-16 22:30 +0200
Re: [PATCH 03/18] xen/pvcalls: initialize the module and register the xenbus backend Juergen Gross <jgross@suse.com> - 2017-05-16 08:50 +0200
Re: [PATCH 03/18] xen/pvcalls: initialize the module and register the xenbus backend Stefano Stabellini <sstabellini@kernel.org> - 2017-05-16 22:00 +0200
Re: [PATCH 03/18] xen/pvcalls: initialize the module and register the xenbus backend Juergen Gross <jgross@suse.com> - 2017-05-17 07:30 +0200
Re: [PATCH 03/18] xen/pvcalls: initialize the module and register the xenbus backend Stefano Stabellini <sstabellini@kernel.org> - 2017-05-18 23:20 +0200
Re: [PATCH 03/18] xen/pvcalls: initialize the module and register the xenbus backend Stefano Stabellini <sstabellini@kernel.org> - 2017-05-20 00:40 +0200
[PATCH 10/18] xen/pvcalls: implement listen command Stefano Stabellini <sstabellini@kernel.org> - 2017-05-15 22:40 +0200
[PATCH 13/18] xen/pvcalls: implement release command Stefano Stabellini <sstabellini@kernel.org> - 2017-05-15 22:40 +0200
[PATCH 06/18] xen/pvcalls: handle commands from the frontend Stefano Stabellini <sstabellini@kernel.org> - 2017-05-15 22:40 +0200
Re: [PATCH 06/18] xen/pvcalls: handle commands from the frontend Boris Ostrovsky <boris.ostrovsky@oracle.com> - 2017-05-16 04:20 +0200
Re: [PATCH 06/18] xen/pvcalls: handle commands from the frontend Stefano Stabellini <sstabellini@kernel.org> - 2017-05-16 23:00 +0200
[PATCH 07/18] xen/pvcalls: implement socket command Stefano Stabellini <sstabellini@kernel.org> - 2017-05-15 22:40 +0200
Re: [PATCH 07/18] xen/pvcalls: implement socket command Boris Ostrovsky <boris.ostrovsky@oracle.com> - 2017-05-16 04:30 +0200
Re: [PATCH 07/18] xen/pvcalls: implement socket command Stefano Stabellini <sstabellini@kernel.org> - 2017-05-16 22:50 +0200
[PATCH 12/18] xen/pvcalls: implement poll command Stefano Stabellini <sstabellini@kernel.org> - 2017-05-15 22:40 +0200
[PATCH 16/18] xen/pvcalls: implement read Stefano Stabellini <sstabellini@kernel.org> - 2017-05-15 22:40 +0200
[PATCH 08/18] xen/pvcalls: implement connect command Stefano Stabellini <sstabellini@kernel.org> - 2017-05-15 22:40 +0200
Re: [PATCH 08/18] xen/pvcalls: implement connect command Boris Ostrovsky <boris.ostrovsky@oracle.com> - 2017-05-16 04:50 +0200
Re: [PATCH 08/18] xen/pvcalls: implement connect command Stefano Stabellini <sstabellini@kernel.org> - 2017-05-16 23:10 +0200
Re: [PATCH 08/18] xen/pvcalls: implement connect command Boris Ostrovsky <boris.ostrovsky@oracle.com> - 2017-05-17 00:00 +0200
Re: [PATCH 08/18] xen/pvcalls: implement connect command Stefano Stabellini <sstabellini@kernel.org> - 2017-05-18 21:20 +0200
Re: [PATCH 08/18] xen/pvcalls: implement connect command Boris Ostrovsky <boris.ostrovsky@oracle.com> - 2017-05-18 22:30 +0200
[PATCH 11/18] xen/pvcalls: implement accept command Stefano Stabellini <sstabellini@kernel.org> - 2017-05-15 22:40 +0200
[PATCH 05/18] xen/pvcalls: connect to a frontend Stefano Stabellini <sstabellini@kernel.org> - 2017-05-15 22:50 +0200
Re: [PATCH 05/18] xen/pvcalls: connect to a frontend Boris Ostrovsky <boris.ostrovsky@oracle.com> - 2017-05-16 04:10 +0200
Re: [PATCH 05/18] xen/pvcalls: connect to a frontend Stefano Stabellini <sstabellini@kernel.org> - 2017-05-16 22:30 +0200
Re: [PATCH 05/18] xen/pvcalls: connect to a frontend Stefano Stabellini <sstabellini@kernel.org> - 2017-05-16 22:40 +0200
[PATCH 04/18] xen/pvcalls: xenbus state handling Stefano Stabellini <sstabellini@kernel.org> - 2017-05-15 22:50 +0200
Re: [PATCH 04/18] xen/pvcalls: xenbus state handling Boris Ostrovsky <boris.ostrovsky@oracle.com> - 2017-05-16 03:50 +0200
Re: [PATCH 04/18] xen/pvcalls: xenbus state handling Stefano Stabellini <sstabellini@kernel.org> - 2017-05-16 22:20 +0200
csiph-web