diff options
author | Christophe Fergeau <cfergeau@redhat.com> | 2013-03-30 18:25:40 +0100 |
---|---|---|
committer | Christophe Fergeau <cfergeau@redhat.com> | 2013-04-22 21:30:14 +0200 |
commit | e42a89cd226a82a391d602b6ce71ae5e5219ecb1 (patch) | |
tree | e14542beb5527eff917bca2a65e5be8d0097828f | |
parent | 666e51535a12044e48ccdad5a100fe32ae84248d (diff) |
Add gvir_designer_domain_get_supported_devices()
This method gathers the list of devices supported by the hypervisor,
and intersects this list with the list of devices supported
by the OS, natively or using a driver (added with
gvir_designer_domain_add_driver()). The lists can be filtered if
needed.
This commit changes gvir_designer_domain_get_supported_disk_bus_types()
to make use of that new helper. This will slightly change its behaviour
as before this commit, it will consider any block devices from
GVirDesignerDomain::os, while after this commit, it will only
consider block devices from GVirDesignerDomain::os that are supported
by GVirDesignerDomain::platform.
This will cause a change for example for OSes that only list
virtio-block as a supported block device, such as Fedora as
described in libosinfo v0.2.6-9-g7a8deb4
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | libvirt-designer/libvirt-designer-domain.c | 82 |
2 files changed, 81 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac index 86c5af5..228a85c 100644 --- a/configure.ac +++ b/configure.ac @@ -10,7 +10,7 @@ AC_CANONICAL_HOST AM_SILENT_RULES([yes]) -LIBOSINFO_REQUIRED=0.2.3 +LIBOSINFO_REQUIRED=0.2.7 LIBVIRT_GCONFIG_REQUIRED=0.0.9 LIBVIRT_GOBJECT_REQUIRED=0.1.3 GOBJECT_INTROSPECTION_REQUIRED=0.10.8 diff --git a/libvirt-designer/libvirt-designer-domain.c b/libvirt-designer/libvirt-designer-domain.c index f980cb5..f959215 100644 --- a/libvirt-designer/libvirt-designer-domain.c +++ b/libvirt-designer/libvirt-designer-domain.c @@ -237,6 +237,80 @@ static void gvir_designer_domain_class_init(GVirDesignerDomainClass *klass) } +static OsinfoDeviceList * +gvir_designer_domain_get_devices_from_drivers(GVirDesignerDomain *design, + OsinfoFilter *filter) +{ + GVirDesignerDomainPrivate *priv = design->priv; + OsinfoDeviceList *devices; + unsigned int i; + + + devices = osinfo_devicelist_new(); + + for (i = 0; i < osinfo_list_get_length(OSINFO_LIST(priv->drivers)); i++) { + OsinfoDeviceDriver *driver; + OsinfoDeviceList *driver_devices; + + driver = OSINFO_DEVICE_DRIVER(osinfo_list_get_nth(OSINFO_LIST(priv->drivers), i)); + driver_devices = osinfo_device_driver_get_devices(driver); + osinfo_list_add_filtered(OSINFO_LIST(devices), + OSINFO_LIST(driver_devices), + filter); + } + + return devices; +} + + +/* Gets the list of devices matching filter that are natively supported + * by (OS) and (platform), or that are supported by (OS with a driver) and + * (platform). + * Drivers are added through gvir_designer_domain_add_driver() + */ +static OsinfoDeviceList * +gvir_designer_domain_get_supported_devices(GVirDesignerDomain *design, + OsinfoFilter *filter) +{ + GVirDesignerDomainPrivate *priv = design->priv; + OsinfoDeviceList *os_devices; + OsinfoDeviceList *platform_devices; + OsinfoDeviceList *driver_devices; + OsinfoDeviceList *devices; + + os_devices = osinfo_os_get_all_devices(priv->os, filter); + platform_devices = osinfo_platform_get_all_devices(priv->platform, filter); + driver_devices = gvir_designer_domain_get_devices_from_drivers(design, filter); + + devices = osinfo_devicelist_new(); + + if (platform_devices == NULL) + goto end; + + if (os_devices != NULL) + osinfo_list_add_intersection(OSINFO_LIST(devices), + OSINFO_LIST(os_devices), + OSINFO_LIST(platform_devices)); + + if (driver_devices != NULL) + osinfo_list_add_intersection(OSINFO_LIST(devices), + OSINFO_LIST(driver_devices), + OSINFO_LIST(platform_devices)); + +end: + if (os_devices != NULL) + g_object_unref(os_devices); + + if (platform_devices != NULL) + g_object_unref(platform_devices); + + if (driver_devices != NULL) + g_object_unref(driver_devices); + + return devices; +} + + static void gvir_designer_domain_init(GVirDesignerDomain *design) { GVirDesignerDomainPrivate *priv; @@ -724,13 +798,15 @@ cleanup: static GList * gvir_designer_domain_get_supported_disk_bus_types(GVirDesignerDomain *design) { - GVirDesignerDomainPrivate *priv = design->priv; OsinfoDeviceList *dev_list; + OsinfoFilter *filter = NULL; GHashTable *bus_hash = g_hash_table_new(g_str_hash, g_str_equal); GList *ret = NULL; GList *devs = NULL, *dev_iterator; - dev_list = osinfo_os_get_devices_by_property(priv->os, "class", "block", TRUE); + filter = osinfo_filter_new(); + osinfo_filter_add_constraint(filter, OSINFO_DEVICE_PROP_CLASS, "block"); + dev_list = gvir_designer_domain_get_supported_devices(design, filter); if (!dev_list) goto cleanup; @@ -750,6 +826,8 @@ cleanup: g_list_free(devs); if (dev_list != NULL) g_object_unref(G_OBJECT(dev_list)); + if (filter != NULL) + g_object_unref(G_OBJECT(filter)); g_hash_table_destroy(bus_hash); return ret; } |