[libvirt] [libvirt-glib PATCHv2 0/6] gconfig: Add classes/methods for snapshot configuration

Hey, This v2 has 3 more patches than the initial series, they were needed to address various issues with the initial series. 3/6 is not strictly needed, I'm still undecided as to whether it makes things nicer or not, so it's open for discussion (the deprecation it introduces would be triggered when building Boxes). Changes since v1: - fix a bug in gvir_config_domain_snapshot_get_parent() when the <parent> element is missing (which happens with the initial snapshot in a given domain) - add missing gvir_config_domain_snapshot_[gs]et_memory_state() and gvir_config_domain_snapshot_[gs]et_memory_file() - return a time_t from gvir_config_domain_snapshot_get_creation_time() - rename the GVirConfigDomainSnapshotState enum to GVirConfigDomainSnapshotDomainState - add a GVirConfigDomainDiskFormat enum and return it from gvir_config_domain_snapshot_disk_get_driver_type() Christophe

This will be useful when implementing gvir_domain_snapshot_get_parent() as the child node 'parent' is not always present in the XML. --- libvirt-gconfig/libvirt-gconfig-object.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c index 9e3b5f2..721f6cb 100644 --- a/libvirt-gconfig/libvirt-gconfig-object.c +++ b/libvirt-gconfig/libvirt-gconfig-object.c @@ -929,7 +929,8 @@ gvir_config_object_get_child_with_type(GVirConfigObject *object, g_return_val_if_fail(child_name != NULL, NULL); node = gvir_config_xml_get_element(object->priv->node, child_name, NULL); - g_return_val_if_fail(node != NULL, NULL); + if (node == NULL) + return NULL; return gvir_config_object_new_from_tree(child_type, object->priv->doc, -- 1.8.2.1

--- libvirt-gconfig/libvirt-gconfig-domain-disk.h | 20 ++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.sym | 2 ++ 2 files changed, 22 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.h b/libvirt-gconfig/libvirt-gconfig-domain-disk.h index 7363d31..e80a2fc 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-disk.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.h @@ -101,6 +101,26 @@ 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; + GType gvir_config_domain_disk_get_type(void); GVirConfigDomainDisk *gvir_config_domain_disk_new(void); diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index ccddd88..ccca05f 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -517,6 +517,8 @@ LIBVIRT_GCONFIG_0.1.7 { gvir_config_domain_channel_get_target_name; gvir_config_domain_channel_get_target_type; + gvir_config_domain_disk_format_get_type; + gvir_config_domain_graphics_desktop_get_type; gvir_config_domain_graphics_desktop_new; gvir_config_domain_graphics_desktop_new_from_xml; -- 1.8.2.1

libvirt commit http://libvirt.org/git/?p=libvirt.git;a=commit;h=e2c41e486018ee74f6a75c1f717... strongly hints that driver type for a disk domain should be an enum rather than a raw string. Since we already have setters/getters for this attribute, the alternate versions have an _enum suffix. I did not set "Rename to: gvir_config_domain_disk_[gs]et_driver_type" in a gtk-doc comment to force bindings to use this better version as this would break Boxes for example. --- libvirt-gconfig/libvirt-gconfig-compat.h | 20 ++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-disk.c | 38 +++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-disk.h | 5 ++++ libvirt-gconfig/libvirt-gconfig.sym | 2 ++ libvirt-gconfig/tests/test-domain-create.c | 6 ++--- 5 files changed, 68 insertions(+), 3 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-compat.h b/libvirt-gconfig/libvirt-gconfig-compat.h index c9ac645..fbf552c 100644 --- a/libvirt-gconfig/libvirt-gconfig-compat.h +++ b/libvirt-gconfig/libvirt-gconfig-compat.h @@ -25,6 +25,26 @@ #include <glib-object.h> +#if !GLIB_CHECK_VERSION(2,32,0) + +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) +#define G_DEPRECATED __attribute__((__deprecated__)) +#elif defined(_MSC_VER) && (_MSC_VER >= 1300) +#define G_DEPRECATED __declspec(deprecated) +#else +#define G_DEPRECATED +#endif + +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) +#define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead"))) +#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320) +#define G_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead")) +#else +#define G_DEPRECATED_FOR(f) G_DEPRECATED +#endif + +#endif + #if GLIB_CHECK_VERSION(2, 35, 0) #define g_type_init() #endif diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-disk.c index a167141..8591cd5 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-disk.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.c @@ -173,6 +173,12 @@ void gvir_config_domain_disk_set_driver_name(GVirConfigDomainDisk *disk, "driver", "name", driver_name); } +/** + * gvir_config_domain_disk_set_driver_type: + * + * Deprecated: 0.1.7: Use gvir_config_domain_disk_set_driver_type_enum() + * instead + */ void gvir_config_domain_disk_set_driver_type(GVirConfigDomainDisk *disk, const char *driver_type) { @@ -181,6 +187,18 @@ void gvir_config_domain_disk_set_driver_type(GVirConfigDomainDisk *disk, "driver", "type", driver_type); } + +void gvir_config_domain_disk_set_driver_type_enum(GVirConfigDomainDisk *disk, + GVirConfigDomainDiskFormat format) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk)); + gvir_config_object_add_child_with_attribute_enum(GVIR_CONFIG_OBJECT(disk), + "driver", "type", + GVIR_CONFIG_TYPE_DOMAIN_DISK_FORMAT, + format); +} + + void gvir_config_domain_disk_set_driver_cache(GVirConfigDomainDisk *disk, GVirConfigDomainDiskCacheType cache_type) { @@ -294,6 +312,12 @@ gvir_config_domain_disk_get_driver_name(GVirConfigDomainDisk *disk) "driver", "name"); } +/** + * gvir_config_domain_disk_get_driver_type: + * + * Deprecated: 0.1.7: Use gvir_config_domain_disk_get_driver_type_enum() + * instead + */ const char * gvir_config_domain_disk_get_driver_type(GVirConfigDomainDisk *disk) { @@ -303,6 +327,20 @@ gvir_config_domain_disk_get_driver_type(GVirConfigDomainDisk *disk) "driver", "type"); } + +GVirConfigDomainDiskFormat +gvir_config_domain_disk_get_driver_type_enum(GVirConfigDomainDisk *disk) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk), + GVIR_CONFIG_DOMAIN_DISK_FORMAT_RAW); + + return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(disk), + "driver", "type", + GVIR_CONFIG_TYPE_DOMAIN_DISK_FORMAT, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_RAW); +} + + GVirConfigDomainDiskCacheType gvir_config_domain_disk_get_driver_cache(GVirConfigDomainDisk *disk) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.h b/libvirt-gconfig/libvirt-gconfig-domain-disk.h index e80a2fc..3843193 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-disk.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.h @@ -141,8 +141,11 @@ void gvir_config_domain_disk_set_driver_cache(GVirConfigDomainDisk *disk, GVirConfigDomainDiskCacheType cache_type); void gvir_config_domain_disk_set_driver_name(GVirConfigDomainDisk *disk, const char *driver_name); +G_DEPRECATED_FOR(gvir_config_domain_disk_set_driver_type_enum) void gvir_config_domain_disk_set_driver_type(GVirConfigDomainDisk *disk, const char *driver_type); +void gvir_config_domain_disk_set_driver_type_enum(GVirConfigDomainDisk *disk, + GVirConfigDomainDiskFormat format); void gvir_config_domain_disk_set_target_bus(GVirConfigDomainDisk *disk, GVirConfigDomainDiskBus bus); void gvir_config_domain_disk_set_target_dev(GVirConfigDomainDisk *disk, @@ -155,7 +158,9 @@ GVirConfigDomainDiskStartupPolicy gvir_config_domain_disk_get_startup_policy(GVi const char *gvir_config_domain_disk_get_source(GVirConfigDomainDisk *disk); GVirConfigDomainDiskCacheType gvir_config_domain_disk_get_driver_cache(GVirConfigDomainDisk *disk); const char *gvir_config_domain_disk_get_driver_name(GVirConfigDomainDisk *disk); +G_DEPRECATED_FOR(gvir_config_domain_disk_get_driver_type_enum) const char *gvir_config_domain_disk_get_driver_type(GVirConfigDomainDisk *disk); +GVirConfigDomainDiskFormat gvir_config_domain_disk_get_driver_type_enum(GVirConfigDomainDisk *disk); GVirConfigDomainDiskBus gvir_config_domain_disk_get_target_bus(GVirConfigDomainDisk *disk); const char *gvir_config_domain_disk_get_target_dev(GVirConfigDomainDisk *disk); void gvir_config_domain_disk_set_readonly(GVirConfigDomainDisk *disk, diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index ccca05f..17d0ca2 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -518,6 +518,8 @@ LIBVIRT_GCONFIG_0.1.7 { gvir_config_domain_channel_get_target_type; gvir_config_domain_disk_format_get_type; + gvir_config_domain_disk_get_driver_type_enum; + gvir_config_domain_disk_set_driver_type_enum; gvir_config_domain_graphics_desktop_get_type; gvir_config_domain_graphics_desktop_new; diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index 51ece7b..7ec34a1 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -240,10 +240,10 @@ int main(int argc, char **argv) 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_type(disk, "bar"); + gvir_config_domain_disk_set_driver_type_enum(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_type(disk, "qcow2"); + gvir_config_domain_disk_set_driver_type_enum(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"); devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(disk)); @@ -254,7 +254,7 @@ int main(int argc, char **argv) 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_str_const_check(gvir_config_domain_disk_get_driver_type(disk), "qcow2"); + g_assert(gvir_config_domain_disk_get_driver_type_enum(disk) == 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.2.1

On Sun, May 12, 2013 at 11:52:22PM +0200, Christophe Fergeau wrote:
libvirt commit http://libvirt.org/git/?p=libvirt.git;a=commit;h=e2c41e486018ee74f6a75c1f717... strongly hints that driver type for a disk domain should be an enum rather than a raw string. Since we already have setters/getters for this attribute, the alternate versions have an _enum suffix. I did not set "Rename to: gvir_config_domain_disk_[gs]et_driver_type" in a gtk-doc comment to force bindings to use this better version as this would break Boxes for example.
Rather than using an _enum suffix, how about just giving it a different name. The word 'type' is really bogus in our XML schema - it should have been 'format'. eg gvir_config_domain_disk_[sg]et_driver_format Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Mon, May 13, 2013 at 09:34:59AM +0100, Daniel P. Berrange wrote:
Rather than using an _enum suffix, how about just giving it a different name. The word 'type' is really bogus in our XML schema - it should have been 'format'. eg
gvir_config_domain_disk_[sg]et_driver_format
Oh sure, I'm quite bad at naming, so suggestions in that area are warmly welcome. I'll change that, thanks! Christophe

libvirt commit http://libvirt.org/git/?p=libvirt.git;a=commit;h=e2c41e486018ee74f6a75c1f717... strongly hints that driver type for a disk domain should be an enum rather than a raw string. Since we already have setters/getters for this attribute, we can't use the same name as in the XML. However, as Daniel Berrangé pointed out, gvir_config_domain_disk_[gs]et_driver_format is a better name for this, so we add the API accepting an enum under this name. I did not set "Rename to: gvir_config_domain_disk_[gs]et_driver_format" in a gtk-doc comment to force bindings to use this better version as this would break Boxes for example. --- Changes since v2: - rename from _[gs]et_driver_type_enum() to the more natural _[gs]et_driver_format() libvirt-gconfig/libvirt-gconfig-compat.h | 20 ++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-disk.c | 38 +++++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-disk.h | 5 ++++ libvirt-gconfig/libvirt-gconfig.sym | 2 ++ libvirt-gconfig/tests/test-domain-create.c | 6 ++--- 5 files changed, 68 insertions(+), 3 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-compat.h b/libvirt-gconfig/libvirt-gconfig-compat.h index c9ac645..fbf552c 100644 --- a/libvirt-gconfig/libvirt-gconfig-compat.h +++ b/libvirt-gconfig/libvirt-gconfig-compat.h @@ -25,6 +25,26 @@ #include <glib-object.h> +#if !GLIB_CHECK_VERSION(2,32,0) + +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) +#define G_DEPRECATED __attribute__((__deprecated__)) +#elif defined(_MSC_VER) && (_MSC_VER >= 1300) +#define G_DEPRECATED __declspec(deprecated) +#else +#define G_DEPRECATED +#endif + +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) +#define G_DEPRECATED_FOR(f) __attribute__((__deprecated__("Use '" #f "' instead"))) +#elif defined(_MSC_FULL_VER) && (_MSC_FULL_VER > 140050320) +#define G_DEPRECATED_FOR(f) __declspec(deprecated("is deprecated. Use '" #f "' instead")) +#else +#define G_DEPRECATED_FOR(f) G_DEPRECATED +#endif + +#endif + #if GLIB_CHECK_VERSION(2, 35, 0) #define g_type_init() #endif diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-disk.c index a167141..4f85262 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-disk.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.c @@ -173,6 +173,12 @@ void gvir_config_domain_disk_set_driver_name(GVirConfigDomainDisk *disk, "driver", "name", driver_name); } +/** + * gvir_config_domain_disk_set_driver_type: + * + * Deprecated: 0.1.7: Use gvir_config_domain_disk_set_driver_format() + * instead + */ void gvir_config_domain_disk_set_driver_type(GVirConfigDomainDisk *disk, const char *driver_type) { @@ -181,6 +187,18 @@ void gvir_config_domain_disk_set_driver_type(GVirConfigDomainDisk *disk, "driver", "type", driver_type); } + +void gvir_config_domain_disk_set_driver_format(GVirConfigDomainDisk *disk, + GVirConfigDomainDiskFormat format) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk)); + gvir_config_object_add_child_with_attribute_enum(GVIR_CONFIG_OBJECT(disk), + "driver", "type", + GVIR_CONFIG_TYPE_DOMAIN_DISK_FORMAT, + format); +} + + void gvir_config_domain_disk_set_driver_cache(GVirConfigDomainDisk *disk, GVirConfigDomainDiskCacheType cache_type) { @@ -294,6 +312,12 @@ gvir_config_domain_disk_get_driver_name(GVirConfigDomainDisk *disk) "driver", "name"); } +/** + * gvir_config_domain_disk_get_driver_type: + * + * Deprecated: 0.1.7: Use gvir_config_domain_disk_get_driver_format() + * instead + */ const char * gvir_config_domain_disk_get_driver_type(GVirConfigDomainDisk *disk) { @@ -303,6 +327,20 @@ gvir_config_domain_disk_get_driver_type(GVirConfigDomainDisk *disk) "driver", "type"); } + +GVirConfigDomainDiskFormat +gvir_config_domain_disk_get_driver_format(GVirConfigDomainDisk *disk) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_DISK(disk), + GVIR_CONFIG_DOMAIN_DISK_FORMAT_RAW); + + return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(disk), + "driver", "type", + GVIR_CONFIG_TYPE_DOMAIN_DISK_FORMAT, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_RAW); +} + + GVirConfigDomainDiskCacheType gvir_config_domain_disk_get_driver_cache(GVirConfigDomainDisk *disk) { diff --git a/libvirt-gconfig/libvirt-gconfig-domain-disk.h b/libvirt-gconfig/libvirt-gconfig-domain-disk.h index e80a2fc..3b82eb5 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-disk.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-disk.h @@ -141,8 +141,11 @@ void gvir_config_domain_disk_set_driver_cache(GVirConfigDomainDisk *disk, GVirConfigDomainDiskCacheType cache_type); void gvir_config_domain_disk_set_driver_name(GVirConfigDomainDisk *disk, const char *driver_name); +G_DEPRECATED_FOR(gvir_config_domain_disk_set_driver_format) void gvir_config_domain_disk_set_driver_type(GVirConfigDomainDisk *disk, const char *driver_type); +void gvir_config_domain_disk_set_driver_format(GVirConfigDomainDisk *disk, + GVirConfigDomainDiskFormat format); void gvir_config_domain_disk_set_target_bus(GVirConfigDomainDisk *disk, GVirConfigDomainDiskBus bus); void gvir_config_domain_disk_set_target_dev(GVirConfigDomainDisk *disk, @@ -155,7 +158,9 @@ GVirConfigDomainDiskStartupPolicy gvir_config_domain_disk_get_startup_policy(GVi const char *gvir_config_domain_disk_get_source(GVirConfigDomainDisk *disk); GVirConfigDomainDiskCacheType gvir_config_domain_disk_get_driver_cache(GVirConfigDomainDisk *disk); const char *gvir_config_domain_disk_get_driver_name(GVirConfigDomainDisk *disk); +G_DEPRECATED_FOR(gvir_config_domain_disk_get_driver_format) const char *gvir_config_domain_disk_get_driver_type(GVirConfigDomainDisk *disk); +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); void gvir_config_domain_disk_set_readonly(GVirConfigDomainDisk *disk, diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index ccca05f..4e12fb2 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -518,6 +518,8 @@ LIBVIRT_GCONFIG_0.1.7 { gvir_config_domain_channel_get_target_type; gvir_config_domain_disk_format_get_type; + gvir_config_domain_disk_get_driver_format; + gvir_config_domain_disk_set_driver_format; gvir_config_domain_graphics_desktop_get_type; gvir_config_domain_graphics_desktop_new; diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index 51ece7b..ae0b248 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -240,10 +240,10 @@ int main(int argc, char **argv) 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_type(disk, "bar"); + 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_type(disk, "qcow2"); + 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"); devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(disk)); @@ -254,7 +254,7 @@ int main(int argc, char **argv) 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_str_const_check(gvir_config_domain_disk_get_driver_type(disk), "qcow2"); + g_assert(gvir_config_domain_disk_get_driver_format(disk) == 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.2.1

On Mon, May 13, 2013 at 09:34:59AM +0100, Daniel P. Berrange wrote:
Rather than using an _enum suffix, how about just giving it a different name. The word 'type' is really bogus in our XML schema - it should have been 'format'. eg
gvir_config_domain_disk_[sg]et_driver_format
I'll change the name of gvir_config_domain_snapshot_disk_set_driver_type() in patch 5/6 as well for more consistency. Christophe

--- libvirt-gconfig/Makefile.am | 3 + .../libvirt-gconfig-domain-snapshot-disk.c | 88 ++++++++++++++++++++++ .../libvirt-gconfig-domain-snapshot-disk.h | 68 +++++++++++++++++ .../libvirt-gconfig-domain-snapshot-private.h | 38 ++++++++++ libvirt-gconfig/libvirt-gconfig-private.h | 1 + libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 4 + 7 files changed, 203 insertions(+) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.h create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-snapshot-private.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 68ba39d..36059da 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -61,6 +61,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-smartcard-host-certificates.h \ libvirt-gconfig-domain-smartcard-passthrough.h \ libvirt-gconfig-domain-snapshot.h \ + libvirt-gconfig-domain-snapshot-disk.h \ libvirt-gconfig-domain-sound.h \ libvirt-gconfig-domain-timer.h \ libvirt-gconfig-domain-timer-pit.h \ @@ -84,6 +85,7 @@ noinst_HEADERS = \ libvirt-gconfig-capabilities-cpu-private.h \ libvirt-gconfig-compat.h \ libvirt-gconfig-domain-device-private.h \ + libvirt-gconfig-domain-snapshot-private.h \ libvirt-gconfig-helpers-private.h \ libvirt-gconfig-object-private.h \ libvirt-gconfig-xml-doc.h @@ -140,6 +142,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-smartcard-host-certificates.c \ libvirt-gconfig-domain-smartcard-passthrough.c \ libvirt-gconfig-domain-snapshot.c \ + libvirt-gconfig-domain-snapshot-disk.c \ libvirt-gconfig-domain-sound.c \ libvirt-gconfig-domain-timer.c \ libvirt-gconfig-domain-timer-pit.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c new file mode 100644 index 0000000..a21f0d6 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c @@ -0,0 +1,88 @@ +/* + * libvirt-gconfig-secret.c: libvirt secret configuration + * + * Copyright (C) 2008 Daniel P. Berrange + * Copyright (C) 2010-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_SNAPSHOT_DISK_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_DISK, GVirConfigDomainSnapshotDiskPrivate)) + +struct _GVirConfigDomainSnapshotDiskPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDomainSnapshotDisk, gvir_config_domain_snapshot_disk, GVIR_CONFIG_TYPE_OBJECT); + + +static void gvir_config_domain_snapshot_disk_class_init(GVirConfigDomainSnapshotDiskClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigDomainSnapshotDiskPrivate)); +} + + +static void gvir_config_domain_snapshot_disk_init(GVirConfigDomainSnapshotDisk *disk) +{ + g_debug("Init GVirConfigDomainSnapshotDisk=%p", disk); + + disk->priv = GVIR_CONFIG_DOMAIN_SNAPSHOT_DISK_GET_PRIVATE(disk); +} + + +GVirConfigDomainSnapshotDisk *gvir_config_domain_snapshot_disk_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_DISK, + "disk", + DATADIR "/libvirt/schemas/domainsnapshot.rng"); + return GVIR_CONFIG_DOMAIN_SNAPSHOT_DISK(object); +} + + +GVirConfigDomainSnapshotDisk *gvir_config_domain_snapshot_disk_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_DISK, + "disk", + DATADIR "/libvirt/schemas/domainsnapshot.rng", + xml, error); + return GVIR_CONFIG_DOMAIN_SNAPSHOT_DISK(object); +} + + +GVirConfigDomainSnapshotDisk * +gvir_config_domain_snapshot_disk_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_tree(GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_DISK, + doc, NULL, tree); + + return GVIR_CONFIG_DOMAIN_SNAPSHOT_DISK(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.h b/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.h new file mode 100644 index 0000000..9a73336 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.h @@ -0,0 +1,68 @@ +/* + * libvirt-gconfig-domain-snapshot-disk.h: libvirt snapshot disk configuration + * + * Copyright (C) 2010-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_SNAPSHOT_DISK_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_SNAPSHOT_DISK_H__ + +G_BEGIN_DECLS + +#define GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_DISK (gvir_config_domain_snapshot_disk_get_type ()) +#define GVIR_CONFIG_DOMAIN_SNAPSHOT_DISK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_DISK, GVirConfigDomainSnapshotDisk)) +#define GVIR_CONFIG_DOMAIN_SNAPSHOT_DISK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_DISK, GVirConfigDomainSnapshotDiskClass)) +#define GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_DISK)) +#define GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_DISK)) +#define GVIR_CONFIG_DOMAIN_SNAPSHOT_DISK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_DISK, GVirConfigDomainSnapshotDiskClass)) + +typedef struct _GVirConfigDomainSnapshotDisk GVirConfigDomainSnapshotDisk; +typedef struct _GVirConfigDomainSnapshotDiskPrivate GVirConfigDomainSnapshotDiskPrivate; +typedef struct _GVirConfigDomainSnapshotDiskClass GVirConfigDomainSnapshotDiskClass; + +struct _GVirConfigDomainSnapshotDisk +{ + GVirConfigObject parent; + + GVirConfigDomainSnapshotDiskPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainSnapshotDiskClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_domain_snapshot_disk_get_type(void); + +GVirConfigDomainSnapshotDisk *gvir_config_domain_snapshot_disk_new(void); +GVirConfigDomainSnapshotDisk *gvir_config_domain_snapshot_disk_new_from_xml(const gchar *xml, + GError **error); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_SNAPSHOT_DISK_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot-private.h b/libvirt-gconfig/libvirt-gconfig-domain-snapshot-private.h new file mode 100644 index 0000000..663d2e7 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-snapshot-private.h @@ -0,0 +1,38 @@ +/* + * libvirt-gconfig-domain-snapshot-private.h: libvirt domain snapshot private methods + * + * Copyright (C) 2010-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: Daniel P. Berrange <berrange@redhat.com> + */ + +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GCONFIG_DOMAIN_SNAPSHOT_PRIVATE_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_SNAPSHOT_PRIVATE_H__ + +#include <libvirt-gconfig/libvirt-gconfig-domain.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.h> + +G_BEGIN_DECLS +GVirConfigDomainSnapshotDisk *gvir_config_domain_snapshot_disk_new_from_tree(GVirConfigXmlDoc *doc, + xmlNodePtr tree); +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_SNAPSHOT_PRIVATE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-private.h b/libvirt-gconfig/libvirt-gconfig-private.h index 9dc6431..c49c57b 100644 --- a/libvirt-gconfig/libvirt-gconfig-private.h +++ b/libvirt-gconfig/libvirt-gconfig-private.h @@ -25,6 +25,7 @@ #include <libvirt-gconfig/libvirt-gconfig-capabilities-cpu-private.h> #include <libvirt-gconfig/libvirt-gconfig-domain-device-private.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-snapshot-private.h> #include <libvirt-gconfig/libvirt-gconfig-helpers-private.h> #include <libvirt-gconfig/libvirt-gconfig-object-private.h> #include <libvirt-gconfig/libvirt-gconfig-xml-doc.h> diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index b000747..03e8ce7 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -78,6 +78,7 @@ #include <libvirt-gconfig/libvirt-gconfig-domain-smartcard-host-certificates.h> #include <libvirt-gconfig/libvirt-gconfig-domain-smartcard-passthrough.h> #include <libvirt-gconfig/libvirt-gconfig-domain-snapshot.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.h> #include <libvirt-gconfig/libvirt-gconfig-domain-sound.h> #include <libvirt-gconfig/libvirt-gconfig-domain-timer.h> #include <libvirt-gconfig/libvirt-gconfig-domain-timer-pit.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 17d0ca2..0a0b1f1 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -561,6 +561,10 @@ LIBVIRT_GCONFIG_0.1.7 { gvir_config_storage_pool_target_get_path; gvir_config_storage_pool_target_get_permissions; + + gvir_config_domain_snapshot_disk_get_type; + gvir_config_domain_snapshot_disk_new; + gvir_config_domain_snapshot_disk_new_from_xml; } LIBVIRT_GCONFIG_0.1.6; # .... define new API here using predicted next version number .... -- 1.8.2.1

--- .../libvirt-gconfig-domain-snapshot-disk.c | 85 ++++++++++++++++++++++ .../libvirt-gconfig-domain-snapshot-disk.h | 16 ++++ libvirt-gconfig/libvirt-gconfig.sym | 9 +++ 3 files changed, 110 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c index a21f0d6..2e6a3f9 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c @@ -86,3 +86,88 @@ gvir_config_domain_snapshot_disk_new_from_tree(GVirConfigXmlDoc *doc, return GVIR_CONFIG_DOMAIN_SNAPSHOT_DISK(object); } + + +const char *gvir_config_domain_snapshot_disk_get_name(GVirConfigDomainSnapshotDisk *disk) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK(disk), NULL); + + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(disk), + "name"); +} + + +void gvir_config_domain_snapshot_disk_set_name(GVirConfigDomainSnapshotDisk *disk, + const char *name) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK(disk)); + + gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(disk), + "name", name); +} + + +GVirConfigDomainDiskSnapshotType gvir_config_domain_snapshot_disk_get_snapshot_type(GVirConfigDomainSnapshotDisk *disk) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK(disk), + GVIR_CONFIG_DOMAIN_DISK_SNAPSHOT_NO); + + return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(disk), + NULL, + "snapshot", + GVIR_CONFIG_TYPE_DOMAIN_DISK_SNAPSHOT_TYPE, + GVIR_CONFIG_DOMAIN_DISK_SNAPSHOT_NO); +} + + +void gvir_config_domain_snapshot_disk_set_snapshot_type(GVirConfigDomainSnapshotDisk *disk, + GVirConfigDomainDiskSnapshotType type) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK(disk)); + + gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(disk), "snapshot", + GVIR_CONFIG_TYPE_DOMAIN_DISK_SNAPSHOT_TYPE, + type, NULL); +} + + +const char *gvir_config_domain_snapshot_disk_get_source_file(GVirConfigDomainSnapshotDisk *disk) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK(disk), NULL); + + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(disk), + "source", "file"); +} + + +void gvir_config_domain_snapshot_disk_set_source_file(GVirConfigDomainSnapshotDisk *disk, + const char *filename) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK(disk)); + + gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(disk), + "source", "file", filename); +} + +GVirConfigDomainDiskFormat gvir_config_domain_snapshot_disk_get_driver_type(GVirConfigDomainSnapshotDisk *disk) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK(disk), + GVIR_CONFIG_DOMAIN_DISK_FORMAT_RAW); + + return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(disk), + "driver", "type", + GVIR_CONFIG_TYPE_DOMAIN_DISK_FORMAT, + GVIR_CONFIG_DOMAIN_DISK_FORMAT_RAW); +} + + +void gvir_config_domain_snapshot_disk_set_driver_type(GVirConfigDomainSnapshotDisk *disk, + GVirConfigDomainDiskFormat type) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK(disk)); + + gvir_config_object_add_child_with_attribute_enum(GVIR_CONFIG_OBJECT(disk), + "driver", "type", + GVIR_CONFIG_TYPE_DOMAIN_DISK_FORMAT, + type); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.h b/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.h index 9a73336..9c59c50 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.h @@ -63,6 +63,22 @@ GVirConfigDomainSnapshotDisk *gvir_config_domain_snapshot_disk_new(void); GVirConfigDomainSnapshotDisk *gvir_config_domain_snapshot_disk_new_from_xml(const gchar *xml, GError **error); +const char *gvir_config_domain_snapshot_disk_get_name(GVirConfigDomainSnapshotDisk *disk); +void gvir_config_domain_snapshot_disk_set_name(GVirConfigDomainSnapshotDisk *disk, + const char *name); + +GVirConfigDomainDiskSnapshotType gvir_config_domain_snapshot_disk_get_snapshot_type(GVirConfigDomainSnapshotDisk *disk); +void gvir_config_domain_snapshot_disk_set_snapshot_type(GVirConfigDomainSnapshotDisk *disk, + GVirConfigDomainDiskSnapshotType type); + +const char *gvir_config_domain_snapshot_disk_get_source_file(GVirConfigDomainSnapshotDisk *disk); +void gvir_config_domain_snapshot_disk_set_source_file(GVirConfigDomainSnapshotDisk *disk, + const char *filename); + +GVirConfigDomainDiskFormat gvir_config_domain_snapshot_disk_get_driver_type(GVirConfigDomainSnapshotDisk *disk); +void gvir_config_domain_snapshot_disk_set_driver_type(GVirConfigDomainSnapshotDisk *disk, + GVirConfigDomainDiskFormat type); + G_END_DECLS #endif /* __LIBVIRT_GCONFIG_DOMAIN_SNAPSHOT_DISK_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 0a0b1f1..f5a1b6c 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -565,6 +565,15 @@ LIBVIRT_GCONFIG_0.1.7 { gvir_config_domain_snapshot_disk_get_type; gvir_config_domain_snapshot_disk_new; gvir_config_domain_snapshot_disk_new_from_xml; + + gvir_config_domain_snapshot_disk_get_driver_type; + gvir_config_domain_snapshot_disk_set_driver_type; + gvir_config_domain_snapshot_disk_get_name; + gvir_config_domain_snapshot_disk_set_name; + gvir_config_domain_snapshot_disk_get_snapshot_type; + gvir_config_domain_snapshot_disk_set_snapshot_type; + gvir_config_domain_snapshot_disk_get_source_file; + gvir_config_domain_snapshot_disk_set_source_file; } LIBVIRT_GCONFIG_0.1.6; # .... define new API here using predicted next version number .... -- 1.8.2.1

