All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Jackson <Ian.Jackson@eu.citrix.com>
To: Chunyan Liu <cyliu@suse.com>
Cc: jgross@suse.com, wei.liu2@citrix.com, ian.campbell@citrix.com,
	george.dunlap@eu.citrix.com,
	George Dunlap <george.dunlap@citrix.com>,
	xen-devel@lists.xen.org, jfehlig@suse.com,
	Simon Cao <caobosimon@gmail.com>
Subject: Re: [PATCH V13 3/5] libxl: add pvusb API
Date: Tue, 19 Jan 2016 15:48:24 +0000	[thread overview]
Message-ID: <22174.23240.402164.635740@mariner.uk.xensource.com> (raw)
In-Reply-To: <1453192795-15693-4-git-send-email-cyliu@suse.com>

Chunyan Liu writes ("[PATCH V13 3/5] libxl: add pvusb API"):
> Add pvusb APIs, including:
>  - attach/detach (create/destroy) virtual usb controller.
>  - attach/detach usb device
>  - list usb controller and usb devices
>  - some other helper functions


Thanks.  This is making progress but I'm afraid we're not quite there
yet.


> +static int usbback_dev_unassign(libxl__gc *gc, const char *busid)
> +{
...
> +    /* Till here, USB device has been unbound from USBBACK and
> +     * removed from xenstore, usb list couldn't show it anymore,
> +     * so no matter removimg driver path successfully or not,
> +     * we will report operation success.
> +     */

I'm still unconvinced by this and this may mean that the code in this
function is in the wrong order.  Earlier we had this exchange:

> > Ought this function to really report success if these calls fail ?
> 
> I think so. Till here, the USB device has already been unbound from
> usbback and removed from xenstore. usb-list cannot list it any more.

The problem is that I think that if this function fails, it can leave
 - debris in xenstore (the usbback path)
 - the interface bound to the wrong driver
And then there is no way for the user to get libxl to re-attempt the
operation, or clean up.  Am I right ?

One way to avoid this kind of problem is to deal with the xenstore
path last.  That way the device will still appear as attached to the
domain.

To do this properly I think bind_usbintf may need to become idempotent
even in the face of other callers racing to assign the device.  I
think that would mean bind_usbif it would have to know what driver to
expect to find the device bound to.

George, am I right here ?


I have a few other comments too:

> +/* get original driver path of usb interface, stored in @drvpath */
> +static int usbintf_get_drvpath(libxl__gc *gc, const char *intf, char **drvpath)
> +{
> +    char *spath, *dp = NULL;
> +    struct stat st;
> +    int rc;
> +
> +    spath = GCSPRINTF(SYSFS_USB_DEV "/%s/driver", intf);
> +
> +    rc = lstat(spath, &st);

This `rc' should be `r'.  (CODING_STYLE.)

I mentioned this in my review of v12 in the context of
sysfs_write_intf.  But there is still more than one occurrence in v13
of `rc' for a syscall return value.


> +static int sysfs_write_intf(libxl__gc *gc, const char *intf, const char *path)
> +{

Last time I wrote:

  But there is nothing usb specific about this function.  Looking for
  similar code elsewhere this function seems very similar to
  libxl_pci.c:sysfs_write_bdf, but I won't ask you to try to refactor
  these two functions together.

This time I have remembered that libxl_write_exactly exists, and could
be used.  Sorry for not saing this last time but I think you can
probably just get rid of this in favour of libxl_write_exactly.  If
you think not, please say why.


> +static int bind_usbintf(libxl__gc *gc, const char *intf, const char *drvpath)
> +{
> +    char *path;
> +    struct stat st;
> +
> +    path = GCSPRINTF("%s/%s", drvpath, intf);
> +    /* if already bound, return */
> +    if (!lstat(path, &st))
> +        return 0;
> +    else if (errno != ENOENT)
> +        return ERROR_FAIL;

This new ERROR_FAIL fails to log anything, and probably should.  I
think the anomalous style leads to this mistake.  You should say
       r = lstat...
and adopt the pattern from the rest of libxl.


Thanks,
Ian.

  reply	other threads:[~2016-01-19 15:48 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-19  8:39 [PATCH V13 0/5] xen pvusb toolstack work Chunyan Liu
2016-01-19  8:39 ` [PATCH V13 1/5] libxl: export some functions for pvusb use Chunyan Liu
2016-01-19  8:39 ` [PATCH V13 2/5] libxl_utils: add internal function to read sysfs file contents Chunyan Liu
2016-01-19  8:39 ` [PATCH V13 3/5] libxl: add pvusb API Chunyan Liu
2016-01-19 15:48   ` Ian Jackson [this message]
2016-02-02 16:26     ` George Dunlap
2016-02-02 18:11       ` Ian Jackson
2016-02-03  7:34         ` Chun Yan Liu
2016-02-03 14:38           ` George Dunlap
2016-02-04  1:44             ` Chun Yan Liu
2016-02-03 14:33         ` George Dunlap
2016-02-04  1:53           ` Chun Yan Liu
     [not found]           ` <56B31FAB02000066000A6596@suse.com>
2016-02-04 14:39             ` Juergen Gross
2016-02-08 14:07               ` George Dunlap
2016-02-08 14:32                 ` Ian Jackson
2016-02-02 16:48     ` George Dunlap
2016-02-03  8:25       ` Chun Yan Liu
2016-01-26 16:12   ` Olaf Hering
2016-01-27  2:29     ` Chun Yan Liu
2016-01-19  8:39 ` [PATCH V13 4/5] domcreate: support pvusb in configuration file Chunyan Liu
2016-01-19 18:08   ` Ian Jackson
2016-01-19  8:39 ` [PATCH V13 5/5] xl: add pvusb commands Chunyan Liu
2016-01-19 18:11   ` Ian Jackson
2016-01-20  3:10     ` Jim Fehlig
2016-01-21 12:12       ` Wei Liu
2016-01-21 12:21         ` Ian Campbell
2016-01-21 12:29           ` Wei Liu
2016-01-21 17:37             ` Ian Jackson
2016-02-16 17:53       ` Ian Jackson
2016-02-17 11:43         ` Wei Liu
2016-02-17 12:17           ` Ian Jackson
2016-02-16 16:56   ` Olaf Hering
2016-02-17  6:14     ` Chun Yan Liu
2016-02-19 10:43     ` Chun Yan Liu
2016-02-19 10:52       ` Olaf Hering
2016-02-19 12:07         ` Olaf Hering
2016-02-24 12:03           ` Wei Liu
2016-02-24 12:52             ` Olaf Hering
     [not found] <569F8391020000660009E667@relay2.provo.novell.com>
2016-01-20  4:56 ` [PATCH V13 3/5] libxl: add pvusb API Chun Yan Liu
2016-01-26  7:43   ` Chun Yan Liu
2016-01-26 16:21     ` George Dunlap
     [not found] <56B0843302000066000A4C90@relay2.provo.novell.com>
2016-02-02  2:36 ` Chun Yan Liu

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=22174.23240.402164.635740@mariner.uk.xensource.com \
    --to=ian.jackson@eu.citrix.com \
    --cc=caobosimon@gmail.com \
    --cc=cyliu@suse.com \
    --cc=george.dunlap@citrix.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=jfehlig@suse.com \
    --cc=jgross@suse.com \
    --cc=wei.liu2@citrix.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.