[libvirt-designer PATCHv2 6/9] Check for vioserial availability before adding a SPICE agent

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

 



This makes use of the new gvir_designer_domain_get_supported_devices()
method.
---
 libvirt-designer/libvirt-designer-domain.c | 42 +++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/libvirt-designer/libvirt-designer-domain.c b/libvirt-designer/libvirt-designer-domain.c
index 0757527..1a622bf 100644
--- a/libvirt-designer/libvirt-designer-domain.c
+++ b/libvirt-designer/libvirt-designer-domain.c
@@ -71,6 +71,7 @@ static gboolean error_is_set(GError **error)
 }
 
 static const char GVIR_DESIGNER_SPICE_CHANNEL_NAME[] = "com.redhat.spice.0";
+static const char GVIR_DESIGNER_SPICE_CHANNEL_DEVICE_ID[] = "http://pciids.sourceforge.net/v2.2/pci.ids/1af4/1003";;
 static const char GVIR_DESIGNER_VIRTIO_BLOCK_DEVICE_ID[] = "http://pciids.sourceforge.net/v2.2/pci.ids/1af4/1001";;
 
 enum {
@@ -411,12 +412,45 @@ gvir_designer_domain_has_spice_channel(GVirDesignerDomain *design)
 }
 
 
-static void gvir_designer_domain_add_spice_channel(GVirDesignerDomain *design)
+static gboolean
+gvir_designer_domain_supports_spice_channel(GVirDesignerDomain *design)
+{
+    OsinfoDeviceList *devices;
+    OsinfoFilter *filter;
+    gboolean vioserial_found = FALSE;
+
+    filter = osinfo_filter_new();
+    osinfo_filter_add_constraint(filter,
+                                 OSINFO_ENTITY_PROP_ID,
+                                 GVIR_DESIGNER_SPICE_CHANNEL_DEVICE_ID);
+    devices = gvir_designer_domain_get_supported_devices(design, filter);
+    if (devices) {
+        g_warn_if_fail(osinfo_list_get_length(OSINFO_LIST(devices)) <= 1);
+        if (osinfo_list_get_length(OSINFO_LIST(devices)) >= 1)
+            vioserial_found = TRUE;
+        g_object_unref(G_OBJECT(devices));
+    }
+    if (filter)
+        g_object_unref(G_OBJECT(filter));
+
+    return vioserial_found;
+}
+
+
+static gboolean gvir_designer_domain_add_spice_channel(GVirDesignerDomain *design,
+                                                       GError **error)
 {
-    /* FIXME: error out if there is no support for the vioserial device */
     GVirConfigDomainChannel *channel;
     GVirConfigDomainChardevSourceSpiceVmc *vmc;
 
+    if (!gvir_designer_domain_supports_spice_channel(design)) {
+        g_set_error(error, GVIR_DESIGNER_DOMAIN_ERROR, 0,
+                    "OS and/or hypervisor don't support virtio-serial"
+                    " which is required by the SPICE channel");
+        g_debug("SPICE channel not supported");
+        return FALSE;
+    }
+
     channel = gvir_config_domain_channel_new();
     gvir_config_domain_channel_set_target_type(channel,
                                                GVIR_CONFIG_DOMAIN_CHANNEL_TARGET_VIRTIO);
@@ -430,6 +464,8 @@ static void gvir_designer_domain_add_spice_channel(GVirDesignerDomain *design)
     gvir_config_domain_add_device(design->priv->config,
                                   GVIR_CONFIG_DOMAIN_DEVICE(channel));
     g_object_unref(G_OBJECT(channel));
+
+    return TRUE;
 }
 
 
@@ -517,7 +553,7 @@ gvir_designer_domain_add_graphics(GVirDesignerDomain *design,
                                                                 GVIR_CONFIG_DOMAIN_GRAPHICS_SPICE_IMAGE_COMPRESSION_OFF);
         graphics = GVIR_CONFIG_DOMAIN_GRAPHICS(spice);
         if (!gvir_designer_domain_has_spice_channel(design))
-            gvir_designer_domain_add_spice_channel(design);
+            gvir_designer_domain_add_spice_channel(design, NULL);
 
         break;
     }
-- 
1.8.1.4

--
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]