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

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

 



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@xxxxxxxxxxxxxx>
---
 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]