Fixes and tweaks around error handling
cover Fixes and tweaks around error handling
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(-)
Signature · 1 line
2.26.2
PATCH 1/5 btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block
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.
--- fs/btrfs/ctree.c | 2 ++ 1 file changed, 2 insertions(+)
fs/btrfs/ctree.c +2 -0
@@ -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
Signature · 1 line
2.26.2
PATCH 2/5 btrfs: print the actual offset in btrfs_root_name
In reply to Josef BacikWe'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.
--- 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(-)
fs/btrfs/disk-io.c +1 -1
@@ -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);
fs/btrfs/print-tree.c +5 -5
@@ -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; }
fs/btrfs/print-tree.h +1 -1
@@ -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
Signature · 1 line
2.26.2
PATCH 3/5 btrfs: noinline btrfs_should_cancel_balance
In reply to Josef BacikI 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.
--- fs/btrfs/relocation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/relocation.c +1 -1
@@ -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);
Signature · 1 line
2.26.2
PATCH 4/5 btrfs: pass down the tree block level through ref-verify
In reply to Josef BacikI 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.
--- fs/btrfs/ref-verify.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
fs/btrfs/ref-verify.c +12 -8
@@ -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);
Signature · 1 line
2.26.2
PATCH 5/5 btrfs: make sure owner is set in ref-verify
In reply to Josef BacikI 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.
--- fs/btrfs/ref-verify.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
fs/btrfs/ref-verify.c +10 -13
@@ -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 ));
Signature · 1 line
2.26.2
Quoted 17 lines · Josef Bacik
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 forbtrfs_search_slotandbtrfs_cow_block
btrfs: print the actual offset inbtrfs_root_name
btrfs: noinlinebtrfs_should_cancel_balance
btrfs: pass down the tree block level through ref-verify
btrfs: make sure owner is set in ref-verify
Quoted 8 lines
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 :
I'm not too familiar with ref-verify for the other 2.
Re: [PATCH 2/5] btrfs: print the actual offset in btrfs_root_name
In reply to Josef Bacikfs/btrfs/print-tree.c static const struct root_name_map root_map[] = { · line 29
Quoted 8 lines · Josef Bacik
fs/btrfs/print-tree.c +1
-1@@ -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.
Quoted 8 lines · Josef Bacik
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,
Quoted 8 lines
Josef
Josef Bacik (5):
btrfs: allow error injection forbtrfs_search_slotandbtrfs_cow_block
btrfs: print the actual offset inbtrfs_root_name
btrfs: noinlinebtrfs_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.