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 01bbd04..f48051a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11155,6 +11155,7 @@ struct virDomainSnapshotNameData {
int numnames;
int maxnames;
char **const names;
+ unsigned int flags;
};
static void virDomainSnapshotObjListCopyNames(void *payload,
@@ -11166,6 +11167,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)))
@@ -11176,9 +11179,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);
@@ -11195,22 +11199,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;
}
static int virDomainSnapshotObjListSearchName(const void *payload,
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 9dd1ceb..d2cb1d7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -8544,7 +8544,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);
@@ -8556,7 +8557,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)
@@ -8572,7 +8574,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);
@@ -8588,7 +8591,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