linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 5/7] btrfs: scrub: Use btrfs_find_item in scrub_enumerate_chunks
Date: Wed,  4 Aug 2021 15:48:52 -0300	[thread overview]
Message-ID: <20210804184854.10696-6-mpdesouza@suse.com> (raw)
In-Reply-To: <20210804184854.10696-1-mpdesouza@suse.com>

Prefer btrfs_find_item instead of btrfs_search_slot, since it calls
btrfs_next_leaf if needed and checks if the item found has the same
objectid and type passed in the search key.

As result, we can remove one btrfs_key from this function.

No functional changes.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
 fs/btrfs/scrub.c | 52 +++++++++++++-----------------------------------
 1 file changed, 14 insertions(+), 38 deletions(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 088641ba7a8e..008eeb502267 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -3657,11 +3657,10 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
 	struct btrfs_root *root = fs_info->dev_root;
 	u64 length;
 	u64 chunk_offset;
+	u64 offset = 0;
 	int ret = 0;
 	int ro_set;
-	int slot;
 	struct extent_buffer *l;
-	struct btrfs_key key;
 	struct btrfs_key found_key;
 	struct btrfs_block_group *cache;
 	struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
@@ -3674,47 +3673,24 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
 	path->search_commit_root = 1;
 	path->skip_locking = 1;
 
-	key.objectid = scrub_dev->devid;
-	key.offset = 0ull;
-	key.type = BTRFS_DEV_EXTENT_KEY;
-
 	while (1) {
-		ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
-		if (ret < 0)
-			break;
-		if (ret > 0) {
-			if (path->slots[0] >=
-			    btrfs_header_nritems(path->nodes[0])) {
-				ret = btrfs_next_leaf(root, path);
-				if (ret < 0)
-					break;
-				if (ret > 0) {
-					ret = 0;
-					break;
-				}
-			} else {
-				ret = 0;
-			}
-		}
-
-		l = path->nodes[0];
-		slot = path->slots[0];
-
-		btrfs_item_key_to_cpu(l, &found_key, slot);
-
-		if (found_key.objectid != scrub_dev->devid)
+		ret = btrfs_find_item(root, path, scrub_dev->devid,
+				BTRFS_DEV_EXTENT_KEY, offset, &found_key);
+		if (ret < 0) {
 			break;
-
-		if (found_key.type != BTRFS_DEV_EXTENT_KEY)
-			break;
-
-		if (found_key.offset >= end)
+		} else if (ret > 0) {
+			/* Reset error if not found. */
+			ret = 0;
 			break;
+		}
 
-		if (found_key.offset < key.offset)
+		if (found_key.offset >= end ||
+		    found_key.offset < offset)
 			break;
 
-		dev_extent = btrfs_item_ptr(l, slot, struct btrfs_dev_extent);
+		l = path->nodes[0];
+		dev_extent = btrfs_item_ptr(l, path->slots[0],
+						struct btrfs_dev_extent);
 		length = btrfs_dev_extent_length(l, dev_extent);
 
 		if (found_key.offset + length <= start)
@@ -3938,7 +3914,7 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
 			break;
 		}
 skip:
-		key.offset = found_key.offset + length;
+		offset = found_key.offset + length;
 		btrfs_release_path(path);
 	}
 
-- 
2.31.1


  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 ` Marcos Paulo de Souza [this message]
2021-08-04 18:48 ` [PATCH 6/7] btrfs: tree-log: Simplify log_new_ancestors Marcos Paulo de Souza
2021-08-05  9:00   ` 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-6-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).