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@xxxxxxxxxx> + */ + +#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@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_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 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list