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 code to construct disk fr

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] libxl: refactor code to construct disk from xenstore backend
From: Xen patchbot-unstable <patchbot@xxxxxxx>
Date: Tue, 01 Nov 2011 23:55:11 +0000
Delivery-date: Tue, 01 Nov 2011 16:55:55 -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 1318930556 -3600
# Node ID f2a50026376cb070df4f2023520395ebb722b41c
# Parent  444fb1a6e8036108aaf7e2dfbe927752a22a525d
libxl: refactor code to construct disk from xenstore backend

Temporarily retain unsafe behaviour of reading f.e. directory.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
Acked-by: Ian Jackson <ian.jackson.citrix.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
---


diff -r 444fb1a6e803 -r f2a50026376c tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Tue Oct 18 10:35:55 2011 +0100
+++ b/tools/libxl/libxl.c       Tue Oct 18 10:35:56 2011 +0100
@@ -1505,24 +1505,69 @@
     return ERROR_NI;
 }
 
+static void libxl__device_disk_from_xs_be(libxl__gc *gc,
+                                          const char *be_path,
+                                          libxl_device_disk *disk)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    unsigned int len;
+    char *tmp;
+    const char *fe_path; /* XXX unsafe */
+
+    memset(disk, 0, sizeof(*disk));
+
+    tmp = xs_read(ctx->xsh, XBT_NULL,
+                  libxl__sprintf(gc, "%s/params", be_path), &len);
+    if (tmp && strchr(tmp, ':')) {
+        disk->pdev_path = strdup(strchr(tmp, ':') + 1);
+        free(tmp);
+    } else {
+        disk->pdev_path = tmp;
+    }
+    libxl_string_to_backend(ctx,
+                        libxl__xs_read(gc, XBT_NULL,
+                                       libxl__sprintf(gc, "%s/type", be_path)),
+                        &(disk->backend));
+    disk->vdev = xs_read(ctx->xsh, XBT_NULL,
+                         libxl__sprintf(gc, "%s/dev", be_path), &len);
+    tmp = libxl__xs_read(gc, XBT_NULL, libxl__sprintf
+                         (gc, "%s/removable", be_path));
+
+    if (tmp)
+        disk->removable = atoi(tmp);
+    else
+        disk->removable = 0;
+
+    tmp = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/mode", be_path));
+    if (!strcmp(tmp, "w"))
+        disk->readwrite = 1;
+    else
+        disk->readwrite = 0;
+
+    fe_path = libxl__xs_read(gc, XBT_NULL,
+                             libxl__sprintf(gc, "%s/frontend", be_path));
+    tmp = libxl__xs_read(gc, XBT_NULL,
+                         libxl__sprintf(gc, "%s/device-type", fe_path));
+    disk->is_cdrom = !strcmp(tmp, "cdrom");
+
+    disk->format = LIBXL_DISK_FORMAT_UNKNOWN;
+}
+
 static int libxl__append_disk_list_of_type(libxl__gc *gc,
                                            uint32_t domid,
                                            const char *type,
                                            libxl_device_disk **disks,
                                            int *ndisks)
 {
-    libxl_ctx *ctx = libxl__gc_owner(gc);
     char *be_path = NULL;
     char **dir = NULL;
-    unsigned int n = 0, len = 0;
+    unsigned int n = 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) {
-        char *removable;
         libxl_device_disk *tmp;
         tmp = realloc(*disks, sizeof (libxl_device_disk) * (*ndisks + n));
         if (tmp == NULL)
@@ -1532,32 +1577,10 @@
         *ndisks += n;
         pdisk_end = *disks + *ndisks;
         for (; pdisk < pdisk_end; pdisk++, dir++) {
-            memset(pdisk, 0, sizeof(*pdisk));
+            const char *p;
+            p = libxl__sprintf(gc, "%s/%s", be_path, *dir);
+            libxl__device_disk_from_xs_be(gc, p, pdisk);
             pdisk->backend_domid = 0;
-            physpath_tmp = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(gc, 
"%s/%s/params", be_path, *dir), &len);
-            if (physpath_tmp && strchr(physpath_tmp, ':')) {
-                pdisk->pdev_path = strdup(strchr(physpath_tmp, ':') + 1);
-                free(physpath_tmp);
-            } else {
-                pdisk->pdev_path = physpath_tmp;
-            }
-            libxl_string_to_backend(ctx, libxl__xs_read(gc, XBT_NULL,
-                libxl__sprintf(gc, "%s/%s/type", be_path, *dir)),
-                &(pdisk->backend));
-            pdisk->vdev = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(gc, 
"%s/%s/dev", be_path, *dir), &len);
-            removable = libxl__xs_read(gc, XBT_NULL, libxl__sprintf
-                                       (gc, "%s/%s/removable", be_path, *dir));
-            if (removable)
-                pdisk->removable = atoi(removable);
-            else
-                pdisk->removable = 0;
-            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");
-            pdisk->format = LIBXL_DISK_FORMAT_UNKNOWN;
         }
     }
     return 0;

_______________________________________________
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 code to construct disk from xenstore backend, Xen patchbot-unstable <=