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

Re: [libvirt] [libvirt-glib 1/4] Add GVirConfigDomainDiskDriver



On Fri, Dec 6, 2013 at 11:13 AM, Christophe Fergeau <cfergeau redhat com> wrote:
> This class wraps creation of configuration data for the driver part of a
> domain disk device. The methods needed for this are currently part of
> GVirConfigDomainDisk, but since the disk driver is getting more and more
> attributes, it's better to move such configuration to a dedicated class to
> avoid a too big API in GVirConfigDomainDisk
> ---
>  libvirt-gconfig/Makefile.am                        |   2 +
>  .../libvirt-gconfig-domain-disk-driver.c           | 244 +++++++++++++++++++++
>  .../libvirt-gconfig-domain-disk-driver.h           | 116 ++++++++++
>  libvirt-gconfig/libvirt-gconfig-domain-disk.c      |   3 +
>  libvirt-gconfig/libvirt-gconfig.h                  |   1 +
>  libvirt-gconfig/libvirt-gconfig.sym                |  21 ++
>  6 files changed, 387 insertions(+)
>  create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-disk-driver.c
>  create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-disk-driver.h
>
> diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am
> index 0793da1..7550afe 100644
> --- a/libvirt-gconfig/Makefile.am
> +++ b/libvirt-gconfig/Makefile.am
> @@ -37,6 +37,7 @@ GCONFIG_HEADER_FILES = \
>                         libvirt-gconfig-domain-cpu-feature.h \
>                         libvirt-gconfig-domain-device.h \
>                         libvirt-gconfig-domain-disk.h \
> +                       libvirt-gconfig-domain-disk-driver.h \
>                         libvirt-gconfig-domain-filesys.h \
>                         libvirt-gconfig-domain-graphics.h \
>                         libvirt-gconfig-domain-graphics-desktop.h \
> @@ -121,6 +122,7 @@ GCONFIG_SOURCE_FILES = \
>                         libvirt-gconfig-domain-cpu-feature.c \
>                         libvirt-gconfig-domain-device.c \
>                         libvirt-gconfig-domain-disk.c \
> +                       libvirt-gconfig-domain-disk-driver.c \
>                         libvirt-gconfig-domain-filesys.c \
>                         libvirt-gconfig-domain-graphics.c \
>                         libvirt-gconfig-domain-graphics-desktop.c \
> diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk-driver.c b/libvirt-gconfig/libvirt-gconfig-domain-disk-driver.c
> new file mode 100644
> index 0000000..ddf7ce2
> --- /dev/null
> +++ b/libvirt-gconfig/libvirt-gconfig-domain-disk-driver.c
> @@ -0,0 +1,244 @@
> +/*
> + * libvirt-gconfig-domain-disk-driver.c: libvirt domain disk driver configuration
> + *
> + * Copyright (C) 2011, 2013 Red Hat, Inc.
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library. If not, see
> + * <http://www.gnu.org/licenses/>.
> + *
> + * Author: Christophe Fergeau <cfergeau redhat com>
> + */
> +
> +#include <config.h>
> +
> +#include "libvirt-gconfig/libvirt-gconfig.h"
> +#include "libvirt-gconfig/libvirt-gconfig-private.h"
> +
> +#define GVIR_CONFIG_DOMAIN_DISK_DRIVER_GET_PRIVATE(obj)                         \
> +        (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER, GVirConfigDomainDiskDriverPrivate))
> +
> +struct _GVirConfigDomainDiskDriverPrivate
> +{
> +    gboolean unused;
> +};
> +
> +G_DEFINE_TYPE(GVirConfigDomainDiskDriver, gvir_config_domain_disk_driver, GVIR_CONFIG_TYPE_OBJECT);
> +
> +
> +static void gvir_config_domain_disk_driver_class_init(GVirConfigDomainDiskDriverClass *klass)
> +{
> +    g_type_class_add_private(klass, sizeof(GVirConfigDomainDiskDriverPrivate));
> +}
> +
> +
> +static void gvir_config_domain_disk_driver_init(GVirConfigDomainDiskDriver *driver)
> +{
> +    g_debug("Init GVirConfigDomainDiskDriver=%p", driver);
> +
> +    driver->priv = GVIR_CONFIG_DOMAIN_DISK_DRIVER_GET_PRIVATE(driver);
> +}
> +
> +
> +GVirConfigDomainDiskDriver *gvir_config_domain_disk_driver_new(void)
> +{
> +    GVirConfigObject *object;
> +
> +    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER,
> +                                    "driver", NULL);
> +    return GVIR_CONFIG_DOMAIN_DISK_DRIVER(object);
> +}
> +
> +GVirConfigDomainDiskDriver *gvir_config_domain_disk_driver_new_from_xml(const gchar *xml,
> +                                                                        GError **error)
> +{
> +    GVirConfigObject *object;
> +
> +    object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER,
> +                                             "driver", NULL, xml, error);
> +    return GVIR_CONFIG_DOMAIN_DISK_DRIVER(object);
> +}
> +
> +
> +void gvir_config_domain_disk_driver_set_cache(GVirConfigDomainDiskDriver *driver,
> +                                              GVirConfigDomainDiskCacheType cache_type)
> +{
> +    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(driver));
> +
> +    gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(driver),
> +                                               "cache",
> +                                               GVIR_CONFIG_TYPE_DOMAIN_DISK_CACHE_TYPE,
> +                                               cache_type,
> +                                               NULL);
> +}
> +
> +
> +GVirConfigDomainDiskCacheType gvir_config_domain_disk_driver_get_cache(GVirConfigDomainDiskDriver *driver)
> +{
> +    g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(driver),
> +                         GVIR_CONFIG_DOMAIN_DISK_CACHE_DEFAULT);
> +
> +    return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(driver),
> +                                                  NULL, "cache",
> +                                                  GVIR_CONFIG_TYPE_DOMAIN_DISK_CACHE_TYPE,
> +                                                  GVIR_CONFIG_DOMAIN_DISK_CACHE_DEFAULT);
> +}
> +
> +
> +void gvir_config_domain_disk_driver_set_name(GVirConfigDomainDiskDriver *driver,
> +                                             const char *name)

Since libvirt support only specific drivers and they are identified by
name, I'd suggest this be an enum.

Rest of the patch looks good.


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