From: Ian Campbell Subject: Re: [PATCH] libxl: add custom disconnect functions for different device types Date: Fri, 23 Sep 2011 16:13:18 +0100 Message-ID: <1316790798.23371.108.camel@zakaz.uk.xensource.com> References: <1d42b1b355c231e794a5.1316778942@loki> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1d42b1b355c231e794a5.1316778942@loki> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Roger Pau Monne Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org On Fri, 2011-09-23 at 12:55 +0100, Roger Pau Monne wrote: > # HG changeset patch > # User Roger Pau Monne > # 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//backend/// */ 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.