xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony.perard@citrix.com>
To: George Dunlap <george.dunlap@eu.citrix.com>
Cc: Ian Jackson <ian.jackson@citrix.com>,
	sstanisi@cbnco.com, Roger Pau Monne <roger.pau@citrix.com>,
	xen-devel@lists.xen.org
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:19:53 +0100	[thread overview]
Message-ID: <51793B89.7020903@citrix.com> (raw)
In-Reply-To: <1366387166-21197-1-git-send-email-george.dunlap@eu.citrix.com>

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.

> +
> +    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);

-- 
Anthony PERARD

  parent reply	other threads:[~2013-04-25 14:19 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-19 15:59 [PATCH v6 1/2] libxl: Introduce functions to add and remove USB devices to an HVM guest George Dunlap
2013-04-19 15:59 ` [PATCH v6 2/2] xl: Add commands for usb hot-plug George Dunlap
2013-04-24 12:45   ` Ian Campbell
2013-04-25 10:16     ` George Dunlap
2013-04-25 11:38       ` Ian Campbell
2013-04-25 11:57         ` George Dunlap
2013-04-25 12:04           ` George Dunlap
2013-04-25 12:08           ` Ian Campbell
2013-04-25 12:14             ` George Dunlap
2013-04-25 12:21               ` George Dunlap
2013-04-25 12:45                 ` Ian Campbell
2013-04-25 12:47               ` Ian Campbell
2013-04-25 13:42           ` Pasi Kärkkäinen
2013-04-25 13:48             ` George Dunlap
2013-04-24 11:56 ` [PATCH v6 1/2] libxl: Introduce functions to add and remove USB devices to an HVM guest Ian Campbell
2013-04-24 12:48   ` George Dunlap
2013-04-24 12:53     ` Ian Campbell
2013-04-24 13:37       ` George Dunlap
2013-04-24 13:53         ` Ian Campbell
2013-04-24 12:38 ` Ian Campbell
2013-04-24 13:32   ` George Dunlap
2013-04-24 13:47     ` Ian Campbell
2013-04-24 13:51     ` Ian Campbell
2013-04-24 15:45       ` George Dunlap
2013-04-24 15:51         ` Ian Campbell
2013-04-24 17:49           ` Pasi Kärkkäinen
2013-04-25  7:44             ` Ian Campbell
2013-04-25  7:54               ` Pasi Kärkkäinen
2013-04-25  9:56               ` George Dunlap
2013-04-25 10:17                 ` Pasi Kärkkäinen
2013-04-25 14:19 ` Anthony PERARD [this message]
2013-04-25 14:31   ` George Dunlap

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51793B89.7020903@citrix.com \
    --to=anthony.perard@citrix.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=ian.jackson@citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=sstanisi@cbnco.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).