From 0e0342f3b37b2c4a312de55902e3cc16af58ccd4 Mon Sep 17 00:00:00 2001 From: "Eduardo Lima (Etrunko)" Date: Fri, 4 Aug 2017 18:32:55 -0300 Subject: [PATCH] foreign-menu: Check if storage domain is active for data center This last patch of the series is where we actually check if the storage domain is active in the data center the VM is associated with. It 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) --- src/Makefile.am | 2 ++ src/glib-compat.c | 35 +++++++++++++++++++++++++++++++++++ src/glib-compat.h | 39 +++++++++++++++++++++++++++++++++++++++ src/ovirt-foreign-menu.c | 25 +++++++++++++++++++++++++ 4 files changed, 101 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 . + */ +#include + +#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) + */ + +#include + +#ifndef GLIB_COMPAT_H +#define GLIB_COMPAT_H 1 + +#include + +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 bf32773..b8ad179 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, @@ -618,6 +619,24 @@ static void ovirt_foreign_menu_fetch_vm_cdrom_async(OvirtForeignMenu *menu, cdroms_fetched_cb, task); } +#ifdef HAVE_OVIRT_DATA_CENTER +static gboolean storage_domain_attached_to_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; +} +#endif + static void storage_domains_fetched_cb(GObject *source_object, GAsyncResult *result, @@ -653,6 +672,12 @@ static void storage_domains_fetched_cb(GObject *source_object, continue; } +#ifdef HAVE_OVIRT_DATA_CENTER + if (!storage_domain_attached_to_data_center(domain, menu->priv->data_center)) { + continue; + } +#endif + file_collection = ovirt_storage_domain_get_files(domain); if (file_collection != NULL) { if (menu->priv->files) { -- 2.13.6