]> xenbits.xensource.com Git - xen.git/commitdiff
libxl: Provide libxl__backendpath_parse_domid
authorIan Jackson <ian.jackson@eu.citrix.com>
Wed, 27 Apr 2016 15:34:19 +0000 (16:34 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Mon, 6 Jun 2016 14:31:24 +0000 (15:31 +0100)
Multiple places in libxl need to figure out the backend domid of a
device.  This can be discovered easily by looking at the backend path,
which always starts /local/domain/$backend_domid/.

There are no call sites yet.

This is part of XSA-175.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
tools/libxl/libxl_device.c
tools/libxl/libxl_internal.h

index a8b97a3edc0bb7a3101950fa2384f3171d29ebfe..9136b26d9e2d1d73d9f06d58a4b940da51915a0f 100644 (file)
@@ -288,6 +288,21 @@ static int disk_try_backend(disk_try_backend_args *a,
     return 0;
 }
 
+int libxl__backendpath_parse_domid(libxl__gc *gc, const char *be_path,
+                                   libxl_domid *domid_out) {
+    int r;
+    unsigned int domid_sc;
+    char delim_sc;
+
+    r = sscanf(be_path, "/local/domain/%u%c", &domid_sc, &delim_sc);
+    if (!(r==2 && delim_sc=='/')) {
+        LOG(ERROR, "internal error: backend path %s unparseable!", be_path);
+        return ERROR_FAIL;
+    }
+    *domid_out = domid_sc;
+    return 0;
+}
+
 int libxl__device_disk_set_backend(libxl__gc *gc, libxl_device_disk *disk) {
     libxl_disk_backend ok;
     disk_try_backend_args a;
index 55b19d9c8b3cce8944b9613ed7684141b13e9eb1..bfe06bd695f37f3fee17af75fff3f2b31932f095 100644 (file)
@@ -594,6 +594,8 @@ _hidden bool libxl__xs_mkdir(libxl__gc *gc, xs_transaction_t t,
 
 _hidden char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid);
 
+_hidden int libxl__backendpath_parse_domid(libxl__gc *gc, const char *be_path,
+                                           libxl_domid *domid_out);
 
 /*----- "checked" xenstore access functions -----*/
 /* Each of these functions will check that it succeeded; if it