[rh8,7/9] ext4: make data=writeback mode safe

Submitted by Konstantin Khorenko on March 3, 2021, 4:31 p.m.

Details

Message ID 20210303163118.294216-8-khorenko@virtuozzo.com
State New
Series "ext4: Port balloon code and other ext4 fixes"
Headers show

Commit Message

Konstantin Khorenko March 3, 2021, 4:31 p.m.
From: Kirill Tkhai <ktkhai@parallels.com>

It is not obvious, but delalloc makes data=writeback mode safer.
This is because actual data allocation happens inside writepages,
So stale blocks after unclean umount no longer an issue.

So in order to make data=writeback mode reliable we can not
temporarily disable delalloc in case of low diskspace. It must
be enabled permanently. Original discussion:
  http://thread.gmane.org/gmane.comp.file-systems.ext4/19527

https://jira.sw.ru:9443/browse/PCLIN-299

diff-ms-ext4-safe-writeback

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
Signed-off-by: Kirill Tkhai <ktkhai@parallels.com>

(cherry picked from vz7 commit 025b3611cf3eba7f1a83bf34c05ea439c4ade410)
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 fs/ext4/inode.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 95db85e44ce6..34893ab118dc 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3006,8 +3006,15 @@  static int ext4_nonda_switch(struct super_block *sb)
 	if (dirty_clusters && (free_clusters < 2 * dirty_clusters))
 		try_to_writeback_inodes_sb(sb, WB_REASON_FS_FREE_SPACE);
 
-	if (2 * free_clusters < 3 * dirty_clusters ||
-	    free_clusters < (dirty_clusters + EXT4_FREECLUSTERS_WATERMARK)) {
+	/*
+	 * NOTE: Delalloc make data=writeback mode safer, similar to ordered
+	 * mode, so stale blocks after power failure no longer an issue Do not
+	 * disable delalloc to guarantee data security on data=writeback mode.
+	 *								-dmon
+	 */
+	if (test_opt(sb, DATA_FLAGS) != EXT4_MOUNT_WRITEBACK_DATA &&
+	    (2 * free_clusters < 3 * dirty_clusters ||
+	     free_clusters < (dirty_clusters + EXT4_FREECLUSTERS_WATERMARK))) {
 		/*
 		 * free block count is less than 150% of dirty blocks
 		 * or free blocks is less than watermark