[libvirt-glib 1/3] Add LibvirtGConfigDomainChardevSourceUnix

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

 



This is needed to be able to add UNIX channels
---
 libvirt-gconfig/Makefile.am                        |  2 +
 .../libvirt-gconfig-domain-chardev-source-unix.c   | 84 ++++++++++++++++++++++
 .../libvirt-gconfig-domain-chardev-source-unix.h   | 68 ++++++++++++++++++
 libvirt-gconfig/libvirt-gconfig.h                  |  1 +
 libvirt-gconfig/libvirt-gconfig.sym                |  7 ++
 libvirt-gconfig/tests/test-domain-create.c         | 14 ++++
 tests/test-gconfig.c                               | 11 +++
 tests/xml/gconfig-domain-device-channel.xml        |  3 +
 8 files changed, 190 insertions(+)
 create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-chardev-source-unix.c
 create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-chardev-source-unix.h

diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am
index a9a6591..77b2032 100644
--- a/libvirt-gconfig/Makefile.am
+++ b/libvirt-gconfig/Makefile.am
@@ -32,6 +32,7 @@ GCONFIG_HEADER_FILES = \
 			libvirt-gconfig-domain-chardev-source-pty.h \
 			libvirt-gconfig-domain-chardev-source-spiceport.h \
 			libvirt-gconfig-domain-chardev-source-spicevmc.h \
+			libvirt-gconfig-domain-chardev-source-unix.h \
 			libvirt-gconfig-domain-clock.h \
 			libvirt-gconfig-domain-console.h \
 			libvirt-gconfig-domain-controller.h \
@@ -122,6 +123,7 @@ GCONFIG_SOURCE_FILES = \
 			libvirt-gconfig-domain-chardev-source-pty.c \
 			libvirt-gconfig-domain-chardev-source-spiceport.c \
 			libvirt-gconfig-domain-chardev-source-spicevmc.c \
