linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: fdmanana@kernel.org
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 08/12] btrfs: use btrfs inodes in btrfs_rmdir() to avoid so much usage of BTRFS_I()
Date: Tue, 24 Jun 2025 15:42:18 +0100	[thread overview]
Message-ID: <461dd2e6771f1000bab3948e841c24be84b74966.1750709411.git.fdmanana@suse.com> (raw)
In-Reply-To: <cover.1750709410.git.fdmanana@suse.com>

From: Filipe Manana <fdmanana@suse.com>

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>
---
 fs/btrfs/inode.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index f8e4651fe60b..6df7ef1b869b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4701,32 +4701,33 @@ int btrfs_delete_subvolume(struct btrfs_inode *dir, struct dentry *dentry)
 	return ret;
 }
 
-static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
+static int btrfs_rmdir(struct inode *vfs_dir, struct dentry *dentry)
 {
-	struct inode *inode = d_inode(dentry);
-	struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info;
+	struct btrfs_inode *dir = BTRFS_I(vfs_dir);
+	struct btrfs_inode *inode = BTRFS_I(d_inode(dentry));
+	struct btrfs_fs_info *fs_info = inode->root->fs_info;
 	int ret = 0;
 	struct btrfs_trans_handle *trans;
 	struct fscrypt_name fname;
 
-	if (inode->i_size > BTRFS_EMPTY_DIR_SIZE)
+	if (inode->vfs_inode.i_size > BTRFS_EMPTY_DIR_SIZE)
 		return -ENOTEMPTY;
-	if (btrfs_ino(BTRFS_I(inode)) == BTRFS_FIRST_FREE_OBJECTID) {
+	if (btrfs_ino(inode) == BTRFS_FIRST_FREE_OBJECTID) {
 		if (unlikely(btrfs_fs_incompat(fs_info, EXTENT_TREE_V2))) {
 			btrfs_err(fs_info,
 			"extent tree v2 doesn't support snapshot deletion yet");
 			return -EOPNOTSUPP;
 		}
-		return btrfs_delete_subvolume(BTRFS_I(dir), dentry);
+		return btrfs_delete_subvolume(dir, dentry);
 	}
 
-	ret = fscrypt_setup_filename(dir, &dentry->d_name, 1, &fname);
+	ret = fscrypt_setup_filename(vfs_dir, &dentry->d_name, 1, &fname);
 	if (ret)
 		return ret;
 
 	/* This needs to handle no-key deletions later on */
 
-	trans = __unlink_start_trans(BTRFS_I(dir));
+	trans = __unlink_start_trans(dir);
 	if (IS_ERR(trans)) {
 		ret = PTR_ERR(trans);
 		goto out_notrans;
@@ -4746,22 +4747,22 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
 	 * This is because we can't unlink other roots when replaying the dir
 	 * deletes for directory foo.
 	 */
-	if (BTRFS_I(inode)->last_unlink_trans >= trans->transid)
-		btrfs_record_snapshot_destroy(trans, BTRFS_I(dir));
+	if (inode->last_unlink_trans >= trans->transid)
+		btrfs_record_snapshot_destroy(trans, dir);
 
-	if (unlikely(btrfs_ino(BTRFS_I(inode)) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) {
-		ret = btrfs_unlink_subvol(trans, BTRFS_I(dir), dentry);
+	if (unlikely(btrfs_ino(inode) == BTRFS_EMPTY_SUBVOL_DIR_OBJECTID)) {
+		ret = btrfs_unlink_subvol(trans, dir, dentry);
 		goto out;
 	}
 
-	ret = btrfs_orphan_add(trans, BTRFS_I(inode));
+	ret = btrfs_orphan_add(trans, inode);
 	if (ret)
 		goto out;
 
 	/* now the directory is empty */
-	ret = btrfs_unlink_inode(trans, BTRFS_I(dir), BTRFS_I(inode), &fname.disk_name);
+	ret = btrfs_unlink_inode(trans, dir, inode, &fname.disk_name);
 	if (!ret)
-		btrfs_i_size_write(BTRFS_I(inode), 0);
+		btrfs_i_size_write(inode, 0);
 out:
 	btrfs_end_transaction(trans);
 out_notrans:
-- 
2.47.2


  parent reply	other threads:[~2025-06-24 14:42 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-24 14:42 [PATCH 00/12] btrfs: log tree fixes and cleanups fdmanana
2025-06-24 14:42 ` [PATCH 01/12] btrfs: fix missing error handling when searching for inode refs during log replay fdmanana
2025-06-25  9:45   ` Johannes Thumshirn
2025-06-25 10:58     ` Filipe Manana
2025-06-24 14:42 ` [PATCH 02/12] btrfs: fix iteration of extrefs " fdmanana
2025-06-25 10:30   ` Johannes Thumshirn
2025-06-27 10:51   ` Qu Wenruo
2025-06-27 12:09     ` Filipe Manana
2025-06-24 14:42 ` [PATCH 03/12] btrfs: fix inode lookup error handling " fdmanana
2025-06-25 10:34   ` Johannes Thumshirn
2025-06-24 14:42 ` [PATCH 04/12] btrfs: record new subvolume in parent dir earlier to avoid dir logging races fdmanana
2025-06-25 10:39   ` Johannes Thumshirn
2025-06-24 14:42 ` [PATCH 05/12] btrfs: propagate last_unlink_trans earlier when doing a rmdir fdmanana
2025-06-25 10:46   ` Johannes Thumshirn
2025-06-24 14:42 ` [PATCH 06/12] btrfs: use btrfs_record_snapshot_destroy() during rmdir fdmanana
2025-06-25 10:47   ` Johannes Thumshirn
2025-06-25 10:55     ` Filipe Manana
2025-06-27 10:11       ` Johannes Thumshirn
2025-06-24 14:42 ` [PATCH 07/12] btrfs: use inode already stored in local variable at btrfs_rmdir() fdmanana
2025-06-25 10:52   ` Johannes Thumshirn
2025-06-25 10:54     ` Filipe Manana
2025-06-27 10:10   ` Johannes Thumshirn
2025-06-24 14:42 ` fdmanana [this message]
2025-06-25 10:54   ` [PATCH 08/12] btrfs: use btrfs inodes in btrfs_rmdir() to avoid so much usage of BTRFS_I() Johannes Thumshirn
2025-06-24 14:42 ` [PATCH 09/12] btrfs: split inode ref processing from __add_inode_ref() into a helper fdmanana
2025-06-25 11:07   ` Johannes Thumshirn
2025-06-24 14:42 ` [PATCH 10/12] btrfs: split inode rextef " fdmanana
2025-06-25 11:35   ` Johannes Thumshirn
2025-06-27 10:09     ` David Sterba
2025-06-24 14:42 ` [PATCH 11/12] btrfs: add btrfs prefix to is_fsstree() and make it return bool fdmanana
2025-06-25 11:35   ` Johannes Thumshirn
2025-06-24 14:42 ` [PATCH 12/12] btrfs: split btrfs_is_fsstree() into multiple if statements for readability fdmanana
2025-06-25 11:37   ` Johannes Thumshirn
2025-06-27 11:04 ` [PATCH 00/12] btrfs: log tree fixes and cleanups Qu Wenruo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=461dd2e6771f1000bab3948e841c24be84b74966.1750709411.git.fdmanana@suse.com \
    --to=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).