[rh8,6/9] ext4: guarantee rename atomic behavior

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

Details

Message ID 20210303163118.294216-7-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>

Ext4 already performs block allocation on rename, but
it does it after rename completes, so race window is much tighter
but still exits. In order to guarantee atomic behavior let's
force block allocation before actual rename.

http://wiki.parallels.com/index.php/Ext4_writeback

diff-ms-ext4-force-atomic-rename

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

khorenko@: conflicts in fs/ext4/namei.c
resolved during rebase to rh7 kernel-3.10.0-229.7.2.el7

(cherry picked from vz7 commit 25e508a4bb83052a8f2311cbca8ff38bdaa22727)
Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 fs/ext4/namei.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 953e882b1d61..46391fb93317 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -3562,7 +3562,7 @@  static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
 	 */
 	retval = -ENOENT;
 	if (!old.bh || le32_to_cpu(old.de->inode) != old.inode->i_ino)
-		goto end_rename;
+		goto out_release;
 
 	new.bh = ext4_find_entry(new.dir, &new.dentry->d_name,
 				 &new.de, &new.inlined);
@@ -3707,6 +3707,9 @@  static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
 	retval = 0;
 
 end_rename:
+	if (handle)
+		ext4_journal_stop(handle);
+out_release:
 	brelse(old.dir_bh);
 	brelse(old.bh);
 	brelse(new.bh);
@@ -3716,8 +3719,6 @@  static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
 		unlock_new_inode(whiteout);
 		iput(whiteout);
 	}
-	if (handle)
-		ext4_journal_stop(handle);
 	return retval;
 }