Re: [libvirt-glib 7/8] Add GVirConfigDomainCpu class

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

 



On Sat, Jun 23, 2012 at 10:18:03PM +0300, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx>
> 
> API to handle 'domain/cpu' nodes.
> ---
>  libvirt-gconfig/Makefile.am                  |    2 +
>  libvirt-gconfig/libvirt-gconfig-domain-cpu.c |  179 ++++++++++++++++++++++++++
>  libvirt-gconfig/libvirt-gconfig-domain-cpu.h |   88 +++++++++++++
>  libvirt-gconfig/libvirt-gconfig-domain.c     |   38 ++++++
>  libvirt-gconfig/libvirt-gconfig-domain.h     |    4 +
>  libvirt-gconfig/libvirt-gconfig.h            |    1 +
>  libvirt-gconfig/libvirt-gconfig.sym          |   13 ++
>  7 files changed, 325 insertions(+)
>  create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-cpu.c
>  create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-cpu.h
> 
> diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am
> index 7f0ea3b..fa43f28 100644
> --- a/libvirt-gconfig/Makefile.am
> +++ b/libvirt-gconfig/Makefile.am
> @@ -33,6 +33,7 @@ GCONFIG_HEADER_FILES = \
>  			libvirt-gconfig-domain-console.h \
>  			libvirt-gconfig-domain-controller.h \
>  			libvirt-gconfig-domain-controller-usb.h \
> +			libvirt-gconfig-domain-cpu.h \
>  			libvirt-gconfig-domain-cpu-feature.h \
>  			libvirt-gconfig-domain-device.h \
>  			libvirt-gconfig-domain-disk.h \
> @@ -102,6 +103,7 @@ GCONFIG_SOURCE_FILES = \
>  			libvirt-gconfig-domain-console.c \
>  			libvirt-gconfig-domain-controller.c \
>  			libvirt-gconfig-domain-controller-usb.c \
> +			libvirt-gconfig-domain-cpu.c \
>  			libvirt-gconfig-domain-cpu-feature.c \
>  			libvirt-gconfig-domain-device.c \
>  			libvirt-gconfig-domain-disk.c \
> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-cpu.c b/libvirt-gconfig/libvirt-gconfig-domain-cpu.c
> new file mode 100644
> index 0000000..e238409
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-domain-cpu.c
> @@ -0,0 +1,179 @@
> +/*
> + * libvirt-gconfig-domain-cpu.c: libvirt Domain CPU
> + *
> + * Copyright (C) 2008 Daniel P. Berrange
> + * Copyright (C) 2010-2012 Red Hat, Inc.
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
> + *
> + * Authors: Zeeshan Ali <zeenix@xxxxxxxxxx>
> + *          Daniel P. Berrange <berrange@xxxxxxxxxx>
> + */
> +
> +#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, GVirConfigDomainCpuPrivate))

missing s/CAPABILITIES/DOMAIN throughout this file

> +
> +struct _GVirConfigDomainCpuPrivate
> +{
> +    gboolean unused;
> +};
> +
> +G_DEFINE_TYPE(GVirConfigDomainCpu, gvir_config_domain_cpu, GVIR_CONFIG_TYPE_CAPABILITIES_CPU);
> +
> +GList *
> +_gvir_config_domain_cpu_get_features(GVirConfigCapabilitiesCpu *cpu);
> +
> +static void gvir_config_domain_cpu_class_init(GVirConfigDomainCpuClass *klass)
> +{
> +    GVirConfigCapabilitiesCpuClass *capabilities_class;
> +
> +    capabilities_class = GVIR_CONFIG_CAPABILITIES_CPU_CLASS(klass);
> +    capabilities_class->get_features = _gvir_config_domain_cpu_get_features;
> +
> +    g_type_class_add_private(klass, sizeof(GVirConfigDomainCpuPrivate));
> +}
> +
> +static void gvir_config_domain_cpu_init(GVirConfigDomainCpu *cpu)
> +{
> +    g_debug("Init GVirConfigDomainCpu=%p", cpu);
> +
> +    cpu->priv = GVIR_CONFIG_CAPABILITIES_CPU_GET_PRIVATE(cpu);
> +}
> +
> +GVirConfigDomainCpu *gvir_config_domain_cpu_new(void)
> +{
> +    GVirConfigObject *object;
> +
> +    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_CPU, "cpu", NULL);
> +
> +    return GVIR_CONFIG_DOMAIN_CPU(object);
> +}
> +
> +GVirConfigDomainCpu *gvir_config_domain_cpu_new_from_xml(const gchar *xml,
> +                                                         GError **error)
> +{
> +    GVirConfigObject *object;
> +
> +    object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_CPU,
> +                                             "cpu",
> +                                             NULL,
> +                                             xml,
> +                                             error);
> +
> +    return GVIR_CONFIG_DOMAIN_CPU(object);
> +}
> +
> +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_DOMAIN_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;
> +}
> +
> +GList *

static GList * ...

> +_gvir_config_domain_cpu_get_features(GVirConfigCapabilitiesCpu *cpu)
> +{
> +    struct GetFeatureData data;
> +
> +    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_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;
> +}
> +
> +GVirConfigDomainCpuMatchPolicy
> +gvir_config_domain_cpu_get_match_policy(GVirConfigDomainCpu *cpu)
> +{
> +    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_CPU(cpu),
> +                         GVIR_CONFIG_DOMAIN_CPU_MATCH_POLICY_EXACT);
> +
> +    return gvir_config_object_get_attribute_genum
> +                (GVIR_CONFIG_OBJECT(cpu),
> +                 NULL,
> +                 "match",
> +                 GVIR_CONFIG_TYPE_DOMAIN_CPU_MATCH_POLICY,
> +                 GVIR_CONFIG_DOMAIN_CPU_MATCH_POLICY_EXACT);
> +}
> +
> +void gvir_config_domain_cpu_set_match_policy(GVirConfigDomainCpu *cpu,
> +                                             GVirConfigDomainCpuMatchPolicy policy)
> +{
> +    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CPU(cpu));
> +
> +    gvir_config_object_set_attribute_with_type
> +                (GVIR_CONFIG_OBJECT(cpu),
> +                 "match", GVIR_CONFIG_TYPE_DOMAIN_CPU_MATCH_POLICY, policy,
> +                 NULL);
> +}
> +
> +GVirConfigDomainCpuMode
> +gvir_config_domain_cpu_get_mode(GVirConfigDomainCpu *cpu)
> +{
> +    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_CPU(cpu),
> +                         GVIR_CONFIG_DOMAIN_CPU_MODE_CUSTOM);
> +
> +    return gvir_config_object_get_attribute_genum
> +                (GVIR_CONFIG_OBJECT(cpu),
> +                 NULL,
> +                 "mode",
> +                 GVIR_CONFIG_TYPE_DOMAIN_CPU_MODE,
> +                 GVIR_CONFIG_DOMAIN_CPU_MODE_CUSTOM);
> +}
> +
> +void gvir_config_domain_cpu_set_mode(GVirConfigDomainCpu *cpu,
> +                                     GVirConfigDomainCpuMode mode)
> +{
> +    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_CPU(cpu));
> +
> +    gvir_config_object_set_attribute_with_type
> +                (GVIR_CONFIG_OBJECT(cpu),
> +                 "mode", GVIR_CONFIG_TYPE_DOMAIN_CPU_MODE, mode,
> +                 NULL);
> +}
> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-cpu.h b/libvirt-gconfig/libvirt-gconfig-domain-cpu.h
> new file mode 100644
> index 0000000..0b14975
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-domain-cpu.h
> @@ -0,0 +1,88 @@
> +/*
> + * libvirt-gconfig-domain-cpu.h: libvirt Domain CPU
> + *
> + * Copyright (C) 2010-2012 Red Hat, Inc.
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
> + *
> + * Authors: Zeeshan Ali <zeenix@xxxxxxxxxx>
> + *          Daniel P. Berrange <berrange@xxxxxxxxxx>
> + */
> +
> +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
> +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
> +#endif
> +
> +#ifndef __LIBVIRT_GCONFIG_DOMAIN_CPU_H__
> +#define __LIBVIRT_GCONFIG_DOMAIN_CPU_H__
> +
> +G_BEGIN_DECLS
> +
> +#define GVIR_CONFIG_TYPE_DOMAIN_CPU            (gvir_config_domain_cpu_get_type ())
> +#define GVIR_CONFIG_DOMAIN_CPU(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_CPU, GVirConfigDomainCpu))
> +#define GVIR_CONFIG_DOMAIN_CPU_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_CPU, GVirConfigDomainCpuClass))
> +#define GVIR_CONFIG_IS_DOMAIN_CPU(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_CPU))
> +#define GVIR_CONFIG_IS_DOMAIN_CPU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_CPU))
> +#define GVIR_CONFIG_DOMAIN_CPU_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_CPU, GVirConfigDomainCpuClass))
> +
> +typedef struct _GVirConfigDomainCpu GVirConfigDomainCpu;
> +typedef struct _GVirConfigDomainCpuPrivate GVirConfigDomainCpuPrivate;
> +typedef struct _GVirConfigDomainCpuClass GVirConfigDomainCpuClass;
> +
> +struct _GVirConfigDomainCpu
> +{
> +    GVirConfigCapabilitiesCpu parent;
> +
> +    GVirConfigDomainCpuPrivate *priv;
> +
> +    /* Do not add fields to this struct */
> +};
> +
> +struct _GVirConfigDomainCpuClass
> +{
> +    GVirConfigCapabilitiesCpuClass parent_class;
> +
> +    gpointer padding[20];
> +};
> +
> +typedef enum {
> +    GVIR_CONFIG_DOMAIN_CPU_MATCH_POLICY_MINIMUM,
> +    GVIR_CONFIG_DOMAIN_CPU_MATCH_POLICY_EXACT,
> +    GVIR_CONFIG_DOMAIN_CPU_MATCH_POLICY_STRICT
> +} GVirConfigDomainCpuMatchPolicy;
> +
> +typedef enum {
> +    GVIR_CONFIG_DOMAIN_CPU_MODE_CUSTOM,
> +    GVIR_CONFIG_DOMAIN_CPU_MODE_HOST_MODEL,
> +    GVIR_CONFIG_DOMAIN_CPU_MODE_HOST_PASSTHROUGH
> +} GVirConfigDomainCpuMode;
> +
> +GType gvir_config_domain_cpu_get_type(void);
> +GVirConfigDomainCpu *gvir_config_domain_cpu_new(void);
> +GVirConfigDomainCpu *gvir_config_domain_cpu_new_from_xml(const gchar *xml,
> +                                                         GError **error);
> +void
> +gvir_config_domain_cpu_set_match_policy(GVirConfigDomainCpu *cpu,
> +                                        GVirConfigDomainCpuMatchPolicy policy);
> +GVirConfigDomainCpuMatchPolicy
> +gvir_config_domain_cpu_get_match_policy(GVirConfigDomainCpu *cpu);
> +void gvir_config_domain_cpu_set_mode(GVirConfigDomainCpu *cpu,
> +                                     GVirConfigDomainCpuMode mode);
> +GVirConfigDomainCpuMode
> +gvir_config_domain_cpu_get_mode(GVirConfigDomainCpu *cpu);
> +
> +G_END_DECLS
> +
> +#endif /* __LIBVIRT_GCONFIG_DOMAIN_CPU_H__ */
> diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c b/libvirt-gconfig/libvirt-gconfig-domain.c
> index fcb3172..2ca478f 100644
> --- a/libvirt-gconfig/libvirt-gconfig-domain.c
> +++ b/libvirt-gconfig/libvirt-gconfig-domain.c
> @@ -632,3 +632,41 @@ gchar *gvir_config_domain_get_custom_xml(GVirConfigDomain *domain,
>                                       lookup_namespaced_node, &data);
>      return gvir_config_xml_node_to_string(data.node);
>  }
> +
> +/**
> + * gvir_config_domain_get_cpu:
> + * @domain: a #GVirConfigDomain
> + *
> + * Gets the CPU configuration of @domain
> + *
> + * Returns: (transfer full): A #GVirConfigDomainCpu. The returned object
> + * should be unreffed with g_object_unref() when no longer needed.
> + */
> +GVirConfigDomainCpu *gvir_config_domain_get_cpu(GVirConfigDomain *domain)
> +{
> +    GVirConfigObject *object;
> +
> +    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN(domain), NULL);
> +
> +    object = gvir_config_object_get_child_with_type(GVIR_CONFIG_OBJECT(domain),
> +                                                    "cpu",
> +                                                    GVIR_CONFIG_TYPE_DOMAIN_CPU);
> +
> +    return GVIR_CONFIG_DOMAIN_CPU(object);
> +}
> +
> +/**
> + * gvir_config_domain_set_cpu:
> + * @domain: a #GVirConfigDomain
> + * @cpu: (allow-none):
> + */
> +void gvir_config_domain_set_cpu(GVirConfigDomain *domain,
> +                                GVirConfigDomainCpu *cpu)
> +{
> +    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN(domain));
> +    g_return_if_fail(cpu != NULL || GVIR_CONFIG_IS_DOMAIN_CPU(cpu));
> +
> +    gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(domain),
> +                                      "cpu",
> +                                      GVIR_CONFIG_OBJECT(cpu));
> +}
> diff --git a/libvirt-gconfig/libvirt-gconfig-domain.h b/libvirt-gconfig/libvirt-gconfig-domain.h
> index af8b86a..b9a0dce 100644
> --- a/libvirt-gconfig/libvirt-gconfig-domain.h
> +++ b/libvirt-gconfig/libvirt-gconfig-domain.h
> @@ -31,6 +31,7 @@
>  #include <libvirt-gconfig/libvirt-gconfig-domain-os.h>
>  #include <libvirt-gconfig/libvirt-gconfig-domain-device.h>
>  #include <libvirt-gconfig/libvirt-gconfig-domain-seclabel.h>
> +#include <libvirt-gconfig/libvirt-gconfig-domain-cpu.h>
>  
>  G_BEGIN_DECLS
>  
> @@ -137,6 +138,9 @@ gboolean gvir_config_domain_set_custom_xml(GVirConfigDomain *domain,
>                                             GError **error);
>  gchar *gvir_config_domain_get_custom_xml(GVirConfigDomain *domain,
>                                           const gchar *ns_uri);
> +GVirConfigDomainCpu *gvir_config_domain_get_cpu(GVirConfigDomain *domain);
> +void gvir_config_domain_set_cpu(GVirConfigDomain *domain,
> +                                GVirConfigDomainCpu *cpu);
>  
>  G_END_DECLS
>  
> diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h
> index 41c3d80..4b5ccbd 100644
> --- a/libvirt-gconfig/libvirt-gconfig.h
> +++ b/libvirt-gconfig/libvirt-gconfig.h
> @@ -50,6 +50,7 @@
>  #include <libvirt-gconfig/libvirt-gconfig-domain-console.h>
>  #include <libvirt-gconfig/libvirt-gconfig-domain-controller.h>
>  #include <libvirt-gconfig/libvirt-gconfig-domain-controller-usb.h>
> +#include <libvirt-gconfig/libvirt-gconfig-domain-cpu.h>
>  #include <libvirt-gconfig/libvirt-gconfig-domain-cpu-feature.h>
>  #include <libvirt-gconfig/libvirt-gconfig-domain-device.h>
>  #include <libvirt-gconfig/libvirt-gconfig-domain-disk.h>
> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
> index fb93931..7eb0971 100644
> --- a/libvirt-gconfig/libvirt-gconfig.sym
> +++ b/libvirt-gconfig/libvirt-gconfig.sym
> @@ -380,6 +380,8 @@ LIBVIRT_GCONFIG_0.0.9 {
>  	gvir_config_domain_get_title;
>  	gvir_config_domain_set_title;
>  	gvir_config_domain_get_virt_type;
> +	gvir_config_domain_get_cpu;
> +	gvir_config_domain_set_cpu;
>  
>  	gvir_config_domain_os_get_arch;
>  	gvir_config_domain_os_get_boot_devices;
> @@ -430,6 +432,17 @@ LIBVIRT_GCONFIG_0.0.9 {
>  	gvir_config_capabilities_host_get_uuid;
>  	gvir_config_capabilities_host_get_cpu;
>  
> +	gvir_config_domain_cpu_get_type;
> +	gvir_config_domain_cpu_match_policy_get_type;
> +	gvir_config_domain_cpu_mode_get_type;
> +	gvir_config_domain_cpu_get_features;
> +	gvir_config_domain_cpu_get_match_policy;
> +	gvir_config_domain_cpu_set_match_policy;
> +	gvir_config_domain_cpu_get_mode;
> +	gvir_config_domain_cpu_set_mode;
> +	gvir_config_domain_cpu_new;
> +	gvir_config_domain_cpu_new_from_xml;
> +
>  	gvir_config_domain_cpu_feature_get_type;
>  	gvir_config_domain_cpu_feature_policy_get_type;
>  	gvir_config_domain_cpu_feature_get_policy;
> -- 
> 1.7.10.4
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

Attachment: pgp9g2ZSSj2hX.pgp
Description: PGP signature

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

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