public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH RFC 5/7] btrfs-progs: Refactor btrfs_new_block_group_record() to accept parameters directly
Date: Mon,  4 Nov 2019 20:03:59 +0800	[thread overview]
Message-ID: <20191104120401.56408-6-wqu@suse.com> (raw)
In-Reply-To: <20191104120401.56408-1-wqu@suse.com>

Currently btrfs_new_block_group_record() needs to extract numbers from
key and block group item manually.

This is not generic enough to handle skinny-bg-tree feature.
So change let btrfs_new_block_group_record() to accept @bytenr, @len and
@flags directly, so later skinny-bg-tree feature can reuse it in
original mode.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 btrfsck.h                   |  4 ++--
 check/common.h              |  4 ++--
 check/main.c                | 25 +++++++++++++------------
 cmds/rescue-chunk-recover.c |  6 +++++-
 4 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/btrfsck.h b/btrfsck.h
index ac7f5d488b5a..be811a133687 100644
--- a/btrfsck.h
+++ b/btrfsck.h
@@ -189,8 +189,8 @@ struct chunk_record *btrfs_new_chunk_record(struct extent_buffer *leaf,
 					    struct btrfs_key *key,
 					    int slot);
 struct block_group_record *
-btrfs_new_block_group_record(struct extent_buffer *leaf, struct btrfs_key *key,
-			     int slot);
+btrfs_new_block_group_record(struct extent_buffer *leaf, u64 bytenr, u64 len,
+			     u64 flags);
 struct device_extent_record *
 btrfs_new_device_extent_record(struct extent_buffer *leaf,
 			       struct btrfs_key *key, int slot);
diff --git a/check/common.h b/check/common.h
index 62cdc1d934c7..ff206f27c304 100644
--- a/check/common.h
+++ b/check/common.h
@@ -166,8 +166,8 @@ struct chunk_record *btrfs_new_chunk_record(struct extent_buffer *leaf,
 					    struct btrfs_key *key,
 					    int slot);
 struct block_group_record *
-btrfs_new_block_group_record(struct extent_buffer *leaf, struct btrfs_key *key,
-			     int slot);
+btrfs_new_block_group_record(struct extent_buffer *leaf, u64 bytenr, u64 len,
+			     u64 flags);
 struct device_extent_record *
 btrfs_new_device_extent_record(struct extent_buffer *leaf,
 			       struct btrfs_key *key, int slot);
diff --git a/check/main.c b/check/main.c
index a0e5ac47c152..a1261ce0ebe7 100644
--- a/check/main.c
+++ b/check/main.c
@@ -5193,10 +5193,9 @@ static int process_device_item(struct rb_root *dev_cache,
 }
 
 struct block_group_record *
-btrfs_new_block_group_record(struct extent_buffer *leaf, struct btrfs_key *key,
-			     int slot)
+btrfs_new_block_group_record(struct extent_buffer *leaf, u64 bytenr, u64 len,
+			     u64 flags)
 {
-	struct btrfs_block_group_item *ptr;
 	struct block_group_record *rec;
 
 	rec = calloc(1, sizeof(*rec));
@@ -5205,17 +5204,15 @@ btrfs_new_block_group_record(struct extent_buffer *leaf, struct btrfs_key *key,
 		exit(-1);
 	}
 
-	rec->cache.start = key->objectid;
-	rec->cache.size = key->offset;
+	rec->cache.start = bytenr;
+	rec->cache.size = len;
 
 	rec->generation = btrfs_header_generation(leaf);
 
-	rec->objectid = key->objectid;
-	rec->type = key->type;
-	rec->offset = key->offset;
-
-	ptr = btrfs_item_ptr(leaf, slot, struct btrfs_block_group_item);
-	rec->flags = btrfs_disk_block_group_flags(leaf, ptr);
+	rec->objectid = bytenr;
+	rec->type = BTRFS_BLOCK_GROUP_ITEM_KEY;
+	rec->offset = len;
+	rec->flags = flags;
 
 	INIT_LIST_HEAD(&rec->list);
 
@@ -5226,10 +5223,14 @@ static int process_block_group_item(struct block_group_tree *block_group_cache,
 				    struct btrfs_key *key,
 				    struct extent_buffer *eb, int slot)
 {
+	struct btrfs_block_group_item bgi;
 	struct block_group_record *rec;
 	int ret = 0;
 
-	rec = btrfs_new_block_group_record(eb, key, slot);
+	read_extent_buffer(eb, &bgi, btrfs_item_ptr_offset(eb, slot),
+			   sizeof(bgi));
+	rec = btrfs_new_block_group_record(eb, key->objectid, key->offset,
+					   btrfs_block_group_flags(&bgi));
 	ret = insert_block_group_record(block_group_cache, rec);
 	if (ret) {
 		fprintf(stderr, "Block Group[%llu, %llu] existed.\n",
diff --git a/cmds/rescue-chunk-recover.c b/cmds/rescue-chunk-recover.c
index 22d7a5959531..cd575668f89e 100644
--- a/cmds/rescue-chunk-recover.c
+++ b/cmds/rescue-chunk-recover.c
@@ -226,12 +226,16 @@ static int process_block_group_item(struct block_group_tree *bg_cache,
 				    struct extent_buffer *leaf,
 				    struct btrfs_key *key, int slot)
 {
+	struct btrfs_block_group_item bgi;
 	struct block_group_record *rec;
 	struct block_group_record *exist;
 	struct cache_extent *cache;
 	int ret = 0;
 
-	rec = btrfs_new_block_group_record(leaf, key, slot);
+	read_extent_buffer(leaf, &bgi, btrfs_item_ptr_offset(leaf, slot),
+			   sizeof(bgi));
+	rec = btrfs_new_block_group_record(leaf, key->objectid, key->offset,
+					   btrfs_block_group_flags(&bgi));
 	if (!rec->cache.size)
 		goto free_out;
 again:
-- 
2.23.0


  parent reply	other threads:[~2019-11-04 12:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-04 12:03 [PATCH RFC 0/7] Qu Wenruo
2019-11-04 12:03 ` [PATCH RFC 1/7] btrfs-progs: check/lowmem: Lookup block group item in a seperate function Qu Wenruo
2019-11-04 12:03 ` [PATCH RFC 2/7] btrfs-progs: Enable read-write ability for 'skinny_bg_tree' feature Qu Wenruo
2019-11-04 12:03 ` [PATCH RFC 3/7] btrfs-progs: mkfs: Introduce -O skinny-bg-tree Qu Wenruo
2019-11-04 12:03 ` [PATCH RFC 4/7] btrfs-progs: dump-tree/dump-super: Introduce support for skinny bg tree Qu Wenruo
2019-11-04 12:03 ` Qu Wenruo [this message]
2019-11-04 12:04 ` [PATCH RFC 6/7] btrfs-progs: check: Introduce support for bg-tree feature Qu Wenruo
2019-11-04 12:04 ` [PATCH RFC 7/7] btrfs-progs: btrfstune: Allow to enable bg-tree feature offline 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=20191104120401.56408-6-wqu@suse.com \
    --to=wqu@suse.com \
    --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