Skip to content

Commit 703c88e

Browse files
fdmananaChris Mason
authored andcommitted
Btrfs: fix tracking of orphan inode count
In inode.c:btrfs_orphan_add() if we failed to insert the orphan item, we would return without decrementing the orphan count that we just incremented before attempting the insertion, leaving the orphan inode count wrong. In inode.c:btrfs_orphan_del(), we were decrementing the inode orphan count if the bit BTRFS_INODE_ORPHAN_META_RESERVED was set, which is logically wrong because it should be decremented if the bit BTRFS_INODE_HAS_ORPHAN_ITEM was set - after all we increment the count when we set the bit BTRFS_INODE_HAS_ORPHAN_ITEM elsewhere. Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
1 parent fe09e16 commit 703c88e

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎fs/btrfs/inode.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,6 +2969,7 @@ int btrfs_orphan_add(struct btrfs_trans_handle *trans, struct inode *inode)
29692969
if (insert >= 1) {
29702970
ret = btrfs_insert_orphan_item(trans, root, btrfs_ino(inode));
29712971
if (ret) {
2972+
atomic_dec(&root->orphan_inodes);
29722973
if (reserve) {
29732974
clear_bit(BTRFS_INODE_ORPHAN_META_RESERVED,
29742975
&BTRFS_I(inode)->runtime_flags);
@@ -3018,14 +3019,16 @@ static int btrfs_orphan_del(struct btrfs_trans_handle *trans,
30183019
release_rsv = 1;
30193020
spin_unlock(&root->orphan_lock);
30203021

3021-
if (trans && delete_item)
3022-
ret = btrfs_del_orphan_item(trans, root, btrfs_ino(inode));
3023-
3024-
if (release_rsv) {
3025-
btrfs_orphan_release_metadata(inode);
3022+
if (delete_item) {
30263023
atomic_dec(&root->orphan_inodes);
3024+
if (trans)
3025+
ret = btrfs_del_orphan_item(trans, root,
3026+
btrfs_ino(inode));
30273027
}
30283028

3029+
if (release_rsv)
3030+
btrfs_orphan_release_metadata(inode);
3031+
30293032
return ret;
30303033
}
30313034

0 commit comments

Comments
 (0)