Skip to contentSkip to conversation

libxl cd-insert/eject with qemu-xen

PATCH In review Anthony PERARD 2 participants 5 messages Oct 8, 2012 – Oct 9, 2012

lore
Share & tools
lore
#0 lore raw

v2 cover libxl cd-insert/eject with qemu-xen

This patch series provides the facility to eject and insert a cdrom when the used device-model is qemu-xen. The only difference between both device-model is a call to a QMP command as xl cd-insert ... will still update xenstore, even if it's not used by QEMU.

Change since v1:
- Update first patch to use new facilities introduce by my previous applied series.
- Use the disk dev number instead of the vdev string as on id for the cdrom.

Anthony PERARD (3):
libxl_qmp, Introduce libxl__qmp_insert_cdrom.
libxl_dm: Set an id to cdrom drives with qemuu.
libxl: Fix cd-insert with qemu-xen.

 tools/libxl/libxl.c          | 12 ++++++------
 tools/libxl/libxl_dm.c       |  7 ++++---
 tools/libxl/libxl_internal.h |  1 +
 tools/libxl/libxl_qmp.c      | 16 ++++++++++++++++
 4 files changed, 27 insertions(+), 9 deletions(-)
Signature · 1 line
Anthony PERARD
#1 lore raw

PATCH v2 1/3 libxl_qmp, Introduce libxl__qmp_insert_cdrom.

This function can eject or change the CDROM for a guest that use qemu-xen as a device-model.

---
 tools/libxl/libxl_internal.h |  1 +
 tools/libxl/libxl_qmp.c      | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)
tools/libxl/libxl_internal.h +1 -0
index afa36a7..4240ef2 100644
@@ -1406,6 +1406,7 @@ _hidden int libxl__qmp_resume(libxl__gc *gc, int domid);
 _hidden int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename);
 /* Set dirty bitmap logging status */
 _hidden int libxl__qmp_set_global_dirty_log(libxl__gc *gc, int domid, bool enable);
+_hidden int libxl__qmp_insert_cdrom(libxl__gc *gc, int domid, const libxl_device_disk *disk);
 /* close and free the QMP handler */
 _hidden void libxl__qmp_close(libxl__qmp_handler *qmp);
 /* remove the socket file, if the file has already been removed,
tools/libxl/libxl_qmp.c +16 -0
index 5fa0c65..7f1dd98 100644
@@ -913,6 +913,22 @@ int libxl__qmp_set_global_dirty_log(libxl__gc *gc, int domid, bool enable)
                            NULL, NULL);
 }
 
+int libxl__qmp_insert_cdrom(libxl__gc *gc, int domid,
+                            const libxl_device_disk *disk)
+{
+    libxl__json_object *args = NULL;
+    int dev_number = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
+
+    QMP_PARAMETERS_SPRINTF(&args, "device", "ide-%i", dev_number);
+
+    if (disk->format == LIBXL_DISK_FORMAT_EMPTY) {
+        return qmp_run_command(gc, domid, "eject", args, NULL, NULL);
+    } else {
+        qmp_parameters_add_string(gc, &args, "target", disk->pdev_path);
+        return qmp_run_command(gc, domid, "change", args, NULL, NULL);
+    }
+}
+
 int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid,
                                const libxl_domain_config *guest_config)
 {
Signature · 1 line
Anthony PERARD
#2 lore raw

PATCH v2 2/3 libxl_dm: Set an id to cdrom drives with qemuu.

In reply to Anthony PERARD

In order to eject and change a cdrom when using qemu-xen, this patch adds an id the cdrom driver when starting the device model.

---
 tools/libxl/libxl_dm.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tools/libxl/libxl_dm.c +4 -3
index 054da3e..c036dc1 100644
@@ -544,11 +544,12 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc,
             if (disks[i].is_cdrom) {
                 if (disks[i].format == LIBXL_DISK_FORMAT_EMPTY)
                     drive = libxl__sprintf
-                        (gc, "if=ide,index=%d,media=cdrom,cache=writeback", disk);
+                        (gc, "if=ide,index=%d,media=cdrom,cache=writeback,id=ide-%i",
+                         disk, dev_number);
                 else
                     drive = libxl__sprintf
-                        (gc, "file=%s,if=ide,index=%d,media=cdrom,format=%s,cache=writeback",
-                         disks[i].pdev_path, disk, format);
+                        (gc, "file=%s,if=ide,index=%d,media=cdrom,format=%s,cache=writeback,id=ide-%i",
+                         disks[i].pdev_path, disk, format, dev_number);
             } else {
                 if (disks[i].format == LIBXL_DISK_FORMAT_EMPTY) {
                     LIBXL__LOG(ctx, LIBXL__LOG_WARNING, "cannot support"
Signature · 1 line
Anthony PERARD
#3 lore raw

PATCH v2 3/3 libxl: Fix cd-insert with qemu-xen.

In reply to Anthony PERARD

If qemu-xen is used as a device model, the command to insert, change or eject a cdrom will go through QMP. XenStore is still updated even if QEMU will not read from it.

---
 tools/libxl/libxl.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
tools/libxl/libxl.c +6 -6
index 0cf4768..3366ccf 100644
@@ -2141,12 +2141,6 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,
         rc = ERROR_FAIL;
         goto out;
     }
-    if (dm_ver != LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL) {
-        LOG(ERROR, "cdrom-insert does not work with %s",
-            libxl_device_model_version_to_string(dm_ver));
-        rc = ERROR_INVAL;
-        goto out;
-    }
 
     disks = libxl_device_disk_list(ctx, domid, &num);
     for (i = 0; i < num; i++) {
@@ -2170,6 +2164,12 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,
 
     rc = libxl__device_from_disk(gc, domid, disk, &device);
     if (rc) goto out;
+
+    if (dm_ver == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) {
+        rc = libxl__qmp_insert_cdrom(gc, domid, disk);
+        if (rc) goto out;
+    }
+
     path = libxl__device_backend_path(gc, &device);
 
     insert = flexarray_make(gc, 4, 1);
Signature · 1 line
Anthony PERARD
Acked-by on the v2 series
#4 lore raw
In reply to Anthony PERARD
Quoted 4 lines · Anthony PERARD

This patch series provides the facility to eject and insert a cdrom when the used device-model is qemu-xen. The only difference between both device-model is a call to a QMP command as xl cd-insert ... will still update xenstore, even if it's not used by QEMU.

All:

And applied.

Quoted 18 lines

Change since v1:
- Update first patch to use new facilities introduce by my previous applied series.
- Use the disk dev number instead of the vdev string as on id for the cdrom.

Anthony PERARD (3):
libxl_qmp, Introduce libxl__qmp_insert_cdrom.
libxl_dm: Set an id to cdrom drives with qemuu.
libxl: Fix cd-insert with qemu-xen.

 tools/libxl/libxl.c          | 12 ++++++------
 tools/libxl/libxl_dm.c       |  7 ++++---
 tools/libxl/libxl_internal.h |  1 +
 tools/libxl/libxl_qmp.c      | 16 ++++++++++++++++
 4 files changed, 27 insertions(+), 9 deletions(-)