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

[Xen-changelog] [xen-unstable] libxl: add function to attach/detach a disk to/from the local VM



# HG changeset patch
# User Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
# Date 1279122258 -3600
# Node ID cb1ca77e4b77728d7c76d8524644f6d47f868b30
# Parent  df18254561b27fe8cad6fc8a37fefa5e14cf6fb2
libxl: add function to attach/detach a disk to/from the local VM

Useful if you need to read a guest filesystem (e.g. pygrub).

I'm not overly thrilled with the implementation WRT tap interfaces,
particularly WRT to detach. I was unable to find a way to get at the
paramters necessary to call tap_ctl_destroy so I assumed for now it
that is OK to assume that the tap device is going to be wanted for the
actual domain at some point in the immediate future and hence there is
no pressing need to destroy it.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
 tools/libxl/libxl.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl.h |    6 ++++++
 2 files changed, 48 insertions(+)

diff -r df18254561b2 -r cb1ca77e4b77 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Wed Jul 14 16:43:49 2010 +0100
+++ b/tools/libxl/libxl.c       Wed Jul 14 16:44:18 2010 +0100
@@ -1423,6 +1423,48 @@ int libxl_device_disk_del(struct libxl_c
     device.devid            = devid;
     device.kind             = DEVICE_VBD;
     return libxl_device_del(ctx, &device, wait);
+}
+
+const char * libxl_device_disk_local_attach(struct libxl_ctx *ctx, 
libxl_device_disk *disk)
+{
+    char *dev = NULL;
+    int phystype = disk->phystype;
+    switch (phystype) {
+        case PHYSTYPE_PHY: {
+            fprintf(stderr, "attaching PHY disk %s to domain 0\n", 
disk->physpath);
+            dev = disk->physpath;
+            break;
+        }
+        case PHYSTYPE_FILE:
+            /* let's pretend is tap:aio for the moment */
+            phystype = PHYSTYPE_AIO;
+        case PHYSTYPE_AIO: case PHYSTYPE_QCOW: case PHYSTYPE_QCOW2: case 
PHYSTYPE_VHD: {
+            const char *msg;
+            if (!tap_ctl_check(&msg)) {
+                const char *type = device_disk_string_of_phystype(phystype);
+                dev = get_blktap2_device(ctx, disk->physpath, type);
+                if (!dev)
+                    dev = make_blktap2_device(ctx, disk->physpath, type);
+            }
+            break;
+        }
+        default:
+            XL_LOG(ctx, XL_LOG_ERROR, "unrecognized disk physical type: %d\n", 
phystype);
+            break;
+    }
+    return dev;
+}
+
+int libxl_device_disk_local_detach(struct libxl_ctx *ctx, libxl_device_disk 
*disk)
+{
+    /* Nothing to do for PHYSTYPE_PHY. */
+
+    /*
+     * For other device types assume that the blktap2 process is
+     * needed by the soon to be started domain and do nothing.
+     */
+
+    return 0;
 }
 
 
/******************************************************************************/
diff -r df18254561b2 -r cb1ca77e4b77 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Wed Jul 14 16:43:49 2010 +0100
+++ b/tools/libxl/libxl.h       Wed Jul 14 16:44:18 2010 +0100
@@ -423,6 +423,12 @@ int libxl_device_disk_getinfo(struct lib
                               libxl_device_disk *disk, libxl_diskinfo 
*diskinfo);
 int libxl_cdrom_insert(struct libxl_ctx *ctx, uint32_t domid, 
libxl_device_disk *disk);
 
+/*
+ * Make a disk available in this domain. Returns path to a device.
+ */
+const char * libxl_device_disk_local_attach(struct libxl_ctx *ctx, 
libxl_device_disk *disk);
+int libxl_device_disk_local_detach(struct libxl_ctx *ctx, libxl_device_disk 
*disk);
+
 typedef struct {
     char *backend;
     uint32_t backend_id;

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


 


Rackspace

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