提交 a9725126 编写于 作者: T Taowei 提交者: Michal Privoznik

vbox: Rewrite vboxDomainRevertToSnapshot

上级 410b2183
......@@ -6444,3 +6444,71 @@ int vboxDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
vboxIIDUnalloc(&iid);
return ret;
}
int vboxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
unsigned int flags)
{
virDomainPtr dom = snapshot->domain;
VBOX_OBJECT_CHECK(dom->conn, int, -1);
vboxIIDUnion domiid;
IMachine *machine = NULL;
ISnapshot *newSnapshot = NULL;
ISnapshot *prevSnapshot = NULL;
PRBool online = PR_FALSE;
PRUint32 state;
nsresult rc;
virCheckFlags(0, -1);
if (openSessionForMachine(data, dom->uuid, &domiid, &machine, false) < 0)
goto cleanup;
newSnapshot = vboxDomainSnapshotGet(data, dom, machine, snapshot->name);
if (!newSnapshot)
goto cleanup;
rc = gVBoxAPI.UISnapshot.GetOnline(newSnapshot, &online);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("could not get online state of snapshot %s"),
snapshot->name);
goto cleanup;
}
rc = gVBoxAPI.UIMachine.GetCurrentSnapshot(machine, &prevSnapshot);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("could not get current snapshot of domain %s"),
dom->name);
goto cleanup;
}
rc = gVBoxAPI.UIMachine.GetState(machine, &state);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("could not get domain state"));
goto cleanup;
}
if (gVBoxAPI.machineStateChecker.Online(state)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("cannot revert snapshot of running domain"));
goto cleanup;
}
if (gVBoxAPI.snapshotRestore(dom, machine, newSnapshot))
goto cleanup;
if (online) {
ret = vboxDomainCreate(dom);
if (!ret)
gVBoxAPI.snapshotRestore(dom, machine, prevSnapshot);
} else
ret = 0;
cleanup:
VBOX_RELEASE(prevSnapshot);
VBOX_RELEASE(newSnapshot);
vboxIIDUnalloc(&domiid);
return ret;
}
......@@ -1525,7 +1525,7 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
#if VBOX_API_VERSION < 3001000
static int
vboxDomainSnapshotRestore(virDomainPtr dom,
_vboxDomainSnapshotRestore(virDomainPtr dom,
IMachine *machine,
ISnapshot *snapshot)
{
......@@ -1555,7 +1555,7 @@ vboxDomainSnapshotRestore(virDomainPtr dom,
}
#else
static int
vboxDomainSnapshotRestore(virDomainPtr dom,
_vboxDomainSnapshotRestore(virDomainPtr dom,
IMachine *machine,
ISnapshot *snapshot)
{
......@@ -1630,81 +1630,6 @@ vboxDomainSnapshotRestore(virDomainPtr dom,
}
#endif
static int
vboxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
unsigned int flags)
{
virDomainPtr dom = snapshot->domain;
VBOX_OBJECT_CHECK(dom->conn, int, -1);
vboxIID domiid = VBOX_IID_INITIALIZER;
IMachine *machine = NULL;
ISnapshot *newSnapshot = NULL;
ISnapshot *prevSnapshot = NULL;
PRBool online = PR_FALSE;
PRUint32 state;
nsresult rc;
virCheckFlags(0, -1);
vboxIIDFromUUID(&domiid, dom->uuid);
rc = VBOX_OBJECT_GET_MACHINE(domiid.value, &machine);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_NO_DOMAIN, "%s",
_("no domain with matching UUID"));
goto cleanup;
}
newSnapshot = vboxDomainSnapshotGet(data, dom, machine, snapshot->name);
if (!newSnapshot)
goto cleanup;
rc = newSnapshot->vtbl->GetOnline(newSnapshot, &online);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("could not get online state of snapshot %s"),
snapshot->name);
goto cleanup;
}
rc = machine->vtbl->GetCurrentSnapshot(machine, &prevSnapshot);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("could not get current snapshot of domain %s"),
dom->name);
goto cleanup;
}
rc = machine->vtbl->GetState(machine, &state);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("could not get domain state"));
goto cleanup;
}
if (state >= MachineState_FirstOnline
&& state <= MachineState_LastOnline) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("cannot revert snapshot of running domain"));
goto cleanup;
}
if (vboxDomainSnapshotRestore(dom, machine, newSnapshot))
goto cleanup;
if (online) {
ret = vboxDomainCreate(dom);
if (!ret)
vboxDomainSnapshotRestore(dom, machine, prevSnapshot);
} else
ret = 0;
cleanup:
VBOX_RELEASE(prevSnapshot);
VBOX_RELEASE(newSnapshot);
vboxIIDUnalloc(&domiid);
return ret;
}
static int
vboxDomainSnapshotDeleteSingle(vboxGlobalData *data,
IConsole *console,
......@@ -7493,6 +7418,7 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
pVBoxAPI->dumpFloppy = _dumpFloppy;
pVBoxAPI->attachFloppy = _attachFloppy;
pVBoxAPI->detachFloppy = _detachFloppy;
pVBoxAPI->snapshotRestore = _vboxDomainSnapshotRestore;
pVBoxAPI->UPFN = _UPFN;
pVBoxAPI->UIID = _UIID;
pVBoxAPI->UArray = _UArray;
......
......@@ -473,6 +473,7 @@ typedef struct {
void (*dumpFloppy)(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine);
int (*attachFloppy)(vboxGlobalData *data, IMachine *machine, const char *src);
int (*detachFloppy)(IMachine *machine);
int (*snapshotRestore)(virDomainPtr dom, IMachine *machine, ISnapshot *snapshot);
vboxUniformedPFN UPFN;
vboxUniformedIID UIID;
vboxUniformedArray UArray;
......@@ -593,6 +594,8 @@ int vboxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
unsigned int flags);
int vboxDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
unsigned int flags);
int vboxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
unsigned int flags);
/* Version specified functions for installing uniformed API */
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册