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

Re: [Xen-devel] [PATCH RFC] libxl: set disk defaults in remove/destroy functions



On Mon, Feb 02, 2015 at 04:38:00PM +0000, Ian Jackson wrote:
> Wei Liu writes ("Re: [Xen-devel] [PATCH RFC] libxl: set disk defaults in 
> remove/destroy functions"):
> > FWIW xl block-detach calls libxl_vdev_to_device_disk to convert a vdev
> > to disk. That function reads xenstore to get the actual backend of that
> > specific vdev. Don't know how useful it is to libvirt though.
> > 
> > Maybe we should look up disk's backend in libxl_device_disk_remove? Not
> > sure what's the best approach.
> 
> libxl_device_disk_remove should definitely not require the caller to
> do what xl currently does.
> 

I come up with something like this (only compile tested).

---8<---
From d2913eb11788db23a1e1541c86e9ffe1a2cb9a30 Mon Sep 17 00:00:00 2001
From: Wei Liu <wei.liu2@xxxxxxxxxx>
Date: Mon, 2 Feb 2015 17:56:47 +0000
Subject: [PATCH] libxl: libxl__device_from_disk should retrieve backend from
 xenstore

Also change the function to use goto idiom while I was there.

Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/libxl/libxl.c | 45 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 82227e8..eff68f2 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2264,12 +2264,49 @@ int libxl__device_from_disk(libxl__gc *gc, uint32_t 
domid,
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     int devid;
+    int rc = 0;
 
     devid = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
     if (devid==-1) {
         LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported"
                " virtual disk identifier %s", disk->vdev);
-        return ERROR_INVAL;
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    if (disk->backend == LIBXL_DISK_BACKEND_UNKNOWN) {
+        char *dompath, *be_path, *be_string;
+
+        dompath = libxl__xs_get_dompath(gc, domid);
+        if (!dompath) {
+            rc = ERROR_FAIL;
+            goto out;
+        }
+
+        be_path = libxl__xs_read(gc, XBT_NULL,
+                                 GCSPRINTF("%s/device/vbd/%d/backend",
+                                           dompath, devid));
+        if  (!be_path) {
+            rc = ERROR_FAIL;
+            goto out;
+        }
+
+        rc = sscanf(be_path, "/local/domain/%d/", &disk->backend_domid);
+        if (rc != 1) {
+            LOG(ERROR, "Unable to fetch device backend domid from %s",
+                be_path);
+            rc =  ERROR_FAIL;
+            goto out;
+        }
+
+        be_string = libxl__xs_read(gc, XBT_NULL,
+                                   GCSPRINTF("%s/type", be_path));
+        if (!be_string) {
+            LOG(ERROR, "Missing xenstore node %s/type", be_path);
+            rc = ERROR_FAIL;
+            goto out;
+        }
+        libxl_string_to_backend(ctx, be_string, &disk->backend);
     }
 
     device->backend_domid = disk->backend_domid;
@@ -2288,14 +2325,16 @@ int libxl__device_from_disk(libxl__gc *gc, uint32_t 
domid,
         default:
             LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend type: 
%d\n",
                        disk->backend);
-            return ERROR_INVAL;
+            rc = ERROR_INVAL;
+            goto out;
     }
 
     device->domid = domid;
     device->devid = devid;
     device->kind  = LIBXL__DEVICE_KIND_VBD;
 
-    return 0;
+out:
+    return rc;
 }
 
 /* Specific function called directly only by local disk attach,
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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