Skip to content

Commit

Permalink
Btrfs: fix cleaner thread not working with inode cache option
Browse files Browse the repository at this point in the history
Right now inode cache inode is treated as the same as space cache
inode, ie. keep inode in memory till putting super.

But this leads to an awkward situation.

If we're going to delete a snapshot/subvolume, btrfs will not
actually delete it and return free space, but will add it to dead
roots list until the last inode on this snap/subvol being destroyed.
Then we'll fetch deleted roots and cleanup them via cleaner thread.

So here is the problem, if we enable inode cache option, each
snap/subvol has a cached inode which is used to store inode allcation
information.  And this cache inode will be kept in memory, as the above
said.  So with inode cache, snap/subvol can only be added into
dead roots list during freeing roots stage in umount, so that we can
ONLY get space back after another remount(we cleanup dead roots on mount).

But the real thing is we'll no more use the snap/subvol if we mark it
deleted, so we can safely iput its cache inode when we delete snap/subvol.

Another thing is that we need to change the rules of droping inode, we
don't keep snap/subvol's cache inode in memory till end so that we can
add snap/subvol into dead roots list in time.

Reported-by: Mitch Harder <mitch.harder@sabayonlinux.org>
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
  • Loading branch information
Liu Bo authored and Josef Bacik committed Feb 20, 2013
1 parent d4edf39 commit fa6ac87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -7315,8 +7315,9 @@ int btrfs_drop_inode(struct inode *inode)
{
struct btrfs_root *root = BTRFS_I(inode)->root;

/* the snap/subvol tree is on deleting */
if (btrfs_root_refs(&root->root_item) == 0 &&
!btrfs_is_free_space_inode(inode))
root != root->fs_info->tree_root)
return 1;
else
return generic_drop_inode(inode);
Expand Down
6 changes: 6 additions & 0 deletions fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2174,6 +2174,12 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
shrink_dcache_sb(root->fs_info->sb);
btrfs_invalidate_inodes(dest);
d_delete(dentry);

/* the last ref */
if (dest->cache_inode) {
iput(dest->cache_inode);
dest->cache_inode = NULL;
}
}
out_dput:
dput(dentry);
Expand Down

0 comments on commit fa6ac87

Please sign in to comment.