[libvirt] [PATCH v2 04/11] snapshot: Add virDomainSnapshotObjListFormat

Eric Blake posted 11 patches 6 years, 11 months ago
There is a newer version of this series
[libvirt] [PATCH v2 04/11] snapshot: Add virDomainSnapshotObjListFormat
Posted by Eric Blake 6 years, 11 months ago
Add a new function to output all of the domain's snapshots in one
buffer.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 src/conf/snapshot_conf.h |  8 +++++++-
 src/conf/snapshot_conf.c | 39 +++++++++++++++++++++++++++++++++++++++
 src/libvirt_private.syms |  1 +
 3 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h
index 4d6e6134a3..19ab75f895 100644
--- a/src/conf/snapshot_conf.h
+++ b/src/conf/snapshot_conf.h
@@ -1,7 +1,7 @@
 /*
  * snapshot_conf.h: domain snapshot XML processing
  *
- * Copyright (C) 2006-2014 Red Hat, Inc.
+ * Copyright (C) 2006-2019 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -123,6 +123,12 @@ char *virDomainSnapshotDefFormat(const char *uuidstr,
                                  virCapsPtr caps,
                                  virDomainXMLOptionPtr xmlopt,
                                  unsigned int flags);
+int virDomainSnapshotObjListFormat(virBufferPtr buf,
+                                   const char *uuidstr,
+                                   virDomainSnapshotObjListPtr snapshots,
+                                   virCapsPtr caps,
+                                   virDomainXMLOptionPtr xmlopt,
+                                   unsigned int flags);
 int virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr snapshot,
                                 int default_snapshot,
                                 bool require_match);
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index 5cb977336a..a572da5b58 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -803,6 +803,45 @@ virDomainSnapshotDefFormat(const char *uuidstr,
     return virBufferContentAndReset(&buf);
 }

+struct virDomainSnapshotFormatData {
+    virBufferPtr buf;
+    const char *uuidstr;
+    virCapsPtr caps;
+    virDomainXMLOptionPtr xmlopt;
+    unsigned int flags;
+};
+
+static int
+virDomainSnapshotFormatOne(void *payload, const void *name ATTRIBUTE_UNUSED,
+                           void *opaque)
+{
+    virDomainSnapshotObjPtr snap = payload;
+    struct virDomainSnapshotFormatData *data = opaque;
+    return virDomainSnapshotDefFormatInternal(data->buf, data->uuidstr,
+                                              snap->def, data->caps,
+                                              data->xmlopt, data->flags);
+}
+
+
+int
+virDomainSnapshotObjListFormat(virBufferPtr buf,
+                               const char *uuidstr,
+                               virDomainSnapshotObjListPtr snapshots,
+                               virCapsPtr caps,
+                               virDomainXMLOptionPtr xmlopt,
+                               unsigned int flags)
+{
+    struct virDomainSnapshotFormatData data = {
+        .buf = buf,
+        .uuidstr = uuidstr,
+        .caps = caps,
+        .xmlopt = xmlopt,
+        .flags = flags,
+    };
+    return virDomainSnapshotForEach(snapshots, virDomainSnapshotFormatOne,
+                                    &data);
+}
+
 /* Snapshot Obj functions */
 static virDomainSnapshotObjPtr virDomainSnapshotObjNew(void)
 {
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6bfb497648..c623737c30 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -891,6 +891,7 @@ virDomainSnapshotFormatConvertXMLFlags;
 virDomainSnapshotIsExternal;
 virDomainSnapshotLocationTypeFromString;
 virDomainSnapshotLocationTypeToString;
+virDomainSnapshotObjListFormat;
 virDomainSnapshotObjListFree;
 virDomainSnapshotObjListGetNames;
 virDomainSnapshotObjListNew;
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 04/11] snapshot: Add virDomainSnapshotObjListFormat
Posted by John Ferlan 6 years, 11 months ago

On 2/23/19 4:24 PM, Eric Blake wrote:
> Add a new function to output all of the domain's snapshots in one
> buffer.
> 
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
>  src/conf/snapshot_conf.h |  8 +++++++-
>  src/conf/snapshot_conf.c | 39 +++++++++++++++++++++++++++++++++++++++
>  src/libvirt_private.syms |  1 +
>  3 files changed, 47 insertions(+), 1 deletion(-)
> 

[...]

> diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
> index 5cb977336a..a572da5b58 100644
> --- a/src/conf/snapshot_conf.c
> +++ b/src/conf/snapshot_conf.c
> @@ -803,6 +803,45 @@ virDomainSnapshotDefFormat(const char *uuidstr,
>      return virBufferContentAndReset(&buf);
>  }
> 
> +struct virDomainSnapshotFormatData {
> +    virBufferPtr buf;
> +    const char *uuidstr;
> +    virCapsPtr caps;
> +    virDomainXMLOptionPtr xmlopt;
> +    unsigned int flags;
> +};
> +
> +static int
> +virDomainSnapshotFormatOne(void *payload, const void *name ATTRIBUTE_UNUSED,

One arg per line.

> +                           void *opaque)
> +{
> +    virDomainSnapshotObjPtr snap = payload;
> +    struct virDomainSnapshotFormatData *data = opaque;
> +    return virDomainSnapshotDefFormatInternal(data->buf, data->uuidstr,
> +                                              snap->def, data->caps,
> +                                              data->xmlopt, data->flags);
> +}
> +
> +

There's no parameter and method description here leading me to wonder...

> +int
> +virDomainSnapshotObjListFormat(virBufferPtr buf,
> +                               const char *uuidstr,
> +                               virDomainSnapshotObjListPtr snapshots,
> +                               virCapsPtr caps,
> +                               virDomainXMLOptionPtr xmlopt,
> +                               unsigned int flags)
> +{
> +    struct virDomainSnapshotFormatData data = {
> +        .buf = buf,
> +        .uuidstr = uuidstr,
> +        .caps = caps,
> +        .xmlopt = xmlopt,
> +        .flags = flags,
> +    };

...Hmm... so should this also clear and reset buffer if
virDomainSnapshotForEach returns -1 or trust the caller to do that?

With a bit of extra docs and since I have read the next patch...

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

> +    return virDomainSnapshotForEach(snapshots, virDomainSnapshotFormatOne,
> +                                    &data);
> +}
> +
>  /* Snapshot Obj functions */
>  static virDomainSnapshotObjPtr virDomainSnapshotObjNew(void)
>  {
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 6bfb497648..c623737c30 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -891,6 +891,7 @@ virDomainSnapshotFormatConvertXMLFlags;
>  virDomainSnapshotIsExternal;
>  virDomainSnapshotLocationTypeFromString;
>  virDomainSnapshotLocationTypeToString;
> +virDomainSnapshotObjListFormat;
>  virDomainSnapshotObjListFree;
>  virDomainSnapshotObjListGetNames;
>  virDomainSnapshotObjListNew;
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list