From patchwork Tue Aug 16 18:30:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Mahoney X-Patchwork-Id: 9284413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D60596086A for ; Tue, 16 Aug 2016 18:43:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9FDC28805 for ; Tue, 16 Aug 2016 18:43:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BE7F42884D; Tue, 16 Aug 2016 18:43:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C85528805 for ; Tue, 16 Aug 2016 18:43:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752736AbcHPSnq (ORCPT ); Tue, 16 Aug 2016 14:43:46 -0400 Received: from mx2.suse.de ([195.135.220.15]:47103 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751266AbcHPSno (ORCPT ); Tue, 16 Aug 2016 14:43:44 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 031C9ABEF; Tue, 16 Aug 2016 18:30:25 +0000 (UTC) To: linux-btrfs , fstests@vger.kernel.org Cc: Qu Wenruo From: Jeff Mahoney Subject: [PATCH 2/2] btrfs/132: test for crash if btrfs quota disable is killed while waiting on rescan Message-ID: <86c01c58-09df-178b-10de-dc4fc822bb55@suse.com> Date: Tue, 16 Aug 2016 14:30:22 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There was a bug in btrfs where the wait for completion of the qgroup rescan worker could be interrupted, resulting in a crash in the rescan worker when the quota root goes away. It is possible to interrupt the wait during file system umount as well, but effectively impossible to test. The umount generally succeeds safely anyway due to other synchronization points. This issue is resolved by the following patch for the Linux kernel: "btrfs: waiting on qgroup rescan should not always be interruptible" Signed-off-by: Jeff Mahoney --- tests/btrfs/132 | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/132.out | 1 + tests/btrfs/group | 1 + 3 files changed, 103 insertions(+) create mode 100755 tests/btrfs/132 create mode 100644 tests/btrfs/132.out diff --git a/tests/btrfs/132 b/tests/btrfs/132 new file mode 100755 index 0000000..3929afa --- /dev/null +++ b/tests/btrfs/132 @@ -0,0 +1,101 @@ +#! /bin/bash +# FS QA Test 132 +# +# Test for race with signal being received in btrfs_qgroup_disable and +# the qgroup rescan worker. The failure case is a crash due to the quota +# root being released prematurely. +# +#----------------------------------------------------------------------- +# Copyright (c) 2016 SUSE. All Rights Reserved. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#----------------------------------------------------------------------- +# + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux + +# We'll exit with a quota rescan paused +_require_scratch_nocheck + +_require_btrfs +BTRFS_DEBUG_TREE_PROG="`set_prog_path btrfs-debug-tree`" +_require_command "$BTRFS_DEBUG_TREE_PROG" btrfs-debug-tree + +rm -f $seqres.full + +_scratch_mkfs >>$seqres.full 2>&1 +_scratch_mount +cp -aR /lib/modules/$(uname -r) $SCRATCH_MNT + +# A qgroup rescan on an empty or small file system completes nearly +# immediately. We need to ensure that it runs long enough that it will +# be running when the disable ioctl executes. Snapshots slow down the +# rescan so we should see the race without a lot of data. This is an +# arbitrary number that works on a ramdisk so it should be sufficient +# for any storage. +for n in $(seq 1 100); do + _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/$n +done + +sync +_run_btrfs_util_prog quota enable $SCRATCH_MNT + +# _run_btrfs_util_prog runs the command in a subshell +# so jobs -p and $! don't work +$BTRFS_UTIL_PROG quota disable $SCRATCH_MNT & + +# This is arbitrary as well but worked for me. The goal is to let the +# command get into the umount syscall before calling kill but not so far +# into it that we've already waited for the rescan worker to complete. +usleep 10000 +jobs=$(jobs -p) +if kill -0 $jobs 2> /dev/null; then + kill -KILL $jobs +else + echo "quota disable command exited too quickly" +fi + +# wait will output the Killed message, so silence that +wait 2> /dev/null +_scratch_unmount + +# success, all done +status=0 +exit diff --git a/tests/btrfs/132.out b/tests/btrfs/132.out new file mode 100644 index 0000000..06c1d19 --- /dev/null +++ b/tests/btrfs/132.out @@ -0,0 +1 @@ +QA output created by 132 diff --git a/tests/btrfs/group b/tests/btrfs/group index 929fa21..c4e880a 100644 --- a/tests/btrfs/group +++ b/tests/btrfs/group @@ -134,3 +134,4 @@ 129 auto quick send 130 auto clone send 131 auto quick qgroup +132 auto quick qgroup