linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arne Jansen <sensille@gmx.net>
To: Josef Bacik <josef@redhat.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] Btrfs: don't map extent buffer if path->skip_locking is set
Date: Thu, 09 Jun 2011 08:55:18 +0200	[thread overview]
Message-ID: <4DF06E56.1030808@gmx.net> (raw)
In-Reply-To: <1307558750-19721-1-git-send-email-josef@redhat.com>

On 08.06.2011 20:45, Josef Bacik wrote:
> Arne's scrub stuff exposed a problem with mapping the extent buffer in
> reada_for_search.  He searches the commit root with multiple threads and with
> skip_locking set, so we can race and overwrite node->map_token since node isn't
> locked.  So fix this so that we only map the extent buffer if we don't already
> have a map_token and skip_locking isn't set.  Without this patch scrub would
> panic almost immediately, with the patch it doesn't panic anymore.  Thanks,
> 
> Reported-by: Arne Jansen <sensille@gmx.net>
> Signed-off-by: Josef Bacik <josef@redhat.com>

This fixes the BUGs I saw, so you can add a Tested-by: Arne Jansen
<sensille@gmx.net> if you like.

-Arne

> ---
>  fs/btrfs/ctree.c |   10 +++++++---
>  1 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> index d840893..2e66786 100644
> --- a/fs/btrfs/ctree.c
> +++ b/fs/btrfs/ctree.c
> @@ -1228,6 +1228,7 @@ static void reada_for_search(struct btrfs_root *root,
>  	u32 nr;
>  	u32 blocksize;
>  	u32 nscan = 0;
> +	bool map = true;
>  
>  	if (level != 1)
>  		return;
> @@ -1249,8 +1250,11 @@ static void reada_for_search(struct btrfs_root *root,
>  
>  	nritems = btrfs_header_nritems(node);
>  	nr = slot;
> +	if (node->map_token || path->skip_locking)
> +		map = false;
> +
>  	while (1) {
> -		if (!node->map_token) {
> +		if (map && !node->map_token) {
>  			unsigned long offset = btrfs_node_key_ptr_offset(nr);
>  			map_private_extent_buffer(node, offset,
>  						  sizeof(struct btrfs_key_ptr),
> @@ -1277,7 +1281,7 @@ static void reada_for_search(struct btrfs_root *root,
>  		if ((search <= target && target - search <= 65536) ||
>  		    (search > target && search - target <= 65536)) {
>  			gen = btrfs_node_ptr_generation(node, nr);
> -			if (node->map_token) {
> +			if (map && node->map_token) {
>  				unmap_extent_buffer(node, node->map_token,
>  						    KM_USER1);
>  				node->map_token = NULL;
> @@ -1289,7 +1293,7 @@ static void reada_for_search(struct btrfs_root *root,
>  		if ((nread > 65536 || nscan > 32))
>  			break;
>  	}
> -	if (node->map_token) {
> +	if (map && node->map_token) {
>  		unmap_extent_buffer(node, node->map_token, KM_USER1);
>  		node->map_token = NULL;
>  	}


      reply	other threads:[~2011-06-09  6:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-08 18:45 [PATCH] Btrfs: don't map extent buffer if path->skip_locking is set Josef Bacik
2011-06-09  6:55 ` Arne Jansen [this message]

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=4DF06E56.1030808@gmx.net \
    --to=sensille@gmx.net \
    --cc=josef@redhat.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).