render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c401cc
From ee718f7ae1a1af66654416219f906e9e1a651e14 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <ee718f7ae1a1af66654416219f906e9e1a651e14@dist-git>
c401cc
From: Peter Krempa <pkrempa@redhat.com>
c401cc
Date: Wed, 26 Feb 2014 14:55:12 +0100
c401cc
Subject: [PATCH] virsh: domain: Fix undefine with storage of 'volume' disks
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
c401cc
c401cc
The undefine code that removes the storage along with the VM didn't take
c401cc
into account the existence of 'volume' type disks. Add the functionality.
c401cc
c401cc
(cherry picked from commit ef56cc43d1e2dd7e8fd8f5b9cb11c7a7b9ba65b3)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 tools/virsh-domain.c | 36 ++++++++++++++++++++++++++++++++++--
c401cc
 1 file changed, 34 insertions(+), 2 deletions(-)
c401cc
c401cc
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
c401cc
index 724ec1a..03f96fb 100644
c401cc
--- a/tools/virsh-domain.c
c401cc
+++ b/tools/virsh-domain.c
c401cc
@@ -2941,6 +2941,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
c401cc
     int nvol_nodes;
c401cc
     char *source = NULL;
c401cc
     char *target = NULL;
c401cc
+    char *pool = NULL;
c401cc
     size_t i;
c401cc
     size_t j;
c401cc
 
c401cc
@@ -3050,6 +3051,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
c401cc
             vshUndefineVolume vol;
c401cc
             VIR_FREE(source);
c401cc
             VIR_FREE(target);
c401cc
+            VIR_FREE(pool);
c401cc
 
c401cc
             /* get volume source and target paths */
c401cc
             if (!(target = virXPathString("string(./target/@dev)", ctxt)))
c401cc
@@ -3059,9 +3061,12 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
c401cc
                                           "./source/@file|"
c401cc
                                           "./source/@dir|"
c401cc
                                           "./source/@name|"
c401cc
-                                          "./source/@dev)", ctxt)))
c401cc
+                                          "./source/@dev|"
c401cc
+                                          "./source/@volume)", ctxt)))
c401cc
                 continue;
c401cc
 
c401cc
+            pool = virXPathString("string(./source/@pool)", ctxt);
c401cc
+
c401cc
             /* lookup if volume was selected by user */
c401cc
             if (vol_list) {
c401cc
                 bool found = false;
c401cc
@@ -3077,7 +3082,33 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
c401cc
                     continue;
c401cc
             }
c401cc
 
c401cc
-            if (!(vol.vol = virStorageVolLookupByPath(ctl->conn, source))) {
c401cc
+            if (pool) {
c401cc
+                virStoragePoolPtr storagepool = NULL;
c401cc
+
c401cc
+                if (!source) {
c401cc
+                    vshPrint(ctl,
c401cc
+                             _("Missing storage volume name for disk '%s'"),
c401cc
+                             target);
c401cc
+                    continue;
c401cc
+                }
c401cc
+
c401cc
+                if (!(storagepool = virStoragePoolLookupByName(ctl->conn,
c401cc
+                                                               pool))) {
c401cc
+                    vshPrint(ctl,
c401cc
+                             _("Storage pool '%s' for volume '%s' not found."),
c401cc
+                             pool, target);
c401cc
+                    vshResetLibvirtError();
c401cc
+                    continue;
c401cc
+                }
c401cc
+
c401cc
+                vol.vol = virStorageVolLookupByName(storagepool, source);
c401cc
+                virStoragePoolFree(storagepool);
c401cc
+
c401cc
+            } else {
c401cc
+               vol.vol = virStorageVolLookupByPath(ctl->conn, source);
c401cc
+            }
c401cc
+
c401cc
+            if (!vol.vol) {
c401cc
                 vshPrint(ctl,
c401cc
                          _("Storage volume '%s'(%s) is not managed by libvirt. "
c401cc
                            "Remove it manually.\n"), target, source);
c401cc
@@ -3192,6 +3223,7 @@ out:
c401cc
 cleanup:
c401cc
     VIR_FREE(source);
c401cc
     VIR_FREE(target);
c401cc
+    VIR_FREE(pool);
c401cc
     for (i = 0; i < nvols; i++) {
c401cc
         VIR_FREE(vols[i].source);
c401cc
         VIR_FREE(vols[i].target);
c401cc
-- 
c401cc
1.9.0
c401cc