[libvirt-gconfig PATCHv2 14/14] Implement gvir_config_domain_setup_default_usb_controllers

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

 



This function is a helper function which adds all the needed devices
for working USB support in the guest. This can be done manually, but
is a bit tedious, hence this helper.
---
 libvirt-gconfig/libvirt-gconfig-domain.c   |   41 ++++++++++++++++++++++++++++
 libvirt-gconfig/libvirt-gconfig-domain.h   |    2 ++
 libvirt-gconfig/libvirt-gconfig.sym        |    1 +
 libvirt-gconfig/tests/test-domain-create.c |    7 +++++
 4 files changed, 51 insertions(+)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c
index 33a69e3..05860bf 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -517,3 +517,44 @@ gchar *gvir_config_domain_get_custom_xml(GVirConfigDomain *domain,
                                      lookup_namespaced_node, &data);
     return gvir_config_xml_node_to_string(data.node);
 }
+
+static GVirConfigDomainControllerUsb *
+create_usb_controller(GVirConfigDomainControllerUsbModel model, guint index,
+                      GVirConfigDomainControllerUsb *master, guint start_port)
+{
+    GVirConfigDomainControllerUsb *controller;
+
+    controller = gvir_config_domain_controller_usb_new();
+    gvir_config_domain_controller_usb_set_model(controller, model);
+    gvir_config_domain_controller_set_index(GVIR_CONFIG_DOMAIN_CONTROLLER(controller), index);
+    if (master)
+        gvir_config_domain_controller_usb_set_master(controller, master, start_port);
+
+    return controller;
+}
+
+void gvir_config_domain_setup_default_usb_controllers(GVirConfigDomain *domain)
+{
+    /* spice usb redirection */
+    GVirConfigDomainControllerUsb *ehci;
+    GVirConfigDomainControllerUsb *uhci1;
+    GVirConfigDomainControllerUsb *uhci2;
+    GVirConfigDomainControllerUsb *uhci3;
+
+    ehci = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_EHCI1,
+                                 0, NULL, 0);
+    gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(ehci));
+    uhci1 = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI1,
+                                  0, ehci, 0);
+    gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(uhci1));
+    g_object_unref(G_OBJECT(uhci1));
+    uhci2 = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI2,
+                                  0, ehci, 2);
+    gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(uhci2));
+    g_object_unref(G_OBJECT(uhci2));
+    uhci3 = create_usb_controller(GVIR_CONFIG_DOMAIN_CONTROLLER_USB_MODEL_ICH9_UHCI3,
+                                  0, ehci, 4);
+    gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(uhci3));
+    g_object_unref(G_OBJECT(uhci3));
+    g_object_unref(G_OBJECT(ehci));
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h
index 1dbfd95..36f1fcd 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain.h
@@ -134,6 +134,8 @@ gboolean gvir_config_domain_set_custom_xml(GVirConfigDomain *domain,
 gchar *gvir_config_domain_get_custom_xml(GVirConfigDomain *domain,
                                          const gchar *ns_uri);
 
+void gvir_config_domain_setup_default_usb_controllers(GVirConfigDomain *domain);
+
 G_END_DECLS
 
 #endif /* __LIBVIRT_GCONFIG_DOMAIN_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 6857320..ada6aa2 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -32,6 +32,7 @@ LIBVIRT_GCONFIG_0.0.4 {
 	gvir_config_domain_get_vcpus;
 	gvir_config_domain_set_vcpus;
 	gvir_config_domain_set_virt_type;
+	gvir_config_domain_setup_default_usb_controllers;
 	gvir_config_domain_virt_type_get_type;
 
 	gvir_config_domain_address_get_type;
diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c
index b6d8813..4828cd7 100644
--- a/libvirt-gconfig/tests/test-domain-create.c
+++ b/libvirt-gconfig/tests/test-domain-create.c
@@ -256,6 +256,7 @@ int main(int argc, char **argv)
     devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(channel));
 
     /* spice usb redirection */
+
     GVirConfigDomainControllerUsb *ehci;
     GVirConfigDomainControllerUsb *uhci1;
     GVirConfigDomainControllerUsb *uhci2;
@@ -293,6 +294,12 @@ int main(int argc, char **argv)
     g_list_free(devices);
     devices = NULL;
 
+    /* this helper function adds everything that is needed for USB support in the host,
+     * the manual creation of the controller below is just for testing/if
+     * more control over the controller devices is needed.
+     */
+    gvir_config_domain_setup_default_usb_controllers(domain);
+
     gvir_config_domain_set_custom_xml(domain, "<foo/>", "ns", "http://foo";, NULL);
     gvir_config_domain_set_custom_xml(domain, "<foo/>", "nsbar", "http://bar";, NULL);
     gvir_config_domain_set_custom_xml(domain, "<foo/>", "ns", "http://bar";, NULL);
-- 
1.7.10

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]