The code executed later when creating a snapshot makes all decisions
based on the configured type rather than the actual type of the existing
file, while the check whether the file exists is based solely on the
on-disk type.
Since a block device is allowed to exist even when not reusing existing
files in contrast to regular files this creates a potential for a block
device to squeak past the check but then be influenced by other code
executed later. Specifically this is a problem when creating a snapshot
with the following XML:
<domainsnapshot>
<disks>
<disk name='vdb' type='file'>
<source file='/dev/sdb'/>
</disk>
</disks>
</domainsnapshot>
If the snapshot creation fails, '/dev/sdb' will be removed because it's
considered to be a regular file by the cleanup code.
Add a check that will force that the configured type matches the on-disk
state.
Additional supporting reason is that qemu stopped to accept block
devices with the 'file' backend, thus the above configuration will not
work any more. This allows us to fail sooner.
Resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=1972145
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_snapshot.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index f06d0ada38..96c43f69e7 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -598,6 +598,15 @@ qemuSnapshotPrepareDiskExternal(virDomainObj *vm,
}
}
} else {
+ /* at this point VIR_STORAGE_TYPE_DIR was already rejected */
+ if ((snapdisk->src->type == VIR_STORAGE_TYPE_BLOCK &&
!S_ISBLK(st.st_mode)) ||
+ (snapdisk->src->type == VIR_STORAGE_TYPE_FILE &&
!S_ISREG(st.st_mode))) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("mismatch between configured type for snapshot disk
'%s' and the type of existing file '%s'"),
+ snapdisk->name, snapdisk->src->path);
+ return -1;
+ }
+
if (!S_ISBLK(st.st_mode) && st.st_size && !reuse) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("external snapshot file for disk %s already "
--
2.31.1