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