Blame SOURCES/0049-foreign-menu-Check-if-storage-domain-is-active-for-d.patch

5bafe0
From 0e0342f3b37b2c4a312de55902e3cc16af58ccd4 Mon Sep 17 00:00:00 2001
5bafe0
From: "Eduardo Lima (Etrunko)" <etrunko@redhat.com>
5bafe0
Date: Fri, 4 Aug 2017 18:32:55 -0300
5bafe0
Subject: [PATCH] foreign-menu: Check if storage domain is active for data
5bafe0
 center
5bafe0
5bafe0
This last patch of the series is where we actually check if the storage
5bafe0
domain is active in the data center the VM is associated with. It makes
5bafe0
use of g_strv_contains(), which is available only in glib version 2.44.
5bafe0
Compatibility code has been added if building against older versions
5bafe0
than required.
5bafe0
5bafe0
Related: https://bugzilla.redhat.com/show_bug.cgi?id=1427467
5bafe0
         https://bugzilla.redhat.com/show_bug.cgi?id=1428401
5bafe0
5bafe0
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
5bafe0
---
5bafe0
 src/Makefile.am          |  2 ++
5bafe0
 src/glib-compat.c        | 35 +++++++++++++++++++++++++++++++++++
5bafe0
 src/glib-compat.h        | 39 +++++++++++++++++++++++++++++++++++++++
5bafe0
 src/ovirt-foreign-menu.c | 25 +++++++++++++++++++++++++
5bafe0
 4 files changed, 101 insertions(+)
5bafe0
 create mode 100644 src/glib-compat.c
5bafe0
 create mode 100644 src/glib-compat.h
5bafe0
5bafe0
diff --git a/src/Makefile.am b/src/Makefile.am
5bafe0
index 9748277..b3eea67 100644
5bafe0
--- a/src/Makefile.am
5bafe0
+++ b/src/Makefile.am
5bafe0
@@ -54,6 +54,8 @@ libvirt_viewer_util_la_SOURCES = \
5bafe0
 
5bafe0
 libvirt_viewer_la_SOURCES =					\
5bafe0
 	$(BUILT_SOURCES)				\
5bafe0
+	glib-compat.h					\
5bafe0
+	glib-compat.c					\
5bafe0
 	virt-viewer-auth.h				\
5bafe0
 	virt-viewer-auth.c				\
5bafe0
 	virt-viewer-app.h				\
