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

[libvirt] [libvirt-glib v3 2/2] Add GVirConfigDomainCpu class



From: "Zeeshan Ali (Khattak)" <zeeshanak gnome org>

API to handle 'domain/cpu' nodes.
---
 libvirt-gconfig/Makefile.am                  |    2 +
 libvirt-gconfig/libvirt-gconfig-domain-cpu.c |  138 ++++++++++++++++++++++++++
 libvirt-gconfig/libvirt-gconfig-domain-cpu.h |   88 ++++++++++++++++
 libvirt-gconfig/libvirt-gconfig-domain.c     |   38 +++++++
 libvirt-gconfig/libvirt-gconfig-domain.h     |    4 +
 libvirt-gconfig/libvirt-gconfig.h            |    1 +
 libvirt-gconfig/libvirt-gconfig.sym          |   14 +++
 7 files changed, 285 insertions(+)
 create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-cpu.c
 create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-cpu.h

diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am
index 52f2d52..5a80123 100644
--- a/libvirt-gconfig/Makefile.am
+++ b/libvirt-gconfig/Makefile.am
@@ -33,6 +33,7 @@ GCONFIG_HEADER_FILES = \
 			libvirt-gconfig-domain-console.h \
 			libvirt-gconfig-domain-controller.h \
 			libvirt-gconfig-domain-controller-usb.h \
+			libvirt-gconfig-domain-cpu.h \
 			libvirt-gconfig-domain-cpu-feature.h \
 			libvirt-gconfig-domain-device.h \
 			libvirt-gconfig-domain-disk.h \
@@ -103,6 +104,7 @@ GCONFIG_SOURCE_FILES = \
 			libvirt-gconfig-domain-console.c \
 			libvirt-gconfig-domain-controller.c \
 			libvirt-gconfig-domain-controller-usb.c \
+			libvirt-gconfig-domain-cpu.c \
 			libvirt-gconfig-domain-cpu-feature.c \
 			libvirt-gconfig-domain-device.c \
 			libvirt-gconfig-domain-disk.c \
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-cpu.c b/libvirt-gconfig/libvirt-gconfig-domain-cpu.c
new file mode 100644
index 0000000..d669a6b
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-domain-cpu.c
@@ -0,0 +1,138 @@
+/*
+ * libvirt-gconfig-domain-cpu.c: libvirt Domain CPU
+ *
+ * Copyright (C) 2008 Daniel P. Berrange
+ * Copyright (C) 2010-2012 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ * Authors: Zeeshan Ali <zeenix redhat com>
+ *          Daniel P. Berrange <berrange redhat com>
+ */
+
+#include <config.h>
+
+#include "libvirt-gconfig/libvirt-gconfig.h"
+#include "libvirt-gconfig/libvirt-gconfig-private.h"
+
+#define GVIR_CONFIG_DOMAIN_CPU_GET_PRIVATE(obj)                         \
+        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_CPU, GVirConfigDomainCpuPrivate))
+
+struct _GVirConfigDomainCpuPrivate
+{
+    gboolean unused;
+};
+
+G_DEFINE_TYPE(GVirConfigDomainCpu, gvir_config_domain_cpu, GVIR_CONFIG_TYPE_CAPABILITIES_CPU);
+
+static GList *
+_gvir_config_domain_cpu_get_features(GVirConfigCapabilitiesCpu *cpu);
+
+static void gvir_config_domain_cpu_class_init(GVirConfigDomainCpuClass *klass)
+{
+    GVirConfigCapabilitiesCpuClass *capabilities_class;
+
+    capabilities_class = GVIR_CONFIG_CAPABILITIES_CPU_CLASS(klass);
+    capabilities_class->get_features = _gvir_config_domain_cpu_get_features;
+
+    g_type_class_add_private(klass, sizeof(GVirConfigDomainCpuPrivate));
+}
+
+static void gvir_config_domain_cpu_init(GVirConfigDomainCpu *cpu)
+{
+    g_debug("Init GVirConfigDomainCpu=%p", cpu);
+
+    cpu->priv = GVIR_CONFIG_DOMAIN_CPU_GET_PRIVATE(cpu);
+}
+
+GVirConfigDomainCpu *gvir_config_domain_cpu_new(void)
+{
+    GVirConfigObject *object;
+
+    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_CPU, "cpu", NULL);
+
+    return GVIR_CONFIG_DOMAIN_CPU(object);
+}
+
+GVirConfigDomainCpu *gvir_config_domain_cpu_new_from_xml(const gchar *xml,
+                                                         GError **error)
+{
+    GVirConfigObject *object;
+
+    object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_CPU,
+                                             "cpu",
+                                             NULL,
+                                             xml,
+                                             error);
+
+    return GVIR_CONFIG_DOMAIN_CPU(object);
+}
+
+static GList *
+_gvir_config_domain_cpu_get_features(GVirConfigCapabilitiesCpu *cpu)
+{
+    return gvir_config_capabilities_cpu_get_features_with_type(
+                        cpu, GVIR_CONFIG_TYPE_DOMAIN_CPU_FEATURE);
+}
+
+GVirConfigDomainCpuMatchPolicy
+gvir_config_domain_cpu_get_match_policy(GVirConfigDomainCpu *cpu)
+{
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_CPU(cpu),
+                         GVIR_CONFIG_DOMAIN_CPU_MATCH_POLICY_EXACT);
+
+    return gvir_config_object_get_attribute_genum
+                (GVIR_CONFIG_OBJECT(cpu),
+                 NULL,
+                 "match",
+                 GVIR_CONFIG_TYPE_DOMAIN_CPU_MATCH_POLICY,
+                 GVIR_CONFIG_DOMAIN_CPU_MATCH_POLICY_EXACT);
+}
+
+void gvir_config_domain_cpu_set_match_policy(GVirConfigDomainCpu *cpu,
+                                             GVirConfigDomainCpuMatchPolicy policy)
+{
+    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CPU(cpu));
+
+    gvir_config_object_set_attribute_with_type
+                (GVIR_CONFIG_OBJECT(cpu),
+                 "match", GVIR_CONFIG_TYPE_DOMAIN_CPU_MATCH_POLICY, policy,
+                 NULL);
+}
+
+GVirConfigDomainCpuMode
+gvir_config_domain_cpu_get_mode(GVirConfigDomainCpu *cpu)
+{
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_CPU(cpu),
+                         GVIR_CONFIG_DOMAIN_CPU_MODE_CUSTOM);
+
+    return gvir_config_object_get_attribute_genum
+                (GVIR_CONFIG_OBJECT(cpu),
+                 NULL,
+                 "mode",
+                 GVIR_CONFIG_TYPE_DOMAIN_CPU_MODE,
+                 GVIR_CONFIG_DOMAIN_CPU_MODE_CUSTOM);
+}
+
+void gvir_config_domain_cpu_set_mode(GVirConfigDomainCpu *cpu,
+                                     GVirConfigDomainCpuMode mode)
+{
+    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CPU(cpu));
+
+    gvir_config_object_set_attribute_with_type
+                (GVIR_CONFIG_OBJECT(cpu),
+                 "mode", GVIR_CONFIG_TYPE_DOMAIN_CPU_MODE, mode,
+                 NULL);
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-cpu.h b/libvirt-gconfig/libvirt-gconfig-domain-cpu.h
new file mode 100644
index 0000000..0b14975
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-domain-cpu.h
@@ -0,0 +1,88 @@
+/*
+ * libvirt-gconfig-domain-cpu.h: libvirt Domain CPU
+ *
+ * Copyright (C) 2010-2012 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ * Authors: Zeeshan Ali <zeenix redhat com>
+ *          Daniel P. Berrange <berrange redhat com>
+ */
+
+#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_CPU_H__
+#define __LIBVIRT_GCONFIG_DOMAIN_CPU_H__
+
+G_BEGIN_DECLS
+
+#define GVIR_CONFIG_TYPE_DOMAIN_CPU            (gvir_config_domain_cpu_get_type ())
+#define GVIR_CONFIG_DOMAIN_CPU(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_CPU, GVirConfigDomainCpu))
+#define GVIR_CONFIG_DOMAIN_CPU_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_CPU, GVirConfigDomainCpuClass))
+#define GVIR_CONFIG_IS_DOMAIN_CPU(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_CPU))
+#define GVIR_CONFIG_IS_DOMAIN_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_CPU))
+#define GVIR_CONFIG_DOMAIN_CPU_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_CPU, GVirConfigDomainCpuClass))
+
+typedef struct _GVirConfigDomainCpu GVirConfigDomainCpu;
+typedef struct _GVirConfigDomainCpuPrivate GVirConfigDomainCpuPrivate;
+typedef struct _GVirConfigDomainCpuClass GVirConfigDomainCpuClass;
+
+struct _GVirConfigDomainCpu
+{
+    GVirConfigCapabilitiesCpu parent;
+
+    GVirConfigDomainCpuPrivate *priv;
+
+    /* Do not add fields to this struct */
+};
+
+struct _GVirConfigDomainCpuClass
+{
+    GVirConfigCapabilitiesCpuClass parent_class;
+
+    gpointer padding[20];
+};
+
+typedef enum {
+    GVIR_CONFIG_DOMAIN_CPU_MATCH_POLICY_MINIMUM,
+    GVIR_CONFIG_DOMAIN_CPU_MATCH_POLICY_EXACT,
+    GVIR_CONFIG_DOMAIN_CPU_MATCH_POLICY_STRICT
+} GVirConfigDomainCpuMatchPolicy;
+
+typedef enum {
+    GVIR_CONFIG_DOMAIN_CPU_MODE_CUSTOM,
+    GVIR_CONFIG_DOMAIN_CPU_MODE_HOST_MODEL,
+    GVIR_CONFIG_DOMAIN_CPU_MODE_HOST_PASSTHROUGH
+} GVirConfigDomainCpuMode;
+
+GType gvir_config_domain_cpu_get_type(void);
+GVirConfigDomainCpu *gvir_config_domain_cpu_new(void);
+GVirConfigDomainCpu *gvir_config_domain_cpu_new_from_xml(const gchar *xml,
+                                                         GError **error);
+void
+gvir_config_domain_cpu_set_match_policy(GVirConfigDomainCpu *cpu,
+                                        GVirConfigDomainCpuMatchPolicy policy);
+GVirConfigDomainCpuMatchPolicy
+gvir_config_domain_cpu_get_match_policy(GVirConfigDomainCpu *cpu);
+void gvir_config_domain_cpu_set_mode(GVirConfigDomainCpu *cpu,
+                                     GVirConfigDomainCpuMode mode);
+GVirConfigDomainCpuMode
+gvir_config_domain_cpu_get_mode(GVirConfigDomainCpu *cpu);
+
+G_END_DECLS
+
+#endif /* __LIBVIRT_GCONFIG_DOMAIN_CPU_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c
index fcb3172..2ca478f 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -632,3 +632,41 @@ gchar *gvir_config_domain_get_custom_xml(GVirConfigDomain *domain,
                                      lookup_namespaced_node, &data);
     return gvir_config_xml_node_to_string(data.node);
 }
+
+/**
+ * gvir_config_domain_get_cpu:
+ * @domain: a #GVirConfigDomain
+ *
+ * Gets the CPU configuration of @domain
+ *
+ * Returns: (transfer full): A #GVirConfigDomainCpu. The returned object
+ * should be unreffed with g_object_unref() when no longer needed.
+ */
+GVirConfigDomainCpu *gvir_config_domain_get_cpu(GVirConfigDomain *domain)
+{
+    GVirConfigObject *object;
+
+    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN(domain), NULL);
+
+    object = gvir_config_object_get_child_with_type(GVIR_CONFIG_OBJECT(domain),
+                                                    "cpu",
+                                                    GVIR_CONFIG_TYPE_DOMAIN_CPU);
+
+    return GVIR_CONFIG_DOMAIN_CPU(object);
+}
+
+/**
+ * gvir_config_domain_set_cpu:
+ * @domain: a #GVirConfigDomain
+ * @cpu: (allow-none):
+ */
+void gvir_config_domain_set_cpu(GVirConfigDomain *domain,
+                                GVirConfigDomainCpu *cpu)
+{
+    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN(domain));
+    g_return_if_fail(cpu != NULL || GVIR_CONFIG_IS_DOMAIN_CPU(cpu));
+
+    gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(domain),
+                                      "cpu",
+                                      GVIR_CONFIG_OBJECT(cpu));
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h
index af8b86a..b9a0dce 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain.h
@@ -31,6 +31,7 @@
 #include <libvirt-gconfig/libvirt-gconfig-domain-os.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-device.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-seclabel.h>
+#include <libvirt-gconfig/libvirt-gconfig-domain-cpu.h>
 
 G_BEGIN_DECLS
 
@@ -137,6 +138,9 @@ gboolean gvir_config_domain_set_custom_xml(GVirConfigDomain *domain,
                                            GError **error);
 gchar *gvir_config_domain_get_custom_xml(GVirConfigDomain *domain,
                                          const gchar *ns_uri);
+GVirConfigDomainCpu *gvir_config_domain_get_cpu(GVirConfigDomain *domain);
+void gvir_config_domain_set_cpu(GVirConfigDomain *domain,
+                                GVirConfigDomainCpu *cpu);
 
 G_END_DECLS
 
diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h
index 41c3d80..4b5ccbd 100644
--- a/libvirt-gconfig/libvirt-gconfig.h
+++ b/libvirt-gconfig/libvirt-gconfig.h
@@ -50,6 +50,7 @@
 #include <libvirt-gconfig/libvirt-gconfig-domain-console.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-controller.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-controller-usb.h>
+#include <libvirt-gconfig/libvirt-gconfig-domain-cpu.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-cpu-feature.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-device.h>
 #include <libvirt-gconfig/libvirt-gconfig-domain-disk.h>
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index a0286a1..7507d45 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -438,6 +438,20 @@ LIBVIRT_GCONFIG_0.1.0 {
 	gvir_config_capabilities_cpu_topology_set_sockets;
 	gvir_config_capabilities_cpu_topology_set_threads;
 
+	gvir_config_domain_get_cpu;
+	gvir_config_domain_set_cpu;
+
+	gvir_config_domain_cpu_get_type;
+	gvir_config_domain_cpu_match_policy_get_type;
+	gvir_config_domain_cpu_mode_get_type;
+	gvir_config_domain_cpu_get_features;
+	gvir_config_domain_cpu_get_match_policy;
+	gvir_config_domain_cpu_set_match_policy;
+	gvir_config_domain_cpu_get_mode;
+	gvir_config_domain_cpu_set_mode;
+	gvir_config_domain_cpu_new;
+	gvir_config_domain_cpu_new_from_xml;
+
 	gvir_config_domain_cpu_feature_get_type;
 	gvir_config_domain_cpu_feature_new;
 	gvir_config_domain_cpu_feature_new_from_xml;
-- 
1.7.10.4


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