@@ -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);