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

Hey, This patch series adds the needed setters/getters to libvirt-gconfig to be able to generate the libvirt XML described at http://libvirt.org/formatsnapshot.html One thing of note is gvir_config_domain_snapshot_get_creation_time() which returns a GDateTime, which was only added in glib 2.26 while libvirt-glib depends on glib 2.22. Alternatively, we can return a time_t instead. 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 ccddd88..9352e34 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -557,6 +557,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.1.4

--- .../libvirt-gconfig-domain-snapshot-disk.c | 81 ++++++++++++++++++++++ .../libvirt-gconfig-domain-snapshot-disk.h | 16 +++++ libvirt-gconfig/libvirt-gconfig.sym | 9 +++ 3 files changed, 106 insertions(+) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c index a21f0d6..8a346d3 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c @@ -86,3 +86,84 @@ 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); +} + + +const char *gvir_config_domain_snapshot_disk_get_driver_type(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), + "driver", "type"); +} + + +void gvir_config_domain_snapshot_disk_set_driver_type(GVirConfigDomainSnapshotDisk *disk, + const char *type) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK(disk)); + + gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(disk), + "driver", "type", type); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.h b/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.h index 9a73336..288a606 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); + +const char *gvir_config_domain_snapshot_disk_get_driver_type(GVirConfigDomainSnapshotDisk *disk); +void gvir_config_domain_snapshot_disk_set_driver_type(GVirConfigDomainSnapshotDisk *disk, + const char *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 9352e34..e8b4efe 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -561,6 +561,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.1.4

On Wed, May 1, 2013 at 10:59 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
--- .../libvirt-gconfig-domain-snapshot-disk.c | 81 ++++++++++++++++++++++ .../libvirt-gconfig-domain-snapshot-disk.h | 16 +++++ libvirt-gconfig/libvirt-gconfig.sym | 9 +++ 3 files changed, 106 insertions(+)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c b/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c index a21f0d6..8a346d3 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.c @@ -86,3 +86,84 @@ 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); +} + + +const char *gvir_config_domain_snapshot_disk_get_driver_type(GVirConfigDomainSnapshotDisk *disk)
Shouldn't 'driver_type' be an enum?
+{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK(disk), NULL); + + return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(disk), + "driver", "type"); +} + + +void gvir_config_domain_snapshot_disk_set_driver_type(GVirConfigDomainSnapshotDisk *disk, + const char *type) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT_DISK(disk)); + + gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(disk), + "driver", "type", type); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.h b/libvirt-gconfig/libvirt-gconfig-domain-snapshot-disk.h index 9a73336..288a606 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); + +const char *gvir_config_domain_snapshot_disk_get_driver_type(GVirConfigDomainSnapshotDisk *disk); +void gvir_config_domain_snapshot_disk_set_driver_type(GVirConfigDomainSnapshotDisk *disk, + const char *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 9352e34..e8b4efe 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -561,6 +561,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;
Looks good otherwise. -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Thu, May 02, 2013 at 06:22:14PM +0300, Zeeshan Ali (Khattak) wrote:
On Wed, May 1, 2013 at 10:59 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+ + +const char *gvir_config_domain_snapshot_disk_get_driver_type(GVirConfigDomainSnapshotDisk *disk)
Shouldn't 'driver_type' be an enum?
libvirt is storing it internally as a string, see http://libvirt.org/git/?p=libvirt.git;a=blob;f=src/conf/snapshot_conf.c;h=5b... libvirt-gconfig generally follows what libvirt does when it comes to choosing between strings and enums. This is also consistent with gvir_config_domain_disk_set_driver_type(). However, the rng defines http://libvirt.org/git/?p=libvirt.git;a=blob;f=docs/schemas/domaincommon.rng... for this attribute. Daniel, any recommendation? Christophe

On Thu, May 2, 2013 at 6:36 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
On Thu, May 02, 2013 at 06:22:14PM +0300, Zeeshan Ali (Khattak) wrote:
On Wed, May 1, 2013 at 10:59 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+ + +const char *gvir_config_domain_snapshot_disk_get_driver_type(GVirConfigDomainSnapshotDisk *disk)
Shouldn't 'driver_type' be an enum?
libvirt is storing it internally as a string, see http://libvirt.org/git/?p=libvirt.git;a=blob;f=src/conf/snapshot_conf.c;h=5b... libvirt-gconfig generally follows what libvirt does when it comes to choosing between strings and enums.
I don't think that is true cause I see examples of enum setter/getters that translate to strings in libvirt xml. e.g GVirConfigDomainOsType, GVirConfigDomainOsSmBiosMode and GVirConfigDomainOsBootDevice. If we go with string option, I suggest we provide #defines for known values and document here that these can be used. Which in the end is not very diff from using enums from app POV. -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Thu, May 02, 2013 at 11:40:56PM +0300, Zeeshan Ali (Khattak) wrote:
On Thu, May 2, 2013 at 6:36 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
On Thu, May 02, 2013 at 06:22:14PM +0300, Zeeshan Ali (Khattak) wrote:
On Wed, May 1, 2013 at 10:59 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+ + +const char *gvir_config_domain_snapshot_disk_get_driver_type(GVirConfigDomainSnapshotDisk *disk)
Shouldn't 'driver_type' be an enum?
libvirt is storing it internally as a string, see http://libvirt.org/git/?p=libvirt.git;a=blob;f=src/conf/snapshot_conf.c;h=5b... libvirt-gconfig generally follows what libvirt does when it comes to choosing between strings and enums.
I don't think that is true cause I see examples of enum setter/getters that translate to strings in libvirt xml. e.g GVirConfigDomainOsType,
This one is indeed inconsistent, maybe it was added before danpb gave this rule of thumb for enum VS string, maybe the inconsistency was not noticed at review time.
GVirConfigDomainOsSmBiosMode
VIR_ENUM_IMPL(virDomainSmbiosMode, VIR_DOMAIN_SMBIOS_LAST, "none", "emulate", "host", "sysinfo")
and GVirConfigDomainOsBootDevice.
VIR_ENUM_IMPL(virDomainBoot, VIR_DOMAIN_BOOT_LAST, "fd", "cdrom", "hd", "network")
If we go with string option, I suggest we provide #defines for known values and document here that these can be used.
Sounds good, though this could be done in an additional patch as this would also be useful for disk devices. However, after a bit more research, http://libvirt.org/git/?p=libvirt.git;a=commit;h=e2c41e486018ee74f6a75c1f717... makes the enum case more compelling. Christophe

On Thu, May 02, 2013 at 11:17:49PM +0200, Christophe Fergeau wrote:
On Thu, May 02, 2013 at 11:40:56PM +0300, Zeeshan Ali (Khattak) wrote:
On Thu, May 2, 2013 at 6:36 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
On Thu, May 02, 2013 at 06:22:14PM +0300, Zeeshan Ali (Khattak) wrote:
On Wed, May 1, 2013 at 10:59 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+ + +const char *gvir_config_domain_snapshot_disk_get_driver_type(GVirConfigDomainSnapshotDisk *disk)
Shouldn't 'driver_type' be an enum?
libvirt is storing it internally as a string, see http://libvirt.org/git/?p=libvirt.git;a=blob;f=src/conf/snapshot_conf.c;h=5b... libvirt-gconfig generally follows what libvirt does when it comes to choosing between strings and enums.
I don't think that is true cause I see examples of enum setter/getters that translate to strings in libvirt xml. e.g GVirConfigDomainOsType,
This one is indeed inconsistent, maybe it was added before danpb gave this rule of thumb for enum VS string, maybe the inconsistency was not noticed at review time.
Yep, that one should have been an enum too.
If we go with string option, I suggest we provide #defines for known values and document here that these can be used.
Sounds good, though this could be done in an additional patch as this would also be useful for disk devices.
However, after a bit more research, http://libvirt.org/git/?p=libvirt.git;a=commit;h=e2c41e486018ee74f6a75c1f717... makes the enum case more compelling.
Yep, if the RNG is declaring an enum of values, we should expose it as an enum in the API imho. 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 :|

--- libvirt-gconfig/libvirt-gconfig-domain-snapshot.c | 227 +++++++++++++++++++++- libvirt-gconfig/libvirt-gconfig-domain-snapshot.h | 38 +++- libvirt-gconfig/libvirt-gconfig.sym | 15 ++ 3 files changed, 278 insertions(+), 2 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c b/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c index 3d967f1..a3cec0c 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,226 @@ 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); +} + +/* +const char *gvir_config_domain_snapshot_get_memory(GVirConfigDomainSnapshot *snapshot) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL); + + return NULL; +} + + +void gvir_config_domain_snapshot_set_memory(GVirConfigDomainSnapshot *snapshot, + const char *memory) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot)); +} +*/ + + +/* FIXME: GDateTime is only available since glib 2.26, libvirt-glib depends + * on glib 2.22, is the dep ok? + */ +GDateTime *gvir_config_domain_snapshot_get_creation_time(GVirConfigDomainSnapshot *snapshot) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL); + guint64 creation_time; + + creation_time = gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(snapshot), + "creationTime"); + return g_date_time_new_from_unix_utc(creation_time); +} + + +GVirConfigDomainSnapshotState gvir_config_domain_snapshot_get_state(GVirConfigDomainSnapshot *snapshot) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), + GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_NOSTATE); + + return gvir_config_object_get_node_content_genum(GVIR_CONFIG_OBJECT(snapshot), + "state", + GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_STATE, + GVIR_CONFIG_DOMAIN_SNAPSHOT_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"); + 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..7b0884e 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,19 @@ struct _GVirConfigDomainSnapshotClass gpointer padding[20]; }; +typedef enum { + GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_NOSTATE = 0, /* no state */ + GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_RUNNING = 1, /* the domain is running */ + GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_BLOCKED = 2, /* the domain is blocked on resource */ + GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_PAUSED = 3, /* the domain is paused by user */ + GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_SHUTDOWN= 4, /* the domain is being shut down */ + GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_SHUTOFF = 5, /* the domain is shut off */ + GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_CRASHED = 6, /* the domain is crashed */ + GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_PMSUSPENDED = 7, /* the domain is suspended by guest + power management */ + GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_DISK_SNAPSHOT = 100 +} GVirConfigDomainSnapshotState; + GType gvir_config_domain_snapshot_get_type(void); @@ -63,6 +80,25 @@ 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); +/*const char *gvir_config_domain_snapshot_get_memory(GVirConfigDomainSnapshot *snapshot); +void gvir_config_domain_snapshot_set_memory(GVirConfigDomainSnapshot *snapshot, + const char *memory);*/ +GDateTime *gvir_config_domain_snapshot_get_creation_time(GVirConfigDomainSnapshot *snapshot); +GVirConfigDomainSnapshotState 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 e8b4efe..16228fb 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -558,6 +558,21 @@ LIBVIRT_GCONFIG_0.1.7 { gvir_config_storage_pool_target_get_path; gvir_config_storage_pool_target_get_permissions; + gvir_config_domain_snapshot_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; + gvir_config_domain_snapshot_set_memory; + 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.1.4

On Wed, May 1, 2013 at 10:59 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
--- libvirt-gconfig/libvirt-gconfig-domain-snapshot.c | 227 +++++++++++++++++++++- libvirt-gconfig/libvirt-gconfig-domain-snapshot.h | 38 +++- libvirt-gconfig/libvirt-gconfig.sym | 15 ++ 3 files changed, 278 insertions(+), 2 deletions(-)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c b/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c index 3d967f1..a3cec0c 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,226 @@ 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); +} + +/* +const char *gvir_config_domain_snapshot_get_memory(GVirConfigDomainSnapshot *snapshot)
Why commented-out? AFAICT from the docs, this deserves a separate object.
+{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL); + + return NULL; +} + + +void gvir_config_domain_snapshot_set_memory(GVirConfigDomainSnapshot *snapshot, + const char *memory) +{ + g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot)); +} +*/ + + +/* FIXME: GDateTime is only available since glib 2.26, libvirt-glib depends + * on glib 2.22, is the dep ok? + */
time_t seems pretty appropriate here.
+GDateTime *gvir_config_domain_snapshot_get_creation_time(GVirConfigDomainSnapshot *snapshot) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL); + guint64 creation_time; + + creation_time = gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(snapshot), + "creationTime"); + return g_date_time_new_from_unix_utc(creation_time); +} + + +GVirConfigDomainSnapshotState gvir_config_domain_snapshot_get_state(GVirConfigDomainSnapshot *snapshot) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), + GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_NOSTATE); + + return gvir_config_object_get_node_content_genum(GVIR_CONFIG_OBJECT(snapshot), + "state", + GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_STATE, + GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_NOSTATE); +} + + +const char *gvir_config_domain_snapshot_get_parent(GVirConfigDomainSnapshot *snapshot) +{
Shouldn't this be returning a GVirConfigDomainSnapshot instance? -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Thu, May 02, 2013 at 06:33:44PM +0300, Zeeshan Ali (Khattak) wrote:
On Wed, May 1, 2013 at 10:59 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+ +/* +const char *gvir_config_domain_snapshot_get_memory(GVirConfigDomainSnapshot *snapshot)
Why commented-out? AFAICT from the docs, this deserves a separate object.
Ah, I knew I still had something to fix somewhere before sending this series, I just couldn't remember what, thanks! However, I'm not sure I'll go with a separate object, the doc says: "memory On input, this is an optional request for how to handle VM memory state. For an offline domain or a disk-only snapshot, attribute snapshot must be no, since there is no VM state saved; otherwise, the attribute can be internal if the memory state is piggy-backed with other internal disk state, or external along with a second attribute file giving the absolute path of the file holding the VM memory state. Since 1.0.1" This would mean GVirConfigDomainSnapshotMemoryNone, GVirConfigDomainSnapshotMemoryInternal and GVirConfigDomainSnapshotMemoryExternal classes so that we can expose the file attribute only on the last of these classes. The MemoryNone class seems a bit weird to me, and 3 classes to make an attribute optional sounds a bit overkill. I think I'll go with gvir_config_domain_snapshot_get_memory(); and gvir_config_domain_snapshot_get_memory_file(); which will return NULL unless the snapshot type is external.
+ +/* FIXME: GDateTime is only available since glib 2.26, libvirt-glib depends + * on glib 2.22, is the dep ok? + */
time_t seems pretty appropriate here.
Ok!
+GDateTime *gvir_config_domain_snapshot_get_creation_time(GVirConfigDomainSnapshot *snapshot) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), NULL); + guint64 creation_time; + + creation_time = gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(snapshot), + "creationTime"); + return g_date_time_new_from_unix_utc(creation_time); +} + + +GVirConfigDomainSnapshotState gvir_config_domain_snapshot_get_state(GVirConfigDomainSnapshot *snapshot) +{ + g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_SNAPSHOT(snapshot), + GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_NOSTATE); + + return gvir_config_object_get_node_content_genum(GVIR_CONFIG_OBJECT(snapshot), + "state", + GVIR_CONFIG_TYPE_DOMAIN_SNAPSHOT_STATE, + GVIR_CONFIG_DOMAIN_SNAPSHOT_STATE_NOSTATE); +} + + +const char *gvir_config_domain_snapshot_get_parent(GVirConfigDomainSnapshot *snapshot) +{
Shouldn't this be returning a GVirConfigDomainSnapshot instance?
Hmm, that's a good point, this is made a bit tricky because of the "Older versions of libvirt stored only a single child element, uuid". This was changed in 2011 for libvirt 0.9.5 by http://libvirt.org/git/?p=libvirt.git;a=commit;h=f609cb85ca11d6d178972e46ebe... Given that we already require libvirt 0.10.2, I'd say it's fine to ignore this 'older version' case. Christophe

On Fri, May 03, 2013 at 07:01:11PM +0200, Christophe Fergeau wrote:
On Thu, May 02, 2013 at 06:33:44PM +0300, Zeeshan Ali (Khattak) wrote:
On Wed, May 1, 2013 at 10:59 PM, Christophe Fergeau <cfergeau@redhat.com> wrote:
+ + +const char *gvir_config_domain_snapshot_get_parent(GVirConfigDomainSnapshot *snapshot) +{
Shouldn't this be returning a GVirConfigDomainSnapshot instance?
Hmm, that's a good point, this is made a bit tricky because of the "Older versions of libvirt stored only a single child element, uuid". This was changed in 2011 for libvirt 0.9.5 by http://libvirt.org/git/?p=libvirt.git;a=commit;h=f609cb85ca11d6d178972e46ebe... Given that we already require libvirt 0.10.2, I'd say it's fine to ignore this 'older version' case.
Actually I confused _get_parent() with _get_domain(), libvirt-gconfig does not have the list of snapshots available, so it cannot do that. libvirt-gobject could probably do that though. Christophe
participants (3)
-
Christophe Fergeau
-
Daniel P. Berrange
-
Zeeshan Ali (Khattak)