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

[Xen-devel] [PATCH 28 of 29 RFC] libxl: add libxl__find_free_vdev



# HG changeset patch
# User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
# Date 1328189112 -3600
# Node ID 35164add2785b8606c0e9b771206d83862afd2c6
# Parent  42bd734ce75d232194372c329a9af9b73e9090fb
libxl: add libxl__find_free_vdev

Add a function that returns the first free xvd<x> device, used to
attach a DomU image and execute the bootloader against that.

Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>

diff -r 42bd734ce75d -r 35164add2785 tools/libxl/libxl_bootloader.c
--- a/tools/libxl/libxl_bootloader.c    Thu Feb 02 11:54:58 2012 +0100
+++ b/tools/libxl/libxl_bootloader.c    Thu Feb 02 14:25:12 2012 +0100
@@ -318,6 +318,39 @@ static void parse_bootloader_result(libx
     }
 }
 
+static char *libxl__find_free_vdev(libxl__gc *gc)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    char *vdev;
+    libxl_device_disk *list;
+    int num;
+    int used;
+
+    list = libxl_device_disk_list(ctx, 0, &num);
+    if (!list || num == 0) {
+        return "xvda";
+    }
+
+    for (char device = 'a'; device <= 'z'; device += 1) {
+        used = 0;
+        vdev = libxl__sprintf(gc, "xvd%c", device);
+        if (!vdev) {
+            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unable to allocate memory");
+            return NULL;
+        }
+        for (int i = 0; i < num; i++) {
+            if (strcmp(list[0].vdev, vdev) == 0) {
+                used = 1;
+                break;
+            }
+        }
+        if (!used)
+            return vdev;
+    }
+    LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unable to find a free device");
+    return NULL;
+}
+
 int libxl_run_bootloader(libxl_ctx *ctx,
                          libxl_domain_build_info *info,
                          libxl_device_disk *disk,
@@ -328,6 +361,7 @@ int libxl_run_bootloader(libxl_ctx *ctx,
     char *fifo = NULL;
     char *diskpath = NULL;
     char **args = NULL;
+    char *vdev_save = NULL;
 
     char tempdir_template[] = "/var/run/libxl/bl.XXXXXX";
     char *tempdir;
@@ -378,6 +412,11 @@ int libxl_run_bootloader(libxl_ctx *ctx,
         goto out_close;
     }
 
+    vdev_save = disk->vdev;
+    disk->vdev = libxl__find_free_vdev(gc);
+    if (!disk->vdev)
+        goto out_close;
+
     diskpath = libxl_device_disk_local_attach(ctx, disk);
     if (!diskpath) {
         goto out_close;
@@ -446,6 +485,8 @@ int libxl_run_bootloader(libxl_ctx *ctx,
 out_close:
     if (diskpath) {
         libxl_device_disk_local_detach(ctx, disk);
+        if (vdev_save)
+            disk->vdev = vdev_save;
         free(diskpath);
     }
     if (fifo_fd > -1)

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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.