render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From ee718f7ae1a1af66654416219f906e9e1a651e14 Mon Sep 17 00:00:00 2001
Message-Id: <ee718f7ae1a1af66654416219f906e9e1a651e14@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 26 Feb 2014 14:55:12 +0100
Subject: [PATCH] virsh: domain: Fix undefine with storage of 'volume' disks

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

The undefine code that removes the storage along with the VM didn't take
into account the existence of 'volume' type disks. Add the functionality.

(cherry picked from commit ef56cc43d1e2dd7e8fd8f5b9cb11c7a7b9ba65b3)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 tools/virsh-domain.c | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 724ec1a..03f96fb 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -2941,6 +2941,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
     int nvol_nodes;
     char *source = NULL;
     char *target = NULL;
+    char *pool = NULL;
     size_t i;
     size_t j;
 
@@ -3050,6 +3051,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
             vshUndefineVolume vol;
             VIR_FREE(source);
             VIR_FREE(target);
+            VIR_FREE(pool);
 
             /* get volume source and target paths */
             if (!(target = virXPathString("string(./target/@dev)", ctxt)))
@@ -3059,9 +3061,12 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
                                           "./source/@file|"
                                           "./source/@dir|"
                                           "./source/@name|"
-                                          "./source/@dev)", ctxt)))
+                                          "./source/@dev|"
+                                          "./source/@volume)", ctxt)))
                 continue;
 
+            pool = virXPathString("string(./source/@pool)", ctxt);
+
             /* lookup if volume was selected by user */
             if (vol_list) {
                 bool found = false;
@@ -3077,7 +3082,33 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
                     continue;
             }
 
-            if (!(vol.vol = virStorageVolLookupByPath(ctl->conn, source))) {
+            if (pool) {
+                virStoragePoolPtr storagepool = NULL;
+
+                if (!source) {
+                    vshPrint(ctl,
+                             _("Missing storage volume name for disk '%s'"),
+                             target);
+                    continue;
+                }
+
+                if (!(storagepool = virStoragePoolLookupByName(ctl->conn,
+                                                               pool))) {
+                    vshPrint(ctl,
+                             _("Storage pool '%s' for volume '%s' not found."),
+                             pool, target);
+                    vshResetLibvirtError();
+                    continue;
+                }
+
+                vol.vol = virStorageVolLookupByName(storagepool, source);
+                virStoragePoolFree(storagepool);
+
+            } else {
+               vol.vol = virStorageVolLookupByPath(ctl->conn, source);
+            }
+
+            if (!vol.vol) {
                 vshPrint(ctl,
                          _("Storage volume '%s'(%s) is not managed by libvirt. "
                            "Remove it manually.\n"), target, source);
@@ -3192,6 +3223,7 @@ out:
 cleanup:
     VIR_FREE(source);
     VIR_FREE(target);
+    VIR_FREE(pool);
     for (i = 0; i < nvols; i++) {
         VIR_FREE(vols[i].source);
         VIR_FREE(vols[i].target);
-- 
1.9.0