Skip to contentSkip to conversation

ext4:fix different behavior of fsync when use fast commit

PATCH RESEND In review Xin Yin 2 participants 3 messages Dec 24, 2021 – Jan 7, 2022 ext4 file system

lore
Share & tools
lore

Xin Yin

author
#0 lore raw

PATCH RESEND 1/1 ext4:fix different behavior of fsync when use fast commit

For the follow test example:
-mkdir test/
-create&write test/a.txt
-fsync test/a.txt
-crash (before a full commit)

If fast commit is used then "a.txt" will lost, while the normal journaling can recover it.

We should keep behavior of fsync unchanged when use fast commit.

other report: https://www.spinics.net/lists/linux-ext4/msg80514.html

---
 fs/ext4/fast_commit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/fast_commit.c +1 -1
index 3deb97b22ca4..4b843648ffe5 100644
@@ -423,7 +423,7 @@ void __ext4_fc_track_create(handle_t *handle, struct inode *inode,
 	args.op = EXT4_FC_TAG_CREAT;
 
 	ret = ext4_fc_track_template(handle, inode, __track_dentry_update,
-					(void *)&args, 0);
+					(void *)&args, 1);
 	trace_ext4_fc_track_create(inode, dentry, ret);
 }
 
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 8 lines · Xin Yin

For the follow test example:

(quoted diff) +0 -4
-mkdir test/
-create&write test/a.txt
-fsync test/a.txt
-crash (before a full commit)

If fast commit is used then "a.txt" will lost, while the normal journaling can recover it.

The problem is that your proposed fix:

fs/ext4/fast_commit.c void __ext4_fc_track_create(handle_t *handle, struct inode *inode, · line 428

Quoted 12 lines
fs/ext4/fast_commit.c +1 -1
index 3deb97b22ca4..4b843648ffe5 100644
@@ -423,7 +423,7 @@ void __ext4_fc_track_create(handle_t *handle, struct inode *inode,
 	args.op = EXT4_FC_TAG_CREAT;
 
 	ret = ext4_fc_track_template(handle, inode, __track_dentry_update,
-					(void *)&args, 0);
+					(void *)&args, 1);
 	trace_ext4_fc_track_create(inode, dentry, ret);
 }

affects both file creations as well as directory creations (mkdir). Putting the inode on the fast commit list is something that is meant for files, and means that on a fast commit we need to force the data blocks out. So it seems that isn't the right fix for the problem.

Why do something really simple? Look at the parent directory's inode, and check its i_sync_tid. If it's not equal to handle->h_transaction->t_tid, then it's safe to do the fast commit. If it's equal to the current transaction, we can either force a full commit.

Optionally, in the case where i_sync_tid == current tid, since there's a chance that the parent directory's inode could have been freshly fetched from disk (see __ext4_iget() in fs/ext4/inode.c), we could compare its i_crtime against ktime_get_real_seconds(), and if the inode was created in the last 2*journal->j_commit_interval/HZ seconds, it's safe to do a fast commit; otherwise do a full commit.

Cheers,

- Ted

author
#2 lore raw

Thanks for the explanation and direction , I will do another fix for this issue.

Best Regards,
Xin Yin

Quoted 47 lines · Theodore Ts'o
Quoted 8 lines · Xin Yin

For the follow test example:

(quoted diff) +0 -4
-mkdir test/
-create&write test/a.txt
-fsync test/a.txt
-crash (before a full commit)

If fast commit is used then "a.txt" will lost, while the normal journaling can recover it.

The problem is that your proposed fix:

fs/ext4/fast_commit.c void __ext4_fc_track_create(handle_t *handle, struct inode *inode, · line 428

Quoted 12 lines
fs/ext4/fast_commit.c +1 -1
index 3deb97b22ca4..4b843648ffe5 100644
@@ -423,7 +423,7 @@ void __ext4_fc_track_create(handle_t *handle, struct inode *inode,
      args.op = EXT4_FC_TAG_CREAT;
 
      ret = ext4_fc_track_template(handle, inode, __track_dentry_update,
-                                     (void *)&args, 0);
+                                     (void *)&args, 1);
      trace_ext4_fc_track_create(inode, dentry, ret);
 }

affects both file creations as well as directory creations (mkdir). Putting the inode on the fast commit list is something that is meant for files, and means that on a fast commit we need to force the data blocks out. So it seems that isn't the right fix for the problem.

Why do something really simple? Look at the parent directory's inode, and check its i_sync_tid. If it's not equal to handle->h_transaction->t_tid, then it's safe to do the fast commit. If it's equal to the current transaction, we can either force a full commit.

Optionally, in the case where i_sync_tid == current tid, since there's a chance that the parent directory's inode could have been freshly fetched from disk (see __ext4_iget() in fs/ext4/inode.c), we could compare its i_crtime against ktime_get_real_seconds(), and if the inode was created in the last 2*journal->j_commit_interval/HZ seconds, it's safe to do a fast commit; otherwise do a full commit.

Cheers,

- Ted