Re: [PATCH v6 05/15] ubifs: Rename whiteout atomically
From: Zhihao Cheng
Date: Mon Jan 10 2022 - 04:35:12 EST
Hi, Richard
How do you make sure the the whiteout is never written to disk (by writeback) before ubifs_jnl_rename() linked
it? That's the reason why other filesystems use the tmpfile mechanism for whiteouts too.
The whiteout inode is clean after creation from create_whiteout(), and
it can't be marked dirty until ubifs_jnl_rename() finished. So, I think
there is no chance for whiteout being written on disk. Then,
'ubifs_assert(c, !whiteout_ui->dirty)' never fails in ubifs_jnl_rename()
during my local stress tests. You may add some delay executions after
whiteout creation to make sure that whiteout won't be written back
before ubifs_jnl_rename().
BTW, I considered plan B(Binding whiteout to a negative dentry), but we
cannot get parent dir's entry in do_rename(), so I abandoned it.
--- a/fs/ubifs/dir.c
+++ b/fs/ubifs/dir.c
@@ -1334,7 +1335,8 @@ static int do_rename(struct inode *old_dir, struct
dentry *old_dentry,
goto out_release;
}
- err = do_tmpfile(old_dir, old_dentry, S_IFCHR |
WHITEOUT_MODE, &whiteout);
+ // tmp_dentry = d_alloc(old_dir_dentry, &slash_name);
// refer to vfs_tmpfile
+ err = do_tmpfile(old_dir, tmp_dentry, S_IFCHR |
WHITEOUT_MODE, &whiteout);
if (err) {
kfree(dev);
goto out_release;