[gnome-boxes] libvirt-machine-props: Allow shrinking volume in wizard
- From: Fabiano Fidêncio <ffidencio src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] libvirt-machine-props: Allow shrinking volume in wizard
- Date: Thu, 13 Mar 2014 21:42:05 +0000 (UTC)
commit a6aecaea51a7ae1fca3024738d1873db104c1a30
Author: Fabiano Fidêncio <fidencio redhat com>
Date: Wed Mar 12 19:49:36 2014 +0100
libvirt-machine-props: Allow shrinking volume in wizard
As the disk format used by Boxes (qcow2) doesn't support shrinking,
lets implement it by deleting the existing storage volume and creating
a new one using the disk size set by the user, when the user is
creating a new VM.
https://bugzilla.gnome.org/show_bug.cgi?id=700374
src/libvirt-machine-properties.vala | 43 +++++++++++++++++++++++++++++++++-
src/os-database.vala | 8 ++++++
2 files changed, 49 insertions(+), 2 deletions(-)
---
diff --git a/src/libvirt-machine-properties.vala b/src/libvirt-machine-properties.vala
index 4f534ea..7e697cf 100644
--- a/src/libvirt-machine-properties.vala
+++ b/src/libvirt-machine-properties.vala
@@ -466,7 +466,7 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
var property = add_size_property (ref list,
_("Maximum Disk Size"),
volume_info.capacity,
- volume_info.capacity,
+ get_minimum_disk_size (),
pool_info.available,
256 * MEGABYTES);
// Disable 'save on timeout' all together since that could lead us to very bad user experience:
@@ -517,7 +517,7 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
});
}
} else {
- machine.storage_volume.resize (value, StorageVolResizeFlags.NONE);
+ resize_storage_volume (value);
debug ("Storage changed to %llu", value);
}
} catch (GLib.Error error) {
@@ -530,4 +530,43 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
return false;
};
}
+
+ private uint64 get_minimum_disk_size () throws GLib.Error {
+ var volume_info = machine.storage_volume.get_info ();
+ if (machine.vm_creator == null) {
+ // Since we disable the properties during install going on we don't need to check for
+ // previous_ui_state here to be WIZARD.
+ return volume_info.capacity;
+ }
+
+ Osinfo.Resources minimum_resources = null;
+
+ if (machine.vm_creator.install_media.os != null) {
+ var os = machine.vm_creator.install_media.os;
+ var architecture = machine.domain_config.get_os ().get_arch ();
+ minimum_resources = OSDatabase.get_minimum_resources_for_os (os, architecture);
+ }
+
+ if (minimum_resources != null) {
+ return minimum_resources.storage;
+ } else {
+ var default_resources = OSDatabase.get_default_resources ();
+ return uint64.min (volume_info.capacity, default_resources.storage);
+ }
+ }
+
+ private void resize_storage_volume (uint64 size) throws GLib.Error {
+ var volume_info = machine.storage_volume.get_info ();
+ if (machine.vm_creator != null && size < volume_info.capacity) {
+ // New VM Customization
+ var config = machine.storage_volume.get_config (GVir.DomainXMLFlags.NONE);
+ config.set_capacity (size);
+ machine.storage_volume.delete (0);
+
+ var pool = get_storage_pool (machine.connection);
+ machine.storage_volume = pool.create_volume (config);
+ } else {
+ machine.storage_volume.resize (size, StorageVolResizeFlags.NONE);
+ }
+ }
}
diff --git a/src/os-database.vala b/src/os-database.vala
index 2d57331..e2f311b 100644
--- a/src/os-database.vala
+++ b/src/os-database.vala
@@ -176,6 +176,14 @@ private class Boxes.OSDatabase : GLib.Object {
return get_prefered_resources (list, prefs);
}
+ public static Resources? get_minimum_resources_for_os (Os os, string architecture) {
+ string[] prefs = { architecture, ARCHITECTURE_ALL };
+
+ var list = os.get_minimum_resources ();
+
+ return get_prefered_resources (list, prefs);
+ }
+
private Resources get_resources_from_os_resources (Resources? minimum, Resources? recommended) {
var resources = get_default_resources ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]