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-changelog

[Xen-changelog] [xen-unstable] libxl: refactor DISK_BACKEND_PHY handling

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] libxl: refactor DISK_BACKEND_PHY handling in libxl_device_disk_add
From: Xen patchbot-unstable <patchbot@xxxxxxx>
Date: Sat, 09 Apr 2011 09:20:28 +0100
Delivery-date: Sat, 09 Apr 2011 01:27:38 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1302277193 -3600
# Node ID b49301d2de11b45de574894953d814cbaac0093c
# Parent  4b0fa61585849a32fda98a88a659b3bfbe38a769
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>
Committed-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---


diff -r 4b0fa6158584 -r b49301d2de11 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Fri Apr 08 16:39:19 2011 +0100
+++ b/tools/libxl/libxl.c       Fri Apr 08 16:39:53 2011 +0100
@@ -949,6 +949,7 @@
     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 @@
         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 @@
 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 4b0fa6158584 -r b49301d2de11 tools/libxl/libxl_blktap2.c
--- a/tools/libxl/libxl_blktap2.c       Fri Apr 08 16:39:19 2011 +0100
+++ b/tools/libxl/libxl_blktap2.c       Fri Apr 08 16:39:53 2011 +0100
@@ -24,9 +24,9 @@
     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 4b0fa6158584 -r b49301d2de11 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Fri Apr 08 16:39:19 2011 +0100
+++ b/tools/libxl/libxl_internal.h      Fri Apr 08 16:39:53 2011 +0100
@@ -325,9 +325,9 @@
  *    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 4b0fa6158584 -r b49301d2de11 tools/libxl/libxl_noblktap2.c
--- a/tools/libxl/libxl_noblktap2.c     Fri Apr 08 16:39:19 2011 +0100
+++ b/tools/libxl/libxl_noblktap2.c     Fri Apr 08 16:39:53 2011 +0100
@@ -21,9 +21,9 @@
     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-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] libxl: refactor DISK_BACKEND_PHY handling in libxl_device_disk_add, Xen patchbot-unstable <=