From: josef@toxicpanda.com
To: kernel-team@fb.com, linux-btrfs@vger.kernel.org
Cc: Josef Bacik <jbacik@fb.com>
Subject: [PATCH 02/10] btrfs: move extent_op cleanup to a helper
Date: Mon, 11 Sep 2017 17:12:28 -0400 [thread overview]
Message-ID: <1505164356-13474-3-git-send-email-jbacik@fb.com> (raw)
In-Reply-To: <1505164356-13474-1-git-send-email-jbacik@fb.com>
From: Josef Bacik <jbacik@fb.com>
Move the extent_op cleanup for an empty head ref to a helper function to
help simplify __btrfs_run_delayed_refs.
Signed-off-by: Josef Bacik <jbacik@fb.com>
---
fs/btrfs/extent-tree.c | 77 ++++++++++++++++++++++++++------------------------
1 file changed, 40 insertions(+), 37 deletions(-)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 636aac0..47780b7 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2519,6 +2519,26 @@ unselect_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_refs,
btrfs_delayed_ref_unlock(head);
}
+static int cleanup_extent_op(struct btrfs_trans_handle *trans,
+ struct btrfs_fs_info *fs_info,
+ struct btrfs_delayed_ref_head *head)
+{
+ struct btrfs_delayed_extent_op *extent_op = head->extent_op;
+ int ret;
+
+ if (!extent_op)
+ return 0;
+ head->extent_op = NULL;
+ if (head->must_insert_reserved) {
+ btrfs_free_delayed_extent_op(extent_op);
+ return 0;
+ }
+ spin_unlock(&head->lock);
+ ret = run_delayed_extent_op(trans, fs_info, &head->node, extent_op);
+ btrfs_free_delayed_extent_op(extent_op);
+ return ret ? ret : 1;
+}
+
/*
* Returns 0 on success or if called with an already aborted transaction.
* Returns -ENOMEM or -EIO on failure and will abort the transaction.
@@ -2599,16 +2619,6 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
continue;
}
- /*
- * record the must insert reserved flag before we
- * drop the spin lock.
- */
- must_insert_reserved = locked_ref->must_insert_reserved;
- locked_ref->must_insert_reserved = 0;
-
- extent_op = locked_ref->extent_op;
- locked_ref->extent_op = NULL;
-
if (!ref) {
@@ -2618,33 +2628,17 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
*/
ref = &locked_ref->node;
- if (extent_op && must_insert_reserved) {
- btrfs_free_delayed_extent_op(extent_op);
- extent_op = NULL;
- }
-
- if (extent_op) {
- spin_unlock(&locked_ref->lock);
- ret = run_delayed_extent_op(trans, fs_info,
- ref, extent_op);
- btrfs_free_delayed_extent_op(extent_op);
-
- if (ret) {
- /*
- * Need to reset must_insert_reserved if
- * there was an error so the abort stuff
- * can cleanup the reserved space
- * properly.
- */
- if (must_insert_reserved)
- locked_ref->must_insert_reserved = 1;
- unselect_delayed_ref_head(delayed_refs,
- locked_ref);
- btrfs_debug(fs_info,
- "run_delayed_extent_op returned %d",
- ret);
- return ret;
- }
+ ret = cleanup_extent_op(trans, fs_info, locked_ref);
+ if (ret < 0) {
+ unselect_delayed_ref_head(delayed_refs,
+ locked_ref);
+ btrfs_debug(fs_info,
+ "run_delayed_extent_op returned %d",
+ ret);
+ return ret;
+ } else if (ret > 0) {
+ /* We dropped our lock, we need to loop. */
+ ret = 0;
continue;
}
@@ -2693,6 +2687,15 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
WARN_ON(1);
}
}
+ /*
+ * record the must insert reserved flag before we
+ * drop the spin lock.
+ */
+ must_insert_reserved = locked_ref->must_insert_reserved;
+ locked_ref->must_insert_reserved = 0;
+
+ extent_op = locked_ref->extent_op;
+ locked_ref->extent_op = NULL;
spin_unlock(&locked_ref->lock);
ret = run_one_delayed_ref(trans, fs_info, ref, extent_op,
--
2.7.4
next prev parent reply other threads:[~2017-09-11 21:12 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-11 21:12 [RFC][0/10] Cleanup and enhance delayed refs josef
2017-09-11 21:12 ` [PATCH 01/10] btrfs: add a helper to return a head ref josef
2017-09-11 21:12 ` josef [this message]
2017-09-11 21:12 ` [PATCH 03/10] btrfs: breakout empty head cleanup to a helper josef
2017-09-11 21:12 ` [PATCH 04/10] btrfs: move ref_mod modification into the if (ref) logic josef
2017-09-11 21:12 ` [PATCH 05/10] btrfs: move all ref head cleanup to the helper function josef
2017-09-11 21:12 ` [PATCH 06/10] btrfs: remove delayed_ref_node from ref_head josef
2017-09-11 21:12 ` [PATCH 07/10] btrfs: remove type argument from comp_tree_refs josef
2017-09-12 16:08 ` Timofey Titovets
2017-09-11 21:12 ` [PATCH 08/10] btrfs: switch args for comp_*_refs josef
2017-09-12 16:21 ` Timofey Titovets
2017-09-12 16:35 ` Timofey Titovets
2017-09-11 21:12 ` [PATCH 09/10] btrfs: add a comp_refs() helper josef
2017-09-11 21:12 ` [PATCH 10/10] btrfs: track refs in a rb_tree instead of a list josef
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=1505164356-13474-3-git-send-email-jbacik@fb.com \
--to=josef@toxicpanda.com \
--cc=jbacik@fb.com \
--cc=kernel-team@fb.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;
as well as URLs for NNTP newsgroup(s).