--- libvirt-gconfig/libvirt-gconfig-domain-snapshot.c | 252 +++++++++++++++++++++- libvirt-gconfig/libvirt-gconfig-domain-snapshot.h | 48 ++++- libvirt-gconfig/libvirt-gconfig.sym | 18 ++ 3 files changed, 316 insertions(+), 2 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c b/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c index 3d967f1..fc9a130 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c @@ -2,7 +2,7 @@ * libvirt-gconfig-domain-snapshot.c: libvirt domain snapshot configuration * * Copyright (C) 2008 Daniel P. Berrange - * Copyright (C) 2010-2011 Red Hat, Inc. + * Copyright (C) 2010-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 @@ -19,11 +19,13 @@ * <http://www.gnu.org/licenses/>. * * Author: Daniel P. Berrange <berrange@redhat.com> + * 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_SNAPSHOT_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT, GVirConfigDomainSnapshotPrivate)) @@ -71,3 +73,251 @@ GVirConfigDomainSnapshot *gvir_config_domain_snapshot_new_from_xml(const gchar * xml, error); return GVIR_CONFIG_DOMAIN_SNAPSHOT(object); } + + +const char *gvir_config_domain_snapshot_get_name(GVirConfigDomainSnapshot *snapshot) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL); + + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(snapshot), + "name"); +} + + +void gvir_config_domain_snapshot_set_name(GVirConfigDomainSnapshot *snapshot, + const char *name) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot)); + + gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(snapshot), + "name", name); +} + + +const char *gvir_config_domain_snapshot_get_description(GVirConfigDomainSnapshot *snapshot) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL); + + return gvir_config_object_get_node_content(GVIR_CONFIG_OBJECT(snapshot), + "description"); +} + + +void gvir_config_domain_snapshot_set_description(GVirConfigDomainSnapshot *snapshot, + const char *description) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot)); + + gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(snapshot), + "description", description); +} + + +GVirConfigDomainSnapshotMemoryState gvir_config_domain_snapshot_get_memory_state(GVirConfigDomainSnapshot *snapshot) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), + GVIR_CONFIG_DOMAIN_SNAPSHOT_MEMORY_STATE_NONE); + + return gvir_config_object_get_attribute_genum(GVIR_CONFIG_OBJECT(snapshot), + "memory", "snapshot", + GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_MEMORY_STATE, + GVIR_CONFIG_DOMAIN_SNAPSHOT_MEMORY_STATE_NONE); +} + + +void gvir_config_domain_snapshot_set_memory_state(GVirConfigDomainSnapshot *snapshot, + GVirConfigDomainSnapshotMemoryState state) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot)); + + gvir_config_object_add_child_with_attribute_enum(GVIR_CONFIG_OBJECT(snapshot), + "memory", "snapshot", + GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_MEMORY_STATE, + state); +} + + +const char *gvir_config_domain_snapshot_get_memory_file(GVirConfigDomainSnapshot *snapshot) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL); + + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(snapshot), + "memory", "file"); +} + + +void gvir_config_domain_snapshot_set_memory_file(GVirConfigDomainSnapshot *snapshot, + const char *filename) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot)); + + gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(snapshot), + "memory", "file", filename); +} + + +time_t gvir_config_domain_snapshot_get_creation_time(GVirConfigDomainSnapshot *snapshot) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), 0); + + return gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(snapshot), + "creationTime"); +} + + +GVirConfigDomainSnapshotDomainState gvir_config_domain_snapshot_get_state(GVirConfigDomainSnapshot *snapshot) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), + GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_NOSTATE); + + return gvir_config_object_get_node_content_genum(GVIR_CONFIG_OBJECT(snapshot), + "state", + GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_DOMAIN_STATE, + GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_NOSTATE); +} + + +const char *gvir_config_domain_snapshot_get_parent(GVirConfigDomainSnapshot *snapshot) +{ + GVirConfigObject *parent; + const char *parent_name; + + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL); + + parent = gvir_config_object_get_child(GVIR_CONFIG_OBJECT(snapshot), + "parent"); + if (parent == NULL) + return NULL; + + parent_name = gvir_config_object_get_node_content(parent, "name"); + g_object_unref(G_OBJECT(parent)); + + return parent_name; +} + + +/** + * gvir_config_domain_snapshot_get_domain: + * @snapshot: a #GVirConfigDomainSnapshot + * + * Gets the configuration of the domain @snapshot is a snapshot of. + * + * Returns: (transfer full): A #GVirConfigDomain. The returned object + * should be unreffed with g_object_unref() when no longer needed. + */ +GVirConfigDomain *gvir_config_domain_snapshot_get_domain(GVirConfigDomainSnapshot *snapshot) +{ + GVirConfigObject *domain; + + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL); + + domain = gvir_config_object_get_child_with_type(GVIR_CONFIG_OBJECT(snapshot), + "domain", + GVIR_CONFIG_TYPE_DOMAIN); + + return GVIR_CONFIG_DOMAIN(domain); +} + + +/** + * gvir_config_domain_snapshot_set_disks: + * @snapshot: a #GVirConfigDomainSnapshot + * @disks: (in) (element-type LibvirtGConfig.DomainSnapshotDisk): + */ +void gvir_config_domain_snapshot_set_disks(GVirConfigDomainSnapshot *snapshot, + GList *disks) +{ + GVirConfigObject *disks_node; + GList *it; + + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot)); + + if (disks == NULL) { + gvir_config_object_delete_children(GVIR_CONFIG_OBJECT(snapshot), + "disks", + NULL); + return; + } + + disks_node = gvir_config_object_new(GVIR_CONFIG_TYPE_OBJECT, + "disks", NULL); + + for (it = disks; it != NULL; it = it->next) { + if (!GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK(it->data)) { + g_warn_if_reached(); + continue; + } + gvir_config_object_attach_add(disks_node, + GVIR_CONFIG_OBJECT(it->data)); + } + + gvir_config_object_attach_replace(GVIR_CONFIG_OBJECT(snapshot), + "disks", + disks_node); + g_object_unref(G_OBJECT(disks_node)); +} + + +void gvir_config_domain_snapshot_add_disk(GVirConfigDomainSnapshot *snapshot, + GVirConfigDomainSnapshotDisk *disk) +{ + GVirConfigObject *disks_node; + + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot)); + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK(disk)); + + disks_node = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(snapshot), + "disks"); + + gvir_config_object_attach_add(disks_node, GVIR_CONFIG_OBJECT(disk)); + g_object_unref(G_OBJECT(disks_node)); +} + + +struct GetDiskData { + GVirConfigXmlDoc *doc; + GList *disks; +}; + +static gboolean get_disk(xmlNodePtr node, gpointer opaque) +{ + struct GetDiskData* data = (struct GetDiskData*)opaque; + GVirConfigDomainSnapshotDisk *disk; + + disk = gvir_config_domain_snapshot_disk_new_from_tree(data->doc, node); + if (disk != NULL) + data->disks = g_list_prepend(data->disks, disk); + else + g_debug("Failed to parse %s node", node->name); + + return TRUE; +} + + +/** + * gvir_config_domain_snapshot_get_disks: + * @snapshot: a #GVirConfigDomainSnapshot + * + * Gets the list of disks attached to @snapshot. The returned list should + * be freed with g_list_free(), after its elements have been unreffed with + * g_object_unref(). + * + * Returns: (element-type LibvirtGConfig.DomainSnapshotDisk) (transfer full): + * a newly allocated #GList of #GVirConfigDomainSnapshotDisk. + */ +GList *gvir_config_domain_snapshot_get_disks(GVirConfigDomainSnapshot *snapshot) +{ + struct GetDiskData data; + + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL); + + g_object_get(G_OBJECT(snapshot), "doc", &data.doc, NULL); + data.disks = NULL; + gvir_config_object_foreach_child(GVIR_CONFIG_OBJECT(snapshot), "disks", + get_disk, &data); + if (data.doc != NULL) { + g_object_unref(G_OBJECT(data.doc)); + } + + return g_list_reverse(data.disks); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot.h b/libvirt-gconfig/libvirt-gconfig-domain-snapshot.h index 49c1d17..00d7019 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-snapshot.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-snapshot.h @@ -1,7 +1,7 @@ /* * libvirt-gconfig-domain-snapshot.h: libvirt domain snapshot configuration * - * Copyright (C) 2010-2011 Red Hat, Inc. + * Copyright (C) 2010-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 @@ -18,6 +18,7 @@ * <http://www.gnu.org/licenses/>. * * Author: Daniel P. Berrange <berrange@redhat.com> + * Christophe Fergeau <cfergeau@redhat.com> */ #if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) @@ -27,6 +28,9 @@ #ifndef __LIBVIRT_GCONFIG_DOMAIN_SNAPSHOT_H__ #define __LIBVIRT_GCONFIG_DOMAIN_SNAPSHOT_H__ +#include <libvirt-gconfig/libvirt-gconfig-domain.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.h> + G_BEGIN_DECLS #define GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT (gvir_config_domain_snapshot_get_type ()) @@ -56,6 +60,26 @@ struct _GVirConfigDomainSnapshotClass gpointer padding[20]; }; +typedef enum { + GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_NOSTATE = 0, /* no state */ + GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_RUNNING = 1, /* the domain is running */ + GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_BLOCKED = 2, /* the domain is blocked on resource */ + GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_PAUSED = 3, /* the domain is paused by user */ + GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_SHUTDOWN= 4, /* the domain is being shut down */ + GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_SHUTOFF = 5, /* the domain is shut off */ + GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_CRASHED = 6, /* the domain is crashed */ + GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_PMSUSPENDED = 7, /* the domain is suspended by guest + power management */ + GVIR_CONFIG_DOMAIN_SNAPSHOT_DOMAIN_STATE_DISK_SNAPSHOT = 100 +} GVirConfigDomainSnapshotDomainState; + + +typedef enum { + GVIR_CONFIG_DOMAIN_SNAPSHOT_MEMORY_STATE_NONE, + GVIR_CONFIG_DOMAIN_SNAPSHOT_MEMORY_STATE_INTERNAL, + GVIR_CONFIG_DOMAIN_SNAPSHOT_MEMORY_STATE_EXTERNAL, +} GVirConfigDomainSnapshotMemoryState; + GType gvir_config_domain_snapshot_get_type(void); @@ -63,6 +87,28 @@ GVirConfigDomainSnapshot *gvir_config_domain_snapshot_new(void); GVirConfigDomainSnapshot *gvir_config_domain_snapshot_new_from_xml(const gchar *xml, GError **error); +const char *gvir_config_domain_snapshot_get_name(GVirConfigDomainSnapshot *snapshot); +void gvir_config_domain_snapshot_set_name(GVirConfigDomainSnapshot *snapshot, + const char *name); +const char *gvir_config_domain_snapshot_get_description(GVirConfigDomainSnapshot *snapshot); +void gvir_config_domain_snapshot_set_description(GVirConfigDomainSnapshot *snapshot, + const char *description); +GVirConfigDomainSnapshotMemoryState gvir_config_domain_snapshot_get_memory_state(GVirConfigDomainSnapshot *snapshot); +void gvir_config_domain_snapshot_set_memory_state(GVirConfigDomainSnapshot *snapshot, + GVirConfigDomainSnapshotMemoryState state); +const char *gvir_config_domain_snapshot_get_memory_file(GVirConfigDomainSnapshot *snapshot); +void gvir_config_domain_snapshot_set_memory_file(GVirConfigDomainSnapshot *snapshot, + const char *filename); +time_t gvir_config_domain_snapshot_get_creation_time(GVirConfigDomainSnapshot *snapshot); +GVirConfigDomainSnapshotDomainState gvir_config_domain_snapshot_get_state(GVirConfigDomainSnapshot *snapshot); +const char *gvir_config_domain_snapshot_get_parent(GVirConfigDomainSnapshot *snapshot); +GVirConfigDomain *gvir_config_domain_snapshot_get_domain(GVirConfigDomainSnapshot *snapshot); +void gvir_config_domain_snapshot_set_disks(GVirConfigDomainSnapshot *snapshot, + GList *disks); +void gvir_config_domain_snapshot_add_disk(GVirConfigDomainSnapshot *snapshot, + GVirConfigDomainSnapshotDisk *disk); +GList *gvir_config_domain_snapshot_get_disks(GVirConfigDomainSnapshot *snapshot); + G_END_DECLS #endif /* __LIBVIRT_GCONFIG_DOMAIN_SNAPSHOT_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index f5a1b6c..c6f9436 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -562,6 +562,24 @@ LIBVIRT_GCONFIG_0.1.7 { gvir_config_storage_pool_target_get_path; gvir_config_storage_pool_target_get_permissions; + gvir_config_domain_snapshot_domain_state_get_type; + gvir_config_domain_snapshot_memory_state_get_type; + gvir_config_domain_snapshot_get_creation_time; + gvir_config_domain_snapshot_get_description; + gvir_config_domain_snapshot_set_description; + gvir_config_domain_snapshot_get_domain; + gvir_config_domain_snapshot_get_memory_state; + gvir_config_domain_snapshot_set_memory_state; + gvir_config_domain_snapshot_get_memory_file; + gvir_config_domain_snapshot_set_memory_file; + gvir_config_domain_snapshot_get_name; + gvir_config_domain_snapshot_set_name; + gvir_config_domain_snapshot_get_parent; + gvir_config_domain_snapshot_get_state; + gvir_config_domain_snapshot_get_disks; + gvir_config_domain_snapshot_add_disk; + gvir_config_domain_snapshot_set_disks; + gvir_config_domain_snapshot_disk_get_type; gvir_config_domain_snapshot_disk_new; gvir_config_domain_snapshot_disk_new_from_xml; -- 1.8.2.1
participants (2)
-
Christophe Fergeau
-
Daniel P. Berrange