Skip to contentSkip to conversation

ocfs2: fix a tiny case that inode can not removed.

PATCH New akpm at linux-foundation.org 3 participants 3 messages Aug 26, 2015 – Aug 31, 2015 OCFS2

lore
Share & tools
lore
#0 lore raw

PATCH 7/28 ocfs2: fix a tiny case that inode can not removed.

From: jiangyiwen <[email protected]>
Subject: ocfs2: fix a tiny case that inode can not removed.

When running dirop_fileop_racer we found a case that inode can not removed.

2 nodes, say Node A and Node B, mount the same ocfs2 volume. Create two dirs /race/1/ and /race/2/ in the filesystem.

Node A Node B
rm -r /race/2/

                                  mv /race/1/ /race/2/

call ocfs2_unlink(), get
the EX mode of /race/2/
wait for B unlock /race/2/
decrease i_nlink of /race/2/ to 0,
and add inode of /race/2/ into
orphan dir, unlock /race/2/
got EX mode of /race/2/. because /race/1/ is dir, so inc i_nlink of /race/2/ and update into disk, unlock /race/2/
because i_nlink of /race/2/
is not zero, this inode will
always remain in orphan dir

This patch fixes this case by test whether i_nlink of new dir is zero.

---

 fs/ocfs2/namei.c |    9 +++++++++
 1 file changed, 9 insertions(+)
fs/ocfs2/namei.c renamed from fs/ocfs2/namei.c~ocfs2-fix-a-tiny-case-that-inode-can-not-removed +9 -0
diff -puN fs/ocfs2/namei.c~ocfs2-fix-a-tiny-case-that-inode-can-not-removed fs/ocfs2/namei.c
@@ -1284,6 +1284,15 @@ static int ocfs2_rename(struct inode *ol
 	}
 	parents_locked = 1;
 
+	if (!new_dir->i_nlink) {
+		mlog(ML_ERROR, "new dir %llu has been removed, inode %llu "
+				"can not be moved into it.",
+				(unsigned long long)new_dir->i_ino,
+				(unsigned long long)old_inode->i_ino);
+		status = -EACCES;
+		goto bail;
+	}
+
 	/* make sure both dirs have bhs
 	 * get an extra ref on old_dir_bh if old==new */
 	if (!new_dir_bh) {

_

#1 lore raw

PATCH 7/28 ocfs2: fix a tiny case that inode can not removed.

Quoted 26 lines · Andrew Morton

From: jiangyiwen <[email protected]>
Subject: ocfs2: fix a tiny case that inode can not removed.

When running dirop_fileop_racer we found a case that inode can not removed.

2 nodes, say Node A and Node B, mount the same ocfs2 volume. Create two dirs /race/1/ and /race/2/ in the filesystem.

Node A Node B
rm -r /race/2/

                                  mv /race/1/ /race/2/

call ocfs2_unlink(), get
the EX mode of /race/2/
wait for B unlock /race/2/
decrease i_nlink of /race/2/ to 0,
and add inode of /race/2/ into
orphan dir, unlock /race/2/
got EX mode of /race/2/. because /race/1/ is dir, so inc i_nlink of /race/2/ and update into disk, unlock /race/2/
because i_nlink of /race/2/
is not zero, this inode will
always remain in orphan dir

Quoted 1 line

This patch fixes this case by test whether i_nlink of new dir is zero.

Good catch, thanks for this.

fs/ocfs2/namei.c static int ocfs2_rename(struct inode *ol · line 1291

Quoted 12 lines

diff -puN fs/ocfs2/namei.c~ocfs2-fix-a-tiny-case-that-inode-can-not-removed fs/ocfs2/namei.c

fs/ocfs2/namei.c renamed from fs/ocfs2/namei.c~ocfs2-fix-a-tiny-case-that-inode-can-not-removed +5 -0
@@ -1284,6 +1284,15 @@ static int ocfs2_rename(struct inode *ol
 	}
 	parents_locked = 1;
 
+	if (!new_dir->i_nlink) {
+		mlog(ML_ERROR, "new dir %llu has been removed, inode %llu "
+				"can not be moved into it.",
+				(unsigned long long)new_dir->i_ino,
+				(unsigned long long)old_inode->i_ino);

This is something that is rare, but not an error or otherwise outstanding condition. Therefore printing to the kernel log is not advisable and may confuse users. Please turn that into a debug print or remove it all together, thanks.

	--Mark

--
Mark Fasheh

#2 lore raw

PATCH 7/28 ocfs2: fix a tiny case that inode can not removed.

Quoted 50 lines · Mark Fasheh
Quoted 26 lines · Andrew Morton

From: jiangyiwen <[email protected]>
Subject: ocfs2: fix a tiny case that inode can not removed.

When running dirop_fileop_racer we found a case that inode can not removed.

2 nodes, say Node A and Node B, mount the same ocfs2 volume. Create two dirs /race/1/ and /race/2/ in the filesystem.

Node A Node B
rm -r /race/2/

                                  mv /race/1/ /race/2/

call ocfs2_unlink(), get
the EX mode of /race/2/
wait for B unlock /race/2/
decrease i_nlink of /race/2/ to 0,
and add inode of /race/2/ into
orphan dir, unlock /race/2/
got EX mode of /race/2/. because /race/1/ is dir, so inc i_nlink of /race/2/ and update into disk, unlock /race/2/
because i_nlink of /race/2/
is not zero, this inode will
always remain in orphan dir

Quoted 1 line

This patch fixes this case by test whether i_nlink of new dir is zero.

Good catch, thanks for this.

fs/ocfs2/namei.c static int ocfs2_rename(struct inode *ol · line 1291

Quoted 12 lines

diff -puN fs/ocfs2/namei.c~ocfs2-fix-a-tiny-case-that-inode-can-not-removed fs/ocfs2/namei.c

fs/ocfs2/namei.c renamed from fs/ocfs2/namei.c~ocfs2-fix-a-tiny-case-that-inode-can-not-removed +5 -0
@@ -1284,6 +1284,15 @@ static int ocfs2_rename(struct inode *ol
 	}
 	parents_locked = 1;
 
+	if (!new_dir->i_nlink) {
+		mlog(ML_ERROR, "new dir %llu has been removed, inode %llu "
+				"can not be moved into it.",
+				(unsigned long long)new_dir->i_ino,
+				(unsigned long long)old_inode->i_ino);

This is something that is rare, but not an error or otherwise outstanding condition. Therefore printing to the kernel log is not advisable and may confuse users. Please turn that into a debug print or remove it all together, thanks.

Quoted 7 lines
	--Mark

--
Mark Fasheh

.

OK, thanks Mark, I will resend a new version immediately.

Thanks,
Yiwen Jiang