From f12b2838978d5a199229a5b15375d73fb76664ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Fri, 17 Jul 2020 19:30:48 +0100 Subject: [PATCH] storage: attempt to disable COW by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This calls virFileSetCOW when building a pool with a request to attempt, but not require, COW to be disabled. The effect is that nothing changes on non-btrfs filesystems, but btrfs will get COW disabled on the directory. This setting is then inherited by all newly created files in the pool, avoiding the need for mgmt app to set "nocow" on a per-volume basis. Reviewed-by: Neal Gompa Reviewed-by: Peter Krempa Reviewed-by: Michal Privoznik Signed-off-by: Daniel P. Berrangé --- src/storage/storage_util.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 2595162a61..80b49bd1cf 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -2712,6 +2712,7 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr pool) bool needs_create_as_uid; unsigned int dir_create_flags; g_autofree char *parent = NULL; + int ret; parent = g_strdup(def->target.path); if (!(p = strrchr(parent, '/'))) { @@ -2745,11 +2746,19 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr pool) /* Now create the final dir in the path with the uid/gid/mode * requested in the config. If the dir already exists, just set * the perms. */ - return virDirCreate(def->target.path, - mode, - def->target.perms.uid, - def->target.perms.gid, - dir_create_flags); + ret = virDirCreate(def->target.path, + mode, + def->target.perms.uid, + def->target.perms.gid, + dir_create_flags); + if (ret < 0) + return -1; + + if (virFileSetCOW(def->target.path, + VIR_TRISTATE_BOOL_ABSENT) < 0) + return -1; + + return 0; }