Re: [libvirt] [PATCH libvirt-glib 3/6] Add GVirDomainDisk

2011-11-14 Thread Christophe Fergeau
On Mon, Nov 14, 2011 at 01:50:04PM +0100, Marc-André Lureau wrote:
> +/**
> + * gvir_domain_disk_get_stats:
> + * @self: the domain disk
> + * @err: an error
> + *
> + * This function returns network disk stats. Individual fields
> + * within the stats structure may be returned as -1, which indicates
> + * that the hypervisor does not support that particular statistic.
> + *
> + * Returns: (transfer full): the stats or %NULL in case of error
> + **/
> +GVirDomainDiskStats *gvir_domain_disk_get_stats(GVirDomainDisk *self, GError 
> **err)
> +{
> +GVirDomainDiskStats *ret = NULL;
> +virDomainBlockStatsStruct stats;
> +GVirDomainDiskPrivate *priv;
> +virDomainPtr handle;
> +
> +g_return_val_if_fail(GVIR_IS_DOMAIN_DISK(self), NULL);
> +
> +priv = self->priv;
> +handle = gvir_domain_device_get_domain_handle(GVIR_DOMAIN_DEVICE(self));
> +
> +if (virDomainBlockStats(handle, priv->path, &stats, sizeof (stats)) < 0) 
> {

Maybe we want to check if handle == NULL before calling into libvirt?
I checked that libvirt will return an error in this case.
(same question in patch 2/3)
(not an important issue, my ACK series still stand whatever you decide to
do about this)

Christophe


pgpNQoJJrLOju.pgp
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH libvirt-glib 3/6] Add GVirDomainDisk

2011-11-14 Thread Marc-André Lureau
---
 libvirt-gobject/Makefile.am   |2 +
 libvirt-gobject/libvirt-gobject-domain-disk.c |  208 +
 libvirt-gobject/libvirt-gobject-domain-disk.h |   78 +
 libvirt-gobject/libvirt-gobject.h |1 +
 libvirt-gobject/libvirt-gobject.sym   |4 +
 5 files changed, 293 insertions(+), 0 deletions(-)
 create mode 100644 libvirt-gobject/libvirt-gobject-domain-disk.c
 create mode 100644 libvirt-gobject/libvirt-gobject-domain-disk.h

diff --git a/libvirt-gobject/Makefile.am b/libvirt-gobject/Makefile.am
index 8b59109..101007e 100644
--- a/libvirt-gobject/Makefile.am
+++ b/libvirt-gobject/Makefile.am
@@ -8,6 +8,7 @@ GOBJECT_HEADER_FILES = \
libvirt-gobject-main.h \
libvirt-gobject-domain-snapshot.h \
libvirt-gobject-domain-device.h \
+   libvirt-gobject-domain-disk.h \
libvirt-gobject-domain-interface.h \
libvirt-gobject-domain.h \
libvirt-gobject-interface.h \
@@ -24,6 +25,7 @@ GOBJECT_SOURCE_FILES = \
libvirt-gobject-main.c \
libvirt-gobject-domain-snapshot.c \
libvirt-gobject-domain-device.c \
+   libvirt-gobject-domain-disk.c \
libvirt-gobject-domain-interface.c \
libvirt-gobject-domain.c \
libvirt-gobject-interface.c \
diff --git a/libvirt-gobject/libvirt-gobject-domain-disk.c 
b/libvirt-gobject/libvirt-gobject-domain-disk.c
new file mode 100644
index 000..fcb2596
--- /dev/null
+++ b/libvirt-gobject/libvirt-gobject-domain-disk.c
@@ -0,0 +1,208 @@
+/*
+ * libvirt-gobject-domain-disk.c: libvirt gobject integration
+ *
+ * Copyright (C) 2011 Red Hat
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ * Author: Marc-André Lureau 
+ */
+
+#include 
+
+#include 
+#include 
+
+#include "libvirt-glib/libvirt-glib.h"
+#include "libvirt-gobject/libvirt-gobject.h"
+
+#include "libvirt-gobject/libvirt-gobject-domain-device-private.h"
+
+extern gboolean debugFlag;
+
+#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## 
__VA_ARGS__); } while (0)
+
+#define GVIR_DOMAIN_DISK_GET_PRIVATE(obj) \
+(G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_DOMAIN_DISK, 
GVirDomainDiskPrivate))
+
+struct _GVirDomainDiskPrivate
+{
+gchar *path;
+};
+
+G_DEFINE_TYPE(GVirDomainDisk, gvir_domain_disk, GVIR_TYPE_DOMAIN_DEVICE);
+
+enum {
+PROP_0,
+PROP_PATH,
+};
+
+#define GVIR_DOMAIN_DISK_ERROR gvir_domain_disk_error_quark()
+
+
+static GQuark
+gvir_domain_disk_error_quark(void)
+{
+return g_quark_from_static_string("gvir-domain-disk");
+}
+
+static void gvir_domain_disk_get_property(GObject *object,
+  guint prop_id,
+  GValue *value,
+  GParamSpec *pspec)
+{
+GVirDomainDisk *self = GVIR_DOMAIN_DISK(object);
+GVirDomainDiskPrivate *priv = self->priv;
+
+switch (prop_id) {
+case PROP_PATH:
+g_value_set_string(value, priv->path);
+break;
+
+default:
+G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+}
+}
+
+
+static void gvir_domain_disk_set_property(GObject *object,
+  guint prop_id,
+  const GValue *value,
+  GParamSpec *pspec)
+{
+GVirDomainDisk *self = GVIR_DOMAIN_DISK(object);
+GVirDomainDiskPrivate *priv = self->priv;
+
+switch (prop_id) {
+case PROP_PATH:
+g_free(priv->path);
+priv->path = g_value_dup_string(value);
+break;
+
+default:
+G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+}
+}
+
+
+static void gvir_domain_disk_finalize(GObject *object)
+{
+GVirDomainDisk *self = GVIR_DOMAIN_DISK(object);
+GVirDomainDiskPrivate *priv = self->priv;
+
+DEBUG("Finalize GVirDomainDisk=%p", self);
+
+g_free(priv->path);
+
+G_OBJECT_CLASS(gvir_domain_disk_parent_class)->finalize(object);
+}
+
+static void gvir_domain_dis