All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] Fixes and tweaks around error handling
@ 2020-12-16 16:18 Josef Bacik
  2020-12-16 16:18 ` [PATCH 1/5] btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block Josef Bacik
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Josef Bacik @ 2020-12-16 16:18 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

Hello,

These patches were originally in my reloc error handling patches that have been
broken out on their own.  They stand on their own and are simple and don't
affect the code in a real way.  Simply fixing some cosmetic stuff, or allowing
error injection in certain places.  They were patches I needed while running
error injection.  Thanks,

Josef

Josef Bacik (5):
  btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block
  btrfs: print the actual offset in btrfs_root_name
  btrfs: noinline btrfs_should_cancel_balance
  btrfs: pass down the tree block level through ref-verify
  btrfs: make sure owner is set in ref-verify

 fs/btrfs/ctree.c      |  2 ++
 fs/btrfs/disk-io.c    |  2 +-
 fs/btrfs/print-tree.c | 10 +++++-----
 fs/btrfs/print-tree.h |  2 +-
 fs/btrfs/ref-verify.c | 43 ++++++++++++++++++++++---------------------
 fs/btrfs/relocation.c |  2 +-
 6 files changed, 32 insertions(+), 29 deletions(-)

-- 
2.26.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/5] btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block
  2020-12-16 16:18 [PATCH 0/5] Fixes and tweaks around error handling Josef Bacik
@ 2020-12-16 16:18 ` Josef Bacik
  2020-12-16 16:18 ` [PATCH 2/5] btrfs: print the actual offset in btrfs_root_name Josef Bacik
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Josef Bacik @ 2020-12-16 16:18 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo, Johannes Thumshirn

The following patches are going to address error handling in relocation,
in order to test those patches I need to be able to inject errors in
btrfs_search_slot and btrfs_cow_block, as we call both of these pretty
often in different cases during relocation.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index cc89b63d65a4..56e132d825a2 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1494,6 +1494,7 @@ noinline int btrfs_cow_block(struct btrfs_trans_handle *trans,
 
 	return ret;
 }
+ALLOW_ERROR_INJECTION(btrfs_cow_block, ERRNO);
 
 /*
  * helper function for defrag to decide if two blocks pointed to by a
@@ -2821,6 +2822,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 		btrfs_release_path(p);
 	return ret;
 }
+ALLOW_ERROR_INJECTION(btrfs_search_slot, ERRNO);
 
 /*
  * Like btrfs_search_slot, this looks for a key in the given tree. It uses the
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/5] btrfs: print the actual offset in btrfs_root_name
  2020-12-16 16:18 [PATCH 0/5] Fixes and tweaks around error handling Josef Bacik
  2020-12-16 16:18 ` [PATCH 1/5] btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block Josef Bacik
@ 2020-12-16 16:18 ` Josef Bacik
  2020-12-18 15:22   ` David Sterba
  2020-12-16 16:18 ` [PATCH 3/5] btrfs: noinline btrfs_should_cancel_balance Josef Bacik
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 9+ messages in thread
From: Josef Bacik @ 2020-12-16 16:18 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

We're supposed to print the root_key.offset in btrfs_root_name in the
case of a reloc root, not the objectid.  Fix this helper to take the key
so we have access to the offset when we need it.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/disk-io.c    |  2 +-
 fs/btrfs/print-tree.c | 10 +++++-----
 fs/btrfs/print-tree.h |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 765deefda92b..0eeadf624dfb 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1457,7 +1457,7 @@ void btrfs_check_leaked_roots(struct btrfs_fs_info *fs_info)
 		root = list_first_entry(&fs_info->allocated_roots,
 					struct btrfs_root, leak_list);
 		btrfs_err(fs_info, "leaked root %s refcount %d",
-			  btrfs_root_name(root->root_key.objectid, buf),
+			  btrfs_root_name(&root->root_key, buf),
 			  refcount_read(&root->refs));
 		while (refcount_read(&root->refs) > 1)
 			btrfs_put_root(root);
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index fe5e0026129d..b8137dbf6a3a 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -26,22 +26,22 @@ static const struct root_name_map root_map[] = {
 	{ BTRFS_DATA_RELOC_TREE_OBJECTID,	"DATA_RELOC_TREE"	},
 };
 
-const char *btrfs_root_name(u64 objectid, char *buf)
+const char *btrfs_root_name(struct btrfs_key *key, char *buf)
 {
 	int i;
 
-	if (objectid == BTRFS_TREE_RELOC_OBJECTID) {
+	if (key->objectid == BTRFS_TREE_RELOC_OBJECTID) {
 		snprintf(buf, BTRFS_ROOT_NAME_BUF_LEN,
-			 "TREE_RELOC offset=%llu", objectid);
+			 "TREE_RELOC offset=%llu", key->offset);
 		return buf;
 	}
 
 	for (i = 0; i < ARRAY_SIZE(root_map); i++) {
-		if (root_map[i].id == objectid)
+		if (root_map[i].id == key->objectid)
 			return root_map[i].name;
 	}
 
-	snprintf(buf, BTRFS_ROOT_NAME_BUF_LEN, "%llu", objectid);
+	snprintf(buf, BTRFS_ROOT_NAME_BUF_LEN, "%llu", key->objectid);
 	return buf;
 }
 
diff --git a/fs/btrfs/print-tree.h b/fs/btrfs/print-tree.h
index 78b99385a503..802628dd1a6e 100644
--- a/fs/btrfs/print-tree.h
+++ b/fs/btrfs/print-tree.h
@@ -11,6 +11,6 @@
 
 void btrfs_print_leaf(struct extent_buffer *l);
 void btrfs_print_tree(struct extent_buffer *c, bool follow);
-const char *btrfs_root_name(u64 objectid, char *buf);
+const char *btrfs_root_name(struct btrfs_key *key, char *buf);
 
 #endif
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/5] btrfs: noinline btrfs_should_cancel_balance
  2020-12-16 16:18 [PATCH 0/5] Fixes and tweaks around error handling Josef Bacik
  2020-12-16 16:18 ` [PATCH 1/5] btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block Josef Bacik
  2020-12-16 16:18 ` [PATCH 2/5] btrfs: print the actual offset in btrfs_root_name Josef Bacik
@ 2020-12-16 16:18 ` Josef Bacik
  2020-12-16 16:18 ` [PATCH 4/5] btrfs: pass down the tree block level through ref-verify Josef Bacik
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Josef Bacik @ 2020-12-16 16:18 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo, Johannes Thumshirn

I was attempting to reproduce a problem that Zygo hit, but my error
injection wasn't firing for a few of the common calls to
btrfs_should_cancel_balance.  This is because the compiler decided to
inline it at these spots.  Keep this from happening by explicitly
noinline'ing the function so that error injection will always work.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 19b7db8b2117..f9500262106e 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2615,7 +2615,7 @@ int setup_extent_mapping(struct inode *inode, u64 start, u64 end,
 /*
  * Allow error injection to test balance cancellation
  */
-int btrfs_should_cancel_balance(struct btrfs_fs_info *fs_info)
+noinline int btrfs_should_cancel_balance(struct btrfs_fs_info *fs_info)
 {
 	return atomic_read(&fs_info->balance_cancel_req) ||
 		fatal_signal_pending(current);
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/5] btrfs: pass down the tree block level through ref-verify
  2020-12-16 16:18 [PATCH 0/5] Fixes and tweaks around error handling Josef Bacik
                   ` (2 preceding siblings ...)
  2020-12-16 16:18 ` [PATCH 3/5] btrfs: noinline btrfs_should_cancel_balance Josef Bacik
@ 2020-12-16 16:18 ` Josef Bacik
  2020-12-16 16:18 ` [PATCH 5/5] btrfs: make sure owner is set in ref-verify Josef Bacik
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Josef Bacik @ 2020-12-16 16:18 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

I noticed that sometimes I would have the wrong level printed out with
ref-verify while testing some error injection related problems.  This is
because we only get the level from the main extent item, but our
references could go off the current leaf into another, and at that point
we lose our level.  Fix this by keeping track of the last tree block
level that we found, the same way we keep track of our bytenr and
num_bytes, in case we happen to wander into another leaf while still
processing the references for a bytenr.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ref-verify.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/ref-verify.c b/fs/btrfs/ref-verify.c
index 4b9b6c52a83b..409b02566b25 100644
--- a/fs/btrfs/ref-verify.c
+++ b/fs/btrfs/ref-verify.c
@@ -495,14 +495,15 @@ static int process_extent_item(struct btrfs_fs_info *fs_info,
 }
 
 static int process_leaf(struct btrfs_root *root,
-			struct btrfs_path *path, u64 *bytenr, u64 *num_bytes)
+			struct btrfs_path *path, u64 *bytenr, u64 *num_bytes,
+			int *tree_block_level)
 {
 	struct btrfs_fs_info *fs_info = root->fs_info;
 	struct extent_buffer *leaf = path->nodes[0];
 	struct btrfs_extent_data_ref *dref;
 	struct btrfs_shared_data_ref *sref;
 	u32 count;
-	int i = 0, tree_block_level = 0, ret = 0;
+	int i = 0, ret = 0;
 	struct btrfs_key key;
 	int nritems = btrfs_header_nritems(leaf);
 
@@ -515,15 +516,15 @@ static int process_leaf(struct btrfs_root *root,
 		case BTRFS_METADATA_ITEM_KEY:
 			*bytenr = key.objectid;
 			ret = process_extent_item(fs_info, path, &key, i,
-						  &tree_block_level);
+						  tree_block_level);
 			break;
 		case BTRFS_TREE_BLOCK_REF_KEY:
 			ret = add_tree_block(fs_info, key.offset, 0,
-					     key.objectid, tree_block_level);
+					     key.objectid, *tree_block_level);
 			break;
 		case BTRFS_SHARED_BLOCK_REF_KEY:
 			ret = add_tree_block(fs_info, 0, key.offset,
-					     key.objectid, tree_block_level);
+					     key.objectid, *tree_block_level);
 			break;
 		case BTRFS_EXTENT_DATA_REF_KEY:
 			dref = btrfs_item_ptr(leaf, i,
@@ -549,7 +550,8 @@ static int process_leaf(struct btrfs_root *root,
 
 /* Walk down to the leaf from the given level */
 static int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path,
-			  int level, u64 *bytenr, u64 *num_bytes)
+			  int level, u64 *bytenr, u64 *num_bytes,
+			  int *tree_block_level)
 {
 	struct extent_buffer *eb;
 	int ret = 0;
@@ -565,7 +567,8 @@ static int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path,
 			path->slots[level-1] = 0;
 			path->locks[level-1] = BTRFS_READ_LOCK;
 		} else {
-			ret = process_leaf(root, path, bytenr, num_bytes);
+			ret = process_leaf(root, path, bytenr, num_bytes,
+					   tree_block_level);
 			if (ret)
 				break;
 		}
@@ -974,6 +977,7 @@ int btrfs_build_ref_tree(struct btrfs_fs_info *fs_info)
 {
 	struct btrfs_path *path;
 	struct extent_buffer *eb;
+	int tree_block_level = 0;
 	u64 bytenr = 0, num_bytes = 0;
 	int ret, level;
 
@@ -998,7 +1002,7 @@ int btrfs_build_ref_tree(struct btrfs_fs_info *fs_info)
 		 * different leaf from the original extent item.
 		 */
 		ret = walk_down_tree(fs_info->extent_root, path, level,
-				     &bytenr, &num_bytes);
+				     &bytenr, &num_bytes, &tree_block_level);
 		if (ret)
 			break;
 		ret = walk_up_tree(path, &level);
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/5] btrfs: make sure owner is set in ref-verify
  2020-12-16 16:18 [PATCH 0/5] Fixes and tweaks around error handling Josef Bacik
                   ` (3 preceding siblings ...)
  2020-12-16 16:18 ` [PATCH 4/5] btrfs: pass down the tree block level through ref-verify Josef Bacik
@ 2020-12-16 16:18 ` Josef Bacik
  2020-12-17 12:56 ` [PATCH 0/5] Fixes and tweaks around error handling Nikolay Borisov
  2020-12-18 15:38 ` David Sterba
  6 siblings, 0 replies; 9+ messages in thread
From: Josef Bacik @ 2020-12-16 16:18 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

I noticed that shared ref entries in ref-verify didn't have the proper
owner set, which caused me to think there was something seriously wrong.
However the problem is if we have a parent we simply weren't filling out
the owner part of the reference, even though we have it.  Fix this by
making sure we set all the proper fields when we modify a reference,
this way we'll have the proper owner if a problem happens and we don't
waste time thinking we're updating the wrong level.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ref-verify.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/ref-verify.c b/fs/btrfs/ref-verify.c
index 409b02566b25..2b490becbe67 100644
--- a/fs/btrfs/ref-verify.c
+++ b/fs/btrfs/ref-verify.c
@@ -669,18 +669,18 @@ int btrfs_ref_tree_mod(struct btrfs_fs_info *fs_info,
 	u64 bytenr = generic_ref->bytenr;
 	u64 num_bytes = generic_ref->len;
 	u64 parent = generic_ref->parent;
-	u64 ref_root;
-	u64 owner;
-	u64 offset;
+	u64 ref_root = 0;
+	u64 owner = 0;
+	u64 offset = 0;
 
 	if (!btrfs_test_opt(fs_info, REF_VERIFY))
 		return 0;
 
 	if (generic_ref->type == BTRFS_REF_METADATA) {
-		ref_root = generic_ref->tree_ref.root;
+		if (!parent)
+			ref_root = generic_ref->tree_ref.root;
 		owner = generic_ref->tree_ref.level;
-		offset = 0;
-	} else {
+	} else if (!parent) {
 		ref_root = generic_ref->data_ref.ref_root;
 		owner = generic_ref->data_ref.ino;
 		offset = generic_ref->data_ref.offset;
@@ -696,13 +696,10 @@ int btrfs_ref_tree_mod(struct btrfs_fs_info *fs_info,
 		goto out;
 	}
 
-	if (parent) {
-		ref->parent = parent;
-	} else {
-		ref->root_objectid = ref_root;
-		ref->owner = owner;
-		ref->offset = offset;
-	}
+	ref->parent = parent;
+	ref->owner = owner;
+	ref->root_objectid = ref_root;
+	ref->offset = offset;
 	ref->num_refs = (action == BTRFS_DROP_DELAYED_REF) ? -1 : 1;
 
 	memcpy(&ra->ref, ref, sizeof(struct ref_entry));
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/5] Fixes and tweaks around error handling
  2020-12-16 16:18 [PATCH 0/5] Fixes and tweaks around error handling Josef Bacik
                   ` (4 preceding siblings ...)
  2020-12-16 16:18 ` [PATCH 5/5] btrfs: make sure owner is set in ref-verify Josef Bacik
@ 2020-12-17 12:56 ` Nikolay Borisov
  2020-12-18 15:38 ` David Sterba
  6 siblings, 0 replies; 9+ messages in thread
From: Nikolay Borisov @ 2020-12-17 12:56 UTC (permalink / raw)
  To: Josef Bacik, linux-btrfs, kernel-team



On 16.12.20 г. 18:18 ч., Josef Bacik wrote:
> Hello,
> 
> These patches were originally in my reloc error handling patches that have been
> broken out on their own.  They stand on their own and are simple and don't
> affect the code in a real way.  Simply fixing some cosmetic stuff, or allowing
> error injection in certain places.  They were patches I needed while running
> error injection.  Thanks,
> 
> Josef
> 
> Josef Bacik (5):
>   btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block
>   btrfs: print the actual offset in btrfs_root_name
>   btrfs: noinline btrfs_should_cancel_balance
>   btrfs: pass down the tree block level through ref-verify
>   btrfs: make sure owner is set in ref-verify
> 
>  fs/btrfs/ctree.c      |  2 ++
>  fs/btrfs/disk-io.c    |  2 +-
>  fs/btrfs/print-tree.c | 10 +++++-----
>  fs/btrfs/print-tree.h |  2 +-
>  fs/btrfs/ref-verify.c | 43 ++++++++++++++++++++++---------------------
>  fs/btrfs/relocation.c |  2 +-
>  6 files changed, 32 insertions(+), 29 deletions(-)
> 

Patches 1-3 can have my :

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

I'm not too familiar with ref-verify for the other 2.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/5] btrfs: print the actual offset in btrfs_root_name
  2020-12-16 16:18 ` [PATCH 2/5] btrfs: print the actual offset in btrfs_root_name Josef Bacik
@ 2020-12-18 15:22   ` David Sterba
  0 siblings, 0 replies; 9+ messages in thread
From: David Sterba @ 2020-12-18 15:22 UTC (permalink / raw)
  To: Josef Bacik; +Cc: linux-btrfs, kernel-team, Qu Wenruo

On Wed, Dec 16, 2020 at 11:18:44AM -0500, Josef Bacik wrote:
> --- a/fs/btrfs/print-tree.c
> +++ b/fs/btrfs/print-tree.c
> @@ -26,22 +26,22 @@ static const struct root_name_map root_map[] = {
>  	{ BTRFS_DATA_RELOC_TREE_OBJECTID,	"DATA_RELOC_TREE"	},
>  };
>  
> -const char *btrfs_root_name(u64 objectid, char *buf)
> +const char *btrfs_root_name(struct btrfs_key *key, char *buf)

I've added 'const' here.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/5] Fixes and tweaks around error handling
  2020-12-16 16:18 [PATCH 0/5] Fixes and tweaks around error handling Josef Bacik
                   ` (5 preceding siblings ...)
  2020-12-17 12:56 ` [PATCH 0/5] Fixes and tweaks around error handling Nikolay Borisov
@ 2020-12-18 15:38 ` David Sterba
  6 siblings, 0 replies; 9+ messages in thread
From: David Sterba @ 2020-12-18 15:38 UTC (permalink / raw)
  To: Josef Bacik; +Cc: linux-btrfs, kernel-team

On Wed, Dec 16, 2020 at 11:18:42AM -0500, Josef Bacik wrote:
> Hello,
> 
> These patches were originally in my reloc error handling patches that have been
> broken out on their own.  They stand on their own and are simple and don't
> affect the code in a real way.  Simply fixing some cosmetic stuff, or allowing
> error injection in certain places.  They were patches I needed while running
> error injection.  Thanks,
> 
> Josef
> 
> Josef Bacik (5):
>   btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block
>   btrfs: print the actual offset in btrfs_root_name
>   btrfs: noinline btrfs_should_cancel_balance
>   btrfs: pass down the tree block level through ref-verify
>   btrfs: make sure owner is set in ref-verify

Added to misc-next, with some changelog adjustments, thanks.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-12-18 15:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-16 16:18 [PATCH 0/5] Fixes and tweaks around error handling Josef Bacik
2020-12-16 16:18 ` [PATCH 1/5] btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block Josef Bacik
2020-12-16 16:18 ` [PATCH 2/5] btrfs: print the actual offset in btrfs_root_name Josef Bacik
2020-12-18 15:22   ` David Sterba
2020-12-16 16:18 ` [PATCH 3/5] btrfs: noinline btrfs_should_cancel_balance Josef Bacik
2020-12-16 16:18 ` [PATCH 4/5] btrfs: pass down the tree block level through ref-verify Josef Bacik
2020-12-16 16:18 ` [PATCH 5/5] btrfs: make sure owner is set in ref-verify Josef Bacik
2020-12-17 12:56 ` [PATCH 0/5] Fixes and tweaks around error handling Nikolay Borisov
2020-12-18 15:38 ` David Sterba

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.