From: Marcos Paulo de Souza <mpdesouza@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.com, nborisov@suse.com,
Marcos Paulo de Souza <mpdesouza@suse.com>
Subject: [PATCH 6/7] btrfs: tree-log: Simplify log_new_ancestors
Date: Wed, 4 Aug 2021 15:48:53 -0300 [thread overview]
Message-ID: <20210804184854.10696-7-mpdesouza@suse.com> (raw)
In-Reply-To: <20210804184854.10696-1-mpdesouza@suse.com>
The search_key variable was being used only as argument of
btrfs_search_slot. This can be simplified by calling btrfs_find_item,
which also handles the next leaf condition as well.
No functional changes.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
fs/btrfs/tree-log.c | 40 ++++++++++++----------------------------
1 file changed, 12 insertions(+), 28 deletions(-)
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 567adc3de11a..22417cd32347 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -5929,31 +5929,30 @@ static int btrfs_log_all_parents(struct btrfs_trans_handle *trans,
return ret;
}
+/*
+ * Iterate over the given and all it's parent directories, logging them if
+ * needed.
+ *
+ * Return 0 if we reach the toplevel directory, or < 0 if error.
+ */
static int log_new_ancestors(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_path *path,
struct btrfs_log_ctx *ctx)
{
+ struct btrfs_fs_info *fs_info = root->fs_info;
struct btrfs_key found_key;
+ u64 ino;
btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]);
while (true) {
- struct btrfs_fs_info *fs_info = root->fs_info;
- struct extent_buffer *leaf = path->nodes[0];
- int slot = path->slots[0];
- struct btrfs_key search_key;
struct inode *inode;
- u64 ino;
int ret = 0;
btrfs_release_path(path);
ino = found_key.offset;
-
- search_key.objectid = found_key.offset;
- search_key.type = BTRFS_INODE_ITEM_KEY;
- search_key.offset = 0;
inode = btrfs_iget(fs_info->sb, ino, root);
if (IS_ERR(inode))
return PTR_ERR(inode);
@@ -5966,29 +5965,14 @@ static int log_new_ancestors(struct btrfs_trans_handle *trans,
if (ret)
return ret;
- if (search_key.objectid == BTRFS_FIRST_FREE_OBJECTID)
+ if (ino == BTRFS_FIRST_FREE_OBJECTID)
break;
- search_key.type = BTRFS_INODE_REF_KEY;
- ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
+ ret = btrfs_find_item(root, path, ino, BTRFS_INODE_REF_KEY, 0,
+ &found_key);
if (ret < 0)
return ret;
-
- leaf = path->nodes[0];
- slot = path->slots[0];
- if (slot >= btrfs_header_nritems(leaf)) {
- ret = btrfs_next_leaf(root, path);
- if (ret < 0)
- return ret;
- else if (ret > 0)
- return -ENOENT;
- leaf = path->nodes[0];
- slot = path->slots[0];
- }
-
- btrfs_item_key_to_cpu(leaf, &found_key, slot);
- if (found_key.objectid != search_key.objectid ||
- found_key.type != BTRFS_INODE_REF_KEY)
+ else if (ret > 0)
return -ENOENT;
}
return 0;
--
2.31.1
next prev parent reply other threads:[~2021-08-04 18:49 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-04 18:48 [PATCH 0/7] btrfs: Use btrfs_find_item whenever possible Marcos Paulo de Souza
2021-08-04 18:48 ` [PATCH 1/7] btrfs: Reorder btrfs_find_item arguments Marcos Paulo de Souza
2021-08-05 2:16 ` Qu Wenruo
2021-08-05 17:28 ` Marcos Paulo de Souza
2021-08-05 22:23 ` Qu Wenruo
2021-08-16 16:51 ` David Sterba
2021-08-04 18:48 ` [PATCH 2/7] btrfs: backref: Use btrfs_find_item in btrfs_find_one_extref Marcos Paulo de Souza
2021-08-05 6:33 ` Qu Wenruo
2021-08-04 18:48 ` [PATCH 3/7] btrfs: zoned: Use btrfs_find_item in calculate_emulated_zone_size Marcos Paulo de Souza
2021-08-05 6:39 ` Qu Wenruo
2021-08-06 5:52 ` Naohiro Aota
2021-08-06 6:11 ` Qu Wenruo
2021-08-06 6:18 ` Naohiro Aota
2021-08-04 18:48 ` [PATCH 4/7] btrfs: root-tree: Use btrfs_find_item in btrfs_find_orphan_roots Marcos Paulo de Souza
2021-08-05 6:42 ` Qu Wenruo
2021-08-04 18:48 ` [PATCH 5/7] btrfs: scrub: Use btrfs_find_item in scrub_enumerate_chunks Marcos Paulo de Souza
2021-08-04 18:48 ` Marcos Paulo de Souza [this message]
2021-08-05 9:00 ` [PATCH 6/7] btrfs: tree-log: Simplify log_new_ancestors Filipe Manana
2021-08-05 12:41 ` Marcos Paulo de Souza
2021-08-04 18:48 ` [PATCH 7/7] btrfs: ioctl: Simplify btrfs_ioctl_get_subvol_info Marcos Paulo de Souza
2021-08-05 12:13 ` Anand Jain
2021-08-05 14:23 ` Marcos Paulo de Souza
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=20210804184854.10696-7-mpdesouza@suse.com \
--to=mpdesouza@suse.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=nborisov@suse.com \
/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).