Skip to content

Commit 4b3a54e

Browse files
fdmananakdave
authored andcommitted
btrfs: use btrfs inodes in btrfs_rmdir() to avoid so much usage of BTRFS_I()
Almost everywhere we want to use a btrfs inode and therefore we have a lot of calls to BTRFS_I(), making the code more verbose. Instead use btrfs inode local variables to avoid so much use of BTRFS_I(). Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent fd97413 commit 4b3a54e

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

fs/btrfs/inode.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4701,32 +4701,33 @@ int btrfs_delete_subvolume(struct btrfs_inode *dir, struct dentry *dentry)
47014701
return ret;
47024702
}
47034703

4704-
static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
4704+
static int btrfs_rmdir(struct inode *vfs_dir, struct dentry *dentry)
47054705
{
4706-
struct inode *inode = d_inode(dentry);
4707-
struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info;
4706+
struct btrfs_inode *dir = BTRFS_I(vfs_dir);
4707+
struct btrfs_inode *inode = BTRFS_I(d_inode(dentry));
4708+
struct btrfs_fs_info *fs_info = inode->root->fs_info;
47084709
int ret = 0;
47094710
struct btrfs_trans_handle *trans;
47104711
struct fscrypt_name fname;
47114712

4712-
if (inode->i_size > BTRFS_EMPTY_DIR_SIZE)
4713+
if (inode->vfs_inode.i_size > BTRFS_EMPTY_DIR_SIZE)
47134714
return -ENOTEMPTY;
4714-
if (btrfs_ino(BTRFS_I(inode)) == BTRFS_FIRST_FREE_OBJECTID) {
4715+
if (btrfs_ino(inode) == BTRFS_FIRST_FREE_OBJECTID) {
47154716
if (unlikely(btrfs_fs_incompat(fs_info, EXTENT_TREE_V2))) {
47164717
btrfs_err(fs_info,
47174718
"extent tree v2 doesn't support snapshot deletion yet");
47184719
return -EOPNOTSUPP;
47194720
}
4720-
return btrfs_delete_subvolume(BTRFS_I(dir), dentry);
4721+
return btrfs_delete_subvolume(dir, dentry);
47214722
}
47224723

4723-
ret = fscrypt_setup_filename(dir, &dentry->d_name, 1, &fname);
4724+
ret = fscrypt_setup_filename(vfs_dir, &dentry->d_name, 1, &fname);
47244725
if (ret)
47254726
return ret;
47264727

47274728
/* This needs to handle no-key deletions later on */
47284729

4729-
trans = __unlink_start_trans(BTRFS_I(dir));
4730+
trans = __unlink_start_trans(dir);
47304731
if (IS_ERR(trans)) {
47314732
ret = PTR_ERR(trans);
47324733
goto out_notrans;
@@ -4746,22 +4747,22 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
47464747
* This is because we can't unlink other roots when replaying the dir
47474748
* deletes for directory foo.
47484749
*/
4749-
if (BTRFS_I(inode)->last_unlink_trans >= trans->transid)
4750-
btrfs_record_snapshot_destroy(trans, BTRFS_I(dir));
4750+
if (inode->last_unlink_trans >= trans->transid)
4751+
btrfs_record_snapshot_destroy(trans, dir);
47514752

4752-
if (unlikely(btrfs_ino(BTRFS_I(inode)) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) {
4753-
ret = btrfs_unlink_subvol(trans, BTRFS_I(dir), dentry);
4753+
if (unlikely(btrfs_ino(inode) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) {
4754+
ret = btrfs_unlink_subvol(trans, dir, dentry);
47544755
goto out;
47554756
}
47564757

4757-
ret = btrfs_orphan_add(trans, BTRFS_I(inode));
4758+
ret = btrfs_orphan_add(trans, inode);
47584759
if (ret)
47594760
goto out;
47604761

47614762
/* now the directory is empty */
4762-
ret = btrfs_unlink_inode(trans, BTRFS_I(dir), BTRFS_I(inode), &fname.disk_name);
4763+
ret = btrfs_unlink_inode(trans, dir, inode, &fname.disk_name);
47634764
if (!ret)
4764-
btrfs_i_size_write(BTRFS_I(inode), 0);
4765+
btrfs_i_size_write(inode, 0);
47654766
out:
47664767
btrfs_end_transaction(trans);
47674768
out_notrans:

0 commit comments

Comments
 (0)