[gnome-boxes] Add "add usb support" button to properties
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Add "add usb support" button to properties
- Date: Wed, 14 Nov 2012 16:27:00 +0000 (UTC)
commit 29e74fb6acb3507b6fb98cd3fed0add195573235
Author: Alexander Larsson <alexl redhat com>
Date: Tue Nov 6 10:08:00 2012 +0100
Add "add usb support" button to properties
This allows converting old pre-USB VMs to support USB redirection.
https://bugzilla.gnome.org/show_bug.cgi?id=672268
src/libvirt-machine.vala | 31 +++++++++++++++++++++++++++++++
src/vm-configurator.vala | 12 ++++++++++++
2 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 1d6c2f0..61537e2 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -301,6 +301,21 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
}
}
+ public void try_enable_usb_redir () throws GLib.Error {
+ var config = domain.get_config (GVir.DomainXMLFlags.INACTIVE);
+
+ // Remove any old usb configuration from old config
+ VMConfigurator.remove_usb_controllers (config);
+
+ // Add usb redirection channel and usb2 controllers
+ VMConfigurator.add_usb_support (config);
+
+ // This will take effect only after next reboot
+ domain.set_config (config);
+ if (is_on ())
+ notify_reboot_required ();
+ }
+
public override List<Boxes.Property> get_properties (Boxes.PropertiesPage page, PropertyCreationFlag flags) {
var list = new List<Boxes.Property> ();
@@ -350,6 +365,22 @@ private class Boxes.LibvirtMachine: Boxes.Machine {
if (!has_usb_redir)
flags |= PropertyCreationFlag.NO_USB;
+
+ /* Only add usb support to guests if HAVE_USBREDIR, as older
+ * qemu versions break migration with it. */
+ if (!has_usb_redir && Config.HAVE_USBREDIR) {
+ var button = new Gtk.Button.with_label (_("Add support to guest"));
+ button.halign = Gtk.Align.START;
+ var property = add_property (ref list, _("USB device support"), button);
+ button.clicked.connect (() => {
+ try {
+ try_enable_usb_redir ();
+ update_domain_config ();
+ property.refresh_properties ();
+ } catch (GLib.Error error) {
+ warning ("Failed to enable usb");
+ }
+ });
}
break;
diff --git a/src/vm-configurator.vala b/src/vm-configurator.vala
index 952462e..64ece92 100644
--- a/src/vm-configurator.vala
+++ b/src/vm-configurator.vala
@@ -329,6 +329,18 @@ private class Boxes.VMConfigurator {
return controller;
}
+ // Remove all existing usb controllers. This is used when upgrading from the old usb1 controllers to usb2
+ public static void remove_usb_controllers (Domain domain) throws Boxes.Error {
+ GLib.List<GVirConfig.DomainDevice> devices = null;
+ foreach (var device in domain.get_devices ()) {
+ if (!(device is DomainControllerUsb)) {
+ devices.prepend (device);
+ }
+ }
+ devices.reverse ();
+ domain.set_devices (devices);
+ }
+
private static CapabilitiesGuest get_best_guest_caps (Capabilities caps, InstallerMedia install_media)
throws VMConfiguratorError {
var guests_caps = caps.get_guests ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]