From patchwork Mon Mar 21 16:24:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Rajendra X-Patchwork-Id: 8634251 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 910CEC0553 for ; Mon, 21 Mar 2016 16:25:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 78C602034C for ; Mon, 21 Mar 2016 16:25:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 93B9320220 for ; Mon, 21 Mar 2016 16:25:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756107AbcCUQZE (ORCPT ); Mon, 21 Mar 2016 12:25:04 -0400 Received: from e23smtp01.au.ibm.com ([202.81.31.143]:35030 "EHLO e23smtp01.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756299AbcCUQZC (ORCPT ); Mon, 21 Mar 2016 12:25:02 -0400 Received: from localhost by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 22 Mar 2016 02:24:59 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp01.au.ibm.com (202.81.31.207) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 22 Mar 2016 02:24:56 +1000 X-IBM-Helo: d23dlp03.au.ibm.com X-IBM-MailFrom: chandan@linux.vnet.ibm.com X-IBM-RcptTo: fstests@vger.kernel.org;linux-btrfs@vger.kernel.org Received: from d23relay10.au.ibm.com (d23relay10.au.ibm.com [9.190.26.77]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 3EC703578052; Tue, 22 Mar 2016 03:24:56 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u2LGOm4g59703498; Tue, 22 Mar 2016 03:24:56 +1100 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u2LGONWC002151; Tue, 22 Mar 2016 03:24:23 +1100 Received: from localhost.in.ibm.com ([9.124.223.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u2LGOLcE001984; Tue, 22 Mar 2016 03:24:21 +1100 From: Chandan Rajendra To: fstests@vger.kernel.org Cc: Chandan Rajendra , linux-btrfs@vger.kernel.org, chandan@mykolab.com, eguan@redhat.com Subject: [PATCH V3] _btrfs_stress_subvolume: Fix race condition by making 'subvolume stress' task to exit gracefully Date: Mon, 21 Mar 2016 21:54:03 +0530 Message-Id: <1458577443-2334-1-git-send-email-chandan@linux.vnet.ibm.com> X-Mailer: git-send-email 2.1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16032116-1618-0000-0000-000045178E4D 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 The following scenario can occur when running btrfs/066, Task A Task B Task C run_test() - Execute _btrfs_stress_subvolume() in a background shell. _btrfs_stress_subvolme() ... - fork & exec "mount" Mount subvolume on directory in $TEST_DIR - Wait for fsstress to finish do_mount() - kill shell process executing - btrfs_mount() _btrfs_stress_subvolume() i.e. Task B. - Init process becomes the parent of "subvolume mount" task i.e. Task C. - In case subvolume is mounted (which is not the case), unmount it. - Complete mounting subvolume Hence on the completion of one iteration of run_test(), the subvolume created inside the filesystem on $SCRATCH_DEV continues to be mounted on $TEST_DIR/$seq.mnt. Subsequent invocations of run_test() (called for remaining Btrfs profile configs) fail during _scratch_pool_mkfs. Instead of killing the 'subvolume stress' task this commit makes _btrfs_stress_subvolume() to break out of the loop when a file exists on the filesystem. The commit also makes relevant changes to other users of _btrfs_stress_subvolume() i.e. btrfs/060, btrfs/065, btrfs/067 & btrfs/068. Suggested-by: Eryu Guan Reviewed-by: Eryu Guan Signed-off-by: Chandan Rajendra --- Changelog: V2->V3: Use the correct argument value as the 'stop file' name in _btrfs_stress_subvolume(). I had forgotten to pull the changes from my github repo and hence had sent out the incorrect patch. V1->V2: Instead of named pipes, Use a file to let 'subvolume stress' task know that it should break from the while loop. common/rc | 3 ++- tests/btrfs/060 | 8 ++++++-- tests/btrfs/065 | 8 ++++++-- tests/btrfs/066 | 8 ++++++-- tests/btrfs/067 | 8 ++++++-- tests/btrfs/068 | 8 ++++++-- 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/common/rc b/common/rc index 16f5a43..886625c 100644 --- a/common/rc +++ b/common/rc @@ -3280,9 +3280,10 @@ _btrfs_stress_subvolume() local btrfs_mnt=$2 local subvol_name=$3 local subvol_mnt=$4 + local stop_file=$5 mkdir -p $subvol_mnt - while true; do + while [ ! -e $stop_file ]; do $BTRFS_UTIL_PROG subvolume create $btrfs_mnt/$subvol_name $MOUNT_PROG -o subvol=$subvol_name $btrfs_dev $subvol_mnt $UMOUNT_PROG $subvol_mnt diff --git a/tests/btrfs/060 b/tests/btrfs/060 index 8ef0e7f..6b6a480 100755 --- a/tests/btrfs/060 +++ b/tests/btrfs/060 @@ -56,6 +56,7 @@ run_test() { local mkfs_opts=$1 local subvol_mnt=$TEST_DIR/$seq.mnt + local stop_file=$TEST_DIR/$seq.stop.$$ echo "Test $mkfs_opts" >>$seqres.full @@ -77,15 +78,18 @@ run_test() balance_pid=$! echo "$balance_pid" >>$seqres.full + # make sure the stop sign is not there + rm -f $stop_file echo -n "Start subvolume worker: " >>$seqres.full - _btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt >/dev/null 2>&1 & + _btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 & subvol_pid=$! echo "$subvol_pid" >>$seqres.full echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full wait $fsstress_pid - kill $balance_pid $subvol_pid + touch $stop_file + kill $balance_pid wait # wait for the balance operation to finish while ps aux | grep "balance start" | grep -qv grep; do diff --git a/tests/btrfs/065 b/tests/btrfs/065 index 7d8249b..a4afe73 100755 --- a/tests/btrfs/065 +++ b/tests/btrfs/065 @@ -58,6 +58,7 @@ run_test() local mkfs_opts=$1 local saved_scratch_dev_pool=$SCRATCH_DEV_POOL local subvol_mnt=$TEST_DIR/$seq.mnt + local stop_file=$TEST_DIR/$seq.stop.$$ echo "Test $mkfs_opts" >>$seqres.full @@ -80,8 +81,10 @@ run_test() $FSSTRESS_PROG $args >/dev/null 2>&1 & fsstress_pid=$! + # make sure the stop sign is not there + rm -f $stop_file echo -n "Start subvolume worker: " >>$seqres.full - _btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt >/dev/null 2>&1 & + _btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 & subvol_pid=$! echo "$subvol_pid" >>$seqres.full @@ -93,7 +96,8 @@ run_test() echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full wait $fsstress_pid - kill $subvol_pid $replace_pid + touch $stop_file + kill $replace_pid wait # wait for the replace operation to finish while ps aux | grep "replace start" | grep -qv grep; do diff --git a/tests/btrfs/066 b/tests/btrfs/066 index 2d9a1d2..cf4dd0d 100755 --- a/tests/btrfs/066 +++ b/tests/btrfs/066 @@ -56,6 +56,7 @@ run_test() { local mkfs_opts=$1 local subvol_mnt=$TEST_DIR/$seq.mnt + local stop_file=$TEST_DIR/$seq.stop.$$ echo "Test $mkfs_opts" >>$seqres.full @@ -72,8 +73,10 @@ run_test() $FSSTRESS_PROG $args >/dev/null 2>&1 & fsstress_pid=$! + # make sure the stop sign is not there + rm -f $stop_file echo -n "Start subvolume worker: " >>$seqres.full - _btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt >/dev/null 2>&1 & + _btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 & subvol_pid=$! echo "$subvol_pid" >>$seqres.full @@ -85,7 +88,8 @@ run_test() echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full wait $fsstress_pid - kill $subvol_pid $scrub_pid + touch $stop_file + kill $scrub_pid wait # wait for the scrub operation to finish while ps aux | grep "scrub start" | grep -qv grep; do diff --git a/tests/btrfs/067 b/tests/btrfs/067 index 2c1e284..b76f5ec 100755 --- a/tests/btrfs/067 +++ b/tests/btrfs/067 @@ -57,6 +57,7 @@ run_test() local mkfs_opts=$1 local with_compress=$2 local subvol_mnt=$TEST_DIR/$seq.mnt + local stop_file=$TEST_DIR/$seq.stop.$$ echo "Test $mkfs_opts with $with_compress" >>$seqres.full @@ -73,8 +74,10 @@ run_test() $FSSTRESS_PROG $args >/dev/null 2>&1 & fsstress_pid=$! + # make sure the stop sign is not there + rm -f $stop_file echo -n "Start subvolume worker: " >>$seqres.full - _btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt >/dev/null 2>&1 & + _btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 & subvol_pid=$! echo "$subvol_pid" >>$seqres.full @@ -86,7 +89,8 @@ run_test() echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full wait $fsstress_pid - kill $subvol_pid $defrag_pid + touch $stop_file + kill $defrag_pid wait # wait for btrfs defrag process to exit, otherwise it will block umount while ps aux | grep "btrfs filesystem defrag" | grep -qv grep; do diff --git a/tests/btrfs/068 b/tests/btrfs/068 index 3126ec2..534aee6 100755 --- a/tests/btrfs/068 +++ b/tests/btrfs/068 @@ -57,6 +57,7 @@ run_test() { local mkfs_opts=$1 local subvol_mnt=$TEST_DIR/$seq.mnt + local stop_file=$TEST_DIR/$seq.stop.$$ echo "Test $mkfs_opts with $with_compress" >>$seqres.full @@ -73,8 +74,10 @@ run_test() $FSSTRESS_PROG $args >/dev/null 2>&1 & fsstress_pid=$! + # make sure the stop sign is not there + rm -f $stop_file echo -n "Start subvolume worker: " >>$seqres.full - _btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt >/dev/null 2>&1 & + _btrfs_stress_subvolume $SCRATCH_DEV $SCRATCH_MNT subvol_$$ $subvol_mnt $stop_file >/dev/null 2>&1 & subvol_pid=$! echo "$subvol_pid" >>$seqres.full @@ -86,7 +89,8 @@ run_test() echo "Wait for fsstress to exit and kill all background workers" >>$seqres.full wait $fsstress_pid - kill $subvol_pid $remount_pid + touch $stop_file + kill $remount_pid wait # wait for the remount loop process to finish while ps aux | grep "mount.*$SCRATCH_MNT" | grep -qv grep; do