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

[Xen-devel] [PATCH 1/3] libxl, xl: don't init/dispose when not necessary



Functions like libxl__device_disk_from_xs_be and
libxl_vdev_to_device_disk should not touch the disk struct passed in.
It's caller's responsibility to do that.

This leads to some changes to the caller to prepare the disk struct.

Note that libxl_vdev_to_device_disk is a public API so a macro is
defined in libxl.h to indicate the change of behaviour.

Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/libxl/libxl.c      | 6 +-----
 tools/libxl/libxl.h      | 7 +++++++
 tools/libxl/xl_cmdimpl.c | 1 +
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index cd6f42c..ef48550 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2556,8 +2556,6 @@ static int libxl__device_disk_from_xs_be(libxl__gc *gc,
     char *tmp;
     int rc;
 
-    libxl_device_disk_init(disk);
-
     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);
@@ -2620,7 +2618,6 @@ static int libxl__device_disk_from_xs_be(libxl__gc *gc,
 
     return 0;
 cleanup:
-    libxl_device_disk_dispose(disk);
     return ERROR_FAIL;
 }
 
@@ -2635,8 +2632,6 @@ int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t 
domid,
     if (devid < 0)
         return ERROR_INVAL;
 
-    libxl_device_disk_init(disk);
-
     dompath = libxl__xs_get_dompath(gc, domid);
     if (!dompath) {
         goto out;
@@ -2675,6 +2670,7 @@ static int libxl__append_disk_list_of_type(libxl__gc *gc,
         tmp = realloc(*disks, sizeof (libxl_device_disk) * (*ndisks + n));
         if (tmp == NULL)
             return ERROR_NOMEM;
+        libxl_device_disk_init(tmp);
         *disks = tmp;
         pdisk = *disks + initial_disks;
         pdisk_end = *disks + initial_disks + n;
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index c219f59..8f6ed3c 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -135,6 +135,13 @@
 #define LIBXL_HAVE_LIBXL_DEVICE_DISK_DISCARD_ENABLE 1
 
 /*
+ * The caller of libxl_vdev_to_device_disk should call
+ * libxl_device_disk_init before passing in the disk struct because
+ * libxl_vdev_to_device_disk doesn't do that anymore.
+ */
+#define LIBXL_VDEV_TO_DEVICE_DISK_NO_INIT 1
+
+/*
  * LIBXL_HAVE_BUILDINFO_IOMEM_START_GFN indicates that it is possible
  * to specify the start guest frame number used to map a range of I/O
  * memory machine frame numbers via the 'gfn' field (of type uint64)
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index b7eac29..ef101c3 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -6411,6 +6411,7 @@ int main_blockdetach(int argc, char **argv)
     }
 
     domid = find_domain(argv[optind]);
+    libxl_device_disk_init(&disk);
 
     if (libxl_vdev_to_device_disk(ctx, domid, argv[optind+1], &disk)) {
         fprintf(stderr, "Error: Device %s not connected.\n", argv[optind+1]);
-- 
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®.