WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 5 of 7] libxl: refactor DISK_BACKEND_PHY handling in

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 5 of 7] libxl: refactor DISK_BACKEND_PHY handling in libxl_device_disk_add
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Thu, 07 Apr 2011 10:52:31 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Thu, 07 Apr 2011 02:58:51 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1302169946@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1302169946@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.4
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1302167211 -3600
# Node ID ec3b25b5aa8095c5fe070173af888f032f6c2c5e
# Parent  cbf6ec01faef6502845d8201a717edc9fa6fae52
libxl: refactor DISK_BACKEND_PHY handling in libxl_device_disk_add

A step on the path to sharing this code with the tail-end of the
DISK_BACKEND_TAP case.

I made the result of libxl__blktap_devpath non-const to achieve
this. The existing caller calls libxl__strdup on the result but since
the function is an internal one and the result is already garbage
collected I think this is unnecessary and we can just use the
non-const result directly.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r cbf6ec01faef -r ec3b25b5aa80 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Thu Apr 07 10:06:51 2011 +0100
+++ b/tools/libxl/libxl.c       Thu Apr 07 10:06:51 2011 +0100
@@ -949,6 +949,7 @@ int libxl_device_disk_add(libxl_ctx *ctx
     libxl__gc gc = LIBXL_INIT_GC(ctx);
     flexarray_t *front;
     flexarray_t *back;
+    char *dev;
     char *backend_type;
     int devid;
     libxl__device device;
@@ -997,36 +998,39 @@ int libxl_device_disk_add(libxl_ctx *ctx
         disk->backend == DISK_BACKEND_QDISK;
 
     switch (disk->backend) {
-        case DISK_BACKEND_PHY: 
-            libxl__device_physdisk_major_minor(disk->pdev_path, &major, 
&minor);
+        case DISK_BACKEND_PHY:
+            dev = disk->pdev_path;
+
+            libxl__device_physdisk_major_minor(dev, &major, &minor);
             flexarray_append(back, "physical-device");
             flexarray_append(back, libxl__sprintf(&gc, "%x:%x", major, minor));
 
             flexarray_append(back, "params");
-            flexarray_append(back, disk->pdev_path);
+            flexarray_append(back, dev);
 
             device.backend_kind = DEVICE_VBD;
             break;
         case DISK_BACKEND_TAP:
-            {
-                const char *dev = libxl__blktap_devpath(&gc,
-                                               disk->pdev_path, disk->format);
-                if (!dev) {
-                    rc = ERROR_FAIL;
-                    goto out_free;
-                }
-                flexarray_append(back, "tapdisk-params");
-                flexarray_append(back, libxl__sprintf(&gc, "%s:%s",
-                    libxl__device_disk_string_of_format(disk->format),
-                    disk->pdev_path));
-                flexarray_append(back, "params");
-                flexarray_append(back, libxl__strdup(&gc, dev));
-                backend_type = "phy";
-                libxl__device_physdisk_major_minor(dev, &major, &minor);
-                flexarray_append(back, "physical-device");
-                flexarray_append(back, libxl__sprintf(&gc, "%x:%x", major, 
minor));
-                device.backend_kind = DEVICE_VBD;
+            dev = libxl__blktap_devpath(&gc, disk->pdev_path, disk->format);
+            if (!dev) {
+                rc = ERROR_FAIL;
+                goto out_free;
             }
+            flexarray_append(back, "tapdisk-params");
+            flexarray_append(back, libxl__sprintf(&gc, "%s:%s",
+                libxl__device_disk_string_of_format(disk->format),
+                disk->pdev_path));
+
+            flexarray_append(back, "params");
+            flexarray_append(back, dev);
+
+            backend_type = "phy";
+
+            libxl__device_physdisk_major_minor(dev, &major, &minor);
+            flexarray_append(back, "physical-device");
+            flexarray_append(back, libxl__sprintf(&gc, "%x:%x", major, minor));
+
+            device.backend_kind = DEVICE_VBD;
             break;
         case DISK_BACKEND_QDISK:
             flexarray_append(back, "params");
@@ -1110,7 +1114,7 @@ int libxl_device_disk_del(libxl_ctx *ctx
 char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
-    const char *dev = NULL;
+    char *dev = NULL;
     char *ret = NULL;
 
     switch (disk->backend) {
diff -r cbf6ec01faef -r ec3b25b5aa80 tools/libxl/libxl_blktap2.c
--- a/tools/libxl/libxl_blktap2.c       Thu Apr 07 10:06:51 2011 +0100
+++ b/tools/libxl/libxl_blktap2.c       Thu Apr 07 10:06:51 2011 +0100
@@ -24,9 +24,9 @@ int libxl__blktap_enabled(libxl__gc *gc)
     return !tap_ctl_check(&msg);
 }
 
-const char *libxl__blktap_devpath(libxl__gc *gc,
-                                 const char *disk,
-                                 libxl_disk_format format)
+char *libxl__blktap_devpath(libxl__gc *gc,
+                            const char *disk,
+                            libxl_disk_format format)
 {
     const char *type;
     char *params, *devname = NULL;
diff -r cbf6ec01faef -r ec3b25b5aa80 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Thu Apr 07 10:06:51 2011 +0100
+++ b/tools/libxl/libxl_internal.h      Thu Apr 07 10:06:51 2011 +0100
@@ -325,9 +325,9 @@ _hidden int libxl__blktap_enabled(libxl_
  *    returns device path xenstore wants to have. returns NULL
  *      if no device corresponds to the disk.
  */
-_hidden const char *libxl__blktap_devpath(libxl__gc *gc,
-                                 const char *disk,
-                                 libxl_disk_format format);
+_hidden char *libxl__blktap_devpath(libxl__gc *gc,
+                                    const char *disk,
+                                    libxl_disk_format format);
 
 _hidden char *libxl__uuid2string(libxl__gc *gc, const libxl_uuid uuid);
 
diff -r cbf6ec01faef -r ec3b25b5aa80 tools/libxl/libxl_noblktap2.c
--- a/tools/libxl/libxl_noblktap2.c     Thu Apr 07 10:06:51 2011 +0100
+++ b/tools/libxl/libxl_noblktap2.c     Thu Apr 07 10:06:51 2011 +0100
@@ -21,9 +21,9 @@ int libxl__blktap_enabled(libxl__gc *gc)
     return 0;
 }
 
-const char *libxl__blktap_devpath(libxl__gc *gc,
-                                 const char *disk,
-                                 libxl_disk_format format)
+char *libxl__blktap_devpath(libxl__gc *gc,
+                            const char *disk,
+                            libxl_disk_format format)
 {
     return NULL;
 }

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