+			libvirt-gconfig-domain-chardev-source-unix.c \
 			libvirt-gconfig-domain-clock.c \
 			libvirt-gconfig-domain-console.c \
 			libvirt-gconfig-domain-controller.c \
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-unix.c b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-unix.c
new file mode 100644
index 0000000..162b788
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-unix.c
@@ -0,0 +1,84 @@
+/*
+ * libvirt-gconfig-domain-chardev-source-unix.c: libvirt domain chardev unix configuration
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ * Copyright (C) 2015 T A Mahadevan
+ *
+ * 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/>.
+ *
+ * Author: T A Mahadevan <ta.mahadevan@xxxxxxxxx>
+ */
+
+#include <config.h>
+
+#include "libvirt-gconfig/libvirt-gconfig.h"
+#include "libvirt-gconfig/libvirt-gconfig-private.h"
+
+#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_UNIX_GET_PRIVATE(obj)                         \
+        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_UNIX, GVirConfigDomainChardevSourceUnixPrivate))
+
+struct _GVirConfigDomainChardevSourceUnixPrivate
+{
+    gboolean unused;
+};
+
+G_DEFINE_TYPE(GVirConfigDomainChardevSourceUnix, gvir_config_domain_chardev_source_unix, GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE);
+
+
+static void gvir_config_domain_chardev_source_unix_class_init(GVirConfigDomainChardevSourceUnixClass *klass)
+{
+    g_type_class_add_private(klass, sizeof(GVirConfigDomainChardevSourceUnixPrivate));
+}
+
+
+static void gvir_config_domain_chardev_source_unix_init(GVirConfigDomainChardevSourceUnix *source)
+{
+    g_debug("Init GVirConfigDomainChardevSourceUnix=%p", source);
+
+    source->priv = GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_UNIX_GET_PRIVATE(source);
+}
+
+
+GVirConfigDomainChardevSourceUnix *gvir_config_domain_chardev_source_unix_new(void)
+{
+    GVirConfigObject *object;
+
+    /* the name of the root node is just a placeholder, it will be
+     * overwritten when the GVirConfigDomainChardevSourceUnix is attached to a
+     * GVirConfigDomainChardev
+     */
+    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_UNIX, "dummy", NULL);
+    gvir_config_object_set_attribute(object, "type", "unix", NULL);
+    return GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_UNIX(object);
+}
+
+
+GVirConfigDomainChardevSourceUnix *gvir_config_domain_chardev_source_unix_new_from_xml(const gchar *xml,
+                                                                                       GError **error)
+{
+    GVirConfigObject *object;
+
+    /* the name of the root node is just a placeholder, it will be
+     * overwritten when the GVirConfigDomainChardevSourceUnix is attached to a
+     * GVirConfigDomainChardev
+     */
+    object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_UNIX,
+                                             "dummy", NULL, xml, error);
+    if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "unix") != 0) {
+        g_object_unref(G_OBJECT(object));
+        g_return_val_if_reached(NULL);
+    }
+    return GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_UNIX(object);
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-unix.h b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-unix.h
new file mode 100644
index 0000000..42891ea
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-unix.h
@@ -0,0 +1,68 @@
+/*
+ * libvirt-gconfig-domain-chardev-source-unix.h: libvirt domain chardev unix configuration
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ * Copyright (C) 2015 T A Mahadevan.
+ *
+ * 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/>.
+ *
+ * Author: T A Mahadevan <ta.mahadevan@xxxxxxxxx>
+ */
+
+#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
+#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
+#endif
+
+#ifndef __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_SOURCE_UNIX_H__
+#define __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_SOURCE_UNIX_H__
+
+G_BEGIN_DECLS
+
+#define GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_UNIX            (gvir_config_domain_chardev_source_unix_get_type ())
+#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_UNIX(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_UNIX, GVirConfigDomainChardevSourceUnix))
+#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_UNIX_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_UNIX, GVirConfigDomainChardevSourceUnixClass))
+#define GVIR_CONFIG_IS_DOMAIN_CHARDEV_SOURCE_UNIX(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_UNIX))
+#define GVIR_CONFIG_IS_DOMAIN_CHARDEV_SOURCE_UNIX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_UNIX))
+#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_UNIX_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_UNIX, GVirConfigDomainChardevSourceUnixClass))
+
+typedef struct _GVirConfigDomainChardevSourceUnix GVirConfigDomainChardevSourceUnix;
+typedef struct _GVirConfigDomainChardevSourceUnixPrivate GVirConfigDomainChardevSourceUnixPrivate;
+typedef struct _GVirConfigDomainChardevSourceUnixClass GVirConfigDomainChardevSourceUnixClass;
+
+struct _GVirConfigDomainChardevSourceUnix
+{
+    GVirConfigDomainChardevSource parent;
+
+    GVirConfigDomainChardevSourceUnixPrivate *priv;
+
+    /* Do not add fields to this struct */
+};
+
+struct _GVirConfigDomainChardevSourceUnixClass
+{
+    GVirConfigDomainChardevSourceClass parent_class;
+
+    gpointer padding[20];
+};
+
+
+GType gvir_config_domain_chardev_source_unix_get_type(void);
+
+GVirConfigDomainChardevSourceUnix *gvir_config_domain_chardev_source_unix_new(void);
+GVirConfigDomainChardevSourceUnix *gvir_config_domain_chardev_source_unix_new_from_xml(const gchar *xml,
+                                                                                       GError **error);
+G_END_DECLS
+
+#endif /* __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_SOURCE_UNIX_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h
index afb9b7b..4624003 100644
--- a/libvirt-gconfig/libvirt-gconfig.h
+++ b/libvirt-gconfig/libvirt-gconfig.h
@@ -48,6 +48,7 @@
 #include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spiceport.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source-spicevmc.h>
+#include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source-unix.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-channel.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-clock.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-console.h>
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 6ce1511..6267197 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -724,4 +724,11 @@ global:
     gvir_config_domain_filesys_set_driver_format;
 } LIBVIRT_GCONFIG_0.2.0;
 
