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

Re: [Xen-devel] [PATCH v4 2/2] xl: Add commands for usb hot-plug



On 17/04/13 11:02, Roger Pau Monne wrote:
On 11/04/13 20:51, George Dunlap wrote:
Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxxxxx>
CC: Ian Jackson <ian.jackson@xxxxxxxxxx>
CC: Roger Pau Monne <roger.pau@xxxxxxxxxx>
CC: sstanisi@xxxxxxxxx
---
  docs/man/xl.pod.1         |   30 +++++++
  tools/libxl/xl.h          |    3 +
  tools/libxl/xl_cmdimpl.c  |  219 +++++++++++++++++++++++++++++++++++++++++++++
  tools/libxl/xl_cmdtable.c |   15 ++++
  4 files changed, 267 insertions(+)

diff --git a/docs/man/xl.pod.1 b/docs/man/xl.pod.1
index a0e298e..18a8eee 100644
--- a/docs/man/xl.pod.1
+++ b/docs/man/xl.pod.1
@@ -1110,6 +1110,36 @@ List virtual network interfaces for a domain.
=back +=head2 USB DEVICES
+
+=over 4
+
+=item B<usb-add> I<-d domain-id> I<-v hosbus.hostaddr>
+
+Passes through the host USB device specified by I<hostbus.hostaddr>.  At
+the moment this will only work for HVM domains via qemu.
+
+The best way to find out the information for the device is typically using
+lsusb.
+
+This command is only available for domains using qemu-xen, not
+qemu-traditional.
+
+=item B<usb-remove> I<-d domain-id> I<-v hosbus.hostaddr>
+
+Remove the host USB device from I<domain-id> which is specified
+by <hostbus.hostaddr>.  This command only works for devices added
+with usb-add; not for those specified in the config file.
+
+This command is only available for domains using qemu-xen, not
+qemu-traditional.
+
+=item B<usb-list> I<domain-id>
+
+Show host USB devices assigned to the guest.
+
+=back
+
  =head2 VTPM DEVICES
=over 4
diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h
index b881f92..5c39fa2 100644
--- a/tools/libxl/xl.h
+++ b/tools/libxl/xl.h
@@ -35,6 +35,9 @@ int main_info(int argc, char **argv);
  int main_sharing(int argc, char **argv);
  int main_cd_eject(int argc, char **argv);
  int main_cd_insert(int argc, char **argv);
+int main_usb_add(int argc, char **argv);
+int main_usb_remove(int argc, char **argv);
+int main_usb_list(int argc, char **argv);
  int main_console(int argc, char **argv);
  int main_vncviewer(int argc, char **argv);
  int main_pcilist(int argc, char **argv);
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 61f7b96..a690823 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -2600,6 +2600,225 @@ int main_cd_insert(int argc, char **argv)
      return 0;
  }
+
+
+static int parse_usb_hostdev_specifier(libxl_device_usb *dev, const char *s)
+{
+    const char * hostbus, *hostaddr, *p;
+
+    hostbus = s;
+    hostaddr=NULL;
+
+#define is_dec(_c) ((_c) >= '0' && (_c) <= '9')
+#define is_hex(_c) (is_dec(_c) || ((_c) >= 'a' && (_c) <= 'f'))
This are kind of general macros, that could be used elsewhere, might be
suitable to put them outside of this function and name them CHAR_IS_DEC
and CHAR_IS_HEX.

Ack


+
+    /* Match [0-9]+\.[0-9] */
+    if (!is_dec(*hostbus))
+        return -1;
+
+    for(p=s; *p; p++) {
+        if(*p == '.') {
+            if ( !hostaddr )
+                hostaddr = p+1;
+            else {
+                return -1;
+            }
+        } else if (!is_dec(*p)) {
+            return -1;
+        }
+    }
+    if (!hostaddr || !is_dec(*hostaddr))
+        return -1;
+    dev->u.hostdev.hostbus  = strtoul(hostbus,  NULL, 10);
+    dev->u.hostdev.hostaddr = strtoul(hostaddr, NULL, 10);
+#undef is_dec
+#undef is_hex
+
+    return 0;
+}
+
+static int usb_add(uint32_t domid, libxl_device_usb_type type,
+                            const char * device)
+{
+    libxl_device_usb usbdev;
+    int rc;
+
+    libxl_device_usb_init(&usbdev);
+
+    usbdev.type = type;
+
+    switch(type) {
+    case LIBXL_DEVICE_USB_TYPE_HOSTDEV:
+        if ( parse_usb_hostdev_specifier(&usbdev, device) < 0 ) {
+            rc = ERROR_FAIL;
+            goto out;
+        }
+        break;
+    default:
+        fprintf(stderr, "INTERNAL ERROR: Unimplemented type.\n");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    if ( (rc = libxl_device_usb_add(ctx, domid, &usbdev, NULL)) < 0 )
+        fprintf(stderr, "libxl_usb_add failed.\n");
+
+    libxl_device_usb_dispose(&usbdev);
+
+out:
+    return rc;
+}
+
+int main_usb_add(int argc, char **argv)
+{
+    uint32_t domid = -1;
You could use INVALID_DOMID that is defined early in the file.

Sorry, should have done that to begin with.

Thanks,
 -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®.