[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC Patch v2 16/17] update libxl__device_disk_from_xs_be() to support blktap device
If the disk backend is blktap device, we store "format:pdev_path" in tapdisk-params, and store "phy" in type. So use tapdisk-params to set libxl_device_disk instead of params and type. Signed-off-by: Wen Congyang <wency@xxxxxxxxxxxxxx> Cc: Shriram Rajagopalan <rshriram@xxxxxxxxx> --- tools/libxl/libxl.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- tools/libxl/libxl_utils.c | 23 +++++++++++++++++++++++ tools/libxl/libxl_utils.h | 1 + 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 3526539..06fb54c 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -2362,6 +2362,47 @@ static int libxl__device_disk_from_xs_be(libxl__gc *gc, goto cleanup; } + disk->format = LIBXL_DISK_FORMAT_UNKNOWN; + + /* "tapdisk-params" is only for tapdisk */ + tmp = xs_read(ctx->xsh, XBT_NULL, + libxl__sprintf(gc, "%s/tapdisk-params", be_path), &len); + if (tmp) { + char *pdev_path; + /* tmp is "format:pdev_path" */ + pdev_path = strchr(tmp, ':'); + if (!pdev_path) { + LOG(ERROR, "corrupted tapdisk-params: \"%s\"\n", tmp); + free(tmp); + goto cleanup; + } + disk->pdev_path = strdup(pdev_path + 1); + *pdev_path = '\0'; + rc = libxl_string_to_format(ctx, tmp, &disk->format); + if (rc) { + LOG(ERROR, "unknown disk format: %s\n", tmp); + free(tmp); + goto cleanup; + } + if (disk->format != LIBXL_DISK_FORMAT_VHD && + disk->format != LIBXL_DISK_FORMAT_RAW && + disk->format != LIBXL_DISK_FORMAT_REMUS && + disk->format != LIBXL_DISK_FORMAT_COLO) { + LOG(ERROR, "unsupported tapdisk format: %s\n", tmp); + free(tmp); + goto cleanup; + } + free(tmp); + + /* + * The backend is tapdisk, so we store tapdev in params, and + * phy in type(see device_disk_add()) + */ + disk->backend = LIBXL_DISK_BACKEND_TAP; + + goto skip_type; + } + /* "params" may not be present; but everything else must be. */ tmp = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(gc, "%s/params", be_path), &len); @@ -2381,6 +2422,7 @@ static int libxl__device_disk_from_xs_be(libxl__gc *gc, } libxl_string_to_backend(ctx, tmp, &(disk->backend)); +skip_type: disk->vdev = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(gc, "%s/dev", be_path), &len); if (!disk->vdev) { @@ -2414,8 +2456,6 @@ static int libxl__device_disk_from_xs_be(libxl__gc *gc, } disk->is_cdrom = !strcmp(tmp, "cdrom"); - disk->format = LIBXL_DISK_FORMAT_UNKNOWN; - return 0; cleanup: libxl_device_disk_dispose(disk); diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c index 58df4f3..6c35ba8 100644 --- a/tools/libxl/libxl_utils.c +++ b/tools/libxl/libxl_utils.c @@ -319,6 +319,29 @@ out: return rc; } +int libxl_string_to_format(libxl_ctx *ctx, char *s, libxl_disk_format *format) +{ + int rc = 0; + if (!strcmp(s, "aio")) { + *format = LIBXL_DISK_FORMAT_RAW; + } else if (!strcmp(s, "qcow")) { + *format = LIBXL_DISK_FORMAT_QCOW; + } else if (!strcmp(s, "qcow2")) { + *format = LIBXL_DISK_FORMAT_QCOW2; + } else if (!strcmp(s, "vhd")) { + *format = LIBXL_DISK_FORMAT_VHD; + } else if (!strcmp(s, "remus")) { + *format = LIBXL_DISK_FORMAT_REMUS; + } else if (!strcmp(s, "colo")) { + *format = LIBXL_DISK_FORMAT_COLO; + } else { + *format = LIBXL_DISK_FORMAT_UNKNOWN; + rc = ERROR_FAIL; + } + + return rc; +} + int libxl_read_file_contents(libxl_ctx *ctx, const char *filename, void **data_r, int *datalen_r) { GC_INIT(ctx); diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h index 117b229..9178836 100644 --- a/tools/libxl/libxl_utils.h +++ b/tools/libxl/libxl_utils.h @@ -33,6 +33,7 @@ int libxl_get_stubdom_id(libxl_ctx *ctx, int guest_domid); int libxl_is_stubdom(libxl_ctx *ctx, uint32_t domid, uint32_t *target_domid); int libxl_create_logfile(libxl_ctx *ctx, const char *name, char **full_name); int libxl_string_to_backend(libxl_ctx *ctx, char *s, libxl_disk_backend *backend); +int libxl_string_to_format(libxl_ctx *ctx, char *s, libxl_disk_format *format); int libxl_read_file_contents(libxl_ctx *ctx, const char *filename, void **data_r, int *datalen_r); -- 1.9.3 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |