]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Don't generate invalid XML in attach-disk command
authorPeter Krempa <pkrempa@redhat.com>
Wed, 13 Jun 2012 14:55:51 +0000 (16:55 +0200)
committerCole Robinson <crobinso@redhat.com>
Thu, 14 Jun 2012 22:38:27 +0000 (18:38 -0400)
The attach-disk command used with parameter --cache created an invalid
XML snippet as the beginning of the <driver> element was not printed
when used solely with --cache and no other attribute to driver.
(cherry picked from commit 5b4740265cf1e9cd00165e54e1f5e81f9008bc63)

tools/virsh.c

index 7307ccb5caf5c270fae68aca9d31ceb2c07e4bae..fd1acbbcb2ffa78890b4d8e57925c31990f5eaf6 100644 (file)
@@ -14493,18 +14493,18 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
         virBufferAddLit(&buf, " rawio='yes'");
     virBufferAddLit(&buf, ">\n");
 
-    if (driver || subdriver)
+    if (driver || subdriver || cache) {
         virBufferAsprintf(&buf, "  <driver");
 
-    if (driver)
-        virBufferAsprintf(&buf, " name='%s'", driver);
-    if (subdriver)
-        virBufferAsprintf(&buf, " type='%s'", subdriver);
-    if (cache)
-        virBufferAsprintf(&buf, " cache='%s'", cache);
+        if (driver)
+            virBufferAsprintf(&buf, " name='%s'", driver);
+        if (subdriver)
+            virBufferAsprintf(&buf, " type='%s'", subdriver);
+        if (cache)
+            virBufferAsprintf(&buf, " cache='%s'", cache);
 
-    if (driver || subdriver || cache)
         virBufferAddLit(&buf, "/>\n");
+    }
 
     if (source)
         virBufferAsprintf(&buf, "  <source %s='%s'/>\n",