From patchwork Fri Nov 6 18:36:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Maggard X-Patchwork-Id: 7570421 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9E868C05C6 for ; Fri, 6 Nov 2015 18:36:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CBB34206F7 for ; Fri, 6 Nov 2015 18:36:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9B4182065A for ; Fri, 6 Nov 2015 18:36:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756671AbbKFSgx (ORCPT ); Fri, 6 Nov 2015 13:36:53 -0500 Received: from mail-pa0-f44.google.com ([209.85.220.44]:34022 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752679AbbKFSgw (ORCPT ); Fri, 6 Nov 2015 13:36:52 -0500 Received: by padhx2 with SMTP id hx2so122121909pad.1 for ; Fri, 06 Nov 2015 10:36:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=H4bZ2/HUeh4ZTlZz5F8WeDEX+5ALQkYG3ZwCQOV1ZLM=; b=L84nvPwWnADjT3Epewk3Aw/8NL3YyVN+jZTe636IPBzcilrvU6Qq/7u3F33/B053Sp AGo7hDCl4X6pw0SiuX7tppPslDr2qHt9J4sKjD67/j5U1xRSJGwDDKNhhEiyHBN5S5gW 4Wvzwib8wteusRegaClizNnQ8FJu7qKZyo+zQ4LHF5CupKvklloO3FZNxbaYpic3W1ri ArAR3H85SY2azz6QwSl93Ki/d7aXaJ34VP2HVntssyXzlGIE1LIg3KJHmGDVJmrgo4Bl NIItrhG1wS+r7pi4X56pvx9elm9oN+a2q+MyLAl/YlWazG5t6VJAHmjjZW7KctjETkkt KRwg== X-Received: by 10.68.178.1 with SMTP id cu1mr20146753pbc.115.1446835011622; Fri, 06 Nov 2015 10:36:51 -0800 (PST) Received: from jmaggard-ThinkPad-W520.infrant-6.com ([209.249.181.1]) by smtp.gmail.com with ESMTPSA id yp9sm1398357pab.1.2015.11.06.10.36.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Nov 2015 10:36:51 -0800 (PST) From: Justin Maggard X-Google-Original-From: Justin Maggard To: linux-btrfs@vger.kernel.org Cc: Justin Maggard Subject: [PATCH] btrfs: qgroup: fix quota disable during rescan Date: Fri, 6 Nov 2015 10:36:42 -0800 Message-Id: <1446835002-11751-1-git-send-email-jmaggard@netgear.com> X-Mailer: git-send-email 2.6.3 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 There's a race condition that leads to a NULL pointer dereference if you disable quotas while a quota rescan is running. To fix this, we just need to wait for the quota rescan worker to actually exit before tearing down the quota structures. Signed-off-by: Justin Maggard --- fs/btrfs/qgroup.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 75c0249..a7cf504 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -993,9 +993,10 @@ int btrfs_quota_disable(struct btrfs_trans_handle *trans, mutex_lock(&fs_info->qgroup_ioctl_lock); if (!fs_info->quota_root) goto out; - spin_lock(&fs_info->qgroup_lock); fs_info->quota_enabled = 0; fs_info->pending_quota_state = 0; + btrfs_qgroup_wait_for_completion(fs_info); + spin_lock(&fs_info->qgroup_lock); quota_root = fs_info->quota_root; fs_info->quota_root = NULL; fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_ON;