5bafe0
diff --git a/src/glib-compat.c b/src/glib-compat.c
5bafe0
new file mode 100644
5bafe0
index 0000000..62ac87e
5bafe0
--- /dev/null
5bafe0
+++ b/src/glib-compat.c
5bafe0
@@ -0,0 +1,35 @@
5bafe0
+/*
5bafe0
+ * This library is free software; you can redistribute it and/or
5bafe0
+ * modify it under the terms of the GNU Lesser General Public
5bafe0
+ * License as published by the Free Software Foundation; either
5bafe0
+ * version 2 of the License, or (at your option) any later version.
5bafe0
+ *
5bafe0
+ * This library is distributed in the hope that it will be useful,
5bafe0
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
5bafe0
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5bafe0
+ * Lesser General Public License for more details.
5bafe0
+ *
5bafe0
+ * You should have received a copy of the GNU Lesser General Public
5bafe0
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
5bafe0
+ */
5bafe0
+#include <config.h>
5bafe0
+
5bafe0
+#include "glib-compat.h"
5bafe0
+
5bafe0
+#if !GLIB_CHECK_VERSION(2,44,0)
5bafe0
+gboolean
5bafe0
+g_strv_contains (const gchar * const *strv,
5bafe0
+                 const gchar         *str)
5bafe0
+{
5bafe0
+  g_return_val_if_fail (strv != NULL, FALSE);
5bafe0
+  g_return_val_if_fail (str != NULL, FALSE);
5bafe0
+
5bafe0
+  for (; *strv != NULL; strv++)
5bafe0
+    {
5bafe0
+      if (g_str_equal (str, *strv))
5bafe0
+        return TRUE;
5bafe0
+    }
5bafe0
+
5bafe0
+  return FALSE;
5bafe0
+}
5bafe0
+#endif
5bafe0
diff --git a/src/glib-compat.h b/src/glib-compat.h
5bafe0
new file mode 100644
5bafe0
index 0000000..f1b43ae
5bafe0
--- /dev/null
5bafe0
+++ b/src/glib-compat.h
5bafe0
@@ -0,0 +1,39 @@
5bafe0
+/*
5bafe0
+ * Virt Viewer: A virtual machine console viewer
5bafe0
+ *
5bafe0
+ * Copyright (C) 2017 Red Hat, Inc.
5bafe0
+ *
5bafe0
+ * This program is free software; you can redistribute it and/or modify
5bafe0
+ * it under the terms of the GNU General Public License as published by
5bafe0
+ * the Free Software Foundation; either version 2 of the License, or
5bafe0
+ * (at your option) any later version.
5bafe0
+ *
5bafe0
+ * This program is distributed in the hope that it will be useful,
5bafe0
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
5bafe0
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5bafe0
+ * GNU General Public License for more details.
5bafe0
+ *
5bafe0
+ * You should have received a copy of the GNU General Public License
5bafe0
+ * along with this program; if not, write to the Free Software
5bafe0
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5bafe0
+ *
5bafe0
+ * Author: Eduardo Lima (Etrunko) <etrunko@redhat.com>
5bafe0
+ */
5bafe0
+
5bafe0
+#include <config.h>
5bafe0
+
5bafe0
+#ifndef GLIB_COMPAT_H
5bafe0
+#define GLIB_COMPAT_H 1
5bafe0
+
5bafe0
+#include <glib.h>
5bafe0
+
5bafe0
+G_BEGIN_DECLS
5bafe0
+
5bafe0
+#if !GLIB_CHECK_VERSION(2,44,0)
5bafe0
+gboolean              g_strv_contains  (const gchar * const *strv,
5bafe0
+                                        const gchar         *str);
5bafe0
+#endif
5bafe0
+
5bafe0
+G_END_DECLS
5bafe0
+
5bafe0
+#endif // GLIB_COMPAT_H
5bafe0
diff --git a/src/ovirt-foreign-menu.c b/src/ovirt-foreign-menu.c
5bafe0
index bf32773..b8ad179 100644
5bafe0
--- a/src/ovirt-foreign-menu.c
5bafe0
+++ b/src/ovirt-foreign-menu.c
5bafe0
@@ -29,6 +29,7 @@
5bafe0
 
5bafe0
 #include "ovirt-foreign-menu.h"
5bafe0
 #include "virt-viewer-util.h"
5bafe0
+#include "glib-compat.h"
5bafe0
 
5bafe0
 typedef enum {
5bafe0
     STATE_0,
5bafe0
@@ -618,6 +619,24 @@ static void ovirt_foreign_menu_fetch_vm_cdrom_async(OvirtForeignMenu *menu,
5bafe0
                                  cdroms_fetched_cb, task);
5bafe0
 }
5bafe0
 
5bafe0
+#ifdef HAVE_OVIRT_DATA_CENTER
5bafe0
+static gboolean storage_domain_attached_to_data_center(OvirtStorageDomain *domain,
5bafe0
+                                                      OvirtDataCenter *data_center)
5bafe0
+{
5bafe0
+    GStrv data_center_ids;
5bafe0
+    char *data_center_guid;
5bafe0
+    gboolean match;
5bafe0
+
5bafe0
+    g_object_get(domain, "data-center-ids", &data_center_ids, NULL);
5bafe0
+    g_object_get(data_center, "guid", &data_center_guid, NULL);
5bafe0
+    match = g_strv_contains((const gchar * const *) data_center_ids, data_center_guid);
5bafe0
+    g_strfreev(data_center_ids);
5bafe0
+    g_free(data_center_guid);
5bafe0
+
5bafe0
+    return match;
5bafe0
+}
5bafe0
+#endif
5bafe0
+
5bafe0
 
5bafe0
 static void storage_domains_fetched_cb(GObject *source_object,
5bafe0
                                        GAsyncResult *result,
5bafe0
@@ -653,6 +672,12 @@ static void storage_domains_fetched_cb(GObject *source_object,
5bafe0
             continue;
5bafe0
         }
5bafe0
 
5bafe0
+#ifdef HAVE_OVIRT_DATA_CENTER
5bafe0
+        if (!storage_domain_attached_to_data_center(domain, menu->priv->data_center)) {
5bafe0
+            continue;
5bafe0
+        }
5bafe0
+#endif
5bafe0
+
5bafe0
         file_collection = ovirt_storage_domain_get_files(domain);
5bafe0
         if (file_collection != NULL) {
5bafe0
             if (menu->priv->files) {
5bafe0
-- 
5bafe0
2.13.6
5bafe0