Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > ebe084c140192657f9094e135a84202c > files > 148

libvirt-0.8.2-29.el5.src.rpm

From 38b52ed025e71614b32efaaf2423f4c0c9ef1d60 Mon Sep 17 00:00:00 2001
Message-Id: <38b52ed025e71614b32efaaf2423f4c0c9ef1d60.1284409901.git.jdenemar@redhat.com>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Fri, 10 Sep 2010 13:37:55 +0200
Subject: [PATCH] virsh: Option for overriding disk type in attach-disk

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=609422

Unless --driver tap|file option was given to attach-disk, virsh would
generate <disk type='block'> XML which might be fine for Xen but not for
other hypervisors. This patch introduces a new option --sourcetype which
can be used to explicitly set the type of disk source. The option
accepts either "file" or "block" types.
(cherry picked from commit dfec22cc6035a95ff1c7609ea060029cb99182cc)
---
 tools/virsh.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 55685dd..515e558 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -7880,6 +7880,7 @@ static const vshCmdOptDef opts_attach_disk[] = {
     {"type",    VSH_OT_STRING, 0, N_("target device type")},
     {"mode",    VSH_OT_STRING, 0, N_("mode of device reading and writing")},
     {"persistent", VSH_OT_BOOL, 0, N_("persist disk attachment")},
+    {"sourcetype", VSH_OT_STRING, 0, N_("type of source (block|file)")},
     {NULL, 0, 0, NULL}
 };
 
@@ -7891,6 +7892,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
     int isFile = 0, ret = FALSE;
     char *buf = NULL, *tmp = NULL;
     unsigned int flags;
+    char *stype;
 
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         goto cleanup;
@@ -7908,10 +7910,16 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
     subdriver = vshCommandOptString(cmd, "subdriver", NULL);
     type = vshCommandOptString(cmd, "type", NULL);
     mode = vshCommandOptString(cmd, "mode", NULL);
+    stype = vshCommandOptString(cmd, "sourcetype", NULL);
 
-    if (driver) {
-        if (STREQ(driver, "file") || STREQ(driver, "tap"))
+    if (!stype) {
+        if (driver && (STREQ(driver, "file") || STREQ(driver, "tap")))
             isFile = 1;
+    } else if (STREQ(stype, "file")) {
+        isFile = 1;
+    } else if (STRNEQ(stype, "block")) {
+        vshError(ctl, _("Unknown source type: '%s'"), stype);
+        goto cleanup;
     }
 
     if (mode) {
-- 
1.7.2.2