|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH v5 4/8] libxl: introduce libxl__device_disk_add
On Fri, 2012-05-04 at 12:13 +0100, Stefano Stabellini wrote:
> Introduce libxl__device_disk_add that takes an additional
> xs_transaction_t paramter.
> Implement libxl_device_disk_add using libxl__device_disk_add.
> Move libxl__device_from_disk to libxl_internal.c.
> No functional change.
>
> Changes in v5:
> - rename libxl__device_generic_add_t to libxl__device_generic_add.
>
> Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
> ---
> tools/libxl/libxl.c | 151 +----------------------------------------
> tools/libxl/libxl_internal.c | 157
> ++++++++++++++++++++++++++++++++++++++++++
> tools/libxl/libxl_internal.h | 6 ++
> 3 files changed, 164 insertions(+), 150 deletions(-)
>
> diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
> index 525f0d6..941dbb9 100644
> --- a/tools/libxl/libxl.c
> +++ b/tools/libxl/libxl.c
> @@ -1258,159 +1258,10 @@ int libxl__device_disk_setdefault(libxl__gc *gc,
> libxl_device_disk *disk)
> return rc;
> }
>
> -static int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
> - libxl_device_disk *disk,
> - libxl__device *device)
> -{
> - libxl_ctx *ctx = libxl__gc_owner(gc);
> - int devid;
> -
> - devid = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
> - if (devid==-1) {
> - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported"
> - " virtual disk identifier %s", disk->vdev);
> - return ERROR_INVAL;
> - }
> -
> - device->backend_domid = disk->backend_domid;
> - device->backend_devid = devid;
> -
> - switch (disk->backend) {
> - case LIBXL_DISK_BACKEND_PHY:
> - device->backend_kind = LIBXL__DEVICE_KIND_VBD;
> - break;
> - case LIBXL_DISK_BACKEND_TAP:
> - device->backend_kind = LIBXL__DEVICE_KIND_VBD;
> - break;
> - case LIBXL_DISK_BACKEND_QDISK:
> - device->backend_kind = LIBXL__DEVICE_KIND_QDISK;
> - break;
> - default:
> - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend
> type: %d\n",
> - disk->backend);
> - return ERROR_INVAL;
> - }
> -
> - device->domid = domid;
> - device->devid = devid;
> - device->kind = LIBXL__DEVICE_KIND_VBD;
> -
> - return 0;
> -}
> -
> int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk
> *disk)
> {
> GC_INIT(ctx);
> - flexarray_t *front;
> - flexarray_t *back;
> - char *dev;
> - libxl__device device;
> - int major, minor, rc;
> -
> - rc = libxl__device_disk_setdefault(gc, disk);
> - if (rc) goto out;
> -
> - front = flexarray_make(16, 1);
> - if (!front) {
> - rc = ERROR_NOMEM;
> - goto out;
> - }
> - back = flexarray_make(16, 1);
> - if (!back) {
> - rc = ERROR_NOMEM;
> - goto out_free;
> - }
> -
> - if (disk->script) {
> - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "External block scripts"
> - " not yet supported, sorry");
> - rc = ERROR_INVAL;
> - goto out_free;
> - }
> -
> - rc = libxl__device_from_disk(gc, domid, disk, &device);
> - if (rc != 0) {
> - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported"
> - " virtual disk identifier %s", disk->vdev);
> - goto out_free;
> - }
> -
> - switch (disk->backend) {
> - case LIBXL_DISK_BACKEND_PHY:
> - dev = disk->pdev_path;
> - do_backend_phy:
> - libxl__device_physdisk_major_minor(dev, &major, &minor);
> - flexarray_append(back, "physical-device");
> - flexarray_append(back, libxl__sprintf(gc, "%x:%x", major,
> minor));
> -
> - flexarray_append(back, "params");
> - flexarray_append(back, dev);
> -
> - assert(device.backend_kind == LIBXL__DEVICE_KIND_VBD);
> - break;
> - case LIBXL_DISK_BACKEND_TAP:
> - dev = libxl__blktap_devpath(gc, disk->pdev_path, disk->format);
> - if (!dev) {
> - rc = ERROR_FAIL;
> - goto out_free;
> - }
> - flexarray_append(back, "tapdisk-params");
> - flexarray_append(back, libxl__sprintf(gc, "%s:%s",
> - libxl__device_disk_string_of_format(disk->format),
> - disk->pdev_path));
> -
> - /* now create a phy device to export the device to the guest */
> - goto do_backend_phy;
> - case LIBXL_DISK_BACKEND_QDISK:
> - flexarray_append(back, "params");
> - flexarray_append(back, libxl__sprintf(gc, "%s:%s",
> - libxl__device_disk_string_of_format(disk->format),
> disk->pdev_path));
> - assert(device.backend_kind == LIBXL__DEVICE_KIND_QDISK);
> - break;
> - default:
> - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend
> type: %d\n", disk->backend);
> - rc = ERROR_INVAL;
> - goto out_free;
> - }
> -
> - flexarray_append(back, "frontend-id");
> - flexarray_append(back, libxl__sprintf(gc, "%d", domid));
> - flexarray_append(back, "online");
> - flexarray_append(back, "1");
> - flexarray_append(back, "removable");
> - flexarray_append(back, libxl__sprintf(gc, "%d", (disk->removable) ? 1 :
> 0));
> - flexarray_append(back, "bootable");
> - flexarray_append(back, libxl__sprintf(gc, "%d", 1));
> - flexarray_append(back, "state");
> - flexarray_append(back, libxl__sprintf(gc, "%d", 1));
> - flexarray_append(back, "dev");
> - flexarray_append(back, disk->vdev);
> - flexarray_append(back, "type");
> - flexarray_append(back,
> libxl__device_disk_string_of_backend(disk->backend));
> - flexarray_append(back, "mode");
> - flexarray_append(back, disk->readwrite ? "w" : "r");
> - flexarray_append(back, "device-type");
> - flexarray_append(back, disk->is_cdrom ? "cdrom" : "disk");
> -
> - flexarray_append(front, "backend-id");
> - flexarray_append(front, libxl__sprintf(gc, "%d", disk->backend_domid));
> - flexarray_append(front, "state");
> - flexarray_append(front, libxl__sprintf(gc, "%d", 1));
> - flexarray_append(front, "virtual-device");
> - flexarray_append(front, libxl__sprintf(gc, "%d", device.devid));
> - flexarray_append(front, "device-type");
> - flexarray_append(front, disk->is_cdrom ? "cdrom" : "disk");
> -
> - 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));
> -
> - rc = 0;
> -
> -out_free:
> - flexarray_free(back);
> - flexarray_free(front);
> -out:
> + int rc = libxl__device_disk_add(gc, domid, XBT_NULL, disk);
> GC_FREE;
> return rc;
> }
> diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c
> index 55dc55c..1bf5d73 100644
> --- a/tools/libxl/libxl_internal.c
> +++ b/tools/libxl/libxl_internal.c
> @@ -323,6 +323,163 @@ out:
> return rc;
> }
>
> +int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
> + libxl_device_disk *disk,
> + libxl__device *device)
> +{
> + libxl_ctx *ctx = libxl__gc_owner(gc);
> + int devid;
> +
> + devid = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
> + if (devid==-1) {
> + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported"
> + " virtual disk identifier %s", disk->vdev);
> + return ERROR_INVAL;
> + }
> +
> + device->backend_domid = disk->backend_domid;
> + device->backend_devid = devid;
> +
> + switch (disk->backend) {
> + case LIBXL_DISK_BACKEND_PHY:
> + device->backend_kind = LIBXL__DEVICE_KIND_VBD;
> + break;
> + case LIBXL_DISK_BACKEND_TAP:
> + device->backend_kind = LIBXL__DEVICE_KIND_VBD;
> + break;
> + case LIBXL_DISK_BACKEND_QDISK:
> + device->backend_kind = LIBXL__DEVICE_KIND_QDISK;
> + break;
> + default:
> + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend
> type: %d\n",
> + disk->backend);
> + return ERROR_INVAL;
> + }
> +
> + device->domid = domid;
> + device->devid = devid;
> + device->kind = LIBXL__DEVICE_KIND_VBD;
> +
> + return 0;
> +}
> +
> +int libxl__device_disk_add(libxl__gc *gc, uint32_t domid,
> + xs_transaction_t t, libxl_device_disk *disk)
> +{
> + flexarray_t *front;
> + flexarray_t *back;
> + char *dev;
> + libxl__device device;
> + int major, minor, rc;
> + libxl_ctx *ctx = gc->owner;
> +
> + rc = libxl__device_disk_setdefault(gc, disk);
> + if (rc) goto out;
> +
> + front = flexarray_make(16, 1);
> + if (!front) {
> + rc = ERROR_NOMEM;
> + goto out;
> + }
> + back = flexarray_make(16, 1);
> + if (!back) {
> + rc = ERROR_NOMEM;
> + goto out_free;
> + }
> +
> + if (disk->script) {
> + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "External block scripts"
> + " not yet supported, sorry");
> + rc = ERROR_INVAL;
> + goto out_free;
> + }
> +
> + rc = libxl__device_from_disk(gc, domid, disk, &device);
> + if (rc != 0) {
> + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported"
> + " virtual disk identifier %s", disk->vdev);
> + goto out_free;
> + }
> +
> + switch (disk->backend) {
> + case LIBXL_DISK_BACKEND_PHY:
> + dev = disk->pdev_path;
> + do_backend_phy:
> + libxl__device_physdisk_major_minor(dev, &major, &minor);
> + flexarray_append(back, "physical-device");
> + flexarray_append(back, libxl__sprintf(gc, "%x:%x", major,
> minor));
> +
> + flexarray_append(back, "params");
> + flexarray_append(back, dev);
> +
> + assert(device.backend_kind == LIBXL__DEVICE_KIND_VBD);
> + break;
> + case LIBXL_DISK_BACKEND_TAP:
> + dev = libxl__blktap_devpath(gc, disk->pdev_path, disk->format);
> + if (!dev) {
> + rc = ERROR_FAIL;
> + goto out_free;
> + }
> + flexarray_append(back, "tapdisk-params");
> + flexarray_append(back, libxl__sprintf(gc, "%s:%s",
> + libxl__device_disk_string_of_format(disk->format),
> + disk->pdev_path));
> +
> + /* now create a phy device to export the device to the guest */
> + goto do_backend_phy;
> + case LIBXL_DISK_BACKEND_QDISK:
> + flexarray_append(back, "params");
> + flexarray_append(back, libxl__sprintf(gc, "%s:%s",
> + libxl__device_disk_string_of_format(disk->format),
> disk->pdev_path));
> + assert(device.backend_kind == LIBXL__DEVICE_KIND_QDISK);
> + break;
> + default:
> + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend
> type: %d\n", disk->backend);
> + rc = ERROR_INVAL;
> + goto out_free;
> + }
> +
> + flexarray_append(back, "frontend-id");
> + flexarray_append(back, libxl__sprintf(gc, "%d", domid));
> + flexarray_append(back, "online");
> + flexarray_append(back, "1");
> + flexarray_append(back, "removable");
> + flexarray_append(back, libxl__sprintf(gc, "%d", (disk->removable) ? 1 :
> 0));
> + flexarray_append(back, "bootable");
> + flexarray_append(back, libxl__sprintf(gc, "%d", 1));
> + flexarray_append(back, "state");
> + flexarray_append(back, libxl__sprintf(gc, "%d", 1));
> + flexarray_append(back, "dev");
> + flexarray_append(back, disk->vdev);
> + flexarray_append(back, "type");
> + flexarray_append(back,
> libxl__device_disk_string_of_backend(disk->backend));
> + flexarray_append(back, "mode");
> + flexarray_append(back, disk->readwrite ? "w" : "r");
> + flexarray_append(back, "device-type");
> + flexarray_append(back, disk->is_cdrom ? "cdrom" : "disk");
> +
> + flexarray_append(front, "backend-id");
> + flexarray_append(front, libxl__sprintf(gc, "%d", disk->backend_domid));
> + flexarray_append(front, "state");
> + flexarray_append(front, libxl__sprintf(gc, "%d", 1));
> + flexarray_append(front, "virtual-device");
> + flexarray_append(front, libxl__sprintf(gc, "%d", device.devid));
> + flexarray_append(front, "device-type");
> + flexarray_append(front, disk->is_cdrom ? "cdrom" : "disk");
> +
> + libxl__device_generic_add(gc, t, &device,
> + libxl__xs_kvs_of_flexarray(gc, back,
> back->count),
> + libxl__xs_kvs_of_flexarray(gc, front,
> front->count));
> +
> + rc = 0;
> +
> +out_free:
> + flexarray_free(back);
> + flexarray_free(front);
> +out:
> + return rc;
> +}
> +
> char * libxl__device_disk_local_attach(libxl__gc *gc,
> const libxl_device_disk *in_disk,
> libxl_device_disk **new_disk)
> diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
> index 2c8f06a..096c96d 100644
> --- a/tools/libxl/libxl_internal.h
> +++ b/tools/libxl/libxl_internal.h
> @@ -1003,6 +1003,12 @@ _hidden char *libxl__blktap_devpath(libxl__gc *gc,
> */
> _hidden void libxl__device_destroy_tapdisk(libxl__gc *gc, char *be_path);
>
> +
> +_hidden int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
> + libxl_device_disk *disk,
> + libxl__device *device);
> +_hidden int libxl__device_disk_add(libxl__gc *gc, uint32_t domid,
> + xs_transaction_t t, libxl_device_disk *disk);
> /*
> * Make a disk available in this (the control) domain. Returns path to
> * a device.
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |