[libvirt] Add GVirConfigDomainDiskDriver

Hey, I wanted to add support in libvirt-gconfig for the 'discard' attribute of the disk driver node. If I follow the way the API is currently done, it would be an additional method to GVirConfigDomainDisk. However, there are quite a few attributes attached to the disk driver node, so I felt it was preferrable to have a dedicated GVirConfigDomainDiskDriver class. This also matches better other places of libvirt-gconfig API. I've implemented support for most of the attributes of the disk driver node, as a result the corresponding methods in GVirConfigDomainDisk have been deprecated. Christophe

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) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(driver)); + + gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(driver), + "name", name, NULL); +} + + +const char *gvir_config_domain_disk_driver_get_name(GVirConfigDomainDiskDriver *driver) + +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(driver), NULL); + + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(driver), + NULL, "name"); +} + + +void gvir_config_domain_disk_driver_set_error_policy(GVirConfigDomainDiskDriver *driver, + GVirConfigDomainDiskDriverErrorPolicy policy) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(driver)); + + gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(driver), + "error_policy", + GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER_ERROR_POLICY, + policy, + NULL); +} + + +GVirConfigDomainDiskDriverErrorPolicy gvir_config_domain_disk_driver_get_error_policy(GVirConfigDomainDiskDriver *driver) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(driver), + GVIR_CONFIG_DOMAIN_DISK_DRIVER_ERROR_POLICY_REPORT); + + return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(driver), + NULL, "error_policy", + GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER_ERROR_POLICY, + GVIR_CONFIG_DOMAIN_DISK_DRIVER_ERROR_POLICY_REPORT); +} + + +void gvir_config_domain_disk_driver_set_format(GVirConfigDomainDiskDriver *driver, + GVirConfigDomainDiskFormat format) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(driver)); + + gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(driver), + "type", + GVIR_CONFIG_TYPE_DOMAIN_DISK_FORMAT, + format, + NULL); +} + + +GVirConfigDomainDiskFormat gvir_config_domain_disk_driver_get_format(GVirConfigDomainDiskDriver *driver) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(driver), + GVIR_CONFIG_DOMAIN_DISK_FORMAT_RAW); + + return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(driver), + NULL, "type", + GVIR_CONFIG_TYPE_DOMAIN_DISK_FORMAT, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_RAW); +} + + +void gvir_config_domain_disk_driver_set_io_policy(GVirConfigDomainDiskDriver *driver, + GVirConfigDomainDiskDriverIoPolicy policy) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(driver)); + + gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(driver), + "io", + GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER_IO_POLICY, + policy, + NULL); +} + + +GVirConfigDomainDiskDriverIoPolicy gvir_config_domain_disk_driver_get_io_policy(GVirConfigDomainDiskDriver *driver) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(driver), + GVIR_CONFIG_DOMAIN_DISK_DRIVER_IO_POLICY_THREADS); + + return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(driver), + NULL, "io", + GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER_IO_POLICY, + GVIR_CONFIG_DOMAIN_DISK_DRIVER_IO_POLICY_THREADS); +} + + +void gvir_config_domain_disk_driver_set_copy_on_read(GVirConfigDomainDiskDriver *driver, + gboolean copy_on_read) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(driver)); + + /* gvir_config_object_set_attribute_with_type(..., G_TYPE_BOOLEAN, ...) + * cannot be used here as it translates into "yes"/"no", but what we + * want is "on"/"off" + */ + gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(driver), + "copy_on_read", + copy_on_read?"on":"off", + NULL); +} + + +gboolean gvir_config_domain_disk_driver_get_copy_on_read(GVirConfigDomainDiskDriver *driver) +{ + const char *copy_on_read; + + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(driver), FALSE); + + copy_on_read = gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(driver), + NULL, "copy_on_read"); + + return (g_strcmp0(copy_on_read, "on") == 0); +} + + +void gvir_config_domain_disk_driver_set_discard(GVirConfigDomainDiskDriver *driver, + GVirConfigDomainDiskDriverDiscard discard) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(driver)); + + gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(driver), + "discard", + GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER_DISCARD, + discard, + NULL); +} + + +GVirConfigDomainDiskDriverDiscard gvir_config_domain_disk_driver_get_discard(GVirConfigDomainDiskDriver *driver) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(driver), + GVIR_CONFIG_DOMAIN_DISK_DRIVER_DISCARD_IGNORE); + + return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(driver), + NULL, "discard", + GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER_DISCARD, + GVIR_CONFIG_DOMAIN_DISK_DRIVER_DISCARD_IGNORE); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk-driver.h b/libvirt-gconfig/libvirt-gconfig-domain-disk-driver.h new file mode 100644 index 0000000..5ad7089 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-disk-driver.h @@ -0,0 +1,116 @@ +/* + * libvirt-gconfig-domain-disk-driver.h: libvirt 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> + */ + +#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_DISK_DRIVER_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_DISK_DRIVER_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER (gvir_config_domain_disk_driver_get_type ()) +#define GVIR_CONFIG_DOMAIN_DISK_DRIVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER, GVirConfigDomainDiskDriver)) +#define GVIR_CONFIG_DOMAIN_DISK_DRIVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER, GVirConfigDomainDiskDriverClass)) +#define GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER)) +#define GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER)) +#define GVIR_CONFIG_DOMAIN_DISK_DRIVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER, GVirConfigDomainDiskDriverClass)) + +typedef struct _GVirConfigDomainDiskDriver GVirConfigDomainDiskDriver; +typedef struct _GVirConfigDomainDiskDriverPrivate GVirConfigDomainDiskDriverPrivate; +typedef struct _GVirConfigDomainDiskDriverClass GVirConfigDomainDiskDriverClass; + +struct _GVirConfigDomainDiskDriver +{ + GVirConfigObject parent; + + GVirConfigDomainDiskDriverPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainDiskDriverClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + + +typedef enum { + GVIR_CONFIG_DOMAIN_DISK_DRIVER_ERROR_POLICY_STOP, + GVIR_CONFIG_DOMAIN_DISK_DRIVER_ERROR_POLICY_REPORT, + GVIR_CONFIG_DOMAIN_DISK_DRIVER_ERROR_POLICY_IGNORE, + GVIR_CONFIG_DOMAIN_DISK_DRIVER_ERROR_POLICY_ENOSPACE +} GVirConfigDomainDiskDriverErrorPolicy; + + +typedef enum { + GVIR_CONFIG_DOMAIN_DISK_DRIVER_IO_POLICY_THREADS, + GVIR_CONFIG_DOMAIN_DISK_DRIVER_IO_POLICY_NATIVE +} GVirConfigDomainDiskDriverIoPolicy; + + +typedef enum { + GVIR_CONFIG_DOMAIN_DISK_DRIVER_DISCARD_UNMAP, + GVIR_CONFIG_DOMAIN_DISK_DRIVER_DISCARD_IGNORE +} GVirConfigDomainDiskDriverDiscard; + + +GType gvir_config_domain_disk_driver_get_type(void); + +GVirConfigDomainDiskDriver *gvir_config_domain_disk_driver_new(void); +GVirConfigDomainDiskDriver *gvir_config_domain_disk_driver_new_from_xml(const gchar *xml, + GError **error); + +void gvir_config_domain_disk_driver_set_cache(GVirConfigDomainDiskDriver *driver, + GVirConfigDomainDiskCacheType cache_type); +GVirConfigDomainDiskCacheType gvir_config_domain_disk_driver_get_cache(GVirConfigDomainDiskDriver *driver); + +void gvir_config_domain_disk_driver_set_name(GVirConfigDomainDiskDriver *driver, + const char *name); +const char *gvir_config_domain_disk_driver_get_name(GVirConfigDomainDiskDriver *driver); + +void gvir_config_domain_disk_driver_set_error_policy(GVirConfigDomainDiskDriver *driver, + GVirConfigDomainDiskDriverErrorPolicy policy); +GVirConfigDomainDiskDriverErrorPolicy gvir_config_domain_disk_driver_get_error_policy(GVirConfigDomainDiskDriver *driver); + +void gvir_config_domain_disk_driver_set_format(GVirConfigDomainDiskDriver *driver, + GVirConfigDomainDiskFormat format); +GVirConfigDomainDiskFormat gvir_config_domain_disk_driver_get_format(GVirConfigDomainDiskDriver *driver); + +void gvir_config_domain_disk_driver_set_io_policy(GVirConfigDomainDiskDriver *driver, + GVirConfigDomainDiskDriverIoPolicy policy); +GVirConfigDomainDiskDriverIoPolicy gvir_config_domain_disk_driver_get_io_policy(GVirConfigDomainDiskDriver *driver); + +void gvir_config_domain_disk_driver_set_copy_on_read(GVirConfigDomainDiskDriver *driver, + gboolean copy_on_read); +gboolean gvir_config_domain_disk_driver_get_copy_on_read(GVirConfigDomainDiskDriver *driver); + +void gvir_config_domain_disk_driver_set_discard(GVirConfigDomainDiskDriver *driver, + GVirConfigDomainDiskDriverDiscard discard); +GVirConfigDomainDiskDriverDiscard gvir_config_domain_disk_driver_get_discard(GVirConfigDomainDiskDriver *driver); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_DISK_DRIVER_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-disk.c index 4f85262..db0416a 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-disk.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.c @@ -353,6 +353,7 @@ gvir_config_domain_disk_get_driver_cache(GVirConfigDomainDisk *disk) GVIR_CONFIG_DOMAIN_DISK_CACHE_DEFAULT); } + GVirConfigDomainDiskBus gvir_config_domain_disk_get_target_bus(GVirConfigDomainDisk *disk) { @@ -368,6 +369,7 @@ gvir_config_domain_disk_get_target_bus(GVirConfigDomainDisk *disk) GVIR_CONFIG_DOMAIN_DISK_BUS_IDE); } + const char * gvir_config_domain_disk_get_target_dev(GVirConfigDomainDisk *disk) { @@ -377,6 +379,7 @@ gvir_config_domain_disk_get_target_dev(GVirConfigDomainDisk *disk) "target", "dev"); } + void gvir_config_domain_disk_set_readonly(GVirConfigDomainDisk *disk, gboolean readonly) diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index af80241..10f7b0f 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -54,6 +54,7 @@ #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> +#include <libvirt-gconfig/libvirt-gconfig-domain-disk-driver.h> #include <libvirt-gconfig/libvirt-gconfig-domain-filesys.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics.h> #include <libvirt-gconfig/libvirt-gconfig-domain-graphics-desktop.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index a5f8b05..9224426 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -604,6 +604,27 @@ global: gvir_config_domain_get_uuid; gvir_config_domain_set_uuid; + gvir_config_domain_disk_driver_get_type; + gvir_config_domain_disk_driver_discard_get_type; + gvir_config_domain_disk_driver_error_policy_get_type; + gvir_config_domain_disk_driver_io_policy_get_type; + gvir_config_domain_disk_driver_new; + gvir_config_domain_disk_driver_new_from_xml; + gvir_config_domain_disk_driver_set_cache; + gvir_config_domain_disk_driver_get_cache; + gvir_config_domain_disk_driver_set_copy_on_read; + gvir_config_domain_disk_driver_get_copy_on_read; + gvir_config_domain_disk_driver_set_discard; + gvir_config_domain_disk_driver_get_discard; + gvir_config_domain_disk_driver_set_error_policy; + gvir_config_domain_disk_driver_get_error_policy; + gvir_config_domain_disk_driver_set_format; + gvir_config_domain_disk_driver_get_format; + gvir_config_domain_disk_driver_set_name; + gvir_config_domain_disk_driver_get_name; + gvir_config_domain_disk_driver_set_io_policy; + gvir_config_domain_disk_driver_get_io_policy; + gvir_config_domain_graphics_rdp_set_multi_user; gvir_config_domain_graphics_rdp_set_replace_user; -- 1.8.4.2

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.

On Thu, Jan 16, 2014 at 07:44:56PM +0000, Zeeshan Ali (Khattak) wrote:
+ +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.
We generally use enums in libvirt-gconfig when libvirt stores the value as an enum. In this case it's stored as a string in domain_conf.c, and it's defined as a string in domaincommon.rng, so it's better to stick with a const char * in libvirt-glib too. Christophe

--- libvirt-gconfig/libvirt-gconfig-domain-disk.c | 42 +++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-disk.h | 58 +++++++++++++++------------ libvirt-gconfig/libvirt-gconfig.sym | 3 ++ 3 files changed, 77 insertions(+), 26 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-disk.c index db0416a..85d2bea 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-disk.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.c @@ -390,3 +390,45 @@ gvir_config_domain_disk_set_readonly(GVirConfigDomainDisk *disk, } else gvir_config_object_delete_child(GVIR_CONFIG_OBJECT(disk), "readonly", NULL); } + + +/** + * gvir_config_domain_disk_set_driver: + * @disk: a #GVirConfigDomainDisk + * @driver: (allow-none): a #GVirConfigDomainDiskDriver + * + * Uses @driver as the driver configuration for @disk. + */ +void gvir_config_domain_disk_set_driver(GVirConfigDomainDisk *disk, + GVirConfigDomainDiskDriver *driver) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk)); + g_return_if_fail(driver == NULL || GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(driver)); + + gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(disk), + "driver", + GVIR_CONFIG_OBJECT(driver)); +} + + +/** + * gvir_config_domain_disk_get_driver: + * @disk: a #GVirConfigDomainDisk + * + * Gets the driver configuration for @disk. + * + * Returns: (transfer full): A #GVirConfigDomainDiskDriver. The returned + * object should be unreffed with g_object_unref() when no longer needed. + */ +GVirConfigDomainDiskDriver *gvir_config_domain_disk_get_driver(GVirConfigDomainDisk *disk) +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk), NULL); + + object = gvir_config_object_get_child_with_type(GVIR_CONFIG_OBJECT(disk), + "driver", + GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER); + + return GVIR_CONFIG_DOMAIN_DISK_DRIVER(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.h b/libvirt-gconfig/libvirt-gconfig-domain-disk.h index 3b82eb5..a28f243 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-disk.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.h @@ -29,6 +29,35 @@ G_BEGIN_DECLS +/* These enum definitions are needed by libvirt-gconfig-domain-disk-driver.h */ +typedef enum { + GVIR_CONFIG_DOMAIN_DISK_CACHE_DEFAULT, + GVIR_CONFIG_DOMAIN_DISK_CACHE_NONE, + GVIR_CONFIG_DOMAIN_DISK_CACHE_WRITETHROUGH, + GVIR_CONFIG_DOMAIN_DISK_CACHE_WRITEBACK, + GVIR_CONFIG_DOMAIN_DISK_CACHE_DIRECTSYNC, + GVIR_CONFIG_DOMAIN_DISK_CACHE_UNSAFE +} GVirConfigDomainDiskCacheType; + +typedef enum { + GVIR_CONFIG_DOMAIN_DISK_FORMAT_RAW, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_DIR, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_BOCHS, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_CLOOP, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_COW, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_DMG, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_ISO, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_QCOW, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_QCOW2, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_QED, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_VMDK, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_VPC, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_FAT, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_VHD, +} GVirConfigDomainDiskFormat; + +#include <libvirt-gconfig/libvirt-gconfig-domain-disk-driver.h> + #define GVIR_CONFIG_TYPE_DOMAIN_DISK (gvir_config_domain_disk_get_type ()) #define GVIR_CONFIG_DOMAIN_DISK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_DISK, GVirConfigDomainDisk)) #define GVIR_CONFIG_DOMAIN_DISK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_DISK, GVirConfigDomainDiskClass)) @@ -75,15 +104,6 @@ typedef enum { } GVirConfigDomainDiskBus; typedef enum { - GVIR_CONFIG_DOMAIN_DISK_CACHE_DEFAULT, - GVIR_CONFIG_DOMAIN_DISK_CACHE_NONE, - GVIR_CONFIG_DOMAIN_DISK_CACHE_WRITETHROUGH, - GVIR_CONFIG_DOMAIN_DISK_CACHE_WRITEBACK, - GVIR_CONFIG_DOMAIN_DISK_CACHE_DIRECTSYNC, - GVIR_CONFIG_DOMAIN_DISK_CACHE_UNSAFE -} GVirConfigDomainDiskCacheType; - -typedef enum { GVIR_CONFIG_DOMAIN_DISK_GUEST_DEVICE_DISK, GVIR_CONFIG_DOMAIN_DISK_GUEST_DEVICE_FLOPPY, GVIR_CONFIG_DOMAIN_DISK_GUEST_DEVICE_CDROM @@ -101,23 +121,6 @@ typedef enum { GVIR_CONFIG_DOMAIN_DISK_STARTUP_POLICY_OPTIONAL } GVirConfigDomainDiskStartupPolicy; -typedef enum { - GVIR_CONFIG_DOMAIN_DISK_FORMAT_RAW, - GVIR_CONFIG_DOMAIN_DISK_FORMAT_DIR, - GVIR_CONFIG_DOMAIN_DISK_FORMAT_BOCHS, - GVIR_CONFIG_DOMAIN_DISK_FORMAT_CLOOP, - GVIR_CONFIG_DOMAIN_DISK_FORMAT_COW, - GVIR_CONFIG_DOMAIN_DISK_FORMAT_DMG, - GVIR_CONFIG_DOMAIN_DISK_FORMAT_ISO, - GVIR_CONFIG_DOMAIN_DISK_FORMAT_QCOW, - GVIR_CONFIG_DOMAIN_DISK_FORMAT_QCOW2, - GVIR_CONFIG_DOMAIN_DISK_FORMAT_QED, - GVIR_CONFIG_DOMAIN_DISK_FORMAT_VMDK, - GVIR_CONFIG_DOMAIN_DISK_FORMAT_VPC, - GVIR_CONFIG_DOMAIN_DISK_FORMAT_FAT, - GVIR_CONFIG_DOMAIN_DISK_FORMAT_VHD, -} GVirConfigDomainDiskFormat; - /* backward compatibility */ #define GVIR_CONFIG_DOMAIN_DISK_FORMAT_AIO GVIR_CONFIG_DOMAIN_DISK_FORMAT_RAW; @@ -150,6 +153,9 @@ void gvir_config_domain_disk_set_target_bus(GVirConfigDomainDisk *disk, GVirConfigDomainDiskBus bus); void gvir_config_domain_disk_set_target_dev(GVirConfigDomainDisk *disk, const char *dev); +void gvir_config_domain_disk_set_driver(GVirConfigDomainDisk *disk, + GVirConfigDomainDiskDriver *driver); +GVirConfigDomainDiskDriver *gvir_config_domain_disk_get_driver(GVirConfigDomainDisk *disk); GVirConfigDomainDiskType gvir_config_domain_disk_get_disk_type(GVirConfigDomainDisk *disk); GVirConfigDomainDiskGuestDeviceType gvir_config_domain_disk_get_guest_device_type(GVirConfigDomainDisk *disk); diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 9224426..b9164d4 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -625,6 +625,9 @@ global: gvir_config_domain_disk_driver_set_io_policy; gvir_config_domain_disk_driver_get_io_policy; + gvir_config_domain_disk_get_driver; + gvir_config_domain_disk_set_driver; + gvir_config_domain_graphics_rdp_set_multi_user; gvir_config_domain_graphics_rdp_set_replace_user; -- 1.8.4.2

On Fri, Dec 6, 2013 at 11:13 AM, Christophe Fergeau <cfergeau@redhat.com> wrote:
--- libvirt-gconfig/libvirt-gconfig-domain-disk.c | 42 +++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-disk.h | 58 +++++++++++++++------------ libvirt-gconfig/libvirt-gconfig.sym | 3 ++ 3 files changed, 77 insertions(+), 26 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-disk.c index db0416a..85d2bea 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-disk.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.c @@ -390,3 +390,45 @@ gvir_config_domain_disk_set_readonly(GVirConfigDomainDisk *disk, } else gvir_config_object_delete_child(GVIR_CONFIG_OBJECT(disk), "readonly", NULL); } + + +/** + * gvir_config_domain_disk_set_driver: + * @disk: a #GVirConfigDomainDisk + * @driver: (allow-none): a #GVirConfigDomainDiskDriver + * + * Uses @driver as the driver configuration for @disk. + */ +void gvir_config_domain_disk_set_driver(GVirConfigDomainDisk *disk, + GVirConfigDomainDiskDriver *driver) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk)); + g_return_if_fail(driver == NULL || GVIR_CONFIG_IS_DOMAIN_DISK_DRIVER(driver)); + + gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(disk), + "driver", + GVIR_CONFIG_OBJECT(driver)); +} + + +/** + * gvir_config_domain_disk_get_driver: + * @disk: a #GVirConfigDomainDisk + * + * Gets the driver configuration for @disk. + * + * Returns: (transfer full): A #GVirConfigDomainDiskDriver. The returned + * object should be unreffed with g_object_unref() when no longer needed. + */ +GVirConfigDomainDiskDriver *gvir_config_domain_disk_get_driver(GVirConfigDomainDisk *disk) +{ + GVirConfigObject *object; + + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk), NULL); + + object = gvir_config_object_get_child_with_type(GVIR_CONFIG_OBJECT(disk), + "driver", + GVIR_CONFIG_TYPE_DOMAIN_DISK_DRIVER); + + return GVIR_CONFIG_DOMAIN_DISK_DRIVER(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.h b/libvirt-gconfig/libvirt-gconfig-domain-disk.h index 3b82eb5..a28f243 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-disk.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.h @@ -29,6 +29,35 @@
G_BEGIN_DECLS
+/* These enum definitions are needed by libvirt-gconfig-domain-disk-driver.h */
Why not just move these enums to that header then?
+typedef enum { + GVIR_CONFIG_DOMAIN_DISK_CACHE_DEFAULT, + GVIR_CONFIG_DOMAIN_DISK_CACHE_NONE, + GVIR_CONFIG_DOMAIN_DISK_CACHE_WRITETHROUGH, + GVIR_CONFIG_DOMAIN_DISK_CACHE_WRITEBACK, + GVIR_CONFIG_DOMAIN_DISK_CACHE_DIRECTSYNC, + GVIR_CONFIG_DOMAIN_DISK_CACHE_UNSAFE +} GVirConfigDomainDiskCacheType; + +typedef enum { + GVIR_CONFIG_DOMAIN_DISK_FORMAT_RAW, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_DIR, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_BOCHS, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_CLOOP, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_COW, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_DMG, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_ISO, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_QCOW, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_QCOW2, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_QED, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_VMDK, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_VPC, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_FAT, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_VHD, +} GVirConfigDomainDiskFormat; +
Looks good otherwise.

On Thu, Jan 16, 2014 at 07:48:31PM +0000, Zeeshan Ali (Khattak) wrote:
On Fri, Dec 6, 2013 at 11:13 AM, Christophe Fergeau <cfergeau@redhat.com> wrote:
G_BEGIN_DECLS
+/* These enum definitions are needed by libvirt-gconfig-domain-disk-driver.h */
Why not just move these enums to that header then?
Inaccurate comment, I'll change it to "These enum definitions are also used by libvirt-gconfig-domain-disk-driver.h". The comment is meant to explain why the enums are defined before #include <libvirt-gconfig/libvirt-gconfig-domain-disk-driver.h> Christophe

On Fri, Jan 17, 2014 at 2:15 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
On Thu, Jan 16, 2014 at 07:48:31PM +0000, Zeeshan Ali (Khattak) wrote:
On Fri, Dec 6, 2013 at 11:13 AM, Christophe Fergeau <cfergeau@redhat.com> wrote:
G_BEGIN_DECLS
+/* These enum definitions are needed by libvirt-gconfig-domain-disk-driver.h */
Why not just move these enums to that header then?
Inaccurate comment, I'll change it to "These enum definitions are also used by libvirt-gconfig-domain-disk-driver.h". The comment is meant to explain why the enums are defined before #include <libvirt-gconfig/libvirt-gconfig-domain-disk-driver.h>
Yeah I understood. What I failed to explain was that these enums seem more appropiate in libvirt-gconfig-domain-disk-driver.h and since its being included here, you wont have to explain anything here or have anything to explain at all. -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Fri, Jan 17, 2014 at 02:27:02PM +0000, Zeeshan Ali (Khattak) wrote:
On Fri, Jan 17, 2014 at 2:15 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
On Thu, Jan 16, 2014 at 07:48:31PM +0000, Zeeshan Ali (Khattak) wrote:
On Fri, Dec 6, 2013 at 11:13 AM, Christophe Fergeau <cfergeau@redhat.com> wrote:
G_BEGIN_DECLS
+/* These enum definitions are needed by libvirt-gconfig-domain-disk-driver.h */
Why not just move these enums to that header then?
Inaccurate comment, I'll change it to "These enum definitions are also used by libvirt-gconfig-domain-disk-driver.h". The comment is meant to explain why the enums are defined before #include <libvirt-gconfig/libvirt-gconfig-domain-disk-driver.h>
Yeah I understood. What I failed to explain was that these enums seem more appropiate in libvirt-gconfig-domain-disk-driver.h and since its being included here, you wont have to explain anything here or have anything to explain at all.
Ah good point ;) The namespacing in the enum name would be slightly off, but probably better than the unusual layout in the .h file. Christophe

They are replaced by equivalent methods in GVirConfigDomainDiskDriver. Initially, we had only one or two attributes to set on the 'driver' child of the 'disk' node. Nowadays, we more than 5 attributes to set on this node, mapping it as a separate object is more consistent with the rest of libvirt-gconfig API. --- libvirt-gconfig/libvirt-gconfig-domain-disk.h | 10 ++++++++-- libvirt-gconfig/tests/test-domain-create.c | 23 +++++++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.h b/libvirt-gconfig/libvirt-gconfig-domain-disk.h index a28f243..686e0ec 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-disk.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.h @@ -140,13 +140,16 @@ void gvir_config_domain_disk_set_startup_policy(GVirConfigDomainDisk *disk, GVirConfigDomainDiskStartupPolicy policy); void gvir_config_domain_disk_set_source(GVirConfigDomainDisk *disk, const char *source); +G_DEPRECATED_FOR(gvir_config_domain_disk_driver_set_cache) void gvir_config_domain_disk_set_driver_cache(GVirConfigDomainDisk *disk, GVirConfigDomainDiskCacheType cache_type); +G_DEPRECATED_FOR(gvir_config_domain_disk_driver_set_name) void gvir_config_domain_disk_set_driver_name(GVirConfigDomainDisk *disk, const char *driver_name); -G_DEPRECATED_FOR(gvir_config_domain_disk_set_driver_format) +G_DEPRECATED_FOR(gvir_config_domain_disk_driver_set_format) void gvir_config_domain_disk_set_driver_type(GVirConfigDomainDisk *disk, const char *driver_type); +G_DEPRECATED_FOR(gvir_config_domain_disk_driver_set_format) void gvir_config_domain_disk_set_driver_format(GVirConfigDomainDisk *disk, GVirConfigDomainDiskFormat format); void gvir_config_domain_disk_set_target_bus(GVirConfigDomainDisk *disk, @@ -162,10 +165,13 @@ GVirConfigDomainDiskGuestDeviceType gvir_config_domain_disk_get_guest_device_typ GVirConfigDomainDiskSnapshotType gvir_config_domain_disk_get_snapshot_type(GVirConfigDomainDisk *disk); GVirConfigDomainDiskStartupPolicy gvir_config_domain_disk_get_startup_policy(GVirConfigDomainDisk *disk); const char *gvir_config_domain_disk_get_source(GVirConfigDomainDisk *disk); +G_DEPRECATED_FOR(gvir_config_domain_disk_driver_get_cache) GVirConfigDomainDiskCacheType gvir_config_domain_disk_get_driver_cache(GVirConfigDomainDisk *disk); +G_DEPRECATED_FOR(gvir_config_domain_disk_driver_get_name) const char *gvir_config_domain_disk_get_driver_name(GVirConfigDomainDisk *disk); -G_DEPRECATED_FOR(gvir_config_domain_disk_get_driver_format) +G_DEPRECATED_FOR(gvir_config_domain_disk_driver_get_format) const char *gvir_config_domain_disk_get_driver_type(GVirConfigDomainDisk *disk); +G_DEPRECATED_FOR(gvir_config_domain_disk_driver_get_format) GVirConfigDomainDiskFormat gvir_config_domain_disk_get_driver_format(GVirConfigDomainDisk *disk); GVirConfigDomainDiskBus gvir_config_domain_disk_get_target_bus(GVirConfigDomainDisk *disk); const char *gvir_config_domain_disk_get_target_dev(GVirConfigDomainDisk *disk); diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index ae0b248..b5c2cf3 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -233,28 +233,35 @@ int main(int argc, char **argv) /* disk node */ GVirConfigDomainDisk *disk; + GVirConfigDomainDiskDriver *driver; + + driver = gvir_config_domain_disk_driver_new(); + gvir_config_domain_disk_driver_set_name(driver, "foo"); + gvir_config_domain_disk_driver_set_format(driver, GVIR_CONFIG_DOMAIN_DISK_FORMAT_BOCHS); + gvir_config_domain_disk_driver_set_name(driver, "qemu"); + gvir_config_domain_disk_driver_set_cache(driver, GVIR_CONFIG_DOMAIN_DISK_CACHE_NONE); + gvir_config_domain_disk_driver_set_format(driver, GVIR_CONFIG_DOMAIN_DISK_FORMAT_QCOW2); disk = gvir_config_domain_disk_new(); gvir_config_domain_disk_set_type(disk, GVIR_CONFIG_DOMAIN_DISK_FILE); gvir_config_domain_disk_set_guest_device_type(disk, GVIR_CONFIG_DOMAIN_DISK_GUEST_DEVICE_DISK); gvir_config_domain_disk_set_source(disk, "/tmp/foo/bar"); gvir_config_domain_disk_set_startup_policy (disk, GVIR_CONFIG_DOMAIN_DISK_STARTUP_POLICY_REQUISITE); - gvir_config_domain_disk_set_driver_name(disk, "foo"); - gvir_config_domain_disk_set_driver_format(disk, GVIR_CONFIG_DOMAIN_DISK_FORMAT_BOCHS); - gvir_config_domain_disk_set_driver_name(disk, "qemu"); - gvir_config_domain_disk_set_driver_cache(disk, GVIR_CONFIG_DOMAIN_DISK_CACHE_NONE); - gvir_config_domain_disk_set_driver_format(disk, GVIR_CONFIG_DOMAIN_DISK_FORMAT_QCOW2); gvir_config_domain_disk_set_target_bus(disk, GVIR_CONFIG_DOMAIN_DISK_BUS_IDE); gvir_config_domain_disk_set_target_dev(disk, "hda"); + gvir_config_domain_disk_set_driver(disk, driver); + g_object_unref(G_OBJECT(driver)); devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(disk)); g_assert(gvir_config_domain_disk_get_disk_type(disk) == GVIR_CONFIG_DOMAIN_DISK_FILE); g_assert(gvir_config_domain_disk_get_guest_device_type(disk) == GVIR_CONFIG_DOMAIN_DISK_GUEST_DEVICE_DISK); g_assert(gvir_config_domain_disk_get_startup_policy (disk) == GVIR_CONFIG_DOMAIN_DISK_STARTUP_POLICY_REQUISITE); g_str_const_check(gvir_config_domain_disk_get_source(disk), "/tmp/foo/bar"); - g_assert(gvir_config_domain_disk_get_driver_cache(disk) == GVIR_CONFIG_DOMAIN_DISK_CACHE_NONE); - g_str_const_check(gvir_config_domain_disk_get_driver_name(disk), "qemu"); - g_assert(gvir_config_domain_disk_get_driver_format(disk) == GVIR_CONFIG_DOMAIN_DISK_FORMAT_QCOW2); + driver = gvir_config_domain_disk_get_driver(disk); + g_assert(driver != NULL); + g_assert(gvir_config_domain_disk_driver_get_cache(driver) == GVIR_CONFIG_DOMAIN_DISK_CACHE_NONE); + g_str_const_check(gvir_config_domain_disk_driver_get_name(driver), "qemu"); + g_assert(gvir_config_domain_disk_driver_get_format(driver) == GVIR_CONFIG_DOMAIN_DISK_FORMAT_QCOW2); g_assert(gvir_config_domain_disk_get_target_bus(disk) == GVIR_CONFIG_DOMAIN_DISK_BUS_IDE); g_str_const_check(gvir_config_domain_disk_get_target_dev(disk), "hda"); -- 1.8.4.2

On Fri, Dec 6, 2013 at 11:13 AM, Christophe Fergeau <cfergeau@redhat.com> wrote:
They are replaced by equivalent methods in GVirConfigDomainDiskDriver. Initially, we had only one or two attributes to set on the 'driver' child of the 'disk' node. Nowadays, we more than 5 attributes to set on this node, mapping it as a separate object is more consistent with the rest of libvirt-gconfig API. ---
ACK -- Regards, Zeeshan Ali (Khattak) FSF member#5124

--- libvirt-gconfig/tests/test-domain-create.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index b5c2cf3..e0d6c00 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -241,6 +241,7 @@ int main(int argc, char **argv) gvir_config_domain_disk_driver_set_name(driver, "qemu"); gvir_config_domain_disk_driver_set_cache(driver, GVIR_CONFIG_DOMAIN_DISK_CACHE_NONE); gvir_config_domain_disk_driver_set_format(driver, GVIR_CONFIG_DOMAIN_DISK_FORMAT_QCOW2); + gvir_config_domain_disk_driver_set_copy_on_read(driver, TRUE); disk = gvir_config_domain_disk_new(); gvir_config_domain_disk_set_type(disk, GVIR_CONFIG_DOMAIN_DISK_FILE); @@ -262,6 +263,7 @@ int main(int argc, char **argv) g_assert(gvir_config_domain_disk_driver_get_cache(driver) == GVIR_CONFIG_DOMAIN_DISK_CACHE_NONE); g_str_const_check(gvir_config_domain_disk_driver_get_name(driver), "qemu"); g_assert(gvir_config_domain_disk_driver_get_format(driver) == GVIR_CONFIG_DOMAIN_DISK_FORMAT_QCOW2); + g_assert(gvir_config_domain_disk_driver_get_copy_on_read(driver)); g_assert(gvir_config_domain_disk_get_target_bus(disk) == GVIR_CONFIG_DOMAIN_DISK_BUS_IDE); g_str_const_check(gvir_config_domain_disk_get_target_dev(disk), "hda"); -- 1.8.4.2

Ping? Christophe On Fri, Dec 06, 2013 at 12:13:39PM +0100, Christophe Fergeau wrote:
Hey,
I wanted to add support in libvirt-gconfig for the 'discard' attribute of the disk driver node. If I follow the way the API is currently done, it would be an additional method to GVirConfigDomainDisk. However, there are quite a few attributes attached to the disk driver node, so I felt it was preferrable to have a dedicated GVirConfigDomainDiskDriver class. This also matches better other places of libvirt-gconfig API. I've implemented support for most of the attributes of the disk driver node, as a result the corresponding methods in GVirConfigDomainDisk have been deprecated.
Christophe
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 06.12.2013 12:13, Christophe Fergeau wrote:
Hey,
I wanted to add support in libvirt-gconfig for the 'discard' attribute of the disk driver node. If I follow the way the API is currently done, it would be an additional method to GVirConfigDomainDisk. However, there are quite a few attributes attached to the disk driver node, so I felt it was preferrable to have a dedicated GVirConfigDomainDiskDriver class. This also matches better other places of libvirt-gconfig API. I've implemented support for most of the attributes of the disk driver node, as a result the corresponding methods in GVirConfigDomainDisk have been deprecated.
Christophe
It's been a while since the last time I've written something for libivrt-glib. So just my two cents: I'd say go with new class esp. if there's a chance for attributes to expand. Although, we still have to maintain the old APIs to set some driver attributes directly - I guess there's no way of deprecating/dropping those APIs right? Michal

Hey, On Mon, Jan 06, 2014 at 10:40:49AM +0100, Michal Privoznik wrote:
It's been a while since the last time I've written something for libivrt-glib. So just my two cents: I'd say go with new class esp. if there's a chance for attributes to expand. Although, we still have to maintain the old APIs to set some driver attributes directly - I guess there's no way of deprecating/dropping those APIs right?
They are marked with G_DEPRECATED_FOR in patch 3/4 so that the compiler warns about uses of the old methods. We still haven't (officially) committed to API/ABI stability for libvirt-glib, so if we were to do such breakage at some point, we could remove them at the same time. For now, I agree it's easier to just keep the old API. Christophe

On Mon, Jan 06, 2014 at 10:59:31AM +0100, Christophe Fergeau wrote:
Hey,
On Mon, Jan 06, 2014 at 10:40:49AM +0100, Michal Privoznik wrote:
It's been a while since the last time I've written something for libivrt-glib. So just my two cents: I'd say go with new class esp. if there's a chance for attributes to expand. Although, we still have to maintain the old APIs to set some driver attributes directly - I guess there's no way of deprecating/dropping those APIs right?
They are marked with G_DEPRECATED_FOR in patch 3/4 so that the compiler warns about uses of the old methods. We still haven't (officially) committed to API/ABI stability for libvirt-glib, so if we were to do such breakage at some point, we could remove them at the same time. For now, I agree it's easier to just keep the old API.
In this case it'd be nice to force users of the lib to define #define LIBVIRT_GLIB_API_SUBJECT_TO_CHANGE and fail compilation otherwise so we at least state publically that the API might change. We're shipping this lib in distros so not doing s.th. like this might hit users with surprise. I was under the impression that the introduction of symbol versioning was done to keep the ABI stable? If not can we at least bump the soname when dropping symbols? Cheers, -- Guido

On Tue, Jan 07, 2014 at 11:21:22PM +0100, Guido Günther wrote:
On Mon, Jan 06, 2014 at 10:59:31AM +0100, Christophe Fergeau wrote:
Hey,
On Mon, Jan 06, 2014 at 10:40:49AM +0100, Michal Privoznik wrote:
It's been a while since the last time I've written something for libivrt-glib. So just my two cents: I'd say go with new class esp. if there's a chance for attributes to expand. Although, we still have to maintain the old APIs to set some driver attributes directly - I guess there's no way of deprecating/dropping those APIs right?
They are marked with G_DEPRECATED_FOR in patch 3/4 so that the compiler warns about uses of the old methods. We still haven't (officially) committed to API/ABI stability for libvirt-glib, so if we were to do such breakage at some point, we could remove them at the same time. For now, I agree it's easier to just keep the old API.
In this case it'd be nice to force users of the lib to define
#define LIBVIRT_GLIB_API_SUBJECT_TO_CHANGE
and fail compilation otherwise so we at least state publically that the API might change. We're shipping this lib in distros so not doing s.th. like this might hit users with surprise.
I was under the impression that the introduction of symbol versioning was done to keep the ABI stable? If not can we at least bump the soname when dropping symbols?
libvirt-glib README is still stating: "NB: at this time, libvirt-glib is *NOT* considered API/ABI stable. Future releases may still include API/ABI incompatible changes." If (and I'm saying if, not when) we were to do such API/ABI breakage, this would go with a soname bump. Christophe

On Tue, Jan 07, 2014 at 11:54:57PM +0100, Christophe Fergeau wrote:
On Tue, Jan 07, 2014 at 11:21:22PM +0100, Guido Günther wrote:
On Mon, Jan 06, 2014 at 10:59:31AM +0100, Christophe Fergeau wrote:
Hey,
On Mon, Jan 06, 2014 at 10:40:49AM +0100, Michal Privoznik wrote:
It's been a while since the last time I've written something for libivrt-glib. So just my two cents: I'd say go with new class esp. if there's a chance for attributes to expand. Although, we still have to maintain the old APIs to set some driver attributes directly - I guess there's no way of deprecating/dropping those APIs right?
They are marked with G_DEPRECATED_FOR in patch 3/4 so that the compiler warns about uses of the old methods. We still haven't (officially) committed to API/ABI stability for libvirt-glib, so if we were to do such breakage at some point, we could remove them at the same time. For now, I agree it's easier to just keep the old API.
In this case it'd be nice to force users of the lib to define
#define LIBVIRT_GLIB_API_SUBJECT_TO_CHANGE
and fail compilation otherwise so we at least state publically that the API might change. We're shipping this lib in distros so not doing s.th. like this might hit users with surprise.
I was under the impression that the introduction of symbol versioning was done to keep the ABI stable? If not can we at least bump the soname when dropping symbols?
libvirt-glib README is still stating: "NB: at this time, libvirt-glib is *NOT* considered API/ABI stable. Future releases may still include API/ABI incompatible changes." If (and I'm saying if, not when) we were to do such API/ABI breakage, this would go with a soname bump.
I didn't spot this in the README but with a soname bump everything is fine. Thanks for the update! I'll make this more prominent in Debian's package description as well. Cheers, -- Guido
participants (4)
-
Christophe Fergeau
-
Guido Günther
-
Michal Privoznik
-
Zeeshan Ali (Khattak)