diff mbox

[2/2] btrfs: fix locking when we put back a delayed ref that's too new

Message ID 1482258508-7594-2-git-send-email-jeffm@suse.com (mailing list archive)
State Accepted
Headers show

Commit Message

Jeff Mahoney Dec. 20, 2016, 6:28 p.m. UTC
From: Jeff Mahoney <jeffm@suse.com>

In __btrfs_run_delayed_refs, when we put back a delayed ref that's too
new, we have already dropped the lock on locked_ref when we set
->processing = 0.

This patch keeps the lock to cover that assignment.

Fixes: d7df2c796d7 (Btrfs: attach delayed ref updates to delayed ref heads)
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/btrfs/extent-tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Liu Bo Dec. 22, 2016, 5:42 a.m. UTC | #1
On Tue, Dec 20, 2016 at 01:28:28PM -0500, jeffm@suse.com wrote:
> From: Jeff Mahoney <jeffm@suse.com>
> 
> In __btrfs_run_delayed_refs, when we put back a delayed ref that's too
> new, we have already dropped the lock on locked_ref when we set
> ->processing = 0.
> 
> This patch keeps the lock to cover that assignment.
> 
> Fixes: d7df2c796d7 (Btrfs: attach delayed ref updates to delayed ref heads)
> Signed-off-by: Jeff Mahoney <jeffm@suse.com>
> ---
>  fs/btrfs/extent-tree.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index d74adf1..930ac8e 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -2526,11 +2526,11 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
>  		if (ref && ref->seq &&
>  		    btrfs_check_delayed_seq(fs_info, delayed_refs, ref->seq)) {
>  			spin_unlock(&locked_ref->lock);
> -			btrfs_delayed_ref_unlock(locked_ref);
>  			spin_lock(&delayed_refs->lock);
>  			locked_ref->processing = 0;
>  			delayed_refs->num_heads_ready++;
>  			spin_unlock(&delayed_refs->lock);
> +			btrfs_delayed_ref_unlock(locked_ref);

I don't think that this would end up a deadlock as we use mutex_try_lock
for head->mutex everywhere, but I'd rather have it cleaned up.

Reviewed-by: Liu Bo <bo.li.liu@oracle.com>

Thanks,

-liubo
>  			locked_ref = NULL;
>  			cond_resched();
>  			count++;
> -- 
> 1.8.5.6
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index d74adf1..930ac8e 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2526,11 +2526,11 @@  static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
 		if (ref && ref->seq &&
 		    btrfs_check_delayed_seq(fs_info, delayed_refs, ref->seq)) {
 			spin_unlock(&locked_ref->lock);
-			btrfs_delayed_ref_unlock(locked_ref);
 			spin_lock(&delayed_refs->lock);
 			locked_ref->processing = 0;
 			delayed_refs->num_heads_ready++;
 			spin_unlock(&delayed_refs->lock);
+			btrfs_delayed_ref_unlock(locked_ref);
 			locked_ref = NULL;
 			cond_resched();
 			count++;