From mboxrd@z Thu Jan 1 00:00:00 1970 From: George Dunlap Subject: Re: [PATCH v4 2/2] xl: Add commands for usb hot-plug Date: Wed, 17 Apr 2013 11:03:30 +0100 Message-ID: <516E7372.3080609@eu.citrix.com> References: <1365706317-5368-1-git-send-email-george.dunlap@eu.citrix.com> <1365706317-5368-2-git-send-email-george.dunlap@eu.citrix.com> <516E7330.2070101@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <516E7330.2070101@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Roger Pau Monne Cc: "sstanisi@cbnco.com" , Ian Jackson , "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org On 17/04/13 11:02, Roger Pau Monne wrote: > On 11/04/13 20:51, George Dunlap wrote: >> Signed-off-by: George Dunlap >> CC: Ian Jackson >> CC: Roger Pau Monne >> CC: sstanisi@cbnco.com >> --- >> 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 I<-d domain-id> I<-v hosbus.hostaddr> >> + >> +Passes through the host USB device specified by I. 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 I<-d domain-id> I<-v hosbus.hostaddr> >> + >> +Remove the host USB device from I which is specified >> +by . 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 I >> + >> +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