public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 1/8] btrfs: Make get_state_failrec return failrec directly
Date: Thu,  2 Jul 2020 15:23:28 +0300	[thread overview]
Message-ID: <20200702122335.9117-2-nborisov@suse.com> (raw)
In-Reply-To: <20200702122335.9117-1-nborisov@suse.com>

Only failure that get_state_failrec can get is if there is no failurec
for the given address. There is no reason why the function should return
a status code and use a separate parameter for returning the actual
failure rec (if one is found). Simplify it by making the return type
a pointer and return ERR_PTR value in case of errors.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/extent-io-tree.h |  4 ++--
 fs/btrfs/extent_io.c      | 23 ++++++++++++-----------
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/extent-io-tree.h b/fs/btrfs/extent-io-tree.h
index b6561455b3c4..62eef5b1dfc6 100644
--- a/fs/btrfs/extent-io-tree.h
+++ b/fs/btrfs/extent-io-tree.h
@@ -233,8 +233,8 @@ bool btrfs_find_delalloc_range(struct extent_io_tree *tree, u64 *start,
 			       struct extent_state **cached_state);
 
 /* This should be reworked in the future and put elsewhere. */
-int get_state_failrec(struct extent_io_tree *tree, u64 start,
-		      struct io_failure_record **failrec);
+struct io_failure_record *get_state_failrec(struct extent_io_tree *tree,
+					    u64 start);
 int set_state_failrec(struct extent_io_tree *tree, u64 start,
 		      struct io_failure_record *failrec);
 void btrfs_free_io_failure_record(struct btrfs_inode *inode, u64 start,
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 8a7e9da74b87..6f0891ad353b 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -2121,12 +2121,12 @@ int set_state_failrec(struct extent_io_tree *tree, u64 start,
 	return ret;
 }
 
-int get_state_failrec(struct extent_io_tree *tree, u64 start,
-		      struct io_failure_record **failrec)
+struct io_failure_record *get_state_failrec(struct extent_io_tree *tree,
+					    u64 start)
 {
 	struct rb_node *node;
 	struct extent_state *state;
-	int ret = 0;
+	struct io_failure_record *failrec;
 
 	spin_lock(&tree->lock);
 	/*
@@ -2135,18 +2135,19 @@ int get_state_failrec(struct extent_io_tree *tree, u64 start,
 	 */
 	node = tree_search(tree, start);
 	if (!node) {
-		ret = -ENOENT;
+		failrec = ERR_PTR(-ENOENT);
 		goto out;
 	}
 	state = rb_entry(node, struct extent_state, rb_node);
 	if (state->start != start) {
-		ret = -ENOENT;
+		failrec = ERR_PTR(-ENOENT);
 		goto out;
 	}
-	*failrec = state->failrec;
+
+	failrec = state->failrec;
 out:
 	spin_unlock(&tree->lock);
-	return ret;
+	return failrec;
 }
 
 /*
@@ -2376,8 +2377,8 @@ int clean_io_failure(struct btrfs_fs_info *fs_info,
 	if (!ret)
 		return 0;
 
-	ret = get_state_failrec(failure_tree, start, &failrec);
-	if (ret)
+	failrec = get_state_failrec(failure_tree, start);
+	if (IS_ERR(failrec))
 		return 0;
 
 	BUG_ON(!failrec->this_mirror);
@@ -2461,8 +2462,8 @@ int btrfs_get_io_failure_record(struct inode *inode, u64 start, u64 end,
 	int ret;
 	u64 logical;
 
-	ret = get_state_failrec(failure_tree, start, &failrec);
-	if (ret) {
+	failrec = get_state_failrec(failure_tree, start);
+	if (IS_ERR(failrec)) {
 		failrec = kzalloc(sizeof(*failrec), GFP_NOFS);
 		if (!failrec)
 			return -ENOMEM;
-- 
2.17.1


  reply	other threads:[~2020-07-02 12:44 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-02 12:23 [PATCH 0/7] Corrupt counter improvement Nikolay Borisov
2020-07-02 12:23 ` Nikolay Borisov [this message]
2020-07-02 13:07   ` [PATCH 1/8] btrfs: Make get_state_failrec return failrec directly Josef Bacik
2020-07-02 13:25     ` David Sterba
2020-07-02 12:23 ` [PATCH 2/8] btrfs: Streamline btrfs_get_io_failure_record logic Nikolay Borisov
2020-07-02 13:13   ` Josef Bacik
2020-07-02 12:23 ` [PATCH 3/8] btrfs: Record btrfs_device directly btrfs_io_bio Nikolay Borisov
2020-07-02 13:14   ` Josef Bacik
2020-07-02 13:16   ` Johannes Thumshirn
2020-07-03  8:14   ` [PATCH v2] " Nikolay Borisov
2020-07-03 13:06     ` Johannes Thumshirn
2020-07-02 12:23 ` [PATCH 4/8] btrfs: Don't check for btrfs_device::bdev in btrfs_end_bio Nikolay Borisov
2020-07-02 13:15   ` Josef Bacik
2020-07-02 12:23 ` [PATCH 5/8] btrfs: Increment device corruption error in case of checksum error Nikolay Borisov
2020-07-02 13:18   ` Josef Bacik
2020-07-02 13:21   ` Johannes Thumshirn
2020-07-02 14:44     ` Nikolay Borisov
2020-07-02 12:23 ` [PATCH 6/8] btrfs: Remove needless ASSERT Nikolay Borisov
2020-07-02 13:19   ` Josef Bacik
2020-07-02 13:26   ` Johannes Thumshirn
2020-07-02 12:23 ` [PATCH 7/8] btrfs: Increment corrupt device counter during compressed read Nikolay Borisov
2020-07-02 13:21   ` Josef Bacik
2020-07-02 13:28   ` Johannes Thumshirn
2020-07-02 12:23 ` [PATCH 8/8] btrfs: sysfs: Add bdi link to the fsid dir Nikolay Borisov
2020-07-02 13:25   ` Josef Bacik
2020-07-02 13:36     ` David Sterba
2020-07-02 14:41       ` Nikolay Borisov
2020-07-03  8:13   ` [PATCH v2] " Nikolay Borisov
2020-07-05 11:39     ` Anand Jain
2020-07-03 15:32 ` [PATCH 0/7] Corrupt counter improvement 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=20200702122335.9117-2-nborisov@suse.com \
    --to=nborisov@suse.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox