From patchwork Fri Mar 14 20:55:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 3835311 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 370CEBF540 for ; Fri, 14 Mar 2014 20:55:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3A0B520320 for ; Fri, 14 Mar 2014 20:55:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2B61320303 for ; Fri, 14 Mar 2014 20:55:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755727AbaCNUzU (ORCPT ); Fri, 14 Mar 2014 16:55:20 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:46370 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753707AbaCNUzU (ORCPT ); Fri, 14 Mar 2014 16:55:20 -0400 Received: by mail-wi0-f169.google.com with SMTP id hm4so203995wib.2 for ; Fri, 14 Mar 2014 13:55:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=5MdthJiYlCUZJkDfU5nA5oAWg0xk/rDF+JDdPShEVqA=; b=zyg1bR/ZsOKn1QrFamn3o+B0ceFogJpblIAB7l1ZgPVMv9fERWsW0210CANrZSKC/3 4If7i9x3LAyrFEoVeaCZFJALEPrg67e37wUROzQiPp4n7hbWmBIfrVGSg34m06/l+7Ww Vy08yf+rAIDzwaSEHnwEEmPrxTrBGJp3aWw2zOuvID5ef6PADhtlUPLhFs6tkArXg4Wv tweGZwiJjaeF/MC3zKDXzg19E6mNGBjOOl2FcTHy9bT2XFd6bsCwQoWFiklGRS2V0diz 2JRPLRrClI9kNfF/skHMMDj/bdhsdkKx2i2c0ZE51I6NBGKtVEdtX7pUcQEYjApwPO3H y5fg== X-Received: by 10.180.94.196 with SMTP id de4mr52565wib.16.1394830518792; Fri, 14 Mar 2014 13:55:18 -0700 (PDT) Received: from storm-desktop.lan (bl10-252-34.dsl.telepac.pt. [85.243.252.34]) by mx.google.com with ESMTPSA id ff9sm424516wib.11.2014.03.14.13.55.17 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Mar 2014 13:55:18 -0700 (PDT) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH] Btrfs: fix race when updating existing ref head Date: Fri, 14 Mar 2014 20:55:01 +0000 Message-Id: <1394830501-24550-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP While we update an existing ref head's extent_op, we're not holding its spinlock, so while we're updating its extent_op contents (key, flags) we can have a task running __btrfs_run_delayed_refs() that holds the ref head's lock and sets its extent_op to NULL right after the task updating the ref head just checked its extent_op was not NULL. Signed-off-by: Filipe David Borba Manana --- fs/btrfs/delayed-ref.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 2502ba5..3129964 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -495,6 +495,7 @@ update_existing_head_ref(struct btrfs_delayed_ref_node *existing, ref = btrfs_delayed_node_to_head(update); BUG_ON(existing_ref->is_data != ref->is_data); + spin_lock(&existing_ref->lock); if (ref->must_insert_reserved) { /* if the extent was freed and then * reallocated before the delayed ref @@ -536,7 +537,6 @@ update_existing_head_ref(struct btrfs_delayed_ref_node *existing, * only need the lock for this case cause we could be processing it * currently, for refs we just added we know we're a-ok. */ - spin_lock(&existing_ref->lock); existing->ref_mod += update->ref_mod; spin_unlock(&existing_ref->lock); }