btrfs: Rework error detection in init_tree_roots
PATCH 1/1 btrfs: Rework error detection in init_tree_roots
To avoid duplicating 3 lines of code the error detection logic in init_tree_roots is somewhat quirky. It first checks for the presence of any error condition, then checks for the specific condition to perform any specific actions. That's spurious because directly checking for each respective error condition and doing the necessary steps is more obvious. Additionally it results in smaller code and the code reads more linearly:
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-95 (-95)
Function old new deltaopen_ctree 17243 17148 -95
Total: Before=113104, After=113009, chg -0.08%
--- fs/btrfs/disk-io.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
fs/btrfs/disk-io.c +8 -9
@@ -2645,17 +2645,16 @@ static int __cold init_tree_roots(struct btrfs_fs_info *fs_info) level =btrfs_super_root_level (sb); tree_root->node =read_tree_block (fs_info,btrfs_super_root (sb), generation, level,NULL ); -if (IS_ERR (tree_root->node) || - !extent_buffer_uptodate (tree_root->node)) { +if (IS_ERR (tree_root->node)) { handle_error = true; + ret =PTR_ERR (tree_root->node); + tree_root->node =NULL ; +btrfs_warn (fs_info,"failed to read tree root" ); +continue ; -if (IS_ERR (tree_root->node)) { - ret =PTR_ERR (tree_root->node); - tree_root->node =NULL ; - }else if (!extent_buffer_uptodate (tree_root->node)) { - ret = -EUCLEAN ; - } - + }else if (!extent_buffer_uptodate (tree_root->node)) { + handle_error = true; + ret = -EUCLEAN ;btrfs_warn (fs_info,"failed to read tree root" );continue ; }
Signature · 1 line
2.17.1
Quoted 12 lines · Nikolay Borisov
fs/btrfs/disk-io.c +5
-2@@ -2645,17 +2645,16 @@ static int __cold init_tree_roots(struct btrfs_fs_info *fs_info) level =btrfs_super_root_level (sb); tree_root->node =read_tree_block (fs_info,btrfs_super_root (sb), generation, level,NULL ); -if (IS_ERR (tree_root->node) || - !extent_buffer_uptodate (tree_root->node)) { +if (IS_ERR (tree_root->node)) { handle_error = true; + ret =PTR_ERR (tree_root->node); + tree_root->node =NULL ; +btrfs_warn (fs_info,"failed to read tree root" ); +continue ;
[...]
fs/btrfs/disk-io.c static int __cold init_tree_roots(struct btrfs_fs_info *fs_info) · line 2660
Quoted 3 lines
fs/btrfs/disk-io.c +0
-0btrfs_warn (fs_info,"failed to read tree root" );continue ; }
Now we're duplicating the warning message. I think it's better to have two distinct messages so we can differentiate which of the two failure cases happened.
The 2nd one could be something like "tree root eb not uptodate".
Otherwise looks good,
Quoted 16 lines · Johannes Thumshirn
Quoted 12 lines · Nikolay Borisov
fs/btrfs/disk-io.c +5
-2@@ -2645,17 +2645,16 @@ static int __cold init_tree_roots(struct btrfs_fs_info *fs_info) level =btrfs_super_root_level (sb); tree_root->node =read_tree_block (fs_info,btrfs_super_root (sb), generation, level,NULL ); -if (IS_ERR (tree_root->node) || - !extent_buffer_uptodate (tree_root->node)) { +if (IS_ERR (tree_root->node)) { handle_error = true; + ret =PTR_ERR (tree_root->node); + tree_root->node =NULL ; +btrfs_warn (fs_info,"failed to read tree root" ); +continue ;[...]
Quoted 8 lines
fs/btrfs/disk-io.c static int __cold init_tree_roots(struct btrfs_fs_info *fs_info) · line 2660
Quoted 3 lines
fs/btrfs/disk-io.c +0
-0btrfs_warn (fs_info,"failed to read tree root" );continue ; }Now we're duplicating the warning message. I think it's better to have two distinct messages so we can differentiate which of the two failure cases happened.
The 2nd one could be something like "tree root eb not uptodate".
Sure, I'm happy too replace it with whatever is more informative. Will take another look at the code and see what I can derive.
Quoted 4 lines
Otherwise looks good,
Reviewed-by Johannes Thumshirn <[email protected]>
Quoted 23 lines · Nikolay Borisov
Quoted 20 lines · Johannes Thumshirn
Quoted 12 lines · Nikolay Borisov
fs/btrfs/disk-io.c +5
-2@@ -2645,17 +2645,16 @@ static int __cold init_tree_roots(struct btrfs_fs_info *fs_info) level =btrfs_super_root_level (sb); tree_root->node =read_tree_block (fs_info,btrfs_super_root (sb), generation, level,NULL ); -if (IS_ERR (tree_root->node) || - !extent_buffer_uptodate (tree_root->node)) { +if (IS_ERR (tree_root->node)) { handle_error = true; + ret =PTR_ERR (tree_root->node); + tree_root->node =NULL ; +btrfs_warn (fs_info,"failed to read tree root" ); +continue ;[...]
Quoted 3 lines
fs/btrfs/disk-io.c +0
-0btrfs_warn (fs_info,"failed to read tree root" );continue ; }
Quoted 7 lines
Quoted 4 lines
Now we're duplicating the warning message. I think it's better to have two distinct messages so we can differentiate which of the two failure cases happened.
The 2nd one could be something like "tree root eb not uptodate".
Sure, I'm happy too replace it with whatever is more informative. Will take another look at the code and see what I can derive.
The errors are different, IS_ERR is because the block was not read at all for some reason, extent_buffer_uptodate is EIO in all other places that do this kind of check.
Here it's EUCLEAN and it's been like that since the beginning but I think it should be EIO.
PATCH v2 1/1 btrfs: Rework error detection in init_tree_roots
In reply to Nikolay BorisovTo avoid duplicating 3 lines of code the error detection logic in init_tree_roots is somewhat quirky. It first checks for the presence of any error condition, then checks for the specific condition to perform any specific actions. That's spurious because directly checking for each respective error condition and doing the necessary steps is more obvious. While at it change the -EUCLEAN to -EIO in case the extent buffer is not read correctly, this is in line with other sites which return -EIO when the eb couldn't be read.
Additionally it results in smaller code and the code reads more linearly:
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-95 (-95)
Function old new deltaopen_ctree 17243 17148 -95
Total: Before=113104, After=113009, chg -0.08%
---
Changes in v2:
* Return -EIO in case of !extent_buffer_uptodate
* Change the error messages to distinguish both cases albeit they are still rather similar.
fs/btrfs/disk-io.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
fs/btrfs/disk-io.c +9 -10
@@ -2624,18 +2624,17 @@ static int __cold init_tree_roots(struct btrfs_fs_info *fs_info) level =btrfs_super_root_level (sb); tree_root->node =read_tree_block (fs_info,btrfs_super_root (sb), generation, level,NULL ); -if (IS_ERR (tree_root->node) || - !extent_buffer_uptodate (tree_root->node)) { +if (IS_ERR (tree_root->node)) { handle_error = true; + ret =PTR_ERR (tree_root->node); + tree_root->node =NULL ; +btrfs_warn (fs_info,"Couldn't read tree root" ); +continue ; -if (IS_ERR (tree_root->node)) { - ret =PTR_ERR (tree_root->node); - tree_root->node =NULL ; - }else if (!extent_buffer_uptodate (tree_root->node)) { - ret = -EUCLEAN ; - } - -btrfs_warn (fs_info,"failed to read tree root" ); + }else if (!extent_buffer_uptodate (tree_root->node)) { + handle_error = true; + ret = -EIO ; +btrfs_warn (fs_info,"Error while reading tree root" );continue ; }
--
2.17.1
Quoted 17 lines · Nikolay Borisov
To avoid duplicating 3 lines of code the error detection logic in
init_tree_rootsis somewhat quirky. It first checks for the presence of any error condition, then checks for the specific condition to perform any specific actions. That's spurious because directly checking for each respective error condition and doing the necessary steps is more obvious. While at it change the-EUCLEANto-EIOin case the extent buffer is not read correctly, this is in line with other sites which return-EIOwhen the eb couldn't be read.Additionally it results in smaller code and the code reads more linearly:
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-95 (-95)
Function old new deltaopen_ctree17243 17148 -95
Total: Before=113104, After=113009, chg -0.08%
Quoted 7 lines
Signed-off-by Nikolay Borisov <[email protected]>---
Changes in v2:
* Return-EIOin case of !extent_buffer_uptodate
* Change the error messages to distinguish both cases albeit they are still rather similar.
Any comments on V2 ?
Quoted 23 lines · Nikolay Borisov
Quoted 20 lines · Nikolay Borisov
To avoid duplicating 3 lines of code the error detection logic in
init_tree_rootsis somewhat quirky. It first checks for the presence of any error condition, then checks for the specific condition to perform any specific actions. That's spurious because directly checking for each respective error condition and doing the necessary steps is more obvious. While at it change the-EUCLEANto-EIOin case the extent buffer is not read correctly, this is in line with other sites which return-EIOwhen the eb couldn't be read.Additionally it results in smaller code and the code reads more linearly:
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-95 (-95)
Function old new deltaopen_ctree17243 17148 -95
Total: Before=113104, After=113009, chg -0.08%Signed-off-by Nikolay Borisov <[email protected]>---
Quoted 6 lines
Quoted 4 lines
Changes in v2:
* Return-EIOin case of !extent_buffer_uptodate
* Change the error messages to distinguish both cases albeit they are still rather similar.Any comments on V2 ?
Code is ok, the messages should not start with an uppercase letter, fixed.