[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v3 10/15] libxl: make libxl_cd_insert "eject" + "insert"
A "cdrom insert" is always processed as "eject" + "insert", with JSON config updated in between. So that we can know the correct state of CDROM later when we try to retrieve domain configuration: if xenstore is "empty", then CDROM is "empty"; otherwise use the information presented in JSON. Note that libxl_cd_insert doesn't care about the incarnation of "empty" state so I don't state explictly what is in xenstore. Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- change in v3: clarify "empty" in commit log --- tools/libxl/libxl.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index fa7d5d5..1fdb2d8 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -2662,8 +2662,9 @@ int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid, return 0; } -int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, - const libxl_asyncop_how *ao_how) +static int libxl__cdrom_insert(libxl_ctx *ctx, uint32_t domid, + libxl_device_disk *disk, + const libxl_asyncop_how *ao_how) { AO_CREATE(ctx, domid, ao_how); int num = 0, i; @@ -2774,6 +2775,68 @@ out: return AO_INPROGRESS; } +/* + * A "cdrom insert" is always processed as "eject" + "insert", with + * updating JSON in between. So that we can know the current state of + * CDROM later when we try to retrieve domain configuration: if + * xenstore is "empty", then CDROM is "empty"; otherwise use the image + * in JSON. + * + * Note that we don't actually care about the incarnation of "empty" + * state so we don't state explicitly what the content in xenstore + * should be. + * + * In order to maintain lock hierarchy, CTX lock is taken when + * entering this function. + */ +int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, + const libxl_asyncop_how *ao_how) +{ + GC_INIT(ctx); + libxl_domain_config d_config; + libxl_device_disk empty; + int rc; + libxl__carefd *lock = NULL; + + CTX_LOCK; + + libxl_domain_config_init(&d_config); + libxl_device_disk_init(&empty); + empty.format = LIBXL_DISK_FORMAT_EMPTY; + empty.vdev = libxl__strdup(NOGC, disk->vdev); + empty.is_cdrom = 1; + + rc = libxl__cdrom_insert(ctx, domid, &empty, NULL); + if (rc) + goto out; + + /* Optimisation: don't insert empty disk twice, and skip + * manipulating JSON. */ + if (disk->format == LIBXL_DISK_FORMAT_EMPTY) + goto out; + + lock = libxl__lock_domain_userdata(gc, domid); + if (!lock) { + rc = ERROR_LOCK_FAIL; + goto out; + } + rc = libxl__get_domain_configuration(gc, domid, &d_config); + if (rc) goto out; + DEVICE_ADD(disk, disks, domid, disk, COMPARE_DISK, &d_config); + rc = libxl__set_domain_configuration(gc, domid, &d_config); + if (rc) goto out; + libxl__unlock_domain_userdata(lock); + + rc = libxl__cdrom_insert(ctx, domid, disk, ao_how); + +out: + libxl_device_disk_dispose(&empty); + libxl_domain_config_dispose(&d_config); + CTX_UNLOCK; + GC_FREE; + return rc; +} + /* libxl__alloc_vdev only works on the local domain, that is the domain * where the toolstack is running */ static char * libxl__alloc_vdev(libxl__gc *gc, void *get_vdev_user, -- 1.7.10.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |