mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
snapshot: Make virDomainSnapshotDef a virObject
This brings about a couple of benefits: - use of VIR_AUTOUNREF() simplifies several callers - Fixes a todo about virDomainMomentObjList not being polymorphic enough Signed-off-by: Eric Blake <eblake@redhat.com> Acked-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
7fe07761a7
commit
57387ff54b
2
cfg.mk
2
cfg.mk
@ -133,7 +133,6 @@ useless_free_options = \
|
||||
--name=virDomainNetDefFree \
|
||||
--name=virDomainObjFree \
|
||||
--name=virDomainSmartcardDefFree \
|
||||
--name=virDomainSnapshotDefFree \
|
||||
--name=virDomainSnapshotObjFree \
|
||||
--name=virDomainSoundDefFree \
|
||||
--name=virDomainVideoDefFree \
|
||||
@ -211,7 +210,6 @@ useless_free_options = \
|
||||
# y virDomainInputDefFree
|
||||
# y virDomainNetDefFree
|
||||
# y virDomainObjFree
|
||||
# y virDomainSnapshotDefFree
|
||||
# n virDomainSnapshotFree (returns int)
|
||||
# n virDomainSnapshotFreeName (returns int)
|
||||
# y virDomainSnapshotObjFree
|
||||
|
@ -34,8 +34,34 @@
|
||||
|
||||
VIR_LOG_INIT("conf.moment_conf");
|
||||
|
||||
void virDomainMomentDefClear(virDomainMomentDefPtr def)
|
||||
static virClassPtr virDomainMomentDefClass;
|
||||
static void virDomainMomentDefDispose(void *obj);
|
||||
|
||||
static int
|
||||
virDomainMomentOnceInit(void)
|
||||
{
|
||||
if (!VIR_CLASS_NEW(virDomainMomentDef, virClassForObject()))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
VIR_ONCE_GLOBAL_INIT(virDomainMoment);
|
||||
|
||||
virClassPtr
|
||||
virClassForDomainMomentDef(void)
|
||||
{
|
||||
if (virDomainMomentInitialize() < 0)
|
||||
return NULL;
|
||||
|
||||
return virDomainMomentDefClass;
|
||||
}
|
||||
|
||||
static void
|
||||
virDomainMomentDefDispose(void *obj)
|
||||
{
|
||||
virDomainMomentDefPtr def = obj;
|
||||
|
||||
VIR_FREE(def->name);
|
||||
VIR_FREE(def->description);
|
||||
VIR_FREE(def->parent_name);
|
||||
|
@ -25,9 +25,12 @@
|
||||
|
||||
# include "internal.h"
|
||||
# include "virconftypes.h"
|
||||
# include "virobject.h"
|
||||
|
||||
/* Base class for a domain moment */
|
||||
struct _virDomainMomentDef {
|
||||
virObject parent;
|
||||
|
||||
/* Common portion of public XML. */
|
||||
char *name;
|
||||
char *description;
|
||||
@ -37,7 +40,7 @@ struct _virDomainMomentDef {
|
||||
virDomainDefPtr dom;
|
||||
};
|
||||
|
||||
void virDomainMomentDefClear(virDomainMomentDefPtr def);
|
||||
virClassPtr virClassForDomainMomentDef(void);
|
||||
|
||||
int virDomainMomentDefPostParse(virDomainMomentDefPtr def);
|
||||
|
||||
|
@ -50,6 +50,20 @@
|
||||
|
||||
VIR_LOG_INIT("conf.snapshot_conf");
|
||||
|
||||
static virClassPtr virDomainSnapshotDefClass;
|
||||
static void virDomainSnapshotDefDispose(void *obj);
|
||||
|
||||
static int
|
||||
virDomainSnapshotOnceInit(void)
|
||||
{
|
||||
if (!VIR_CLASS_NEW(virDomainSnapshotDef, virClassForDomainMomentDef()))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
VIR_ONCE_GLOBAL_INIT(virDomainSnapshot);
|
||||
|
||||
VIR_ENUM_IMPL(virDomainSnapshotLocation,
|
||||
VIR_DOMAIN_SNAPSHOT_LOCATION_LAST,
|
||||
"default",
|
||||
@ -81,29 +95,30 @@ virDomainSnapshotDiskDefClear(virDomainSnapshotDiskDefPtr disk)
|
||||
disk->src = NULL;
|
||||
}
|
||||
|
||||
/* Allocate a new virDomainSnapshotDef; free with virObjectUnref() */
|
||||
virDomainSnapshotDefPtr
|
||||
virDomainSnapshotDefNew(void)
|
||||
{
|
||||
virDomainSnapshotDefPtr def;
|
||||
|
||||
ignore_value(VIR_ALLOC(def));
|
||||
if (virDomainSnapshotInitialize() < 0)
|
||||
return NULL;
|
||||
|
||||
def = virObjectNew(virDomainSnapshotDefClass);
|
||||
return def;
|
||||
}
|
||||
|
||||
void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def)
|
||||
static void
|
||||
virDomainSnapshotDefDispose(void *obj)
|
||||
{
|
||||
virDomainSnapshotDefPtr def = obj;
|
||||
size_t i;
|
||||
|
||||
if (!def)
|
||||
return;
|
||||
|
||||
virDomainMomentDefClear(&def->parent);
|
||||
VIR_FREE(def->file);
|
||||
for (i = 0; i < def->ndisks; i++)
|
||||
virDomainSnapshotDiskDefClear(&def->disks[i]);
|
||||
VIR_FREE(def->disks);
|
||||
virObjectUnref(def->cookie);
|
||||
VIR_FREE(def);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -373,7 +388,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
|
||||
VIR_FREE(nodes);
|
||||
VIR_FREE(memorySnapshot);
|
||||
VIR_FREE(memoryFile);
|
||||
virDomainSnapshotDefFree(def);
|
||||
virObjectUnref(def);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -995,7 +1010,7 @@ virDomainSnapshotRedefinePrep(virDomainPtr domain,
|
||||
/* Drop and rebuild the parent relationship, but keep all
|
||||
* child relations by reusing snap. */
|
||||
virDomainMomentDropParent(other);
|
||||
virDomainSnapshotDefFree(otherdef);
|
||||
virObjectUnref(otherdef);
|
||||
other->def = &(*defptr)->parent;
|
||||
*defptr = NULL;
|
||||
*snap = other;
|
||||
|
@ -115,7 +115,6 @@ virDomainSnapshotDefPtr virDomainSnapshotDefParseNode(xmlDocPtr xml,
|
||||
bool *current,
|
||||
unsigned int flags);
|
||||
virDomainSnapshotDefPtr virDomainSnapshotDefNew(void);
|
||||
void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def);
|
||||
char *virDomainSnapshotDefFormat(const char *uuidstr,
|
||||
virDomainSnapshotDefPtr def,
|
||||
virCapsPtr caps,
|
||||
|
@ -208,8 +208,7 @@ virDomainMomentObjFree(virDomainMomentObjPtr moment)
|
||||
|
||||
VIR_DEBUG("obj=%p", moment);
|
||||
|
||||
/* FIXME: Make this polymorphic by inheriting from virObject */
|
||||
virDomainSnapshotDefFree(virDomainSnapshotObjGetDef(moment));
|
||||
virObjectUnref(moment->def);
|
||||
VIR_FREE(moment);
|
||||
}
|
||||
|
||||
|
@ -4081,7 +4081,6 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc,
|
||||
unsigned int flags)
|
||||
{
|
||||
esxPrivate *priv = domain->conn->privateData;
|
||||
virDomainSnapshotDefPtr def = NULL;
|
||||
esxVI_ObjectContent *virtualMachine = NULL;
|
||||
esxVI_VirtualMachineSnapshotTree *rootSnapshotList = NULL;
|
||||
esxVI_VirtualMachineSnapshotTree *snapshotTree = NULL;
|
||||
@ -4091,6 +4090,7 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc,
|
||||
virDomainSnapshotPtr snapshot = NULL;
|
||||
bool diskOnly = (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) != 0;
|
||||
bool quiesce = (flags & VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE) != 0;
|
||||
VIR_AUTOUNREF(virDomainSnapshotDefPtr) def = NULL;
|
||||
|
||||
/* ESX supports disk-only and quiesced snapshots; libvirt tracks no
|
||||
* snapshot metadata so supporting that flag is trivial. */
|
||||
@ -4151,7 +4151,6 @@ esxDomainSnapshotCreateXML(virDomainPtr domain, const char *xmlDesc,
|
||||
snapshot = virGetDomainSnapshot(domain, def->parent.name);
|
||||
|
||||
cleanup:
|
||||
virDomainSnapshotDefFree(def);
|
||||
esxVI_ObjectContent_Free(&virtualMachine);
|
||||
esxVI_VirtualMachineSnapshotTree_Free(&rootSnapshotList);
|
||||
esxVI_ManagedObjectReference_Free(&task);
|
||||
|
@ -892,7 +892,6 @@ virSecretEventValueChangedNew;
|
||||
# conf/snapshot_conf.h
|
||||
virDomainSnapshotAlignDisks;
|
||||
virDomainSnapshotDefFormat;
|
||||
virDomainSnapshotDefFree;
|
||||
virDomainSnapshotDefIsExternal;
|
||||
virDomainSnapshotDefNew;
|
||||
virDomainSnapshotDefParseString;
|
||||
|
@ -481,7 +481,7 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm,
|
||||
|
||||
snap = virDomainSnapshotAssignDef(vm->snapshots, def);
|
||||
if (snap == NULL) {
|
||||
virDomainSnapshotDefFree(def);
|
||||
virObjectUnref(def);
|
||||
} else if (cur) {
|
||||
if (current)
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
@ -15552,7 +15552,6 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
|
||||
char *xml = NULL;
|
||||
virDomainMomentObjPtr snap = NULL;
|
||||
virDomainSnapshotPtr snapshot = NULL;
|
||||
virDomainSnapshotDefPtr def = NULL;
|
||||
virDomainMomentObjPtr current = NULL;
|
||||
bool update_current = true;
|
||||
bool redefine = flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE;
|
||||
@ -15564,6 +15563,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
|
||||
virCapsPtr caps = NULL;
|
||||
qemuDomainObjPrivatePtr priv;
|
||||
virDomainSnapshotState state;
|
||||
VIR_AUTOFREE(virDomainSnapshotDefPtr) def = NULL;
|
||||
|
||||
virCheckFlags(VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE |
|
||||
VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT |
|
||||
@ -15831,7 +15831,6 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
|
||||
|
||||
cleanup:
|
||||
virDomainObjEndAPI(&vm);
|
||||
virDomainSnapshotDefFree(def);
|
||||
VIR_FREE(xml);
|
||||
virObjectUnref(caps);
|
||||
virObjectUnref(cfg);
|
||||
|
@ -848,7 +848,7 @@ testParseDomainSnapshots(testDriverPtr privconn,
|
||||
goto error;
|
||||
|
||||
if (!(snap = virDomainSnapshotAssignDef(domobj->snapshots, def))) {
|
||||
virDomainSnapshotDefFree(def);
|
||||
virObjectUnref(def);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -6348,13 +6348,13 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
|
||||
{
|
||||
testDriverPtr privconn = domain->conn->privateData;
|
||||
virDomainObjPtr vm = NULL;
|
||||
virDomainSnapshotDefPtr def = NULL;
|
||||
virDomainMomentObjPtr snap = NULL;
|
||||
virDomainSnapshotPtr snapshot = NULL;
|
||||
virObjectEventPtr event = NULL;
|
||||
bool update_current = true;
|
||||
bool redefine = flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE;
|
||||
unsigned int parse_flags = VIR_DOMAIN_SNAPSHOT_PARSE_DISKS;
|
||||
VIR_AUTOUNREF(virDomainSnapshotDefPtr) def = NULL;
|
||||
|
||||
/*
|
||||
* DISK_ONLY: Not implemented yet
|
||||
@ -6448,7 +6448,6 @@ testDomainSnapshotCreateXML(virDomainPtr domain,
|
||||
virDomainObjEndAPI(&vm);
|
||||
}
|
||||
virObjectEventStateQueue(privconn->eventState, event);
|
||||
virDomainSnapshotDefFree(def);
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
|
@ -5476,7 +5476,6 @@ vboxDomainSnapshotCreateXML(virDomainPtr dom,
|
||||
unsigned int flags)
|
||||
{
|
||||
vboxDriverPtr data = dom->conn->privateData;
|
||||
virDomainSnapshotDefPtr def = NULL;
|
||||
vboxIID domiid;
|
||||
IMachine *machine = NULL;
|
||||
IConsole *console = NULL;
|
||||
@ -5488,6 +5487,7 @@ vboxDomainSnapshotCreateXML(virDomainPtr dom,
|
||||
nsresult rc;
|
||||
resultCodeUnion result;
|
||||
virDomainSnapshotPtr ret = NULL;
|
||||
VIR_AUTOUNREF(virDomainSnapshotDefPtr) def = NULL;
|
||||
|
||||
if (!data->vboxObj)
|
||||
return ret;
|
||||
@ -5587,7 +5587,6 @@ vboxDomainSnapshotCreateXML(virDomainPtr dom,
|
||||
gVBoxAPI.UISession.Close(data->vboxSession);
|
||||
VBOX_RELEASE(machine);
|
||||
vboxIIDUnalloc(&domiid);
|
||||
virDomainSnapshotDefFree(def);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -6200,7 +6199,6 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
|
||||
ISnapshot *snap = NULL;
|
||||
ISnapshot *parent = NULL;
|
||||
nsresult rc;
|
||||
virDomainSnapshotDefPtr def = NULL;
|
||||
PRUnichar *str16;
|
||||
char *str8;
|
||||
PRInt64 timestamp;
|
||||
@ -6208,6 +6206,7 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
|
||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||
char *ret = NULL;
|
||||
virDomainDefPtr defdom;
|
||||
VIR_AUTOUNREF(virDomainSnapshotDefPtr) def = NULL;
|
||||
|
||||
if (!data->vboxObj)
|
||||
return ret;
|
||||
@ -6330,7 +6329,6 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
|
||||
ret = virDomainSnapshotDefFormat(uuidstr, def, data->caps, data->xmlopt, 0);
|
||||
|
||||
cleanup:
|
||||
virDomainSnapshotDefFree(def);
|
||||
VBOX_RELEASE(parent);
|
||||
VBOX_RELEASE(snap);
|
||||
VBOX_RELEASE(machine);
|
||||
|
@ -2576,7 +2576,6 @@ vzDomainSnapshotCreateXML(virDomainPtr domain,
|
||||
const char *xmlDesc,
|
||||
unsigned int flags)
|
||||
{
|
||||
virDomainSnapshotDefPtr def = NULL;
|
||||
virDomainSnapshotPtr snapshot = NULL;
|
||||
virDomainObjPtr dom;
|
||||
vzConnPtr privconn = domain->conn->privateData;
|
||||
@ -2585,6 +2584,7 @@ vzDomainSnapshotCreateXML(virDomainPtr domain,
|
||||
virDomainSnapshotObjListPtr snapshots = NULL;
|
||||
virDomainMomentObjPtr current;
|
||||
bool job = false;
|
||||
VIR_AUTOUNREF(virDomainSnapshotDefPtr) def = NULL;
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
@ -2636,7 +2636,6 @@ vzDomainSnapshotCreateXML(virDomainPtr domain,
|
||||
|
||||
cleanup:
|
||||
virDomainSnapshotObjListFree(snapshots);
|
||||
virDomainSnapshotDefFree(def);
|
||||
if (job)
|
||||
vzDomainObjEndJob(dom);
|
||||
virDomainObjEndAPI(&dom);
|
||||
|
@ -35,10 +35,10 @@ testCompareXMLToXMLFiles(const char *inxml,
|
||||
char *outXmlData = NULL;
|
||||
char *actual = NULL;
|
||||
int ret = -1;
|
||||
virDomainSnapshotDefPtr def = NULL;
|
||||
unsigned int parseflags = VIR_DOMAIN_SNAPSHOT_PARSE_DISKS;
|
||||
unsigned int formatflags = VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE;
|
||||
bool cur = false;
|
||||
VIR_AUTOUNREF(virDomainSnapshotDefPtr) def = NULL;
|
||||
|
||||
if (flags & TEST_INTERNAL) {
|
||||
parseflags |= VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL;
|
||||
@ -85,7 +85,6 @@ testCompareXMLToXMLFiles(const char *inxml,
|
||||
VIR_FREE(inXmlData);
|
||||
VIR_FREE(outXmlData);
|
||||
VIR_FREE(actual);
|
||||
virDomainSnapshotDefFree(def);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user