From mboxrd@z Thu Jan 1 00:00:00 1970 From: George Dunlap Subject: Re: [PATCH v6 1/2] libxl: Introduce functions to add and remove USB devices to an HVM guest Date: Thu, 25 Apr 2013 15:31:52 +0100 Message-ID: <51793E58.1070403@eu.citrix.com> References: <1366387166-21197-1-git-send-email-george.dunlap@eu.citrix.com> <51793B89.7020903@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <51793B89.7020903@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: Anthony PERARD Cc: "sstanisi@cbnco.com" , Roger Pau Monne , Ian Jackson , "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org 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