libvirt/src/qemu/qemu_snapshot.h
Peter Krempa ec8be9aceb qemu: Avoid use of '-loadvm' commandline argument for internal snapshot reversion
The '-loadvm' commandline parameter has exactly the same semantics as
the HMP 'loadvm' command. This includes the selection of which block
device is considered to contain the 'vmstate' section.

Since libvirt recently switched to the new QMP commands which allow a
free selection of where the 'vmstate' is placed, snapshot reversion will
no longer work if libvirt's algorithm disagrees with qemu's. This is the
case when the VM has UEFI NVRAM image, in qcow2 format, present.

To solve this we'll use the QMP counterpart 'snapshot-load' to load the
snapshot instead of using '-loadvm'. We'll do this before resuming
processors after startup of qemu and thus the behaviour is identical to
what we had before.

The logic for selecting the images now checks both the snapshot metadata
and the VM definition. In case images not covered by the snapshot
definition do have the snapshot it's included in the reversion, but it's
fatal if the snapshot is not present in a disk covered in snapshot
metadata.

The vmstate is selected based on where it's present as libvirt doesn't
store this information.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2024-11-18 13:51:13 +01:00

92 lines
2.9 KiB
C

/*
* qemu_snapshot.h: Implementation and handling of snapshots
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "virconftypes.h"
#include "qemu_conf.h"
#include "qemu_domainjob.h"
virDomainMomentObj *
qemuSnapObjFromName(virDomainObj *vm,
const char *name);
virDomainMomentObj *
qemuSnapObjFromSnapshot(virDomainObj *vm,
virDomainSnapshotPtr snapshot);
int
qemuSnapshotFSFreeze(virDomainObj *vm,
const char **mountpoints,
unsigned int nmountpoints);
int
qemuSnapshotFSThaw(virDomainObj *vm,
bool report);
virDomainSnapshotPtr
qemuSnapshotCreateXML(virDomainPtr domain,
virDomainObj *vm,
const char *xmlDesc,
unsigned int flags);
int
qemuSnapshotRevert(virDomainObj *vm,
virDomainSnapshotPtr snapshot,
unsigned int flags);
int
qemuSnapshotDiscardAllMetadata(virQEMUDriver *driver,
virDomainObj *vm);
int
qemuSnapshotDelete(virDomainObj *vm,
virDomainSnapshotPtr snapshot,
unsigned int flags);
typedef struct _qemuSnapshotDiskContext qemuSnapshotDiskContext;
qemuSnapshotDiskContext *
qemuSnapshotDiskContextNew(size_t ndisks,
virDomainObj *vm,
virDomainAsyncJob asyncJob);
void
qemuSnapshotDiskContextCleanup(qemuSnapshotDiskContext *snapctxt);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuSnapshotDiskContext, qemuSnapshotDiskContextCleanup);
int
qemuSnapshotDiskPrepareOne(qemuSnapshotDiskContext *snapctxt,
virDomainDiskDef *disk,
virDomainSnapshotDiskDef *snapdisk,
GHashTable *blockNamedNodeData,
bool reuse,
bool updateConfig);
int
qemuSnapshotDiskCreate(qemuSnapshotDiskContext *snapctxt);
virDomainSnapshotDiskDef *
qemuSnapshotGetTransientDiskDef(virDomainDiskDef *domdisk,
const char *suffix);
int
qemuSnapshotInternalRevert(virDomainObj *vm,
virDomainMomentObj *snapshot,
virDomainAsyncJob asyncJob);