All of lore.kernel.org
 help / color / mirror / Atom feed
From: Olaf Hering <olaf@aepfle.de>
To: xen-devel@lists.xen.org
Cc: Wei Liu <wei.liu2@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Ian Campbell <ian.campbell@citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: wating for backend changes (was Re: [PATCH v3 4/4] libxl: add support for vscsi)
Date: Fri, 10 Apr 2015 11:23:57 +0200	[thread overview]
Message-ID: <20150410092357.GA22131@aepfle.de> (raw)
In-Reply-To: <1425635156-2357-5-git-send-email-olaf@aepfle.de>

How is new code supposed to wait for backend changes?

Right now there are two APIs for that:
- libxl__wait_for_backend loops for a while until it returns an error.
- libxl__ev_devstate_wait registers a watch and a timer.


In case of pvscsi there are three variants:
- new, can use libxl__wait_device_connection
- reconfigure, can use both of the above
- remove, may use DEFINE_DEVICE_REMOVE and its
  libxl__initiate_device_remove

The reconfigure case has to wait for various states, depending on the
state before the reconfiguration.

The pci code in libxl uses just libxl__wait_for_backend. Looking through
the history it seems the function was added just for pci. Is it a
deprecated function, should callers get converted to
libxl__ev_devstate_wait?

Olaf

On Fri, Mar 06, Olaf Hering wrote:

> +void libxl__device_vscsi_add(libxl__egc *egc, uint32_t domid,
> +                             libxl_device_vscsi *vscsi,
> +                             libxl__ao_device *aodev)
> +{
> +    STATE_AO_GC(aodev->ao);
> +    libxl_ctx *ctx = libxl__gc_owner(gc);
> +    flexarray_t *front;
> +    flexarray_t *back;
> +    libxl__device *device;
> +    char *be_path;
> +    unsigned int be_dirs = 0, rc, i;
> +
> +    if (vscsi->devid == -1) {
> +        rc = ERROR_FAIL;
> +        goto out;
> +    }
> +
> +    /* Prealloc key+value: 4 toplevel + 4 per device */
> +    i = 2 * (4 + (4 * vscsi->num_vscsi_devs));
> +    back = flexarray_make(gc, i, 1);
> +    front = flexarray_make(gc, 2 * 2, 1);
> +
> +    GCNEW(device);
> +    rc = libxl__device_from_vscsi(gc, domid, vscsi, device);
> +    if ( rc != 0 ) goto out;
> +
> +    /* Check if backend device path is already present */
> +    be_path = libxl__device_backend_path(gc, device);
> +    if (!libxl__xs_directory(gc, XBT_NULL, be_path, &be_dirs) || !be_dirs) {
> +        /* backend does not exist, create a new one */
> +        flexarray_append_pair(back, "frontend-id", GCSPRINTF("%d", domid));
> +        flexarray_append_pair(back, "online", "1");
> +        flexarray_append_pair(back, "state", "1");
> +        flexarray_append_pair(back, "feature-host", GCSPRINTF("%d", !!vscsi->feature_host));
> +
> +        flexarray_append_pair(front, "backend-id", GCSPRINTF("%d", vscsi->backend_domid));
> +        flexarray_append_pair(front, "state", "1");
> +    }
> +
> +    for (i = 0; i < vscsi->num_vscsi_devs; i++) {
> +        libxl_vscsi_dev *v = vscsi->vscsi_devs + i;
> +        /* Trigger removal, otherwise create new device */
> +        if (be_dirs) {
> +            unsigned int nb = 0;
> +            /* Preserve existing device */
> +            if (libxl__xs_directory(gc, XBT_NULL, GCSPRINTF("%s/vscsi-devs/dev-%u", be_path, v->vscsi_dev_id), &nb) && nb) {
> +                /* Trigger device removal by forwarding state to XenbusStateClosing */
> +                if (v->remove)
> +                    flexarray_append_pair(back, GCSPRINTF("vscsi-devs/dev-%u/state", v->vscsi_dev_id), "5");
> +                continue;
> +            }
> +        }
> +        flexarray_append_pair(back, GCSPRINTF("vscsi-devs/dev-%u/p-devname", v->vscsi_dev_id), v->p_devname);
> +        switch (v->pdev_type) {
> +            case LIBXL_VSCSI_PDEV_TYPE_WWN:
> +                flexarray_append_pair(back,
> +                                      GCSPRINTF("vscsi-devs/dev-%u/p-dev", v->vscsi_dev_id),
> +                                      v->p_devname);
> +                break;
> +            case LIBXL_VSCSI_PDEV_TYPE_DEV:
> +            case LIBXL_VSCSI_PDEV_TYPE_HCTL:
> +                flexarray_append_pair(back,
> +                                      GCSPRINTF("vscsi-devs/dev-%u/p-dev", v->vscsi_dev_id),
> +                                      GCSPRINTF("%u:%u:%u:%u", v->pdev.hst, v->pdev.chn, v->pdev.tgt, v->pdev.lun));
> +                break;
> +            case LIBXL_VSCSI_PDEV_TYPE_INVALID:
> +            default:
> +                rc = ERROR_FAIL;
> +                goto out;
> +        }
> +        flexarray_append_pair(back, GCSPRINTF("vscsi-devs/dev-%u/v-dev", v->vscsi_dev_id),
> +                              GCSPRINTF("%u:%u:%u:%u", v->vdev.hst, v->vdev.chn, v->vdev.tgt, v->vdev.lun));
> +        flexarray_append_pair(back, GCSPRINTF("vscsi-devs/dev-%u/state", v->vscsi_dev_id), "1");
> +    }
> +
> +    aodev->dev = device;
> +    /* Either create new host or reconfigure existing host */
> +    if (be_dirs == 0) {
> +        libxl__device_generic_add(gc, XBT_NULL, device,
> +                                  libxl__xs_kvs_of_flexarray(gc, back, back->count),
> +                                  libxl__xs_kvs_of_flexarray(gc, front, front->count),
> +                                  NULL);
> +        aodev->action = LIBXL__DEVICE_ACTION_ADD;
> +        libxl__wait_device_connection(egc, aodev);
> +        rc = 0;
> +        /* Done with new host */
> +        goto out;
> +    }
> +
> +    /* Only new devices, write them and do vscsi host reconfiguration */
> +    xs_transaction_t t;
> +retry_transaction:
> +    t = xs_transaction_start(ctx->xsh);
> +    libxl__xs_writev(gc, t, be_path,
> +                     libxl__xs_kvs_of_flexarray(gc, back, back->count));
> +    xs_write(ctx->xsh, t, GCSPRINTF("%s/state", be_path), "7", 2);
> +    if (!xs_transaction_end(ctx->xsh, t, 0)) {
> +        if (errno == EAGAIN)
> +            goto retry_transaction;
> +        LOGE(ERROR, "xs transaction failed");
> +        rc = ERROR_FAIL;
> +        goto out;
> +    }
> +    libxl__wait_for_backend(gc, be_path, "4");
> +
> +retry_transaction2:
> +    t = xs_transaction_start(ctx->xsh);
> +    for (i = 0; i < vscsi->num_vscsi_devs; i++) {
> +        libxl_vscsi_dev *v = vscsi->vscsi_devs + i;
> +        if (v->remove) {
> +            char *path, *val;
> +            path = GCSPRINTF("%s/vscsi-devs/dev-%u/state", be_path, v->vscsi_dev_id);
> +            val = libxl__xs_read(gc, t, path);
> +            if (val && strcmp(val, "6") == 0) {
> +                path = GCSPRINTF("%s/vscsi-devs/dev-%u/state", be_path, v->vscsi_dev_id);
> +                xs_rm(ctx->xsh, t, path);
> +                path = GCSPRINTF("%s/vscsi-devs/dev-%u/p-devname", be_path, v->vscsi_dev_id);
> +                xs_rm(ctx->xsh, t, path);
> +                path = GCSPRINTF("%s/vscsi-devs/dev-%u/p-dev", be_path, v->vscsi_dev_id);
> +                xs_rm(ctx->xsh, t, path);
> +                path = GCSPRINTF("%s/vscsi-devs/dev-%u/v-dev", be_path, v->vscsi_dev_id);
> +                xs_rm(ctx->xsh, t, path);
> +                path = GCSPRINTF("%s/vscsi-devs/dev-%u", be_path, v->vscsi_dev_id);
> +                xs_rm(ctx->xsh, t, path);
> +            } else {
> +                LOGE(ERROR, "%s: %s has %s, expected 6", __func__, path, val);
> +            }
> +        }
> +    }
> +
> +    if (!xs_transaction_end(ctx->xsh, t, 0)) {
> +        if (errno == EAGAIN)
> +            goto retry_transaction2;
> +        LOGE(ERROR, "xs transaction failed");
> +        rc = ERROR_FAIL;
> +        goto out;
> +    }
> +    /* As we are not adding new device, skip waiting for it */
> +    libxl__ao_complete(egc, aodev->ao, 0);
> +
> +    rc = 0;
> +out:
> +    aodev->rc = rc;
> +    if(rc) aodev->callback(egc, aodev);
> +    return;
> +}

  parent reply	other threads:[~2015-04-10  9:23 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-06  9:45 [PATCH v3 0/4] libbxl: add support for pvscsi, iteration 3 Olaf Hering
2015-03-06  9:45 ` [PATCH v3 1/4] vscsiif.h: fix WWN notation for p-dev property Olaf Hering
2015-03-06  9:45 ` [PATCH v3 2/4] docs: add vscsi to xenstore-paths.markdown Olaf Hering
2015-03-06 13:55   ` Wei Liu
2015-03-06 15:07     ` Olaf Hering
2015-03-06  9:45 ` [PATCH v3 3/4] docs: add pvscsi.txt Olaf Hering
2015-03-06 13:55   ` Wei Liu
2015-03-06 15:11     ` Olaf Hering
2015-03-06 15:37       ` Wei Liu
2015-03-11 15:23       ` Ian Campbell
2015-03-06  9:45 ` [PATCH v3 4/4] libxl: add support for vscsi Olaf Hering
2015-03-06 14:31   ` Wei Liu
2015-03-06 15:25     ` Olaf Hering
2015-03-06 15:53       ` Wei Liu
2015-03-09 16:08     ` Olaf Hering
2015-03-09 16:46       ` Wei Liu
2015-03-11 15:24     ` Ian Campbell
2015-03-11 15:33   ` Ian Campbell
2015-03-11 16:02     ` Olaf Hering
2015-03-11 16:09       ` Ian Campbell
2015-03-13 13:49         ` Olaf Hering
2015-03-11 16:06     ` Olaf Hering
2015-03-12 16:07     ` Olaf Hering
2015-03-12 16:47       ` Ian Campbell
2015-03-13 13:45         ` Olaf Hering
2015-03-13 15:10           ` Wei Liu
2015-03-16  8:16             ` Olaf Hering
2015-03-16 11:30               ` Wei Liu
2015-03-12 16:20     ` Olaf Hering
2015-03-12 16:46       ` Ian Campbell
2015-03-13 13:44         ` Olaf Hering
2015-03-13 14:18           ` Ian Campbell
2015-03-26 12:55             ` Olaf Hering
2015-03-26 13:46               ` Ian Campbell
2015-03-27  7:38                 ` Olaf Hering
2015-04-10  9:23   ` Olaf Hering [this message]
2015-04-14 15:55     ` wating for backend changes (was Re: [PATCH v3 4/4] libxl: add support for vscsi) Olaf Hering
2015-04-15 11:50     ` Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150410092357.GA22131@aepfle.de \
    --to=olaf@aepfle.de \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.