提交 6b3801b0 编写于 作者: E Eric Blake

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.
上级 22a833e7
...@@ -11579,6 +11579,7 @@ struct virDomainSnapshotNameData { ...@@ -11579,6 +11579,7 @@ struct virDomainSnapshotNameData {
int numnames; int numnames;
int maxnames; int maxnames;
char **const names; char **const names;
unsigned int flags;
}; };
static void virDomainSnapshotObjListCopyNames(void *payload, static void virDomainSnapshotObjListCopyNames(void *payload,
...@@ -11590,6 +11591,8 @@ static void virDomainSnapshotObjListCopyNames(void *payload, ...@@ -11590,6 +11591,8 @@ static void virDomainSnapshotObjListCopyNames(void *payload,
if (data->oom) if (data->oom)
return; return;
if ((data->flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) && obj->def->parent)
return;
if (data->numnames < data->maxnames) { if (data->numnames < data->maxnames) {
if (!(data->names[data->numnames] = strdup(obj->def->name))) if (!(data->names[data->numnames] = strdup(obj->def->name)))
...@@ -11600,9 +11603,10 @@ static void virDomainSnapshotObjListCopyNames(void *payload, ...@@ -11600,9 +11603,10 @@ static void virDomainSnapshotObjListCopyNames(void *payload,
} }
int virDomainSnapshotObjListGetNames(virDomainSnapshotObjListPtr snapshots, 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; int i;
virHashForEach(snapshots->objs, virDomainSnapshotObjListCopyNames, &data); virHashForEach(snapshots->objs, virDomainSnapshotObjListCopyNames, &data);
...@@ -11619,22 +11623,31 @@ cleanup: ...@@ -11619,22 +11623,31 @@ cleanup:
return -1; 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, 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 virDomainSnapshotObjPtr
......
...@@ -1418,8 +1418,10 @@ virDomainSnapshotObjPtr virDomainSnapshotAssignDef(virDomainSnapshotObjListPtr s ...@@ -1418,8 +1418,10 @@ virDomainSnapshotObjPtr virDomainSnapshotAssignDef(virDomainSnapshotObjListPtr s
int virDomainSnapshotObjListInit(virDomainSnapshotObjListPtr objs); int virDomainSnapshotObjListInit(virDomainSnapshotObjListPtr objs);
int virDomainSnapshotObjListGetNames(virDomainSnapshotObjListPtr snapshots, int virDomainSnapshotObjListGetNames(virDomainSnapshotObjListPtr snapshots,
char **const names, int maxnames); char **const names, int maxnames,
int virDomainSnapshotObjListNum(virDomainSnapshotObjListPtr snapshots); unsigned int flags);
int virDomainSnapshotObjListNum(virDomainSnapshotObjListPtr snapshots,
unsigned int flags);
virDomainSnapshotObjPtr virDomainSnapshotFindByName(const virDomainSnapshotObjListPtr snapshots, virDomainSnapshotObjPtr virDomainSnapshotFindByName(const virDomainSnapshotObjListPtr snapshots,
const char *name); const char *name);
void virDomainSnapshotObjListRemove(virDomainSnapshotObjListPtr snapshots, void virDomainSnapshotObjListRemove(virDomainSnapshotObjListPtr snapshots,
......
...@@ -8712,7 +8712,8 @@ static int qemuDomainSnapshotListNames(virDomainPtr domain, char **names, ...@@ -8712,7 +8712,8 @@ static int qemuDomainSnapshotListNames(virDomainPtr domain, char **names,
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
int n = -1; int n = -1;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1); virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
qemuDriverLock(driver); qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, domain->uuid); vm = virDomainFindByUUID(&driver->domains, domain->uuid);
...@@ -8724,7 +8725,8 @@ static int qemuDomainSnapshotListNames(virDomainPtr domain, char **names, ...@@ -8724,7 +8725,8 @@ static int qemuDomainSnapshotListNames(virDomainPtr domain, char **names,
goto cleanup; goto cleanup;
} }
n = virDomainSnapshotObjListGetNames(&vm->snapshots, names, nameslen); n = virDomainSnapshotObjListGetNames(&vm->snapshots, names, nameslen,
flags);
cleanup: cleanup:
if (vm) if (vm)
...@@ -8740,7 +8742,8 @@ static int qemuDomainSnapshotNum(virDomainPtr domain, ...@@ -8740,7 +8742,8 @@ static int qemuDomainSnapshotNum(virDomainPtr domain,
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
int n = -1; int n = -1;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1); virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
qemuDriverLock(driver); qemuDriverLock(driver);
vm = virDomainFindByUUID(&driver->domains, domain->uuid); vm = virDomainFindByUUID(&driver->domains, domain->uuid);
...@@ -8756,7 +8759,7 @@ static int qemuDomainSnapshotNum(virDomainPtr domain, ...@@ -8756,7 +8759,7 @@ static int qemuDomainSnapshotNum(virDomainPtr domain,
* VIR_DOMAIN_SNAPSHOT_LIST_METADATA makes no difference to our * VIR_DOMAIN_SNAPSHOT_LIST_METADATA makes no difference to our
* answer. */ * answer. */
n = virDomainSnapshotObjListNum(&vm->snapshots); n = virDomainSnapshotObjListNum(&vm->snapshots, flags);
cleanup: cleanup:
if (vm) if (vm)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册