From e944a71f091359bb0c88fbc87241a133d9c3e77d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Fri, 17 Jul 2020 19:28:08 +0100 Subject: [PATCH] storage: convert to use virFileSetCOW MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When disabling COW on individual files, we now use the virFileSetCOW method. Note that this change has a slight semantic difference to the old implementation. The original code reported errors but returned success when disabling COW failed. With this new code, we will always report an error if the user requested disabling of COW and we could not honour it, either because btrfs returned an error, or because the filesystem is not btrfs. Reviewed-by: Neal Gompa Reviewed-by: Peter Krempa Reviewed-by: Michal Privoznik Signed-off-by: Daniel P. Berrangé --- src/storage/storage_util.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index ee048f02fe..2595162a61 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -28,9 +28,6 @@ #ifdef __linux__ # include # include -# ifndef FS_NOCOW_FL -# define FS_NOCOW_FL 0x00800000 /* Do not cow file */ -# endif # define default_mount_opts "nodev,nosuid,noexec" #elif defined(__FreeBSD__) # define default_mount_opts "nosuid,noexec" @@ -456,25 +453,11 @@ storageBackendCreateRaw(virStoragePoolObjPtr pool, } created = true; - if (vol->target.nocow) { -#ifdef __linux__ - int attr; - - /* Set NOCOW flag. This is an optimisation for btrfs. - * The FS_IOC_SETFLAGS ioctl return value will be ignored since any - * failure of this operation should not block the volume creation. - */ - if (ioctl(fd, FS_IOC_GETFLAGS, &attr) < 0) { - virReportSystemError(errno, "%s", _("Failed to get fs flags")); - } else { - attr |= FS_NOCOW_FL; - if (ioctl(fd, FS_IOC_SETFLAGS, &attr) < 0) { - virReportSystemError(errno, "%s", - _("Failed to set NOCOW flag")); - } - } -#endif - } + /* NB, COW flag can only be toggled when the file is zero-size, + * so must go before the createRawFile call allocates payload */ + if (vol->target.nocow && + virFileSetCOW(vol->target.path, VIR_TRISTATE_BOOL_NO) < 0) + goto cleanup; if ((ret = createRawFile(fd, vol, inputvol, reflink_copy)) < 0) /* createRawFile already reported the exact error. */ -- 2.47.2