All of lore.kernel.org
 help / color / mirror / Atom feed
From: George Dunlap <george.dunlap@eu.citrix.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: "sstanisi@cbnco.com" <sstanisi@cbnco.com>,
	Roger Pau Monne <roger.pau@citrix.com>,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [PATCH v5 1/2] libxl: Introduce functions to add and remove USB devices to an HVM guest
Date: Fri, 19 Apr 2013 11:18:52 +0100	[thread overview]
Message-ID: <51711A0C.7030408@eu.citrix.com> (raw)
In-Reply-To: <20848.12940.847860.437708@mariner.uk.xensource.com>

On 18/04/13 18:51, Ian Jackson wrote:
> George Dunlap writes ("[PATCH v5 1/2] libxl: Introduce functions to add and remove USB devices to an HVM guest"):
>> +    /* Helpfully, libxl__xs_rm_checked() returns 0 on success... */
>> +    rc = libxl__xs_rm_checked(gc, t, libxl_usb_path);
>> +    if (rc) goto out;
>> +    /* ...but libxl__xs_mkdir() returns 1 on success, 0 on failure. */
>> +    rc = libxl__xs_mkdir(gc, t, libxl_usb_path, noperm, ARRAY_SIZE(noperm));
>> +    if (!rc) goto out;
> Is this really right ?  If mkdir fails, you cause libxl__domain_make
> to immediately return success.  The out label expects the error code
> to be in rc.  I think it's a stylistic error to assign the
> (deprecated) boolean return value from libxl__xs_mkdir to rc; rc would
> normally contain a libxl error code.

Yes, you're right on both points.  Good catch.

>
>> +    id = GCSPRINTF(HOST_USB_QDEV_ID,
>> +                   (uint16_t) dev->u.hostdev.hostbus,
>> +                   (uint16_t) dev->u.hostdev.hostaddr);
> I think the style in libxl is to cuddle casts.

Ack.  I've never thought of variables as cuddly before...

>
>> +    switch(usbdev->type) {
> Missing space.  (etc.)  And some overly long lines.

Ack.

>
> Most of the rest of this looks plausible although I wish you wouldn't
> write things like this:
>
>> +    switch(usbdev->type) {
>> +    case LIBXL_DEVICE_USB_TYPE_HOSTDEV:
>> +        if ((rc = read_hostdev_xenstore_entry(gc, path, usbdev)) < 0)
>> +            goto out;
> I guess old habits are hard to break :-).

Well I prefer that way -- having the 'if' on a separate line actually 
annoys me (mildly).  "Do this and handle the error if any" seems like 
one operation in my mind, not two.  But I don't mind changing it.

> I haven't checked the semantics and timing of the xenstore/qmp
> protocol in detail.  But let me ask a question:
>
> Suppose attempted attach or remove of a usb device fails halfway
> through (eg, the user presses ^C and xl just stops since it doesn't
> handle SIGINT).  Is the situation now (a) reported in the usb device
> listing (b) capable of being cleaned up with a remove operation (c)
> tidied up on domain destroy ?  (Is this true at all times - ie does it
> never go through a state where things won't be cleaned up?)

As far as I could determine, there is absolutely no way to query qemu to 
find out what devices are actually attached at the moment; that's the 
whole reason for storing stuff in xenstore in the first place.  So yes 
-- if you kill the process after the qmp command has been issued but 
before writing something in xenstore, then usb-list will not show the 
device, usb-remove will return an error if you attempt to remove the 
device.  usb-add will issue the qmp command, which will then fail.

I think this is probably true of most of the add/remove functions.

We could add an option that says "attempt to do the remove even if you 
don't see the device in xenstore" I suppose.  But I'm not really sure 
how to document that in a useful way without basically describing the 
internal mechanics of the command.

There's nothing we can really do about usb-list though.

On the whole I think I'd rather just say, "Don't do that."

  -George

  reply	other threads:[~2013-04-19 10:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-18 14:46 [PATCH v5 1/2] libxl: Introduce functions to add and remove USB devices to an HVM guest George Dunlap
2013-04-18 14:46 ` [PATCH v5 2/2] xl: Add commands for usb hot-plug George Dunlap
2013-04-18 17:41   ` Ian Jackson
2013-04-19 10:02     ` George Dunlap
2013-04-18 17:51 ` [PATCH v5 1/2] libxl: Introduce functions to add and remove USB devices to an HVM guest Ian Jackson
2013-04-19 10:18   ` George Dunlap [this message]
2013-04-19 10:50     ` Ian Campbell
2013-04-19 11:00       ` George Dunlap
2013-04-19 14:14         ` George Dunlap
2013-04-19 10:53   ` 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=51711A0C.7030408@eu.citrix.com \
    --to=george.dunlap@eu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.