[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v3 27/31] libxl_qmp: Implement libxl__qmp_insert_cdrom_ev



This function is a reimplementation of libxl__qmp_insert_cdrom() but to be
use with libxl__ev_qmp.

It also open the cdrom in libxl and send the FD via QMP, so QEMU doesn't
need access permition on the cdrom file.

libxl_cdrom_insert() will need to be reorganize to be able to use that
new function, this is done in the next few patches.

Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
---
 tools/libxl/libxl_internal.h |   4 ++
 tools/libxl/libxl_qmp.c      | 102 +++++++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+)

diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 16533f651e..371b27e866 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1870,6 +1870,10 @@ _hidden int libxl__qmp_restore(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);
+int libxl__qmp_insert_cdrom_ev(libxl__gc *gc, int domid,
+                               libxl__ev_qmp *ev,
+                               libxl__ev_qmp_callback *callback,
+                               const libxl_device_disk *disk);
 /* Add a virtual CPU */
 _hidden int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int index);
 /* Query the bitmap of CPUs */
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index f44b313a5e..6728e5ad9e 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -1361,6 +1361,108 @@ int libxl__qmp_initializations(libxl__gc *gc, uint32_t 
domid,
     return ret;
 }
 
+/*
+ * Function using libxl__ev_qmp
+ */
+
+/* libxl__qmp_insert_cdrom_ev */
+
+struct cdrom_insert_ev_callback {
+    libxl__ev_qmp ev;
+    libxl__ev_qmp *callback_ev;
+    libxl__ev_qmp_callback *callback;
+    const libxl_device_disk *disk;
+};
+
+static void cdrom_insert_fd_cb(libxl__egc *egc, libxl__ev_qmp *ev,
+                               const libxl__json_object *response,
+                               libxl__qmp_error_class error)
+{
+    EGC_GC;
+    libxl__json_object *args = NULL;
+    const libxl__json_object *o;
+    struct cdrom_insert_ev_callback *cb = CONTAINER_OF(ev, *cb, ev);
+    const libxl_device_disk *disk = cb->disk;
+    int dev_number = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
+    int fdset;
+    int rc;
+
+    o = libxl__json_map_get("fdset-id", response, JSON_INTEGER);
+    if (!o) {
+        rc = ERROR_FAIL;
+        goto out;
+    }
+    fdset = libxl__json_object_get_integer(o);
+
+    QMP_PARAMETERS_SPRINTF(&args, "device", "ide-%i", dev_number);
+    QMP_PARAMETERS_SPRINTF(&args, "target", "/dev/fdset/%d", fdset);
+    qmp_parameters_add_string(gc, &args, "arg",
+                              libxl__qemu_disk_format_string(disk->format));
+    rc = libxl__ev_qmp_register(gc, cb->callback_ev,
+                                cb->callback,
+                                ev->domid,
+                                "change", args);
+    if (rc)
+        goto out;
+out:
+    libxl__ev_qmp_deregister(gc, ev);
+    if (!o || rc) {
+        cb->callback(egc, cb->callback_ev, NULL,
+                     LIBXL__QMP_ERROR_CLASS_LIBXL_ERROR);
+    }
+    free(cb);
+}
+
+
+int libxl__qmp_insert_cdrom_ev(libxl__gc *gc, int domid, libxl__ev_qmp *ev,
+                               libxl__ev_qmp_callback *callback,
+                               const libxl_device_disk *disk)
+{
+    libxl__json_object *args = NULL;
+    int dev_number = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
+    int rc;
+    libxl__carefd *cdrom_efd = NULL;
+    struct cdrom_insert_ev_callback *cb = NULL;
+
+    if (disk->format == LIBXL_DISK_FORMAT_EMPTY) {
+        QMP_PARAMETERS_SPRINTF(&args, "device", "ide-%i", dev_number);
+        rc = libxl__ev_qmp_register(gc, ev, callback, domid,
+                                    "eject", args);
+    } else {
+        libxl__carefd_begin();
+        cdrom_efd = libxl__carefd_opened(CTX, open(disk->pdev_path, O_RDONLY));
+        if (!cdrom_efd) {
+            LOGED(ERROR, domid,
+                  "Failed to open cdrom file %s", disk->pdev_path);
+            rc = ERROR_FAIL;
+            goto out;
+        }
+
+        cb = libxl__malloc(NOGC, sizeof (*cb));
+        libxl__ev_qmp_init(&cb->ev);
+        cb->callback = callback;
+        cb->callback_ev = ev;
+        cb->disk = disk;
+
+        /* This free form parameter is not use by QEMU or libxl. */
+        QMP_PARAMETERS_SPRINTF(&args, "opaque", "%s:%s",
+                               libxl_disk_format_to_string(disk->format),
+                               disk->pdev_path);
+        cb->ev.efd = cdrom_efd;
+        rc = libxl__ev_qmp_register(gc, &cb->ev, cdrom_insert_fd_cb, domid,
+                                    "add-fd", args);
+        if (rc)
+            goto out;
+    }
+out:
+    if (rc) {
+        free(cb);
+        libxl__carefd_close(cdrom_efd);
+    }
+    return rc;
+}
+
+
 /* ------------ Implementation of libxl__ev_qmp ---------------- */
 
 typedef struct libxl__qmp_rx_buf libxl__qmp_rx_buf;
-- 
Anthony PERARD


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.