[gnome-boxes/gnome-3-26] libvirt-machine-props: Allow resize of disk w/ snapshots



commit 1c61d1b68399a0af8531ff2149003a7fc3cf4df5
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Fri Apr 1 23:53:44 2016 +0100

    libvirt-machine-props: Allow resize of disk w/ snapshots
    
    Since it is currently not possible to resize a disk image if it has
    snapshots on it, resize operation ends up not working with a warning on
    the console. Let's fix that by deleting all associated snapshots before
    attempting to resize the disk image but not before notifying user about
    what we are about to do.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=756140

 src/libvirt-machine-properties.vala |   44 +++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/src/libvirt-machine-properties.vala b/src/libvirt-machine-properties.vala
index 8b99121..1cc49cd 100644
--- a/src/libvirt-machine-properties.vala
+++ b/src/libvirt-machine-properties.vala
@@ -523,6 +523,36 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
         if (machine.storage_volume == null)
             return;
 
+        List<GVir.DomainSnapshot> snapshots;
+        try {
+            snapshots = yield get_snapshots (null);
+        } catch (GLib.Error e) {
+            warning ("Error fetching snapshots for %s: %s", machine.name, e.message);
+            snapshots = new List<GVir.DomainSnapshot> ();
+        }
+
+        var num_snapshots = snapshots.length ();
+        if (num_snapshots != 0) {
+            // qemu-img doesn't support resizing disk image with snapshots:
+            // https://bugs.launchpad.net/qemu/+bug/1563931
+            var msg = ngettext ("Storage resize requires deleting associated snapshot.",
+                                "Storage resize requires deleting %llu associated snapshots.",
+                                num_snapshots).printf (num_snapshots);
+
+            Notification.OKFunc undo = () => {
+                debug ("Storage resize of '%s' cancelled by user.", machine.name);
+            };
+
+            Notification.DismissFunc really_resize = () => {
+                debug ("User did not cancel storage resize of '%s'. Deleting all snapshots..", machine.name);
+                force_change_storage_size.begin (property, value);
+            };
+
+            machine.window.notificationbar.display_for_action (msg, _("_Undo"), (owned) undo, (owned) 
really_resize);
+
+            return;
+        }
+
         try {
             if (machine.is_running) {
                 var disk = machine.get_domain_disk ();
@@ -555,6 +585,20 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
         }
     }
 
+    private async void force_change_storage_size (Boxes.Property property, uint64 value) {
+        try {
+            var snapshots = yield get_snapshots (null);
+
+            foreach (var snapshot in snapshots) {
+                yield snapshot.delete_async (0, null);
+            }
+
+            change_storage_size.begin (property, value);
+        } catch (GLib.Error e) {
+            warning ("Error while deleting snapshots: %s", e.message);
+        }
+    }
+
     private uint64 get_minimum_disk_size () throws GLib.Error {
         var volume_info = machine.storage_volume.get_info ();
         if (machine.vm_creator == null) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]