[gnome-boxes] libvirt-machine: Keep associated storage volume around
- From: Christophe Fergeau <teuf src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] libvirt-machine: Keep associated storage volume around
- Date: Mon, 3 Sep 2012 14:18:55 +0000 (UTC)
commit 7a4d759dcd6898f552246b5aff2b779ad67ab5a6
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Fri Aug 31 01:58:16 2012 +0300
libvirt-machine: Keep associated storage volume around
So that it can be just accessed directly instead of every piece of code
having to search it in storage pool all the time.
https://bugzilla.gnome.org/show_bug.cgi?id=672554
src/libvirt-machine.vala | 31 ++++++++++++-------------------
src/util-app.vala | 34 ++++++++++++++++++++++++++++++----
src/vm-creator.vala | 17 ++++++++---------
3 files changed, 50 insertions(+), 32 deletions(-)
---
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 40cae7a..1271231 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -6,7 +6,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
public GVir.Domain domain;
public GVirConfig.Domain domain_config;
public GVir.Connection connection;
- private string? storage_volume_path;
+ public GVir.StorageVol? storage_volume;
public VMCreator? vm_creator; // Under installation if this is set to non-null
public bool save_on_quit {
@@ -63,9 +63,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
private void update_domain_config () {
try {
domain_config = domain.get_config (GVir.DomainXMLFlags.NONE);
-
- var volume = get_storage_volume (connection, domain, null);
- storage_volume_path = (volume != null)? volume.get_path () : null;
+ storage_volume = get_storage_volume (connection, domain);
} catch (GLib.Error error) {
critical ("Failed to fetch configuration for domain '%s': %s", domain.get_name (), error.message);
}
@@ -391,9 +389,6 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
set_stats_enable (false);
if (by_user) {
- GVir.StorageVol? volume = null;
- if (connection == App.app.default_connection)
- volume = get_storage_volume (connection, domain, null);
var domain = this.domain; // Don't reference self in thread
/* Run all the slow operations in a separate thread
@@ -414,9 +409,9 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
}
// Remove any images controlled by boxes
- if (volume != null)
+ if (storage_volume != null)
try {
- volume.delete (0);
+ storage_volume.delete (0);
} catch (GLib.Error err) {
warning (err.message);
}
@@ -457,6 +452,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
if (device_config is GVirConfig.DomainDisk) {
var disk_config = device_config as GVirConfig.DomainDisk;
var disk_type = disk_config.get_guest_device_type ();
+ var storage_volume_path = (storage_volume != null)? storage_volume.get_path () : null;
// Prefer Boxes' managed volume over other disks
if (disk_type == GVirConfig.DomainDiskGuestDeviceType.DISK &&
@@ -594,14 +590,12 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
}
private void add_storage_property (ref List list) {
- StoragePool pool;
-
- var volume = get_storage_volume (connection, domain, out pool);
- if (volume == null)
+ if (storage_volume == null)
return;
try {
- var volume_info = volume.get_info ();
+ var volume_info = storage_volume.get_info ();
+ var pool = get_storage_pool (connection);
var pool_info = pool.get_info ();
var max_storage = (volume_info.capacity + pool_info.available) / Osinfo.KIBIBYTES;
@@ -614,7 +608,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
on_storage_changed);
} catch (GLib.Error error) {
warning ("Failed to get information on volume '%s' or it's parent pool: %s",
- volume.get_name (),
+ storage_volume.get_name (),
error.message);
}
}
@@ -625,8 +619,7 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
Source.remove (storage_update_timeout);
storage_update_timeout = Timeout.add_seconds (1, () => {
- var volume = get_storage_volume (connection, domain, null);
- if (volume == null)
+ if (storage_volume == null)
return false;
try {
@@ -636,11 +629,11 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
disk.resize (value, 0);
} else
// Currently this never happens as properties page cant be reached without starting the machine
- volume.resize (value * Osinfo.KIBIBYTES, StorageVolResizeFlags.NONE);
+ storage_volume.resize (value * Osinfo.KIBIBYTES, StorageVolResizeFlags.NONE);
debug ("Storage changed to %llu", value);
} catch (GLib.Error error) {
warning ("Failed to change storage capacity of volume '%s' to %llu: %s",
- volume.get_name (),
+ storage_volume.get_name (),
value,
error.message);
}
diff --git a/src/util-app.vala b/src/util-app.vala
index 6882504..4354baa 100644
--- a/src/util-app.vala
+++ b/src/util-app.vala
@@ -142,10 +142,36 @@ namespace Boxes {
return (devices.get_length () > 0) ? devices.get_nth (0) as Osinfo.Device : null;
}
- public GVir.StorageVol? get_storage_volume (GVir.Connection connection,
- GVir.Domain domain,
- out GVir.StoragePool pool) {
- pool = connection.find_storage_pool_by_name (Config.PACKAGE_TARNAME);
+ public Gtk.Image get_os_logo (Osinfo.Os? os, int size) {
+ var image = new Gtk.Image.from_icon_name ("media-optical", 0);
+ image.pixel_size = size;
+
+ if (os != null)
+ fetch_os_logo (image, os, size);
+
+ return image;
+ }
+
+ public void fetch_os_logo (Gtk.Image image, Osinfo.Os os, int size) {
+ var path = get_logo_path (os);
+
+ if (path == null)
+ return;
+
+ try {
+ var pixbuf = new Gdk.Pixbuf.from_file_at_size (path, size, -1);
+ image.set_from_pixbuf (pixbuf);
+ } catch (GLib.Error error) {
+ warning ("Error loading logo file '%s': %s", path, error.message);
+ }
+ }
+
+ public GVir.StoragePool? get_storage_pool (GVir.Connection connection) {
+ return connection.find_storage_pool_by_name (Config.PACKAGE_TARNAME);
+ }
+
+ public GVir.StorageVol? get_storage_volume (GVir.Connection connection, GVir.Domain domain) {
+ var pool = get_storage_pool (connection);
if (pool == null)
// Absence of our pool just means that disk was not created by us.
return null;
diff --git a/src/vm-creator.vala b/src/vm-creator.vala
index 1b6c52e..0bfcf27 100644
--- a/src/vm-creator.vala
+++ b/src/vm-creator.vala
@@ -106,9 +106,7 @@ private class Boxes.VMCreator {
return;
}
- var volume = get_storage_volume (connection, domain, null);
-
- if (guest_installed_os (volume)) {
+ if (guest_installed_os (machine.storage_volume)) {
mark_as_installed (machine);
try {
domain.start (0);
@@ -188,8 +186,7 @@ private class Boxes.VMCreator {
if (!install_trackable ())
return;
- var volume = get_storage_volume (connection, machine.domain, null);
- return_if_fail (volume != null);
+ return_if_fail (machine.storage_volume != null);
Timeout.add_seconds (6, () => {
if (prev_progress == 100) {
@@ -199,22 +196,24 @@ private class Boxes.VMCreator {
}
if (!updating_install_progress)
- update_install_progress.begin (machine, volume);
+ update_install_progress.begin (machine);
return true;
});
}
- private async void update_install_progress (LibvirtMachine machine, GVir.StorageVol volume) {
+ private async void update_install_progress (LibvirtMachine machine) {
updating_install_progress = true;
int progress = 0;
try {
yield run_in_thread (() => {
- progress = get_progress (volume);
+ progress = get_progress (machine.storage_volume);
});
} catch (GLib.Error error) {
- warning ("Failed to get information from volume '%s': %s", volume.get_name (), error.message);
+ warning ("Failed to get information from volume '%s': %s",
+ machine.storage_volume.get_name (),
+ error.message);
}
if (progress < 0)
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]