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(-) -- Anthony PERARD
Anthony PERARD
2012-Oct-08 18:55 UTC
[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. Signed-off-by: Anthony PERARD <anthony.perard@citrix.com> --- tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_qmp.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index afa36a7..4240ef2 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -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, diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index 5fa0c65..7f1dd98 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -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) { -- Anthony PERARD
Anthony PERARD
2012-Oct-08 18:55 UTC
[PATCH V2 2/3] libxl_dm: Set an id to cdrom drives with qemuu.
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. Signed-off-by: Anthony PERARD <anthony.perard@citrix.com> --- tools/libxl/libxl_dm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 054da3e..c036dc1 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -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" -- 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. Signed-off-by: Anthony PERARD <anthony.perard@citrix.com> --- tools/libxl/libxl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 0cf4768..3366ccf 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -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); -- Anthony PERARD
On Mon, 2012-10-08 at 19:55 +0100, Anthony PERARD wrote:> 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: Acked-by: Ian Campbell <ian.campbell@citrix.com> And applied.> > > 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(-) >