[libvirt] [PATCH 1/7] virsh: domain: Don't use vshPrepareDiskXML for creating XML to detach disk

Peter Krempa pkrempa at redhat.com
Thu Mar 12 17:09:53 UTC 2015


Since cmdDetachDisk() calls into vshPrepareDiskXML() with
type == VSH_PREPARE_DISK_XML_NONE && source == NULL this would result
into skipping all the checks and effectively turn the function into a
XML formatter.

This patch changes the code to use the formatter directly so that the
function can be refactored in a easier way.
---
 tools/virsh-domain.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 1a364bb..8bc0512 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -11365,9 +11365,10 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
     if (!(disk_node = vshFindDisk(doc, target, VSH_FIND_DISK_NORMAL)))
         goto cleanup;

-    if (!(disk_xml = vshPrepareDiskXML(disk_node, NULL, NULL,
-                                       VSH_PREPARE_DISK_XML_NONE)))
+    if (!(disk_xml = virXMLNodeToString(NULL, disk_node))) {
+        vshSaveLibvirtError();
         goto cleanup;
+    }

     if (flags != 0 || current)
         ret = virDomainDetachDeviceFlags(dom, disk_xml, flags);
-- 
2.2.2




More information about the libvir-list mailing list