* [PATCH] btrfs: delayed-ref: extract find_first_ref_head from find_ref_head
@ 2018-10-15 6:25 Lu Fengqi
2018-10-15 6:51 ` Nikolay Borisov
2018-10-17 17:21 ` David Sterba
0 siblings, 2 replies; 3+ messages in thread
From: Lu Fengqi @ 2018-10-15 6:25 UTC (permalink / raw)
To: linux-btrfs; +Cc: nborisov
The find_ref_head shouldn't return the first entry even if no exact match
is found. So move the hidden behavior to higher level.
Besides, remove the useless local variables in the btrfs_select_ref_head.
Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
---
fs/btrfs/delayed-ref.c | 45 +++++++++++++++++++++++-------------------
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
index 6e8be384398e..a92f104cf06f 100644
--- a/fs/btrfs/delayed-ref.c
+++ b/fs/btrfs/delayed-ref.c
@@ -164,14 +164,28 @@ static struct btrfs_delayed_ref_node* tree_insert(struct rb_root_cached *root,
return NULL;
}
+static struct btrfs_delayed_ref_head *find_first_ref_head(
+ struct btrfs_delayed_ref_root *dr)
+{
+ struct rb_node *n;
+ struct btrfs_delayed_ref_head *entry;
+
+ n = rb_first_cached(&dr->href_root);
+ if (!n)
+ return NULL;
+
+ entry = rb_entry(n, struct btrfs_delayed_ref_head, href_node);
+
+ return entry;
+}
+
/*
* find an head entry based on bytenr. This returns the delayed ref
* head if it was able to find one, or NULL if nothing was in that spot.
* If return_bigger is given, the next bigger entry is returned if no exact
- * match is found. But if no bigger one is found then the first node of the
- * ref head tree will be returned.
+ * match is found.
*/
-static struct btrfs_delayed_ref_head* find_ref_head(
+static struct btrfs_delayed_ref_head *find_ref_head(
struct btrfs_delayed_ref_root *dr, u64 bytenr,
bool return_bigger)
{
@@ -195,10 +209,9 @@ static struct btrfs_delayed_ref_head* find_ref_head(
if (bytenr > entry->bytenr) {
n = rb_next(&entry->href_node);
if (!n)
- n = rb_first_cached(&dr->href_root);
+ return NULL;
entry = rb_entry(n, struct btrfs_delayed_ref_head,
href_node);
- return entry;
}
return entry;
}
@@ -358,33 +371,25 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head(
struct btrfs_delayed_ref_root *delayed_refs)
{
struct btrfs_delayed_ref_head *head;
- u64 start;
- bool loop = false;
again:
- start = delayed_refs->run_delayed_start;
- head = find_ref_head(delayed_refs, start, true);
- if (!head && !loop) {
+ head = find_ref_head(delayed_refs, delayed_refs->run_delayed_start,
+ true);
+ if (!head && delayed_refs->run_delayed_start != 0) {
delayed_refs->run_delayed_start = 0;
- start = 0;
- loop = true;
- head = find_ref_head(delayed_refs, start, true);
- if (!head)
- return NULL;
- } else if (!head && loop) {
- return NULL;
+ head = find_first_ref_head(delayed_refs);
}
+ if (!head)
+ return NULL;
while (head->processing) {
struct rb_node *node;
node = rb_next(&head->href_node);
if (!node) {
- if (loop)
+ if (delayed_refs->run_delayed_start == 0)
return NULL;
delayed_refs->run_delayed_start = 0;
- start = 0;
- loop = true;
goto again;
}
head = rb_entry(node, struct btrfs_delayed_ref_head,
--
2.19.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: delayed-ref: extract find_first_ref_head from find_ref_head
2018-10-15 6:25 [PATCH] btrfs: delayed-ref: extract find_first_ref_head from find_ref_head Lu Fengqi
@ 2018-10-15 6:51 ` Nikolay Borisov
2018-10-17 17:21 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: Nikolay Borisov @ 2018-10-15 6:51 UTC (permalink / raw)
To: Lu Fengqi, linux-btrfs
On 15.10.2018 09:25, Lu Fengqi wrote:
> The find_ref_head shouldn't return the first entry even if no exact match
> is found. So move the hidden behavior to higher level.
>
> Besides, remove the useless local variables in the btrfs_select_ref_head.
>
> Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
> ---
> fs/btrfs/delayed-ref.c | 45 +++++++++++++++++++++++-------------------
> 1 file changed, 25 insertions(+), 20 deletions(-)
>
> diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c
> index 6e8be384398e..a92f104cf06f 100644
> --- a/fs/btrfs/delayed-ref.c
> +++ b/fs/btrfs/delayed-ref.c
> @@ -164,14 +164,28 @@ static struct btrfs_delayed_ref_node* tree_insert(struct rb_root_cached *root,
> return NULL;
> }
>
> +static struct btrfs_delayed_ref_head *find_first_ref_head(
> + struct btrfs_delayed_ref_root *dr)
> +{
> + struct rb_node *n;
> + struct btrfs_delayed_ref_head *entry;
> +
> + n = rb_first_cached(&dr->href_root);
> + if (!n)
> + return NULL;
> +
> + entry = rb_entry(n, struct btrfs_delayed_ref_head, href_node);
> +
> + return entry;
> +}
> +
> /*
> * find an head entry based on bytenr. This returns the delayed ref
> * head if it was able to find one, or NULL if nothing was in that spot.
> * If return_bigger is given, the next bigger entry is returned if no exact
> - * match is found. But if no bigger one is found then the first node of the
> - * ref head tree will be returned.
> + * match is found.
> */
> -static struct btrfs_delayed_ref_head* find_ref_head(
> +static struct btrfs_delayed_ref_head *find_ref_head(
> struct btrfs_delayed_ref_root *dr, u64 bytenr,
> bool return_bigger)
> {
> @@ -195,10 +209,9 @@ static struct btrfs_delayed_ref_head* find_ref_head(
> if (bytenr > entry->bytenr) {
> n = rb_next(&entry->href_node);
> if (!n)
> - n = rb_first_cached(&dr->href_root);
> + return NULL;
> entry = rb_entry(n, struct btrfs_delayed_ref_head,
> href_node);
> - return entry;
> }
> return entry;
> }
> @@ -358,33 +371,25 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head(
> struct btrfs_delayed_ref_root *delayed_refs)
> {
> struct btrfs_delayed_ref_head *head;
> - u64 start;
> - bool loop = false;
>
> again:
> - start = delayed_refs->run_delayed_start;
> - head = find_ref_head(delayed_refs, start, true);
> - if (!head && !loop) {
> + head = find_ref_head(delayed_refs, delayed_refs->run_delayed_start,
> + true);
> + if (!head && delayed_refs->run_delayed_start != 0) {
> delayed_refs->run_delayed_start = 0;
> - start = 0;
> - loop = true;
> - head = find_ref_head(delayed_refs, start, true);
> - if (!head)
> - return NULL;
> - } else if (!head && loop) {
> - return NULL;
> + head = find_first_ref_head(delayed_refs);
> }
> + if (!head)
> + return NULL;
>
> while (head->processing) {
> struct rb_node *node;
>
> node = rb_next(&head->href_node);
> if (!node) {
> - if (loop)
> + if (delayed_refs->run_delayed_start == 0)
> return NULL;
> delayed_refs->run_delayed_start = 0;
> - start = 0;
> - loop = true;
> goto again;
> }
> head = rb_entry(node, struct btrfs_delayed_ref_head,
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: delayed-ref: extract find_first_ref_head from find_ref_head
2018-10-15 6:25 [PATCH] btrfs: delayed-ref: extract find_first_ref_head from find_ref_head Lu Fengqi
2018-10-15 6:51 ` Nikolay Borisov
@ 2018-10-17 17:21 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2018-10-17 17:21 UTC (permalink / raw)
To: Lu Fengqi; +Cc: linux-btrfs, nborisov
On Mon, Oct 15, 2018 at 02:25:38PM +0800, Lu Fengqi wrote:
> The find_ref_head shouldn't return the first entry even if no exact match
> is found. So move the hidden behavior to higher level.
>
> Besides, remove the useless local variables in the btrfs_select_ref_head.
>
> Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Added to misc-next, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-10-17 17:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-15 6:25 [PATCH] btrfs: delayed-ref: extract find_first_ref_head from find_ref_head Lu Fengqi
2018-10-15 6:51 ` Nikolay Borisov
2018-10-17 17:21 ` David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).