[libvirt] [PATCH RFC 3/3] undefine: Add coresponding switches to virsh, for removing storage devices associated with domain

Peter Krempa pkrempa at redhat.com
Thu Jul 21 15:12:16 UTC 2011


Adds switches for the virsh command "undefine", for managing removal of associated storage devices
for the undefined domain.

--remove-unmanaged-disks - removes only disk images, that aren't a part of any libvirt storage pool.
Only file-based storage devices are removed.

--remove-managed-disks - removes only libvirt managed storage devices

--remove-all-disks - removes both managed and unmanaged storage devices
---
 tools/virsh.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index ca92f0c..9d2808f 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1421,6 +1421,9 @@ static const vshCmdInfo info_undefine[] = {
 static const vshCmdOptDef opts_undefine[] = {
     {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name or uuid")},
     {"managed-save", VSH_OT_BOOL, 0, N_("remove domain managed state file")},
+    {"remove-unmanaged-disks", VSH_OT_BOOL, 0, N_("remove unmanaged storage images")},
+    {"remove-managed-disks", VSH_OT_BOOL, 0, N_("remove disks managed in storage pools")},
+    {"remove-all-disks", VSH_OT_BOOL, 0, N_("remove all disks associated with the undefined domain")},
     {NULL, 0, 0, NULL}
 };

@@ -1433,13 +1436,25 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
     int id;
     int flags = 0;
     int managed_save = vshCommandOptBool(cmd, "managed-save");
+    int remove_unmanaged_disks = vshCommandOptBool(cmd, "remove-unmanaged-disks");
+    int remove_backend_disks = vshCommandOptBool(cmd, "remove-managed-disks");
+    int remove_all_disks = vshCommandOptBool(cmd, "remove-all-disks");
     int has_managed_save = 0;
     int rc = -1;

     if (managed_save)
         flags |= VIR_DOMAIN_UNDEFINE_MANAGED_SAVE;

-    if (!managed_save)
+    if (remove_unmanaged_disks || remove_all_disks)
+        flags |= VIR_DOMAIN_UNDEFINE_DISK_FILE;
+
+    if (remove_backend_disks || remove_all_disks)
+        flags |= VIR_DOMAIN_UNDEFINE_DISK_BACKEND;
+
+    if (!managed_save &&
+        !remove_unmanaged_disks &&
+        !remove_backend_disks &&
+        !remove_all_disks)
         flags = -1;

     if (!vshConnectionUsability(ctl, ctl->conn))
-- 
1.7.6




More information about the libvir-list mailing list