[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv4 18/51] snapshot: identify qemu snapshot roots



Filtering for roots is pretty easy to do.

* src/conf/domain_conf.h (virDomainSnapshotObjListGetNames)
(virDomainSnapshotObjListNum): Update prototype.
* src/conf/domain_conf.c (virDomainSnapshotObjListCopyNames)
(virDomainSnapshotObjListGetNames, virDomainSnapshotObjListCount)
(virDomainSnapshotObjListNum): Support filtering.
* src/qemu/qemu_driver.c (qemuDomainSnapshotNum)
(qemuDomainSnapshotListNames): Update callers.
---
 src/conf/domain_conf.c |   33 +++++++++++++++++++++++----------
 src/conf/domain_conf.h |    6 ++++--
 src/qemu/qemu_driver.c |   11 +++++++----
 3 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3f3d2bb..1b2fd61 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11157,6 +11157,7 @@ struct virDomainSnapshotNameData {
     int numnames;
     int maxnames;
     char **const names;
+    unsigned int flags;
 };

 static void virDomainSnapshotObjListCopyNames(void *payload,
@@ -11168,6 +11169,8 @@ static void virDomainSnapshotObjListCopyNames(void *payload,

     if (data->oom)
         return;
+    if ((data->flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) && obj->def->parent)
+        return;

     if (data->numnames < data->maxnames) {
         if (!(data->names[data->numnames] = strdup(obj->def->name)))
@@ -11178,9 +11181,10 @@ static void virDomainSnapshotObjListCopyNames(void *payload,
 }

 int virDomainSnapshotObjListGetNames(virDomainSnapshotObjListPtr snapshots,
-                                     char **const names, int maxnames)
+                                     char **const names, int maxnames,
+                                     unsigned int flags)
 {
-    struct virDomainSnapshotNameData data = { 0, 0, maxnames, names };
+    struct virDomainSnapshotNameData data = { 0, 0, maxnames, names, flags };
     int i;

     virHashForEach(snapshots->objs, virDomainSnapshotObjListCopyNames, &data);
@@ -11197,22 +11201,31 @@ cleanup:
     return -1;
 }

-static void virDomainSnapshotObjListCount(void *payload ATTRIBUTE_UNUSED,
+struct virDomainSnapshotNumData {
+    int count;
+    unsigned int flags;
+};
+
+static void virDomainSnapshotObjListCount(void *payload,
                                           const void *name ATTRIBUTE_UNUSED,
-                                          void *data)
+                                          void *opaque)
 {
-    int *count = data;
+    virDomainSnapshotObjPtr obj = payload;
+    struct virDomainSnapshotNumData *data = opaque;

-    (*count)++;
+    if ((data->flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) && obj->def->parent)
+        return;
+    data->count++;
 }

-int virDomainSnapshotObjListNum(virDomainSnapshotObjListPtr snapshots)
+int virDomainSnapshotObjListNum(virDomainSnapshotObjListPtr snapshots,
+                                unsigned int flags)
 {
-    int count = 0;
+    struct virDomainSnapshotNumData data = { 0, flags };

-    virHashForEach(snapshots->objs, virDomainSnapshotObjListCount, &count);
+    virHashForEach(snapshots->objs, virDomainSnapshotObjListCount, &data);

-    return count;
+    return data.count;
 }

 virDomainSnapshotObjPtr
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 5f752ec..503fb58 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1335,8 +1335,10 @@ virDomainSnapshotObjPtr virDomainSnapshotAssignDef(virDomainSnapshotObjListPtr s

 int virDomainSnapshotObjListInit(virDomainSnapshotObjListPtr objs);
 int virDomainSnapshotObjListGetNames(virDomainSnapshotObjListPtr snapshots,
-                                     char **const names, int maxnames);
-int virDomainSnapshotObjListNum(virDomainSnapshotObjListPtr snapshots);
+                                     char **const names, int maxnames,
+                                     unsigned int flags);
+int virDomainSnapshotObjListNum(virDomainSnapshotObjListPtr snapshots,
+                                unsigned int flags);
 virDomainSnapshotObjPtr virDomainSnapshotFindByName(const virDomainSnapshotObjListPtr snapshots,
                                                     const char *name);
 void virDomainSnapshotObjListRemove(virDomainSnapshotObjListPtr snapshots,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index dcb3661..840c444 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -8676,7 +8676,8 @@ static int qemuDomainSnapshotListNames(virDomainPtr domain, char **names,
     virDomainObjPtr vm = NULL;
     int n = -1;

-    virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
+    virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
+                  VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);

     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, domain->uuid);
@@ -8688,7 +8689,8 @@ static int qemuDomainSnapshotListNames(virDomainPtr domain, char **names,
         goto cleanup;
     }

-    n = virDomainSnapshotObjListGetNames(&vm->snapshots, names, nameslen);
+    n = virDomainSnapshotObjListGetNames(&vm->snapshots, names, nameslen,
+                                         flags);

 cleanup:
     if (vm)
@@ -8704,7 +8706,8 @@ static int qemuDomainSnapshotNum(virDomainPtr domain,
     virDomainObjPtr vm = NULL;
     int n = -1;

-    virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
+    virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
+                  VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);

     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, domain->uuid);
@@ -8720,7 +8723,7 @@ static int qemuDomainSnapshotNum(virDomainPtr domain,
      * VIR_DOMAIN_SNAPSHOT_LIST_METADATA makes no difference to our
      * answer.  */

-    n = virDomainSnapshotObjListNum(&vm->snapshots);
+    n = virDomainSnapshotObjListNum(&vm->snapshots, flags);

 cleanup:
     if (vm)
-- 
1.7.4.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]