Skip to contentSkip to conversation

f2fs: write the directory inode in fsync before checkpoint

PATCH In review Daeho Jeong 2 participants 3 messages Oct 7 – Oct 9 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: write the directory inode in fsync before checkpoint

From: Daeho Jeong <[email protected]>

fsync() on a directory is done by a checkpoint, but the checkpoint does not write timestamp-only inode updates. Since commit 7c45729a4d6d ("f2fs: keep dirty inodes selectively for checkpoint"), such updates are marked with sync=false and left to inode writeback on purpose.

fsync() on a regular file calls f2fs_write_inode() first when the inode is dirty, but fsync() on a directory goes to the checkpoint directly and misses it. So if the last change to a directory only updated its timestamps, e.g. unlinking a file in it, the new mtime is lost after a sudden power off even though fsync() returned. generic/547 fails sometimes because of this.

Call f2fs_write_inode() for a directory before the checkpoint, as the regular file path does. The inode block becomes dirty and is written by the same checkpoint, so no extra checkpoint or flush is added. Timestamp-only updates without fsync() are still not written by the checkpoint.

Fixes 7c45729a4d6d ("f2fs: keep dirty inodes selectively for checkpoint")
---
 fs/f2fs/file.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
fs/f2fs/file.c +8 -1
index 56c686b8580..b012cc22307 100644
@@ -351,8 +351,15 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,
 
 	trace_f2fs_sync_file_enter(inode);
 
-	if (S_ISDIR(inode->i_mode))
+	if (S_ISDIR(inode->i_mode)) {
+		/*
+		 * Checkpoint writes only the inodes on the dirty meta list.
+		 * Timestamp updates of a directory, e.g. by unlinking a file
+		 * in it, do not put it on the list, so write it here.
+		 */
+		f2fs_write_inode(inode, NULL);
 		goto go_write;
+	}
 
 	/* if fdatasync is triggered, let's do in-place-update */
 	if (datasync || get_dirty_pages(inode) <= SM_I(sbi)->min_fsync_blocks)
Signature · 1 line
2.56.0.360.g66cac248cb-goog
maintainer
#1 lore raw
Quoted 7 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

fsync() on a directory is done by a checkpoint, but the checkpoint does not write timestamp-only inode updates. Since commit 7c45729a4d6d ("f2fs: keep dirty inodes selectively for checkpoint"), such updates are marked with sync=false and left to inode writeback on purpose.

Quoted 6 lines

fsync() on a regular file calls f2fs_write_inode() first when the inode is dirty, but fsync() on a directory goes to the checkpoint directly and misses it. So if the last change to a directory only updated its timestamps, e.g. unlinking a file in it, the new mtime is lost after a sudden power off even though fsync() returned. generic/547 fails sometimes because of this.

Has 9ec09d5f4b31 ("f2fs: dirty directory inodes on mtime/ctime update") fixed this issue?

Thanks,

Quoted 34 lines

Call f2fs_write_inode() for a directory before the checkpoint, as the regular file path does. The inode block becomes dirty and is written by the same checkpoint, so no extra checkpoint or flush is added. Timestamp-only updates without fsync() are still not written by the checkpoint.

Fixes 7c45729a4d6d ("f2fs: keep dirty inodes selectively for checkpoint")
---
 fs/f2fs/file.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
fs/f2fs/file.c +8 -1
index 56c686b8580..b012cc22307 100644
@@ -351,8 +351,15 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,
 
 	trace_f2fs_sync_file_enter(inode);
 
-	if (S_ISDIR(inode->i_mode))
+	if (S_ISDIR(inode->i_mode)) {
+		/*
+		 * Checkpoint writes only the inodes on the dirty meta list.
+		 * Timestamp updates of a directory, e.g. by unlinking a file
+		 * in it, do not put it on the list, so write it here.
+		 */
+		f2fs_write_inode(inode, NULL);
 		goto go_write;
+	}
 
 	/* if fdatasync is triggered, let's do in-place-update */
 	if (datasync || get_dirty_pages(inode) <= SM_I(sbi)->min_fsync_blocks)
#2 lore raw
Quoted 16 lines · Chao Yu
Quoted 7 lines · Daeho Jeong

From: Daeho Jeong <[email protected]>

fsync() on a directory is done by a checkpoint, but the checkpoint does not write timestamp-only inode updates. Since commit 7c45729a4d6d ("f2fs: keep dirty inodes selectively for checkpoint"), such updates are marked with sync=false and left to inode writeback on purpose.

Quoted 6 lines

fsync() on a regular file calls f2fs_write_inode() first when the inode is dirty, but fsync() on a directory goes to the checkpoint directly and misses it. So if the last change to a directory only updated its timestamps, e.g. unlinking a file in it, the new mtime is lost after a sudden power off even though fsync() returned. generic/547 fails sometimes because of this.

Quoted 4 lines

Has 9ec09d5f4b31 ("f2fs: dirty directory inodes on mtime/ctime update") fixed this issue?

Thanks,

Oh, yes, it does. I missed that commit since I tested on a tree without it. Please drop this patch.

Thanks,

Thanks,

Quoted 36 lines
Quoted 35 lines

Call f2fs_write_inode() for a directory before the checkpoint, as the regular file path does. The inode block becomes dirty and is written by the same checkpoint, so no extra checkpoint or flush is added. Timestamp-only updates without fsync() are still not written by the checkpoint.

Fixes 7c45729a4d6d ("f2fs: keep dirty inodes selectively for checkpoint")
---
 fs/f2fs/file.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
fs/f2fs/file.c +8 -1
index 56c686b8580..b012cc22307 100644
@@ -351,8 +351,15 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,
 
      trace_f2fs_sync_file_enter(inode);
 
-     if (S_ISDIR(inode->i_mode))
+     if (S_ISDIR(inode->i_mode)) {
+             /*
+              * Checkpoint writes only the inodes on the dirty meta list.
+              * Timestamp updates of a directory, e.g. by unlinking a file
+              * in it, do not put it on the list, so write it here.
+              */
+             f2fs_write_inode(inode, NULL);
              goto go_write;
+     }
 
      /* if fdatasync is triggered, let's do in-place-update */
      if (datasync || get_dirty_pages(inode) <= SM_I(sbi)->min_fsync_blocks)