+LIBVIRT_GCONFIG_0.2.2 {
+global:
+	gvir_config_domain_chardev_source_unix_get_type;
+	gvir_config_domain_chardev_source_unix_new;
+	gvir_config_domain_chardev_source_unix_new_from_xml;
+} LIBVIRT_GCONFIG_0.2.1;
+
 # .... define new API here using predicted next version number ....
diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c
index 1a512de..79c242f 100644
--- a/libvirt-gconfig/tests/test-domain-create.c
+++ b/libvirt-gconfig/tests/test-domain-create.c
@@ -401,6 +401,20 @@ int main(int argc, char **argv)
     redirdev = create_redirdev(0, 5);
     devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(redirdev));
 
+    /* unix channel */
+    GVirConfigDomainChardevSourceUnix *unix_source;
+
+    channel = gvir_config_domain_channel_new();
+    gvir_config_domain_channel_set_target_type(channel,
+                                               GVIR_CONFIG_DOMAIN_CHANNEL_TARGET_VIRTIO);
+    gvir_config_domain_channel_set_target_name(channel, "org.qemu.guest_agent.0");
+    unix_source = gvir_config_domain_chardev_source_unix_new();
+    gvir_config_domain_chardev_set_source(GVIR_CONFIG_DOMAIN_CHARDEV(channel),
+                                          GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE(unix_source));
+    g_object_unref(G_OBJECT(unix_source));
+    devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(channel));
+
+
     gvir_config_domain_set_devices(domain, devices);
     g_list_foreach(devices, (GFunc)g_object_unref, NULL);
     g_list_free(devices);
diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c
index bd2daa6..606c7ef 100644
--- a/tests/test-gconfig.c
+++ b/tests/test-gconfig.c
@@ -546,6 +546,7 @@ static void test_domain_device_channel(void)
     GVirConfigDomainChannel *channel;
     GVirConfigDomainChardevSourceSpiceVmc *spicevmc;
     GVirConfigDomainChardevSourceSpicePort *spiceport;
+    GVirConfigDomainChardevSourceUnix *unix_source;
 
     channel = gvir_config_domain_channel_new();
     gvir_config_domain_channel_set_target_type(channel,
@@ -570,6 +571,16 @@ static void test_domain_device_channel(void)
     gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(channel));
     g_object_unref(G_OBJECT(channel));
 
+    channel = gvir_config_domain_channel_new();
+    gvir_config_domain_channel_set_target_type(channel,
+                                               GVIR_CONFIG_DOMAIN_CHANNEL_TARGET_VIRTIO);
+    gvir_config_domain_channel_set_target_name(channel, "org.qemu.guest_agent.0");
+    unix_source = gvir_config_domain_chardev_source_unix_new();
+    gvir_config_domain_chardev_set_source(GVIR_CONFIG_DOMAIN_CHARDEV(channel),
+                                          GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE(unix_source));
+    g_object_unref(G_OBJECT(unix_source));
+    gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE(channel));
+    g_object_unref(G_OBJECT(channel));
     check_xml(domain, "gconfig-domain-device-channel.xml");
 
     g_object_unref(G_OBJECT(domain));
diff --git a/tests/xml/gconfig-domain-device-channel.xml b/tests/xml/gconfig-domain-device-channel.xml
index 27dd28a..583d8be 100644
--- a/tests/xml/gconfig-domain-device-channel.xml
+++ b/tests/xml/gconfig-domain-device-channel.xml
@@ -7,5 +7,8 @@
       <target type="virtio" name="org.spice-space.webdav.0"/>
       <source channel="org.spice-space.webdav.0"/>
     </channel>
+    <channel type="unix">
+      <target type="virtio" name="org.qemu.guest_agent.0"/>
+    </channel>
   </devices>
 </domain>
-- 
1.9.1

--
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]