[gnome-boxes] installer: Domain & its volume should share name
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] installer: Domain & its volume should share name
- Date: Wed, 15 Feb 2012 22:48:31 +0000 (UTC)
commit 38a1874641c4dcd2e94d292dea724b81a37fa299
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Wed Jan 18 06:13:56 2012 +0200
installer: Domain & its volume should share name
If simply create the domain and its main storage volume by the same
name, its much faster/easier to find the volume given a domain.
https://bugzilla.gnome.org/show_bug.cgi?id=668211
src/libvirt-machine.vala | 28 +++-------------------------
src/util.vala | 9 +++++++++
src/vm-creator.vala | 30 ++++++++++++++----------------
3 files changed, 26 insertions(+), 41 deletions(-)
---
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 21b2e27..bd58b7f 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -340,7 +340,9 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
// The reason we fetch the volume before stopping the domain is that we need the domain's
// configuration for fechting its volume and transient domains stop existing after they are stopped.
// OTOH we can't just delete the volume from a running domain.
- var volume = get_storage_volume ();
+ StorageVol volume = null;
+ if (connection == app.default_connection)
+ volume = get_storage_volume (connection, domain);
try {
if (is_running ())
@@ -362,28 +364,4 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
public async void suspend () throws GLib.Error {
(save_on_quit) ? yield domain.save_async (0, null) : domain.suspend ();
}
-
- private GVir.StorageVol? get_storage_volume () throws GLib.Error {
- if (connection != app.default_connection)
- return null;
-
- var pool = connection.find_storage_pool_by_name (Config.PACKAGE_TARNAME);
- if (pool == null)
- // Absence of our pool just means that disk was not created by us and therefore should not be deleted by
- // us either.
- return null;
-
- foreach (var device in domain_config.get_devices ()) {
- if (!(device is GVirConfig.DomainDisk))
- continue;
-
- var path = (device as GVirConfig.DomainDisk).get_source ();
-
- foreach (var volume in pool.get_volumes ())
- if (volume.get_path () == path)
- return volume;
- }
-
- return null;
- }
}
diff --git a/src/util.vala b/src/util.vala
index e4fe160..5030094 100644
--- a/src/util.vala
+++ b/src/util.vala
@@ -278,6 +278,15 @@ namespace Boxes {
return val.value;
}
+ public GVir.StorageVol? get_storage_volume (GVir.Connection connection, GVir.Domain domain) {
+ var pool = connection.find_storage_pool_by_name (Config.PACKAGE_TARNAME);
+ if (pool == null)
+ // Absence of our pool just means that disk was not created by us.
+ return null;
+
+ return pool.get_volume (domain.get_name ());
+ }
+
public class Pair<T1,T2> {
public T1 first;
public T2 second;
diff --git a/src/vm-creator.vala b/src/vm-creator.vala
index 5ce6150..5a9aa2d 100644
--- a/src/vm-creator.vala
+++ b/src/vm-creator.vala
@@ -18,18 +18,9 @@ private class Boxes.VMCreator {
if (install_media is UnattendedInstaller)
yield (install_media as UnattendedInstaller).setup (cancellable);
- string name;
- if (install_media.os != null)
- name = install_media.os.name;
- else
- name = install_media.label;
-
- var domain_name = name;
- for (var i = 1; connection.find_domain_by_name (domain_name) != null; i++)
- domain_name = name + "-" + i.to_string ();
-
+ var name = yield create_domain_name_from_media (install_media);
var volume = yield create_target_volume (name, install_media.resources.storage);
- var config = configurator.create_domain_config (install_media, domain_name, volume.get_path ());
+ var config = configurator.create_domain_config (install_media, name, volume.get_path ());
Domain domain;
if (install_media.live)
@@ -88,14 +79,21 @@ private class Boxes.VMCreator {
}
}
- private async StorageVol create_target_volume (string name, int64 storage) throws GLib.Error {
+ private async string create_domain_name_from_media (InstallerMedia install_media) throws GLib.Error {
+ var base_name = (install_media.os != null) ? install_media.os.name : install_media.label;
+ var name = base_name;
+
var pool = yield get_storage_pool ();
+ for (var i = 1; connection.find_domain_by_name (name) != null || pool.get_volume (name) != null; i++)
+ name = base_name + "-" + i.to_string ();
- var volume_name = name + ".qcow2";
- for (var i = 1; pool.get_volume (volume_name) != null; i++)
- volume_name = name + "-" + i.to_string () + ".qcow2";
+ return name;
+ }
+
+ private async StorageVol create_target_volume (string name, int64 storage) throws GLib.Error {
+ var pool = yield get_storage_pool ();
- var config = configurator.create_volume_config (volume_name, storage);
+ var config = configurator.create_volume_config (name, storage);
var volume = pool.create_volume (config);
return volume;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]