[libvirt] [PATCH] virsh: Parse "--mode readonly, shareable" in virsh attach-disk.

Dongsheng Yang dongsheng081251 at gmail.com
Sun Jun 15 09:48:31 UTC 2014


We can not attach a disk with mode of both readonly and shareable.
Before:
	# virsh attach-disk --domain jeos --source attach.img --target vdb --persistent --mode readonly --mode shareable
	error: option --mode already seen
	# virsh attach-disk --domain jeos --source attach.img --target vdb --persistent --mode readonly --shareable
	error: option --mode already seen
	# virsh attach-disk --domain jeos --source attach.img --target vdb --persistent --mode readonly,shareable
	error: No support for readonly,shareable in command 'attach-disk'
After:
	# virsh attach-disk --domain jeos --source attach.img --target vdb --persistent --mode readonly,shareable
	Disk attached successfully

Signed-off-by: Dongsheng Yang <yangds.fnst at cn.fujitsu.com>
---
 tools/virsh-domain.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 6b3dd70..62a9824 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -515,6 +515,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
     bool config = vshCommandOptBool(cmd, "config");
     bool live = vshCommandOptBool(cmd, "live");
     bool persistent = vshCommandOptBool(cmd, "persistent");
+    char **modes = NULL, **tmp;
 
     VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current);
 
@@ -553,12 +554,9 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
-    if (mode) {
-        if (STRNEQ(mode, "readonly") && STRNEQ(mode, "shareable")) {
-            vshError(ctl, _("No support for %s in command 'attach-disk'"),
-                     mode);
-            goto cleanup;
-        }
+    if (mode && !(modes = virStringSplit(mode, ",", 0))) {
+        vshError(ctl, "%s", _("Cannot parse mode string"));
+        goto cleanup;
     }
 
     if (wwn && !virValidateWWN(wwn))
@@ -591,8 +589,19 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
         virBufferAsprintf(&buf, "<source %s='%s'/>\n",
                           isFile ? "file" : "dev", source);
     virBufferAsprintf(&buf, "<target dev='%s'/>\n", target);
-    if (mode)
-        virBufferAsprintf(&buf, "<%s/>\n", mode);
+
+    tmp = modes;
+    while (tmp && *tmp) {
+        mode = *tmp;
+        if (STREQ(mode, "readonly") || STREQ(mode, "shareable")) {
+            virBufferAsprintf(&buf, "<%s/>\n", mode);
+        } else {
+            vshError(ctl, _("Unknown mode %s value, expecting "
+                            "'readonly', 'shareable'"), mode);
+            goto cleanup;
+        }
+        tmp++;
+    }
 
     if (serial)
         virBufferAsprintf(&buf, "<serial>%s</serial>\n", serial);
-- 
1.8.3.1




More information about the libvir-list mailing list