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

[Xen-devel] [PATCH 6 of 6] xl: block-detach command

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 6 of 6] xl: block-detach command
From: Eric Chanudet <eric.chanudet@xxxxxxxxxx>
Date: Wed, 12 May 2010 18:32:14 +0100
Delivery-date: Wed, 12 May 2010 10:41:47 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1273685528@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1273685528@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.5.1
This patch adds block-detach command to xl.

Usage: xl block-detach <Domain> <DevId>

diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -430,3 +430,38 @@ int libxl_devid_to_device_nic(struct lib
     libxl_free(ctx, nic_path_be);
     return 0;
 }
+
+int libxl_devid_to_device_disk(struct libxl_ctx *ctx, uint32_t domid,
+                               const char *devid, libxl_device_disk *disk)
+{
+    char *endptr, *val;
+    char *dompath, *diskpath, *be_path;
+    unsigned int devid_n;
+
+    devid_n = strtoul(devid, &endptr, 10);
+    if (devid == endptr) {
+        return ERROR_INVAL;
+    }
+    dompath = libxl_xs_get_dompath(ctx, domid);
+    diskpath = libxl_sprintf(ctx, "%s/device/vbd/%s", dompath, devid);
+    if (!diskpath) {
+        return ERROR_FAIL;
+    }
+
+    val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/backend-id", 
diskpath));
+    disk->backend_domid = strtoul(val, NULL, 10);
+    disk->domid = domid;
+    be_path = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/backend", 
diskpath));
+    disk->physpath = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, 
"%s/params", be_path));
+    val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/type", be_path));
+    libxl_string_to_phystype(ctx, val, &(disk->phystype));
+    disk->virtpath = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/dev", 
be_path));
+    val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/removable", 
be_path));
+    disk->unpluggable = !strcmp(val, "1");
+    val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/mode", be_path));
+    disk->readwrite = !!strcmp(val, "w");
+    val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/device-type", 
diskpath));
+    disk->is_cdrom = !strcmp(val, "cdrom");
+
+    return 0;
+}
diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h
--- a/tools/libxl/libxl_utils.h
+++ b/tools/libxl/libxl_utils.h
@@ -61,6 +61,9 @@ int libxl_mac_to_device_nic(struct libxl
 int libxl_devid_to_device_nic(struct libxl_ctx *ctx, uint32_t domid,
                               const char *devid, libxl_device_nic *nic);
 
+int libxl_devid_to_device_disk(struct libxl_ctx *ctx, uint32_t domid,
+                               const char *devid, libxl_device_disk *disk);
+
 /* log levels: */
 #define XL_LOG_DEBUG 3
 #define XL_LOG_INFO 2
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -3348,3 +3348,37 @@ int main_blocklist(int argc, char **argv
     }
     exit(0);
 }
+
+int main_blockdetach(int argc, char **argv)
+{
+    int opt;
+    libxl_device_disk disk;
+
+    if (argc != 3) {
+        help("block-detach");
+        exit(0);
+    }
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+            help("block-detach");
+            exit(0);
+        default:
+            fprintf(stderr, "option `%c' not supported.\n", opt);
+            break;
+        }
+    }
+
+    if (domain_qualifier_to_domid(argv[1], &domid, 0) < 0) {
+        fprintf(stderr, "%s is an invalid domain identifier\n", argv[1]);
+        exit(1);
+    }
+    if (libxl_devid_to_device_disk(&ctx, domid, argv[2], &disk)) {
+        fprintf(stderr, "Error: Device %s not connected.\n", argv[2]);
+        exit(1);
+    }
+    if (libxl_device_disk_del(&ctx, &disk, 1)) {
+        fprintf(stderr, "libxl_device_del failed.\n");
+    }
+    exit(0);
+}
diff --git a/tools/libxl/xl_cmdimpl.h b/tools/libxl/xl_cmdimpl.h
--- a/tools/libxl/xl_cmdimpl.h
+++ b/tools/libxl/xl_cmdimpl.h
@@ -44,5 +44,6 @@ int main_networklist(int argc, char **ar
 int main_networkdetach(int argc, char **argv);
 int main_blockattach(int argc, char **argv);
 int main_blocklist(int argc, char **argv);
+int main_blockdetach(int argc, char **argv);
 
 void help(char *command);
diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c
+++ b/tools/libxl/xl_cmdtable.c
@@ -192,6 +192,10 @@ struct cmd_spec cmd_table[] = {
       &main_blocklist,
       "List virtual block devices for a domain"
     },
+    { "block-detach",
+      &main_blockdetach,
+      "Destroy a domain's virtual block device"
+    },
 };
 
 int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);

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