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: Factorize function libxl_device_di

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] libxl: Factorize function libxl_device_disk_list
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 17 Jan 2011 07:58:45 -0800
Delivery-date: Mon, 17 Jan 2011 08:04:44 -0800
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 Anthony PERARD <anthony.perard@xxxxxxxxxx>
# Date 1294336991 0
# Node ID 2c487c02d8d7a5c0401f25ebd39c39ad23c990e6
# Parent  4e120cb427f44b1d6b11b725ca4b7420ff2262bb
libxl: Factorize function libxl_device_disk_list

This patch adds function libxl_append_disk_list_of_type to get disks
parameter of one backend type.

Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Committed-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/libxl/libxl.c |  107 ++++++++++++++++++++++++++--------------------------
 1 files changed, 54 insertions(+), 53 deletions(-)

diff -r 4e120cb427f4 -r 2c487c02d8d7 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Thu Jan 06 17:37:00 2011 +0000
+++ b/tools/libxl/libxl.c       Thu Jan 06 18:03:11 2011 +0000
@@ -2495,61 +2495,62 @@ int libxl_device_vkb_hard_shutdown(libxl
     return ERROR_NI;
 }
 
+static unsigned int libxl_append_disk_list_of_type(libxl_ctx *ctx,
+                                                   uint32_t domid,
+                                                   const char *type,
+                                                   libxl_device_disk **disks,
+                                                   unsigned int *ndisks)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    char *be_path = NULL;
+    char **dir = NULL;
+    unsigned int n = 0, len = 0;
+    libxl_device_disk *pdisk = NULL, *pdisk_end = NULL;
+    char *physpath_tmp = NULL;
+
+    be_path = libxl__sprintf(&gc, "%s/backend/%s/%d",
+                             libxl__xs_get_dompath(&gc, 0), type, domid);
+    dir = libxl__xs_directory(&gc, XBT_NULL, be_path, &n);
+    if (dir) {
+        *disks = realloc(*disks, sizeof (libxl_device_disk) * (*ndisks + n));
+        pdisk = *disks + *ndisks;
+        *ndisks += n;
+        pdisk_end = *disks + *ndisks;
+        for (; pdisk < pdisk_end; pdisk++, dir++) {
+            pdisk->backend_domid = 0;
+            pdisk->domid = domid;
+            physpath_tmp = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, 
"%s/%s/params", be_path, *dir), &len);
+            if (strchr(physpath_tmp, ':')) {
+                pdisk->physpath = strdup(strchr(physpath_tmp, ':') + 1);
+                free(physpath_tmp);
+            } else {
+                pdisk->physpath = physpath_tmp;
+            }
+            libxl_string_to_phystype(ctx, libxl__xs_read(&gc, XBT_NULL, 
libxl__sprintf(&gc, "%s/%s/type", be_path, *dir)), &(pdisk->phystype));
+            pdisk->virtpath = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, 
"%s/%s/dev", be_path, *dir), &len);
+            pdisk->unpluggable = atoi(libxl__xs_read(&gc, XBT_NULL, 
libxl__sprintf(&gc, "%s/%s/removable", be_path, *dir)));
+            if (!strcmp(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, 
"%s/%s/mode", be_path, *dir)), "w"))
+                pdisk->readwrite = 1;
+            else
+                pdisk->readwrite = 0;
+            type = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, 
"%s/device-type", libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, 
"%s/%s/frontend", be_path, *dir))));
+            pdisk->is_cdrom = !strcmp(type, "cdrom");
+        }
+    }
+
+    libxl__free_all(&gc);
+    return n;
+}
+
 libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int 
*num)
 {
-    libxl__gc gc = LIBXL_INIT_GC(ctx);
-    char *be_path_tap, *be_path_vbd;
-    libxl_device_disk *dend, *disks, *ret = NULL;
-    char **b, **l = NULL;
-    unsigned int numl, len;
-    char *type;
-
-    be_path_vbd = libxl__sprintf(&gc, "%s/backend/vbd/%d", 
libxl__xs_get_dompath(&gc, 0), domid);
-    be_path_tap = libxl__sprintf(&gc, "%s/backend/tap/%d", 
libxl__xs_get_dompath(&gc, 0), domid);
-
-    b = l = libxl__xs_directory(&gc, XBT_NULL, be_path_vbd, &numl);
-    if (l) {
-        ret = realloc(ret, sizeof(libxl_device_disk) * numl);
-        disks = ret;
-        *num = numl;
-        dend = ret + *num;
-        for (; disks < dend; ++disks, ++l) {
-            disks->backend_domid = 0;
-            disks->domid = domid;
-            disks->physpath = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, 
"%s/%s/params", be_path_vbd, *l), &len);
-            libxl_string_to_phystype(ctx, libxl__xs_read(&gc, XBT_NULL, 
libxl__sprintf(&gc, "%s/%s/type", be_path_vbd, *l)), &(disks->phystype));
-            disks->virtpath = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, 
"%s/%s/dev", be_path_vbd, *l), &len);
-            disks->unpluggable = atoi(libxl__xs_read(&gc, XBT_NULL, 
libxl__sprintf(&gc, "%s/%s/removable", be_path_vbd, *l)));
-            if (!strcmp(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, 
"%s/%s/mode", be_path_vbd, *l)), "w"))
-                disks->readwrite = 1;
-            else
-                disks->readwrite = 0;
-            type = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, 
"%s/device-type", libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, 
"%s/%s/frontend", be_path_vbd, *l))));
-            disks->is_cdrom = !strcmp(type, "cdrom");
-        }
-    }
-    b = l = libxl__xs_directory(&gc, XBT_NULL, be_path_tap, &numl);
-    if (l) {
-        ret = realloc(ret, sizeof(libxl_device_disk) * (*num + numl));
-        disks = ret + *num;
-        *num += numl;
-        for (dend = ret + *num; disks < dend; ++disks, ++l) {
-            disks->backend_domid = 0;
-            disks->domid = domid;
-            disks->physpath = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, 
"%s/%s/params", be_path_tap, *l), &len);
-            libxl_string_to_phystype(ctx, libxl__xs_read(&gc, XBT_NULL, 
libxl__sprintf(&gc, "%s/%s/type", be_path_tap, *l)), &(disks->phystype));
-            disks->virtpath = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, 
"%s/%s/dev", be_path_tap, *l), &len);
-            disks->unpluggable = atoi(libxl__xs_read(&gc, XBT_NULL, 
libxl__sprintf(&gc, "%s/%s/removable", be_path_tap, *l)));
-            if (!strcmp(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, 
"%s/%s/mode", be_path_tap, *l)), "w"))
-                disks->readwrite = 1;
-            else
-                disks->readwrite = 0;
-            type = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, 
"%s/device-type", libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, 
"%s/%s/frontend", be_path_tap, *l))));
-            disks->is_cdrom = !strcmp(type, "cdrom");
-        }
-    }
-    libxl__free_all(&gc);
-    return ret;
+    libxl_device_disk *disks = NULL;
+    unsigned int ndisks = 0;
+
+    *num = libxl_append_disk_list_of_type(ctx, domid, "vbd", &disks, &ndisks);
+    *num += libxl_append_disk_list_of_type(ctx, domid, "tap", &disks, &ndisks);
+
+    return disks;
 }
 
 int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid,

_______________________________________________
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: Factorize function libxl_device_disk_list, Xen patchbot-unstable <=