Blame SOURCES/0006-ovirt-foreign-menu-Use-proper-function-in-the-case-o.patch

0f5b8b
From 0a16fd513034c2a1475ed84b38461faea7a12250 Mon Sep 17 00:00:00 2001
0f5b8b
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
0f5b8b
Date: Thu, 25 Jun 2020 21:19:32 -0300
0f5b8b
Subject: [PATCH virt-viewer] ovirt-foreign-menu: Use proper function in the
0f5b8b
 case of DATA StorageDomains
0f5b8b
0f5b8b
Unlike the StorageDomain objects of ISO type, the DATA ones require a
0f5b8b
specific API recently added to libgovirt to support them. This commit
0f5b8b
makes use of those new functions under #ifdef guards and adds proper a
0f5b8b
check to configure.ac.
0f5b8b
0f5b8b
Related: https://bugzilla.redhat.com/show_bug.cgi?id=1847223
0f5b8b
0f5b8b
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
0f5b8b
---
0f5b8b
 configure.ac             |  2 +-
0f5b8b
 src/ovirt-foreign-menu.c | 36 ++++++++++++++++++++++++++++++++++--
0f5b8b
 2 files changed, 35 insertions(+), 3 deletions(-)
0f5b8b
0f5b8b
diff --git a/configure.ac b/configure.ac
0f5b8b
index 9da056f..a313ce1 100644
0f5b8b
--- a/configure.ac
0f5b8b
+++ b/configure.ac
0f5b8b
@@ -203,7 +203,7 @@ AS_IF([test "x$with_ovirt" = "xyes"],
0f5b8b
        SAVED_LIBS="$LIBS"
0f5b8b
        CFLAGS="$SAVED_CFLAGS $OVIRT_CFLAGS"
0f5b8b
        LIBS="$SAVED_LIBS $OVIRT_LIBS"
0f5b8b
-       AC_CHECK_FUNCS([ovirt_api_search_vms ovirt_vm_get_host ovirt_host_get_cluster ovirt_cluster_get_data_center],
0f5b8b
+       AC_CHECK_FUNCS([ovirt_api_search_vms ovirt_vm_get_host ovirt_host_get_cluster ovirt_cluster_get_data_center ovirt_storage_domain_get_disks],
0f5b8b
                       [AC_DEFINE([HAVE_OVIRT_DATA_CENTER], 1, [Have support for data center])],
0f5b8b
                       []
0f5b8b
                       )
0f5b8b
diff --git a/src/ovirt-foreign-menu.c b/src/ovirt-foreign-menu.c
0f5b8b
index c31c93f..3c67f1a 100644
0f5b8b
--- a/src/ovirt-foreign-menu.c
0f5b8b
+++ b/src/ovirt-foreign-menu.c
0f5b8b
@@ -481,6 +481,18 @@ static void ovirt_foreign_menu_set_files(OvirtForeignMenu *menu,
0f5b8b
     for (it = files; it != NULL; it = it->next) {
0f5b8b
         char *name;
0f5b8b
         g_object_get(it->data, "name", &name, NULL);
0f5b8b
+
0f5b8b
+#ifdef HAVE_OVIRT_STORAGE_DOMAIN_GET_DISKS
0f5b8b
+        if (OVIRT_IS_DISK(it->data)) {
0f5b8b
+            OvirtDiskContentType content_type;
0f5b8b
+            g_object_get(it->data, "content-type", &content_type, NULL);
0f5b8b
+            if (content_type != OVIRT_DISK_CONTENT_TYPE_ISO) {
0f5b8b
+                g_debug("Ignoring %s disk which content-type is not ISO", name);
0f5b8b
+                continue;
0f5b8b
+            }
0f5b8b
+        }
0f5b8b
+#endif
0f5b8b
+
0f5b8b
         /* The oVirt REST API is supposed to have a 'type' node
0f5b8b
          * associated with file resources , but as of 3.2, this node
0f5b8b
          * is not present, so we do an extension check instead
0f5b8b
@@ -695,6 +707,26 @@ static gboolean ovirt_foreign_menu_set_file_collection(OvirtForeignMenu *menu, O
0f5b8b
     return TRUE;
0f5b8b
 }
0f5b8b
 
0f5b8b
+static OvirtCollection *storage_domain_get_files(OvirtStorageDomain *domain)
0f5b8b
+{
0f5b8b
+    OvirtCollection *files = NULL;
0f5b8b
+    OvirtStorageDomainType type;
0f5b8b
+
0f5b8b
+    if (domain == NULL)
0f5b8b
+        return NULL;
0f5b8b
+
0f5b8b
+    g_object_get(domain, "type", &type, NULL);
0f5b8b
+
0f5b8b
+    if (type == OVIRT_STORAGE_DOMAIN_TYPE_ISO)
0f5b8b
+        files = ovirt_storage_domain_get_files(domain);
0f5b8b
+#ifdef HAVE_OVIRT_STORAGE_DOMAIN_GET_DISKS
0f5b8b
+    else if (type == OVIRT_STORAGE_DOMAIN_TYPE_DATA)
0f5b8b
+        files = ovirt_storage_domain_get_disks(domain);
0f5b8b
+#endif
0f5b8b
+
0f5b8b
+    return files;
0f5b8b
+}
0f5b8b
+
0f5b8b
 static gboolean set_file_collection_from_toplevel_storage_domain(OvirtForeignMenu *menu, OvirtStorageDomain *domain)
0f5b8b
 {
0f5b8b
     gboolean ret = FALSE;
0f5b8b
@@ -716,7 +748,7 @@ static gboolean set_file_collection_from_toplevel_storage_domain(OvirtForeignMen
0f5b8b
         goto end;
0f5b8b
     }
0f5b8b
 
0f5b8b
-    ret = ovirt_foreign_menu_set_file_collection(menu, ovirt_storage_domain_get_files(OVIRT_STORAGE_DOMAIN(resource)));
0f5b8b
+    ret = ovirt_foreign_menu_set_file_collection(menu, storage_domain_get_files(OVIRT_STORAGE_DOMAIN(resource)));
0f5b8b
 
0f5b8b
 end:
0f5b8b
     g_clear_error(&error);
0f5b8b
@@ -756,7 +788,7 @@ static void storage_domains_fetched_cb(GObject *source_object,
0f5b8b
         if (!domain_valid)
0f5b8b
             domain_valid = TRUE;
0f5b8b
 
0f5b8b
-        file_collection = ovirt_storage_domain_get_files(domain);
0f5b8b
+        file_collection = storage_domain_get_files(domain);
0f5b8b
         if (!ovirt_foreign_menu_set_file_collection(menu, file_collection)) {
0f5b8b
             /* Retry with toplevel storage domain */
0f5b8b
             if (!set_file_collection_from_toplevel_storage_domain(menu, domain))
0f5b8b
-- 
0f5b8b
2.26.2
0f5b8b