From: Peter Krempa <pkrempa@redhat.com>
The 'sparse' uses a mode in qemu which requires direct access to the
file descriptior of the file itself. If we reside on root-squashed NFS
the FD from 'virQEMUFileOpenAs' may not actually be a file which would
not work with qemu.
Reject such a config with a better error message and add documentation
outlining the quirk.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
src/qemu/qemu_saveimage.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/src/qemu/qemu_saveimage.c b/src/qemu/qemu_saveimage.c
index 23922acd51..a3519f8538 100644
--- a/src/qemu/qemu_saveimage.c
+++ b/src/qemu/qemu_saveimage.c
@@ -423,6 +423,20 @@ qemuSaveImageDecompressionStop(virCommand *cmd,
}
+/**
+ * qemuSaveImageCreateFd:
+ * @vm: domain object
+ * @path: path to the save image file
+ * @wrapperFd: filled with helper structure for the virFileWrapper
+ * @sparse: 'sparse' image format is used for the save image
+ * @needUnlink: if filled with 'true' a new file was created and needs to be
+ * removed on failure
+ * @bypassCache: Don't use cache for the writes of the save image
+ *
+ * Opens the save image @path and prepares it for saving of the VM state.
+ * Returns a file descriptor on succes. The returned FD is a pipe unless @
+ * sparse is true in which case it's an fd to a file.
+ */
static int
qemuSaveImageCreateFd(virDomainObj *vm,
const char *path,
@@ -455,6 +469,16 @@ qemuSaveImageCreateFd(virDomainObj *vm,
if (fd < 0)
return -1;
+ /* 'virQEMUFileOpenAs' can return a pipe/socket in case when it needs to bypass
+ * root-squashed NFS. Since 'sparse' backing format works only with real
+ * files we need to reject such cases */
+ if (sparse && !virFileFDIsRegular(fd)) {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+ _("path '%1$s' can't be opened directly (without the use of helper proces) which is incompatible with 'sparse' save image"),
+ path);
+ return -1;
+ }
+
if (qemuSecuritySetImageFDLabel(priv->driver->securityManager, vm->def, fd) < 0)
return -1;
--
2.53.0