[gnome-boxes/wip/resize-snapshots2: 6/6] tmp



commit c5b2e6bffe3fc2200676c69deb1f837a69cfcfec
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Apr 6 15:50:52 2016 +0100

    tmp

 src/libvirt-machine-properties.vala |   37 +++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/src/libvirt-machine-properties.vala b/src/libvirt-machine-properties.vala
index 886fc0a..27a892a 100644
--- a/src/libvirt-machine-properties.vala
+++ b/src/libvirt-machine-properties.vala
@@ -609,6 +609,29 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
         if (machine.storage_volume == null)
             return;
 
+        var snapshots = get_snapshots ();
+        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 ();
@@ -641,6 +664,20 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
         }
     }
 
+    private async void force_change_storage_size (Boxes.Property property, uint64 value) {
+        try {
+            var snapshots = get_snapshots ();
+
+            foreach (var snapshot in snapshots)
+                yield snapshot.delete_async (0, null);
+            yield fetch_snapshots (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]