From 6b3801b04263c4c0303fb340f5e6d89e40def900 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Sat, 13 Aug 2011 11:18:44 -0600 Subject: [PATCH] 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 f52dc3fefd..0def87c0aa 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11579,6 +11579,7 @@ struct virDomainSnapshotNameData { int numnames; int maxnames; char **const names; + unsigned int flags; }; static void virDomainSnapshotObjListCopyNames(void *payload, @@ -11590,6 +11591,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))) @@ -11600,9 +11603,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); @@ -11619,22 +11623,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 7f69ea05f7..f970782b7e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1418,8 +1418,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 118e818988..886fb6d954 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8712,7 +8712,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); @@ -8724,7 +8725,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) @@ -8740,7 +8742,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); @@ -8756,7 +8759,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) -- GitLab