All of lore.kernel.org
 help / color / mirror / Atom feed
From: Liu Bo <bo.liu@linux.alibaba.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH 5/6] Btrfs: grab write lock directly if write_lock_level is the max level
Date: Wed, 16 May 2018 01:52:07 +0800	[thread overview]
Message-ID: <1526406728-109055-6-git-send-email-bo.liu@linux.alibaba.com> (raw)
In-Reply-To: <1526406728-109055-1-git-send-email-bo.liu@linux.alibaba.com>

In case of (cow && (p->keep_locks || p->lowest_level)), write_lock_level
is the max level, and we should grab write lock of root node from the very
beginning.

Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
---
 fs/btrfs/ctree.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index cf34eca41d4e..f7c3f581f647 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -2633,20 +2633,23 @@ static struct extent_buffer *btrfs_search_slot_get_root(struct btrfs_root *root,
 		goto out;
 	}
 
-	/*
-	 * we don't know the level of the root node until we actually
-	 * have it read locked
-	 */
-	b = btrfs_read_lock_root_node(root);
-	level = btrfs_header_level(b);
-	if (level > write_lock_level)
-		goto out;
+	if (write_lock_level < BTRFS_MAX_LEVEL) {
+		/*
+		 * we don't know the level of the root node until we actually
+		 * have it read locked
+		 */
+		b = btrfs_read_lock_root_node(root);
+		level = btrfs_header_level(b);
+		if (level > write_lock_level)
+			goto out;
+
+		/*
+		 * whoops, must trade for write lock
+		 */
+		btrfs_tree_read_unlock(b);
+		free_extent_buffer(b);
+	}
 
-	/*
-	 * whoops, must trade for write lock
-	 */
-	btrfs_tree_read_unlock(b);
-	free_extent_buffer(b);
 	b = btrfs_lock_root_node(root);
 	root_lock = BTRFS_WRITE_LOCK;
 	/*
-- 
1.8.3.1


  parent reply	other threads:[~2018-05-15 17:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-15 17:52 [PATCH 0/6] btrfs_search_slot cleanups Liu Bo
2018-05-15 17:52 ` [PATCH 1/6] Btrfs: remove superfluous free_extent_buffer Liu Bo
2018-05-16  6:40   ` Nikolay Borisov
2018-05-15 17:52 ` [PATCH 2/6] Btrfs: use more straightforward extent_buffer_uptodate Liu Bo
2018-05-16  6:43   ` Nikolay Borisov
2018-05-18  2:09     ` Liu Bo
2018-05-15 17:52 ` [PATCH 3/6] Btrfs: move get root of btrfs_search_slot to a helper Liu Bo
2018-05-16  6:54   ` Nikolay Borisov
2018-05-15 17:52 ` [PATCH 4/6] Btrfs: remove unused check of skip_locking Liu Bo
2018-05-16  7:03   ` Nikolay Borisov
2018-05-16  7:06     ` Qu Wenruo
2018-05-18  2:55     ` Liu Bo
2018-05-18  5:36       ` Nikolay Borisov
2018-05-15 17:52 ` Liu Bo [this message]
2018-05-16  7:09   ` [PATCH 5/6] Btrfs: grab write lock directly if write_lock_level is the max level Nikolay Borisov
2018-05-15 17:52 ` [PATCH 6/6] Btrfs: remove always true check in unlock_up Liu Bo
2018-05-16  6:47   ` Nikolay Borisov
2018-05-15 18:15 ` [PATCH 0/6] btrfs_search_slot cleanups 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=1526406728-109055-6-git-send-email-bo.liu@linux.alibaba.com \
    --to=bo.liu@linux.alibaba.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.