mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-08 16:54:49 +00:00
snapshot: implement new APIs for qemu
The two APIs are rather trivial; based on bits and pieces of other existing APIs. It leaves the door open for future extension to qemu to report snapshots without metadata based on reading qcow2 internal snapshot names. * src/qemu/qemu_driver.c (qemuDomainSnapshotIsCurrent) (qemuDomainSnapshotHasMetadata): New functions.
This commit is contained in:
parent
549741ee44
commit
e3559a6e66
@ -10916,6 +10916,87 @@ cleanup:
|
||||
return xml;
|
||||
}
|
||||
|
||||
static int
|
||||
qemuDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
|
||||
unsigned int flags)
|
||||
{
|
||||
struct qemud_driver *driver = snapshot->domain->conn->privateData;
|
||||
virDomainObjPtr vm = NULL;
|
||||
int ret = -1;
|
||||
virDomainSnapshotObjPtr snap = NULL;
|
||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
qemuDriverLock(driver);
|
||||
virUUIDFormat(snapshot->domain->uuid, uuidstr);
|
||||
vm = virDomainFindByUUID(&driver->domains, snapshot->domain->uuid);
|
||||
if (!vm) {
|
||||
qemuReportError(VIR_ERR_NO_DOMAIN,
|
||||
_("no domain with matching uuid '%s'"), uuidstr);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
snap = virDomainSnapshotFindByName(&vm->snapshots, snapshot->name);
|
||||
if (!snap) {
|
||||
qemuReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
|
||||
_("no domain snapshot with matching name '%s'"),
|
||||
snapshot->name);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = (vm->current_snapshot &&
|
||||
STREQ(snapshot->name, vm->current_snapshot->def->name));
|
||||
|
||||
cleanup:
|
||||
if (vm)
|
||||
virDomainObjUnlock(vm);
|
||||
qemuDriverUnlock(driver);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
|
||||
unsigned int flags)
|
||||
{
|
||||
struct qemud_driver *driver = snapshot->domain->conn->privateData;
|
||||
virDomainObjPtr vm = NULL;
|
||||
int ret = -1;
|
||||
virDomainSnapshotObjPtr snap = NULL;
|
||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
qemuDriverLock(driver);
|
||||
virUUIDFormat(snapshot->domain->uuid, uuidstr);
|
||||
vm = virDomainFindByUUID(&driver->domains, snapshot->domain->uuid);
|
||||
if (!vm) {
|
||||
qemuReportError(VIR_ERR_NO_DOMAIN,
|
||||
_("no domain with matching uuid '%s'"), uuidstr);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
snap = virDomainSnapshotFindByName(&vm->snapshots, snapshot->name);
|
||||
if (!snap) {
|
||||
qemuReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
|
||||
_("no domain snapshot with matching name '%s'"),
|
||||
snapshot->name);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
/* XXX Someday, we should recognize internal snapshots in qcow2
|
||||
* images that are not tied to a libvirt snapshot; if we ever do
|
||||
* that, then we would have a reason to return 0 here. */
|
||||
ret = 1;
|
||||
|
||||
cleanup:
|
||||
if (vm)
|
||||
virDomainObjUnlock(vm);
|
||||
qemuDriverUnlock(driver);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* The domain is expected to be locked and inactive. */
|
||||
static int
|
||||
qemuDomainSnapshotRevertInactive(struct qemud_driver *driver,
|
||||
@ -13073,6 +13154,8 @@ static virDriver qemuDriver = {
|
||||
.domainHasCurrentSnapshot = qemuDomainHasCurrentSnapshot, /* 0.8.0 */
|
||||
.domainSnapshotGetParent = qemuDomainSnapshotGetParent, /* 0.9.7 */
|
||||
.domainSnapshotCurrent = qemuDomainSnapshotCurrent, /* 0.8.0 */
|
||||
.domainSnapshotIsCurrent = qemuDomainSnapshotIsCurrent, /* 0.9.13 */
|
||||
.domainSnapshotHasMetadata = qemuDomainSnapshotHasMetadata, /* 0.9.13 */
|
||||
.domainRevertToSnapshot = qemuDomainRevertToSnapshot, /* 0.8.0 */
|
||||
.domainSnapshotDelete = qemuDomainSnapshotDelete, /* 0.8.0 */
|
||||
.qemuDomainMonitorCommand = qemuDomainMonitorCommand, /* 0.8.3 */
|
||||
|
Loading…
Reference in New Issue
Block a user