Skip to contentSkip to conversation

ext4: recheck buffer uptodate bit under buffer lock

PATCH Applied Zhang Yi 3 participants 3 messages Sep 10, 2021 – Oct 1, 2021 ext4 file system

lore
Share & tools
lore

Zhang Yi

author reviewer
#0 lore raw

PATCH 1/1 ext4: recheck buffer uptodate bit under buffer lock

Commit 8e33fadf945a ("ext4: remove an unnecessary if statement in __ext4_get_inode_loc()") forget to recheck buffer's uptodate bit again under buffer lock, which may overwrite the buffer if someone else have already brought it uptodate and changed it.

Fixes 8e33fadf945a ("ext4: remove an unnecessary if statement in __ext4_get_inode_loc()")
---
 fs/ext4/inode.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/ext4/inode.c +6 -0
index d18852d6029c..236adc647eb0 100644
@@ -4340,6 +4340,12 @@ static int __ext4_get_inode_loc(struct super_block *sb, unsigned long ino,
 		goto has_buffer;
 
 	lock_buffer(bh);
+	if (ext4_buffer_uptodate(bh)) {
+		/* Someone brought it uptodate while we waited */
+		unlock_buffer(bh);
+		goto has_buffer;
+	}
+
 	/*
 	 * If we have all information of the inode in memory and this
 	 * is the only valid inode in the block, we need not read the
Signature · 1 line
2.31.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Zhang Yi

Commit 8e33fadf945a ("ext4: remove an unnecessary if statement in __ext4_get_inode_loc()") forget to recheck buffer's uptodate bit again under buffer lock, which may overwrite the buffer if someone else have already brought it uptodate and changed it.

Fixes 8e33fadf945a ("ext4: remove an unnecessary if statement in __ext4_get_inode_loc()")

Oh, right. Thanks for fixing this. Feel free to add:

Honza

Quoted 24 lines
---
 fs/ext4/inode.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/ext4/inode.c +6 -0
index d18852d6029c..236adc647eb0 100644
@@ -4340,6 +4340,12 @@ static int __ext4_get_inode_loc(struct super_block *sb, unsigned long ino,
 		goto has_buffer;
 
 	lock_buffer(bh);
+	if (ext4_buffer_uptodate(bh)) {
+		/* Someone brought it uptodate while we waited */
+		unlock_buffer(bh);
+		goto has_buffer;
+	}
+
 	/*
 	 * If we have all information of the inode in memory and this
 	 * is the only valid inode in the block, we need not read the
Signature · 1 line
2.31.1
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer Applied
#2 lore raw
In reply to Zhang Yi
Quoted 6 lines · Zhang Yi

Commit 8e33fadf945a ("ext4: remove an unnecessary if statement in __ext4_get_inode_loc()") forget to recheck buffer's uptodate bit again under buffer lock, which may overwrite the buffer if someone else have already brought it uptodate and changed it.

Applied, thanks!

[1/1] ext4: recheck buffer uptodate bit under buffer lock

      commit: f2c77973507fd116c3657df1dc048864a2b16a1c

Best regards,

Signature · 1 line
Theodore Ts'o <[email protected]>