mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-11-23 04:24:24 +03:00
snapshot: Access snapshot def directly when needed
An upcoming patch will rework virDomainSnapshotObjList to be generic for both snapshots and checkpoints; reduce the churn by adding a new accessor virDomainSnapshotObjGetDef() which returns the snapshot-specific definition even when the list is rewritten to operate only on a base class, then using it at sites that that are specific to snapshots. Use VIR_STEAL_PTR when appropriate in the affected lines. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
@@ -461,8 +461,10 @@ virDomainSnapshotRedefineValidate(virDomainSnapshotDefPtr def,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (other) {
|
if (other) {
|
||||||
if ((other->def->state == VIR_DOMAIN_SNAPSHOT_RUNNING ||
|
virDomainSnapshotDefPtr otherdef = virDomainSnapshotObjGetDef(other);
|
||||||
other->def->state == VIR_DOMAIN_SNAPSHOT_PAUSED) !=
|
|
||||||
|
if ((otherdef->state == VIR_DOMAIN_SNAPSHOT_RUNNING ||
|
||||||
|
otherdef->state == VIR_DOMAIN_SNAPSHOT_PAUSED) !=
|
||||||
(def->state == VIR_DOMAIN_SNAPSHOT_RUNNING ||
|
(def->state == VIR_DOMAIN_SNAPSHOT_RUNNING ||
|
||||||
def->state == VIR_DOMAIN_SNAPSHOT_PAUSED)) {
|
def->state == VIR_DOMAIN_SNAPSHOT_PAUSED)) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
@@ -472,7 +474,7 @@ virDomainSnapshotRedefineValidate(virDomainSnapshotDefPtr def,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((other->def->state == VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT) !=
|
if ((otherdef->state == VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT) !=
|
||||||
(def->state == VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT)) {
|
(def->state == VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT)) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
_("cannot change between disk only and "
|
_("cannot change between disk only and "
|
||||||
@@ -481,15 +483,14 @@ virDomainSnapshotRedefineValidate(virDomainSnapshotDefPtr def,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (other->def->dom) {
|
if (otherdef->dom) {
|
||||||
if (def->dom) {
|
if (def->dom) {
|
||||||
if (!virDomainDefCheckABIStability(other->def->dom,
|
if (!virDomainDefCheckABIStability(otherdef->dom,
|
||||||
def->dom, xmlopt))
|
def->dom, xmlopt))
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
/* Transfer the domain def */
|
/* Transfer the domain def */
|
||||||
def->dom = other->def->dom;
|
VIR_STEAL_PTR(def->dom, otherdef->dom);
|
||||||
other->def->dom = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -914,7 +915,9 @@ virDomainSnapshotDefIsExternal(virDomainSnapshotDefPtr def)
|
|||||||
bool
|
bool
|
||||||
virDomainSnapshotIsExternal(virDomainSnapshotObjPtr snap)
|
virDomainSnapshotIsExternal(virDomainSnapshotObjPtr snap)
|
||||||
{
|
{
|
||||||
return virDomainSnapshotDefIsExternal(snap->def);
|
virDomainSnapshotDefPtr def = virDomainSnapshotObjGetDef(snap);
|
||||||
|
|
||||||
|
return virDomainSnapshotDefIsExternal(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -928,6 +931,7 @@ virDomainSnapshotRedefinePrep(virDomainPtr domain,
|
|||||||
{
|
{
|
||||||
virDomainSnapshotDefPtr def = *defptr;
|
virDomainSnapshotDefPtr def = *defptr;
|
||||||
virDomainSnapshotObjPtr other;
|
virDomainSnapshotObjPtr other;
|
||||||
|
virDomainSnapshotDefPtr otherdef;
|
||||||
bool check_if_stolen;
|
bool check_if_stolen;
|
||||||
|
|
||||||
/* Prevent circular chains */
|
/* Prevent circular chains */
|
||||||
@@ -945,15 +949,16 @@ virDomainSnapshotRedefinePrep(virDomainPtr domain,
|
|||||||
def->parent, def->name);
|
def->parent, def->name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while (other->def->parent) {
|
otherdef = virDomainSnapshotObjGetDef(other);
|
||||||
if (STREQ(other->def->parent, def->name)) {
|
while (otherdef->parent) {
|
||||||
|
if (STREQ(otherdef->parent, def->name)) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
_("parent %s would create cycle to %s"),
|
_("parent %s would create cycle to %s"),
|
||||||
other->def->name, def->name);
|
otherdef->name, def->name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
other = virDomainSnapshotFindByName(vm->snapshots,
|
other = virDomainSnapshotFindByName(vm->snapshots,
|
||||||
other->def->parent);
|
otherdef->parent);
|
||||||
if (!other) {
|
if (!other) {
|
||||||
VIR_WARN("snapshots are inconsistent for %s",
|
VIR_WARN("snapshots are inconsistent for %s",
|
||||||
vm->def->name);
|
vm->def->name);
|
||||||
@@ -963,14 +968,13 @@ virDomainSnapshotRedefinePrep(virDomainPtr domain,
|
|||||||
}
|
}
|
||||||
|
|
||||||
other = virDomainSnapshotFindByName(vm->snapshots, def->name);
|
other = virDomainSnapshotFindByName(vm->snapshots, def->name);
|
||||||
check_if_stolen = other && other->def->dom;
|
otherdef = other ? virDomainSnapshotObjGetDef(other) : NULL;
|
||||||
|
check_if_stolen = other && otherdef->dom;
|
||||||
if (virDomainSnapshotRedefineValidate(def, domain->uuid, other, xmlopt,
|
if (virDomainSnapshotRedefineValidate(def, domain->uuid, other, xmlopt,
|
||||||
flags) < 0) {
|
flags) < 0) {
|
||||||
/* revert any stealing of the snapshot domain definition */
|
/* revert any stealing of the snapshot domain definition */
|
||||||
if (check_if_stolen && def->dom && !other->def->dom) {
|
if (check_if_stolen && def->dom && !otherdef->dom)
|
||||||
other->def->dom = def->dom;
|
VIR_STEAL_PTR(otherdef->dom, def->dom);
|
||||||
def->dom = NULL;
|
|
||||||
}
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (other) {
|
if (other) {
|
||||||
@@ -982,9 +986,8 @@ virDomainSnapshotRedefinePrep(virDomainPtr domain,
|
|||||||
/* Drop and rebuild the parent relationship, but keep all
|
/* Drop and rebuild the parent relationship, but keep all
|
||||||
* child relations by reusing snap. */
|
* child relations by reusing snap. */
|
||||||
virDomainSnapshotDropParent(other);
|
virDomainSnapshotDropParent(other);
|
||||||
virDomainSnapshotDefFree(other->def);
|
virDomainSnapshotDefFree(otherdef);
|
||||||
other->def = def;
|
VIR_STEAL_PTR(other->def, *defptr);
|
||||||
*defptr = NULL;
|
|
||||||
*snap = other;
|
*snap = other;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -168,8 +168,9 @@ virDomainSnapshotFormatOne(void *payload,
|
|||||||
virDomainSnapshotObjPtr snap = payload;
|
virDomainSnapshotObjPtr snap = payload;
|
||||||
struct virDomainSnapshotFormatData *data = opaque;
|
struct virDomainSnapshotFormatData *data = opaque;
|
||||||
return virDomainSnapshotDefFormatInternal(data->buf, data->uuidstr,
|
return virDomainSnapshotDefFormatInternal(data->buf, data->uuidstr,
|
||||||
snap->def, data->caps,
|
virDomainSnapshotObjGetDef(snap),
|
||||||
data->xmlopt, data->flags);
|
data->caps, data->xmlopt,
|
||||||
|
data->flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -229,7 +230,7 @@ static void virDomainSnapshotObjFree(virDomainSnapshotObjPtr snapshot)
|
|||||||
|
|
||||||
VIR_DEBUG("obj=%p", snapshot);
|
VIR_DEBUG("obj=%p", snapshot);
|
||||||
|
|
||||||
virDomainSnapshotDefFree(snapshot->def);
|
virDomainSnapshotDefFree(virDomainSnapshotObjGetDef(snapshot));
|
||||||
VIR_FREE(snapshot);
|
VIR_FREE(snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,15 +316,17 @@ static int virDomainSnapshotObjListCopyNames(void *payload,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (data->flags & VIR_DOMAIN_SNAPSHOT_FILTERS_STATUS) {
|
if (data->flags & VIR_DOMAIN_SNAPSHOT_FILTERS_STATUS) {
|
||||||
|
virDomainSnapshotDefPtr def = virDomainSnapshotObjGetDef(obj);
|
||||||
|
|
||||||
if (!(data->flags & VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE) &&
|
if (!(data->flags & VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE) &&
|
||||||
obj->def->state == VIR_DOMAIN_SNAPSHOT_SHUTOFF)
|
def->state == VIR_DOMAIN_SNAPSHOT_SHUTOFF)
|
||||||
return 0;
|
return 0;
|
||||||
if (!(data->flags & VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY) &&
|
if (!(data->flags & VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY) &&
|
||||||
obj->def->state == VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT)
|
def->state == VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT)
|
||||||
return 0;
|
return 0;
|
||||||
if (!(data->flags & VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE) &&
|
if (!(data->flags & VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE) &&
|
||||||
obj->def->state != VIR_DOMAIN_SNAPSHOT_SHUTOFF &&
|
def->state != VIR_DOMAIN_SNAPSHOT_SHUTOFF &&
|
||||||
obj->def->state != VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT)
|
def->state != VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,4 +76,11 @@ int virDomainListSnapshots(virDomainSnapshotObjListPtr snapshots,
|
|||||||
virDomainSnapshotPtr **snaps,
|
virDomainSnapshotPtr **snaps,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
|
||||||
|
/* Access the snapshot-specific definition from a given list member. */
|
||||||
|
static inline virDomainSnapshotDefPtr
|
||||||
|
virDomainSnapshotObjGetDef(virDomainSnapshotObjPtr obj)
|
||||||
|
{
|
||||||
|
return obj->def;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* LIBVIRT_VIRDOMAINSNAPSHOTOBJLIST_H */
|
#endif /* LIBVIRT_VIRDOMAINSNAPSHOTOBJLIST_H */
|
||||||
|
|||||||
@@ -8460,12 +8460,12 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
|
|||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
unsigned int flags = VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE |
|
unsigned int flags = VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE |
|
||||||
VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL;
|
VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL;
|
||||||
|
virDomainSnapshotDefPtr def = virDomainSnapshotObjGetDef(snapshot);
|
||||||
|
|
||||||
if (virDomainSnapshotGetCurrent(vm->snapshots) == snapshot)
|
if (virDomainSnapshotGetCurrent(vm->snapshots) == snapshot)
|
||||||
flags |= VIR_DOMAIN_SNAPSHOT_FORMAT_CURRENT;
|
flags |= VIR_DOMAIN_SNAPSHOT_FORMAT_CURRENT;
|
||||||
virUUIDFormat(vm->def->uuid, uuidstr);
|
virUUIDFormat(vm->def->uuid, uuidstr);
|
||||||
newxml = virDomainSnapshotDefFormat(uuidstr, snapshot->def, caps, xmlopt,
|
newxml = virDomainSnapshotDefFormat(uuidstr, def, caps, xmlopt, flags);
|
||||||
flags);
|
|
||||||
if (newxml == NULL)
|
if (newxml == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@@ -8477,7 +8477,7 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virAsprintf(&snapFile, "%s/%s.xml", snapDir, snapshot->def->name) < 0)
|
if (virAsprintf(&snapFile, "%s/%s.xml", snapDir, def->name) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = virXMLSaveFile(snapFile, NULL, "snapshot-edit", newxml);
|
ret = virXMLSaveFile(snapFile, NULL, "snapshot-edit", newxml);
|
||||||
|
|||||||
Reference in New Issue
Block a user