Blame SOURCES/0007-ovirt-foreign-menu-Take-into-account-StorageDomains-.patch

509daa
From f5936a87795dfdefee10f87672abcf8f9175a7c9 Mon Sep 17 00:00:00 2001
509daa
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
509daa
Date: Mon, 15 Jun 2020 20:53:18 -0300
509daa
Subject: [PATCH virt-viewer] ovirt-foreign-menu: Take into account
509daa
 StorageDomains of type DATA
509daa
509daa
Now that we support both ISO and DATA storage domain types, we need to
509daa
make sure that the files are listed correctly. In this case we give the
509daa
domains of ISO type the precedence over DATA ones.
509daa
509daa
This change extends previous commit bbda3aa which made it possible for
509daa
storage domains of type DATA to be considered valid.
509daa
509daa
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
509daa
---
509daa
 src/ovirt-foreign-menu.c | 39 ++++++++++++++++++++++-----------------
509daa
 1 file changed, 22 insertions(+), 17 deletions(-)
509daa
509daa
diff --git a/src/ovirt-foreign-menu.c b/src/ovirt-foreign-menu.c
509daa
index 3c67f1a..8d02a79 100644
509daa
--- a/src/ovirt-foreign-menu.c
509daa
+++ b/src/ovirt-foreign-menu.c
509daa
@@ -734,6 +734,9 @@ static gboolean set_file_collection_from_toplevel_storage_domain(OvirtForeignMen
509daa
     OvirtResource *resource = NULL;
509daa
     gchar *href = NULL, *id = NULL;
509daa
 
509daa
+    if (domain == NULL)
509daa
+        return FALSE;
509daa
+
509daa
     g_object_get(domain, "guid", &id, NULL);
509daa
     href = g_strdup_printf("/ovirt-engine/api/storagedomains/%s", id);
509daa
     resource = g_initable_new(OVIRT_TYPE_STORAGE_DOMAIN, NULL, &error, "guid", id, "href", href, NULL);
509daa
@@ -767,8 +770,8 @@ static void storage_domains_fetched_cb(GObject *source_object,
509daa
     OvirtForeignMenu *menu = OVIRT_FOREIGN_MENU(g_task_get_source_object(task));
509daa
     OvirtCollection *collection = OVIRT_COLLECTION(source_object);
509daa
     GHashTableIter iter;
509daa
-    OvirtStorageDomain *domain;
509daa
-    gboolean domain_valid = FALSE;
509daa
+    OvirtStorageDomain *domain, *valid_domain = NULL;
509daa
+    OvirtCollection *file_collection;
509daa
 
509daa
     ovirt_collection_fetch_finish(collection, result, &error);
509daa
     if (error != NULL) {
509daa
@@ -780,35 +783,37 @@ static void storage_domains_fetched_cb(GObject *source_object,
509daa
 
509daa
     g_hash_table_iter_init(&iter, ovirt_collection_get_resources(collection));
509daa
     while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&domain)) {
509daa
-        OvirtCollection *file_collection;
509daa
-
509daa
         if (!storage_domain_validate(menu, domain))
509daa
             continue;
509daa
 
509daa
-        if (!domain_valid)
509daa
-            domain_valid = TRUE;
509daa
+        /* Storage domain of type ISO has precedence over type DATA */
509daa
+        if (valid_domain != NULL) {
509daa
+            OvirtStorageDomainType domain_type, valid_type;
509daa
+            g_object_get(domain, "type", &domain_type, NULL);
509daa
+            g_object_get(valid_domain, "type", &valid_type, NULL);
509daa
 
509daa
-        file_collection = storage_domain_get_files(domain);
509daa
-        if (!ovirt_foreign_menu_set_file_collection(menu, file_collection)) {
509daa
-            /* Retry with toplevel storage domain */
509daa
-            if (!set_file_collection_from_toplevel_storage_domain(menu, domain))
509daa
-                continue;
509daa
+            if (domain_type > valid_type)
509daa
+                valid_domain = domain;
509daa
+
509daa
+            continue;
509daa
         }
509daa
 
509daa
-        break; /* There can only be one valid storage domain at a time,
509daa
-                  no need to iterate more on the list */
509daa
+        valid_domain = domain;
509daa
     }
509daa
 
509daa
-    if (menu->priv->files != NULL) {
509daa
-        ovirt_foreign_menu_next_async_step(menu, task, STATE_STORAGE_DOMAIN);
509daa
-    } else {
509daa
-        const char *msg = domain_valid ? "Could not find ISO file collection"
509daa
+    file_collection = storage_domain_get_files(valid_domain);
509daa
+    if (!ovirt_foreign_menu_set_file_collection(menu, file_collection) &&
509daa
+        !set_file_collection_from_toplevel_storage_domain(menu, valid_domain)) { /* Retry with toplevel storage domain */
509daa
+        const char *msg = valid_domain ? "Could not find ISO file collection"
509daa
                                        : "Could not find valid ISO storage domain";
509daa
 
509daa
         g_debug("%s", msg);
509daa
         g_task_return_new_error(task, OVIRT_ERROR, OVIRT_ERROR_FAILED, "%s", msg);
509daa
         g_object_unref(task);
509daa
+        return;
509daa
     }
509daa
+
509daa
+    ovirt_foreign_menu_next_async_step(menu, task, STATE_STORAGE_DOMAIN);
509daa
 }
509daa
 
509daa
 
509daa
-- 
509daa
2.26.2
509daa