[libvirt-designer][PATCH] gvir_designer_domain_add_disk_full: Adapt to latest libvirt-glib

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



With libvirt-glib update, I've noticed a deprecation warning:

libvirt-designer-domain.c: In function 'gvir_designer_domain_add_disk_full':
libvirt-designer-domain.c:1610:9: error: 'gvir_config_domain_disk_set_driver_type' is deprecated (declared at /usr/include/libvirt-gconfig-1.0/libvirt-gconfig/libvirt-gconfig-domain-disk.h:145): Use 'gvir_config_domain_disk_set_driver_format' instead [-Werror=deprecated-declarations]
         gvir_config_domain_disk_set_driver_type(disk, format);
         ^
cc1: all warnings being treated as errors

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 libvirt-designer/Makefile.am                 |  1 +
 libvirt-designer/libvirt-designer-domain.c   | 22 +++++++++++--
 libvirt-designer/libvirt-designer-internal.c | 46 ++++++++++++++++++++++++++++
 libvirt-designer/libvirt-designer-internal.h |  2 ++
 4 files changed, 68 insertions(+), 3 deletions(-)
 create mode 100644 libvirt-designer/libvirt-designer-internal.c

diff --git a/libvirt-designer/Makefile.am b/libvirt-designer/Makefile.am
index 7becfd2..bda4240 100644
--- a/libvirt-designer/Makefile.am
+++ b/libvirt-designer/Makefile.am
@@ -25,6 +25,7 @@ DESIGNER_HEADER_FILES = \
 			libvirt-designer-domain.h \
 			$(NULL)
 DESIGNER_SOURCE_FILES = \
+			libvirt-designer-internal.c \
 			libvirt-designer-main.c \
 			libvirt-designer-domain.c \
 			$(NULL)
diff --git a/libvirt-designer/libvirt-designer-domain.c b/libvirt-designer/libvirt-designer-domain.c
index 848dfea..5475c79 100644
--- a/libvirt-designer/libvirt-designer-domain.c
+++ b/libvirt-designer/libvirt-designer-domain.c
@@ -1580,6 +1580,7 @@ gvir_designer_domain_add_disk_full(GVirDesignerDomain *design,
 {
     GVirDesignerDomainPrivate *priv = design->priv;
     GVirConfigDomainDisk *disk = NULL;
+    GVirConfigDomainDiskDriver *driver = NULL;
     GVirConfigDomainDiskBus bus;
     gchar *target_gen = NULL;
     const char *driver_name;
@@ -1602,12 +1603,27 @@ gvir_designer_domain_add_disk_full(GVirDesignerDomain *design,
         break;
     }
 
+    driver = gvir_config_domain_disk_driver_new();
+    gvir_config_domain_disk_driver_set_name(driver, driver_name);
+    if (format) {
+        int fmt;
+
+        fmt = gvir_designer_genum_get_value(GVIR_CONFIG_TYPE_DOMAIN_DISK_FORMAT,
+                                            format, -1);
+
+        if (fmt == -1) {
+            g_set_error(error, GVIR_DESIGNER_DOMAIN_ERROR, 0,
+                        "Unknown disk format: %s", format);
+            goto error;
+        }
+
+        gvir_config_domain_disk_driver_set_format(driver, fmt);
+    }
+
     disk = gvir_config_domain_disk_new();
     gvir_config_domain_disk_set_type(disk, type);
     gvir_config_domain_disk_set_source(disk, path);
-    gvir_config_domain_disk_set_driver_name(disk, driver_name);
-    if (format)
-        gvir_config_domain_disk_set_driver_type(disk, format);
+    gvir_config_domain_disk_set_driver(disk, driver);
 
     controller = gvir_designer_domain_get_preferred_disk_controller(design, NULL);
     if (controller == NULL)
diff --git a/libvirt-designer/libvirt-designer-internal.c b/libvirt-designer/libvirt-designer-internal.c
new file mode 100644
index 0000000..bdfa5d1
--- /dev/null
+++ b/libvirt-designer/libvirt-designer-internal.c
@@ -0,0 +1,46 @@
+/*
+ * libvirt-designer-internal.c: libvirt-designer helpers
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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.1 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/>.
+ *
+ * Authors: Michal Privoznik <mprivozn@xxxxxxxxxx>
+ */
+
+#include <config.h>
+
+#include "libvirt-designer/libvirt-designer.h"
+#include "libvirt-designer/libvirt-designer-internal.h"
+
+G_GNUC_INTERNAL int
+gvir_designer_genum_get_value(GType enum_type, const char *nick,
+                              gint default_value)
+{
+    GEnumClass *enum_class;
+    GEnumValue *enum_value;
+
+    g_return_val_if_fail(G_TYPE_IS_ENUM(enum_type), default_value);
+    g_return_val_if_fail(nick != NULL, default_value);
+
+    enum_class = g_type_class_ref(enum_type);
+    enum_value = g_enum_get_value_by_nick(enum_class, nick);
+    g_type_class_unref(enum_class);
+
+    if (enum_value != NULL)
+        return enum_value->value;
+
+    g_return_val_if_reached(default_value);
+}
diff --git a/libvirt-designer/libvirt-designer-internal.h b/libvirt-designer/libvirt-designer-internal.h
index e95edfc..fd3db2c 100644
--- a/libvirt-designer/libvirt-designer-internal.h
+++ b/libvirt-designer/libvirt-designer-internal.h
@@ -24,4 +24,6 @@
 #ifndef __LIBVIRT_DESIGNER_INTERNAL_H__
 #define __LIBVIRT_DESIGNER_INTERNAL_H__
 
+int gvir_designer_genum_get_value(GType enum_type, const char *nick, gint default_value);
+
 #endif /* __LIBVIRT_DESIGNER_INTERNAL_H__ */
-- 
1.8.5.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]