Commit 045d3967 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: rework arguments of btrfs_unlink_subvol

btrfs_unlink_subvol takes the name of the dentry and the root objectid
based on what kind of inode this is, either a real subvolume link or a
empty one that we inherited as a snapshot.  We need to fix how we unlink
in the case for BTRFS_EMPTY_SUBVOL_DIR_OBJECTID in the future, so rework
btrfs_unlink_subvol to just take the dentry and handle getting the right
objectid given the type of inode this is.  There is no functional change
here, simply pushing the work into btrfs_unlink_subvol() proper.
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent de7999af
...@@ -4238,18 +4238,30 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry) ...@@ -4238,18 +4238,30 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry)
} }
static int btrfs_unlink_subvol(struct btrfs_trans_handle *trans, static int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
struct inode *dir, u64 objectid, struct inode *dir, struct dentry *dentry)
const char *name, int name_len)
{ {
struct btrfs_root *root = BTRFS_I(dir)->root; struct btrfs_root *root = BTRFS_I(dir)->root;
struct btrfs_inode *inode = BTRFS_I(d_inode(dentry));
struct btrfs_path *path; struct btrfs_path *path;
struct extent_buffer *leaf; struct extent_buffer *leaf;
struct btrfs_dir_item *di; struct btrfs_dir_item *di;
struct btrfs_key key; struct btrfs_key key;
const char *name = dentry->d_name.name;
int name_len = dentry->d_name.len;
u64 index; u64 index;
int ret; int ret;
u64 objectid;
u64 dir_ino = btrfs_ino(BTRFS_I(dir)); u64 dir_ino = btrfs_ino(BTRFS_I(dir));
if (btrfs_ino(inode) == BTRFS_FIRST_FREE_OBJECTID) {
objectid = inode->root->root_key.objectid;
} else if (btrfs_ino(inode) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID) {
objectid = inode->location.objectid;
} else {
WARN_ON(1);
return -EINVAL;
}
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) if (!path)
return -ENOMEM; return -ENOMEM;
...@@ -4487,8 +4499,7 @@ int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry) ...@@ -4487,8 +4499,7 @@ int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry)
btrfs_record_snapshot_destroy(trans, BTRFS_I(dir)); btrfs_record_snapshot_destroy(trans, BTRFS_I(dir));
ret = btrfs_unlink_subvol(trans, dir, dest->root_key.objectid, ret = btrfs_unlink_subvol(trans, dir, dentry);
dentry->d_name.name, dentry->d_name.len);
if (ret) { if (ret) {
err = ret; err = ret;
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);
...@@ -4583,10 +4594,7 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry) ...@@ -4583,10 +4594,7 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
return PTR_ERR(trans); return PTR_ERR(trans);
if (unlikely(btrfs_ino(BTRFS_I(inode)) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) { if (unlikely(btrfs_ino(BTRFS_I(inode)) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) {
err = btrfs_unlink_subvol(trans, dir, err = btrfs_unlink_subvol(trans, dir, dentry);
BTRFS_I(inode)->location.objectid,
dentry->d_name.name,
dentry->d_name.len);
goto out; goto out;
} }
...@@ -9536,7 +9544,6 @@ static int btrfs_rename_exchange(struct inode *old_dir, ...@@ -9536,7 +9544,6 @@ static int btrfs_rename_exchange(struct inode *old_dir,
u64 new_ino = btrfs_ino(BTRFS_I(new_inode)); u64 new_ino = btrfs_ino(BTRFS_I(new_inode));
u64 old_idx = 0; u64 old_idx = 0;
u64 new_idx = 0; u64 new_idx = 0;
u64 root_objectid;
int ret; int ret;
bool root_log_pinned = false; bool root_log_pinned = false;
bool dest_log_pinned = false; bool dest_log_pinned = false;
...@@ -9642,10 +9649,7 @@ static int btrfs_rename_exchange(struct inode *old_dir, ...@@ -9642,10 +9649,7 @@ static int btrfs_rename_exchange(struct inode *old_dir,
/* src is a subvolume */ /* src is a subvolume */
if (old_ino == BTRFS_FIRST_FREE_OBJECTID) { if (old_ino == BTRFS_FIRST_FREE_OBJECTID) {
root_objectid = BTRFS_I(old_inode)->root->root_key.objectid; ret = btrfs_unlink_subvol(trans, old_dir, old_dentry);
ret = btrfs_unlink_subvol(trans, old_dir, root_objectid,
old_dentry->d_name.name,
old_dentry->d_name.len);
} else { /* src is an inode */ } else { /* src is an inode */
ret = __btrfs_unlink_inode(trans, root, BTRFS_I(old_dir), ret = __btrfs_unlink_inode(trans, root, BTRFS_I(old_dir),
BTRFS_I(old_dentry->d_inode), BTRFS_I(old_dentry->d_inode),
...@@ -9661,10 +9665,7 @@ static int btrfs_rename_exchange(struct inode *old_dir, ...@@ -9661,10 +9665,7 @@ static int btrfs_rename_exchange(struct inode *old_dir,
/* dest is a subvolume */ /* dest is a subvolume */
if (new_ino == BTRFS_FIRST_FREE_OBJECTID) { if (new_ino == BTRFS_FIRST_FREE_OBJECTID) {
root_objectid = BTRFS_I(new_inode)->root->root_key.objectid; ret = btrfs_unlink_subvol(trans, new_dir, new_dentry);
ret = btrfs_unlink_subvol(trans, new_dir, root_objectid,
new_dentry->d_name.name,
new_dentry->d_name.len);
} else { /* dest is an inode */ } else { /* dest is an inode */
ret = __btrfs_unlink_inode(trans, dest, BTRFS_I(new_dir), ret = __btrfs_unlink_inode(trans, dest, BTRFS_I(new_dir),
BTRFS_I(new_dentry->d_inode), BTRFS_I(new_dentry->d_inode),
...@@ -9862,7 +9863,6 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -9862,7 +9863,6 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_inode = d_inode(new_dentry); struct inode *new_inode = d_inode(new_dentry);
struct inode *old_inode = d_inode(old_dentry); struct inode *old_inode = d_inode(old_dentry);
u64 index = 0; u64 index = 0;
u64 root_objectid;
int ret; int ret;
u64 old_ino = btrfs_ino(BTRFS_I(old_inode)); u64 old_ino = btrfs_ino(BTRFS_I(old_inode));
bool log_pinned = false; bool log_pinned = false;
...@@ -9970,10 +9970,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -9970,10 +9970,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
BTRFS_I(old_inode), 1); BTRFS_I(old_inode), 1);
if (unlikely(old_ino == BTRFS_FIRST_FREE_OBJECTID)) { if (unlikely(old_ino == BTRFS_FIRST_FREE_OBJECTID)) {
root_objectid = BTRFS_I(old_inode)->root->root_key.objectid; ret = btrfs_unlink_subvol(trans, old_dir, old_dentry);
ret = btrfs_unlink_subvol(trans, old_dir, root_objectid,
old_dentry->d_name.name,
old_dentry->d_name.len);
} else { } else {
ret = __btrfs_unlink_inode(trans, root, BTRFS_I(old_dir), ret = __btrfs_unlink_inode(trans, root, BTRFS_I(old_dir),
BTRFS_I(d_inode(old_dentry)), BTRFS_I(d_inode(old_dentry)),
...@@ -9992,10 +9989,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -9992,10 +9989,7 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
new_inode->i_ctime = current_time(new_inode); new_inode->i_ctime = current_time(new_inode);
if (unlikely(btrfs_ino(BTRFS_I(new_inode)) == if (unlikely(btrfs_ino(BTRFS_I(new_inode)) ==
BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) { BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) {
root_objectid = BTRFS_I(new_inode)->location.objectid; ret = btrfs_unlink_subvol(trans, new_dir, new_dentry);
ret = btrfs_unlink_subvol(trans, new_dir, root_objectid,
new_dentry->d_name.name,
new_dentry->d_name.len);
BUG_ON(new_inode->i_nlink == 0); BUG_ON(new_inode->i_nlink == 0);
} else { } else {
ret = btrfs_unlink_inode(trans, dest, BTRFS_I(new_dir), ret = btrfs_unlink_inode(trans, dest, BTRFS_I(new_dir),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment