From: George Dunlap <george.dunlap@eu.citrix.com>
To: Ian Campbell <Ian.Campbell@citrix.com>
Cc: "sstanisi@cbnco.com" <sstanisi@cbnco.com>,
Roger Pau Monne <roger.pau@citrix.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>,
"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [PATCH v6 2/2] xl: Add commands for usb hot-plug
Date: Thu, 25 Apr 2013 11:16:34 +0100 [thread overview]
Message-ID: <51790282.8090903@eu.citrix.com> (raw)
In-Reply-To: <1366807503.20256.333.camel@zakaz.uk.xensource.com>
On 04/24/2013 01:45 PM, Ian Campbell wrote:
> On Fri, 2013-04-19 at 16:59 +0100, George Dunlap wrote:
>> +
>> +int main_usb_attach(int argc, char **argv)
>> +{
>> + uint32_t domid = INVALID_DOMID;
>> + int opt = 0, rc;
>> + char *device = NULL;
>> +
>> + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-attach", 2) {
>> + /* No options */
>> + }
>> +
>> + domid = find_domain(argv[optind]);
>> + device = argv[optind + 1];
>> +
>> + if (domid == INVALID_DOMID) {
>> + fprintf(stderr, "Must specify domid\n\n");
>> + help("usb-attach");
>> + return 2;
>> + }
>
> find_domain won't return in this case, so no need to worry about it
> yourself.
I find that kind of scary, actually...
>
>> +int main_usb_detach(int argc, char **argv)
>> +{
>> + uint32_t domid = INVALID_DOMID;
>> + int opt = 0, rc;
>> + char *device = NULL;
>> + int type = 0;
>> +
>> + SWITCH_FOREACH_OPT(opt, "", NULL, "usb-detach", 2) {
>> + /* No options */
>> + }
>> +
>> + domid = find_domain(argv[optind]);
>> + device = argv[optind + 1];
>> +
>> + if (domid == INVALID_DOMID) {
>> + fprintf(stderr, "Must specify domid\n\n");
>> + help("usb-detach");
>> + return 2;
>> + }
>
>
> Same again.
>
>> +
>> + rc = usb_detach(domid, type, device);
>> + if (rc < 0)
>> + return 1;
>> + else
>> + return 0;
>> +}
>> +
>> +static void usb_list(uint32_t domid)
>> +{
>> + libxl_device_usb *dev;
>> + int num, i;
>> +
>> + dev = libxl_device_usb_list(ctx, domid, &num);
>> + if (dev == NULL)
>> + return;
>> + printf("protocol backend type device\n");
>> + for (i = 0; i < num; i++) {
>> + printf("%8s ", (dev[i].protocol==LIBXL_USB_PROTOCOL_PV)?"pv":"dm");
>
> You can use libxl_usb_protocol_to_string here.
Could do, but I didn't necessarily want the long version ("devicemodel").
>
>> + printf("%7d ", dev[i].backend_domid);
>> + printf("%7s ", (dev[i].type==LIBXL_DEVICE_USB_TYPE_HOSTDEV)?"hostdev":"unknown");
>
> libxl_device_usb_type_to_string.
Will that print "unknown" in the case of unknown device types?
>
>> + if (dev[i].type == LIBXL_DEVICE_USB_TYPE_HOSTDEV)
>> + printf("%03d.%03d",
>> + dev[i].u.hostdev.hostbus,
>> + dev[i].u.hostdev.hostaddr);
>> + printf("\n");
>> + }
>> + free(dev);
>
> You leak the content of the devices, you need to call
> libxl_device_usb_dispose on each, or better define
> libxl_device_usb_list_free (this is inconsistently provided by other
> devices, but may as well get it right for new code).
Ack.
-George
next prev parent reply other threads:[~2013-04-25 10:16 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 [this message]
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
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=51790282.8090903@eu.citrix.com \
--to=george.dunlap@eu.citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=Ian.Jackson@eu.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).