Btrfs: Fix subvolume creation locking rules

Creating a subvolume is in many ways like a normal VFS ->mkdir, and we
really need to play with the VFS topology locking rules.  So instead of
just creating the snapshot on disk and then later getting rid of
confliting aliases do it correctly from the start.  This will become
especially important once we allow for subvolumes anywhere in the tree,
and not just below a hidden root.

Note that snapshots will need the same treatment, but do to the delay
in creating them we can't do it currently.  Chris promised to fix that
issue, so I'll wait on that.

Signed-off-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
Christoph Hellwig
2008-10-09 13:39:39 -04:00
committed by Chris Mason
parent 833023e46c
commit cb8e70901d
3 changed files with 100 additions and 14 deletions

View File

@@ -3420,11 +3420,12 @@ void btrfs_invalidate_dcache_root(struct btrfs_root *root, char *name,
/*
* create a new subvolume directory/inode (helper for the ioctl).
*/
int btrfs_create_subvol_root(struct btrfs_root *new_root,
int btrfs_create_subvol_root(struct btrfs_root *new_root, struct dentry *dentry,
struct btrfs_trans_handle *trans, u64 new_dirid,
struct btrfs_block_group_cache *block_group)
{
struct inode *inode;
int error;
u64 index = 0;
inode = btrfs_new_inode(trans, new_root, NULL, "..", 2, new_dirid,
@@ -3438,7 +3439,12 @@ int btrfs_create_subvol_root(struct btrfs_root *new_root,
inode->i_nlink = 1;
btrfs_i_size_write(inode, 0);
return btrfs_update_inode(trans, new_root, inode);
error = btrfs_update_inode(trans, new_root, inode);
if (error)
return error;
d_instantiate(dentry, inode);
return 0;
}
/* helper function for file defrag and space balancing. This