All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>, <dsterba@suse.cz>
Subject: [PATCH 30/32] btrfs-progs: Refactor btrfs_root paramters in btrfs-corrupt-block.c
Date: Thu, 18 May 2017 11:38:55 +0800	[thread overview]
Message-ID: <20170518033857.15002-31-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <20170518033857.15002-1-quwenruo@cn.fujitsu.com>

Refactor the following functions and its callers to get rid of
incorrectly passed btrfs_root parameters:

1) corrupt_keys()
2) corrupt_metadata_block()

The only reason passing btrfs_root for them is to get block sizes.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 btrfs-corrupt-block.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index 20a4c1df..5649a00e 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -126,7 +126,7 @@ static void print_usage(int ret)
 }
 
 static void corrupt_keys(struct btrfs_trans_handle *trans,
-			 struct btrfs_root *root,
+			 struct btrfs_fs_info *fs_info,
 			 struct extent_buffer *eb)
 {
 	int slot;
@@ -158,22 +158,22 @@ static void corrupt_keys(struct btrfs_trans_handle *trans,
 	btrfs_mark_buffer_dirty(eb);
 	if (!trans) {
 		u16 csum_size =
-			btrfs_super_csum_size(root->fs_info->super_copy);
+			btrfs_super_csum_size(fs_info->super_copy);
 		csum_tree_block_size(eb, csum_size, 0);
 		write_extent_to_disk(eb);
 	}
 }
 
 
-static int corrupt_keys_in_block(struct btrfs_root *root, u64 bytenr)
+static int corrupt_keys_in_block(struct btrfs_fs_info *fs_info, u64 bytenr)
 {
 	struct extent_buffer *eb;
 
-	eb = read_tree_block(root, bytenr, root->fs_info->nodesize, 0);
+	eb = read_tree_block_fs_info(fs_info, bytenr, fs_info->nodesize, 0);
 	if (!extent_buffer_uptodate(eb))
 		return -EIO;;
 
-	corrupt_keys(NULL, root, eb);
+	corrupt_keys(NULL, fs_info, eb);
 	free_extent_buffer(eb);
 	return 0;
 }
@@ -745,10 +745,11 @@ static void shift_items(struct btrfs_root *root, struct extent_buffer *eb)
 	}
 }
 
-static int corrupt_metadata_block(struct btrfs_root *root, u64 block,
+static int corrupt_metadata_block(struct btrfs_fs_info *fs_info, u64 block,
 				  char *field)
 {
 	struct btrfs_trans_handle *trans;
+	struct btrfs_root *root;
 	struct btrfs_path *path;
 	struct extent_buffer *eb;
 	struct btrfs_key key, root_key;
@@ -764,7 +765,7 @@ static int corrupt_metadata_block(struct btrfs_root *root, u64 block,
 		return -EINVAL;
 	}
 
-	eb = read_tree_block(root, block, root->fs_info->nodesize, 0);
+	eb = read_tree_block_fs_info(fs_info, block, fs_info->nodesize, 0);
 	if (!extent_buffer_uptodate(eb)) {
 		fprintf(stderr, "Couldn't read in tree block %s\n", field);
 		return -EINVAL;
@@ -781,7 +782,7 @@ static int corrupt_metadata_block(struct btrfs_root *root, u64 block,
 	root_key.type = BTRFS_ROOT_ITEM_KEY;
 	root_key.offset = (u64)-1;
 
-	root = btrfs_read_fs_root(root->fs_info, &root_key);
+	root = btrfs_read_fs_root(fs_info, &root_key);
 	if (IS_ERR(root)) {
 		fprintf(stderr, "Couldn't find owner root %llu\n",
 			key.objectid);
@@ -1295,7 +1296,8 @@ int main(int argc, char **argv)
 	if (metadata_block) {
 		if (*field == 0)
 			print_usage(1);
-		ret = corrupt_metadata_block(root, metadata_block, field);
+		ret = corrupt_metadata_block(root->fs_info, metadata_block,
+					     field);
 		goto out_close;
 	}
 	if (corrupt_di) {
@@ -1358,7 +1360,7 @@ int main(int argc, char **argv)
 
 	while (bytes > 0) {
 		if (corrupt_block_keys) {
-			corrupt_keys_in_block(root, logical);
+			corrupt_keys_in_block(root->fs_info, logical);
 		} else {
 			struct extent_buffer *eb;
 
-- 
2.13.0




  parent reply	other threads:[~2017-05-18  3:39 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-18  3:38 [PATCH 00/32] btrfs_fs_info refactoring Qu Wenruo
2017-05-18  3:38 ` [PATCH 01/32] btrfs-progs: Remove deprecated leafsize usage Qu Wenruo
2017-05-18  3:38 ` [PATCH 02/32] btrfs-progs: Introduce sectorsize nodesize and stripesize members for btrfs_fs_info Qu Wenruo
2017-05-18  3:38 ` [PATCH 03/32] btrfs-progs: Refactor block sizes users in disk-io.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 04/32] btrfs-progs: Refactor block sizes users in btrfs-corrupt-block.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 05/32] btrfs-progs: Refactor block sizes users in ctree.c and ctree.h Qu Wenruo
2017-05-18  3:38 ` [PATCH 06/32] btrfs-progs: Refactor block sizes users in btrfs-map-logical.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 07/32] btrfs-progs: Refactor block sizes users in chunk-recover.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 08/32] btrfs-progs: Refactor block sizes users in backref.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 09/32] btrfs-progs: Refactor block sizes users in cmds-restore.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 10/32] btrfs-progs: Refactor nodesize user in extent_io.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 11/32] btrfs-progs: Refactor nodesize users in image/main.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 12/32] btrfs-progs: Refactor block sizes users in cmds-check.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 13/32] btrfs-progs: Refactor nodesize user in btrfstune.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 14/32] btrfs-progs: Refactor nodesize users in utils.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 15/32] btrfs-progs: Refactor block sizes users in extent-tree.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 16/32] btrfs-progs: Refactor nodesize user in print-tree.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 17/32] btrfs-progs: Refactor nodesize users in qgroup-verify.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 18/32] btrfs-progs: Refactor nodesize users in cmds-inspect-tree-stats.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 19/32] btrfs-progs: Refactor sectorsize users in mkfs/main.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 20/32] btrfs-progs: Refactor sectorsizes users in file-item.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 21/32] btrfs-progs: Refactor sectorsize users in free-space-cache.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 22/32] btrfs-progs: Refactor sectorsize users in file.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 23/32] btrfs-progs: Refactor sectorsize users in volumes.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 24/32] btrfs-progs: Refactor sectorsize users in free-space-tree.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 25/32] btrfs-progs: Refactor sectorsize in convert/source-fs.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 26/32] btrfs-progs: Refactor sectorsize users in convert/main.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 27/32] btrfs-progs: Refactor sectorsize users in convert/source-ext2.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 28/32] btrfs-progs: Refactor sectorsize users in cmds-inspect-dump-tree.c Qu Wenruo
2017-05-18  3:38 ` [PATCH 29/32] btrfs-progs: Remove block size members in btrfs_root Qu Wenruo
2017-05-18  3:38 ` Qu Wenruo [this message]
2017-05-18  3:38 ` [PATCH 31/32] btrfs-progs: Refactor read_tree_block to get rid of btrfs_root Qu Wenruo
2017-05-18  3:38 ` [PATCH 32/32] btrfs-progs: Refactor read_node_slot function to get rid of btrfs_root parameter Qu Wenruo
2017-05-29 18:07 ` [PATCH 00/32] btrfs_fs_info refactoring David Sterba

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=20170518033857.15002-31-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=dsterba@suse.cz \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.