diff mbox series

[v2] btrfs: Rework error detection in init_tree_roots

Message ID 20200812131635.8432-1-nborisov@suse.com (mailing list archive)
State New, archived
Headers show
Series [v2] btrfs: Rework error detection in init_tree_roots | expand

Commit Message

Nikolay Borisov Aug. 12, 2020, 1:16 p.m. UTC
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. 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   delta
open_ctree                                 17243   17148     -95
Total: Before=113104, After=113009, chg -0.08%

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

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(-)

--
2.17.1

Comments

Nikolay Borisov Aug. 27, 2020, 7:02 a.m. UTC | #1
On 12.08.20 г. 16:16 ч., Nikolay Borisov wrote:
> 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. 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   delta
> open_ctree                                 17243   17148     -95
> Total: Before=113104, After=113009, chg -0.08%
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
> 
> 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.

Any comments on V2 ?
David Sterba Aug. 27, 2020, 12:37 p.m. UTC | #2
On Thu, Aug 27, 2020 at 10:02:10AM +0300, Nikolay Borisov wrote:
> 
> 
> On 12.08.20 г. 16:16 ч., Nikolay Borisov wrote:
> > 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. 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   delta
> > open_ctree                                 17243   17148     -95
> > Total: Before=113104, After=113009, chg -0.08%
> > 
> > Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> > ---
> > 
> > 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.
> 
> Any comments on V2 ?

Code is ok, the messages should not start with an uppercase letter,
fixed.
diff mbox series

Patch

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 2f4169231992..2483648f2915 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -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;
 		}