[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 06/13] libxl: cleanup libxl__device_{disk, nic}_add
Change libxl__sprintf for GCSPRINTF, LIBXL__LOG* for LOG and remove use of ctx variable in favour of the CTX constant. Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxx> --- tools/libxl/libxl_device.c | 114 +++++++++++++++++++++----------------------- 1 files changed, 55 insertions(+), 59 deletions(-) diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index edc4ad1..1e34135 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -253,13 +253,12 @@ 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); + LOG(ERROR, "Invalid or unsupported virtual disk identifier %s", + disk->vdev); return ERROR_INVAL; } @@ -267,19 +266,18 @@ int libxl__device_from_disk(libxl__gc *gc, uint32_t 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; + 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: + LOG(ERROR, "unrecognized disk backend type: %d\n", disk->backend); + return ERROR_INVAL; } device->domid = domid; @@ -292,10 +290,9 @@ int libxl__device_from_disk(libxl__gc *gc, uint32_t domid, int libxl__device_disk_add(libxl__gc *gc, uint32_t domid, libxl_device_disk *disk) { - libxl_ctx *ctx = CTX; flexarray_t *front; flexarray_t *back; - char *dev; + char *dev, *format; libxl__device device; int major, minor, rc; @@ -314,18 +311,18 @@ int libxl__device_disk_add(libxl__gc *gc, uint32_t domid, } if (disk->script) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "External block scripts" - " not yet supported, sorry"); + 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); + LOG(ERROR, "Invalid or unsupported virtual disk identifier %s", + disk->vdev); goto out_free; } + format = libxl__device_disk_string_of_format(disk->format); switch (disk->backend) { case LIBXL_DISK_BACKEND_PHY: @@ -333,7 +330,7 @@ int libxl__device_disk_add(libxl__gc *gc, uint32_t domid, 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, GCSPRINTF("%x:%x", major, minor)); flexarray_append(back, "params"); flexarray_append(back, dev); @@ -349,34 +346,31 @@ int libxl__device_disk_add(libxl__gc *gc, uint32_t domid, 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)); + flexarray_append(back, GCSPRINTF("%s:%s", 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)); + flexarray_append(back, GCSPRINTF("%s:%s", 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); + 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, GCSPRINTF("%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, GCSPRINTF("%d", (disk->removable) ? 1 : 0)); flexarray_append(back, "bootable"); - flexarray_append(back, libxl__sprintf(gc, "%d", 1)); + flexarray_append(back, GCSPRINTF("%d", 1)); flexarray_append(back, "state"); - flexarray_append(back, libxl__sprintf(gc, "%d", 1)); + flexarray_append(back, GCSPRINTF("%d", 1)); flexarray_append(back, "dev"); flexarray_append(back, disk->vdev); flexarray_append(back, "type"); @@ -387,17 +381,17 @@ int libxl__device_disk_add(libxl__gc *gc, uint32_t domid, 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, GCSPRINTF("%d", disk->backend_domid)); flexarray_append(front, "state"); - flexarray_append(front, libxl__sprintf(gc, "%d", 1)); + flexarray_append(front, GCSPRINTF("%d", 1)); flexarray_append(front, "virtual-device"); - flexarray_append(front, libxl__sprintf(gc, "%d", device.devid)); + flexarray_append(front, GCSPRINTF("%d", device.devid)); flexarray_append(front, "device-type"); flexarray_append(front, disk->is_cdrom ? "cdrom" : "disk"); libxl__device_generic_add(gc, &device, - libxl__xs_kvs_of_flexarray(gc, back, back->count), - libxl__xs_kvs_of_flexarray(gc, front, front->count)); + libxl__xs_kvs_of_flexarray(gc, back, back->count), + libxl__xs_kvs_of_flexarray(gc, front, front->count)); rc = 0; @@ -449,8 +443,10 @@ int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic) rc = ERROR_FAIL; goto out_free; } - if (!(l = libxl__xs_directory(gc, XBT_NULL, - libxl__sprintf(gc, "%s/device/vif", dompath), &nb))) { + l = libxl__xs_directory(gc, XBT_NULL, GCSPRINTF( + "%s/device/vif", dompath), + &nb); + if (!l) { nic->devid = 0; } else { nic->devid = strtoul(l[nb - 1], NULL, 10) + 1; @@ -461,17 +457,18 @@ int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic) if ( rc != 0 ) goto out_free; flexarray_append(back, "frontend-id"); - flexarray_append(back, libxl__sprintf(gc, "%d", domid)); + flexarray_append(back, GCSPRINTF("%d", domid)); flexarray_append(back, "online"); flexarray_append(back, "1"); flexarray_append(back, "state"); - flexarray_append(back, libxl__sprintf(gc, "%d", 1)); + flexarray_append(back, GCSPRINTF("%d", 1)); if (nic->script) { flexarray_append(back, "script"); - flexarray_append(back, nic->script[0]=='/' ? nic->script - : libxl__sprintf(gc, "%s/%s", - libxl__xen_script_dir_path(), - nic->script)); + flexarray_append(back, nic->script[0]=='/' ? + nic->script : + GCSPRINTF("%s/%s", + libxl__xen_script_dir_path(), + nic->script)); } if (nic->ifname) { @@ -480,8 +477,7 @@ int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic) } flexarray_append(back, "mac"); - flexarray_append(back,libxl__sprintf(gc, - LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac))); + flexarray_append(back, GCSPRINTF(LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac))); if (nic->ip) { flexarray_append(back, "ip"); flexarray_append(back, libxl__strdup(gc, nic->ip)); @@ -489,28 +485,28 @@ int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic) if (nic->rate_interval_usecs > 0) { flexarray_append(back, "rate"); - flexarray_append(back, libxl__sprintf(gc, "%"PRIu64",%"PRIu32"", - nic->rate_bytes_per_interval, - nic->rate_interval_usecs)); + flexarray_append(back, GCSPRINTF("%"PRIu64",%"PRIu32"", + nic->rate_bytes_per_interval, + nic->rate_interval_usecs)); } flexarray_append(back, "bridge"); flexarray_append(back, libxl__strdup(gc, nic->bridge)); flexarray_append(back, "handle"); - flexarray_append(back, libxl__sprintf(gc, "%d", nic->devid)); + flexarray_append(back, GCSPRINTF("%d", nic->devid)); flexarray_append(front, "backend-id"); - flexarray_append(front, libxl__sprintf(gc, "%d", nic->backend_domid)); + flexarray_append(front, GCSPRINTF("%d", nic->backend_domid)); flexarray_append(front, "state"); - flexarray_append(front, libxl__sprintf(gc, "%d", 1)); + flexarray_append(front, GCSPRINTF("%d", 1)); flexarray_append(front, "handle"); - flexarray_append(front, libxl__sprintf(gc, "%d", nic->devid)); + flexarray_append(front, GCSPRINTF("%d", nic->devid)); flexarray_append(front, "mac"); - flexarray_append(front, libxl__sprintf(gc, - LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac))); + flexarray_append(front, GCSPRINTF(LIBXL_MAC_FMT, + LIBXL_MAC_BYTES(nic->mac))); libxl__device_generic_add(gc, &device, - libxl__xs_kvs_of_flexarray(gc, back, back->count), - libxl__xs_kvs_of_flexarray(gc, front, front->count)); + libxl__xs_kvs_of_flexarray(gc, back, back->count), + libxl__xs_kvs_of_flexarray(gc, front, front->count)); /* FIXME: wait for plug */ rc = 0; -- 1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |