[libvirt] [libvirt-glib 1/3] API to get capabilities from connection

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> --- libvirt-gconfig/libvirt-gconfig-capabilities.c | 4 --- libvirt-gobject/libvirt-gobject-connection.c | 32 ++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-connection.h | 3 ++ libvirt-gobject/libvirt-gobject.sym | 1 + 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 4c4df68..3d9d036 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -54,8 +54,6 @@ GVirConfigCapabilities *gvir_config_capabilities_new(void) { GVirConfigObject *object; - /* FIXME: what is the XML root of the capability node? I suspect it is - * either 'guest' or 'host' */ object = gvir_config_object_new(GVIR_CONFIG_TYPE_CAPABILITIES, "capabilities", DATADIR "/libvirt/schemas/capability.rng"); @@ -67,8 +65,6 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, { GVirConfigObject *object; - /* FIXME: what is the XML root of the capability node? I suspect it is - * either 'guest' or 'host' */ object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_CAPABILITIES, "capabilities", DATADIR "/libvirt/schemas/capability.rng", diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index baeeb1c..4f04f98 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -1387,3 +1387,35 @@ GVirNodeInfo *gvir_connection_get_node_info(GVirConnection *conn, return ret; } + +/** + * gvir_connection_get_capabilities: + * @conn: the connection + * @err: return location for any #GError + * + * Return value: (transfer full): a #GVirConfigCapabilities or NULL + */ +GVirConfigCapabilities *gvir_connection_get_capabilities(GVirConnection *conn, + GError **err) +{ + GVirConfigCapabilities *caps; + char *caps_xml; + + g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL); + g_return_val_if_fail(err == NULL || *err == NULL, NULL); + g_return_val_if_fail(conn->priv->conn, NULL); + + caps_xml = virConnectGetCapabilities(conn->priv->conn); + if (caps_xml == NULL) { + gvir_set_error_literal(err, GVIR_CONNECTION_ERROR, + 0, + "Unable to get capabilities"); + return NULL; + } + + caps = gvir_config_capabilities_new_from_xml(caps_xml, err); + free(caps_xml); + + return caps; +} + diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h index 3cc60a2..8c48f67 100644 --- a/libvirt-gobject/libvirt-gobject-connection.h +++ b/libvirt-gobject/libvirt-gobject-connection.h @@ -191,6 +191,9 @@ GVirStream *gvir_connection_get_stream(GVirConnection *conn, GVirNodeInfo *gvir_connection_get_node_info(GVirConnection *conn, GError **err); +GVirConfigCapabilities *gvir_connection_get_capabilities(GVirConnection *conn, + GError **err); + G_END_DECLS #endif /* __LIBVIRT_GOBJECT_CONNECTION_H__ */ diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index f43836f..0c9fc37 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -31,6 +31,7 @@ LIBVIRT_GOBJECT_0.0.8 { gvir_connection_create_storage_pool; gvir_connection_start_domain; gvir_connection_get_node_info; + gvir_connection_get_capabilities; gvir_domain_device_get_type; gvir_domain_device_get_domain; -- 1.7.7.6

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> Not quite complete but its a good start. --- libvirt-gconfig/Makefile.am | 11 ++- ...virt-gconfig-capabilities-cpu-feature-private.h | 39 ++++++ .../libvirt-gconfig-capabilities-cpu-feature.c | 77 ++++++++++++ .../libvirt-gconfig-capabilities-cpu-feature.h | 67 ++++++++++ .../libvirt-gconfig-capabilities-cpu-private.h | 39 ++++++ libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c | 127 ++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h | 69 +++++++++++ .../libvirt-gconfig-capabilities-host-private.h | 39 ++++++ .../libvirt-gconfig-capabilities-host.c | 98 +++++++++++++++ .../libvirt-gconfig-capabilities-host.h | 70 +++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.c | 27 ++++ libvirt-gconfig/libvirt-gconfig-capabilities.h | 3 +- libvirt-gconfig/libvirt-gconfig-private.h | 3 + libvirt-gconfig/libvirt-gconfig.h | 3 + libvirt-gconfig/libvirt-gconfig.sym | 13 ++ 15 files changed, 683 insertions(+), 2 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-host.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-host.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index fd32c3d..9bd0df8 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -12,6 +12,9 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-main.h \ libvirt-gconfig-object.h \ libvirt-gconfig-capabilities.h \ + libvirt-gconfig-capabilities-host.h \ + libvirt-gconfig-capabilities-cpu.h \ + libvirt-gconfig-capabilities-cpu-feature.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-address.h \ libvirt-gconfig-domain-address-pci.h \ @@ -67,11 +70,17 @@ noinst_HEADERS = \ libvirt-gconfig-domain-device-private.h \ libvirt-gconfig-helpers-private.h \ libvirt-gconfig-object-private.h \ - libvirt-gconfig-xml-doc.h + libvirt-gconfig-xml-doc.h \ + libvirt-gconfig-capabilities-host-private.h \ + libvirt-gconfig-capabilities-cpu-private.h \ + libvirt-gconfig-capabilities-cpu-feature-private.h GCONFIG_SOURCE_FILES = \ libvirt-gconfig-object.c \ libvirt-gconfig-main.c \ libvirt-gconfig-capabilities.c \ + libvirt-gconfig-capabilities-host.c \ + libvirt-gconfig-capabilities-cpu.c \ + libvirt-gconfig-capabilities-cpu-feature.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-address.c \ libvirt-gconfig-domain-address-pci.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h new file mode 100644 index 0000000..d99e374 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h @@ -0,0 +1,39 @@ +/* + * libvirt-gconfig-capabilities-cpu-feature-private.h: libvirt CPU feature capabilities + * + * 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_CAPABILITIES_CPU_FEATURE_PRIVATE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_PRIVATE_H__ + +G_BEGIN_DECLS + +GVirConfigCapabilitiesCPUFeature * +gvir_config_capabilities_cpu_feature_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c new file mode 100644 index 0000000..d7f02c4 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c @@ -0,0 +1,77 @@ +/* + * libvirt-gconfig-capabilities-cpu-feature.c: libvirt CPU feature capabilities + * + * 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_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCPUFeaturePrivate)) + +struct _GVirConfigCapabilitiesCPUFeaturePrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCPUFeature, gvir_config_capabilities_cpu_feature, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_cpu_feature_class_init(GVirConfigCapabilitiesCPUFeatureClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCPUFeaturePrivate)); +} + +static void gvir_config_capabilities_cpu_feature_init(GVirConfigCapabilitiesCPUFeature *conn) +{ + g_debug("Init GVirConfigCapabilitiesCPUFeature=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesCPUFeature * +gvir_config_capabilities_cpu_feature_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_CPU_FEATURE(object); +} + +const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCPUFeature *caps) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + if (g_strcmp0((const gchar *)node->name, "feature") == 0) + return gvir_config_xml_get_attribute_content(node, "name"); + else + return (const gchar *)node->name; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h new file mode 100644 index 0000000..b96c9f1 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h @@ -0,0 +1,67 @@ +/* + * libvirt-gconfig-capabilities-cpu-feature.h: libvirt CPU feature capabilities + * + * 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_CAPABILITIES_CPU_FEATURE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE (gvir_config_capabilities_cpu_feature_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCPUFeature)) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCPUFeatureClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE)) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCPUFeatureClass)) + +typedef struct _GVirConfigCapabilitiesCPUFeature GVirConfigCapabilitiesCPUFeature; +typedef struct _GVirConfigCapabilitiesCPUFeaturePrivate GVirConfigCapabilitiesCPUFeaturePrivate; +typedef struct _GVirConfigCapabilitiesCPUFeatureClass GVirConfigCapabilitiesCPUFeatureClass; + +struct _GVirConfigCapabilitiesCPUFeature +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCPUFeaturePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCPUFeatureClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_feature_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCPUFeature *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h new file mode 100644 index 0000000..beebc3b --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h @@ -0,0 +1,39 @@ +/* + * libvirt-gconfig-capabilities-cpu-private.h: libvirt CPU capabilities + * + * Copyright (C) 2010-2011 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_CAPABILITIES_CPU_PRIVATE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_PRIVATE_H__ + +G_BEGIN_DECLS + +GVirConfigCapabilitiesCPU * +gvir_config_capabilities_cpu_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c new file mode 100644 index 0000000..f1488a9 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c @@ -0,0 +1,127 @@ +/* + * libvirt-gconfig-capabilities-cpu.c: libvirt CPU capabilities + * + * 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_CAPABILITIES_CPU_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCPUPrivate)) + +struct _GVirConfigCapabilitiesCPUPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCPU, gvir_config_capabilities_cpu, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_cpu_class_init(GVirConfigCapabilitiesCPUClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCPUPrivate)); +} + +static void gvir_config_capabilities_cpu_init(GVirConfigCapabilitiesCPU *conn) +{ + g_debug("Init GVirConfigCapabilitiesCPU=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_CPU_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesCPU * +gvir_config_capabilities_cpu_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_CPU, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_CPU(object); +} + +const gchar * +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCPU *caps) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + return gvir_config_xml_get_child_element_content(node, "arch"); +} + +struct GetFeatureData { + GVirConfigXmlDoc *doc; + GList *features; +}; + +static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigCapabilitiesCPUFeature *feature; + + if (g_strcmp0((const gchar *)node->name, "feature") != 0) + return TRUE; + + feature = gvir_config_capabilities_cpu_feature_new_from_tree(data->doc, node); + if (feature != NULL) + data->features = g_list_append(data->features, feature); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_cpu_get_features: + * + * Gets the features of this CPU. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesCPUFeature) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesCPUFeature. + */ +GList * +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCPU *caps) +{ + struct GetFeatureData data; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU(caps), NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + data.features = NULL; + + gvir_config_xml_foreach_child(node, add_feature, &data); + + g_clear_object(&data.doc); + + return data.features; +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h new file mode 100644 index 0000000..abad676 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h @@ -0,0 +1,69 @@ +/* + * libvirt-gconfig-capabilities-cpu.h: libvirt CPU capabilities + * + * 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_CAPABILITIES_CPU_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU (gvir_config_capabilities_cpu_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCPU)) +#define GVIR_CONFIG_CAPABILITIES_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCPUClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU)) +#define GVIR_CONFIG_CAPABILITIES_CPU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCPUClass)) + +typedef struct _GVirConfigCapabilitiesCPU GVirConfigCapabilitiesCPU; +typedef struct _GVirConfigCapabilitiesCPUPrivate GVirConfigCapabilitiesCPUPrivate; +typedef struct _GVirConfigCapabilitiesCPUClass GVirConfigCapabilitiesCPUClass; + +struct _GVirConfigCapabilitiesCPU +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCPUPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCPUClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCPU *caps); +GList * +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCPU *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h new file mode 100644 index 0000000..732b64c --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h @@ -0,0 +1,39 @@ +/* + * libvirt-gconfig-capabilities-host-private.h: libvirt host capabilities + * + * 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_CAPABILITIES_HOST_PRIVATE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_HOST_PRIVATE_H__ + +G_BEGIN_DECLS + +GVirConfigCapabilitiesHost * +gvir_config_capabilities_host_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_HOST_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.c b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c new file mode 100644 index 0000000..becaf6d --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c @@ -0,0 +1,98 @@ +/* + * libvirt-gconfig-capabilities-host.c: libvirt host capabilities + * + * 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_CAPABILITIES_HOST_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostPrivate)) + +struct _GVirConfigCapabilitiesHostPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesHost, gvir_config_capabilities_host, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_host_class_init(GVirConfigCapabilitiesHostClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesHostPrivate)); +} + +static void gvir_config_capabilities_host_init(GVirConfigCapabilitiesHost *conn) +{ + g_debug("Init GVirConfigCapabilitiesHost=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_HOST_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesHost * +gvir_config_capabilities_host_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_HOST, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_HOST(object); +} + +const gchar * +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *caps) +{ + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(caps), "uuid"); +} + +/** + * gvir_config_capabilities_host_get_cpu: + * + * Gets the CPU capabilities of the host. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesCPU. + */ +GVirConfigCapabilitiesCPU * +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *caps) +{ + GVirConfigXmlDoc *doc; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_HOST(caps), NULL); + + g_object_get(G_OBJECT(caps), "doc", &doc, NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + node = gvir_config_xml_get_element(node, "cpu", NULL); + g_return_val_if_fail(node != NULL, NULL); + + return gvir_config_capabilities_cpu_new_from_tree(doc, node); +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.h b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h new file mode 100644 index 0000000..34ee19e --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h @@ -0,0 +1,70 @@ +/* + * libvirt-gconfig-capabilities-host.h: libvirt host capabilities + * + * 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_CAPABILITIES_HOST_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_HOST_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_HOST (gvir_config_capabilities_host_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_HOST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHost)) +#define GVIR_CONFIG_CAPABILITIES_HOST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_HOST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST)) +#define GVIR_CONFIG_IS_CAPABILITIES_HOST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_HOST)) +#define GVIR_CONFIG_CAPABILITIES_HOST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostClass)) + +typedef struct _GVirConfigCapabilitiesHost GVirConfigCapabilitiesHost; +typedef struct _GVirConfigCapabilitiesHostPrivate GVirConfigCapabilitiesHostPrivate; +typedef struct _GVirConfigCapabilitiesHostClass GVirConfigCapabilitiesHostClass; + +struct _GVirConfigCapabilitiesHost +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesHostPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesHostClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_host_get_type(void); + +const gchar * +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *caps); + +GVirConfigCapabilitiesCPU * +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_HOST_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 3d9d036..9518a30 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -24,6 +24,7 @@ #include <config.h> #include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" #define GVIR_CONFIG_CAPABILITIES_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES, GVirConfigCapabilitiesPrivate)) @@ -71,3 +72,29 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, xml, error); return GVIR_CONFIG_CAPABILITIES(object); } + +/** + * gvir_config_capabilities_get_host: + * + * Gets the host capabilities. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesHost. + */ +GVirConfigCapabilitiesHost * +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps) +{ + GVirConfigXmlDoc *doc; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL); + + g_object_get(G_OBJECT(caps), "doc", &doc, NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + node = gvir_config_xml_get_element(node, "host", NULL); + g_return_val_if_fail(node != NULL, NULL); + + return gvir_config_capabilities_host_new_from_tree(doc, node); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h index 733886d..18edaf7 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h @@ -56,12 +56,13 @@ struct _GVirConfigCapabilitiesClass gpointer padding[20]; }; - GType gvir_config_capabilities_get_type(void); GVirConfigCapabilities *gvir_config_capabilities_new(void); GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, GError **error); +GVirConfigCapabilitiesHost * +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-private.h b/libvirt-gconfig/libvirt-gconfig-private.h index d4df030..845a883 100644 --- a/libvirt-gconfig/libvirt-gconfig-private.h +++ b/libvirt-gconfig/libvirt-gconfig-private.h @@ -24,6 +24,9 @@ #define __LIBVIRT_GCONFIG_PRIVATE_H__ #include <libvirt-gconfig/libvirt-gconfig-domain-device-private.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h> #include <libvirt-gconfig/libvirt-gconfig-helpers-private.h> #include <libvirt-gconfig/libvirt-gconfig-object-private.h> #include <libvirt-gconfig/libvirt-gconfig-xml-doc.h> diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index bd16244..b2b7c15 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -28,6 +28,9 @@ #include <libvirt-gconfig/libvirt-gconfig-main.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-host.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index ffeb16b..b1df17b 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -6,6 +6,19 @@ LIBVIRT_GCONFIG_0.0.8 { gvir_config_capabilities_get_type; gvir_config_capabilities_new; gvir_config_capabilities_new_from_xml; + gvir_config_capabilities_get_host; + + gvir_config_capabilities_host_get_type; + gvir_config_capabilities_host_new_from_tree; + gvir_config_capabilities_host_get_uuid; + gvir_config_capabilities_host_get_cpu; + + gvir_config_capabilities_cpu_get_type; + gvir_config_capabilities_cpu_get_arch; + gvir_config_capabilities_cpu_get_features; + + gvir_config_capabilities_cpu_feature_get_type; + gvir_config_capabilities_cpu_feature_get_name; gvir_config_domain_add_device; gvir_config_domain_get_type; -- 1.7.7.6

On Tue, May 01, 2012 at 08:30:39PM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
Not quite complete but its a good start. --- libvirt-gconfig/Makefile.am | 11 ++- ...virt-gconfig-capabilities-cpu-feature-private.h | 39 ++++++ .../libvirt-gconfig-capabilities-cpu-feature.c | 77 ++++++++++++ .../libvirt-gconfig-capabilities-cpu-feature.h | 67 ++++++++++ .../libvirt-gconfig-capabilities-cpu-private.h | 39 ++++++ libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c | 127 ++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h | 69 +++++++++++ .../libvirt-gconfig-capabilities-host-private.h | 39 ++++++ .../libvirt-gconfig-capabilities-host.c | 98 +++++++++++++++ .../libvirt-gconfig-capabilities-host.h | 70 +++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.c | 27 ++++ libvirt-gconfig/libvirt-gconfig-capabilities.h | 3 +- libvirt-gconfig/libvirt-gconfig-private.h | 3 + libvirt-gconfig/libvirt-gconfig.h | 3 + libvirt-gconfig/libvirt-gconfig.sym | 13 ++ 15 files changed, 683 insertions(+), 2 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-host.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-host.h
diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index fd32c3d..9bd0df8 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -12,6 +12,9 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-main.h \ libvirt-gconfig-object.h \ libvirt-gconfig-capabilities.h \ + libvirt-gconfig-capabilities-host.h \ + libvirt-gconfig-capabilities-cpu.h \ + libvirt-gconfig-capabilities-cpu-feature.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-address.h \ libvirt-gconfig-domain-address-pci.h \ @@ -67,11 +70,17 @@ noinst_HEADERS = \ libvirt-gconfig-domain-device-private.h \ libvirt-gconfig-helpers-private.h \ libvirt-gconfig-object-private.h \ - libvirt-gconfig-xml-doc.h + libvirt-gconfig-xml-doc.h \ + libvirt-gconfig-capabilities-host-private.h \ + libvirt-gconfig-capabilities-cpu-private.h \ + libvirt-gconfig-capabilities-cpu-feature-private.h
I'd keep this one ordered alphabetically
GCONFIG_SOURCE_FILES = \ libvirt-gconfig-object.c \ libvirt-gconfig-main.c \ libvirt-gconfig-capabilities.c \ + libvirt-gconfig-capabilities-host.c \ + libvirt-gconfig-capabilities-cpu.c \ + libvirt-gconfig-capabilities-cpu-feature.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-address.c \ libvirt-gconfig-domain-address-pci.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h new file mode 100644 index 0000000..d99e374 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h @@ -0,0 +1,39 @@ +/* + * libvirt-gconfig-capabilities-cpu-feature-private.h: libvirt CPU feature capabilities + * + * 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
This is not really useful as -private files will never be included from libvirt-gconfig.h, just drop it (and we'll have to fix libvirt-gconfig-helpers-private.h as well). For what it's worth, for the device/... _new_from_tree methods I've been lazy and I've grouped them in the same -private file, but I'm fine with a separate file per class.
+ +#ifndef __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_PRIVATE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_PRIVATE_H__ + +G_BEGIN_DECLS + +GVirConfigCapabilitiesCPUFeature * +gvir_config_capabilities_cpu_feature_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c new file mode 100644 index 0000000..d7f02c4 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c @@ -0,0 +1,77 @@ +/* + * libvirt-gconfig-capabilities-cpu-feature.c: libvirt CPU feature capabilities + * + * 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_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCPUFeaturePrivate))
I've spelt 3 letter acronyms "Xml" instead of XML when using camel case spelling, I'd rather use Cpu instead of cpu here too
+ +struct _GVirConfigCapabilitiesCPUFeaturePrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCPUFeature, gvir_config_capabilities_cpu_feature, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_cpu_feature_class_init(GVirConfigCapabilitiesCPUFeatureClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCPUFeaturePrivate)); +} + +static void gvir_config_capabilities_cpu_feature_init(GVirConfigCapabilitiesCPUFeature *conn)
s/conn/feature (not your fault, this c&p error is present everywhere)
+{ + g_debug("Init GVirConfigCapabilitiesCPUFeature=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesCPUFeature * +gvir_config_capabilities_cpu_feature_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_CPU_FEATURE(object); +} + +const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCPUFeature *caps) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + if (g_strcmp0((const gchar *)node->name, "feature") == 0) + return gvir_config_xml_get_attribute_content(node, "name"); + else + return (const gchar *)node->name;
This "if" is needed because we can have <features><foo/></features> VS <feature name="foo">? This deserves a comment explaining why we do this test. Having a per-feature GVirConfigObject seems overkill since it will only be a string wrapper, and a GVirConfigObject wrapping just a string with no node name identifying the type of the node is unusual. Not having this class, and doing the parsing directly from gvir_config_capabilities_cpu_get_features would allow to remove it. GVirConfigDomain can also have a <features> node, the strings mentioned above can be wrapped in a GVirConfigCpuFeatures object (or just a typedef?) instead of in a raw GList, and then we can factor the GVirConfigDomain and GVirConfigCapabilitiesCpu code somehow.
+} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h new file mode 100644 index 0000000..b96c9f1 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h @@ -0,0 +1,67 @@ +/* + * libvirt-gconfig-capabilities-cpu-feature.h: libvirt CPU feature capabilities + * + * 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_CAPABILITIES_CPU_FEATURE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE (gvir_config_capabilities_cpu_feature_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCPUFeature)) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCPUFeatureClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE)) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCPUFeatureClass)) + +typedef struct _GVirConfigCapabilitiesCPUFeature GVirConfigCapabilitiesCPUFeature;
If we keep this, Cpu
+typedef struct _GVirConfigCapabilitiesCPUFeaturePrivate GVirConfigCapabilitiesCPUFeaturePrivate; +typedef struct _GVirConfigCapabilitiesCPUFeatureClass GVirConfigCapabilitiesCPUFeatureClass; + +struct _GVirConfigCapabilitiesCPUFeature +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCPUFeaturePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCPUFeatureClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_feature_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCPUFeature *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h new file mode 100644 index 0000000..beebc3b --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h @@ -0,0 +1,39 @@ +/* + * libvirt-gconfig-capabilities-cpu-private.h: libvirt CPU capabilities + * + * Copyright (C) 2010-2011 Red Hat, Inc.
2012
+ * + * 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
Not needed
+ +#ifndef __LIBVIRT_GCONFIG_CAPABILITIES_CPU_PRIVATE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_PRIVATE_H__ + +G_BEGIN_DECLS + +GVirConfigCapabilitiesCPU * +gvir_config_capabilities_cpu_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c new file mode 100644 index 0000000..f1488a9 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c @@ -0,0 +1,127 @@ +/* + * libvirt-gconfig-capabilities-cpu.c: libvirt CPU capabilities + * + * 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_CAPABILITIES_CPU_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCPUPrivate)) + +struct _GVirConfigCapabilitiesCPUPrivate
Cpu
+{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCPU, gvir_config_capabilities_cpu, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_cpu_class_init(GVirConfigCapabilitiesCPUClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCPUPrivate)); +} + +static void gvir_config_capabilities_cpu_init(GVirConfigCapabilitiesCPU *conn)
s/conn/cpu
+{ + g_debug("Init GVirConfigCapabilitiesCPU=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_CPU_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesCPU * +gvir_config_capabilities_cpu_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; +
I don't think many _new_from_tree functions are currently doing that, but I'd add a g_return_val_if_fail(!GVIR_CONFIG_IS_XML_DOC(doc), NULL); g_return_val_if_fail(g_strcmp0(tree->name, "cpu") == 0, NULL);
+ object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_CPU, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_CPU(object); +} + +const gchar * +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCPU *caps) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + return gvir_config_xml_get_child_element_content(node, "arch"); +}
This is gvir_config_object_get_node_content
+ +struct GetFeatureData { + GVirConfigXmlDoc *doc; + GList *features; +}; + +static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigCapabilitiesCPUFeature *feature; + + if (g_strcmp0((const gchar *)node->name, "feature") != 0) + return TRUE;
Is it expected that "features" nodes are ignored? Are the 2 kind of nodes (feature/features) two different things that we want to expose differently in the API?
+ + feature = gvir_config_capabilities_cpu_feature_new_from_tree(data->doc, node); + if (feature != NULL) + data->features = g_list_append(data->features, feature); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_cpu_get_features: + * + * Gets the features of this CPU. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesCPUFeature) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesCPUFeature. + */ +GList * +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCPU *caps) +{ + struct GetFeatureData data; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU(caps), NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + data.features = NULL; + + gvir_config_xml_foreach_child(node, add_feature, &data);
gvir_config_object_foreach_child
+ + g_clear_object(&data.doc); + + return data.features; +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h new file mode 100644 index 0000000..abad676 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h @@ -0,0 +1,69 @@ +/* + * libvirt-gconfig-capabilities-cpu.h: libvirt CPU capabilities + * + * 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_CAPABILITIES_CPU_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU (gvir_config_capabilities_cpu_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCPU)) +#define GVIR_CONFIG_CAPABILITIES_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCPUClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU)) +#define GVIR_CONFIG_CAPABILITIES_CPU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCPUClass)) + +typedef struct _GVirConfigCapabilitiesCPU GVirConfigCapabilitiesCPU;
Cpu
+typedef struct _GVirConfigCapabilitiesCPUPrivate GVirConfigCapabilitiesCPUPrivate; +typedef struct _GVirConfigCapabilitiesCPUClass GVirConfigCapabilitiesCPUClass; + +struct _GVirConfigCapabilitiesCPU +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCPUPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCPUClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCPU *caps); +GList * +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCPU *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h new file mode 100644 index 0000000..732b64c --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h @@ -0,0 +1,39 @@ +/* + * libvirt-gconfig-capabilities-host-private.h: libvirt host capabilities + * + * 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_CAPABILITIES_HOST_PRIVATE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_HOST_PRIVATE_H__ + +G_BEGIN_DECLS + +GVirConfigCapabilitiesHost * +gvir_config_capabilities_host_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_HOST_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.c b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c new file mode 100644 index 0000000..becaf6d --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c @@ -0,0 +1,98 @@ +/* + * libvirt-gconfig-capabilities-host.c: libvirt host capabilities + * + * 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_CAPABILITIES_HOST_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostPrivate)) + +struct _GVirConfigCapabilitiesHostPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesHost, gvir_config_capabilities_host, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_host_class_init(GVirConfigCapabilitiesHostClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesHostPrivate)); +} + +static void gvir_config_capabilities_host_init(GVirConfigCapabilitiesHost *conn) +{ + g_debug("Init GVirConfigCapabilitiesHost=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_HOST_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesHost * +gvir_config_capabilities_host_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_HOST, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_HOST(object); +} + +const gchar * +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *caps) +{ + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(caps), "uuid"); +} + +/** + * gvir_config_capabilities_host_get_cpu: + * + * Gets the CPU capabilities of the host. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesCPU. + */ +GVirConfigCapabilitiesCPU * +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *caps) +{ + GVirConfigXmlDoc *doc; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_HOST(caps), NULL); + + g_object_get(G_OBJECT(caps), "doc", &doc, NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + node = gvir_config_xml_get_element(node, "cpu", NULL); + g_return_val_if_fail(node != NULL, NULL);
Is it a mandatory element in the capabilities XML? If not, a if (node == NULL) { return NULL; } is better
+ + return gvir_config_capabilities_cpu_new_from_tree(doc, node); +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.h b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h new file mode 100644 index 0000000..34ee19e --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h @@ -0,0 +1,70 @@ +/* + * libvirt-gconfig-capabilities-host.h: libvirt host capabilities + * + * 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_CAPABILITIES_HOST_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_HOST_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_HOST (gvir_config_capabilities_host_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_HOST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHost)) +#define GVIR_CONFIG_CAPABILITIES_HOST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_HOST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST)) +#define GVIR_CONFIG_IS_CAPABILITIES_HOST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_HOST)) +#define GVIR_CONFIG_CAPABILITIES_HOST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostClass)) + +typedef struct _GVirConfigCapabilitiesHost GVirConfigCapabilitiesHost; +typedef struct _GVirConfigCapabilitiesHostPrivate GVirConfigCapabilitiesHostPrivate; +typedef struct _GVirConfigCapabilitiesHostClass GVirConfigCapabilitiesHostClass; + +struct _GVirConfigCapabilitiesHost +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesHostPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesHostClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_host_get_type(void); + +const gchar * +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *caps); + +GVirConfigCapabilitiesCPU * +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_HOST_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 3d9d036..9518a30 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -24,6 +24,7 @@ #include <config.h>
#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h"
#define GVIR_CONFIG_CAPABILITIES_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES, GVirConfigCapabilitiesPrivate)) @@ -71,3 +72,29 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, xml, error); return GVIR_CONFIG_CAPABILITIES(object); } + +/** + * gvir_config_capabilities_get_host: + * + * Gets the host capabilities. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesHost. + */ +GVirConfigCapabilitiesHost * +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps) +{ + GVirConfigXmlDoc *doc; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL); + + g_object_get(G_OBJECT(caps), "doc", &doc, NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + node = gvir_config_xml_get_element(node, "host", NULL); + g_return_val_if_fail(node != NULL, NULL); + + return gvir_config_capabilities_host_new_from_tree(doc, node); +}
This is the same code as gvir_config_capabilities_host_get_cpu, if this pattern gets repeated often, it will be worth trying to factor it in a helper function.
diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h index 733886d..18edaf7 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h @@ -56,12 +56,13 @@ struct _GVirConfigCapabilitiesClass gpointer padding[20]; };
- GType gvir_config_capabilities_get_type(void);
GVirConfigCapabilities *gvir_config_capabilities_new(void); GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, GError **error); +GVirConfigCapabilitiesHost * +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps);
G_END_DECLS
diff --git a/libvirt-gconfig/libvirt-gconfig-private.h b/libvirt-gconfig/libvirt-gconfig-private.h index d4df030..845a883 100644 --- a/libvirt-gconfig/libvirt-gconfig-private.h +++ b/libvirt-gconfig/libvirt-gconfig-private.h @@ -24,6 +24,9 @@ #define __LIBVIRT_GCONFIG_PRIVATE_H__
#include <libvirt-gconfig/libvirt-gconfig-domain-device-private.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h> #include <libvirt-gconfig/libvirt-gconfig-helpers-private.h> #include <libvirt-gconfig/libvirt-gconfig-object-private.h> #include <libvirt-gconfig/libvirt-gconfig-xml-doc.h> diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index bd16244..b2b7c15 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -28,6 +28,9 @@
#include <libvirt-gconfig/libvirt-gconfig-main.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-host.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h>
-capabilities.h comes before -capabilities-cpu-feature.h
#include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index ffeb16b..b1df17b 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -6,6 +6,19 @@ LIBVIRT_GCONFIG_0.0.8 { gvir_config_capabilities_get_type; gvir_config_capabilities_new; gvir_config_capabilities_new_from_xml; + gvir_config_capabilities_get_host; + + gvir_config_capabilities_host_get_type; + gvir_config_capabilities_host_new_from_tree;
This should not be exported. Christophe
+ gvir_config_capabilities_host_get_uuid; + gvir_config_capabilities_host_get_cpu; + + gvir_config_capabilities_cpu_get_type; + gvir_config_capabilities_cpu_get_arch; + gvir_config_capabilities_cpu_get_features; + + gvir_config_capabilities_cpu_feature_get_type; + gvir_config_capabilities_cpu_feature_get_name;
gvir_config_domain_add_device; gvir_config_domain_get_type; -- 1.7.7.6
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Wed, May 2, 2012 at 5:25 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
On Tue, May 01, 2012 at 08:30:39PM +0300, Zeeshan Ali (Khattak) wrote:
+{ + g_debug("Init GVirConfigCapabilitiesCPUFeature=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesCPUFeature * +gvir_config_capabilities_cpu_feature_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_CPU_FEATURE(object); +} + +const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCPUFeature *caps) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + if (g_strcmp0((const gchar *)node->name, "feature") == 0) + return gvir_config_xml_get_attribute_content(node, "name"); + else + return (const gchar *)node->name;
This "if" is needed because we can have <features><foo/></features> VS <feature name="foo">? This deserves a comment explaining why we do this test.
Yup!
Having a per-feature GVirConfigObject seems overkill since it will only be a string wrapper, and a GVirConfigObject wrapping just a string with no node name identifying the type of the node is unusual.
Thats only because I haven't added 2 possible getters of this object. We don't need them right now but they could be added when needed later. I have discussed this with Daniel and he and I both think this 'feature' deserves a separate class.
+ +struct GetFeatureData { + GVirConfigXmlDoc *doc; + GList *features; +}; + +static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigCapabilitiesCPUFeature *feature; + + if (g_strcmp0((const gchar *)node->name, "feature") != 0) + return TRUE;
Is it expected that "features" nodes are ignored?
? Its the other way around: We ignore other nodes and create objects for 'feature' nodes.
Are the 2 kind of nodes (feature/features) two different things that we want to expose differently in the API?
I don't think we need separate classes for both. They both represent the same concept, just that libvirt capabilties xml is a bit inconsistent AFAICT.
+ node = gvir_config_xml_get_element(node, "cpu", NULL); + g_return_val_if_fail(node != NULL, NULL);
Is it a mandatory element in the capabilities XML?
According to RNG, it is mandatory.
+GVirConfigCapabilitiesHost * +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps) +{ + GVirConfigXmlDoc *doc; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL); + + g_object_get(G_OBJECT(caps), "doc", &doc, NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + node = gvir_config_xml_get_element(node, "host", NULL); + g_return_val_if_fail(node != NULL, NULL); + + return gvir_config_capabilities_host_new_from_tree(doc, node); +}
This is the same code as gvir_config_capabilities_host_get_cpu, if this pattern gets repeated often, it will be worth trying to factor it in a helper function.
True and since we'll need to use g_object_new() instead in that helper, we can just ditch all these new private headers. -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Wed, May 02, 2012 at 06:35:07PM +0300, Zeeshan Ali (Khattak) wrote:
On Wed, May 2, 2012 at 5:25 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
Having a per-feature GVirConfigObject seems overkill since it will only be a string wrapper, and a GVirConfigObject wrapping just a string with no node name identifying the type of the node is unusual.
Thats only because I haven't added 2 possible getters of this object. We don't need them right now but they could be added when needed later. I have discussed this with Daniel and he and I both think this 'feature' deserves a separate class.
What would be these getters apart from the already existing _get_name?
+static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigCapabilitiesCPUFeature *feature; + + if (g_strcmp0((const gchar *)node->name, "feature") != 0) + return TRUE;
Is it expected that "features" nodes are ignored?
? Its the other way around: We ignore other nodes and create objects for 'feature' nodes.
Yes, and I was asking about "feature*S*" nodes ;) Agreed, libvirt is confusing.
Are the 2 kind of nodes (feature/features) two different things that we want to expose differently in the API?
I don't think we need separate classes for both. They both represent the same concept, just that libvirt capabilties xml is a bit inconsistent AFAICT.
Oh, that wasn't a suggestion, I was merely making sure my assumption that feature/features are the same is a good assumption to make, thanks for the clarification. Christophe

On Wed, May 2, 2012 at 6:47 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
On Wed, May 02, 2012 at 06:35:07PM +0300, Zeeshan Ali (Khattak) wrote:
On Wed, May 2, 2012 at 5:25 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
Having a per-feature GVirConfigObject seems overkill since it will only be a string wrapper, and a GVirConfigObject wrapping just a string with no node name identifying the type of the node is unusual.
Thats only because I haven't added 2 possible getters of this object. We don't need them right now but they could be added when needed later. I have discussed this with Daniel and he and I both think this 'feature' deserves a separate class.
What would be these getters apart from the already existing _get_name?
The features under 'guest' can have boolean attributes, 'default' and 'toggle'. According to RNG and examples I have seen so far, 'feature' in the context can't have props but I recall Daniel said on IRC that the RNG is wrong and these nodes can have props too. Any ways, he suggests we keep a class for both 'feature's and I didn't see any harm in that. -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Wed, May 02, 2012 at 09:04:00PM +0300, Zeeshan Ali (Khattak) wrote:
On Wed, May 2, 2012 at 6:47 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
What would be these getters apart from the already existing _get_name?
The features under 'guest' can have boolean attributes, 'default' and 'toggle'.
Ah indeed thanks.
According to RNG and examples I have seen so far, 'feature' in the context can't have props but I recall Daniel said on IRC that the RNG is wrong and these nodes can have props too. Any ways, he suggests we keep a class for both 'feature's and I didn't see any harm in that.
I'm not 100% sure what "both" refers to here, since I can see 3 different features, /guest/features, /host/cpu/feature and /host/cpu/features. Given that feature/features are treated the same for host capabilities, I assume you mean having one class for guest features, and one for host CPU features? Works for me, though for the latter, a class wrapping a GList of feature would be less heavyweight, but I'm fine with either approach. Christophe

On Thu, May 03, 2012 at 01:11:26PM +0200, Christophe Fergeau wrote:
On Wed, May 02, 2012 at 09:04:00PM +0300, Zeeshan Ali (Khattak) wrote:
On Wed, May 2, 2012 at 6:47 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
What would be these getters apart from the already existing _get_name?
The features under 'guest' can have boolean attributes, 'default' and 'toggle'.
Ah indeed thanks.
According to RNG and examples I have seen so far, 'feature' in the context can't have props but I recall Daniel said on IRC that the RNG is wrong and these nodes can have props too. Any ways, he suggests we keep a class for both 'feature's and I didn't see any harm in that.
I'm not 100% sure what "both" refers to here, since I can see 3 different features, /guest/features, /host/cpu/feature and /host/cpu/features. Given that feature/features are treated the same for host capabilities,
Guest features (capabilities XML) - these are really just capabilities of the hypervisor in general Host CPU features (capabilities XML) - individual CPU feature flags (ala /proc/cpuinfo flags on host) Guest CPU featrures (domain XML) - individual CPU feature flags (ala /proc/cpuinfo flags in the guest) The schema for Guest CPU features is a superset of the schema for Host CPU features. My preference is thus to use the same class for both of these. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Hi, There's still one bit I'm missing, here is my understanding so far: On Thu, May 03, 2012 at 12:53:10PM +0100, Daniel P. Berrange wrote:
On Thu, May 03, 2012 at 01:11:26PM +0200, Christophe Fergeau wrote: Guest features (capabilities XML) - these are really just capabilities of the hypervisor in general
this is /capabilities/guest/features
Host CPU features (capabilities XML) - individual CPU feature flags (ala /proc/cpuinfo flags on host)
this is /capabilities/host/cpu/feature (ie caps->hosts.cpu->features)
Guest CPU featrures (domain XML) - individual CPU feature flags (ala /proc/cpuinfo flags in the guest)
this is /domain/features I'm left with /capabilities/host/cpu/features (which correspond to caps->host->features), which I'm not sure how it relates to /capabilities/host/cpu/feature. Any insight on that one? Thanks, Christophe

On Wed, May 09, 2012 at 05:47:19PM +0200, Christophe Fergeau wrote:
Hi,
There's still one bit I'm missing, here is my understanding so far:
On Thu, May 03, 2012 at 12:53:10PM +0100, Daniel P. Berrange wrote:
On Thu, May 03, 2012 at 01:11:26PM +0200, Christophe Fergeau wrote: Guest features (capabilities XML) - these are really just capabilities of the hypervisor in general
this is /capabilities/guest/features
Host CPU features (capabilities XML) - individual CPU feature flags (ala /proc/cpuinfo flags on host)
this is /capabilities/host/cpu/feature (ie caps->hosts.cpu->features)
Guest CPU featrures (domain XML) - individual CPU feature flags (ala /proc/cpuinfo flags in the guest)
this is /domain/features
Opps, no I was meaning /domain/cpu/feature here, which is the same schem as /capabilities/host/cpu/feature. I forgot there was also a /domain/features which corresponds to /capabilities/guest/features
I'm left with /capabilities/host/cpu/features (which correspond to
Doh, I completely forgot about that. This is basically a bit of legacy XML, which isn't even really used. It would only ever be used to set 'pae', 'nonpae', 'vmx', or 'svm' flags. This is the same kind of info as /capabilities/guest/features and also /domain/features. The new /capabilities/host/cpu/feature is a superset of this info
caps->host->features), which I'm not sure how it relates to /capabilities/host/cpu/feature. Any insight on that one?
Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Wed, May 09, 2012 at 05:01:25PM +0100, Daniel P. Berrange wrote:
Opps, no I was meaning /domain/cpu/feature here, which is the same schem as /capabilities/host/cpu/feature.
Ah thanks, that clears things up.
I forgot there was also a /domain/features which corresponds to /capabilities/guest/features
Ok, this means gvir_config_domain_get_features should return a GList of GVirConfigCapabilitiesGuestFeature instead of raw char *, and gvir_config_domain_cpu_get_features (or whatever it's called, this does not exist yet) would return GVirConfigCapabilitiesCpuFeature?
I'm left with /capabilities/host/cpu/features (which correspond to
Doh, I completely forgot about that. This is basically a bit of legacy XML, which isn't even really used. It would only ever be used to set 'pae', 'nonpae', 'vmx', or 'svm' flags. This is the same kind of info as /capabilities/guest/features and also /domain/features.
The new /capabilities/host/cpu/feature is a superset of this info
I guess libvirt-glib does not need to parse it if it's legacy? Thanks, Christophe

On Wed, May 2, 2012 at 5:25 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
On Tue, May 01, 2012 at 08:30:39PM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
Not quite complete but its a good start.
CUT
--- +/** + * gvir_config_capabilities_cpu_get_features: + * + * Gets the features of this CPU. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesCPUFeature) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesCPUFeature. + */ +GList * +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCPU *caps) +{ + struct GetFeatureData data; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU(caps), NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + data.features = NULL; + + gvir_config_xml_foreach_child(node, add_feature, &data);
gvir_config_object_foreach_child
Not really, gvir_config_object_foreach_child seem to iterate grand children of the object node and we are iterating direct children. -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Fri, May 04, 2012 at 05:02:37AM +0300, Zeeshan Ali (Khattak) wrote:
On Wed, May 2, 2012 at 5:25 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
On Tue, May 01, 2012 at 08:30:39PM +0300, Zeeshan Ali (Khattak) wrote:
+ + gvir_config_xml_foreach_child(node, add_feature, &data);
gvir_config_object_foreach_child
Not really, gvir_config_object_foreach_child seem to iterate grand children of the object node and we are iterating direct children.
If you use NULL as the second argument, it should do what you want. Christophe

On Tue, May 01, 2012 at 08:30:39PM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index ffeb16b..b1df17b 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -6,6 +6,19 @@ LIBVIRT_GCONFIG_0.0.8 { gvir_config_capabilities_get_type; gvir_config_capabilities_new; gvir_config_capabilities_new_from_xml; + gvir_config_capabilities_get_host; + + gvir_config_capabilities_host_get_type; + gvir_config_capabilities_host_new_from_tree; + gvir_config_capabilities_host_get_uuid; + gvir_config_capabilities_host_get_cpu; + + gvir_config_capabilities_cpu_get_type; + gvir_config_capabilities_cpu_get_arch; + gvir_config_capabilities_cpu_get_features; + + gvir_config_capabilities_cpu_feature_get_type; + gvir_config_capabilities_cpu_feature_get_name;
gvir_config_domain_add_device; gvir_config_domain_get_type;
Again, start a new version block for 0.0.9 symbols Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> Not quite complete but its a good start. --- libvirt-gconfig/Makefile.am | 11 ++- ...libvirt-gconfig-capabilities-cpu-arch-private.h | 39 +++++ .../libvirt-gconfig-capabilities-cpu-arch.c | 135 +++++++++++++++++ .../libvirt-gconfig-capabilities-cpu-arch.h | 71 +++++++++ .../libvirt-gconfig-capabilities-domain-private.h | 39 +++++ .../libvirt-gconfig-capabilities-domain.c | 93 ++++++++++++ .../libvirt-gconfig-capabilities-domain.h | 72 +++++++++ .../libvirt-gconfig-capabilities-guest-private.h | 39 +++++ .../libvirt-gconfig-capabilities-guest.c | 153 ++++++++++++++++++++ .../libvirt-gconfig-capabilities-guest.h | 74 ++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.c | 52 +++++++ libvirt-gconfig/libvirt-gconfig-capabilities.h | 1 + libvirt-gconfig/libvirt-gconfig-private.h | 3 + libvirt-gconfig/libvirt-gconfig.h | 3 + libvirt-gconfig/libvirt-gconfig.sym | 16 ++ 15 files changed, 800 insertions(+), 1 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch-private.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-domain-private.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-domain.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-domain.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-private.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 9bd0df8..606df92 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -13,7 +13,10 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-object.h \ libvirt-gconfig-capabilities.h \ libvirt-gconfig-capabilities-host.h \ + libvirt-gconfig-capabilities-guest.h \ + libvirt-gconfig-capabilities-domain.h \ libvirt-gconfig-capabilities-cpu.h \ + libvirt-gconfig-capabilities-cpu-arch.h \ libvirt-gconfig-capabilities-cpu-feature.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-address.h \ @@ -72,14 +75,20 @@ noinst_HEADERS = \ libvirt-gconfig-object-private.h \ libvirt-gconfig-xml-doc.h \ libvirt-gconfig-capabilities-host-private.h \ + libvirt-gconfig-capabilities-guest-private.h \ libvirt-gconfig-capabilities-cpu-private.h \ - libvirt-gconfig-capabilities-cpu-feature-private.h + libvirt-gconfig-capabilities-cpu-arch-private.h \ + libvirt-gconfig-capabilities-cpu-feature-private.h \ + libvirt-gconfig-capabilities-domain-private.h GCONFIG_SOURCE_FILES = \ libvirt-gconfig-object.c \ libvirt-gconfig-main.c \ libvirt-gconfig-capabilities.c \ libvirt-gconfig-capabilities-host.c \ + libvirt-gconfig-capabilities-guest.c \ + libvirt-gconfig-capabilities-domain.c \ libvirt-gconfig-capabilities-cpu.c \ + libvirt-gconfig-capabilities-cpu-arch.c \ libvirt-gconfig-capabilities-cpu-feature.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-address.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch-private.h new file mode 100644 index 0000000..c864847 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch-private.h @@ -0,0 +1,39 @@ +/* + * libvirt-gconfig-capabilities-cpu-arch-private.h: libvirt CPU architecture capabilities + * + * 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_CAPABILITIES_CPU_ARCH_PRIVATE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_PRIVATE_H__ + +G_BEGIN_DECLS + +GVirConfigCapabilitiesCPUArch * +gvir_config_capabilities_cpu_arch_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.c new file mode 100644 index 0000000..e4d25d3 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.c @@ -0,0 +1,135 @@ +/* + * libvirt-gconfig-capabilities-cpu-arch.c: libvirt CPU architecture capabilities + * + * 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_CAPABILITIES_CPU_ARCH_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, GVirConfigCapabilitiesCPUArchPrivate)) + +struct _GVirConfigCapabilitiesCPUArchPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCPUArch, gvir_config_capabilities_cpu_arch, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_cpu_arch_class_init(GVirConfigCapabilitiesCPUArchClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCPUArchPrivate)); +} + +static void gvir_config_capabilities_cpu_arch_init(GVirConfigCapabilitiesCPUArch *conn) +{ + g_debug("Init GVirConfigCapabilitiesCPUArch=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_CPU_ARCH_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesCPUArch * +gvir_config_capabilities_cpu_arch_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_CPU_ARCH(object); +} + +const gchar * +gvir_config_capabilities_cpu_arch_get_name(GVirConfigCapabilitiesCPUArch *caps) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + return gvir_config_xml_get_attribute_content(node, "name"); +} + +struct GetDomainData { + GVirConfigXmlDoc *doc; + GList *domains; +}; + +static gboolean add_domain(xmlNodePtr node, gpointer opaque) +{ + struct GetDomainData* data = (struct GetDomainData*)opaque; + GVirConfigCapabilitiesDomain *domain; + + if (g_strcmp0((const gchar *)node->name, "domain") != 0) + return TRUE; + + domain = gvir_config_capabilities_domain_new_from_tree(data->doc, node); + if (domain != NULL) + data->domains = g_list_append(data->domains, domain); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_cpu_arch_get_domains: + * + * Gets the possible domains for this architecture. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesDomain) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesDomain. + */ +GList * +gvir_config_capabilities_cpu_arch_get_domains(GVirConfigCapabilitiesCPUArch *caps) +{ + struct GetDomainData data; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU_ARCH(caps), NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + data.domains = NULL; + + gvir_config_xml_foreach_child(node, add_domain, &data); + + g_clear_object(&data.doc); + + return data.domains; +} + +const gchar * +gvir_config_capabilities_cpu_arch_get_emulator(GVirConfigCapabilitiesCPUArch *caps) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + return gvir_config_xml_get_child_element_content(node, "emulator"); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.h new file mode 100644 index 0000000..5953ef9 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.h @@ -0,0 +1,71 @@ +/* + * libvirt-gconfig-capabilities-cpu-arch.h: libvirt CPU architecture capabilities + * + * 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_CAPABILITIES_CPU_ARCH_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH (gvir_config_capabilities_cpu_arch_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU_ARCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, GVirConfigCapabilitiesCPUArch)) +#define GVIR_CONFIG_CAPABILITIES_CPU_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, GVirConfigCapabilitiesCPUArchClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_ARCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH)) +#define GVIR_CONFIG_CAPABILITIES_CPU_ARCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, GVirConfigCapabilitiesCPUArchClass)) + +typedef struct _GVirConfigCapabilitiesCPUArch GVirConfigCapabilitiesCPUArch; +typedef struct _GVirConfigCapabilitiesCPUArchPrivate GVirConfigCapabilitiesCPUArchPrivate; +typedef struct _GVirConfigCapabilitiesCPUArchClass GVirConfigCapabilitiesCPUArchClass; + +struct _GVirConfigCapabilitiesCPUArch +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCPUArchPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCPUArchClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_arch_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_arch_get_name(GVirConfigCapabilitiesCPUArch *caps); +GList * +gvir_config_capabilities_cpu_arch_get_domains(GVirConfigCapabilitiesCPUArch *caps); +const gchar * +gvir_config_capabilities_cpu_arch_get_emulator(GVirConfigCapabilitiesCPUArch *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-domain-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-domain-private.h new file mode 100644 index 0000000..a657e2e --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-domain-private.h @@ -0,0 +1,39 @@ +/* + * libvirt-gconfig-capabilities-domain-private.h: libvirt CPU capabilities + * + * Copyright (C) 2010-2011 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_CAPABILITIES_DOMAIN_PRIVATE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_DOMAIN_PRIVATE_H__ + +G_BEGIN_DECLS + +GVirConfigCapabilitiesDomain * +gvir_config_capabilities_domain_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_DOMAIN_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-domain.c b/libvirt-gconfig/libvirt-gconfig-capabilities-domain.c new file mode 100644 index 0000000..1023f9d --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-domain.c @@ -0,0 +1,93 @@ +/* + * libvirt-gconfig-capabilities-domain.c: libvirt domain capabilities + * + * 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_CAPABILITIES_DOMAIN_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, GVirConfigCapabilitiesDomainPrivate)) + +struct _GVirConfigCapabilitiesDomainPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesDomain, gvir_config_capabilities_domain, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_domain_class_init(GVirConfigCapabilitiesDomainClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesDomainPrivate)); +} + +static void gvir_config_capabilities_domain_init(GVirConfigCapabilitiesDomain *conn) +{ + g_debug("Init GVirConfigCapabilitiesDomain=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_DOMAIN_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesDomain * +gvir_config_capabilities_domain_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_DOMAIN(object); +} + +const gchar * +gvir_config_capabilities_domain_get_emulator(GVirConfigCapabilitiesDomain *caps) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + return gvir_config_xml_get_child_element_content(node, "emulator"); +} + +GVirConfigDomainVirtType +gvir_config_capabilities_domain_get_virt_type(GVirConfigCapabilitiesDomain *caps) +{ + xmlNodePtr node; + const gchar *str; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + str = gvir_config_xml_get_attribute_content(node, "type"); + if (str == NULL) + return GVIR_CONFIG_DOMAIN_VIRT_QEMU; + + return gvir_config_genum_get_value(GVIR_CONFIG_TYPE_DOMAIN_VIRT_TYPE, + str, + GVIR_CONFIG_DOMAIN_VIRT_QEMU); +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-domain.h b/libvirt-gconfig/libvirt-gconfig-capabilities-domain.h new file mode 100644 index 0000000..6c20191 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-domain.h @@ -0,0 +1,72 @@ +/* + * libvirt-gconfig-capabilities-domain.h: libvirt domain capabilities + * + * 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_CAPABILITIES_DOMAIN_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_DOMAIN_H__ + +#include "libvirt-gconfig-domain.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN (gvir_config_capabilities_domain_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, GVirConfigCapabilitiesDomain)) +#define GVIR_CONFIG_CAPABILITIES_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, GVirConfigCapabilitiesDomainClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN)) +#define GVIR_CONFIG_IS_CAPABILITIES_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN)) +#define GVIR_CONFIG_CAPABILITIES_DOMAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, GVirConfigCapabilitiesDomainClass)) + +typedef struct _GVirConfigCapabilitiesDomain GVirConfigCapabilitiesDomain; +typedef struct _GVirConfigCapabilitiesDomainPrivate GVirConfigCapabilitiesDomainPrivate; +typedef struct _GVirConfigCapabilitiesDomainClass GVirConfigCapabilitiesDomainClass; + +struct _GVirConfigCapabilitiesDomain +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesDomainPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesDomainClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_domain_get_type(void); + +const gchar * +gvir_config_capabilities_domain_get_emulator(GVirConfigCapabilitiesDomain *caps); + +GVirConfigDomainVirtType +gvir_config_capabilities_domain_get_virt_type(GVirConfigCapabilitiesDomain *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_DOMAIN_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-private.h new file mode 100644 index 0000000..1092ad0 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-private.h @@ -0,0 +1,39 @@ +/* + * libvirt-gconfig-capabilities-guest-private.h: libvirt guest capabilities + * + * 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_CAPABILITIES_GUEST_PRIVATE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_PRIVATE_H__ + +G_BEGIN_DECLS + +GVirConfigCapabilitiesGuest * +gvir_config_capabilities_guest_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c new file mode 100644 index 0000000..8f42d4c --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c @@ -0,0 +1,153 @@ +/* + * libvirt-gconfig-capabilities-guest.c: libvirt guest capabilities + * + * 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_CAPABILITIES_GUEST_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestPrivate)) + +struct _GVirConfigCapabilitiesGuestPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuest, gvir_config_capabilities_guest, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_guest_class_init(GVirConfigCapabilitiesGuestClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestPrivate)); +} + +static void gvir_config_capabilities_guest_init(GVirConfigCapabilitiesGuest *conn) +{ + g_debug("Init GVirConfigCapabilitiesGuest=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_GUEST_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesGuest * +gvir_config_capabilities_guest_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_GUEST(object); +} + +GVirConfigDomainOsType +gvir_config_capabilities_guest_get_os_type(GVirConfigCapabilitiesGuest *caps) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), -1); + + return gvir_config_object_get_node_content_genum(GVIR_CONFIG_OBJECT(caps), + "os_type", + GVIR_CONFIG_TYPE_DOMAIN_OS_TYPE, + GVIR_CONFIG_DOMAIN_OS_TYPE_LINUX); +} + +/** + * gvir_config_capabilities_guest_get_cpu_arch: + * + * Gets the CPU architecture capabilities of the guest. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesCPUArch. + */ +GVirConfigCapabilitiesCPUArch * +gvir_config_capabilities_guest_get_cpu_arch(GVirConfigCapabilitiesGuest *caps) +{ + GVirConfigXmlDoc *doc; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), NULL); + + g_object_get(G_OBJECT(caps), "doc", &doc, NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + node = gvir_config_xml_get_element(node, "arch", NULL); + g_return_val_if_fail(node != NULL, NULL); + + return gvir_config_capabilities_cpu_arch_new_from_tree(doc, node); +} + +struct GetFeatureData { + GVirConfigXmlDoc *doc; + GList *features; +}; + +static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigCapabilitiesCPUFeature *feature; + + feature = gvir_config_capabilities_cpu_feature_new_from_tree(data->doc, node); + if (feature != NULL) + data->features = g_list_append(data->features, feature); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_guest_get_cpu_features: + * + * Gets the CPU features for this guest. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesCPUFeature) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesCPUFeature. + */ +GList * +gvir_config_capabilities_guest_get_cpu_features(GVirConfigCapabilitiesGuest *caps) +{ + struct GetFeatureData data; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + node = gvir_config_xml_get_element(node, "features", NULL); + if (node == NULL) + return NULL; + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + data.features = NULL; + + gvir_config_xml_foreach_child(node, add_feature, &data); + + g_clear_object(&data.doc); + + return data.features; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h new file mode 100644 index 0000000..c70177d --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h @@ -0,0 +1,74 @@ +/* + * libvirt-gconfig-capabilities-guest.h: libvirt guest capabilities + * + * 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_CAPABILITIES_GUEST_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ + +#include "libvirt-gconfig-domain-os.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST (gvir_config_capabilities_guest_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuest)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestClass)) + +typedef struct _GVirConfigCapabilitiesGuest GVirConfigCapabilitiesGuest; +typedef struct _GVirConfigCapabilitiesGuestPrivate GVirConfigCapabilitiesGuestPrivate; +typedef struct _GVirConfigCapabilitiesGuestClass GVirConfigCapabilitiesGuestClass; + +struct _GVirConfigCapabilitiesGuest +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_get_type(void); + +GVirConfigDomainOsType +gvir_config_capabilities_guest_get_os_type(GVirConfigCapabilitiesGuest *caps); + +GVirConfigCapabilitiesCPUArch * +gvir_config_capabilities_guest_get_cpu_arch(GVirConfigCapabilitiesGuest *caps); +GList * +gvir_config_capabilities_guest_get_cpu_features(GVirConfigCapabilitiesGuest *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 9518a30..5f38ac8 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -98,3 +98,55 @@ gvir_config_capabilities_get_host(GVirConfigCapabilities *caps) return gvir_config_capabilities_host_new_from_tree(doc, node); } + +struct GetGuestData { + GVirConfigXmlDoc *doc; + GList *guests; +}; + +static gboolean add_guest(xmlNodePtr node, gpointer opaque) +{ + struct GetGuestData* data = (struct GetGuestData*)opaque; + GVirConfigCapabilitiesGuest *guest; + + if (g_strcmp0((const gchar *)node->name, "guest") != 0) + return TRUE; + + guest = gvir_config_capabilities_guest_new_from_tree(data->doc, node); + if (guest != NULL) + data->guests = g_list_append(data->guests, guest); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_get_guests: + * + * Gets the list of guest capabilities. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesGuest) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesGuest. + */ +GList * +gvir_config_capabilities_get_guests(GVirConfigCapabilities *caps) +{ + struct GetGuestData data; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + data.guests = NULL; + + gvir_config_xml_foreach_child(node, add_guest, &data); + + if (data.doc != NULL) + g_object_unref(G_OBJECT(data.doc)); + + return data.guests; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h index 18edaf7..7e16099 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h @@ -63,6 +63,7 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, GError **error); GVirConfigCapabilitiesHost * gvir_config_capabilities_get_host(GVirConfigCapabilities *caps); +GList *gvir_config_capabilities_get_guests(GVirConfigCapabilities *caps); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-private.h b/libvirt-gconfig/libvirt-gconfig-private.h index 845a883..67fd4be 100644 --- a/libvirt-gconfig/libvirt-gconfig-private.h +++ b/libvirt-gconfig/libvirt-gconfig-private.h @@ -24,9 +24,12 @@ #define __LIBVIRT_GCONFIG_PRIVATE_H__ #include <libvirt-gconfig/libvirt-gconfig-domain-device-private.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-domain-private.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch-private.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-private.h> #include <libvirt-gconfig/libvirt-gconfig-helpers-private.h> #include <libvirt-gconfig/libvirt-gconfig-object-private.h> #include <libvirt-gconfig/libvirt-gconfig-xml-doc.h> diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index b2b7c15..32d286b 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -28,9 +28,12 @@ #include <libvirt-gconfig/libvirt-gconfig-main.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-domain.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-host.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index b1df17b..51f6ce6 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -7,6 +7,7 @@ LIBVIRT_GCONFIG_0.0.8 { gvir_config_capabilities_new; gvir_config_capabilities_new_from_xml; gvir_config_capabilities_get_host; + gvir_config_capabilities_get_guests; gvir_config_capabilities_host_get_type; gvir_config_capabilities_host_new_from_tree; @@ -20,6 +21,21 @@ LIBVIRT_GCONFIG_0.0.8 { gvir_config_capabilities_cpu_feature_get_type; gvir_config_capabilities_cpu_feature_get_name; + gvir_config_capabilities_guest_get_type; + gvir_config_capabilities_guest_new_from_tree; + gvir_config_capabilities_guest_get_os_type; + gvir_config_capabilities_guest_get_cpu_arch; + gvir_config_capabilities_guest_get_cpu_features; + + gvir_config_capabilities_cpu_arch_get_type; + gvir_config_capabilities_cpu_arch_get_name; + gvir_config_capabilities_cpu_arch_get_domains; + gvir_config_capabilities_cpu_arch_get_emulator; + + gvir_config_capabilities_domain_get_type; + gvir_config_capabilities_domain_get_emulator; + gvir_config_capabilities_domain_get_virt_type; + gvir_config_domain_add_device; gvir_config_domain_get_type; gvir_config_domain_lifecycle_action_get_type; -- 1.7.7.6

A few quick comments, I'll review it more deeply later, On Tue, May 01, 2012 at 08:30:40PM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
Not quite complete but its a good start. --- libvirt-gconfig/Makefile.am | 11 ++- ...libvirt-gconfig-capabilities-cpu-arch-private.h | 39 +++++ .../libvirt-gconfig-capabilities-cpu-arch.c | 135 +++++++++++++++++ .../libvirt-gconfig-capabilities-cpu-arch.h | 71 +++++++++ .../libvirt-gconfig-capabilities-domain-private.h | 39 +++++ .../libvirt-gconfig-capabilities-domain.c | 93 ++++++++++++ .../libvirt-gconfig-capabilities-domain.h | 72 +++++++++ .../libvirt-gconfig-capabilities-guest-private.h | 39 +++++ .../libvirt-gconfig-capabilities-guest.c | 153 ++++++++++++++++++++ .../libvirt-gconfig-capabilities-guest.h | 74 ++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.c | 52 +++++++ libvirt-gconfig/libvirt-gconfig-capabilities.h | 1 + libvirt-gconfig/libvirt-gconfig-private.h | 3 + libvirt-gconfig/libvirt-gconfig.h | 3 + libvirt-gconfig/libvirt-gconfig.sym | 16 ++ 15 files changed, 800 insertions(+), 1 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch-private.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-domain-private.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-domain.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-domain.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-private.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest.h
diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 9bd0df8..606df92 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -13,7 +13,10 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-object.h \ libvirt-gconfig-capabilities.h \ libvirt-gconfig-capabilities-host.h \ + libvirt-gconfig-capabilities-guest.h \ + libvirt-gconfig-capabilities-domain.h \ libvirt-gconfig-capabilities-cpu.h \ + libvirt-gconfig-capabilities-cpu-arch.h \ libvirt-gconfig-capabilities-cpu-feature.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-address.h \ @@ -72,14 +75,20 @@ noinst_HEADERS = \ libvirt-gconfig-object-private.h \ libvirt-gconfig-xml-doc.h \ libvirt-gconfig-capabilities-host-private.h \ + libvirt-gconfig-capabilities-guest-private.h \ libvirt-gconfig-capabilities-cpu-private.h \ - libvirt-gconfig-capabilities-cpu-feature-private.h + libvirt-gconfig-capabilities-cpu-arch-private.h \ + libvirt-gconfig-capabilities-cpu-feature-private.h \ + libvirt-gconfig-capabilities-domain-private.h GCONFIG_SOURCE_FILES = \ libvirt-gconfig-object.c \ libvirt-gconfig-main.c \ libvirt-gconfig-capabilities.c \ libvirt-gconfig-capabilities-host.c \ + libvirt-gconfig-capabilities-guest.c \ + libvirt-gconfig-capabilities-domain.c \ libvirt-gconfig-capabilities-cpu.c \ + libvirt-gconfig-capabilities-cpu-arch.c \ libvirt-gconfig-capabilities-cpu-feature.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-address.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch-private.h new file mode 100644 index 0000000..c864847 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch-private.h @@ -0,0 +1,39 @@ +/* + * libvirt-gconfig-capabilities-cpu-arch-private.h: libvirt CPU architecture capabilities + * + * 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
Not needed
+ +#ifndef __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_PRIVATE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_PRIVATE_H__ + +G_BEGIN_DECLS + +GVirConfigCapabilitiesCPUArch *
Cpu
+gvir_config_capabilities_cpu_arch_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.c new file mode 100644 index 0000000..e4d25d3 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.c @@ -0,0 +1,135 @@ +/* + * libvirt-gconfig-capabilities-cpu-arch.c: libvirt CPU architecture capabilities + * + * 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_CAPABILITIES_CPU_ARCH_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, GVirConfigCapabilitiesCPUArchPrivate)) + +struct _GVirConfigCapabilitiesCPUArchPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCPUArch, gvir_config_capabilities_cpu_arch, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_cpu_arch_class_init(GVirConfigCapabilitiesCPUArchClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCPUArchPrivate)); +} + +static void gvir_config_capabilities_cpu_arch_init(GVirConfigCapabilitiesCPUArch *conn) +{ + g_debug("Init GVirConfigCapabilitiesCPUArch=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_CPU_ARCH_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesCPUArch * +gvir_config_capabilities_cpu_arch_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_CPU_ARCH(object); +} + +const gchar * +gvir_config_capabilities_cpu_arch_get_name(GVirConfigCapabilitiesCPUArch *caps) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + return gvir_config_xml_get_attribute_content(node, "name"); +}
gvir_config_object_get_attribute can be used there I think
+ +struct GetDomainData { + GVirConfigXmlDoc *doc; + GList *domains; +}; + +static gboolean add_domain(xmlNodePtr node, gpointer opaque) +{ + struct GetDomainData* data = (struct GetDomainData*)opaque; + GVirConfigCapabilitiesDomain *domain; + + if (g_strcmp0((const gchar *)node->name, "domain") != 0) + return TRUE; + + domain = gvir_config_capabilities_domain_new_from_tree(data->doc, node); + if (domain != NULL) + data->domains = g_list_append(data->domains, domain); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_cpu_arch_get_domains: + * + * Gets the possible domains for this architecture. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesDomain) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesDomain. + */ +GList * +gvir_config_capabilities_cpu_arch_get_domains(GVirConfigCapabilitiesCPUArch *caps) +{ + struct GetDomainData data; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU_ARCH(caps), NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + data.domains = NULL; + + gvir_config_xml_foreach_child(node, add_domain, &data);
gvir_config_object_foreach_child
+ + g_clear_object(&data.doc); + + return data.domains; +} + +const gchar * +gvir_config_capabilities_cpu_arch_get_emulator(GVirConfigCapabilitiesCPUArch *caps) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + return gvir_config_xml_get_child_element_content(node, "emulator");
gvir_config_object_get_node_content
+} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.h new file mode 100644 index 0000000..5953ef9 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.h @@ -0,0 +1,71 @@ +/* + * libvirt-gconfig-capabilities-cpu-arch.h: libvirt CPU architecture capabilities + * + * 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_CAPABILITIES_CPU_ARCH_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH (gvir_config_capabilities_cpu_arch_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU_ARCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, GVirConfigCapabilitiesCPUArch)) +#define GVIR_CONFIG_CAPABILITIES_CPU_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, GVirConfigCapabilitiesCPUArchClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_ARCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH)) +#define GVIR_CONFIG_CAPABILITIES_CPU_ARCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, GVirConfigCapabilitiesCPUArchClass)) + +typedef struct _GVirConfigCapabilitiesCPUArch GVirConfigCapabilitiesCPUArch;
Cpu
+typedef struct _GVirConfigCapabilitiesCPUArchPrivate GVirConfigCapabilitiesCPUArchPrivate; +typedef struct _GVirConfigCapabilitiesCPUArchClass GVirConfigCapabilitiesCPUArchClass; + +struct _GVirConfigCapabilitiesCPUArch +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCPUArchPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCPUArchClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_arch_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_arch_get_name(GVirConfigCapabilitiesCPUArch *caps); +GList * +gvir_config_capabilities_cpu_arch_get_domains(GVirConfigCapabilitiesCPUArch *caps); +const gchar * +gvir_config_capabilities_cpu_arch_get_emulator(GVirConfigCapabilitiesCPUArch *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-domain-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-domain-private.h new file mode 100644 index 0000000..a657e2e --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-domain-private.h @@ -0,0 +1,39 @@ +/* + * libvirt-gconfig-capabilities-domain-private.h: libvirt CPU capabilities + * + * Copyright (C) 2010-2011 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
Can be removed
+ +#ifndef __LIBVIRT_GCONFIG_CAPABILITIES_DOMAIN_PRIVATE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_DOMAIN_PRIVATE_H__ + +G_BEGIN_DECLS + +GVirConfigCapabilitiesDomain * +gvir_config_capabilities_domain_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_DOMAIN_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-domain.c b/libvirt-gconfig/libvirt-gconfig-capabilities-domain.c new file mode 100644 index 0000000..1023f9d --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-domain.c @@ -0,0 +1,93 @@ +/* + * libvirt-gconfig-capabilities-domain.c: libvirt domain capabilities + * + * 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_CAPABILITIES_DOMAIN_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, GVirConfigCapabilitiesDomainPrivate)) + +struct _GVirConfigCapabilitiesDomainPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesDomain, gvir_config_capabilities_domain, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_domain_class_init(GVirConfigCapabilitiesDomainClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesDomainPrivate)); +} + +static void gvir_config_capabilities_domain_init(GVirConfigCapabilitiesDomain *conn)
s/conn/domain
+{ + g_debug("Init GVirConfigCapabilitiesDomain=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_DOMAIN_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesDomain * +gvir_config_capabilities_domain_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_DOMAIN(object); +}
Check 'doc' root node name?
+ +const gchar * +gvir_config_capabilities_domain_get_emulator(GVirConfigCapabilitiesDomain *caps)
Is this method just a copy and paste bug, or is it needed? The reason I'm asking is that I cannot see the corresponding XML on http://libvirt.org/formatcaps.html <domain type="xen"></domain> but maybe this example is partial.
+{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + return gvir_config_xml_get_child_element_content(node, "emulator");
gvir_config_object_get_node_content
+} + +GVirConfigDomainVirtType +gvir_config_capabilities_domain_get_virt_type(GVirConfigCapabilitiesDomain *caps) +{ + xmlNodePtr node; + const gchar *str; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + str = gvir_config_xml_get_attribute_content(node, "type"); + if (str == NULL) + return GVIR_CONFIG_DOMAIN_VIRT_QEMU; + + return gvir_config_genum_get_value(GVIR_CONFIG_TYPE_DOMAIN_VIRT_TYPE, + str, + GVIR_CONFIG_DOMAIN_VIRT_QEMU); +}
gvir_config_object_get_node_content_genum
+ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-domain.h b/libvirt-gconfig/libvirt-gconfig-capabilities-domain.h new file mode 100644 index 0000000..6c20191 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-domain.h @@ -0,0 +1,72 @@ +/* + * libvirt-gconfig-capabilities-domain.h: libvirt domain capabilities + * + * 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_CAPABILITIES_DOMAIN_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_DOMAIN_H__ + +#include "libvirt-gconfig-domain.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN (gvir_config_capabilities_domain_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, GVirConfigCapabilitiesDomain)) +#define GVIR_CONFIG_CAPABILITIES_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, GVirConfigCapabilitiesDomainClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN)) +#define GVIR_CONFIG_IS_CAPABILITIES_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN)) +#define GVIR_CONFIG_CAPABILITIES_DOMAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, GVirConfigCapabilitiesDomainClass)) + +typedef struct _GVirConfigCapabilitiesDomain GVirConfigCapabilitiesDomain; +typedef struct _GVirConfigCapabilitiesDomainPrivate GVirConfigCapabilitiesDomainPrivate; +typedef struct _GVirConfigCapabilitiesDomainClass GVirConfigCapabilitiesDomainClass; + +struct _GVirConfigCapabilitiesDomain +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesDomainPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesDomainClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_domain_get_type(void); + +const gchar * +gvir_config_capabilities_domain_get_emulator(GVirConfigCapabilitiesDomain *caps); + +GVirConfigDomainVirtType +gvir_config_capabilities_domain_get_virt_type(GVirConfigCapabilitiesDomain *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_DOMAIN_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-private.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-private.h new file mode 100644 index 0000000..1092ad0 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-private.h @@ -0,0 +1,39 @@ +/* + * libvirt-gconfig-capabilities-guest-private.h: libvirt guest capabilities + * + * 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
Unneeded
+ +#ifndef __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_PRIVATE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_PRIVATE_H__ + +G_BEGIN_DECLS + +GVirConfigCapabilitiesGuest * +gvir_config_capabilities_guest_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c new file mode 100644 index 0000000..8f42d4c --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c @@ -0,0 +1,153 @@ +/* + * libvirt-gconfig-capabilities-guest.c: libvirt guest capabilities + * + * 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_CAPABILITIES_GUEST_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestPrivate)) + +struct _GVirConfigCapabilitiesGuestPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuest, gvir_config_capabilities_guest, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_guest_class_init(GVirConfigCapabilitiesGuestClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestPrivate)); +} + +static void gvir_config_capabilities_guest_init(GVirConfigCapabilitiesGuest *conn)
Usual 'conn' c&p error
+{ + g_debug("Init GVirConfigCapabilitiesGuest=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_GUEST_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesGuest * +gvir_config_capabilities_guest_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_GUEST(object); +} + +GVirConfigDomainOsType +gvir_config_capabilities_guest_get_os_type(GVirConfigCapabilitiesGuest *caps) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), -1);
Usual issue with -1 not being a member of GVirConfigDomainOsType leading to undefined behaviour. I suggest returning the default value.
+ + return gvir_config_object_get_node_content_genum(GVIR_CONFIG_OBJECT(caps), + "os_type", + GVIR_CONFIG_TYPE_DOMAIN_OS_TYPE, + GVIR_CONFIG_DOMAIN_OS_TYPE_LINUX); +} + +/** + * gvir_config_capabilities_guest_get_cpu_arch: + * + * Gets the CPU architecture capabilities of the guest. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesCPUArch. + */ +GVirConfigCapabilitiesCPUArch * +gvir_config_capabilities_guest_get_cpu_arch(GVirConfigCapabilitiesGuest *caps) +{ + GVirConfigXmlDoc *doc; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), NULL); + + g_object_get(G_OBJECT(caps), "doc", &doc, NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + node = gvir_config_xml_get_element(node, "arch", NULL); + g_return_val_if_fail(node != NULL, NULL); + + return gvir_config_capabilities_cpu_arch_new_from_tree(doc, node); +} + +struct GetFeatureData { + GVirConfigXmlDoc *doc; + GList *features; +}; + +static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigCapabilitiesCPUFeature *feature; + + feature = gvir_config_capabilities_cpu_feature_new_from_tree(data->doc, node); + if (feature != NULL) + data->features = g_list_append(data->features, feature);
I don't think I've mentioned this so far, but since it appears multiple times... usual preference for g_list_prepend in case this code gets copied to handle lists with tons of elements.
+ else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_guest_get_cpu_features: + * + * Gets the CPU features for this guest. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesCPUFeature) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesCPUFeature. + */ +GList * +gvir_config_capabilities_guest_get_cpu_features(GVirConfigCapabilitiesGuest *caps) +{ + struct GetFeatureData data; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + node = gvir_config_xml_get_element(node, "features", NULL); + if (node == NULL) + return NULL; + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + data.features = NULL; + + gvir_config_xml_foreach_child(node, add_feature, &data);
Use of API from gvir-config-object-private.h favoured as usual. gvir_config_xml_* API should be rarely needed.
+ + g_clear_object(&data.doc); + + return data.features; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h new file mode 100644 index 0000000..c70177d --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h @@ -0,0 +1,74 @@ +/* + * libvirt-gconfig-capabilities-guest.h: libvirt guest capabilities + * + * 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_CAPABILITIES_GUEST_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ + +#include "libvirt-gconfig-domain-os.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST (gvir_config_capabilities_guest_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuest)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestClass)) + +typedef struct _GVirConfigCapabilitiesGuest GVirConfigCapabilitiesGuest; +typedef struct _GVirConfigCapabilitiesGuestPrivate GVirConfigCapabilitiesGuestPrivate; +typedef struct _GVirConfigCapabilitiesGuestClass GVirConfigCapabilitiesGuestClass; + +struct _GVirConfigCapabilitiesGuest +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_get_type(void); + +GVirConfigDomainOsType +gvir_config_capabilities_guest_get_os_type(GVirConfigCapabilitiesGuest *caps); + +GVirConfigCapabilitiesCPUArch * +gvir_config_capabilities_guest_get_cpu_arch(GVirConfigCapabilitiesGuest *caps); +GList * +gvir_config_capabilities_guest_get_cpu_features(GVirConfigCapabilitiesGuest *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 9518a30..5f38ac8 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -98,3 +98,55 @@ gvir_config_capabilities_get_host(GVirConfigCapabilities *caps)
return gvir_config_capabilities_host_new_from_tree(doc, node); } + +struct GetGuestData { + GVirConfigXmlDoc *doc; + GList *guests; +}; + +static gboolean add_guest(xmlNodePtr node, gpointer opaque) +{ + struct GetGuestData* data = (struct GetGuestData*)opaque; + GVirConfigCapabilitiesGuest *guest; + + if (g_strcmp0((const gchar *)node->name, "guest") != 0) + return TRUE; + + guest = gvir_config_capabilities_guest_new_from_tree(data->doc, node); + if (guest != NULL) + data->guests = g_list_append(data->guests, guest); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_get_guests: + * + * Gets the list of guest capabilities. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesGuest) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesGuest. + */ +GList * +gvir_config_capabilities_get_guests(GVirConfigCapabilities *caps) +{ + struct GetGuestData data; + xmlNodePtr node; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL); + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + data.guests = NULL; + + gvir_config_xml_foreach_child(node, add_guest, &data); + + if (data.doc != NULL) + g_object_unref(G_OBJECT(data.doc)); + + return data.guests; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h index 18edaf7..7e16099 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h @@ -63,6 +63,7 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, GError **error); GVirConfigCapabilitiesHost * gvir_config_capabilities_get_host(GVirConfigCapabilities *caps); +GList *gvir_config_capabilities_get_guests(GVirConfigCapabilities *caps);
G_END_DECLS
diff --git a/libvirt-gconfig/libvirt-gconfig-private.h b/libvirt-gconfig/libvirt-gconfig-private.h index 845a883..67fd4be 100644 --- a/libvirt-gconfig/libvirt-gconfig-private.h +++ b/libvirt-gconfig/libvirt-gconfig-private.h @@ -24,9 +24,12 @@ #define __LIBVIRT_GCONFIG_PRIVATE_H__
#include <libvirt-gconfig/libvirt-gconfig-domain-device-private.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-domain-private.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature-private.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch-private.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-host-private.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-private.h> #include <libvirt-gconfig/libvirt-gconfig-helpers-private.h> #include <libvirt-gconfig/libvirt-gconfig-object-private.h> #include <libvirt-gconfig/libvirt-gconfig-xml-doc.h> diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index b2b7c15..32d286b 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -28,9 +28,12 @@
#include <libvirt-gconfig/libvirt-gconfig-main.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-domain.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-arch.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-host.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest.h>
d, c, h, g is not very alphabetical ;)
#include <libvirt-gconfig/libvirt-gconfig-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index b1df17b..51f6ce6 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -7,6 +7,7 @@ LIBVIRT_GCONFIG_0.0.8 { gvir_config_capabilities_new; gvir_config_capabilities_new_from_xml; gvir_config_capabilities_get_host; + gvir_config_capabilities_get_guests;
gvir_config_capabilities_host_get_type; gvir_config_capabilities_host_new_from_tree; @@ -20,6 +21,21 @@ LIBVIRT_GCONFIG_0.0.8 { gvir_config_capabilities_cpu_feature_get_type; gvir_config_capabilities_cpu_feature_get_name;
+ gvir_config_capabilities_guest_get_type; + gvir_config_capabilities_guest_new_from_tree; + gvir_config_capabilities_guest_get_os_type; + gvir_config_capabilities_guest_get_cpu_arch; + gvir_config_capabilities_guest_get_cpu_features; + + gvir_config_capabilities_cpu_arch_get_type; + gvir_config_capabilities_cpu_arch_get_name; + gvir_config_capabilities_cpu_arch_get_domains; + gvir_config_capabilities_cpu_arch_get_emulator; + + gvir_config_capabilities_domain_get_type; + gvir_config_capabilities_domain_get_emulator; + gvir_config_capabilities_domain_get_virt_type; + gvir_config_domain_add_device; gvir_config_domain_get_type; gvir_config_domain_lifecycle_action_get_type; -- 1.7.7.6
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Wed, May 2, 2012 at 5:55 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+ +const gchar * +gvir_config_capabilities_domain_get_emulator(GVirConfigCapabilitiesDomain *caps)
Is this method just a copy and paste bug, or is it needed? The reason I'm asking is that I cannot see the corresponding XML on http://libvirt.org/formatcaps.html <domain type="xen"></domain> but maybe this example is partial.
AFAICT, *in practice* you only get child nodes under 'arch/domain' if type is 'kvm'. You might want to check against the example xml I provided with the testcase patch (or see the output of `virsh capabilities` on your machine) and the RNG instead of that online example BTW. -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Tue, May 01, 2012 at 08:30:40PM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
Not quite complete but its a good start. + +#ifndef __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_ARCH_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH (gvir_config_capabilities_cpu_arch_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU_ARCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, GVirConfigCapabilitiesCPUArch)) +#define GVIR_CONFIG_CAPABILITIES_CPU_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, GVirConfigCapabilitiesCPUArchClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_ARCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH)) +#define GVIR_CONFIG_CAPABILITIES_CPU_ARCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_ARCH, GVirConfigCapabilitiesCPUArchClass)) + +typedef struct _GVirConfigCapabilitiesCPUArch GVirConfigCapabilitiesCPUArch; +typedef struct _GVirConfigCapabilitiesCPUArchPrivate GVirConfigCapabilitiesCPUArchPrivate; +typedef struct _GVirConfigCapabilitiesCPUArchClass GVirConfigCapabilitiesCPUArchClass; + +struct _GVirConfigCapabilitiesCPUArch +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCPUArchPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCPUArchClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_arch_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_arch_get_name(GVirConfigCapabilitiesCPUArch *caps); +GList * +gvir_config_capabilities_cpu_arch_get_domains(GVirConfigCapabilitiesCPUArch *caps); +const gchar * +gvir_config_capabilities_cpu_arch_get_emulator(GVirConfigCapabilitiesCPUArch *caps);
I think this should be calling GVirConfigCapabilitiesGuestArch to avoid confusion with CPU model types.
diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-domain.c b/libvirt-gconfig/libvirt-gconfig-capabilities-domain.c new file mode 100644 index 0000000..1023f9d --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-domain.c @@ -0,0 +1,93 @@ +/* + * libvirt-gconfig-capabilities-domain.c: libvirt domain capabilities + * + * 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_CAPABILITIES_DOMAIN_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, GVirConfigCapabilitiesDomainPrivate)) + +struct _GVirConfigCapabilitiesDomainPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesDomain, gvir_config_capabilities_domain, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_domain_class_init(GVirConfigCapabilitiesDomainClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesDomainPrivate)); +} + +static void gvir_config_capabilities_domain_init(GVirConfigCapabilitiesDomain *conn) +{ + g_debug("Init GVirConfigCapabilitiesDomain=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_DOMAIN_GET_PRIVATE(conn); +} + +G_GNUC_INTERNAL GVirConfigCapabilitiesDomain * +gvir_config_capabilities_domain_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, + doc, + NULL, + tree); + + return GVIR_CONFIG_CAPABILITIES_DOMAIN(object); +} + +const gchar * +gvir_config_capabilities_domain_get_emulator(GVirConfigCapabilitiesDomain *caps) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + return gvir_config_xml_get_child_element_content(node, "emulator"); +} + +GVirConfigDomainVirtType +gvir_config_capabilities_domain_get_virt_type(GVirConfigCapabilitiesDomain *caps) +{ + xmlNodePtr node; + const gchar *str; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + + str = gvir_config_xml_get_attribute_content(node, "type"); + if (str == NULL) + return GVIR_CONFIG_DOMAIN_VIRT_QEMU; + + return gvir_config_genum_get_value(GVIR_CONFIG_TYPE_DOMAIN_VIRT_TYPE, + str, + GVIR_CONFIG_DOMAIN_VIRT_QEMU); +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-domain.h b/libvirt-gconfig/libvirt-gconfig-capabilities-domain.h new file mode 100644 index 0000000..6c20191 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-domain.h @@ -0,0 +1,72 @@ +/* + * libvirt-gconfig-capabilities-domain.h: libvirt domain capabilities + * + * 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_CAPABILITIES_DOMAIN_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_DOMAIN_H__ + +#include "libvirt-gconfig-domain.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN (gvir_config_capabilities_domain_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, GVirConfigCapabilitiesDomain)) +#define GVIR_CONFIG_CAPABILITIES_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, GVirConfigCapabilitiesDomainClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN)) +#define GVIR_CONFIG_IS_CAPABILITIES_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN)) +#define GVIR_CONFIG_CAPABILITIES_DOMAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_DOMAIN, GVirConfigCapabilitiesDomainClass)) + +typedef struct _GVirConfigCapabilitiesDomain GVirConfigCapabilitiesDomain; +typedef struct _GVirConfigCapabilitiesDomainPrivate GVirConfigCapabilitiesDomainPrivate; +typedef struct _GVirConfigCapabilitiesDomainClass GVirConfigCapabilitiesDomainClass; + +struct _GVirConfigCapabilitiesDomain +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesDomainPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesDomainClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_domain_get_type(void); + +const gchar * +gvir_config_capabilities_domain_get_emulator(GVirConfigCapabilitiesDomain *caps); + +GVirConfigDomainVirtType +gvir_config_capabilities_domain_get_virt_type(GVirConfigCapabilitiesDomain *caps);
And use GVirConfigCapabilitiesGuestDomain here
+struct GetFeatureData { + GVirConfigXmlDoc *doc; + GList *features; +}; + +static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigCapabilitiesCPUFeature *feature; + + feature = gvir_config_capabilities_cpu_feature_new_from_tree(data->doc, node); + if (feature != NULL) + data->features = g_list_append(data->features, feature); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_guest_get_cpu_features: + * + * Gets the CPU features for this guest. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesCPUFeature) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesCPUFeature. + */
This isn't right - the things in the /capabilities/guest/features XML is nothing at all todo with the /capabilities/host/cpu/feature XML. We should have a separate GVirConfigCapabilitiesGuestFeature object for these, and remove 'cpu' from the method name here.
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index b1df17b..51f6ce6 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -7,6 +7,7 @@ LIBVIRT_GCONFIG_0.0.8 { gvir_config_capabilities_new; gvir_config_capabilities_new_from_xml; gvir_config_capabilities_get_host; + gvir_config_capabilities_get_guests;
gvir_config_capabilities_host_get_type; gvir_config_capabilities_host_new_from_tree; @@ -20,6 +21,21 @@ LIBVIRT_GCONFIG_0.0.8 { gvir_config_capabilities_cpu_feature_get_type; gvir_config_capabilities_cpu_feature_get_name;
+ gvir_config_capabilities_guest_get_type; + gvir_config_capabilities_guest_new_from_tree; + gvir_config_capabilities_guest_get_os_type; + gvir_config_capabilities_guest_get_cpu_arch; + gvir_config_capabilities_guest_get_cpu_features; + + gvir_config_capabilities_cpu_arch_get_type; + gvir_config_capabilities_cpu_arch_get_name; + gvir_config_capabilities_cpu_arch_get_domains; + gvir_config_capabilities_cpu_arch_get_emulator; + + gvir_config_capabilities_domain_get_type; + gvir_config_capabilities_domain_get_emulator; + gvir_config_capabilities_domain_get_virt_type; + gvir_config_domain_add_device; gvir_config_domain_get_type; gvir_config_domain_lifecycle_action_get_type;
Again, add these in a new version block Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

ACK on this one, dunno if we'll want an async variant of this. Christophe On Tue, May 01, 2012 at 08:30:38PM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
--- libvirt-gconfig/libvirt-gconfig-capabilities.c | 4 --- libvirt-gobject/libvirt-gobject-connection.c | 32 ++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-connection.h | 3 ++ libvirt-gobject/libvirt-gobject.sym | 1 + 4 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 4c4df68..3d9d036 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -54,8 +54,6 @@ GVirConfigCapabilities *gvir_config_capabilities_new(void) { GVirConfigObject *object;
- /* FIXME: what is the XML root of the capability node? I suspect it is - * either 'guest' or 'host' */ object = gvir_config_object_new(GVIR_CONFIG_TYPE_CAPABILITIES, "capabilities", DATADIR "/libvirt/schemas/capability.rng"); @@ -67,8 +65,6 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, { GVirConfigObject *object;
- /* FIXME: what is the XML root of the capability node? I suspect it is - * either 'guest' or 'host' */ object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_CAPABILITIES, "capabilities", DATADIR "/libvirt/schemas/capability.rng", diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index baeeb1c..4f04f98 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -1387,3 +1387,35 @@ GVirNodeInfo *gvir_connection_get_node_info(GVirConnection *conn,
return ret; } + +/** + * gvir_connection_get_capabilities: + * @conn: the connection + * @err: return location for any #GError + * + * Return value: (transfer full): a #GVirConfigCapabilities or NULL + */ +GVirConfigCapabilities *gvir_connection_get_capabilities(GVirConnection *conn, + GError **err) +{ + GVirConfigCapabilities *caps; + char *caps_xml; + + g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL); + g_return_val_if_fail(err == NULL || *err == NULL, NULL); + g_return_val_if_fail(conn->priv->conn, NULL); + + caps_xml = virConnectGetCapabilities(conn->priv->conn); + if (caps_xml == NULL) { + gvir_set_error_literal(err, GVIR_CONNECTION_ERROR, + 0, + "Unable to get capabilities"); + return NULL; + } + + caps = gvir_config_capabilities_new_from_xml(caps_xml, err); + free(caps_xml); + + return caps; +} + diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h index 3cc60a2..8c48f67 100644 --- a/libvirt-gobject/libvirt-gobject-connection.h +++ b/libvirt-gobject/libvirt-gobject-connection.h @@ -191,6 +191,9 @@ GVirStream *gvir_connection_get_stream(GVirConnection *conn, GVirNodeInfo *gvir_connection_get_node_info(GVirConnection *conn, GError **err);
+GVirConfigCapabilities *gvir_connection_get_capabilities(GVirConnection *conn, + GError **err); + G_END_DECLS
#endif /* __LIBVIRT_GOBJECT_CONNECTION_H__ */ diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index f43836f..0c9fc37 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -31,6 +31,7 @@ LIBVIRT_GOBJECT_0.0.8 { gvir_connection_create_storage_pool; gvir_connection_start_domain; gvir_connection_get_node_info; + gvir_connection_get_capabilities;
gvir_domain_device_get_type; gvir_domain_device_get_domain; -- 1.7.7.6
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Wed, May 2, 2012 at 2:05 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
ACK on this one, dunno if we'll want an async variant of this.
Yeah, maybe async variant is needed if this situation doesn't improve significantly: https://bugzilla.redhat.com/show_bug.cgi?id=817427 -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Tue, May 01, 2012 at 08:30:38PM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
--- libvirt-gconfig/libvirt-gconfig-capabilities.c | 4 --- libvirt-gobject/libvirt-gobject-connection.c | 32 ++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-connection.h | 3 ++ libvirt-gobject/libvirt-gobject.sym | 1 + 4 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 4c4df68..3d9d036 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -54,8 +54,6 @@ GVirConfigCapabilities *gvir_config_capabilities_new(void) { GVirConfigObject *object;
- /* FIXME: what is the XML root of the capability node? I suspect it is - * either 'guest' or 'host' */ object = gvir_config_object_new(GVIR_CONFIG_TYPE_CAPABILITIES, "capabilities", DATADIR "/libvirt/schemas/capability.rng"); @@ -67,8 +65,6 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, { GVirConfigObject *object;
- /* FIXME: what is the XML root of the capability node? I suspect it is - * either 'guest' or 'host' */ object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_CAPABILITIES, "capabilities", DATADIR "/libvirt/schemas/capability.rng", diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index baeeb1c..4f04f98 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -1387,3 +1387,35 @@ GVirNodeInfo *gvir_connection_get_node_info(GVirConnection *conn,
return ret; } + +/** + * gvir_connection_get_capabilities: + * @conn: the connection + * @err: return location for any #GError + * + * Return value: (transfer full): a #GVirConfigCapabilities or NULL + */ +GVirConfigCapabilities *gvir_connection_get_capabilities(GVirConnection *conn, + GError **err) +{ + GVirConfigCapabilities *caps; + char *caps_xml; + + g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL); + g_return_val_if_fail(err == NULL || *err == NULL, NULL); + g_return_val_if_fail(conn->priv->conn, NULL); + + caps_xml = virConnectGetCapabilities(conn->priv->conn); + if (caps_xml == NULL) { + gvir_set_error_literal(err, GVIR_CONNECTION_ERROR, + 0, + "Unable to get capabilities"); + return NULL; + } + + caps = gvir_config_capabilities_new_from_xml(caps_xml, err); + free(caps_xml); + + return caps; +} + diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h index 3cc60a2..8c48f67 100644 --- a/libvirt-gobject/libvirt-gobject-connection.h +++ b/libvirt-gobject/libvirt-gobject-connection.h @@ -191,6 +191,9 @@ GVirStream *gvir_connection_get_stream(GVirConnection *conn, GVirNodeInfo *gvir_connection_get_node_info(GVirConnection *conn, GError **err);
+GVirConfigCapabilities *gvir_connection_get_capabilities(GVirConnection *conn, + GError **err); + G_END_DECLS
#endif /* __LIBVIRT_GOBJECT_CONNECTION_H__ */ diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index f43836f..0c9fc37 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -31,6 +31,7 @@ LIBVIRT_GOBJECT_0.0.8 { gvir_connection_create_storage_pool; gvir_connection_start_domain; gvir_connection_get_node_info; + gvir_connection_get_capabilities;
gvir_domain_device_get_type; gvir_domain_device_get_domain;
Start a new version block now. Don't change the existing one. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> --- libvirt-gconfig/libvirt-gconfig-capabilities.c | 4 - libvirt-gobject/libvirt-gobject-connection.c | 104 ++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-connection.h | 11 +++ libvirt-gobject/libvirt-gobject.sym | 7 ++ 4 files changed, 122 insertions(+), 4 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 4c4df68..3d9d036 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -54,8 +54,6 @@ GVirConfigCapabilities *gvir_config_capabilities_new(void) { GVirConfigObject *object; - /* FIXME: what is the XML root of the capability node? I suspect it is - * either 'guest' or 'host' */ object = gvir_config_object_new(GVIR_CONFIG_TYPE_CAPABILITIES, "capabilities", DATADIR "/libvirt/schemas/capability.rng"); @@ -67,8 +65,6 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, { GVirConfigObject *object; - /* FIXME: what is the XML root of the capability node? I suspect it is - * either 'guest' or 'host' */ object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_CAPABILITIES, "capabilities", DATADIR "/libvirt/schemas/capability.rng", diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index 186ad9d..9426510 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -1383,3 +1383,107 @@ GVirNodeInfo *gvir_connection_get_node_info(GVirConnection *conn, return ret; } + +/** + * gvir_connection_get_capabilities: + * @conn: the connection + * @err: return location for any #GError + * + * Return value: (transfer full): a #GVirConfigCapabilities or NULL + */ +GVirConfigCapabilities *gvir_connection_get_capabilities(GVirConnection *conn, + GError **err) +{ + GVirConfigCapabilities *caps; + char *caps_xml; + + g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL); + g_return_val_if_fail(err == NULL || *err == NULL, NULL); + g_return_val_if_fail(conn->priv->conn, NULL); + + caps_xml = virConnectGetCapabilities(conn->priv->conn); + if (caps_xml == NULL) { + gvir_set_error_literal(err, GVIR_CONNECTION_ERROR, + 0, + "Unable to get capabilities"); + return NULL; + } + + caps = gvir_config_capabilities_new_from_xml(caps_xml, err); + free(caps_xml); + + return caps; +} + +static void +gvir_connection_get_capabilities_helper(GSimpleAsyncResult *res, + GObject *object, + GCancellable *cancellable) +{ + GVirConnection *conn = GVIR_CONNECTION(object); + GError *err = NULL; + GVirConfigCapabilities *caps; + + caps = gvir_connection_get_capabilities(conn, &err); + if (caps == NULL) { + g_simple_async_result_set_from_error(res, err); + g_error_free(err); + + return; + } + + g_simple_async_result_set_op_res_gpointer(res, caps, g_object_unref); +} + +/** + * gvir_connection_get_capabilities_async: + * @conn: the connection + * @cancellable: (allow-none)(transfer none): cancellation object + * @callback: (scope async): completion callback + * @user_data: (closure): opaque data for callback + */ +void gvir_connection_get_capabilities_async(GVirConnection *conn, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *res; + + res = g_simple_async_result_new(G_OBJECT(conn), + callback, + user_data, + gvir_connection_get_capabilities_async); + g_simple_async_result_run_in_thread(res, + gvir_connection_get_capabilities_helper, + G_PRIORITY_DEFAULT, + cancellable); + g_object_unref(res); +} + +/** + * gvir_connection_get_capabilities_finish: + * @conn: the connection + * @result: (transfer none): async method result + * + * Return value: (transfer full): a #GVirConfigCapabilities or NULL. + */ +GVirConfigCapabilities * +gvir_connection_get_capabilities_finish(GVirConnection *conn, + GAsyncResult *result, + GError **err) +{ + GVirConfigCapabilities *caps; + + g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL); + g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(conn), + gvir_connection_get_capabilities_async), + NULL); + + if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err)) + return NULL; + + caps = g_simple_async_result_get_op_res_gpointer(G_SIMPLE_ASYNC_RESULT(result)); + g_object_ref(caps); + + return caps; +} diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h index 3cc60a2..c80eecf 100644 --- a/libvirt-gobject/libvirt-gobject-connection.h +++ b/libvirt-gobject/libvirt-gobject-connection.h @@ -191,6 +191,17 @@ GVirStream *gvir_connection_get_stream(GVirConnection *conn, GVirNodeInfo *gvir_connection_get_node_info(GVirConnection *conn, GError **err); +GVirConfigCapabilities *gvir_connection_get_capabilities(GVirConnection *conn, + GError **err); +void gvir_connection_get_capabilities_async(GVirConnection *conn, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +GVirConfigCapabilities * +gvir_connection_get_capabilities_finish(GVirConnection *conn, + GAsyncResult *result, + GError **err); + G_END_DECLS #endif /* __LIBVIRT_GOBJECT_CONNECTION_H__ */ diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index f43836f..7121794 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -160,4 +160,11 @@ LIBVIRT_GOBJECT_0.0.8 { *; }; +LIBVIRT_GOBJECT_0.0.9 { + global: + gvir_connection_get_capabilities; + gvir_connection_get_capabilities_async; + gvir_connection_get_capabilities_finish; +} LIBVIRT_GOBJECT_0.0.8; + # .... define new API here using predicted next version number .... -- 1.7.7.6

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> Not quite complete but its a good start. --- libvirt-gconfig/Makefile.am | 6 + .../libvirt-gconfig-capabilities-cpu-feature.c | 58 ++++++++++ .../libvirt-gconfig-capabilities-cpu-feature.h | 67 ++++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c | 115 ++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h | 69 ++++++++++++ .../libvirt-gconfig-capabilities-host.c | 80 ++++++++++++++ .../libvirt-gconfig-capabilities-host.h | 72 ++++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.c | 23 ++++ libvirt-gconfig/libvirt-gconfig-capabilities.h | 5 +- libvirt-gconfig/libvirt-gconfig-object.c | 1 - libvirt-gconfig/libvirt-gconfig.h | 3 + libvirt-gconfig/libvirt-gconfig.sym | 13 +++ 12 files changed, 510 insertions(+), 2 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-host.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-host.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index fd32c3d..54899a3 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -12,6 +12,9 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-main.h \ libvirt-gconfig-object.h \ libvirt-gconfig-capabilities.h \ + libvirt-gconfig-capabilities-host.h \ + libvirt-gconfig-capabilities-cpu.h \ + libvirt-gconfig-capabilities-cpu-feature.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-address.h \ libvirt-gconfig-domain-address-pci.h \ @@ -72,6 +75,9 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-object.c \ libvirt-gconfig-main.c \ libvirt-gconfig-capabilities.c \ + libvirt-gconfig-capabilities-host.c \ + libvirt-gconfig-capabilities-cpu.c \ + libvirt-gconfig-capabilities-cpu-feature.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-address.c \ libvirt-gconfig-domain-address-pci.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c new file mode 100644 index 0000000..b7902a5 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c @@ -0,0 +1,58 @@ +/* + * libvirt-gconfig-capabilities-cpu-feature.c: libvirt CPU feature capabilities + * + * 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_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeaturePrivate)) + +struct _GVirConfigCapabilitiesCpuFeaturePrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCpuFeature, gvir_config_capabilities_cpu_feature, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_cpu_feature_class_init(GVirConfigCapabilitiesCpuFeatureClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCpuFeaturePrivate)); +} + +static void gvir_config_capabilities_cpu_feature_init(GVirConfigCapabilitiesCpuFeature *feature) +{ + g_debug("Init GVirConfigCapabilitiesCpuFeature=%p", feature); + + feature->priv = GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(feature); +} + +const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCpuFeature *caps) +{ + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(caps), + NULL, + "name"); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h new file mode 100644 index 0000000..e1c7835 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h @@ -0,0 +1,67 @@ +/* + * libvirt-gconfig-capabilities-cpu-feature.h: libvirt CPU feature capabilities + * + * 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_CAPABILITIES_CPU_FEATURE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE (gvir_config_capabilities_cpu_feature_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeature)) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeatureClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE)) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeatureClass)) + +typedef struct _GVirConfigCapabilitiesCpuFeature GVirConfigCapabilitiesCpuFeature; +typedef struct _GVirConfigCapabilitiesCpuFeaturePrivate GVirConfigCapabilitiesCpuFeaturePrivate; +typedef struct _GVirConfigCapabilitiesCpuFeatureClass GVirConfigCapabilitiesCpuFeatureClass; + +struct _GVirConfigCapabilitiesCpuFeature +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCpuFeaturePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCpuFeatureClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_feature_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCpuFeature *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c new file mode 100644 index 0000000..c4cba88 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c @@ -0,0 +1,115 @@ +/* + * libvirt-gconfig-capabilities-cpu.c: libvirt CPU capabilities + * + * 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_CAPABILITIES_CPU_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuPrivate)) + +struct _GVirConfigCapabilitiesCpuPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCpu, gvir_config_capabilities_cpu, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_cpu_class_init(GVirConfigCapabilitiesCpuClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCpuPrivate)); +} + +static void gvir_config_capabilities_cpu_init(GVirConfigCapabilitiesCpu *cpu) +{ + g_debug("Init GVirConfigCapabilitiesCpu=%p", cpu); + + cpu->priv = GVIR_CONFIG_CAPABILITIES_CPU_GET_PRIVATE(cpu); +} + +const gchar * +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCpu *caps) +{ + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(caps), "arch"); +} + +struct GetFeatureData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *features; +}; + +static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigObject *feature; + + if (g_strcmp0((const gchar *)node->name, "feature") != 0) + return TRUE; + + feature = gvir_config_object_new_from_tree + (GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, + data->doc, + data->schema, + node); + if (feature != NULL) + data->features = g_list_append(data->features, feature); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_cpu_get_features: + * + * Gets the features of this CPU. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesCpuFeature) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesCpuFeature. + */ +GList * +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *caps) +{ + struct GetFeatureData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU(caps), NULL); + + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(data.schema != NULL, NULL); + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + g_return_val_if_fail(data.doc != NULL, NULL); + data.features = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(caps), + NULL, + add_feature, + &data); + g_clear_object(&data.doc); + + return data.features; +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h new file mode 100644 index 0000000..a414523 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h @@ -0,0 +1,69 @@ +/* + * libvirt-gconfig-capabilities-cpu.h: libvirt CPU capabilities + * + * 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_CAPABILITIES_CPU_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU (gvir_config_capabilities_cpu_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpu)) +#define GVIR_CONFIG_CAPABILITIES_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU)) +#define GVIR_CONFIG_CAPABILITIES_CPU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuClass)) + +typedef struct _GVirConfigCapabilitiesCpu GVirConfigCapabilitiesCpu; +typedef struct _GVirConfigCapabilitiesCpuPrivate GVirConfigCapabilitiesCpuPrivate; +typedef struct _GVirConfigCapabilitiesCpuClass GVirConfigCapabilitiesCpuClass; + +struct _GVirConfigCapabilitiesCpu +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCpuPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCpuClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCpu *caps); +GList * +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.c b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c new file mode 100644 index 0000000..c579ef9 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c @@ -0,0 +1,80 @@ +/* + * libvirt-gconfig-capabilities-host.c: libvirt host capabilities + * + * 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_CAPABILITIES_HOST_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostPrivate)) + +struct _GVirConfigCapabilitiesHostPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesHost, gvir_config_capabilities_host, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_host_class_init(GVirConfigCapabilitiesHostClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesHostPrivate)); +} + +static void gvir_config_capabilities_host_init(GVirConfigCapabilitiesHost *host) +{ + g_debug("Init GVirConfigCapabilitiesHost=%p", host); + + host->priv = GVIR_CONFIG_CAPABILITIES_HOST_GET_PRIVATE(host); +} + +const gchar * +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *caps) +{ + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(caps), "uuid"); +} + +/** + * gvir_config_capabilities_host_get_cpu: + * + * Gets the CPU capabilities of the host. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesCpu. + */ +GVirConfigCapabilitiesCpu * +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *caps) +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_HOST(caps), NULL); + + object = gvir_config_object_get_child_with_type + (GVIR_CONFIG_OBJECT(caps), + "cpu", + GVIR_CONFIG_TYPE_CAPABILITIES_CPU); + + return GVIR_CONFIG_CAPABILITIES_CPU(object); +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.h b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h new file mode 100644 index 0000000..67b61ab --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h @@ -0,0 +1,72 @@ +/* + * libvirt-gconfig-capabilities-host.h: libvirt host capabilities + * + * 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_CAPABILITIES_HOST_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_HOST_H__ + +#include "libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_HOST (gvir_config_capabilities_host_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_HOST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHost)) +#define GVIR_CONFIG_CAPABILITIES_HOST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_HOST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST)) +#define GVIR_CONFIG_IS_CAPABILITIES_HOST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_HOST)) +#define GVIR_CONFIG_CAPABILITIES_HOST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostClass)) + +typedef struct _GVirConfigCapabilitiesHost GVirConfigCapabilitiesHost; +typedef struct _GVirConfigCapabilitiesHostPrivate GVirConfigCapabilitiesHostPrivate; +typedef struct _GVirConfigCapabilitiesHostClass GVirConfigCapabilitiesHostClass; + +struct _GVirConfigCapabilitiesHost +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesHostPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesHostClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_host_get_type(void); + +const gchar * +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *caps); + +GVirConfigCapabilitiesCpu * +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_HOST_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 3d9d036..0bba874 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -24,6 +24,7 @@ #include <config.h> #include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" #define GVIR_CONFIG_CAPABILITIES_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES, GVirConfigCapabilitiesPrivate)) @@ -71,3 +72,25 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, xml, error); return GVIR_CONFIG_CAPABILITIES(object); } + +/** + * gvir_config_capabilities_get_host: + * + * Gets the host capabilities. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesHost. + */ +GVirConfigCapabilitiesHost * +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps) +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL); + + object = gvir_config_object_get_child_with_type + (GVIR_CONFIG_OBJECT(caps), + "host", + GVIR_CONFIG_TYPE_CAPABILITIES_HOST); + + return GVIR_CONFIG_CAPABILITIES_HOST(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h index 733886d..2ec8369 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h @@ -27,6 +27,8 @@ #ifndef __LIBVIRT_GCONFIG_CAPABILITIES_H__ #define __LIBVIRT_GCONFIG_CAPABILITIES_H__ +#include "libvirt-gconfig/libvirt-gconfig-capabilities-host.h" + G_BEGIN_DECLS #define GVIR_CONFIG_TYPE_CAPABILITIES (gvir_config_capabilities_get_type ()) @@ -56,12 +58,13 @@ struct _GVirConfigCapabilitiesClass gpointer padding[20]; }; - GType gvir_config_capabilities_get_type(void); GVirConfigCapabilities *gvir_config_capabilities_new(void); GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, GError **error); +GVirConfigCapabilitiesHost * +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index 0495a3f..30d80a4 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -915,4 +915,3 @@ gvir_config_object_get_child(GVirConfigObject *object, child_name, GVIR_CONFIG_TYPE_OBJECT); } - diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index bd16244..f9be83f 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -29,6 +29,9 @@ #include <libvirt-gconfig/libvirt-gconfig-main.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-host.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address-pci.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 7bc9e2d..7d015f5 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -378,6 +378,19 @@ LIBVIRT_GCONFIG_0.0.9 { global: gvir_config_domain_get_os; gvir_config_domain_os_get_boot_devices; + + gvir_config_capabilities_get_host; + + gvir_config_capabilities_cpu_get_type; + gvir_config_capabilities_cpu_get_arch; + gvir_config_capabilities_cpu_get_features; + + gvir_config_capabilities_cpu_feature_get_type; + gvir_config_capabilities_cpu_feature_get_name; + + gvir_config_capabilities_host_get_type; + gvir_config_capabilities_host_get_uuid; + gvir_config_capabilities_host_get_cpu; } LIBVIRT_GCONFIG_0.0.8; # .... define new API here using predicted next version number .... -- 1.7.7.6

This does not seem to apply on top of master + PATCH 1/4 :-/ Christophe On Wed, May 09, 2012 at 04:16:14AM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
Not quite complete but its a good start. --- libvirt-gconfig/Makefile.am | 6 + .../libvirt-gconfig-capabilities-cpu-feature.c | 58 ++++++++++ .../libvirt-gconfig-capabilities-cpu-feature.h | 67 ++++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c | 115 ++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h | 69 ++++++++++++ .../libvirt-gconfig-capabilities-host.c | 80 ++++++++++++++ .../libvirt-gconfig-capabilities-host.h | 72 ++++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.c | 23 ++++ libvirt-gconfig/libvirt-gconfig-capabilities.h | 5 +- libvirt-gconfig/libvirt-gconfig-object.c | 1 - libvirt-gconfig/libvirt-gconfig.h | 3 + libvirt-gconfig/libvirt-gconfig.sym | 13 +++ 12 files changed, 510 insertions(+), 2 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-host.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-host.h
diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index fd32c3d..54899a3 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -12,6 +12,9 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-main.h \ libvirt-gconfig-object.h \ libvirt-gconfig-capabilities.h \ + libvirt-gconfig-capabilities-host.h \ + libvirt-gconfig-capabilities-cpu.h \ + libvirt-gconfig-capabilities-cpu-feature.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-address.h \ libvirt-gconfig-domain-address-pci.h \ @@ -72,6 +75,9 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-object.c \ libvirt-gconfig-main.c \ libvirt-gconfig-capabilities.c \ + libvirt-gconfig-capabilities-host.c \ + libvirt-gconfig-capabilities-cpu.c \ + libvirt-gconfig-capabilities-cpu-feature.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-address.c \ libvirt-gconfig-domain-address-pci.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c new file mode 100644 index 0000000..b7902a5 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c @@ -0,0 +1,58 @@ +/* + * libvirt-gconfig-capabilities-cpu-feature.c: libvirt CPU feature capabilities + * + * 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_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeaturePrivate)) + +struct _GVirConfigCapabilitiesCpuFeaturePrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCpuFeature, gvir_config_capabilities_cpu_feature, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_cpu_feature_class_init(GVirConfigCapabilitiesCpuFeatureClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCpuFeaturePrivate)); +} + +static void gvir_config_capabilities_cpu_feature_init(GVirConfigCapabilitiesCpuFeature *feature) +{ + g_debug("Init GVirConfigCapabilitiesCpuFeature=%p", feature); + + feature->priv = GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(feature); +} + +const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCpuFeature *caps) +{ + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(caps), + NULL, + "name"); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h new file mode 100644 index 0000000..e1c7835 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h @@ -0,0 +1,67 @@ +/* + * libvirt-gconfig-capabilities-cpu-feature.h: libvirt CPU feature capabilities + * + * 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_CAPABILITIES_CPU_FEATURE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE (gvir_config_capabilities_cpu_feature_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeature)) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeatureClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE)) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeatureClass)) + +typedef struct _GVirConfigCapabilitiesCpuFeature GVirConfigCapabilitiesCpuFeature; +typedef struct _GVirConfigCapabilitiesCpuFeaturePrivate GVirConfigCapabilitiesCpuFeaturePrivate; +typedef struct _GVirConfigCapabilitiesCpuFeatureClass GVirConfigCapabilitiesCpuFeatureClass; + +struct _GVirConfigCapabilitiesCpuFeature +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCpuFeaturePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCpuFeatureClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_feature_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCpuFeature *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c new file mode 100644 index 0000000..c4cba88 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c @@ -0,0 +1,115 @@ +/* + * libvirt-gconfig-capabilities-cpu.c: libvirt CPU capabilities + * + * 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_CAPABILITIES_CPU_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuPrivate)) + +struct _GVirConfigCapabilitiesCpuPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCpu, gvir_config_capabilities_cpu, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_cpu_class_init(GVirConfigCapabilitiesCpuClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCpuPrivate)); +} + +static void gvir_config_capabilities_cpu_init(GVirConfigCapabilitiesCpu *cpu) +{ + g_debug("Init GVirConfigCapabilitiesCpu=%p", cpu); + + cpu->priv = GVIR_CONFIG_CAPABILITIES_CPU_GET_PRIVATE(cpu); +} + +const gchar * +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCpu *caps) +{ + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(caps), "arch"); +} + +struct GetFeatureData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *features; +}; + +static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigObject *feature; + + if (g_strcmp0((const gchar *)node->name, "feature") != 0) + return TRUE; + + feature = gvir_config_object_new_from_tree + (GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, + data->doc, + data->schema, + node); + if (feature != NULL) + data->features = g_list_append(data->features, feature); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_cpu_get_features: + * + * Gets the features of this CPU. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesCpuFeature) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesCpuFeature. + */ +GList * +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *caps) +{ + struct GetFeatureData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU(caps), NULL); + + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(data.schema != NULL, NULL); + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + g_return_val_if_fail(data.doc != NULL, NULL); + data.features = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(caps), + NULL, + add_feature, + &data); + g_clear_object(&data.doc); + + return data.features; +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h new file mode 100644 index 0000000..a414523 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h @@ -0,0 +1,69 @@ +/* + * libvirt-gconfig-capabilities-cpu.h: libvirt CPU capabilities + * + * 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_CAPABILITIES_CPU_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU (gvir_config_capabilities_cpu_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpu)) +#define GVIR_CONFIG_CAPABILITIES_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU)) +#define GVIR_CONFIG_CAPABILITIES_CPU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuClass)) + +typedef struct _GVirConfigCapabilitiesCpu GVirConfigCapabilitiesCpu; +typedef struct _GVirConfigCapabilitiesCpuPrivate GVirConfigCapabilitiesCpuPrivate; +typedef struct _GVirConfigCapabilitiesCpuClass GVirConfigCapabilitiesCpuClass; + +struct _GVirConfigCapabilitiesCpu +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCpuPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCpuClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCpu *caps); +GList * +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.c b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c new file mode 100644 index 0000000..c579ef9 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c @@ -0,0 +1,80 @@ +/* + * libvirt-gconfig-capabilities-host.c: libvirt host capabilities + * + * 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_CAPABILITIES_HOST_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostPrivate)) + +struct _GVirConfigCapabilitiesHostPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesHost, gvir_config_capabilities_host, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_host_class_init(GVirConfigCapabilitiesHostClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesHostPrivate)); +} + +static void gvir_config_capabilities_host_init(GVirConfigCapabilitiesHost *host) +{ + g_debug("Init GVirConfigCapabilitiesHost=%p", host); + + host->priv = GVIR_CONFIG_CAPABILITIES_HOST_GET_PRIVATE(host); +} + +const gchar * +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *caps) +{ + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(caps), "uuid"); +} + +/** + * gvir_config_capabilities_host_get_cpu: + * + * Gets the CPU capabilities of the host. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesCpu. + */ +GVirConfigCapabilitiesCpu * +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *caps) +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_HOST(caps), NULL); + + object = gvir_config_object_get_child_with_type + (GVIR_CONFIG_OBJECT(caps), + "cpu", + GVIR_CONFIG_TYPE_CAPABILITIES_CPU); + + return GVIR_CONFIG_CAPABILITIES_CPU(object); +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.h b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h new file mode 100644 index 0000000..67b61ab --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h @@ -0,0 +1,72 @@ +/* + * libvirt-gconfig-capabilities-host.h: libvirt host capabilities + * + * 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_CAPABILITIES_HOST_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_HOST_H__ + +#include "libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_HOST (gvir_config_capabilities_host_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_HOST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHost)) +#define GVIR_CONFIG_CAPABILITIES_HOST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_HOST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST)) +#define GVIR_CONFIG_IS_CAPABILITIES_HOST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_HOST)) +#define GVIR_CONFIG_CAPABILITIES_HOST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostClass)) + +typedef struct _GVirConfigCapabilitiesHost GVirConfigCapabilitiesHost; +typedef struct _GVirConfigCapabilitiesHostPrivate GVirConfigCapabilitiesHostPrivate; +typedef struct _GVirConfigCapabilitiesHostClass GVirConfigCapabilitiesHostClass; + +struct _GVirConfigCapabilitiesHost +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesHostPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesHostClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_host_get_type(void); + +const gchar * +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *caps); + +GVirConfigCapabilitiesCpu * +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_HOST_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 3d9d036..0bba874 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -24,6 +24,7 @@ #include <config.h>
#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h"
#define GVIR_CONFIG_CAPABILITIES_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES, GVirConfigCapabilitiesPrivate)) @@ -71,3 +72,25 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, xml, error); return GVIR_CONFIG_CAPABILITIES(object); } + +/** + * gvir_config_capabilities_get_host: + * + * Gets the host capabilities. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesHost. + */ +GVirConfigCapabilitiesHost * +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps) +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL); + + object = gvir_config_object_get_child_with_type + (GVIR_CONFIG_OBJECT(caps), + "host", + GVIR_CONFIG_TYPE_CAPABILITIES_HOST); + + return GVIR_CONFIG_CAPABILITIES_HOST(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h index 733886d..2ec8369 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h @@ -27,6 +27,8 @@ #ifndef __LIBVIRT_GCONFIG_CAPABILITIES_H__ #define __LIBVIRT_GCONFIG_CAPABILITIES_H__
+#include "libvirt-gconfig/libvirt-gconfig-capabilities-host.h" + G_BEGIN_DECLS
#define GVIR_CONFIG_TYPE_CAPABILITIES (gvir_config_capabilities_get_type ()) @@ -56,12 +58,13 @@ struct _GVirConfigCapabilitiesClass gpointer padding[20]; };
- GType gvir_config_capabilities_get_type(void);
GVirConfigCapabilities *gvir_config_capabilities_new(void); GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, GError **error); +GVirConfigCapabilitiesHost * +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps);
G_END_DECLS
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index 0495a3f..30d80a4 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -915,4 +915,3 @@ gvir_config_object_get_child(GVirConfigObject *object, child_name, GVIR_CONFIG_TYPE_OBJECT); } - diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index bd16244..f9be83f 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -29,6 +29,9 @@ #include <libvirt-gconfig/libvirt-gconfig-main.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-host.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address-pci.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 7bc9e2d..7d015f5 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -378,6 +378,19 @@ LIBVIRT_GCONFIG_0.0.9 { global: gvir_config_domain_get_os; gvir_config_domain_os_get_boot_devices; + + gvir_config_capabilities_get_host; + + gvir_config_capabilities_cpu_get_type; + gvir_config_capabilities_cpu_get_arch; + gvir_config_capabilities_cpu_get_features; + + gvir_config_capabilities_cpu_feature_get_type; + gvir_config_capabilities_cpu_feature_get_name; + + gvir_config_capabilities_host_get_type; + gvir_config_capabilities_host_get_uuid; + gvir_config_capabilities_host_get_cpu; } LIBVIRT_GCONFIG_0.0.8;
# .... define new API here using predicted next version number .... -- 1.7.7.6
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Wed, May 9, 2012 at 4:17 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
This does not seem to apply on top of master + PATCH 1/4 :-/
Sorry, I forgot to mention this capabilities series is on top the other changes I sent earlier. -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Wed, May 09, 2012 at 04:30:39PM +0300, Zeeshan Ali (Khattak) wrote:
On Wed, May 9, 2012 at 4:17 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
This does not seem to apply on top of master + PATCH 1/4 :-/
Sorry, I forgot to mention this capabilities series is on top the other changes I sent earlier.
Ah I got them in the opposite order in my INBOX so I started with these patches ;) Christophe

Sorry, I messed up the quoting while reviewing this, hope it's fine with my comments inline in the patch (looking for lines not starting with + should show all my comments), sorry for the inconvenience. diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index fd32c3d..54899a3 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -12,6 +12,9 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-main.h \ libvirt-gconfig-object.h \ libvirt-gconfig-capabilities.h \ + libvirt-gconfig-capabilities-host.h \ + libvirt-gconfig-capabilities-cpu.h \ + libvirt-gconfig-capabilities-cpu-feature.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-address.h \ libvirt-gconfig-domain-address-pci.h \ @@ -72,6 +75,9 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-object.c \ libvirt-gconfig-main.c \ libvirt-gconfig-capabilities.c \ + libvirt-gconfig-capabilities-host.c \ + libvirt-gconfig-capabilities-cpu.c \ + libvirt-gconfig-capabilities-cpu-feature.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-address.c \ libvirt-gconfig-domain-address-pci.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c new file mode 100644 index 0000000..b7902a5 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c @@ -0,0 +1,58 @@ +/* + * libvirt-gconfig-capabilities-cpu-feature.c: libvirt CPU feature capabilities + * + * 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_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeaturePrivate)) + +struct _GVirConfigCapabilitiesCpuFeaturePrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCpuFeature, gvir_config_capabilities_cpu_feature, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_cpu_feature_class_init(GVirConfigCapabilitiesCpuFeatureClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCpuFeaturePrivate)); +} + +static void gvir_config_capabilities_cpu_feature_init(GVirConfigCapabilitiesCpuFeature *feature) +{ + g_debug("Init GVirConfigCapabilitiesCpuFeature=%p", feature); + + feature->priv = GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(feature); +} + +const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCpuFeature *caps) s/caps/feature +{ g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE(feature); + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(caps), + NULL, + "name"); +} Can you add the 2 other attributes while you are at it? diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h new file mode 100644 index 0000000..e1c7835 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h @@ -0,0 +1,67 @@ +/* + * libvirt-gconfig-capabilities-cpu-feature.h: libvirt CPU feature capabilities + * + * 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_CAPABILITIES_CPU_FEATURE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE (gvir_config_capabilities_cpu_feature_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeature)) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeatureClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE)) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeatureClass)) + +typedef struct _GVirConfigCapabilitiesCpuFeature GVirConfigCapabilitiesCpuFeature; +typedef struct _GVirConfigCapabilitiesCpuFeaturePrivate GVirConfigCapabilitiesCpuFeaturePrivate; +typedef struct _GVirConfigCapabilitiesCpuFeatureClass GVirConfigCapabilitiesCpuFeatureClass; + +struct _GVirConfigCapabilitiesCpuFeature +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCpuFeaturePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCpuFeatureClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_feature_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCpuFeature *caps); s/caps/feature/ + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c new file mode 100644 index 0000000..c4cba88 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c @@ -0,0 +1,115 @@ +/* + * libvirt-gconfig-capabilities-cpu.c: libvirt CPU capabilities + * + * 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_CAPABILITIES_CPU_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuPrivate)) + +struct _GVirConfigCapabilitiesCpuPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCpu, gvir_config_capabilities_cpu, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_cpu_class_init(GVirConfigCapabilitiesCpuClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCpuPrivate)); +} + +static void gvir_config_capabilities_cpu_init(GVirConfigCapabilitiesCpu *cpu) +{ + g_debug("Init GVirConfigCapabilitiesCpu=%p", cpu); + + cpu->priv = GVIR_CONFIG_CAPABILITIES_CPU_GET_PRIVATE(cpu); +} + +const gchar * +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCpu *caps) +{ + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(caps), "arch"); +} + +struct GetFeatureData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *features; +}; + +static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigObject *feature; + + if (g_strcmp0((const gchar *)node->name, "feature") != 0) + return TRUE; + + feature = gvir_config_object_new_from_tree + (GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, + data->doc, + data->schema, + node); + if (feature != NULL) + data->features = g_list_append(data->features, feature); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_cpu_get_features: + * + * Gets the features of this CPU. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesCpuFeature) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesCpuFeature. + */ +GList * +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *caps) s/caps/cpu (?) +{ + struct GetFeatureData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU(caps), NULL); + + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(data.schema != NULL, NULL); Usual comment about allowing NULL schemas + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + g_return_val_if_fail(data.doc != NULL, NULL); + data.features = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(caps), + NULL, + add_feature, + &data); + g_clear_object(&data.doc); + + return data.features; +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h new file mode 100644 index 0000000..a414523 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h @@ -0,0 +1,69 @@ +/* + * libvirt-gconfig-capabilities-cpu.h: libvirt CPU capabilities + * + * 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_CAPABILITIES_CPU_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU (gvir_config_capabilities_cpu_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpu)) +#define GVIR_CONFIG_CAPABILITIES_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU)) +#define GVIR_CONFIG_CAPABILITIES_CPU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuClass)) + +typedef struct _GVirConfigCapabilitiesCpu GVirConfigCapabilitiesCpu; +typedef struct _GVirConfigCapabilitiesCpuPrivate GVirConfigCapabilitiesCpuPrivate; +typedef struct _GVirConfigCapabilitiesCpuClass GVirConfigCapabilitiesCpuClass; + +struct _GVirConfigCapabilitiesCpu +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCpuPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCpuClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCpu *caps); s/caps/cpu +GList * +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *caps); s/caps/cpu + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.c b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c new file mode 100644 index 0000000..c579ef9 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c @@ -0,0 +1,80 @@ +/* + * libvirt-gconfig-capabilities-host.c: libvirt host capabilities + * + * 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_CAPABILITIES_HOST_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostPrivate)) + +struct _GVirConfigCapabilitiesHostPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesHost, gvir_config_capabilities_host, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_host_class_init(GVirConfigCapabilitiesHostClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesHostPrivate)); +} + +static void gvir_config_capabilities_host_init(GVirConfigCapabilitiesHost *host) +{ + g_debug("Init GVirConfigCapabilitiesHost=%p", host); + + host->priv = GVIR_CONFIG_CAPABILITIES_HOST_GET_PRIVATE(host); +} + +const gchar * +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *caps) s/caps/host +{ g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_HOST(host), NULL); + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(caps), "uuid"); +} + +/** + * gvir_config_capabilities_host_get_cpu: + * + * Gets the CPU capabilities of the host. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesCpu. + */ +GVirConfigCapabilitiesCpu * +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *caps) s/caps/host +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_HOST(caps), NULL); + + object = gvir_config_object_get_child_with_type + (GVIR_CONFIG_OBJECT(caps), + "cpu", + GVIR_CONFIG_TYPE_CAPABILITIES_CPU); + + return GVIR_CONFIG_CAPABILITIES_CPU(object); +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.h b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h new file mode 100644 index 0000000..67b61ab --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h @@ -0,0 +1,72 @@ +/* + * libvirt-gconfig-capabilities-host.h: libvirt host capabilities + * + * 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_CAPABILITIES_HOST_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_HOST_H__ + +#include "libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_HOST (gvir_config_capabilities_host_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_HOST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHost)) +#define GVIR_CONFIG_CAPABILITIES_HOST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_HOST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST)) +#define GVIR_CONFIG_IS_CAPABILITIES_HOST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_HOST)) +#define GVIR_CONFIG_CAPABILITIES_HOST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostClass)) + +typedef struct _GVirConfigCapabilitiesHost GVirConfigCapabilitiesHost; +typedef struct _GVirConfigCapabilitiesHostPrivate GVirConfigCapabilitiesHostPrivate; +typedef struct _GVirConfigCapabilitiesHostClass GVirConfigCapabilitiesHostClass; + +struct _GVirConfigCapabilitiesHost +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesHostPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesHostClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_host_get_type(void); + +const gchar * +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *caps); s/caps/host + +GVirConfigCapabilitiesCpu * +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *caps); s/caps/host + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_HOST_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 3d9d036..0bba874 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -24,6 +24,7 @@ #include <config.h> #include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" #define GVIR_CONFIG_CAPABILITIES_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES, GVirConfigCapabilitiesPrivate)) @@ -71,3 +72,25 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, xml, error); return GVIR_CONFIG_CAPABILITIES(object); } + +/** + * gvir_config_capabilities_get_host: + * + * Gets the host capabilities. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesHost. + */ +GVirConfigCapabilitiesHost * +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps) +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL); + + object = gvir_config_object_get_child_with_type + (GVIR_CONFIG_OBJECT(caps), + "host", + GVIR_CONFIG_TYPE_CAPABILITIES_HOST); + + return GVIR_CONFIG_CAPABILITIES_HOST(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h index 733886d..2ec8369 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h @@ -27,6 +27,8 @@ #ifndef __LIBVIRT_GCONFIG_CAPABILITIES_H__ #define __LIBVIRT_GCONFIG_CAPABILITIES_H__ +#include "libvirt-gconfig/libvirt-gconfig-capabilities-host.h" + G_BEGIN_DECLS #define GVIR_CONFIG_TYPE_CAPABILITIES (gvir_config_capabilities_get_type ()) @@ -56,12 +58,13 @@ struct _GVirConfigCapabilitiesClass gpointer padding[20]; }; - GType gvir_config_capabilities_get_type(void); GVirConfigCapabilities *gvir_config_capabilities_new(void); GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, GError **error); +GVirConfigCapabilitiesHost * +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index 0495a3f..30d80a4 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -915,4 +915,3 @@ gvir_config_object_get_child(GVirConfigObject *object, child_name, GVIR_CONFIG_TYPE_OBJECT); } - This doesn't belong in this patch, feel free to sneak it in a patch modifying -object.c diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index bd16244..f9be83f 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -29,6 +29,9 @@ #include <libvirt-gconfig/libvirt-gconfig-main.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-host.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address-pci.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 7bc9e2d..7d015f5 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -378,6 +378,19 @@ LIBVIRT_GCONFIG_0.0.9 { global: gvir_config_domain_get_os; gvir_config_domain_os_get_boot_devices; + + gvir_config_capabilities_get_host; + + gvir_config_capabilities_cpu_get_type; + gvir_config_capabilities_cpu_get_arch; + gvir_config_capabilities_cpu_get_features; + + gvir_config_capabilities_cpu_feature_get_type; + gvir_config_capabilities_cpu_feature_get_name; + + gvir_config_capabilities_host_get_type; + gvir_config_capabilities_host_get_uuid; + gvir_config_capabilities_host_get_cpu; } LIBVIRT_GCONFIG_0.0.8; # .... define new API here using predicted next version number .... -- 1.7.7.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Wed, May 9, 2012 at 7:10 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCpuFeature *caps)
s/caps/feature
I was thinking of using 'caps' for all GVirConfigCapabilities* instances but no strong feelings so I'll change..
+{
g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE(feature);
+ return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(caps), + NULL, + "name"); +}
Can you add the 2 other attributes while you are at it?
Which other 2 attributes? AFAICT from RNG and 'capabilities' xml on my machine, those attributes only exists in guest features.
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index 0495a3f..30d80a4 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -915,4 +915,3 @@ gvir_config_object_get_child(GVirConfigObject *object, child_name, GVIR_CONFIG_TYPE_OBJECT); } -
This doesn't belong in this patch, feel free to sneak it in a patch modifying -object.c
Marc-Andre would disagree but sure. -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Wed, May 09, 2012 at 11:00:51PM +0300, Zeeshan Ali (Khattak) wrote:
On Wed, May 9, 2012 at 7:10 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCpuFeature *caps)
s/caps/feature
I was thinking of using 'caps' for all GVirConfigCapabilities* instances but no strong feelings so I'll change..
At the moment, it's not consistent at all, in some files some methods have a caps argument, and some others a feature argument (and sometimes 'conn' is used). Since some changes are needed, I have a slight preference for more specific names
+{
g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE(feature);
+ return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(caps), + NULL, + "name"); +}
Can you add the 2 other attributes while you are at it?
Which other 2 attributes? AFAICT from RNG and 'capabilities' xml on my machine, those attributes only exists in guest features.
Ah sorry, confusion on my side, forget this comment ;) Christophe

On Wed, May 09, 2012 at 11:00:51PM +0300, Zeeshan Ali (Khattak) wrote:
On Wed, May 9, 2012 at 7:10 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
This doesn't belong in this patch, feel free to sneak it in a patch modifying -object.c
Marc-Andre would disagree but sure.
Ah, it's actually introduced by "More internal helpers for GVirConfigObject subclasses" so just remove this trailing new line from this patch. Christophe

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> Not quite complete but its a good start. --- libvirt-gconfig/Makefile.am | 6 + .../libvirt-gconfig-capabilities-cpu-feature.c | 58 ++++++++++ .../libvirt-gconfig-capabilities-cpu-feature.h | 67 ++++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c | 114 ++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h | 69 ++++++++++++ .../libvirt-gconfig-capabilities-host.c | 80 ++++++++++++++ .../libvirt-gconfig-capabilities-host.h | 72 ++++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.c | 23 ++++ libvirt-gconfig/libvirt-gconfig-capabilities.h | 5 +- libvirt-gconfig/libvirt-gconfig.h | 3 + libvirt-gconfig/libvirt-gconfig.sym | 13 +++ 11 files changed, 509 insertions(+), 1 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-host.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-host.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index fd32c3d..54899a3 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -12,6 +12,9 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-main.h \ libvirt-gconfig-object.h \ libvirt-gconfig-capabilities.h \ + libvirt-gconfig-capabilities-host.h \ + libvirt-gconfig-capabilities-cpu.h \ + libvirt-gconfig-capabilities-cpu-feature.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-address.h \ libvirt-gconfig-domain-address-pci.h \ @@ -72,6 +75,9 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-object.c \ libvirt-gconfig-main.c \ libvirt-gconfig-capabilities.c \ + libvirt-gconfig-capabilities-host.c \ + libvirt-gconfig-capabilities-cpu.c \ + libvirt-gconfig-capabilities-cpu-feature.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-address.c \ libvirt-gconfig-domain-address-pci.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c new file mode 100644 index 0000000..0c71885 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c @@ -0,0 +1,58 @@ +/* + * libvirt-gconfig-capabilities-cpu-feature.c: libvirt CPU feature capabilities + * + * 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_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeaturePrivate)) + +struct _GVirConfigCapabilitiesCpuFeaturePrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCpuFeature, gvir_config_capabilities_cpu_feature, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_cpu_feature_class_init(GVirConfigCapabilitiesCpuFeatureClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCpuFeaturePrivate)); +} + +static void gvir_config_capabilities_cpu_feature_init(GVirConfigCapabilitiesCpuFeature *feature) +{ + g_debug("Init GVirConfigCapabilitiesCpuFeature=%p", feature); + + feature->priv = GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(feature); +} + +const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCpuFeature *feature) +{ + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(feature), + NULL, + "name"); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h new file mode 100644 index 0000000..8bb2f2b --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h @@ -0,0 +1,67 @@ +/* + * libvirt-gconfig-capabilities-cpu-feature.h: libvirt CPU feature capabilities + * + * 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_CAPABILITIES_CPU_FEATURE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE (gvir_config_capabilities_cpu_feature_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeature)) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeatureClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE)) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeatureClass)) + +typedef struct _GVirConfigCapabilitiesCpuFeature GVirConfigCapabilitiesCpuFeature; +typedef struct _GVirConfigCapabilitiesCpuFeaturePrivate GVirConfigCapabilitiesCpuFeaturePrivate; +typedef struct _GVirConfigCapabilitiesCpuFeatureClass GVirConfigCapabilitiesCpuFeatureClass; + +struct _GVirConfigCapabilitiesCpuFeature +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCpuFeaturePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCpuFeatureClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_feature_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCpuFeature *feature); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c new file mode 100644 index 0000000..e9a3f10 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c @@ -0,0 +1,114 @@ +/* + * libvirt-gconfig-capabilities-cpu.c: libvirt CPU capabilities + * + * 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_CAPABILITIES_CPU_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuPrivate)) + +struct _GVirConfigCapabilitiesCpuPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCpu, gvir_config_capabilities_cpu, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_cpu_class_init(GVirConfigCapabilitiesCpuClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCpuPrivate)); +} + +static void gvir_config_capabilities_cpu_init(GVirConfigCapabilitiesCpu *cpu) +{ + g_debug("Init GVirConfigCapabilitiesCpu=%p", cpu); + + cpu->priv = GVIR_CONFIG_CAPABILITIES_CPU_GET_PRIVATE(cpu); +} + +const gchar * +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCpu *cpu) +{ + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(cpu), "arch"); +} + +struct GetFeatureData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *features; +}; + +static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigObject *feature; + + if (g_strcmp0((const gchar *)node->name, "feature") != 0) + return TRUE; + + feature = gvir_config_object_new_from_tree + (GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, + data->doc, + data->schema, + node); + if (feature != NULL) + data->features = g_list_append(data->features, feature); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_cpu_get_features: + * + * Gets the features of this CPU. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesCpuFeature) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesCpuFeature. + */ +GList * +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *cpu) +{ + struct GetFeatureData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU(cpu), NULL); + + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(cpu)); + g_object_get(G_OBJECT(cpu), "doc", &data.doc, NULL); + g_return_val_if_fail(data.doc != NULL, NULL); + data.features = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(cpu), + NULL, + add_feature, + &data); + g_clear_object(&data.doc); + + return data.features; +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h new file mode 100644 index 0000000..8b221ae --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h @@ -0,0 +1,69 @@ +/* + * libvirt-gconfig-capabilities-cpu.h: libvirt CPU capabilities + * + * 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_CAPABILITIES_CPU_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU (gvir_config_capabilities_cpu_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpu)) +#define GVIR_CONFIG_CAPABILITIES_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU)) +#define GVIR_CONFIG_CAPABILITIES_CPU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuClass)) + +typedef struct _GVirConfigCapabilitiesCpu GVirConfigCapabilitiesCpu; +typedef struct _GVirConfigCapabilitiesCpuPrivate GVirConfigCapabilitiesCpuPrivate; +typedef struct _GVirConfigCapabilitiesCpuClass GVirConfigCapabilitiesCpuClass; + +struct _GVirConfigCapabilitiesCpu +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCpuPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCpuClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCpu *cpu); +GList * +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *cpu); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.c b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c new file mode 100644 index 0000000..47ad0fc --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c @@ -0,0 +1,80 @@ +/* + * libvirt-gconfig-capabilities-host.c: libvirt host capabilities + * + * 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_CAPABILITIES_HOST_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostPrivate)) + +struct _GVirConfigCapabilitiesHostPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesHost, gvir_config_capabilities_host, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_host_class_init(GVirConfigCapabilitiesHostClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesHostPrivate)); +} + +static void gvir_config_capabilities_host_init(GVirConfigCapabilitiesHost *host) +{ + g_debug("Init GVirConfigCapabilitiesHost=%p", host); + + host->priv = GVIR_CONFIG_CAPABILITIES_HOST_GET_PRIVATE(host); +} + +const gchar * +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *host) +{ + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(host), "uuid"); +} + +/** + * gvir_config_capabilities_host_get_cpu: + * + * Gets the CPU capabilities of the host. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesCpu. + */ +GVirConfigCapabilitiesCpu * +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *host) +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_HOST(host), NULL); + + object = gvir_config_object_get_child_with_type + (GVIR_CONFIG_OBJECT(host), + "cpu", + GVIR_CONFIG_TYPE_CAPABILITIES_CPU); + + return GVIR_CONFIG_CAPABILITIES_CPU(object); +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.h b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h new file mode 100644 index 0000000..d5e325b --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h @@ -0,0 +1,72 @@ +/* + * libvirt-gconfig-capabilities-host.h: libvirt host capabilities + * + * 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_CAPABILITIES_HOST_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_HOST_H__ + +#include "libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_HOST (gvir_config_capabilities_host_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_HOST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHost)) +#define GVIR_CONFIG_CAPABILITIES_HOST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_HOST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST)) +#define GVIR_CONFIG_IS_CAPABILITIES_HOST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_HOST)) +#define GVIR_CONFIG_CAPABILITIES_HOST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostClass)) + +typedef struct _GVirConfigCapabilitiesHost GVirConfigCapabilitiesHost; +typedef struct _GVirConfigCapabilitiesHostPrivate GVirConfigCapabilitiesHostPrivate; +typedef struct _GVirConfigCapabilitiesHostClass GVirConfigCapabilitiesHostClass; + +struct _GVirConfigCapabilitiesHost +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesHostPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesHostClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_host_get_type(void); + +const gchar * +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *host); + +GVirConfigCapabilitiesCpu * +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *host); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_HOST_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 6fb9af7..43b91e0 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -24,6 +24,7 @@ #include <config.h> #include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h" #define GVIR_CONFIG_CAPABILITIES_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES, GVirConfigCapabilitiesPrivate)) @@ -71,3 +72,25 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, xml, error); return GVIR_CONFIG_CAPABILITIES(object); } + +/** + * gvir_config_capabilities_get_host: + * + * Gets the host capabilities. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesHost. + */ +GVirConfigCapabilitiesHost * +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps) +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL); + + object = gvir_config_object_get_child_with_type + (GVIR_CONFIG_OBJECT(caps), + "host", + GVIR_CONFIG_TYPE_CAPABILITIES_HOST); + + return GVIR_CONFIG_CAPABILITIES_HOST(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h index 733886d..2ec8369 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h @@ -27,6 +27,8 @@ #ifndef __LIBVIRT_GCONFIG_CAPABILITIES_H__ #define __LIBVIRT_GCONFIG_CAPABILITIES_H__ +#include "libvirt-gconfig/libvirt-gconfig-capabilities-host.h" + G_BEGIN_DECLS #define GVIR_CONFIG_TYPE_CAPABILITIES (gvir_config_capabilities_get_type ()) @@ -56,12 +58,13 @@ struct _GVirConfigCapabilitiesClass gpointer padding[20]; }; - GType gvir_config_capabilities_get_type(void); GVirConfigCapabilities *gvir_config_capabilities_new(void); GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, GError **error); +GVirConfigCapabilitiesHost * +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index bd16244..f9be83f 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -29,6 +29,9 @@ #include <libvirt-gconfig/libvirt-gconfig-main.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-host.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address-pci.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 7bc9e2d..7d015f5 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -378,6 +378,19 @@ LIBVIRT_GCONFIG_0.0.9 { global: gvir_config_domain_get_os; gvir_config_domain_os_get_boot_devices; + + gvir_config_capabilities_get_host; + + gvir_config_capabilities_cpu_get_type; + gvir_config_capabilities_cpu_get_arch; + gvir_config_capabilities_cpu_get_features; + + gvir_config_capabilities_cpu_feature_get_type; + gvir_config_capabilities_cpu_feature_get_name; + + gvir_config_capabilities_host_get_type; + gvir_config_capabilities_host_get_uuid; + gvir_config_capabilities_host_get_cpu; } LIBVIRT_GCONFIG_0.0.8; # .... define new API here using predicted next version number .... -- 1.7.7.6

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> Not quite complete but its a good start. --- libvirt-gconfig/Makefile.am | 8 + .../libvirt-gconfig-capabilities-guest-arch.c | 125 ++++++++++++++++++ .../libvirt-gconfig-capabilities-guest-arch.h | 71 ++++++++++ .../libvirt-gconfig-capabilities-guest-domain.c | 73 ++++++++++ .../libvirt-gconfig-capabilities-guest-domain.h | 72 ++++++++++ .../libvirt-gconfig-capabilities-guest-feature.c | 61 +++++++++ .../libvirt-gconfig-capabilities-guest-feature.h | 67 ++++++++++ .../libvirt-gconfig-capabilities-guest.c | 139 ++++++++++++++++++++ .../libvirt-gconfig-capabilities-guest.h | 75 +++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.c | 55 ++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.h | 1 + libvirt-gconfig/libvirt-gconfig.h | 6 +- libvirt-gconfig/libvirt-gconfig.sym | 18 +++ 13 files changed, 770 insertions(+), 1 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 54899a3..4bc3ee1 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -15,6 +15,10 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-capabilities-host.h \ libvirt-gconfig-capabilities-cpu.h \ libvirt-gconfig-capabilities-cpu-feature.h \ + libvirt-gconfig-capabilities-guest.h \ + libvirt-gconfig-capabilities-guest-arch.h \ + libvirt-gconfig-capabilities-guest-domain.h \ + libvirt-gconfig-capabilities-guest-feature.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-address.h \ libvirt-gconfig-domain-address-pci.h \ @@ -78,6 +82,10 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-capabilities-host.c \ libvirt-gconfig-capabilities-cpu.c \ libvirt-gconfig-capabilities-cpu-feature.c \ + libvirt-gconfig-capabilities-guest.c \ + libvirt-gconfig-capabilities-guest-arch.c \ + libvirt-gconfig-capabilities-guest-domain.c \ + libvirt-gconfig-capabilities-guest-feature.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-address.c \ libvirt-gconfig-domain-address-pci.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c new file mode 100644 index 0000000..fe45525 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c @@ -0,0 +1,125 @@ +/* + * libvirt-gconfig-capabilities-cpu-arch.c: libvirt guest architecture capabilities + * + * 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_CAPABILITIES_GUEST_ARCH_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArchPrivate)) + +struct _GVirConfigCapabilitiesGuestArchPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuestArch, gvir_config_capabilities_guest_arch, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_guest_arch_class_init(GVirConfigCapabilitiesGuestArchClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestArchPrivate)); +} + +static void gvir_config_capabilities_guest_arch_init(GVirConfigCapabilitiesGuestArch *arch) +{ + g_debug("Init GVirConfigCapabilitiesGuestArch=%p", arch); + + arch->priv = GVIR_CONFIG_CAPABILITIES_GUEST_ARCH_GET_PRIVATE(arch); +} + +const gchar * +gvir_config_capabilities_guest_arch_get_name(GVirConfigCapabilitiesGuestArch *arch) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(arch), NULL); + + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(arch), + NULL, + "name"); +} + +struct GetDomainData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *domains; +}; + +static gboolean add_domain(xmlNodePtr node, gpointer opaque) +{ + struct GetDomainData* data = (struct GetDomainData*)opaque; + GVirConfigObject *object; + + if (g_strcmp0((const gchar *)node->name, "domain") != 0) + return TRUE; + + object = gvir_config_object_new_from_tree + (GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, + data->doc, + data->schema, + node); + if (object != NULL) + data->domains = g_list_append(data->domains, object); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_guest_arch_get_domains: + * + * Gets the possible domains for this architecture. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesGuestDomain) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesGuestDomain. + */ +GList * +gvir_config_capabilities_guest_arch_get_domains(GVirConfigCapabilitiesGuestArch *arch) +{ + struct GetDomainData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(arch), NULL); + + g_object_get(G_OBJECT(arch), "doc", &data.doc, NULL); + g_return_val_if_fail(data.doc != NULL, NULL); + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(arch)); + data.domains = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(arch), + NULL, + add_domain, + &data); + g_clear_object(&data.doc); + + return data.domains; +} + +const gchar * +gvir_config_capabilities_guest_arch_get_emulator(GVirConfigCapabilitiesGuestArch *arch) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(arch), NULL); + + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(arch), + "emulator"); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h new file mode 100644 index 0000000..08612f2 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h @@ -0,0 +1,71 @@ +/* + * libvirt-gconfig-capabilities-guest-arch.h: libvirt guest architecture capabilities + * + * 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_CAPABILITIES_GUEST_ARCH_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_ARCH_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH (gvir_config_capabilities_guest_arch_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST_ARCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArch)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArchClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_ARCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArchClass)) + +typedef struct _GVirConfigCapabilitiesGuestArch GVirConfigCapabilitiesGuestArch; +typedef struct _GVirConfigCapabilitiesGuestArchPrivate GVirConfigCapabilitiesGuestArchPrivate; +typedef struct _GVirConfigCapabilitiesGuestArchClass GVirConfigCapabilitiesGuestArchClass; + +struct _GVirConfigCapabilitiesGuestArch +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestArchPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestArchClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_arch_get_type(void); + +const gchar * +gvir_config_capabilities_guest_arch_get_name(GVirConfigCapabilitiesGuestArch *arch); +GList * +gvir_config_capabilities_guest_arch_get_domains(GVirConfigCapabilitiesGuestArch *arch); +const gchar * +gvir_config_capabilities_guest_arch_get_emulator(GVirConfigCapabilitiesGuestArch *arch); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_ARCH_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c new file mode 100644 index 0000000..0d6f269 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c @@ -0,0 +1,73 @@ +/* + * libvirt-gconfig-capabilities-guest-domain.c: libvirt guest domain capabilities + * + * 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_CAPABILITIES_GUEST_DOMAIN_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomainPrivate)) + +struct _GVirConfigCapabilitiesGuestDomainPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuestDomain, gvir_config_capabilities_guest_domain, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_guest_domain_class_init(GVirConfigCapabilitiesGuestDomainClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestDomainPrivate)); +} + +static void gvir_config_capabilities_guest_domain_init(GVirConfigCapabilitiesGuestDomain *domain) +{ + g_debug("Init GVirConfigCapabilitiesGuestDomain=%p", domain); + + domain->priv = GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN_GET_PRIVATE(domain); +} + +const gchar * +gvir_config_capabilities_guest_domain_get_emulator(GVirConfigCapabilitiesGuestDomain *domain) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN(domain), NULL); + + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(domain), "emulator"); +} + +GVirConfigDomainVirtType +gvir_config_capabilities_guest_domain_get_virt_type(GVirConfigCapabilitiesGuestDomain *domain) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN(domain), + GVIR_CONFIG_DOMAIN_VIRT_QEMU); + + return gvir_config_object_get_attribute_genum + (GVIR_CONFIG_OBJECT(domain), + NULL, + "type", + GVIR_CONFIG_TYPE_DOMAIN_VIRT_TYPE, + GVIR_CONFIG_DOMAIN_VIRT_QEMU); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h new file mode 100644 index 0000000..2215bce --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h @@ -0,0 +1,72 @@ +/* + * libvirt-gconfig-capabilities-guest-domain.h: libvirt guest domain capabilities + * + * 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_CAPABILITIES_GUEST_DOMAIN_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_DOMAIN_H__ + +#include "libvirt-gconfig-domain.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN (gvir_config_capabilities_guest_domain_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomain)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomainClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomainClass)) + +typedef struct _GVirConfigCapabilitiesGuestDomain GVirConfigCapabilitiesGuestDomain; +typedef struct _GVirConfigCapabilitiesGuestDomainPrivate GVirConfigCapabilitiesGuestDomainPrivate; +typedef struct _GVirConfigCapabilitiesGuestDomainClass GVirConfigCapabilitiesGuestDomainClass; + +struct _GVirConfigCapabilitiesGuestDomain +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestDomainPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestDomainClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_domain_get_type(void); + +const gchar * +gvir_config_capabilities_guest_domain_get_emulator(GVirConfigCapabilitiesGuestDomain *domain); + +GVirConfigDomainVirtType +gvir_config_capabilities_guest_domain_get_virt_type(GVirConfigCapabilitiesGuestDomain *domain); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_DOMAIN_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c new file mode 100644 index 0000000..52b4524 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c @@ -0,0 +1,61 @@ +/* + * libvirt-gconfig-capabilities-guest-feature.c: libvirt guest feature capabilities + * + * 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_CAPABILITIES_GUEST_FEATURE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeaturePrivate)) + +struct _GVirConfigCapabilitiesGuestFeaturePrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuestFeature, gvir_config_capabilities_guest_feature, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_guest_feature_class_init(GVirConfigCapabilitiesGuestFeatureClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestFeaturePrivate)); +} + +static void gvir_config_capabilities_guest_feature_init(GVirConfigCapabilitiesGuestFeature *feature) +{ + g_debug("Init GVirConfigCapabilitiesGuestFeature=%p", feature); + + feature->priv = GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE_GET_PRIVATE(feature); +} + +const gchar * +gvir_config_capabilities_guest_feature_get_name(GVirConfigCapabilitiesGuestFeature *feature) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(feature)); + g_return_val_if_fail(node != NULL, NULL); + + return (const gchar *)node->name; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h new file mode 100644 index 0000000..83b3fea --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h @@ -0,0 +1,67 @@ +/* + * libvirt-gconfig-capabilities-guest-feature.h: libvirt guest feature capabilities + * + * 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_CAPABILITIES_GUEST_FEATURE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_FEATURE_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE (gvir_config_capabilities_guest_feature_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeature)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeatureClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeatureClass)) + +typedef struct _GVirConfigCapabilitiesGuestFeature GVirConfigCapabilitiesGuestFeature; +typedef struct _GVirConfigCapabilitiesGuestFeaturePrivate GVirConfigCapabilitiesGuestFeaturePrivate; +typedef struct _GVirConfigCapabilitiesGuestFeatureClass GVirConfigCapabilitiesGuestFeatureClass; + +struct _GVirConfigCapabilitiesGuestFeature +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestFeaturePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestFeatureClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_feature_get_type(void); + +const gchar * +gvir_config_capabilities_guest_feature_get_name(GVirConfigCapabilitiesGuestFeature *feature); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_FEATURE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c new file mode 100644 index 0000000..04b610a --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c @@ -0,0 +1,139 @@ +/* + * libvirt-gconfig-capabilities-guest.c: libvirt guest capabilities + * + * 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_CAPABILITIES_GUEST_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestPrivate)) + +struct _GVirConfigCapabilitiesGuestPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuest, gvir_config_capabilities_guest, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_guest_class_init(GVirConfigCapabilitiesGuestClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestPrivate)); +} + +static void gvir_config_capabilities_guest_init(GVirConfigCapabilitiesGuest *guest) +{ + g_debug("Init GVirConfigCapabilitiesGuest=%p", guest); + + guest->priv = GVIR_CONFIG_CAPABILITIES_GUEST_GET_PRIVATE(guest); +} + +GVirConfigDomainOsType +gvir_config_capabilities_guest_get_os_type(GVirConfigCapabilitiesGuest *guest) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(guest), + GVIR_CONFIG_DOMAIN_OS_TYPE_LINUX); + + return gvir_config_object_get_node_content_genum(GVIR_CONFIG_OBJECT(guest), + "os_type", + GVIR_CONFIG_TYPE_DOMAIN_OS_TYPE, + GVIR_CONFIG_DOMAIN_OS_TYPE_LINUX); +} + +/** + * gvir_config_capabilities_guest_get_arch: + * + * Gets the CPU architecture capabilities of the guest. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesGuestArch. + */ +GVirConfigCapabilitiesGuestArch * +gvir_config_capabilities_guest_get_arch(GVirConfigCapabilitiesGuest *guest) +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(guest), NULL); + + object = gvir_config_object_get_child_with_type + (GVIR_CONFIG_OBJECT(guest), + "arch", + GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH); + + return GVIR_CONFIG_CAPABILITIES_GUEST_ARCH(object); +} + +struct GetFeatureData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *features; +}; + +static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree + (GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, + data->doc, + data->schema, + node); + if (object != NULL) + data->features = g_list_append(data->features, object); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_guest_get_features: + * + * Gets the CPU features for this guest. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesGuestFeature) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesGuestFeature. + */ +GList * +gvir_config_capabilities_guest_get_features(GVirConfigCapabilitiesGuest *guest) +{ + struct GetFeatureData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(guest), NULL); + + g_object_get(G_OBJECT(guest), "doc", &data.doc, NULL); + g_return_val_if_fail(data.doc != NULL, NULL); + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(guest)); + data.features = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(guest), + "features", + add_feature, + &data); + + g_clear_object(&data.doc); + + return data.features; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h new file mode 100644 index 0000000..fd074f2 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h @@ -0,0 +1,75 @@ +/* + * libvirt-gconfig-capabilities-guest.h: libvirt guest capabilities + * + * 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_CAPABILITIES_GUEST_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ + +#include "libvirt-gconfig-domain-os.h" +#include "libvirt-gconfig-capabilities-guest-arch.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST (gvir_config_capabilities_guest_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuest)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestClass)) + +typedef struct _GVirConfigCapabilitiesGuest GVirConfigCapabilitiesGuest; +typedef struct _GVirConfigCapabilitiesGuestPrivate GVirConfigCapabilitiesGuestPrivate; +typedef struct _GVirConfigCapabilitiesGuestClass GVirConfigCapabilitiesGuestClass; + +struct _GVirConfigCapabilitiesGuest +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_get_type(void); + +GVirConfigDomainOsType +gvir_config_capabilities_guest_get_os_type(GVirConfigCapabilitiesGuest *guest); + +GVirConfigCapabilitiesGuestArch * +gvir_config_capabilities_guest_get_arch(GVirConfigCapabilitiesGuest *guest); +GList * +gvir_config_capabilities_guest_get_features(GVirConfigCapabilitiesGuest *guest); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 43b91e0..d2664cc 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -94,3 +94,58 @@ gvir_config_capabilities_get_host(GVirConfigCapabilities *caps) return GVIR_CONFIG_CAPABILITIES_HOST(object); } + +struct GetGuestData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *guests; +}; + +static gboolean add_guest(xmlNodePtr node, gpointer opaque) +{ + struct GetGuestData* data = (struct GetGuestData*)opaque; + GVirConfigObject *object; + + if (g_strcmp0((const gchar *)node->name, "guest") != 0) + return TRUE; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, + data->doc, + data->schema, + node); + if (object != NULL) + data->guests = g_list_append(data->guests, object); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_get_guests: + * + * Gets the list of guest capabilities. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesGuest) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesGuest. + */ +GList * +gvir_config_capabilities_get_guests(GVirConfigCapabilities *caps) +{ + struct GetGuestData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(caps)); + data.guests = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(caps), + NULL, + add_guest, + &data); + + g_clear_object(&data.doc); + + return data.guests; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h index 2ec8369..2e373c9 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h @@ -65,6 +65,7 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, GError **error); GVirConfigCapabilitiesHost * gvir_config_capabilities_get_host(GVirConfigCapabilities *caps); +GList *gvir_config_capabilities_get_guests(GVirConfigCapabilities *caps); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index f9be83f..1201eb8 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -29,8 +29,12 @@ #include <libvirt-gconfig/libvirt-gconfig-main.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> -#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-host.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 7d015f5..21fff46 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -380,6 +380,7 @@ LIBVIRT_GCONFIG_0.0.9 { gvir_config_domain_os_get_boot_devices; gvir_config_capabilities_get_host; + gvir_config_capabilities_get_guests; gvir_config_capabilities_cpu_get_type; gvir_config_capabilities_cpu_get_arch; @@ -388,6 +389,23 @@ LIBVIRT_GCONFIG_0.0.9 { gvir_config_capabilities_cpu_feature_get_type; gvir_config_capabilities_cpu_feature_get_name; + gvir_config_capabilities_guest_get_type; + gvir_config_capabilities_guest_get_arch; + gvir_config_capabilities_guest_get_features; + gvir_config_capabilities_guest_get_os_type; + + gvir_config_capabilities_guest_arch_get_type; + gvir_config_capabilities_guest_arch_get_domains; + gvir_config_capabilities_guest_arch_get_emulator; + gvir_config_capabilities_guest_arch_get_name; + + gvir_config_capabilities_guest_domain_get_type; + gvir_config_capabilities_guest_domain_get_emulator; + gvir_config_capabilities_guest_domain_get_virt_type; + + gvir_config_capabilities_guest_feature_get_type; + gvir_config_capabilities_guest_feature_get_name; + gvir_config_capabilities_host_get_type; gvir_config_capabilities_host_get_uuid; gvir_config_capabilities_host_get_cpu; -- 1.7.7.6

On Fri, May 11, 2012 at 04:18:16PM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
Not quite complete but its a good start. --- libvirt-gconfig/Makefile.am | 8 + .../libvirt-gconfig-capabilities-guest-arch.c | 125 ++++++++++++++++++ .../libvirt-gconfig-capabilities-guest-arch.h | 71 ++++++++++ .../libvirt-gconfig-capabilities-guest-domain.c | 73 ++++++++++ .../libvirt-gconfig-capabilities-guest-domain.h | 72 ++++++++++ .../libvirt-gconfig-capabilities-guest-feature.c | 61 +++++++++ .../libvirt-gconfig-capabilities-guest-feature.h | 67 ++++++++++ .../libvirt-gconfig-capabilities-guest.c | 139 ++++++++++++++++++++ .../libvirt-gconfig-capabilities-guest.h | 75 +++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.c | 55 ++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.h | 1 + libvirt-gconfig/libvirt-gconfig.h | 6 +- libvirt-gconfig/libvirt-gconfig.sym | 18 +++ 13 files changed, 770 insertions(+), 1 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest.h
diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 54899a3..4bc3ee1 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -15,6 +15,10 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-capabilities-host.h \ libvirt-gconfig-capabilities-cpu.h \ libvirt-gconfig-capabilities-cpu-feature.h \ + libvirt-gconfig-capabilities-guest.h \ + libvirt-gconfig-capabilities-guest-arch.h \ + libvirt-gconfig-capabilities-guest-domain.h \ + libvirt-gconfig-capabilities-guest-feature.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-address.h \ libvirt-gconfig-domain-address-pci.h \ @@ -78,6 +82,10 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-capabilities-host.c \ libvirt-gconfig-capabilities-cpu.c \ libvirt-gconfig-capabilities-cpu-feature.c \ + libvirt-gconfig-capabilities-guest.c \ + libvirt-gconfig-capabilities-guest-arch.c \ + libvirt-gconfig-capabilities-guest-domain.c \ + libvirt-gconfig-capabilities-guest-feature.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-address.c \ libvirt-gconfig-domain-address-pci.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c new file mode 100644 index 0000000..fe45525 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c @@ -0,0 +1,125 @@ +/* + * libvirt-gconfig-capabilities-cpu-arch.c: libvirt guest architecture capabilities + * + * 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_CAPABILITIES_GUEST_ARCH_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArchPrivate)) + +struct _GVirConfigCapabilitiesGuestArchPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuestArch, gvir_config_capabilities_guest_arch, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_guest_arch_class_init(GVirConfigCapabilitiesGuestArchClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestArchPrivate)); +} + +static void gvir_config_capabilities_guest_arch_init(GVirConfigCapabilitiesGuestArch *arch) +{ + g_debug("Init GVirConfigCapabilitiesGuestArch=%p", arch); + + arch->priv = GVIR_CONFIG_CAPABILITIES_GUEST_ARCH_GET_PRIVATE(arch); +} + +const gchar * +gvir_config_capabilities_guest_arch_get_name(GVirConfigCapabilitiesGuestArch *arch) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(arch), NULL); + + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(arch), + NULL, + "name"); +} + +struct GetDomainData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *domains; +}; + +static gboolean add_domain(xmlNodePtr node, gpointer opaque) +{ + struct GetDomainData* data = (struct GetDomainData*)opaque; + GVirConfigObject *object; + + if (g_strcmp0((const gchar *)node->name, "domain") != 0) + return TRUE; + + object = gvir_config_object_new_from_tree + (GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, + data->doc, + data->schema, + node); + if (object != NULL) + data->domains = g_list_append(data->domains, object); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_guest_arch_get_domains: + * + * Gets the possible domains for this architecture. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesGuestDomain) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesGuestDomain. + */ +GList * +gvir_config_capabilities_guest_arch_get_domains(GVirConfigCapabilitiesGuestArch *arch) +{ + struct GetDomainData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(arch), NULL); + + g_object_get(G_OBJECT(arch), "doc", &data.doc, NULL); + g_return_val_if_fail(data.doc != NULL, NULL); + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(arch)); + data.domains = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(arch), + NULL, + add_domain, + &data); + g_clear_object(&data.doc); + + return data.domains; +} + +const gchar * +gvir_config_capabilities_guest_arch_get_emulator(GVirConfigCapabilitiesGuestArch *arch) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(arch), NULL); + + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(arch), + "emulator"); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h new file mode 100644 index 0000000..08612f2 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h @@ -0,0 +1,71 @@ +/* + * libvirt-gconfig-capabilities-guest-arch.h: libvirt guest architecture capabilities + * + * 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_CAPABILITIES_GUEST_ARCH_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_ARCH_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH (gvir_config_capabilities_guest_arch_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST_ARCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArch)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArchClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_ARCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArchClass)) + +typedef struct _GVirConfigCapabilitiesGuestArch GVirConfigCapabilitiesGuestArch; +typedef struct _GVirConfigCapabilitiesGuestArchPrivate GVirConfigCapabilitiesGuestArchPrivate; +typedef struct _GVirConfigCapabilitiesGuestArchClass GVirConfigCapabilitiesGuestArchClass; + +struct _GVirConfigCapabilitiesGuestArch +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestArchPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestArchClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_arch_get_type(void); + +const gchar * +gvir_config_capabilities_guest_arch_get_name(GVirConfigCapabilitiesGuestArch *arch); +GList * +gvir_config_capabilities_guest_arch_get_domains(GVirConfigCapabilitiesGuestArch *arch); +const gchar * +gvir_config_capabilities_guest_arch_get_emulator(GVirConfigCapabilitiesGuestArch *arch); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_ARCH_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c new file mode 100644 index 0000000..0d6f269 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c @@ -0,0 +1,73 @@ +/* + * libvirt-gconfig-capabilities-guest-domain.c: libvirt guest domain capabilities + * + * 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_CAPABILITIES_GUEST_DOMAIN_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomainPrivate)) + +struct _GVirConfigCapabilitiesGuestDomainPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuestDomain, gvir_config_capabilities_guest_domain, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_guest_domain_class_init(GVirConfigCapabilitiesGuestDomainClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestDomainPrivate)); +} + +static void gvir_config_capabilities_guest_domain_init(GVirConfigCapabilitiesGuestDomain *domain) +{ + g_debug("Init GVirConfigCapabilitiesGuestDomain=%p", domain); + + domain->priv = GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN_GET_PRIVATE(domain); +} + +const gchar * +gvir_config_capabilities_guest_domain_get_emulator(GVirConfigCapabilitiesGuestDomain *domain) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN(domain), NULL); + + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(domain), "emulator"); +} + +GVirConfigDomainVirtType +gvir_config_capabilities_guest_domain_get_virt_type(GVirConfigCapabilitiesGuestDomain *domain) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN(domain), + GVIR_CONFIG_DOMAIN_VIRT_QEMU); + + return gvir_config_object_get_attribute_genum + (GVIR_CONFIG_OBJECT(domain), + NULL, + "type", + GVIR_CONFIG_TYPE_DOMAIN_VIRT_TYPE, + GVIR_CONFIG_DOMAIN_VIRT_QEMU); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h new file mode 100644 index 0000000..2215bce --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h @@ -0,0 +1,72 @@ +/* + * libvirt-gconfig-capabilities-guest-domain.h: libvirt guest domain capabilities + * + * 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_CAPABILITIES_GUEST_DOMAIN_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_DOMAIN_H__ + +#include "libvirt-gconfig-domain.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN (gvir_config_capabilities_guest_domain_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomain)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomainClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomainClass)) + +typedef struct _GVirConfigCapabilitiesGuestDomain GVirConfigCapabilitiesGuestDomain; +typedef struct _GVirConfigCapabilitiesGuestDomainPrivate GVirConfigCapabilitiesGuestDomainPrivate; +typedef struct _GVirConfigCapabilitiesGuestDomainClass GVirConfigCapabilitiesGuestDomainClass; + +struct _GVirConfigCapabilitiesGuestDomain +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestDomainPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestDomainClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_domain_get_type(void); + +const gchar * +gvir_config_capabilities_guest_domain_get_emulator(GVirConfigCapabilitiesGuestDomain *domain); + +GVirConfigDomainVirtType +gvir_config_capabilities_guest_domain_get_virt_type(GVirConfigCapabilitiesGuestDomain *domain); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_DOMAIN_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c new file mode 100644 index 0000000..52b4524 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c @@ -0,0 +1,61 @@ +/* + * libvirt-gconfig-capabilities-guest-feature.c: libvirt guest feature capabilities + * + * 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_CAPABILITIES_GUEST_FEATURE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeaturePrivate)) + +struct _GVirConfigCapabilitiesGuestFeaturePrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuestFeature, gvir_config_capabilities_guest_feature, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_guest_feature_class_init(GVirConfigCapabilitiesGuestFeatureClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestFeaturePrivate)); +} + +static void gvir_config_capabilities_guest_feature_init(GVirConfigCapabilitiesGuestFeature *feature) +{ + g_debug("Init GVirConfigCapabilitiesGuestFeature=%p", feature); + + feature->priv = GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE_GET_PRIVATE(feature); +} + +const gchar * +gvir_config_capabilities_guest_feature_get_name(GVirConfigCapabilitiesGuestFeature *feature) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(feature)); + g_return_val_if_fail(node != NULL, NULL); + + return (const gchar *)node->name; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h new file mode 100644 index 0000000..83b3fea --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h @@ -0,0 +1,67 @@ +/* + * libvirt-gconfig-capabilities-guest-feature.h: libvirt guest feature capabilities + * + * 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_CAPABILITIES_GUEST_FEATURE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_FEATURE_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE (gvir_config_capabilities_guest_feature_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeature)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeatureClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeatureClass)) + +typedef struct _GVirConfigCapabilitiesGuestFeature GVirConfigCapabilitiesGuestFeature; +typedef struct _GVirConfigCapabilitiesGuestFeaturePrivate GVirConfigCapabilitiesGuestFeaturePrivate; +typedef struct _GVirConfigCapabilitiesGuestFeatureClass GVirConfigCapabilitiesGuestFeatureClass; + +struct _GVirConfigCapabilitiesGuestFeature +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestFeaturePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestFeatureClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_feature_get_type(void); + +const gchar * +gvir_config_capabilities_guest_feature_get_name(GVirConfigCapabilitiesGuestFeature *feature); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_FEATURE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c new file mode 100644 index 0000000..04b610a --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c @@ -0,0 +1,139 @@ +/* + * libvirt-gconfig-capabilities-guest.c: libvirt guest capabilities + * + * 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_CAPABILITIES_GUEST_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestPrivate)) + +struct _GVirConfigCapabilitiesGuestPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuest, gvir_config_capabilities_guest, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_guest_class_init(GVirConfigCapabilitiesGuestClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestPrivate)); +} + +static void gvir_config_capabilities_guest_init(GVirConfigCapabilitiesGuest *guest) +{ + g_debug("Init GVirConfigCapabilitiesGuest=%p", guest); + + guest->priv = GVIR_CONFIG_CAPABILITIES_GUEST_GET_PRIVATE(guest); +} + +GVirConfigDomainOsType
This is missing an additional patch adding the missing entries to GVirConfigDomainOsType, ACK otherwise. Christophe
+gvir_config_capabilities_guest_get_os_type(GVirConfigCapabilitiesGuest *guest) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(guest), + GVIR_CONFIG_DOMAIN_OS_TYPE_LINUX); + + return gvir_config_object_get_node_content_genum(GVIR_CONFIG_OBJECT(guest), + "os_type", + GVIR_CONFIG_TYPE_DOMAIN_OS_TYPE, + GVIR_CONFIG_DOMAIN_OS_TYPE_LINUX); +} + +/** + * gvir_config_capabilities_guest_get_arch: + * + * Gets the CPU architecture capabilities of the guest. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesGuestArch. + */ +GVirConfigCapabilitiesGuestArch * +gvir_config_capabilities_guest_get_arch(GVirConfigCapabilitiesGuest *guest) +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(guest), NULL); + + object = gvir_config_object_get_child_with_type + (GVIR_CONFIG_OBJECT(guest), + "arch", + GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH); + + return GVIR_CONFIG_CAPABILITIES_GUEST_ARCH(object); +} + +struct GetFeatureData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *features; +}; + +static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree + (GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, + data->doc, + data->schema, + node); + if (object != NULL) + data->features = g_list_append(data->features, object); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_guest_get_features: + * + * Gets the CPU features for this guest. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesGuestFeature) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesGuestFeature. + */ +GList * +gvir_config_capabilities_guest_get_features(GVirConfigCapabilitiesGuest *guest) +{ + struct GetFeatureData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(guest), NULL); + + g_object_get(G_OBJECT(guest), "doc", &data.doc, NULL); + g_return_val_if_fail(data.doc != NULL, NULL); + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(guest)); + data.features = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(guest), + "features", + add_feature, + &data); + + g_clear_object(&data.doc); + + return data.features; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h new file mode 100644 index 0000000..fd074f2 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h @@ -0,0 +1,75 @@ +/* + * libvirt-gconfig-capabilities-guest.h: libvirt guest capabilities + * + * 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_CAPABILITIES_GUEST_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ + +#include "libvirt-gconfig-domain-os.h" +#include "libvirt-gconfig-capabilities-guest-arch.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST (gvir_config_capabilities_guest_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuest)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestClass)) + +typedef struct _GVirConfigCapabilitiesGuest GVirConfigCapabilitiesGuest; +typedef struct _GVirConfigCapabilitiesGuestPrivate GVirConfigCapabilitiesGuestPrivate; +typedef struct _GVirConfigCapabilitiesGuestClass GVirConfigCapabilitiesGuestClass; + +struct _GVirConfigCapabilitiesGuest +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_get_type(void); + +GVirConfigDomainOsType +gvir_config_capabilities_guest_get_os_type(GVirConfigCapabilitiesGuest *guest); + +GVirConfigCapabilitiesGuestArch * +gvir_config_capabilities_guest_get_arch(GVirConfigCapabilitiesGuest *guest); +GList * +gvir_config_capabilities_guest_get_features(GVirConfigCapabilitiesGuest *guest); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 43b91e0..d2664cc 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -94,3 +94,58 @@ gvir_config_capabilities_get_host(GVirConfigCapabilities *caps)
return GVIR_CONFIG_CAPABILITIES_HOST(object); } + +struct GetGuestData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *guests; +}; + +static gboolean add_guest(xmlNodePtr node, gpointer opaque) +{ + struct GetGuestData* data = (struct GetGuestData*)opaque; + GVirConfigObject *object; + + if (g_strcmp0((const gchar *)node->name, "guest") != 0) + return TRUE; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, + data->doc, + data->schema, + node); + if (object != NULL) + data->guests = g_list_append(data->guests, object); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_get_guests: + * + * Gets the list of guest capabilities. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesGuest) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesGuest. + */ +GList * +gvir_config_capabilities_get_guests(GVirConfigCapabilities *caps) +{ + struct GetGuestData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(caps)); + data.guests = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(caps), + NULL, + add_guest, + &data); + + g_clear_object(&data.doc); + + return data.guests; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h index 2ec8369..2e373c9 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h @@ -65,6 +65,7 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, GError **error); GVirConfigCapabilitiesHost * gvir_config_capabilities_get_host(GVirConfigCapabilities *caps); +GList *gvir_config_capabilities_get_guests(GVirConfigCapabilities *caps);
G_END_DECLS
diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index f9be83f..1201eb8 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -29,8 +29,12 @@ #include <libvirt-gconfig/libvirt-gconfig-main.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> -#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-host.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 7d015f5..21fff46 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -380,6 +380,7 @@ LIBVIRT_GCONFIG_0.0.9 { gvir_config_domain_os_get_boot_devices;
gvir_config_capabilities_get_host; + gvir_config_capabilities_get_guests;
gvir_config_capabilities_cpu_get_type; gvir_config_capabilities_cpu_get_arch; @@ -388,6 +389,23 @@ LIBVIRT_GCONFIG_0.0.9 { gvir_config_capabilities_cpu_feature_get_type; gvir_config_capabilities_cpu_feature_get_name;
+ gvir_config_capabilities_guest_get_type; + gvir_config_capabilities_guest_get_arch; + gvir_config_capabilities_guest_get_features; + gvir_config_capabilities_guest_get_os_type; + + gvir_config_capabilities_guest_arch_get_type; + gvir_config_capabilities_guest_arch_get_domains; + gvir_config_capabilities_guest_arch_get_emulator; + gvir_config_capabilities_guest_arch_get_name; + + gvir_config_capabilities_guest_domain_get_type; + gvir_config_capabilities_guest_domain_get_emulator; + gvir_config_capabilities_guest_domain_get_virt_type; + + gvir_config_capabilities_guest_feature_get_type; + gvir_config_capabilities_guest_feature_get_name; + gvir_config_capabilities_host_get_type; gvir_config_capabilities_host_get_uuid; gvir_config_capabilities_host_get_cpu; -- 1.7.7.6
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

ACK On Fri, May 11, 2012 at 04:18:15PM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
Not quite complete but its a good start. --- libvirt-gconfig/Makefile.am | 6 + .../libvirt-gconfig-capabilities-cpu-feature.c | 58 ++++++++++ .../libvirt-gconfig-capabilities-cpu-feature.h | 67 ++++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c | 114 ++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h | 69 ++++++++++++ .../libvirt-gconfig-capabilities-host.c | 80 ++++++++++++++ .../libvirt-gconfig-capabilities-host.h | 72 ++++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.c | 23 ++++ libvirt-gconfig/libvirt-gconfig-capabilities.h | 5 +- libvirt-gconfig/libvirt-gconfig.h | 3 + libvirt-gconfig/libvirt-gconfig.sym | 13 +++ 11 files changed, 509 insertions(+), 1 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-host.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-host.h
diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index fd32c3d..54899a3 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -12,6 +12,9 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-main.h \ libvirt-gconfig-object.h \ libvirt-gconfig-capabilities.h \ + libvirt-gconfig-capabilities-host.h \ + libvirt-gconfig-capabilities-cpu.h \ + libvirt-gconfig-capabilities-cpu-feature.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-address.h \ libvirt-gconfig-domain-address-pci.h \ @@ -72,6 +75,9 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-object.c \ libvirt-gconfig-main.c \ libvirt-gconfig-capabilities.c \ + libvirt-gconfig-capabilities-host.c \ + libvirt-gconfig-capabilities-cpu.c \ + libvirt-gconfig-capabilities-cpu-feature.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-address.c \ libvirt-gconfig-domain-address-pci.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c new file mode 100644 index 0000000..0c71885 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.c @@ -0,0 +1,58 @@ +/* + * libvirt-gconfig-capabilities-cpu-feature.c: libvirt CPU feature capabilities + * + * 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_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeaturePrivate)) + +struct _GVirConfigCapabilitiesCpuFeaturePrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCpuFeature, gvir_config_capabilities_cpu_feature, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_cpu_feature_class_init(GVirConfigCapabilitiesCpuFeatureClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCpuFeaturePrivate)); +} + +static void gvir_config_capabilities_cpu_feature_init(GVirConfigCapabilitiesCpuFeature *feature) +{ + g_debug("Init GVirConfigCapabilitiesCpuFeature=%p", feature); + + feature->priv = GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_PRIVATE(feature); +} + +const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCpuFeature *feature) +{ + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(feature), + NULL, + "name"); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h new file mode 100644 index 0000000..8bb2f2b --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h @@ -0,0 +1,67 @@ +/* + * libvirt-gconfig-capabilities-cpu-feature.h: libvirt CPU feature capabilities + * + * 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_CAPABILITIES_CPU_FEATURE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE (gvir_config_capabilities_cpu_feature_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeature)) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeatureClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE)) +#define GVIR_CONFIG_CAPABILITIES_CPU_FEATURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, GVirConfigCapabilitiesCpuFeatureClass)) + +typedef struct _GVirConfigCapabilitiesCpuFeature GVirConfigCapabilitiesCpuFeature; +typedef struct _GVirConfigCapabilitiesCpuFeaturePrivate GVirConfigCapabilitiesCpuFeaturePrivate; +typedef struct _GVirConfigCapabilitiesCpuFeatureClass GVirConfigCapabilitiesCpuFeatureClass; + +struct _GVirConfigCapabilitiesCpuFeature +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCpuFeaturePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCpuFeatureClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_feature_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_feature_get_name(GVirConfigCapabilitiesCpuFeature *feature); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_FEATURE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c new file mode 100644 index 0000000..e9a3f10 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.c @@ -0,0 +1,114 @@ +/* + * libvirt-gconfig-capabilities-cpu.c: libvirt CPU capabilities + * + * 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_CAPABILITIES_CPU_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuPrivate)) + +struct _GVirConfigCapabilitiesCpuPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesCpu, gvir_config_capabilities_cpu, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_cpu_class_init(GVirConfigCapabilitiesCpuClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesCpuPrivate)); +} + +static void gvir_config_capabilities_cpu_init(GVirConfigCapabilitiesCpu *cpu) +{ + g_debug("Init GVirConfigCapabilitiesCpu=%p", cpu); + + cpu->priv = GVIR_CONFIG_CAPABILITIES_CPU_GET_PRIVATE(cpu); +} + +const gchar * +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCpu *cpu) +{ + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(cpu), "arch"); +} + +struct GetFeatureData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *features; +}; + +static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigObject *feature; + + if (g_strcmp0((const gchar *)node->name, "feature") != 0) + return TRUE; + + feature = gvir_config_object_new_from_tree + (GVIR_CONFIG_TYPE_CAPABILITIES_CPU_FEATURE, + data->doc, + data->schema, + node); + if (feature != NULL) + data->features = g_list_append(data->features, feature); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_cpu_get_features: + * + * Gets the features of this CPU. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesCpuFeature) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesCpuFeature. + */ +GList * +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *cpu) +{ + struct GetFeatureData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_CPU(cpu), NULL); + + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(cpu)); + g_object_get(G_OBJECT(cpu), "doc", &data.doc, NULL); + g_return_val_if_fail(data.doc != NULL, NULL); + data.features = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(cpu), + NULL, + add_feature, + &data); + g_clear_object(&data.doc); + + return data.features; +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h new file mode 100644 index 0000000..8b221ae --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h @@ -0,0 +1,69 @@ +/* + * libvirt-gconfig-capabilities-cpu.h: libvirt CPU capabilities + * + * 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_CAPABILITIES_CPU_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_CPU (gvir_config_capabilities_cpu_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_CPU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpu)) +#define GVIR_CONFIG_CAPABILITIES_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU)) +#define GVIR_CONFIG_IS_CAPABILITIES_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_CPU)) +#define GVIR_CONFIG_CAPABILITIES_CPU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_CPU, GVirConfigCapabilitiesCpuClass)) + +typedef struct _GVirConfigCapabilitiesCpu GVirConfigCapabilitiesCpu; +typedef struct _GVirConfigCapabilitiesCpuPrivate GVirConfigCapabilitiesCpuPrivate; +typedef struct _GVirConfigCapabilitiesCpuClass GVirConfigCapabilitiesCpuClass; + +struct _GVirConfigCapabilitiesCpu +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesCpuPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesCpuClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_cpu_get_type(void); + +const gchar * +gvir_config_capabilities_cpu_get_arch(GVirConfigCapabilitiesCpu *cpu); +GList * +gvir_config_capabilities_cpu_get_features(GVirConfigCapabilitiesCpu *cpu); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_CPU_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.c b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c new file mode 100644 index 0000000..47ad0fc --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.c @@ -0,0 +1,80 @@ +/* + * libvirt-gconfig-capabilities-host.c: libvirt host capabilities + * + * 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_CAPABILITIES_HOST_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostPrivate)) + +struct _GVirConfigCapabilitiesHostPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesHost, gvir_config_capabilities_host, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_host_class_init(GVirConfigCapabilitiesHostClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesHostPrivate)); +} + +static void gvir_config_capabilities_host_init(GVirConfigCapabilitiesHost *host) +{ + g_debug("Init GVirConfigCapabilitiesHost=%p", host); + + host->priv = GVIR_CONFIG_CAPABILITIES_HOST_GET_PRIVATE(host); +} + +const gchar * +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *host) +{ + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(host), "uuid"); +} + +/** + * gvir_config_capabilities_host_get_cpu: + * + * Gets the CPU capabilities of the host. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesCpu. + */ +GVirConfigCapabilitiesCpu * +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *host) +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_HOST(host), NULL); + + object = gvir_config_object_get_child_with_type + (GVIR_CONFIG_OBJECT(host), + "cpu", + GVIR_CONFIG_TYPE_CAPABILITIES_CPU); + + return GVIR_CONFIG_CAPABILITIES_CPU(object); +} + diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-host.h b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h new file mode 100644 index 0000000..d5e325b --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-host.h @@ -0,0 +1,72 @@ +/* + * libvirt-gconfig-capabilities-host.h: libvirt host capabilities + * + * 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_CAPABILITIES_HOST_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_HOST_H__ + +#include "libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_HOST (gvir_config_capabilities_host_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_HOST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHost)) +#define GVIR_CONFIG_CAPABILITIES_HOST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_HOST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST)) +#define GVIR_CONFIG_IS_CAPABILITIES_HOST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_HOST)) +#define GVIR_CONFIG_CAPABILITIES_HOST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_HOST, GVirConfigCapabilitiesHostClass)) + +typedef struct _GVirConfigCapabilitiesHost GVirConfigCapabilitiesHost; +typedef struct _GVirConfigCapabilitiesHostPrivate GVirConfigCapabilitiesHostPrivate; +typedef struct _GVirConfigCapabilitiesHostClass GVirConfigCapabilitiesHostClass; + +struct _GVirConfigCapabilitiesHost +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesHostPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesHostClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_host_get_type(void); + +const gchar * +gvir_config_capabilities_host_get_uuid(GVirConfigCapabilitiesHost *host); + +GVirConfigCapabilitiesCpu * +gvir_config_capabilities_host_get_cpu(GVirConfigCapabilitiesHost *host); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_HOST_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 6fb9af7..43b91e0 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -24,6 +24,7 @@ #include <config.h>
#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-private.h"
#define GVIR_CONFIG_CAPABILITIES_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES, GVirConfigCapabilitiesPrivate)) @@ -71,3 +72,25 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, xml, error); return GVIR_CONFIG_CAPABILITIES(object); } + +/** + * gvir_config_capabilities_get_host: + * + * Gets the host capabilities. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesHost. + */ +GVirConfigCapabilitiesHost * +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps) +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL); + + object = gvir_config_object_get_child_with_type + (GVIR_CONFIG_OBJECT(caps), + "host", + GVIR_CONFIG_TYPE_CAPABILITIES_HOST); + + return GVIR_CONFIG_CAPABILITIES_HOST(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h index 733886d..2ec8369 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h @@ -27,6 +27,8 @@ #ifndef __LIBVIRT_GCONFIG_CAPABILITIES_H__ #define __LIBVIRT_GCONFIG_CAPABILITIES_H__
+#include "libvirt-gconfig/libvirt-gconfig-capabilities-host.h" + G_BEGIN_DECLS
#define GVIR_CONFIG_TYPE_CAPABILITIES (gvir_config_capabilities_get_type ()) @@ -56,12 +58,13 @@ struct _GVirConfigCapabilitiesClass gpointer padding[20]; };
- GType gvir_config_capabilities_get_type(void);
GVirConfigCapabilities *gvir_config_capabilities_new(void); GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, GError **error); +GVirConfigCapabilitiesHost * +gvir_config_capabilities_get_host(GVirConfigCapabilities *caps);
G_END_DECLS
diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index bd16244..f9be83f 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -29,6 +29,9 @@ #include <libvirt-gconfig/libvirt-gconfig-main.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-host.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address-pci.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 7bc9e2d..7d015f5 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -378,6 +378,19 @@ LIBVIRT_GCONFIG_0.0.9 { global: gvir_config_domain_get_os; gvir_config_domain_os_get_boot_devices; + + gvir_config_capabilities_get_host; + + gvir_config_capabilities_cpu_get_type; + gvir_config_capabilities_cpu_get_arch; + gvir_config_capabilities_cpu_get_features; + + gvir_config_capabilities_cpu_feature_get_type; + gvir_config_capabilities_cpu_feature_get_name; + + gvir_config_capabilities_host_get_type; + gvir_config_capabilities_host_get_uuid; + gvir_config_capabilities_host_get_cpu; } LIBVIRT_GCONFIG_0.0.8;
# .... define new API here using predicted next version number .... -- 1.7.7.6
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> Not quite complete but its a good start. --- libvirt-gconfig/Makefile.am | 8 + .../libvirt-gconfig-capabilities-guest-arch.c | 122 +++++++++++++++++ .../libvirt-gconfig-capabilities-guest-arch.h | 71 ++++++++++ .../libvirt-gconfig-capabilities-guest-domain.c | 68 ++++++++++ .../libvirt-gconfig-capabilities-guest-domain.h | 72 ++++++++++ .../libvirt-gconfig-capabilities-guest-feature.c | 61 +++++++++ .../libvirt-gconfig-capabilities-guest-feature.h | 67 ++++++++++ .../libvirt-gconfig-capabilities-guest.c | 139 ++++++++++++++++++++ .../libvirt-gconfig-capabilities-guest.h | 75 +++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.c | 57 ++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.h | 1 + libvirt-gconfig/libvirt-gconfig.h | 6 +- libvirt-gconfig/libvirt-gconfig.sym | 19 +++ 13 files changed, 765 insertions(+), 1 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 54899a3..4bc3ee1 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -15,6 +15,10 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-capabilities-host.h \ libvirt-gconfig-capabilities-cpu.h \ libvirt-gconfig-capabilities-cpu-feature.h \ + libvirt-gconfig-capabilities-guest.h \ + libvirt-gconfig-capabilities-guest-arch.h \ + libvirt-gconfig-capabilities-guest-domain.h \ + libvirt-gconfig-capabilities-guest-feature.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-address.h \ libvirt-gconfig-domain-address-pci.h \ @@ -78,6 +82,10 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-capabilities-host.c \ libvirt-gconfig-capabilities-cpu.c \ libvirt-gconfig-capabilities-cpu-feature.c \ + libvirt-gconfig-capabilities-guest.c \ + libvirt-gconfig-capabilities-guest-arch.c \ + libvirt-gconfig-capabilities-guest-domain.c \ + libvirt-gconfig-capabilities-guest-feature.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-address.c \ libvirt-gconfig-domain-address-pci.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c new file mode 100644 index 0000000..fde835b --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c @@ -0,0 +1,122 @@ +/* + * libvirt-gconfig-capabilities-cpu-arch.c: libvirt guest architecture capabilities + * + * 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_CAPABILITIES_GUEST_ARCH_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArchPrivate)) + +struct _GVirConfigCapabilitiesGuestArchPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuestArch, gvir_config_capabilities_guest_arch, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_guest_arch_class_init(GVirConfigCapabilitiesGuestArchClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestArchPrivate)); +} + +static void gvir_config_capabilities_guest_arch_init(GVirConfigCapabilitiesGuestArch *conn) +{ + g_debug("Init GVirConfigCapabilitiesGuestArch=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_GUEST_ARCH_GET_PRIVATE(conn); +} + +const gchar * +gvir_config_capabilities_guest_arch_get_name(GVirConfigCapabilitiesGuestArch *caps) +{ + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(caps), + NULL, + "name"); +} + +struct GetDomainData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *domains; +}; + +static gboolean add_domain(xmlNodePtr node, gpointer opaque) +{ + struct GetDomainData* data = (struct GetDomainData*)opaque; + GVirConfigObject *object; + + if (g_strcmp0((const gchar *)node->name, "domain") != 0) + return TRUE; + + object = gvir_config_object_new_from_tree + (GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, + data->doc, + data->schema, + node); + if (object != NULL) + data->domains = g_list_append(data->domains, object); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_guest_arch_get_domains: + * + * Gets the possible domains for this architecture. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesGuestDomain) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesGuestDomain. + */ +GList * +gvir_config_capabilities_guest_arch_get_domains(GVirConfigCapabilitiesGuestArch *caps) +{ + struct GetDomainData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(caps), NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + g_return_val_if_fail(data.doc != NULL, NULL); + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(data.schema != NULL, NULL); + data.domains = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(caps), + NULL, + add_domain, + &data); + g_clear_object(&data.doc); + + return data.domains; +} + +const gchar * +gvir_config_capabilities_guest_arch_get_emulator(GVirConfigCapabilitiesGuestArch *caps) +{ + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(caps), + "emulator"); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h new file mode 100644 index 0000000..05bb0e7 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h @@ -0,0 +1,71 @@ +/* + * libvirt-gconfig-capabilities-cpu-arch.h: libvirt guest architecture capabilities + * + * 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_CAPABILITIES_GUEST_ARCH_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_ARCH_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH (gvir_config_capabilities_guest_arch_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST_ARCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArch)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArchClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_ARCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArchClass)) + +typedef struct _GVirConfigCapabilitiesGuestArch GVirConfigCapabilitiesGuestArch; +typedef struct _GVirConfigCapabilitiesGuestArchPrivate GVirConfigCapabilitiesGuestArchPrivate; +typedef struct _GVirConfigCapabilitiesGuestArchClass GVirConfigCapabilitiesGuestArchClass; + +struct _GVirConfigCapabilitiesGuestArch +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestArchPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestArchClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_arch_get_type(void); + +const gchar * +gvir_config_capabilities_guest_arch_get_name(GVirConfigCapabilitiesGuestArch *caps); +GList * +gvir_config_capabilities_guest_arch_get_domains(GVirConfigCapabilitiesGuestArch *caps); +const gchar * +gvir_config_capabilities_guest_arch_get_emulator(GVirConfigCapabilitiesGuestArch *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_ARCH_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c new file mode 100644 index 0000000..eeebfab --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c @@ -0,0 +1,68 @@ +/* + * libvirt-gconfig-capabilities-domain.c: libvirt guest domain capabilities + * + * 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_CAPABILITIES_GUEST_DOMAIN_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomainPrivate)) + +struct _GVirConfigCapabilitiesGuestDomainPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuestDomain, gvir_config_capabilities_guest_domain, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_guest_domain_class_init(GVirConfigCapabilitiesGuestDomainClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestDomainPrivate)); +} + +static void gvir_config_capabilities_guest_domain_init(GVirConfigCapabilitiesGuestDomain *conn) +{ + g_debug("Init GVirConfigCapabilitiesGuestDomain=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN_GET_PRIVATE(conn); +} + +const gchar * +gvir_config_capabilities_guest_domain_get_emulator(GVirConfigCapabilitiesGuestDomain *caps) +{ + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(caps), "emulator"); +} + +GVirConfigDomainVirtType +gvir_config_capabilities_guest_domain_get_virt_type(GVirConfigCapabilitiesGuestDomain *caps) +{ + return gvir_config_object_get_attribute_genum + (GVIR_CONFIG_OBJECT(caps), + NULL, + "type", + GVIR_CONFIG_TYPE_DOMAIN_VIRT_TYPE, + GVIR_CONFIG_DOMAIN_VIRT_QEMU); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h new file mode 100644 index 0000000..c80bde6 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h @@ -0,0 +1,72 @@ +/* + * libvirt-gconfig-capabilities-domain.h: libvirt guest domain capabilities + * + * 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_CAPABILITIES_GUEST_DOMAIN_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_DOMAIN_H__ + +#include "libvirt-gconfig-domain.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN (gvir_config_capabilities_guest_domain_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomain)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomainClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomainClass)) + +typedef struct _GVirConfigCapabilitiesGuestDomain GVirConfigCapabilitiesGuestDomain; +typedef struct _GVirConfigCapabilitiesGuestDomainPrivate GVirConfigCapabilitiesGuestDomainPrivate; +typedef struct _GVirConfigCapabilitiesGuestDomainClass GVirConfigCapabilitiesGuestDomainClass; + +struct _GVirConfigCapabilitiesGuestDomain +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestDomainPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestDomainClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_domain_get_type(void); + +const gchar * +gvir_config_capabilities_guest_domain_get_emulator(GVirConfigCapabilitiesGuestDomain *caps); + +GVirConfigDomainVirtType +gvir_config_capabilities_guest_domain_get_virt_type(GVirConfigCapabilitiesGuestDomain *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_DOMAIN_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c new file mode 100644 index 0000000..1554f5a --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c @@ -0,0 +1,61 @@ +/* + * libvirt-gconfig-capabilities-guest-feature.c: libvirt guest feature capabilities + * + * 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_CAPABILITIES_GUEST_FEATURE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeaturePrivate)) + +struct _GVirConfigCapabilitiesGuestFeaturePrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuestFeature, gvir_config_capabilities_guest_feature, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_guest_feature_class_init(GVirConfigCapabilitiesGuestFeatureClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestFeaturePrivate)); +} + +static void gvir_config_capabilities_guest_feature_init(GVirConfigCapabilitiesGuestFeature *feature) +{ + g_debug("Init GVirConfigCapabilitiesGuestFeature=%p", feature); + + feature->priv = GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE_GET_PRIVATE(feature); +} + +const gchar * +gvir_config_capabilities_guest_feature_get_name(GVirConfigCapabilitiesGuestFeature *caps) +{ + xmlNodePtr node; + + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + return (const gchar *)node->name; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h new file mode 100644 index 0000000..46e4f36 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h @@ -0,0 +1,67 @@ +/* + * libvirt-gconfig-capabilities-guest-feature.h: libvirt guest feature capabilities + * + * 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_CAPABILITIES_GUEST_FEATURE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_FEATURE_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE (gvir_config_capabilities_guest_feature_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeature)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeatureClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeatureClass)) + +typedef struct _GVirConfigCapabilitiesGuestFeature GVirConfigCapabilitiesGuestFeature; +typedef struct _GVirConfigCapabilitiesGuestFeaturePrivate GVirConfigCapabilitiesGuestFeaturePrivate; +typedef struct _GVirConfigCapabilitiesGuestFeatureClass GVirConfigCapabilitiesGuestFeatureClass; + +struct _GVirConfigCapabilitiesGuestFeature +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestFeaturePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestFeatureClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_feature_get_type(void); + +const gchar * +gvir_config_capabilities_guest_feature_get_name(GVirConfigCapabilitiesGuestFeature *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_FEATURE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c new file mode 100644 index 0000000..5d1262b --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c @@ -0,0 +1,139 @@ +/* + * libvirt-gconfig-capabilities-guest.c: libvirt guest capabilities + * + * 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_CAPABILITIES_GUEST_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestPrivate)) + +struct _GVirConfigCapabilitiesGuestPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuest, gvir_config_capabilities_guest, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_guest_class_init(GVirConfigCapabilitiesGuestClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestPrivate)); +} + +static void gvir_config_capabilities_guest_init(GVirConfigCapabilitiesGuest *conn) +{ + g_debug("Init GVirConfigCapabilitiesGuest=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_GUEST_GET_PRIVATE(conn); +} + +GVirConfigDomainOsType +gvir_config_capabilities_guest_get_os_type(GVirConfigCapabilitiesGuest *caps) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), -1); + + return gvir_config_object_get_node_content_genum(GVIR_CONFIG_OBJECT(caps), + "os_type", + GVIR_CONFIG_TYPE_DOMAIN_OS_TYPE, + GVIR_CONFIG_DOMAIN_OS_TYPE_LINUX); +} + +/** + * gvir_config_capabilities_guest_get_arch: + * + * Gets the CPU architecture capabilities of the guest. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesGuestArch. + */ +GVirConfigCapabilitiesGuestArch * +gvir_config_capabilities_guest_get_arch(GVirConfigCapabilitiesGuest *caps) +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), NULL); + + object = gvir_config_object_get_child_with_type + (GVIR_CONFIG_OBJECT(caps), + "arch", + GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH); + + return GVIR_CONFIG_CAPABILITIES_GUEST_ARCH(object); +} + +struct GetFeatureData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *features; +}; + +static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree + (GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, + data->doc, + data->schema, + node); + if (object != NULL) + data->features = g_list_append(data->features, object); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_guest_get_features: + * + * Gets the CPU features for this guest. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesGuestFeature) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesGuestFeature. + */ +GList * +gvir_config_capabilities_guest_get_features(GVirConfigCapabilitiesGuest *caps) +{ + struct GetFeatureData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + g_return_val_if_fail(data.doc != NULL, NULL); + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(data.schema != NULL, NULL); + data.features = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(caps), + "features", + add_feature, + &data); + + g_clear_object(&data.doc); + + return data.features; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h new file mode 100644 index 0000000..b75d82f --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h @@ -0,0 +1,75 @@ +/* + * libvirt-gconfig-capabilities-guest.h: libvirt guest capabilities + * + * 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_CAPABILITIES_GUEST_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ + +#include "libvirt-gconfig-domain-os.h" +#include "libvirt-gconfig-capabilities-guest-arch.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST (gvir_config_capabilities_guest_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuest)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestClass)) + +typedef struct _GVirConfigCapabilitiesGuest GVirConfigCapabilitiesGuest; +typedef struct _GVirConfigCapabilitiesGuestPrivate GVirConfigCapabilitiesGuestPrivate; +typedef struct _GVirConfigCapabilitiesGuestClass GVirConfigCapabilitiesGuestClass; + +struct _GVirConfigCapabilitiesGuest +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_get_type(void); + +GVirConfigDomainOsType +gvir_config_capabilities_guest_get_os_type(GVirConfigCapabilitiesGuest *caps); + +GVirConfigCapabilitiesGuestArch * +gvir_config_capabilities_guest_get_arch(GVirConfigCapabilitiesGuest *caps); +GList * +gvir_config_capabilities_guest_get_features(GVirConfigCapabilitiesGuest *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 0bba874..debee83 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -94,3 +94,60 @@ gvir_config_capabilities_get_host(GVirConfigCapabilities *caps) return GVIR_CONFIG_CAPABILITIES_HOST(object); } + +struct GetGuestData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *guests; +}; + +static gboolean add_guest(xmlNodePtr node, gpointer opaque) +{ + struct GetGuestData* data = (struct GetGuestData*)opaque; + GVirConfigObject *object; + + if (g_strcmp0((const gchar *)node->name, "guest") != 0) + return TRUE; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, + data->doc, + data->schema, + node); + if (object != NULL) + data->guests = g_list_append(data->guests, object); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_get_guests: + * + * Gets the list of guest capabilities. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesGuest) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesGuest. + */ +GList * +gvir_config_capabilities_get_guests(GVirConfigCapabilities *caps) +{ + struct GetGuestData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(data.schema != NULL, NULL); + data.guests = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(caps), + NULL, + add_guest, + &data); + + if (data.doc != NULL) + g_object_unref(G_OBJECT(data.doc)); + + return data.guests; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h index 2ec8369..2e373c9 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h @@ -65,6 +65,7 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, GError **error); GVirConfigCapabilitiesHost * gvir_config_capabilities_get_host(GVirConfigCapabilities *caps); +GList *gvir_config_capabilities_get_guests(GVirConfigCapabilities *caps); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index f9be83f..1201eb8 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -29,8 +29,12 @@ #include <libvirt-gconfig/libvirt-gconfig-main.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> -#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-host.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 7d015f5..709f97f 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -380,6 +380,7 @@ LIBVIRT_GCONFIG_0.0.9 { gvir_config_domain_os_get_boot_devices; gvir_config_capabilities_get_host; + gvir_config_capabilities_get_guests; gvir_config_capabilities_cpu_get_type; gvir_config_capabilities_cpu_get_arch; @@ -388,6 +389,24 @@ LIBVIRT_GCONFIG_0.0.9 { gvir_config_capabilities_cpu_feature_get_type; gvir_config_capabilities_cpu_feature_get_name; + gvir_config_capabilities_guest_get_type; + gvir_config_capabilities_guest_get_arch; + gvir_config_capabilities_guest_get_features; + gvir_config_capabilities_guest_get_os_type; + gvir_config_capabilities_guest_new_from_tree; + + gvir_config_capabilities_guest_arch_get_type; + gvir_config_capabilities_guest_arch_get_domains; + gvir_config_capabilities_guest_arch_get_emulator; + gvir_config_capabilities_guest_arch_get_name; + + gvir_config_capabilities_guest_domain_get_type; + gvir_config_capabilities_guest_domain_get_emulator; + gvir_config_capabilities_guest_domain_get_virt_type; + + gvir_config_capabilities_guest_feature_get_type; + gvir_config_capabilities_guest_feature_get_name; + gvir_config_capabilities_host_get_type; gvir_config_capabilities_host_get_uuid; gvir_config_capabilities_host_get_cpu; -- 1.7.7.6

On Wed, May 09, 2012 at 04:16:15AM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
Not quite complete but its a good start. --- libvirt-gconfig/Makefile.am | 8 + .../libvirt-gconfig-capabilities-guest-arch.c | 122 +++++++++++++++++ .../libvirt-gconfig-capabilities-guest-arch.h | 71 ++++++++++ .../libvirt-gconfig-capabilities-guest-domain.c | 68 ++++++++++ .../libvirt-gconfig-capabilities-guest-domain.h | 72 ++++++++++ .../libvirt-gconfig-capabilities-guest-feature.c | 61 +++++++++ .../libvirt-gconfig-capabilities-guest-feature.h | 67 ++++++++++ .../libvirt-gconfig-capabilities-guest.c | 139 ++++++++++++++++++++ .../libvirt-gconfig-capabilities-guest.h | 75 +++++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.c | 57 ++++++++ libvirt-gconfig/libvirt-gconfig-capabilities.h | 1 + libvirt-gconfig/libvirt-gconfig.h | 6 +- libvirt-gconfig/libvirt-gconfig.sym | 19 +++ 13 files changed, 765 insertions(+), 1 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest.c create mode 100644 libvirt-gconfig/libvirt-gconfig-capabilities-guest.h
diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 54899a3..4bc3ee1 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -15,6 +15,10 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-capabilities-host.h \ libvirt-gconfig-capabilities-cpu.h \ libvirt-gconfig-capabilities-cpu-feature.h \ + libvirt-gconfig-capabilities-guest.h \ + libvirt-gconfig-capabilities-guest-arch.h \ + libvirt-gconfig-capabilities-guest-domain.h \ + libvirt-gconfig-capabilities-guest-feature.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-address.h \ libvirt-gconfig-domain-address-pci.h \ @@ -78,6 +82,10 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-capabilities-host.c \ libvirt-gconfig-capabilities-cpu.c \ libvirt-gconfig-capabilities-cpu-feature.c \ + libvirt-gconfig-capabilities-guest.c \ + libvirt-gconfig-capabilities-guest-arch.c \ + libvirt-gconfig-capabilities-guest-domain.c \ + libvirt-gconfig-capabilities-guest-feature.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-address.c \ libvirt-gconfig-domain-address-pci.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c new file mode 100644 index 0000000..fde835b --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.c @@ -0,0 +1,122 @@ +/* + * libvirt-gconfig-capabilities-cpu-arch.c: libvirt guest architecture capabilities
s/cpu/guest
+ * + * 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_CAPABILITIES_GUEST_ARCH_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArchPrivate)) + +struct _GVirConfigCapabilitiesGuestArchPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuestArch, gvir_config_capabilities_guest_arch, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_guest_arch_class_init(GVirConfigCapabilitiesGuestArchClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestArchPrivate)); +} + +static void gvir_config_capabilities_guest_arch_init(GVirConfigCapabilitiesGuestArch *conn)
usual nit about 'conn' here
+{ + g_debug("Init GVirConfigCapabilitiesGuestArch=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_GUEST_ARCH_GET_PRIVATE(conn); +} + +const gchar * +gvir_config_capabilities_guest_arch_get_name(GVirConfigCapabilitiesGuestArch *caps)
s/caps/arch
+{
g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(arch), NULL);
+ return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(caps), + NULL, + "name"); +} + +struct GetDomainData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *domains; +}; + +static gboolean add_domain(xmlNodePtr node, gpointer opaque) +{ + struct GetDomainData* data = (struct GetDomainData*)opaque; + GVirConfigObject *object; + + if (g_strcmp0((const gchar *)node->name, "domain") != 0) + return TRUE; + + object = gvir_config_object_new_from_tree + (GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, + data->doc, + data->schema, + node); + if (object != NULL) + data->domains = g_list_append(data->domains, object); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_guest_arch_get_domains: + * + * Gets the possible domains for this architecture. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesGuestDomain) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesGuestDomain. + */ +GList * +gvir_config_capabilities_guest_arch_get_domains(GVirConfigCapabilitiesGuestArch *caps)
s/caps/arch
+{ + struct GetDomainData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(caps), NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + g_return_val_if_fail(data.doc != NULL, NULL); + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(data.schema != NULL, NULL);
I don't think the schema needs to be mandatory
+ data.domains = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(caps), + NULL, + add_domain, + &data); + g_clear_object(&data.doc); + + return data.domains; +} + +const gchar * +gvir_config_capabilities_guest_arch_get_emulator(GVirConfigCapabilitiesGuestArch *caps)
s/caps/arch
+{
g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(arch), NULL);
+ return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(caps), + "emulator"); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h new file mode 100644 index 0000000..05bb0e7 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h @@ -0,0 +1,71 @@ +/* + * libvirt-gconfig-capabilities-cpu-arch.h: libvirt guest architecture capabilities
s/cpu/guest
+ * + * 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_CAPABILITIES_GUEST_ARCH_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_ARCH_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH (gvir_config_capabilities_guest_arch_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST_ARCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArch)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArchClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_ARCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_ARCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH, GVirConfigCapabilitiesGuestArchClass)) + +typedef struct _GVirConfigCapabilitiesGuestArch GVirConfigCapabilitiesGuestArch; +typedef struct _GVirConfigCapabilitiesGuestArchPrivate GVirConfigCapabilitiesGuestArchPrivate; +typedef struct _GVirConfigCapabilitiesGuestArchClass GVirConfigCapabilitiesGuestArchClass; + +struct _GVirConfigCapabilitiesGuestArch +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestArchPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestArchClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_arch_get_type(void); + +const gchar * +gvir_config_capabilities_guest_arch_get_name(GVirConfigCapabilitiesGuestArch *caps); +GList * +gvir_config_capabilities_guest_arch_get_domains(GVirConfigCapabilitiesGuestArch *caps); +const gchar * +gvir_config_capabilities_guest_arch_get_emulator(GVirConfigCapabilitiesGuestArch *caps);
s/caps/arch on these 3 lines.
+ +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_ARCH_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c new file mode 100644 index 0000000..eeebfab --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.c @@ -0,0 +1,68 @@ +/* + * libvirt-gconfig-capabilities-domain.c: libvirt guest domain capabilities
missing -guest-
+ * + * 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_CAPABILITIES_GUEST_DOMAIN_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomainPrivate)) + +struct _GVirConfigCapabilitiesGuestDomainPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuestDomain, gvir_config_capabilities_guest_domain, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_guest_domain_class_init(GVirConfigCapabilitiesGuestDomainClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestDomainPrivate)); +} + +static void gvir_config_capabilities_guest_domain_init(GVirConfigCapabilitiesGuestDomain *conn)
s/conn/domain
+{ + g_debug("Init GVirConfigCapabilitiesGuestDomain=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN_GET_PRIVATE(conn); +} + +const gchar * +gvir_config_capabilities_guest_domain_get_emulator(GVirConfigCapabilitiesGuestDomain *caps)
s/caps/domain
+{
g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN(domain), NULL);
+ return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(caps), "emulator"); +} + +GVirConfigDomainVirtType +gvir_config_capabilities_guest_domain_get_virt_type(GVirConfigCapabilitiesGuestDomain *caps) s/caps/domain +{
g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN(domain), GVIR_CONFIG_DOMAIN_VIRT_QEMU);
+ return gvir_config_object_get_attribute_genum + (GVIR_CONFIG_OBJECT(caps), + NULL, + "type", + GVIR_CONFIG_TYPE_DOMAIN_VIRT_TYPE, + GVIR_CONFIG_DOMAIN_VIRT_QEMU); +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h new file mode 100644 index 0000000..c80bde6 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h @@ -0,0 +1,72 @@ +/* + * libvirt-gconfig-capabilities-domain.h: libvirt guest domain capabilities
Missing -guest-
+ * + * 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_CAPABILITIES_GUEST_DOMAIN_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_DOMAIN_H__ + +#include "libvirt-gconfig-domain.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN (gvir_config_capabilities_guest_domain_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomain)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomainClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_DOMAIN, GVirConfigCapabilitiesGuestDomainClass)) + +typedef struct _GVirConfigCapabilitiesGuestDomain GVirConfigCapabilitiesGuestDomain; +typedef struct _GVirConfigCapabilitiesGuestDomainPrivate GVirConfigCapabilitiesGuestDomainPrivate; +typedef struct _GVirConfigCapabilitiesGuestDomainClass GVirConfigCapabilitiesGuestDomainClass; + +struct _GVirConfigCapabilitiesGuestDomain +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestDomainPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestDomainClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_domain_get_type(void); + +const gchar * +gvir_config_capabilities_guest_domain_get_emulator(GVirConfigCapabilitiesGuestDomain *caps); + +GVirConfigDomainVirtType +gvir_config_capabilities_guest_domain_get_virt_type(GVirConfigCapabilitiesGuestDomain *caps);
s/caps/domain
+ +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_DOMAIN_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c new file mode 100644 index 0000000..1554f5a --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.c @@ -0,0 +1,61 @@ +/* + * libvirt-gconfig-capabilities-guest-feature.c: libvirt guest feature capabilities + * + * 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_CAPABILITIES_GUEST_FEATURE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeaturePrivate)) + +struct _GVirConfigCapabilitiesGuestFeaturePrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuestFeature, gvir_config_capabilities_guest_feature, GVIR_CONFIG_TYPE_OBJECT); + +static void gvir_config_capabilities_guest_feature_class_init(GVirConfigCapabilitiesGuestFeatureClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestFeaturePrivate)); +} + +static void gvir_config_capabilities_guest_feature_init(GVirConfigCapabilitiesGuestFeature *feature) +{ + g_debug("Init GVirConfigCapabilitiesGuestFeature=%p", feature); + + feature->priv = GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE_GET_PRIVATE(feature); +} + +const gchar * +gvir_config_capabilities_guest_feature_get_name(GVirConfigCapabilitiesGuestFeature *caps)
s/caps/feature
+{ + xmlNodePtr node;
g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST_FEATURE(caps), NULL);
+ + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(node != NULL, NULL); + + return (const gchar *)node->name; +}
I'd have added a gvir_config_object_get_node_name() method.
diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h new file mode 100644 index 0000000..46e4f36 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h @@ -0,0 +1,67 @@ +/* + * libvirt-gconfig-capabilities-guest-feature.h: libvirt guest feature capabilities + * + * 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_CAPABILITIES_GUEST_FEATURE_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_FEATURE_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE (gvir_config_capabilities_guest_feature_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeature)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeatureClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_FEATURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_FEATURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, GVirConfigCapabilitiesGuestFeatureClass)) + +typedef struct _GVirConfigCapabilitiesGuestFeature GVirConfigCapabilitiesGuestFeature; +typedef struct _GVirConfigCapabilitiesGuestFeaturePrivate GVirConfigCapabilitiesGuestFeaturePrivate; +typedef struct _GVirConfigCapabilitiesGuestFeatureClass GVirConfigCapabilitiesGuestFeatureClass; + +struct _GVirConfigCapabilitiesGuestFeature +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestFeaturePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestFeatureClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_feature_get_type(void); + +const gchar * +gvir_config_capabilities_guest_feature_get_name(GVirConfigCapabilitiesGuestFeature *caps);
s/caps/feature
+ +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_FEATURE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c new file mode 100644 index 0000000..5d1262b --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.c @@ -0,0 +1,139 @@ +/* + * libvirt-gconfig-capabilities-guest.c: libvirt guest capabilities + * + * 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_CAPABILITIES_GUEST_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestPrivate)) + +struct _GVirConfigCapabilitiesGuestPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigCapabilitiesGuest, gvir_config_capabilities_guest, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_capabilities_guest_class_init(GVirConfigCapabilitiesGuestClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigCapabilitiesGuestPrivate)); +} + +static void gvir_config_capabilities_guest_init(GVirConfigCapabilitiesGuest *conn)
s/conn/caps
+{ + g_debug("Init GVirConfigCapabilitiesGuest=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_GUEST_GET_PRIVATE(conn); +} + +GVirConfigDomainOsType
I don't think this is the right return type, this enum currently translates to "hvm", "linux" and "exe", while "xen" and "uml" should also be valid (re-reading libvirt source code, it might have been better to use a string instead of this enum). The only valid values for guest caps os type are "xen" and "hvm"
+gvir_config_capabilities_guest_get_os_type(GVirConfigCapabilitiesGuest *caps) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), -1);
s/-1/...OS_TYPE_LINUX
+ + return gvir_config_object_get_node_content_genum(GVIR_CONFIG_OBJECT(caps), + "os_type", + GVIR_CONFIG_TYPE_DOMAIN_OS_TYPE, + GVIR_CONFIG_DOMAIN_OS_TYPE_LINUX); +} + +/** + * gvir_config_capabilities_guest_get_arch: + * + * Gets the CPU architecture capabilities of the guest. + * + * Returns: (transfer full): a new #GVirConfigCapabilitiesGuestArch. + */ +GVirConfigCapabilitiesGuestArch * +gvir_config_capabilities_guest_get_arch(GVirConfigCapabilitiesGuest *caps) +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), NULL); + + object = gvir_config_object_get_child_with_type + (GVIR_CONFIG_OBJECT(caps), + "arch", + GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_ARCH); + + return GVIR_CONFIG_CAPABILITIES_GUEST_ARCH(object); +} + +struct GetFeatureData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *features; +}; + +static gboolean add_feature(xmlNodePtr node, gpointer opaque) +{ + struct GetFeatureData* data = (struct GetFeatureData*)opaque; + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree + (GVIR_CONFIG_TYPE_CAPABILITIES_GUEST_FEATURE, + data->doc, + data->schema, + node); + if (object != NULL) + data->features = g_list_append(data->features, object); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_guest_get_features: + * + * Gets the CPU features for this guest. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesGuestFeature) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesGuestFeature. + */ +GList * +gvir_config_capabilities_guest_get_features(GVirConfigCapabilitiesGuest *caps) +{ + struct GetFeatureData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES_GUEST(caps), NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + g_return_val_if_fail(data.doc != NULL, NULL); + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(data.schema != NULL, NULL);
same here, I wouldn't bail out if schema is NULL. If you want to keep it, you need to switch the g_object_get and the _get_schema if you don't want to leak data.doc.
+ data.features = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(caps), + "features", + add_feature, + &data); + + g_clear_object(&data.doc); + + return data.features; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h new file mode 100644 index 0000000..b75d82f --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-capabilities-guest.h @@ -0,0 +1,75 @@ +/* + * libvirt-gconfig-capabilities-guest.h: libvirt guest capabilities + * + * 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_CAPABILITIES_GUEST_H__ +#define __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ + +#include "libvirt-gconfig-domain-os.h" +#include "libvirt-gconfig-capabilities-guest-arch.h" + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_CAPABILITIES_GUEST (gvir_config_capabilities_guest_get_type ()) +#define GVIR_CONFIG_CAPABILITIES_GUEST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuest)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestClass)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST)) +#define GVIR_CONFIG_IS_CAPABILITIES_GUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST)) +#define GVIR_CONFIG_CAPABILITIES_GUEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, GVirConfigCapabilitiesGuestClass)) + +typedef struct _GVirConfigCapabilitiesGuest GVirConfigCapabilitiesGuest; +typedef struct _GVirConfigCapabilitiesGuestPrivate GVirConfigCapabilitiesGuestPrivate; +typedef struct _GVirConfigCapabilitiesGuestClass GVirConfigCapabilitiesGuestClass; + +struct _GVirConfigCapabilitiesGuest +{ + GVirConfigObject parent; + + GVirConfigCapabilitiesGuestPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigCapabilitiesGuestClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_config_capabilities_guest_get_type(void); + +GVirConfigDomainOsType +gvir_config_capabilities_guest_get_os_type(GVirConfigCapabilitiesGuest *caps); + +GVirConfigCapabilitiesGuestArch * +gvir_config_capabilities_guest_get_arch(GVirConfigCapabilitiesGuest *caps); +GList * +gvir_config_capabilities_guest_get_features(GVirConfigCapabilitiesGuest *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_CAPABILITIES_GUEST_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 0bba874..debee83 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -94,3 +94,60 @@ gvir_config_capabilities_get_host(GVirConfigCapabilities *caps)
return GVIR_CONFIG_CAPABILITIES_HOST(object); } + +struct GetGuestData { + GVirConfigXmlDoc *doc; + const gchar *schema; + GList *guests; +}; + +static gboolean add_guest(xmlNodePtr node, gpointer opaque) +{ + struct GetGuestData* data = (struct GetGuestData*)opaque; + GVirConfigObject *object; + + if (g_strcmp0((const gchar *)node->name, "guest") != 0) + return TRUE; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_CAPABILITIES_GUEST, + data->doc, + data->schema, + node); + if (object != NULL) + data->guests = g_list_append(data->guests, object); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + +/** + * gvir_config_capabilities_get_guests: + * + * Gets the list of guest capabilities. + * + * Returns: (element-type LibvirtGConfig.CapabilitiesGuest) (transfer full): + * a newly allocated #GList of #GVirConfigCapabilitiesGuest. + */ +GList * +gvir_config_capabilities_get_guests(GVirConfigCapabilities *caps) +{ + struct GetGuestData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_CAPABILITIES(caps), NULL); + + g_object_get(G_OBJECT(caps), "doc", &data.doc, NULL); + data.schema = gvir_config_object_get_schema(GVIR_CONFIG_OBJECT(caps)); + g_return_val_if_fail(data.schema != NULL, NULL);
Usual comment about this test
+ data.guests = NULL; + + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(caps), + NULL, + add_guest, + &data); + + if (data.doc != NULL) + g_object_unref(G_OBJECT(data.doc));
You used g_clear_object in the other similar functions when you knew for sure that data.doc != NULL, but here you use g_object_unref when it might be NULL? I would have used g_object_unref everywhere, but I'm fine with g_clear_object too as long as things are consistent.
+ + return data.guests; +} diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h index 2ec8369..2e373c9 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h @@ -65,6 +65,7 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, GError **error); GVirConfigCapabilitiesHost * gvir_config_capabilities_get_host(GVirConfigCapabilities *caps); +GList *gvir_config_capabilities_get_guests(GVirConfigCapabilities *caps);
G_END_DECLS
diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index f9be83f..1201eb8 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -29,8 +29,12 @@ #include <libvirt-gconfig/libvirt-gconfig-main.h> #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> -#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-feature.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-arch.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-domain.h> +#include <libvirt-gconfig/libvirt-gconfig-capabilities-guest-feature.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities-host.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-address.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 7d015f5..709f97f 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -380,6 +380,7 @@ LIBVIRT_GCONFIG_0.0.9 { gvir_config_domain_os_get_boot_devices;
gvir_config_capabilities_get_host; + gvir_config_capabilities_get_guests;
gvir_config_capabilities_cpu_get_type; gvir_config_capabilities_cpu_get_arch; @@ -388,6 +389,24 @@ LIBVIRT_GCONFIG_0.0.9 { gvir_config_capabilities_cpu_feature_get_type; gvir_config_capabilities_cpu_feature_get_name;
+ gvir_config_capabilities_guest_get_type; + gvir_config_capabilities_guest_get_arch; + gvir_config_capabilities_guest_get_features; + gvir_config_capabilities_guest_get_os_type; + gvir_config_capabilities_guest_new_from_tree;
This symbol does not exist
+ + gvir_config_capabilities_guest_arch_get_type; + gvir_config_capabilities_guest_arch_get_domains; + gvir_config_capabilities_guest_arch_get_emulator; + gvir_config_capabilities_guest_arch_get_name; + + gvir_config_capabilities_guest_domain_get_type; + gvir_config_capabilities_guest_domain_get_emulator; + gvir_config_capabilities_guest_domain_get_virt_type; + + gvir_config_capabilities_guest_feature_get_type; + gvir_config_capabilities_guest_feature_get_name; +
Christophe
gvir_config_capabilities_host_get_type; gvir_config_capabilities_host_get_uuid; gvir_config_capabilities_host_get_cpu; -- 1.7.7.6
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Wed, May 9, 2012 at 5:54 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
On Wed, May 09, 2012 at 04:16:15AM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
Not quite complete but its a good start. +{ + g_debug("Init GVirConfigCapabilitiesGuest=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_GUEST_GET_PRIVATE(conn); +} + +GVirConfigDomainOsType
I don't think this is the right return type, this enum currently translates to "hvm", "linux" and "exe", while "xen" and "uml" should also be valid (re-reading libvirt source code, it might have been better to use a string instead of this enum). The only valid values for guest caps os type are "xen" and "hvm"
RTF RNG :) <define name='guestcaps'> <element name='guest'> <ref name='ostype'/> ... <define name='ostype'> <element name='os_type'> <choice> <value>xen</value> <!-- Xen 3.0 pv --> <value>linux</value> <!-- same as 'xen' - legacy --> <value>hvm</value> <!-- unmodified OS --> <value>exe</value> <!-- For container based virt --> <value>uml</value> <!-- user mode linux --> -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Wed, May 09, 2012 at 11:44:24PM +0300, Zeeshan Ali (Khattak) wrote:
On Wed, May 9, 2012 at 5:54 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
On Wed, May 09, 2012 at 04:16:15AM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
Not quite complete but its a good start. +{ + g_debug("Init GVirConfigCapabilitiesGuest=%p", conn); + + conn->priv = GVIR_CONFIG_CAPABILITIES_GUEST_GET_PRIVATE(conn); +} + +GVirConfigDomainOsType
I don't think this is the right return type, this enum currently translates to "hvm", "linux" and "exe", while "xen" and "uml" should also be valid (re-reading libvirt source code, it might have been better to use a string instead of this enum). The only valid values for guest caps os type are "xen" and "hvm"
RTF RNG :)
Sorry slightly out of date documentation in src/conf/capabilities.c, I've confirmed that all these values are used with: git grep -A 1 virCapabilitiesAddGuest\( GVIR_CONFIG_DOMAIN_OS_TYPE_UML and GVIR_CONFIG_DOMAIN_OS_TYPE_XEN need to be added to GVirConfigDomainOsType. Christophe

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> --- libvirt-gconfig/tests/Makefile.am | 4 +- libvirt-gconfig/tests/test-capabilities-parse.c | 159 +++++++++++ libvirt-gconfig/tests/test-capabilities-parse.xml | 294 +++++++++++++++++++++ 3 files changed, 456 insertions(+), 1 deletions(-) create mode 100644 libvirt-gconfig/tests/test-capabilities-parse.c create mode 100644 libvirt-gconfig/tests/test-capabilities-parse.xml diff --git a/libvirt-gconfig/tests/Makefile.am b/libvirt-gconfig/tests/Makefile.am index 5061fd9..4d1a564 100644 --- a/libvirt-gconfig/tests/Makefile.am +++ b/libvirt-gconfig/tests/Makefile.am @@ -1,4 +1,4 @@ -noinst_PROGRAMS = test-domain-create test-domain-parse +noinst_PROGRAMS = test-domain-create test-domain-parse test-capabilities-parse AM_CFLAGS = \ $(GOBJECT2_CFLAGS) \ @@ -14,3 +14,5 @@ LDADD = \ test_domain_create_SOURCES = test-domain-create.c test_domain_parse_SOURCES = test-domain-parse.c + +test_capabilities_parse_SOURCES = test-capabilities-parse.c diff --git a/libvirt-gconfig/tests/test-capabilities-parse.c b/libvirt-gconfig/tests/test-capabilities-parse.c new file mode 100644 index 0000000..f895441 --- /dev/null +++ b/libvirt-gconfig/tests/test-capabilities-parse.c @@ -0,0 +1,159 @@ +/* + * test-capabilities-parse.c: test libvirt-gconfig capabilities parsing + * + * Copyright (C) 2011-2012 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * The Software is provided "as is", without warranty of any kind, express + * or implied, including but not limited to the warranties of + * merchantability, fitness for a particular purpose and noninfringement. + * In no event shall the authors or copyright holders be liable for any + * claim, damages or other liability, whether in an action of contract, + * tort or otherwise, arising from, out of or in connection with the + * software or the use or other dealings in the Software. + * + * Authors: Zeeshan Ali <zeenix@redhat.com> + * Christophe Fergeau <cfergeau@redhat.com> + */ + +#include <config.h> + +#include <string.h> +#include <libvirt-gconfig/libvirt-gconfig.h> + +static void verify_host_caps(GVirConfigCapabilitiesHost *host_caps) +{ + GVirConfigCapabilitiesCpu *cpu_caps; + GList *features, *iter; + const char *str; + + g_assert(host_caps != NULL); + str = gvir_config_capabilities_host_get_uuid(host_caps); + g_assert(g_strcmp0(str, "cd6a24b3-46f8-01aa-bb39-c39aa2123730") == 0); + cpu_caps = gvir_config_capabilities_host_get_cpu(host_caps); + g_assert(cpu_caps != NULL); + str = gvir_config_capabilities_cpu_get_arch(cpu_caps); + g_assert(g_strcmp0(str, "x86_64") == 0); + + features = gvir_config_capabilities_cpu_get_features(cpu_caps); + for (iter = features; iter != NULL; iter = iter->next) { + g_assert(iter->data != NULL); + g_object_unref(G_OBJECT(iter->data)); + } + g_list_free(features); +} + +static void verify_guest_caps(GVirConfigCapabilitiesGuest *guest_caps) +{ + GVirConfigCapabilitiesGuestArch *arch_caps; + GList *features, *domains, *iter; + const char *str; + + g_assert(guest_caps != NULL); + g_assert(gvir_config_capabilities_guest_get_os_type(guest_caps) == + GVIR_CONFIG_DOMAIN_OS_TYPE_HVM); + + features = gvir_config_capabilities_guest_get_features(guest_caps); + for (iter = features; iter != NULL; iter = iter->next) { + GVirConfigCapabilitiesGuestFeature *feature_caps; + + feature_caps = GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE(iter->data); + g_assert(feature_caps != NULL); + str = gvir_config_capabilities_guest_feature_get_name(feature_caps); + g_assert(str != NULL); + g_object_unref(G_OBJECT(feature_caps)); + } + g_list_free(features); + + arch_caps = gvir_config_capabilities_guest_get_arch(guest_caps); + g_assert(arch_caps != NULL); + str = gvir_config_capabilities_guest_arch_get_name(arch_caps); + g_assert(str != NULL); + str = gvir_config_capabilities_guest_arch_get_emulator(arch_caps); + g_assert(str != NULL); + + domains = gvir_config_capabilities_guest_arch_get_domains(arch_caps); + for (iter = domains; iter != NULL; iter = iter->next) { + GVirConfigCapabilitiesGuestDomain *domain_caps; + GVirConfigDomainVirtType virt_type; + + domain_caps = GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN(iter->data); + g_assert(domain_caps != NULL); + virt_type = gvir_config_capabilities_guest_domain_get_virt_type(domain_caps); + str = gvir_config_capabilities_guest_domain_get_emulator(domain_caps); + g_assert((virt_type == GVIR_CONFIG_DOMAIN_VIRT_QEMU && str == NULL) || + (virt_type == GVIR_CONFIG_DOMAIN_VIRT_KVM && + g_strcmp0(str, "/usr/bin/qemu-kvm") == 0)); + g_object_unref(G_OBJECT(domain_caps)); + } + g_list_free(features); +} + +int main(int argc, char **argv) +{ + GVirConfigCapabilities *caps; + GVirConfigCapabilitiesHost *host_caps; + GList *guests_caps, *iter; + char *xml; + GError *error = NULL; + + gvir_config_init(&argc, &argv); + if (argc != 2) { + g_print("Usage: %s filename\n", argv[0]); + g_print("Attempt to parse the libvirt XML definition from filename\n"); + return 1; + } + + g_file_get_contents(argv[1], &xml, NULL, &error); + if (error != NULL) { + g_print("Couldn't read %s: %s\n", argv[1], error->message); + return 2; + } + + g_type_init(); + + caps = gvir_config_capabilities_new_from_xml(xml, &error); + if (error != NULL) { + g_print("Couldn't parse %s: %s\n", argv[1], error->message); + return 3; + } + g_assert(caps != NULL); + gvir_config_object_validate(GVIR_CONFIG_OBJECT(caps), &error); + if (error != NULL) { + g_print("%s format is invalid: %s\n", argv[1], error->message); + g_clear_error(&error); + } + + host_caps = gvir_config_capabilities_get_host(caps); + verify_host_caps(host_caps); + g_object_unref(G_OBJECT(host_caps)); + + guests_caps = gvir_config_capabilities_get_guests(caps); + for (iter = guests_caps; iter != NULL; iter = iter->next) { + GVirConfigCapabilitiesGuest *guest_caps; + + guest_caps = GVIR_CONFIG_CAPABILITIES_GUEST(iter->data); + verify_guest_caps(guest_caps); + g_object_unref(G_OBJECT(guest_caps)); + } + g_list_free(guests_caps); + + g_free(xml); + + xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(caps)); + g_print("%s\n", xml); + g_free(xml); + g_object_unref(G_OBJECT(caps)); + + return 0; +} diff --git a/libvirt-gconfig/tests/test-capabilities-parse.xml b/libvirt-gconfig/tests/test-capabilities-parse.xml new file mode 100644 index 0000000..796c81d --- /dev/null +++ b/libvirt-gconfig/tests/test-capabilities-parse.xml @@ -0,0 +1,294 @@ +<capabilities> + + <host> + <uuid>cd6a24b3-46f8-01aa-bb39-c39aa2123730</uuid> + <cpu> + <arch>x86_64</arch> + <model>Westmere</model> + <vendor>Intel</vendor> + <topology sockets="1" cores="2" threads="2"/> + <feature name="rdtscp"/> + <feature name="pdcm"/> + <feature name="xtpr"/> + <feature name="tm2"/> + <feature name="est"/> + <feature name="smx"/> + <feature name="vmx"/> + <feature name="ds_cpl"/> + <feature name="monitor"/> + <feature name="dtes64"/> + <feature name="pclmuldq"/> + <feature name="pbe"/> + <feature name="tm"/> + <feature name="ht"/> + <feature name="ss"/> + <feature name="acpi"/> + <feature name="ds"/> + <feature name="vme"/> + </cpu> + <power_management> + <suspend_mem/> + <suspend_disk/> + </power_management> + <migration_features> + <live/> + <uri_transports> + <uri_transport>tcp</uri_transport> + </uri_transports> + </migration_features> + <secmodel> + <model>selinux</model> + <doi>0</doi> + </secmodel> + </host> + + <guest> + <os_type>hvm</os_type> + <arch name="i686"> + <wordsize>32</wordsize> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <machine>pc-1.1</machine> + <machine canonical="pc-1.1">pc</machine> + <machine>pc-1.0</machine> + <machine>pc-0.15</machine> + <machine>pc-0.14</machine> + <machine>pc-0.13</machine> + <machine>pc-0.12</machine> + <machine>pc-0.11</machine> + <machine>pc-0.10</machine> + <machine>isapc</machine> + <domain type="qemu"> + </domain> + <domain type="kvm"> + <emulator>/usr/bin/qemu-kvm</emulator> + <machine>pc-1.1</machine> + <machine canonical="pc-1.1">pc</machine> + <machine>pc-1.0</machine> + <machine>pc-0.15</machine> + <machine>pc-0.14</machine> + <machine>pc-0.13</machine> + <machine>pc-0.12</machine> + <machine>pc-0.11</machine> + <machine>pc-0.10</machine> + <machine>isapc</machine> + </domain> + </arch> + <features> + <cpuselection/> + <pae/> + <nonpae/> + <acpi default="on" toggle="yes"/> + <apic default="on" toggle="no"/> + </features> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="x86_64"> + <wordsize>64</wordsize> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <machine>pc-1.1</machine> + <machine canonical="pc-1.1">pc</machine> + <machine>pc-1.0</machine> + <machine>pc-0.15</machine> + <machine>pc-0.14</machine> + <machine>pc-0.13</machine> + <machine>pc-0.12</machine> + <machine>pc-0.11</machine> + <machine>pc-0.10</machine> + <machine>isapc</machine> + <domain type="qemu"> + </domain> + <domain type="kvm"> + <emulator>/usr/bin/qemu-kvm</emulator> + <machine>pc-1.1</machine> + <machine canonical="pc-1.1">pc</machine> + <machine>pc-1.0</machine> + <machine>pc-0.15</machine> + <machine>pc-0.14</machine> + <machine>pc-0.13</machine> + <machine>pc-0.12</machine> + <machine>pc-0.11</machine> + <machine>pc-0.10</machine> + <machine>isapc</machine> + </domain> + </arch> + <features> + <cpuselection/> + <acpi default="on" toggle="yes"/> + <apic default="on" toggle="no"/> + </features> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="arm"> + <wordsize>32</wordsize> + <emulator>/usr/bin/qemu-system-arm</emulator> + <machine>integratorcp</machine> + <machine>collie</machine> + <machine>nuri</machine> + <machine>smdkc210</machine> + <machine>connex</machine> + <machine>verdex</machine> + <machine>highbank</machine> + <machine>mainstone</machine> + <machine>musicpal</machine> + <machine>n800</machine> + <machine>n810</machine> + <machine>sx1</machine> + <machine>sx1-v1</machine> + <machine>cheetah</machine> + <machine>realview-eb</machine> + <machine>realview-eb-mpcore</machine> + <machine>realview-pb-a8</machine> + <machine>realview-pbx-a9</machine> + <machine>akita</machine> + <machine>spitz</machine> + <machine>borzoi</machine> + <machine>terrier</machine> + <machine>lm3s811evb</machine> + <machine>lm3s6965evb</machine> + <machine>tosa</machine> + <machine>versatilepb</machine> + <machine>versatileab</machine> + <machine>vexpress-a9</machine> + <machine>vexpress-a15</machine> + <machine>xilinx-zynq-a9</machine> + <machine>z2</machine> + <domain type="qemu"> + </domain> + </arch> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="microblaze"> + <wordsize>32</wordsize> + <emulator>/usr/bin/qemu-system-microblaze</emulator> + <machine>petalogix-s3adsp1800</machine> + <machine>petalogix-ml605</machine> + <domain type="qemu"> + </domain> + </arch> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="microblazeel"> + <wordsize>32</wordsize> + <emulator>/usr/bin/qemu-system-microblazeel</emulator> + <machine>petalogix-s3adsp1800</machine> + <machine>petalogix-ml605</machine> + <domain type="qemu"> + </domain> + </arch> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="mips"> + <wordsize>32</wordsize> + <emulator>/usr/bin/qemu-system-mips</emulator> + <machine>malta</machine> + <machine>magnum</machine> + <machine>pica61</machine> + <machine>mipssim</machine> + <machine>mips</machine> + <domain type="qemu"> + </domain> + </arch> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="mipsel"> + <wordsize>32</wordsize> + <emulator>/usr/bin/qemu-system-mipsel</emulator> + <machine>malta</machine> + <machine>magnum</machine> + <machine>pica61</machine> + <machine>mipssim</machine> + <machine>mips</machine> + <domain type="qemu"> + </domain> + </arch> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="sparc"> + <wordsize>32</wordsize> + <emulator>/usr/bin/qemu-system-sparc</emulator> + <machine>SS-5</machine> + <machine>leon3_generic</machine> + <machine>SS-10</machine> + <machine>SS-600MP</machine> + <machine>SS-20</machine> + <machine>Voyager</machine> + <machine>LX</machine> + <machine>SS-4</machine> + <machine>SPARCClassic</machine> + <machine>SPARCbook</machine> + <machine>SS-1000</machine> + <machine>SS-2000</machine> + <machine>SS-2</machine> + <domain type="qemu"> + </domain> + </arch> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="ppc"> + <wordsize>32</wordsize> + <emulator>/usr/bin/qemu-system-ppc</emulator> + <machine>g3beige</machine> + <machine>ref405ep</machine> + <machine>taihu</machine> + <machine>bamboo</machine> + <machine>mac99</machine> + <machine>prep</machine> + <machine>mpc8544ds</machine> + <machine>virtex-ml507</machine> + <domain type="qemu"> + </domain> + </arch> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="ppc64"> + <wordsize>64</wordsize> + <emulator>/usr/bin/qemu-system-ppc64</emulator> + <machine>mac99</machine> + <machine>ref405ep</machine> + <machine>taihu</machine> + <machine>bamboo</machine> + <machine>g3beige</machine> + <machine>prep</machine> + <machine>mpc8544ds</machine> + <machine>virtex-ml507</machine> + <domain type="qemu"> + </domain> + </arch> + <features> + <cpuselection/> + </features> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="s390x"> + <wordsize>64</wordsize> + <emulator>/usr/bin/qemu-system-s390x</emulator> + <machine>s390-virtio</machine> + <machine canonical="s390-virtio">s390</machine> + <domain type="qemu"> + </domain> + </arch> + </guest> + +</capabilities> + + -- 1.7.7.6

Running this through valgrind revealed two leaks and an invalid free: diff --git a/libvirt-gconfig/tests/test-capabilities-parse.c b/libvirt-gconfig/tests/test-capabilities-parse.c index f895441..eefff2a 100644 --- a/libvirt-gconfig/tests/test-capabilities-parse.c +++ b/libvirt-gconfig/tests/test-capabilities-parse.c @@ -44,6 +44,7 @@ static void verify_host_caps(GVirConfigCapabilitiesHost *host_caps) g_assert(cpu_caps != NULL); str = gvir_config_capabilities_cpu_get_arch(cpu_caps); g_assert(g_strcmp0(str, "x86_64") == 0); + g_object_unref(G_OBJECT(cpu_caps)); features = gvir_config_capabilities_cpu_get_features(cpu_caps); for (iter = features; iter != NULL; iter = iter->next) { @@ -81,6 +82,7 @@ static void verify_guest_caps(GVirConfigCapabilitiesGuest *guest_caps) g_assert(str != NULL); str = gvir_config_capabilities_guest_arch_get_emulator(arch_caps); g_assert(str != NULL); + g_object_unref(G_OBJECT(arch_caps)); domains = gvir_config_capabilities_guest_arch_get_domains(arch_caps); for (iter = domains; iter != NULL; iter = iter->next) { @@ -96,7 +98,7 @@ static void verify_guest_caps(GVirConfigCapabilitiesGuest *guest_caps) g_strcmp0(str, "/usr/bin/qemu-kvm") == 0)); g_object_unref(G_OBJECT(domain_caps)); } - g_list_free(features); + g_list_free(domains); } int main(int argc, char **argv) On Wed, May 09, 2012 at 04:16:16AM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
--- libvirt-gconfig/tests/Makefile.am | 4 +- libvirt-gconfig/tests/test-capabilities-parse.c | 159 +++++++++++ libvirt-gconfig/tests/test-capabilities-parse.xml | 294 +++++++++++++++++++++ 3 files changed, 456 insertions(+), 1 deletions(-) create mode 100644 libvirt-gconfig/tests/test-capabilities-parse.c create mode 100644 libvirt-gconfig/tests/test-capabilities-parse.xml
diff --git a/libvirt-gconfig/tests/Makefile.am b/libvirt-gconfig/tests/Makefile.am index 5061fd9..4d1a564 100644 --- a/libvirt-gconfig/tests/Makefile.am +++ b/libvirt-gconfig/tests/Makefile.am @@ -1,4 +1,4 @@ -noinst_PROGRAMS = test-domain-create test-domain-parse +noinst_PROGRAMS = test-domain-create test-domain-parse test-capabilities-parse
AM_CFLAGS = \ $(GOBJECT2_CFLAGS) \ @@ -14,3 +14,5 @@ LDADD = \ test_domain_create_SOURCES = test-domain-create.c
test_domain_parse_SOURCES = test-domain-parse.c + +test_capabilities_parse_SOURCES = test-capabilities-parse.c diff --git a/libvirt-gconfig/tests/test-capabilities-parse.c b/libvirt-gconfig/tests/test-capabilities-parse.c new file mode 100644 index 0000000..f895441 --- /dev/null +++ b/libvirt-gconfig/tests/test-capabilities-parse.c @@ -0,0 +1,159 @@ +/* + * test-capabilities-parse.c: test libvirt-gconfig capabilities parsing + * + * Copyright (C) 2011-2012 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * The Software is provided "as is", without warranty of any kind, express + * or implied, including but not limited to the warranties of + * merchantability, fitness for a particular purpose and noninfringement. + * In no event shall the authors or copyright holders be liable for any + * claim, damages or other liability, whether in an action of contract, + * tort or otherwise, arising from, out of or in connection with the + * software or the use or other dealings in the Software. + * + * Authors: Zeeshan Ali <zeenix@redhat.com> + * Christophe Fergeau <cfergeau@redhat.com> + */ + +#include <config.h> + +#include <string.h> +#include <libvirt-gconfig/libvirt-gconfig.h> + +static void verify_host_caps(GVirConfigCapabilitiesHost *host_caps) +{ + GVirConfigCapabilitiesCpu *cpu_caps; + GList *features, *iter; + const char *str; + + g_assert(host_caps != NULL); + str = gvir_config_capabilities_host_get_uuid(host_caps); + g_assert(g_strcmp0(str, "cd6a24b3-46f8-01aa-bb39-c39aa2123730") == 0); + cpu_caps = gvir_config_capabilities_host_get_cpu(host_caps); + g_assert(cpu_caps != NULL); + str = gvir_config_capabilities_cpu_get_arch(cpu_caps); + g_assert(g_strcmp0(str, "x86_64") == 0); + + features = gvir_config_capabilities_cpu_get_features(cpu_caps); + for (iter = features; iter != NULL; iter = iter->next) { + g_assert(iter->data != NULL); + g_object_unref(G_OBJECT(iter->data)); + } + g_list_free(features); +} + +static void verify_guest_caps(GVirConfigCapabilitiesGuest *guest_caps) +{ + GVirConfigCapabilitiesGuestArch *arch_caps; + GList *features, *domains, *iter; + const char *str; + + g_assert(guest_caps != NULL); + g_assert(gvir_config_capabilities_guest_get_os_type(guest_caps) == + GVIR_CONFIG_DOMAIN_OS_TYPE_HVM); + + features = gvir_config_capabilities_guest_get_features(guest_caps); + for (iter = features; iter != NULL; iter = iter->next) { + GVirConfigCapabilitiesGuestFeature *feature_caps; + + feature_caps = GVIR_CONFIG_CAPABILITIES_GUEST_FEATURE(iter->data); + g_assert(feature_caps != NULL); + str = gvir_config_capabilities_guest_feature_get_name(feature_caps); + g_assert(str != NULL); + g_object_unref(G_OBJECT(feature_caps)); + } + g_list_free(features); + + arch_caps = gvir_config_capabilities_guest_get_arch(guest_caps); + g_assert(arch_caps != NULL); + str = gvir_config_capabilities_guest_arch_get_name(arch_caps); + g_assert(str != NULL); + str = gvir_config_capabilities_guest_arch_get_emulator(arch_caps); + g_assert(str != NULL); + + domains = gvir_config_capabilities_guest_arch_get_domains(arch_caps); + for (iter = domains; iter != NULL; iter = iter->next) { + GVirConfigCapabilitiesGuestDomain *domain_caps; + GVirConfigDomainVirtType virt_type; + + domain_caps = GVIR_CONFIG_CAPABILITIES_GUEST_DOMAIN(iter->data); + g_assert(domain_caps != NULL); + virt_type = gvir_config_capabilities_guest_domain_get_virt_type(domain_caps); + str = gvir_config_capabilities_guest_domain_get_emulator(domain_caps); + g_assert((virt_type == GVIR_CONFIG_DOMAIN_VIRT_QEMU && str == NULL) || + (virt_type == GVIR_CONFIG_DOMAIN_VIRT_KVM && + g_strcmp0(str, "/usr/bin/qemu-kvm") == 0)); + g_object_unref(G_OBJECT(domain_caps)); + } + g_list_free(features); +} + +int main(int argc, char **argv) +{ + GVirConfigCapabilities *caps; + GVirConfigCapabilitiesHost *host_caps; + GList *guests_caps, *iter; + char *xml; + GError *error = NULL; + + gvir_config_init(&argc, &argv); + if (argc != 2) { + g_print("Usage: %s filename\n", argv[0]); + g_print("Attempt to parse the libvirt XML definition from filename\n"); + return 1; + } + + g_file_get_contents(argv[1], &xml, NULL, &error); + if (error != NULL) { + g_print("Couldn't read %s: %s\n", argv[1], error->message); + return 2; + } + + g_type_init();
Not needed, gvir_config_init calls it
+ + caps = gvir_config_capabilities_new_from_xml(xml, &error); + if (error != NULL) { + g_print("Couldn't parse %s: %s\n", argv[1], error->message); + return 3; + } + g_assert(caps != NULL); + gvir_config_object_validate(GVIR_CONFIG_OBJECT(caps), &error); + if (error != NULL) { + g_print("%s format is invalid: %s\n", argv[1], error->message); + g_clear_error(&error); + } + + host_caps = gvir_config_capabilities_get_host(caps); + verify_host_caps(host_caps); + g_object_unref(G_OBJECT(host_caps)); + + guests_caps = gvir_config_capabilities_get_guests(caps); + for (iter = guests_caps; iter != NULL; iter = iter->next) { + GVirConfigCapabilitiesGuest *guest_caps; + + guest_caps = GVIR_CONFIG_CAPABILITIES_GUEST(iter->data); + verify_guest_caps(guest_caps); + g_object_unref(G_OBJECT(guest_caps)); + } + g_list_free(guests_caps); + + g_free(xml);
I'd move this much closer to gvir_config_capabilities_new_from_xml so that it's obvious it's no longer useful after this, but feel free to keep things this way
+ + xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(caps)); + g_print("%s\n", xml); + g_free(xml); + g_object_unref(G_OBJECT(caps)); + + return 0; +} diff --git a/libvirt-gconfig/tests/test-capabilities-parse.xml b/libvirt-gconfig/tests/test-capabilities-parse.xml new file mode 100644 index 0000000..796c81d --- /dev/null +++ b/libvirt-gconfig/tests/test-capabilities-parse.xml @@ -0,0 +1,294 @@ +<capabilities> + + <host> + <uuid>cd6a24b3-46f8-01aa-bb39-c39aa2123730</uuid> + <cpu> + <arch>x86_64</arch> + <model>Westmere</model> + <vendor>Intel</vendor> + <topology sockets="1" cores="2" threads="2"/> + <feature name="rdtscp"/> + <feature name="pdcm"/> + <feature name="xtpr"/> + <feature name="tm2"/> + <feature name="est"/> + <feature name="smx"/> + <feature name="vmx"/> + <feature name="ds_cpl"/> + <feature name="monitor"/> + <feature name="dtes64"/> + <feature name="pclmuldq"/> + <feature name="pbe"/> + <feature name="tm"/> + <feature name="ht"/> + <feature name="ss"/> + <feature name="acpi"/> + <feature name="ds"/> + <feature name="vme"/> + </cpu> + <power_management> + <suspend_mem/> + <suspend_disk/> + </power_management> + <migration_features> + <live/> + <uri_transports> + <uri_transport>tcp</uri_transport> + </uri_transports> + </migration_features> + <secmodel> + <model>selinux</model> + <doi>0</doi> + </secmodel> + </host> + + <guest> + <os_type>hvm</os_type> + <arch name="i686"> + <wordsize>32</wordsize> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <machine>pc-1.1</machine> + <machine canonical="pc-1.1">pc</machine> + <machine>pc-1.0</machine> + <machine>pc-0.15</machine> + <machine>pc-0.14</machine> + <machine>pc-0.13</machine> + <machine>pc-0.12</machine> + <machine>pc-0.11</machine> + <machine>pc-0.10</machine> + <machine>isapc</machine> + <domain type="qemu"> + </domain> + <domain type="kvm"> + <emulator>/usr/bin/qemu-kvm</emulator> + <machine>pc-1.1</machine> + <machine canonical="pc-1.1">pc</machine> + <machine>pc-1.0</machine> + <machine>pc-0.15</machine> + <machine>pc-0.14</machine> + <machine>pc-0.13</machine> + <machine>pc-0.12</machine> + <machine>pc-0.11</machine> + <machine>pc-0.10</machine> + <machine>isapc</machine> + </domain> + </arch> + <features> + <cpuselection/> + <pae/> + <nonpae/> + <acpi default="on" toggle="yes"/> + <apic default="on" toggle="no"/> + </features> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="x86_64"> + <wordsize>64</wordsize> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <machine>pc-1.1</machine> + <machine canonical="pc-1.1">pc</machine> + <machine>pc-1.0</machine> + <machine>pc-0.15</machine> + <machine>pc-0.14</machine> + <machine>pc-0.13</machine> + <machine>pc-0.12</machine> + <machine>pc-0.11</machine> + <machine>pc-0.10</machine> + <machine>isapc</machine> + <domain type="qemu"> + </domain> + <domain type="kvm"> + <emulator>/usr/bin/qemu-kvm</emulator> + <machine>pc-1.1</machine> + <machine canonical="pc-1.1">pc</machine> + <machine>pc-1.0</machine> + <machine>pc-0.15</machine> + <machine>pc-0.14</machine> + <machine>pc-0.13</machine> + <machine>pc-0.12</machine> + <machine>pc-0.11</machine> + <machine>pc-0.10</machine> + <machine>isapc</machine> + </domain> + </arch> + <features> + <cpuselection/> + <acpi default="on" toggle="yes"/> + <apic default="on" toggle="no"/> + </features> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="arm"> + <wordsize>32</wordsize> + <emulator>/usr/bin/qemu-system-arm</emulator> + <machine>integratorcp</machine> + <machine>collie</machine> + <machine>nuri</machine> + <machine>smdkc210</machine> + <machine>connex</machine> + <machine>verdex</machine> + <machine>highbank</machine> + <machine>mainstone</machine> + <machine>musicpal</machine> + <machine>n800</machine> + <machine>n810</machine> + <machine>sx1</machine> + <machine>sx1-v1</machine> + <machine>cheetah</machine> + <machine>realview-eb</machine> + <machine>realview-eb-mpcore</machine> + <machine>realview-pb-a8</machine> + <machine>realview-pbx-a9</machine> + <machine>akita</machine> + <machine>spitz</machine> + <machine>borzoi</machine> + <machine>terrier</machine> + <machine>lm3s811evb</machine> + <machine>lm3s6965evb</machine> + <machine>tosa</machine> + <machine>versatilepb</machine> + <machine>versatileab</machine> + <machine>vexpress-a9</machine> + <machine>vexpress-a15</machine> + <machine>xilinx-zynq-a9</machine> + <machine>z2</machine> + <domain type="qemu"> + </domain> + </arch> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="microblaze"> + <wordsize>32</wordsize> + <emulator>/usr/bin/qemu-system-microblaze</emulator> + <machine>petalogix-s3adsp1800</machine> + <machine>petalogix-ml605</machine> + <domain type="qemu"> + </domain> + </arch> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="microblazeel"> + <wordsize>32</wordsize> + <emulator>/usr/bin/qemu-system-microblazeel</emulator> + <machine>petalogix-s3adsp1800</machine> + <machine>petalogix-ml605</machine> + <domain type="qemu"> + </domain> + </arch> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="mips"> + <wordsize>32</wordsize> + <emulator>/usr/bin/qemu-system-mips</emulator> + <machine>malta</machine> + <machine>magnum</machine> + <machine>pica61</machine> + <machine>mipssim</machine> + <machine>mips</machine> + <domain type="qemu"> + </domain> + </arch> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="mipsel"> + <wordsize>32</wordsize> + <emulator>/usr/bin/qemu-system-mipsel</emulator> + <machine>malta</machine> + <machine>magnum</machine> + <machine>pica61</machine> + <machine>mipssim</machine> + <machine>mips</machine> + <domain type="qemu"> + </domain> + </arch> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="sparc"> + <wordsize>32</wordsize> + <emulator>/usr/bin/qemu-system-sparc</emulator> + <machine>SS-5</machine> + <machine>leon3_generic</machine> + <machine>SS-10</machine> + <machine>SS-600MP</machine> + <machine>SS-20</machine> + <machine>Voyager</machine> + <machine>LX</machine> + <machine>SS-4</machine> + <machine>SPARCClassic</machine> + <machine>SPARCbook</machine> + <machine>SS-1000</machine> + <machine>SS-2000</machine> + <machine>SS-2</machine> + <domain type="qemu"> + </domain> + </arch> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="ppc"> + <wordsize>32</wordsize> + <emulator>/usr/bin/qemu-system-ppc</emulator> + <machine>g3beige</machine> + <machine>ref405ep</machine> + <machine>taihu</machine> + <machine>bamboo</machine> + <machine>mac99</machine> + <machine>prep</machine> + <machine>mpc8544ds</machine> + <machine>virtex-ml507</machine> + <domain type="qemu"> + </domain> + </arch> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="ppc64"> + <wordsize>64</wordsize> + <emulator>/usr/bin/qemu-system-ppc64</emulator> + <machine>mac99</machine> + <machine>ref405ep</machine> + <machine>taihu</machine> + <machine>bamboo</machine> + <machine>g3beige</machine> + <machine>prep</machine> + <machine>mpc8544ds</machine> + <machine>virtex-ml507</machine> + <domain type="qemu"> + </domain> + </arch> + <features> + <cpuselection/> + </features> + </guest> + + <guest> + <os_type>hvm</os_type> + <arch name="s390x"> + <wordsize>64</wordsize> + <emulator>/usr/bin/qemu-system-s390x</emulator> + <machine>s390-virtio</machine> + <machine canonical="s390-virtio">s390</machine> + <domain type="qemu"> + </domain> + </arch> + </guest> + +</capabilities> + +
And I'd remove these 2 blank lines. ACK with these issues fixed. Christophe

On Thu, May 10, 2012 at 10:27 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
Running this through valgrind revealed two leaks and an invalid free:
Totally forgot these in the rebase/rework of the whole series. Pushed a separate fix for all these now.. -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Wed, May 09, 2012 at 04:16:13AM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
--- libvirt-gconfig/libvirt-gconfig-capabilities.c | 4 - libvirt-gobject/libvirt-gobject-connection.c | 104 ++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-connection.h | 11 +++ libvirt-gobject/libvirt-gobject.sym | 7 ++ 4 files changed, 122 insertions(+), 4 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 4c4df68..3d9d036 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -54,8 +54,6 @@ GVirConfigCapabilities *gvir_config_capabilities_new(void) { GVirConfigObject *object;
- /* FIXME: what is the XML root of the capability node? I suspect it is - * either 'guest' or 'host' */ object = gvir_config_object_new(GVIR_CONFIG_TYPE_CAPABILITIES, "capabilities", DATADIR "/libvirt/schemas/capability.rng"); @@ -67,8 +65,6 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, { GVirConfigObject *object;
- /* FIXME: what is the XML root of the capability node? I suspect it is - * either 'guest' or 'host' */ object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_CAPABILITIES, "capabilities", DATADIR "/libvirt/schemas/capability.rng", diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index 186ad9d..9426510 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -1383,3 +1383,107 @@ GVirNodeInfo *gvir_connection_get_node_info(GVirConnection *conn,
return ret; } + +/** + * gvir_connection_get_capabilities: + * @conn: the connection + * @err: return location for any #GError + * + * Return value: (transfer full): a #GVirConfigCapabilities or NULL + */ +GVirConfigCapabilities *gvir_connection_get_capabilities(GVirConnection *conn, + GError **err) +{ + GVirConfigCapabilities *caps; + char *caps_xml; + + g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL); + g_return_val_if_fail(err == NULL || *err == NULL, NULL); + g_return_val_if_fail(conn->priv->conn, NULL); + + caps_xml = virConnectGetCapabilities(conn->priv->conn); + if (caps_xml == NULL) { + gvir_set_error_literal(err, GVIR_CONNECTION_ERROR, + 0, + "Unable to get capabilities"); + return NULL; + } + + caps = gvir_config_capabilities_new_from_xml(caps_xml, err); + free(caps_xml); + + return caps; +} + +static void +gvir_connection_get_capabilities_helper(GSimpleAsyncResult *res, + GObject *object, + GCancellable *cancellable) +{ + GVirConnection *conn = GVIR_CONNECTION(object); + GError *err = NULL; + GVirConfigCapabilities *caps; + + caps = gvir_connection_get_capabilities(conn, &err); + if (caps == NULL) { + g_simple_async_result_set_from_error(res, err); + g_error_free(err);
These 2 lines can be replaced with g_simple_async_result_take_error(res, err);
+ + return; + } + + g_simple_async_result_set_op_res_gpointer(res, caps, g_object_unref); +} + +/** + * gvir_connection_get_capabilities_async: + * @conn: the connection + * @cancellable: (allow-none)(transfer none): cancellation object + * @callback: (scope async): completion callback + * @user_data: (closure): opaque data for callback + */ +void gvir_connection_get_capabilities_async(GVirConnection *conn, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *res; + + res = g_simple_async_result_new(G_OBJECT(conn), + callback, + user_data, + gvir_connection_get_capabilities_async); + g_simple_async_result_run_in_thread(res, + gvir_connection_get_capabilities_helper, + G_PRIORITY_DEFAULT, + cancellable); + g_object_unref(res); +} + +/** + * gvir_connection_get_capabilities_finish: + * @conn: the connection + * @result: (transfer none): async method result + * + * Return value: (transfer full): a #GVirConfigCapabilities or NULL. + */ +GVirConfigCapabilities * +gvir_connection_get_capabilities_finish(GVirConnection *conn, + GAsyncResult *result, + GError **err) +{ + GVirConfigCapabilities *caps; + + g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL); + g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(conn), + gvir_connection_get_capabilities_async), + NULL); + + if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err)) + return NULL; + + caps = g_simple_async_result_get_op_res_gpointer(G_SIMPLE_ASYNC_RESULT(result)); + g_object_ref(caps); + + return caps;
This could be return g_object_ref(caps); ACK with or without these 2 changes merged in Christophe
participants (3)
-
Christophe Fergeau
-
Daniel P. Berrange
-
Zeeshan Ali (Khattak)