mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
qemu_snapshot: create: refactor external snapshot detection
Introduce new function qemuSnapshotCreateUseExternal() that will return true if we will use external snapshots as default location. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
7143c4e1f9
commit
faa2e3bb54
@ -1576,6 +1576,25 @@ qemuSnapshotCreateXMLValidateDef(virDomainObj *vm,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if libvirt should use external snapshots as default align_location
|
||||
* that will be used by virDomainSnapshotAlignDisks(). Otherwise we default
|
||||
* to internal snapshots.
|
||||
*/
|
||||
static bool
|
||||
qemuSnapshotCreateUseExternal(virDomainSnapshotDef *def,
|
||||
unsigned int flags)
|
||||
{
|
||||
if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY)
|
||||
return true;
|
||||
|
||||
if (def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuSnapshotCreateAlignDisks(virDomainObj *vm,
|
||||
virDomainSnapshotDef *def,
|
||||
@ -1584,7 +1603,7 @@ qemuSnapshotCreateAlignDisks(virDomainObj *vm,
|
||||
{
|
||||
g_autofree char *xml = NULL;
|
||||
qemuDomainObjPrivate *priv = vm->privateData;
|
||||
virDomainSnapshotLocation align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
|
||||
virDomainSnapshotLocation align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_DEFAULT;
|
||||
|
||||
/* Easiest way to clone inactive portion of vm->def is via
|
||||
* conversion in and back out of xml. */
|
||||
@ -1604,17 +1623,19 @@ qemuSnapshotCreateAlignDisks(virDomainObj *vm,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) {
|
||||
if (qemuSnapshotCreateUseExternal(def, flags)) {
|
||||
align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
|
||||
if (virDomainObjIsActive(vm))
|
||||
def->state = VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT;
|
||||
else
|
||||
def->state = VIR_DOMAIN_SNAPSHOT_SHUTOFF;
|
||||
def->memory = VIR_DOMAIN_SNAPSHOT_LOCATION_NO;
|
||||
} else if (def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
|
||||
def->state = virDomainObjGetState(vm, NULL);
|
||||
align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
|
||||
|
||||
if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) {
|
||||
if (virDomainObjIsActive(vm))
|
||||
def->state = VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT;
|
||||
else
|
||||
def->state = VIR_DOMAIN_SNAPSHOT_SHUTOFF;
|
||||
def->memory = VIR_DOMAIN_SNAPSHOT_LOCATION_NO;
|
||||
}
|
||||
} else {
|
||||
align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
|
||||
def->state = virDomainObjGetState(vm, NULL);
|
||||
|
||||
if (virDomainObjIsActive(vm) &&
|
||||
|
Loading…
Reference in New Issue
Block a user