[gnome-boxes] vm-creator: Separate instances for each VM creation



commit 0d87fa396215bb4674dec01463d486b5ae822107
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Jun 28 22:38:05 2012 +0300

    vm-creator: Separate instances for each VM creation
    
    This breaks first-shutdown setup in case of boxes exiting before
    installation/live session is finished but it will be fixed in the
    subsequent patches along with other race-conditions/issues in that code.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=678894

 src/vm-creator.vala |   14 ++++++++------
 src/wizard.vala     |   45 ++++++++++++++++++++++-----------------------
 2 files changed, 30 insertions(+), 29 deletions(-)
---
diff --git a/src/vm-creator.vala b/src/vm-creator.vala
index a2443a3..be20a6f 100644
--- a/src/vm-creator.vala
+++ b/src/vm-creator.vala
@@ -4,10 +4,13 @@ using Osinfo;
 using GVir;
 
 private class Boxes.VMCreator {
+    public InstallerMedia install_media { get; private set; }
+
     private Connection? connection { get { return App.app.default_connection; } }
     private ulong stopped_id;
 
-    public VMCreator () {
+    public VMCreator (InstallerMedia install_media) {
+        this.install_media = install_media;
 
         App.app.collection.item_added.connect (on_item_added);
     }
@@ -38,7 +41,7 @@ private class Boxes.VMCreator {
         }
     }
 
-    public async LibvirtMachine create_vm (InstallerMedia install_media, Cancellable? cancellable) throws GLib.Error {
+    public async LibvirtMachine create_vm (Cancellable? cancellable) throws GLib.Error {
         if (connection == null) {
             // Wait for needed libvirt connection
             ulong handler = 0;
@@ -51,7 +54,7 @@ private class Boxes.VMCreator {
         }
 
         string title;
-        var name = yield create_domain_name_and_title_from_media (install_media, out title);
+        var name = yield create_domain_name_and_title_from_media (out title);
         if (install_media is UnattendedInstaller)
             yield (install_media as UnattendedInstaller).setup (name, cancellable);
 
@@ -66,7 +69,7 @@ private class Boxes.VMCreator {
         return App.app.add_domain (App.app.default_source, App.app.default_connection, domain);
     }
 
-    public void launch_vm (LibvirtMachine machine, InstallerMedia install_media) throws GLib.Error {
+    public void launch_vm (LibvirtMachine machine) throws GLib.Error {
         machine.domain.start (0);
 
         post_install_setup (machine.domain);
@@ -150,8 +153,7 @@ private class Boxes.VMCreator {
         }
     }
 
-    private async string create_domain_name_and_title_from_media (InstallerMedia install_media,
-                                                                  out string     title) throws GLib.Error {
+    private async string create_domain_name_and_title_from_media (out string title) throws GLib.Error {
         var base_title = install_media.label;
         title = base_title;
         var base_name = (install_media.os != null) ? install_media.os.short_id : base_title;
diff --git a/src/wizard.vala b/src/wizard.vala
index 1cbda8b..9dfa236 100644
--- a/src/wizard.vala
+++ b/src/wizard.vala
@@ -29,9 +29,8 @@ private class Boxes.Wizard: Boxes.UI {
     private Gtk.Image installer_image;
 
     private MediaManager media_manager;
-    private VMCreator vm_creator;
 
-    private InstallerMedia? install_media;
+    private VMCreator? vm_creator;
     private LibvirtMachine? machine;
 
     private WizardPage _page;
@@ -161,7 +160,6 @@ private class Boxes.Wizard: Boxes.UI {
     }
 
     public Wizard () {
-        vm_creator = new VMCreator ();
         wizard_source = new Boxes.WizardSource (media_manager);
         wizard_source.notify["page"].connect(wizard_source_update_next);
         wizard_source.notify["selected"].connect(wizard_source_update_next);
@@ -180,19 +178,19 @@ private class Boxes.Wizard: Boxes.UI {
 
     private bool create () {
         if (source == null) {
-            if (install_media == null)
+            if (vm_creator == null)
                 return false;
 
             next_button.sensitive = false;
             try {
-                vm_creator.launch_vm (machine, install_media);
+                vm_creator.launch_vm (machine);
             } catch (GLib.Error error) {
                 warning (error.message);
 
                 return false;
             }
 
-            install_media = null;
+            vm_creator = null;
             machine = null;
             wizard_source.uri = "";
 
@@ -256,7 +254,8 @@ private class Boxes.Wizard: Boxes.UI {
         next_button.sensitive = true;
 
         try {
-            install_media = media_manager.create_installer_media_for_path.end (result);
+            var install_media = media_manager.create_installer_media_for_path.end (result);
+            vm_creator = new VMCreator (install_media);
             fetch_os_logo (installer_image, install_media.os, 128);
             prep_progress.fraction = 1.0;
             page = WizardPage.SETUP;
@@ -271,7 +270,7 @@ private class Boxes.Wizard: Boxes.UI {
         installer_image.set_from_icon_name ("media-optical", 0); // Reset
 
         if (this.wizard_source.install_media != null) {
-            install_media = this.wizard_source.install_media;
+            vm_creator = new VMCreator (this.wizard_source.install_media);
             prep_progress.fraction = 1.0;
             page = WizardPage.SETUP;
             return false;
@@ -293,15 +292,15 @@ private class Boxes.Wizard: Boxes.UI {
         if (source != null)
             return true;
 
-        return_if_fail (install_media != null);
+        return_if_fail (vm_creator != null);
         // Setup only needed for Unattended installers
-        if (!(install_media is UnattendedInstaller))
+        if (!(vm_creator.install_media is UnattendedInstaller))
             return true;
 
         foreach (var child in setup_vbox.get_children ())
             setup_vbox.remove (child);
 
-        (install_media as UnattendedInstaller).populate_setup_vbox (setup_vbox);
+        (vm_creator.install_media as UnattendedInstaller).populate_setup_vbox (setup_vbox);
         setup_vbox.show_all ();
 
         return true;
@@ -311,10 +310,10 @@ private class Boxes.Wizard: Boxes.UI {
         nokvm_label.hide ();
         summary.clear ();
 
-        if (install_media != null && install_media is UnattendedInstaller) {
+        if (vm_creator != null && vm_creator.install_media is UnattendedInstaller) {
             try {
-                (install_media as UnattendedInstaller).check_needed_info ();
-                machine = yield vm_creator.create_vm (install_media, null);
+                (vm_creator.install_media as UnattendedInstaller).check_needed_info ();
+                machine = yield vm_creator.create_vm (null);
             } catch (IOError.CANCELLED cancel_error) { // We did this, so ignore!
                 return false;
             } catch (GLib.Error error) {
@@ -353,20 +352,20 @@ private class Boxes.Wizard: Boxes.UI {
             if (source.source_type == "libvirt") {
                 review_label.set_text (_("Will add boxes for all systems available from this account:"));
             }
-        } else if (install_media != null) {
-            summary.add_property (_("System"), install_media.label);
+        } else if (vm_creator != null) {
+            summary.add_property (_("System"), vm_creator.install_media.label);
 
-            if (install_media is UnattendedInstaller) {
-                var media = install_media as UnattendedInstaller;
+            if (vm_creator.install_media is UnattendedInstaller) {
+                var media = vm_creator.install_media as UnattendedInstaller;
                 if (media.express_install) {
                     summary.add_property (_("Username"), media.username);
                     summary.add_property (_("Password"), media.hidden_password);
                 }
             }
 
-            var memory = format_size (install_media.resources.ram, FormatSizeFlags.IEC_UNITS);
+            var memory = format_size (vm_creator.install_media.resources.ram, FormatSizeFlags.IEC_UNITS);
             summary.add_property (_("Memory"), memory);
-            memory = format_size (install_media.resources.storage, FormatSizeFlags.IEC_UNITS);
+            memory = format_size (vm_creator.install_media.resources.storage, FormatSizeFlags.IEC_UNITS);
             summary.add_property (_("Disk"),  _("%s maximum".printf (memory)));
             nokvm_label.visible = (machine.domain_config.get_virt_type () != GVirConfig.DomainVirtType.KVM);
         }
@@ -406,14 +405,14 @@ private class Boxes.Wizard: Boxes.UI {
             page == Boxes.WizardPage.PREPARATION)
             skip_to = page - 1;
 
-        if (install_media != null) {
-            if (forwards && page == Boxes.WizardPage.SETUP && install_media.live)
+        if (vm_creator != null) {
+            if (forwards && page == Boxes.WizardPage.SETUP && vm_creator.install_media.live)
                 // No setup required for live media and also skip review if told to do so
                 skip_to = skip_review_for_live ? WizardPage.LAST : WizardPage.REVIEW;
 
             // always skip SETUP page if not unattended installer
             if (page == Boxes.WizardPage.SETUP &&
-                !(install_media is UnattendedInstaller))
+                !(vm_creator.install_media is UnattendedInstaller))
                 skip_to = forwards ? page + 1 : page - 1;
         }
 



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