[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] libxl: add custom disconnect functions for different device types



On Fri, 2011-09-23 at 12:55 +0100, Roger Pau Monne wrote:
> # HG changeset patch
> # User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
> # Date 1316778937 -7200
> # Node ID 1d42b1b355c231e794a56dfadf3ee450346e3516
> # Parent  0ab9f548890e5e58122f73aa1c4164fd6e319b1c
> libxl: add custom disconnect functions for different device types.
> 
> This patch creates a new struct, called libxl__disconnect that can be
> used to assign different functions that will be called to check if the
> device is disconnected and to add it to the shutdown watch. Added a
> helper function to get the libxl__device_kind from a be_path. The only
> device that has a different shutdown mechanism right now is vbd.

Looks good. I think all the new functions can be static to
libxl_device.c though.

> diff -r 0ab9f548890e -r 1d42b1b355c2 tools/libxl/libxl_device.c
> --- a/tools/libxl/libxl_device.c      Fri Sep 23 13:31:51 2011 +0200
> +++ b/tools/libxl/libxl_device.c      Fri Sep 23 13:55:37 2011 +0200
> @@ -59,6 +80,18 @@ char *libxl__device_backend_path(libxl__
>                            device->domid, device->devid);
>  }
>  
> +libxl__device_kinds libxl__device_identify(char *be_path)
> +{
> +    int len = sizeof(string_of_kinds)/sizeof(char *);
> +
> +    for (int j = 1; j < len; j++) {
> +        if (strstr(be_path, string_of_kinds[j]))
> +            return j;
> +    }
> +
> +    return DEVICE_UNKNOWN;

You can sscanf out the precise backend rather than using strstr (which I
worry might give false positives and/or rely in the ordering on the enum
in the future).

e.g. something like:
    /* /local/domain/<domid>/backend/<kind>/<domid>/<devid> */
    char strkind[16]; /* Longest is actually "console" */
    uint32_t domain;
    int rc = sscanf(path, "/local/domain/%d/backend/%16s/%d/%d",
                   domid, strkind, &domain, devid);

    /* loop and strcmp of strkind vs string_of_kinds */

Ian.



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.