mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 13:05:27 +00:00
snapshot: s/parent/parent_name/ as prep for virObject
VIR_CLASS_NEW insists that descendents of virObject have 'parent' as the name of their inherited base class member at offset 0. While it would be possible to write a new class-creation macro that takes the actual field name, and rewrite VIR_CLASS_NEW to call the new macro with the hard-coded name 'parent', so that we could make virDomainMomentDef use a custom name for its base class, it seems less confusing if all object code uses similar naming. Thus, this is a mechanical rename in preparation of making virDomainSnapshotDef a descendent of virObject, when we can no longer use 'parent' for a different purpose than the base class. Signed-off-by: Eric Blake <eblake@redhat.com> Acked-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
76b9aba2ba
commit
36603bc568
@ -38,7 +38,7 @@ void virDomainMomentDefClear(virDomainMomentDefPtr def)
|
||||
{
|
||||
VIR_FREE(def->name);
|
||||
VIR_FREE(def->description);
|
||||
VIR_FREE(def->parent);
|
||||
VIR_FREE(def->parent_name);
|
||||
virDomainDefFree(def->dom);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ struct _virDomainMomentDef {
|
||||
/* Common portion of public XML. */
|
||||
char *name;
|
||||
char *description;
|
||||
char *parent;
|
||||
char *parent_name;
|
||||
long long creationTime; /* in seconds */
|
||||
|
||||
virDomainDefPtr dom;
|
||||
|
@ -227,7 +227,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
def->common.parent = virXPathString("string(./parent/name)", ctxt);
|
||||
def->common.parent_name = virXPathString("string(./parent/name)", ctxt);
|
||||
|
||||
state = virXPathString("string(./state)", ctxt);
|
||||
if (state == NULL) {
|
||||
@ -809,10 +809,11 @@ virDomainSnapshotDefFormatInternal(virBufferPtr buf,
|
||||
virBufferAsprintf(buf, "<state>%s</state>\n",
|
||||
virDomainSnapshotStateTypeToString(def->state));
|
||||
|
||||
if (def->common.parent) {
|
||||
if (def->common.parent_name) {
|
||||
virBufferAddLit(buf, "<parent>\n");
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
virBufferEscapeString(buf, "<name>%s</name>\n", def->common.parent);
|
||||
virBufferEscapeString(buf, "<name>%s</name>\n",
|
||||
def->common.parent_name);
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</parent>\n");
|
||||
}
|
||||
@ -932,30 +933,31 @@ virDomainSnapshotRedefinePrep(virDomainPtr domain,
|
||||
bool check_if_stolen;
|
||||
|
||||
/* Prevent circular chains */
|
||||
if (def->common.parent) {
|
||||
if (STREQ(def->common.name, def->common.parent)) {
|
||||
if (def->common.parent_name) {
|
||||
if (STREQ(def->common.name, def->common.parent_name)) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("cannot set snapshot %s as its own parent"),
|
||||
def->common.name);
|
||||
return -1;
|
||||
}
|
||||
other = virDomainSnapshotFindByName(vm->snapshots, def->common.parent);
|
||||
other = virDomainSnapshotFindByName(vm->snapshots,
|
||||
def->common.parent_name);
|
||||
if (!other) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("parent %s for snapshot %s not found"),
|
||||
def->common.parent, def->common.name);
|
||||
def->common.parent_name, def->common.name);
|
||||
return -1;
|
||||
}
|
||||
otherdef = virDomainSnapshotObjGetDef(other);
|
||||
while (otherdef->common.parent) {
|
||||
if (STREQ(otherdef->common.parent, def->common.name)) {
|
||||
while (otherdef->common.parent_name) {
|
||||
if (STREQ(otherdef->common.parent_name, def->common.name)) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("parent %s would create cycle to %s"),
|
||||
otherdef->common.name, def->common.name);
|
||||
return -1;
|
||||
}
|
||||
other = virDomainSnapshotFindByName(vm->snapshots,
|
||||
otherdef->common.parent);
|
||||
otherdef->common.parent_name);
|
||||
if (!other) {
|
||||
VIR_WARN("snapshots are inconsistent for %s",
|
||||
vm->def->name);
|
||||
|
@ -464,7 +464,7 @@ virDomainMomentForEach(virDomainMomentObjListPtr moments,
|
||||
|
||||
|
||||
/* Struct and callback function used as a hash table callback; each call
|
||||
* inspects the pre-existing moment->def->parent field, and adjusts
|
||||
* inspects the pre-existing moment->def->parent_name field, and adjusts
|
||||
* the moment->parent field as well as the parent's child fields to
|
||||
* wire up the hierarchical relations for the given moment. The error
|
||||
* indicator gets set if a parent is missing or a requested parent would
|
||||
@ -483,7 +483,7 @@ virDomainMomentSetRelations(void *payload,
|
||||
virDomainMomentObjPtr tmp;
|
||||
virDomainMomentObjPtr parent;
|
||||
|
||||
parent = virDomainMomentFindByName(curr->moments, obj->def->parent);
|
||||
parent = virDomainMomentFindByName(curr->moments, obj->def->parent_name);
|
||||
if (!parent) {
|
||||
curr->err = -1;
|
||||
parent = &curr->moments->metaroot;
|
||||
|
@ -4191,7 +4191,7 @@ esxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
|
||||
|
||||
def.common.name = snapshot->name;
|
||||
def.common.description = snapshotTree->description;
|
||||
def.common.parent = snapshotTreeParent ? snapshotTreeParent->name : NULL;
|
||||
def.common.parent_name = snapshotTreeParent ? snapshotTreeParent->name : NULL;
|
||||
|
||||
if (esxVI_DateTime_ConvertToCalendarTime(snapshotTree->createTime,
|
||||
&def.common.creationTime) < 0) {
|
||||
|
@ -8606,19 +8606,19 @@ qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
|
||||
|
||||
if (snap == virDomainSnapshotGetCurrent(vm->snapshots)) {
|
||||
virDomainSnapshotSetCurrent(vm->snapshots, NULL);
|
||||
if (update_parent && snap->def->parent) {
|
||||
if (update_parent && snap->def->parent_name) {
|
||||
parentsnap = virDomainSnapshotFindByName(vm->snapshots,
|
||||
snap->def->parent);
|
||||
snap->def->parent_name);
|
||||
if (!parentsnap) {
|
||||
VIR_WARN("missing parent snapshot matching name '%s'",
|
||||
snap->def->parent);
|
||||
snap->def->parent_name);
|
||||
} else {
|
||||
virDomainSnapshotSetCurrent(vm->snapshots, parentsnap);
|
||||
if (qemuDomainSnapshotWriteMetadata(vm, parentsnap, driver->caps,
|
||||
driver->xmlopt,
|
||||
cfg->snapshotDir) < 0) {
|
||||
VIR_WARN("failed to set parent snapshot '%s' as current",
|
||||
snap->def->parent);
|
||||
snap->def->parent_name);
|
||||
virDomainSnapshotSetCurrent(vm->snapshots, NULL);
|
||||
}
|
||||
}
|
||||
|
@ -15752,7 +15752,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
|
||||
current = virDomainSnapshotGetCurrent(vm->snapshots);
|
||||
if (current) {
|
||||
if (!redefine &&
|
||||
VIR_STRDUP(snap->def->parent, current->def->name) < 0)
|
||||
VIR_STRDUP(snap->def->parent_name, current->def->name) < 0)
|
||||
goto endjob;
|
||||
if (update_current) {
|
||||
virDomainSnapshotSetCurrent(vm->snapshots, NULL);
|
||||
@ -15820,7 +15820,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
|
||||
virDomainSnapshotObjListRemove(vm->snapshots, snap);
|
||||
} else {
|
||||
other = virDomainSnapshotFindByName(vm->snapshots,
|
||||
snap->def->parent);
|
||||
snap->def->parent_name);
|
||||
virDomainMomentSetParent(snap, other);
|
||||
}
|
||||
} else if (snap) {
|
||||
@ -16080,14 +16080,14 @@ qemuDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
|
||||
if (!(snap = qemuSnapObjFromSnapshot(vm, snapshot)))
|
||||
goto cleanup;
|
||||
|
||||
if (!snap->def->parent) {
|
||||
if (!snap->def->parent_name) {
|
||||
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
|
||||
_("snapshot '%s' does not have a parent"),
|
||||
snap->def->name);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
parent = virGetDomainSnapshot(snapshot->domain, snap->def->parent);
|
||||
parent = virGetDomainSnapshot(snapshot->domain, snap->def->parent_name);
|
||||
|
||||
cleanup:
|
||||
virDomainObjEndAPI(&vm);
|
||||
@ -16668,10 +16668,10 @@ qemuDomainMomentReparentChildren(void *payload,
|
||||
if (rep->err < 0)
|
||||
return 0;
|
||||
|
||||
VIR_FREE(moment->def->parent);
|
||||
VIR_FREE(moment->def->parent_name);
|
||||
|
||||
if (rep->parent->def &&
|
||||
VIR_STRDUP(moment->def->parent, rep->parent->def->name) < 0) {
|
||||
VIR_STRDUP(moment->def->parent_name, rep->parent->def->name) < 0) {
|
||||
rep->err = -1;
|
||||
return 0;
|
||||
}
|
||||
|
@ -6195,14 +6195,14 @@ testDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
|
||||
if (!(snap = testSnapObjFromSnapshot(vm, snapshot)))
|
||||
goto cleanup;
|
||||
|
||||
if (!snap->def->parent) {
|
||||
if (!snap->def->parent_name) {
|
||||
virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
|
||||
_("snapshot '%s' does not have a parent"),
|
||||
snap->def->name);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
parent = virGetDomainSnapshot(snapshot->domain, snap->def->parent);
|
||||
parent = virGetDomainSnapshot(snapshot->domain, snap->def->parent_name);
|
||||
|
||||
cleanup:
|
||||
virDomainObjEndAPI(&vm);
|
||||
@ -6421,7 +6421,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
|
||||
}
|
||||
|
||||
if (!redefine) {
|
||||
if (VIR_STRDUP(snap->def->parent,
|
||||
if (VIR_STRDUP(snap->def->parent_name,
|
||||
virDomainSnapshotGetCurrentName(vm->snapshots)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
@ -6442,7 +6442,7 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
|
||||
if (update_current)
|
||||
virDomainSnapshotSetCurrent(vm->snapshots, snap);
|
||||
other = virDomainSnapshotFindByName(vm->snapshots,
|
||||
snap->def->parent);
|
||||
snap->def->parent_name);
|
||||
virDomainMomentSetParent(snap, other);
|
||||
}
|
||||
virDomainObjEndAPI(&vm);
|
||||
@ -6491,10 +6491,10 @@ testDomainSnapshotReparentChildren(void *payload,
|
||||
if (rep->err < 0)
|
||||
return 0;
|
||||
|
||||
VIR_FREE(snap->def->parent);
|
||||
VIR_FREE(snap->def->parent_name);
|
||||
|
||||
if (rep->parent->def &&
|
||||
VIR_STRDUP(snap->def->parent, rep->parent->def->name) < 0) {
|
||||
VIR_STRDUP(snap->def->parent_name, rep->parent->def->name) < 0) {
|
||||
rep->err = -1;
|
||||
return 0;
|
||||
}
|
||||
@ -6549,12 +6549,12 @@ testDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
|
||||
} else {
|
||||
virDomainMomentDropParent(snap);
|
||||
if (snap == virDomainSnapshotGetCurrent(vm->snapshots)) {
|
||||
if (snap->def->parent) {
|
||||
if (snap->def->parent_name) {
|
||||
parentsnap = virDomainSnapshotFindByName(vm->snapshots,
|
||||
snap->def->parent);
|
||||
snap->def->parent_name);
|
||||
if (!parentsnap)
|
||||
VIR_WARN("missing parent snapshot matching name '%s'",
|
||||
snap->def->parent);
|
||||
snap->def->parent_name);
|
||||
}
|
||||
virDomainSnapshotSetCurrent(vm->snapshots, parentsnap);
|
||||
}
|
||||
|
@ -5061,7 +5061,7 @@ vboxSnapshotRedefine(virDomainPtr dom,
|
||||
|
||||
VIR_FREE(tmp);
|
||||
}
|
||||
if (virVBoxSnapshotConfAddSnapshotToXmlMachine(newSnapshotPtr, snapshotMachineDesc, def->common.parent) < 0) {
|
||||
if (virVBoxSnapshotConfAddSnapshotToXmlMachine(newSnapshotPtr, snapshotMachineDesc, def->common.parent_name) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Unable to add the snapshot to the machine description"));
|
||||
goto cleanup;
|
||||
@ -6305,7 +6305,7 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
|
||||
}
|
||||
VBOX_UTF16_TO_UTF8(str16, &str8);
|
||||
VBOX_UTF16_FREE(str16);
|
||||
if (VIR_STRDUP(def->common.parent, str8) < 0) {
|
||||
if (VIR_STRDUP(def->common.parent_name, str8) < 0) {
|
||||
VBOX_UTF8_FREE(str8);
|
||||
goto cleanup;
|
||||
}
|
||||
@ -6999,7 +6999,7 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot)
|
||||
* disks. The first thing to do is to manipulate VirtualBox API to create
|
||||
* differential read-write disks if the parent snapshot is not null.
|
||||
*/
|
||||
if (def->common.parent != NULL) {
|
||||
if (def->common.parent_name != NULL) {
|
||||
for (it = 0; it < def->common.dom->ndisks; it++) {
|
||||
virVBoxSnapshotConfHardDiskPtr readOnly = NULL;
|
||||
IMedium *medium = NULL;
|
||||
@ -7058,7 +7058,7 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot)
|
||||
VBOX_UTF8_TO_UTF16("VDI", &formatUtf16);
|
||||
|
||||
if (virAsprintf(&newLocationUtf8, "%sfakedisk-%s-%d.vdi",
|
||||
machineLocationPath, def->common.parent, it) < 0)
|
||||
machineLocationPath, def->common.parent_name, it) < 0)
|
||||
goto cleanup;
|
||||
VBOX_UTF8_TO_UTF16(newLocationUtf8, &newLocation);
|
||||
rc = gVBoxAPI.UIVirtualBox.CreateHardDisk(data->vboxObj,
|
||||
@ -7209,7 +7209,7 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot)
|
||||
}
|
||||
}
|
||||
/*If the parent snapshot is not NULL, we remove the-read only disks from the media registry*/
|
||||
if (def->common.parent != NULL) {
|
||||
if (def->common.parent_name != NULL) {
|
||||
for (it = 0; it < def->common.dom->ndisks; it++) {
|
||||
const char *uuidRO =
|
||||
virVBoxSnapshotConfHardDiskUuidByLocation(snapshotMachineDesc,
|
||||
@ -7289,8 +7289,8 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot)
|
||||
|
||||
if (isCurrent) {
|
||||
VIR_FREE(snapshotMachineDesc->currentSnapshot);
|
||||
if (def->common.parent != NULL) {
|
||||
virVBoxSnapshotConfSnapshotPtr snap = virVBoxSnapshotConfSnapshotByName(snapshotMachineDesc->snapshot, def->common.parent);
|
||||
if (def->common.parent_name != NULL) {
|
||||
virVBoxSnapshotConfSnapshotPtr snap = virVBoxSnapshotConfSnapshotByName(snapshotMachineDesc->snapshot, def->common.parent_name);
|
||||
if (!snap) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Unable to get the snapshot to remove"));
|
||||
|
@ -4703,7 +4703,7 @@ prlsdkParseSnapshotTree(const char *treexml)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
def->common.parent = virXPathString("string(../@guid)", ctxt);
|
||||
def->common.parent_name = virXPathString("string(../@guid)", ctxt);
|
||||
|
||||
xmlstr = virXPathString("string(./DateTime)", ctxt);
|
||||
if (!xmlstr) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user