Skip to contentSkip to conversation

Btrfs: fix another orphan cleanup problem

PATCH In review Josef Bacik 2 participants 2 messages Jan 25, 2010 – Jan 26, 2010 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: fix another orphan cleanup problem

Because orphan cleanup now happens well after the fs is all initialized and such, we can run into this problem where we find orphan entries that were just added to the fs, not ones that were added previously during a crash. This does not bode well for the system, and results in a couple of odd things happening, like truncate being run on non-regular files. In order to fix this we just check and see if the inode has been added to the in-memory orphan list, and if it has, set the key to it's inode number - 1 so we don't find this orphan entry again, and continue searching.

This problem kept popping up while running xfs tests, and was 100% reproduceable. With this patch the problem no longer happens. Thanks,

---
 fs/btrfs/inode.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
fs/btrfs/inode.c +11 -0
index c7fbfaa..067f4b5 100644
@@ -2202,6 +2202,17 @@ void btrfs_orphan_cleanup(struct btrfs_root *root)
 		 * the proper thing when we hit it
 		 */
 		spin_lock(&root->list_lock);
+		if (!list_empty(&BTRFS_I(inode)->i_orphan)) {
+			/*
+			 * This inode is on the in-memory list, which means we
+			 * shouldn't be cleaning it up, move on to the next
+			 * orphan item.
+			 */
+			spin_unlock(&root->list_lock);
+			key.offset = inode->i_ino - 1;
+			iput(inode);
+			continue;
+		}
 		list_add(&BTRFS_I(inode)->i_orphan, &root->orphan_list);
 		spin_unlock(&root->list_lock);
 
Signature · 1 line
1.5.4.3
#1 lore raw
Quoted 1 line · Josef Bacik

Because orphan cleanup now happens well after the fs is all initializ=

ed and

Quoted 1 line

such, we can run into this problem where we find orphan entries that =

were just

Quoted 1 line

added to the fs, not ones that were added previously during a crash. =

=A0This does

Quoted 1 line

not bode well for the system, and results in a couple of odd things h=

appening,

Quoted 1 line

like truncate being run on non-regular files. =A0In order to fix this=

we just

Quoted 1 line

check and see if the inode has been added to the in-memory orphan lis=

t, and if

Quoted 1 line

it has, set the key to it's inode number - 1 so we don't find this or=

phan entry

Quoted 4 lines

again, and continue searching.

This problem kept popping up while running xfs tests, and was 100% reproduceable. =A0With this patch the problem no longer happens. =A0T=

hanks,

Quoted 1 line

Hi Josef,

I think this problem was introduced by your previous orphan cleanup fix= =2E
Before I introduced the orphan cleanup regression, orphan cleanup on a subvol was triggered by the first access. Your previous orphan clean = fix
broke this rule, orphan clean is triggered when the first time btrfs_lo= okup
finds a valid inode. I think it's better to keep the old rule. revert y= our
previous changes and add code to open_ctree() to do orphan cleanup for the default subvol.

Regards
Yan, Zheng
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html