[gnome-boxes] vm-creator: No need to fetch domain configuration



commit e18ba16e16b2a69bb3d5a9eea3dc891fd5427875
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Sat Jun 30 22:00:53 2012 +0300

    vm-creator: No need to fetch domain configuration
    
    LibvirtMachine keeps domain configuration cached for us so no need for
    potentially slow blocking call to GVir.Domain.get_config ().
    
    https://bugzilla.gnome.org/show_bug.cgi?id=678894

 src/vm-creator.vala |   47 ++++++++++++++++++++++-------------------------
 1 files changed, 22 insertions(+), 25 deletions(-)
---
diff --git a/src/vm-creator.vala b/src/vm-creator.vala
index f8852c5..7300a04 100644
--- a/src/vm-creator.vala
+++ b/src/vm-creator.vala
@@ -51,7 +51,7 @@ private class Boxes.VMCreator {
     public void launch_vm (LibvirtMachine machine) throws GLib.Error {
         machine.domain.start (0);
 
-        set_post_install_config (machine.domain);
+        set_post_install_config (machine);
 
         if (!(install_media is UnattendedInstaller) || !(install_media as UnattendedInstaller).express_install) {
             ulong signal_id = 0;
@@ -99,7 +99,7 @@ private class Boxes.VMCreator {
         var volume = get_storage_volume (connection, domain, null);
 
         if (guest_installed_os (volume)) {
-            mark_as_installed (domain);
+            mark_as_installed (machine);
             try {
                 domain.start (0);
             } catch (GLib.Error error) {
@@ -108,40 +108,37 @@ private class Boxes.VMCreator {
             machine.disconnect (state_changed_id);
             machine.vm_creator = null;
         } else {
-            try {
-                var config = domain.get_config (0);
-
-                if (!VMConfigurator.is_live_config (config))
-                    return;
+            if (!VMConfigurator.is_live_config (machine.domain_config))
+                return;
 
-                // No installation during live session, so lets delete the VM
-                machine.disconnect (state_changed_id);
-                App.app.delete_machine (machine);
-            } catch (GLib.Error error) {
-                warning ("Failed to delete domain '%s' or its volume: %s", domain.get_name (), error.message);
-            }
+            // No installation during live session, so lets delete the VM
+            machine.disconnect (state_changed_id);
+            App.app.delete_machine (machine);
         }
     }
 
-    private void set_post_install_config (Domain domain) {
-        debug ("Setting post-installation configuration on '%s'", domain.get_name ());
+    private void set_post_install_config (LibvirtMachine machine) {
+        debug ("Setting post-installation configuration on '%s'", machine.name);
         try {
-            var config = domain.get_config (0);
-            VMConfigurator.post_install_setup (config);
-            domain.set_config (config);
+            // We need to clone the domain_config as that is supposed to reflect the active config while we are
+            // modifying the inactive config, which are different when domain is running.
+            var config_xml = machine.domain_config.to_xml ();
+            var post_install_config = new GVirConfig.Domain.from_xml (config_xml);
+            VMConfigurator.post_install_setup (post_install_config);
+            machine.domain.set_config (post_install_config);
         } catch (GLib.Error error) {
-            warning ("Failed to set post-install configuration on '%s' failed: %s", domain.get_uuid (), error.message);
+            warning ("Failed to set post-install configuration on '%s' failed: %s", machine.name, error.message);
         }
     }
 
-    private void mark_as_installed (Domain domain) {
-        debug ("Marking '%s' as installed.", domain.get_name ());
+    private void mark_as_installed (LibvirtMachine machine) requires (machine.state == Machine.MachineState.STOPPED ||
+                                                                      machine.state == Machine.MachineState.UNKNOWN) {
+        debug ("Marking '%s' as installed.", machine.name);
         try {
-            var config = domain.get_config (0);
-            VMConfigurator.mark_as_installed (config);
-            domain.set_config (config);
+            VMConfigurator.mark_as_installed (machine.domain_config);
+            machine.domain.set_config (machine.domain_config);
         } catch (GLib.Error error) {
-            warning ("Failed to marking domain '%s' as installed: %s", domain.get_uuid (), error.message);
+            warning ("Failed to marking domain '%s' as installed: %s", machine.name, error.message);
         }
     }
 



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