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

Re: [Xen-devel] [PATCH v6 1/2] libxl: Introduce functions to add and remove USB devices to an HVM guest



On 04/25/2013 03:19 PM, Anthony PERARD wrote:
On 19/04/13 16:59, George Dunlap wrote:
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index 644d2c0..9ad3e59 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -42,6 +42,7 @@

  #define QMP_RECEIVE_BUFFER_SIZE 4096
  #define PCI_PT_QDEV_ID "pci-pt-%02x_%02x.%01x"
+#define HOST_USB_QDEV_ID "usb-hostdev-%04x.%04x"

  typedef int (*qmp_callback_t)(libxl__qmp_handler *qmp,
                                const libxl__json_object *tree,
@@ -929,6 +930,70 @@ int libxl__qmp_insert_cdrom(libxl__gc *gc, int domid,
      }
  }

+static int libxl__qmp_usb_hostdev_add(libxl__gc *gc, int domid,
+                                      libxl__device_usb *dev)
+{
+    libxl__json_object *args = NULL;
+    char *id;
+
+    id = GCSPRINTF(HOST_USB_QDEV_ID,
+                   (uint16_t)dev->u.hostdev.hostbus,
+                   (uint16_t)dev->u.hostdev.hostaddr);
+
+    qmp_parameters_add_string(gc, &args, "driver", "usb-host");
+    QMP_PARAMETERS_SPRINTF(&args, "hostbus", "0x%x",
dev->u.hostdev.hostbus);
+    QMP_PARAMETERS_SPRINTF(&args, "hostaddr", "0x%x",
dev->u.hostdev.hostaddr);
+
+    qmp_parameters_add_string(gc, &args, "id", id);

You can use QMP_PARAMETERS_SPRINTF here instead of having a separate
GCSPRINTF call. The former do the same call to sprintf as the later.

Ah, right -- another vestige of when I was passing the 'id' string back inside the device.


+
+    return qmp_run_command(gc, domid, "device_add", args, NULL, NULL);
+}
+
+int libxl__qmp_usb_add(libxl__gc *gc, int domid, libxl__device_usb
*usbdev)
+{
+    int rc;
+    switch (usbdev->type) {
+    case LIBXL_DEVICE_USB_TYPE_HOSTDEV:
+        rc = libxl__qmp_usb_hostdev_add(gc, domid, usbdev);
+        break;
+    default:
+        return ERROR_INVAL;
+    }
+    return rc;
+}
+
+
+static int libxl__qmp_usb_hostdev_remove(libxl__gc *gc, int domid,
+                                         libxl__device_usb *dev)
+{
+    libxl__json_object *args = NULL;
+    char *id;
+
+    id = GCSPRINTF(HOST_USB_QDEV_ID,
+                   (uint16_t)dev->u.hostdev.hostbus,
+                   (uint16_t)dev->u.hostdev.hostaddr);
+
+    qmp_parameters_add_string(gc, &args, "id", id);
+
+    return qmp_run_command(gc, domid, "device_del", args, NULL, NULL);

There is already a "device_del" which can be called:
static int qmp_device_del(libxl__gc *gc, int domid, char *id);


Ack.

 -George


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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