|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2 13/18] 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.
Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
tools/libxl/libxl.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 55 insertions(+), 2 deletions(-)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 430a45f..d64d8f1 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2640,8 +2640,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;
@@ -2752,6 +2753,58 @@ 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.
+ *
+ * In order to maintain lock hierachy, 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_device_disk empty;
+ int rc;
+ libxl__carefd *lock = NULL;
+
+ CTX_LOCK;
+
+ 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_data(gc, domid);
+ if (!lock) {
+ rc = ERROR_LOCK_FAIL;
+ goto out;
+ }
+ rc = DEVICE_UPDATE_JSON(disk, disks, num_disks, domid, disk,
+ COMPARE_DISK);
+ libxl__unlock_domain_data(lock);
+
+ rc = libxl__cdrom_insert(ctx, domid, disk, ao_how);
+
+out:
+ libxl_device_disk_dispose(&empty);
+ 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 |