From patchwork Wed Nov 4 23:56:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Maggard X-Patchwork-Id: 7556081 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 01BD19F327 for ; Wed, 4 Nov 2015 23:56:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1FA37207F0 for ; Wed, 4 Nov 2015 23:56:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B5117207DF for ; Wed, 4 Nov 2015 23:56:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031169AbbKDX4Y (ORCPT ); Wed, 4 Nov 2015 18:56:24 -0500 Received: from mail-pa0-f54.google.com ([209.85.220.54]:36818 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030573AbbKDX4X (ORCPT ); Wed, 4 Nov 2015 18:56:23 -0500 Received: by pacdm15 with SMTP id dm15so43022535pac.3 for ; Wed, 04 Nov 2015 15:56:22 -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=tUvq48K/c3n7jLH1Cb4/w30Vs+WJBHmvo5SNzNTV4nc=; b=BvBbLZ2ev2DQLWLSiHvotTpka4ihknFx9ybnAzRRFbb7tC7REj2LXrdHFlj4T/XM3w 6KS4dTH6PTtMYpLiQoobNUPaSd2jUyYRR3mUXpf/I6fOYLefcaBB98QpitRTRcyGUET+ 1akvy8UJ2XiKWpbUgw2CO6D0qIjTRgBp1HzL4iu+1RtFT/C90l25Ua4VGXyC9F6axS4e nBAGUEiLVpU61uTLngujotN5syOtFBIBtanKm5XmtjRUnE+pecw5ZdRgCwBpM9bQs0Ms YLOVSIlhsWtSUF3JvmsMIW61yXesoDJO2vMqYp6Zyi2zb4yGih+Yhq7h4+YQpksAwGnF b3YQ== X-Received: by 10.66.254.73 with SMTP id ag9mr5500870pad.116.1446681382446; Wed, 04 Nov 2015 15:56:22 -0800 (PST) Received: from jmaggard-ThinkPad-W520.infrant-6.com ([209.249.181.1]) by smtp.gmail.com with ESMTPSA id ph8sm4194145pbc.8.2015.11.04.15.56.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Nov 2015 15:56:22 -0800 (PST) From: Justin Maggard X-Google-Original-From: Justin Maggard To: linux-btrfs@vger.kernel.org Cc: fdmanana@gmail.com, Justin Maggard Subject: [PATCH v3] btrfs: qgroup: exit the rescan worker during umount Date: Wed, 4 Nov 2015 15:56:16 -0800 Message-Id: <1446681376-24583-1-git-send-email-jmaggard@netgear.com> X-Mailer: git-send-email 2.6.2 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 I was hitting a consistent NULL pointer dereference during shutdown that showed the trace running through end_workqueue_bio(). I traced it back to the endio_meta_workers workqueue being poked after it had already been destroyed. Eventually I found that the root cause was a qgroup rescan that was still in progress while we were stopping all the btrfs workers. Currently we explicitly pause balance and scrub operations in close_ctree(), but we do nothing to stop the qgroup rescan. We should probably be doing the same for qgroup rescan, but that's a much larger change. This small change is good enough to allow me to unmount without crashing. v3: avoid more races by calling btrfs_qgroup_wait_for_completion() Signed-off-by: Justin Maggard Reviewed-by: Filipe Manana --- fs/btrfs/disk-io.c | 3 +++ fs/btrfs/qgroup.c | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 2d46675..1eb0839 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3780,6 +3780,9 @@ void close_ctree(struct btrfs_root *root) fs_info->closing = 1; smp_mb(); + /* wait for the qgroup rescan worker to stop */ + btrfs_qgroup_wait_for_completion(fs_info); + /* wait for the uuid_scan task to finish */ down(&fs_info->uuid_tree_rescan_sem); /* avoid complains from lockdep et al., set sem back to initial state */ diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 46476c2..75c0249 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -2286,7 +2286,7 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work) goto out; err = 0; - while (!err) { + while (!err && !btrfs_fs_closing(fs_info)) { trans = btrfs_start_transaction(fs_info->fs_root, 0); if (IS_ERR(trans)) { err = PTR_ERR(trans); @@ -2307,7 +2307,8 @@ out: btrfs_free_path(path); mutex_lock(&fs_info->qgroup_rescan_lock); - fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN; + if (!btrfs_fs_closing(fs_info)) + fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN; if (err > 0 && fs_info->qgroup_flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT) { @@ -2336,7 +2337,9 @@ out: } btrfs_end_transaction(trans, fs_info->quota_root); - if (err >= 0) { + if (btrfs_fs_closing(fs_info)) { + btrfs_info(fs_info, "qgroup scan paused"); + } else if (err >= 0) { btrfs_info(fs_info, "qgroup scan completed%s", err > 0 ? " (inconsistency flag cleared)" : ""); } else {