mirror of https://gitee.com/openkylin/libvirt.git
snapshot: merge domain and snapshot computation
Now that domain listing is a thin wrapper around child listing, it's easier to have a common entry point. This restores the hashForEach optimization lost in the previous patch when there are no snapshots being filtered out of the entire list. * src/conf/domain_conf.h (virDomainSnapshotObjListGetNames) (virDomainSnapshotObjListNum): Add parameter. (virDomainSnapshotObjListGetNamesFrom) (virDomainSnapshotObjListNumFrom): Delete. * src/libvirt_private.syms (domain_conf.h): Drop deleted functions. * src/conf/domain_conf.c (virDomainSnapshotObjListGetNames): Merge, and (re)add an optimization. * src/qemu/qemu_driver.c (qemuDomainUndefineFlags) (qemuDomainSnapshotListNames, qemuDomainSnapshotNum) (qemuDomainSnapshotListChildrenNames) (qemuDomainSnapshotNumChildren): Update callers. * src/qemu/qemu_migration.c (qemuMigrationIsAllowed): Likewise. * src/conf/virdomainlist.c (virDomainListPopulate): Likewise.
This commit is contained in:
parent
06d4a1e429
commit
7e111c6fe6
|
@ -14286,34 +14286,37 @@ static void virDomainSnapshotObjListCopyNames(void *payload,
|
|||
}
|
||||
}
|
||||
|
||||
int virDomainSnapshotObjListGetNames(virDomainSnapshotObjListPtr snapshots,
|
||||
char **const names, int maxnames,
|
||||
unsigned int flags)
|
||||
{
|
||||
/* LIST_ROOTS and LIST_DESCENDANTS have the same bit value, but
|
||||
* opposite semantics. Toggle here to get the correct traversal
|
||||
* on the metaroot. */
|
||||
flags ^= VIR_DOMAIN_SNAPSHOT_LIST_ROOTS;
|
||||
return virDomainSnapshotObjListGetNamesFrom(&snapshots->metaroot, names,
|
||||
maxnames, flags);
|
||||
}
|
||||
|
||||
int virDomainSnapshotObjListGetNamesFrom(virDomainSnapshotObjPtr snapshot,
|
||||
char **const names, int maxnames,
|
||||
unsigned int flags)
|
||||
int
|
||||
virDomainSnapshotObjListGetNames(virDomainSnapshotObjListPtr snapshots,
|
||||
virDomainSnapshotObjPtr from,
|
||||
char **const names, int maxnames,
|
||||
unsigned int flags)
|
||||
{
|
||||
struct virDomainSnapshotNameData data = { 0, 0, maxnames, names, 0 };
|
||||
int i;
|
||||
|
||||
if (!from) {
|
||||
/* LIST_ROOTS and LIST_DESCENDANTS have the same bit value,
|
||||
* but opposite semantics. Toggle here to get the correct
|
||||
* traversal on the metaroot. */
|
||||
flags ^= VIR_DOMAIN_SNAPSHOT_LIST_ROOTS;
|
||||
from = &snapshots->metaroot;
|
||||
}
|
||||
|
||||
data.flags = flags & ~VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS;
|
||||
|
||||
if (flags & VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS)
|
||||
virDomainSnapshotForEachDescendant(snapshot,
|
||||
virDomainSnapshotObjListCopyNames,
|
||||
&data);
|
||||
else
|
||||
virDomainSnapshotForEachChild(snapshot,
|
||||
if (flags & VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS) {
|
||||
if (from->def)
|
||||
virDomainSnapshotForEachDescendant(from,
|
||||
virDomainSnapshotObjListCopyNames,
|
||||
&data);
|
||||
else
|
||||
virHashForEach(snapshots->objs, virDomainSnapshotObjListCopyNames,
|
||||
&data);
|
||||
} else {
|
||||
virDomainSnapshotForEachChild(from,
|
||||
virDomainSnapshotObjListCopyNames, &data);
|
||||
}
|
||||
|
||||
if (data.oom) {
|
||||
virReportOOMError();
|
||||
|
@ -14348,33 +14351,36 @@ static void virDomainSnapshotObjListCount(void *payload,
|
|||
data->count++;
|
||||
}
|
||||
|
||||
int virDomainSnapshotObjListNum(virDomainSnapshotObjListPtr snapshots,
|
||||
unsigned int flags)
|
||||
{
|
||||
/* LIST_ROOTS and LIST_DESCENDANTS have the same bit value, but
|
||||
* opposite semantics. Toggle here to get the correct traversal
|
||||
* on the metaroot. */
|
||||
flags ^= VIR_DOMAIN_SNAPSHOT_LIST_ROOTS;
|
||||
return virDomainSnapshotObjListNumFrom(&snapshots->metaroot, flags);
|
||||
}
|
||||
|
||||
int
|
||||
virDomainSnapshotObjListNumFrom(virDomainSnapshotObjPtr snapshot,
|
||||
unsigned int flags)
|
||||
virDomainSnapshotObjListNum(virDomainSnapshotObjListPtr snapshots,
|
||||
virDomainSnapshotObjPtr from,
|
||||
unsigned int flags)
|
||||
{
|
||||
struct virDomainSnapshotNumData data = { 0, 0 };
|
||||
|
||||
if (!from) {
|
||||
/* LIST_ROOTS and LIST_DESCENDANTS have the same bit value,
|
||||
* but opposite semantics. Toggle here to get the correct
|
||||
* traversal on the metaroot. */
|
||||
flags ^= VIR_DOMAIN_SNAPSHOT_LIST_ROOTS;
|
||||
from = &snapshots->metaroot;
|
||||
}
|
||||
|
||||
data.flags = flags & ~VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS;
|
||||
|
||||
if (flags & VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS)
|
||||
virDomainSnapshotForEachDescendant(snapshot,
|
||||
virDomainSnapshotObjListCount,
|
||||
&data);
|
||||
else if (data.flags)
|
||||
virDomainSnapshotForEachChild(snapshot,
|
||||
if (flags & VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS) {
|
||||
if (data.flags || from->def)
|
||||
virDomainSnapshotForEachDescendant(from,
|
||||
virDomainSnapshotObjListCount,
|
||||
&data);
|
||||
else
|
||||
data.count = virHashSize(snapshots->objs);
|
||||
} else if (data.flags) {
|
||||
virDomainSnapshotForEachChild(from,
|
||||
virDomainSnapshotObjListCount, &data);
|
||||
else
|
||||
data.count = snapshot->nchildren;
|
||||
} else {
|
||||
data.count = from->nchildren;
|
||||
}
|
||||
|
||||
return data.count;
|
||||
}
|
||||
|
|
|
@ -1769,15 +1769,12 @@ virDomainSnapshotObjPtr virDomainSnapshotAssignDef(virDomainSnapshotObjListPtr s
|
|||
|
||||
int virDomainSnapshotObjListInit(virDomainSnapshotObjListPtr objs);
|
||||
int virDomainSnapshotObjListGetNames(virDomainSnapshotObjListPtr snapshots,
|
||||
virDomainSnapshotObjPtr from,
|
||||
char **const names, int maxnames,
|
||||
unsigned int flags);
|
||||
int virDomainSnapshotObjListNum(virDomainSnapshotObjListPtr snapshots,
|
||||
virDomainSnapshotObjPtr from,
|
||||
unsigned int flags);
|
||||
int virDomainSnapshotObjListGetNamesFrom(virDomainSnapshotObjPtr snapshot,
|
||||
char **const names, int maxnames,
|
||||
unsigned int flags);
|
||||
int virDomainSnapshotObjListNumFrom(virDomainSnapshotObjPtr snapshot,
|
||||
unsigned int flags);
|
||||
virDomainSnapshotObjPtr virDomainSnapshotFindByName(const virDomainSnapshotObjListPtr snapshots,
|
||||
const char *name);
|
||||
void virDomainSnapshotObjListRemove(virDomainSnapshotObjListPtr snapshots,
|
||||
|
|
|
@ -106,7 +106,7 @@ virDomainListPopulate(void *payload,
|
|||
|
||||
/* filter by snapshot existence */
|
||||
if (MATCH(VIR_CONNECT_LIST_FILTERS_SNAPSHOT)) {
|
||||
int nsnap = virDomainSnapshotObjListNum(&vm->snapshots, 0);
|
||||
int nsnap = virDomainSnapshotObjListNum(&vm->snapshots, NULL, 0);
|
||||
if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT) && nsnap > 0) ||
|
||||
(MATCH(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT) && nsnap <= 0)))
|
||||
goto cleanup;
|
||||
|
|
|
@ -457,9 +457,7 @@ virDomainSnapshotFindByName;
|
|||
virDomainSnapshotForEachChild;
|
||||
virDomainSnapshotForEachDescendant;
|
||||
virDomainSnapshotObjListGetNames;
|
||||
virDomainSnapshotObjListGetNamesFrom;
|
||||
virDomainSnapshotObjListNum;
|
||||
virDomainSnapshotObjListNumFrom;
|
||||
virDomainSnapshotObjListRemove;
|
||||
virDomainSnapshotStateTypeFromString;
|
||||
virDomainSnapshotStateTypeToString;
|
||||
|
|
|
@ -5139,7 +5139,7 @@ qemuDomainUndefineFlags(virDomainPtr dom,
|
|||
}
|
||||
|
||||
if (!virDomainObjIsActive(vm) &&
|
||||
(nsnapshots = virDomainSnapshotObjListNum(&vm->snapshots, 0))) {
|
||||
(nsnapshots = virDomainSnapshotObjListNum(&vm->snapshots, NULL, 0))) {
|
||||
if (!(flags & VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA)) {
|
||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
||||
_("cannot delete inactive domain with %d "
|
||||
|
@ -10663,7 +10663,7 @@ static int qemuDomainSnapshotListNames(virDomainPtr domain, char **names,
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
n = virDomainSnapshotObjListGetNames(&vm->snapshots, names, nameslen,
|
||||
n = virDomainSnapshotObjListGetNames(&vm->snapshots, NULL, names, nameslen,
|
||||
flags);
|
||||
|
||||
cleanup:
|
||||
|
@ -10698,7 +10698,7 @@ static int qemuDomainSnapshotNum(virDomainPtr domain,
|
|||
* VIR_DOMAIN_SNAPSHOT_LIST_METADATA makes no difference to our
|
||||
* answer. */
|
||||
|
||||
n = virDomainSnapshotObjListNum(&vm->snapshots, flags);
|
||||
n = virDomainSnapshotObjListNum(&vm->snapshots, NULL, flags);
|
||||
|
||||
cleanup:
|
||||
if (vm)
|
||||
|
@ -10740,7 +10740,8 @@ qemuDomainSnapshotListChildrenNames(virDomainSnapshotPtr snapshot,
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
n = virDomainSnapshotObjListGetNamesFrom(snap, names, nameslen, flags);
|
||||
n = virDomainSnapshotObjListGetNames(&vm->snapshots, snap, names, nameslen,
|
||||
flags);
|
||||
|
||||
cleanup:
|
||||
if (vm)
|
||||
|
@ -10784,7 +10785,7 @@ qemuDomainSnapshotNumChildren(virDomainSnapshotPtr snapshot,
|
|||
* VIR_DOMAIN_SNAPSHOT_LIST_METADATA makes no difference to our
|
||||
* answer. */
|
||||
|
||||
n = virDomainSnapshotObjListNumFrom(snap, flags);
|
||||
n = virDomainSnapshotObjListNum(&vm->snapshots, snap, flags);
|
||||
|
||||
cleanup:
|
||||
if (vm)
|
||||
|
|
|
@ -807,7 +807,8 @@ qemuMigrationIsAllowed(struct qemud_driver *driver, virDomainObjPtr vm,
|
|||
"%s", _("domain is marked for auto destroy"));
|
||||
return false;
|
||||
}
|
||||
if ((nsnapshots = virDomainSnapshotObjListNum(&vm->snapshots, 0))) {
|
||||
if ((nsnapshots = virDomainSnapshotObjListNum(&vm->snapshots, NULL,
|
||||
0))) {
|
||||
qemuReportError(VIR_ERR_OPERATION_INVALID,
|
||||
_("cannot migrate domain with %d snapshots"),
|
||||
nsnapshots);
|
||||
|
|
Loading…
Reference in New Issue