btrfs/079: fix failure to umount scratch fs due to running filefrag process
[xfstests-dev.git] / tests / btrfs / 079
index ed4eb727ee2b9c50b58d987b2e07981dff56149c..1e9411be79ed7c32d92e83c4a046cecd0177d3c3 100755 (executable)
@@ -1,4 +1,7 @@
 #! /bin/bash
 #! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2014 Fujitsu All Rights Reserved.
+#
 # FS QA Test No. btrfs/079
 #
 # Do write along with fiemap ioctl.
 # FS QA Test No. btrfs/079
 #
 # Do write along with fiemap ioctl.
 # btrfs: Fix and enhance merge_extent_mapping() to insert best fitted extent map
 # btrfs: Fix the wrong condition judgment about subset extent map
 #
 # btrfs: Fix and enhance merge_extent_mapping() to insert best fitted extent map
 # btrfs: Fix the wrong condition judgment about subset extent map
 #
-#-----------------------------------------------------------------------
-# Copyright (C) 2014 Fujitsu All Rights Reserved.
-# Author: Qu Wenruo <quwenruo@cn.fujitsu.com>
-#
-# 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"
 seq=`basename $0`
 seqres=$RESULT_DIR/$seq
 echo "QA output created by $seq"
@@ -60,7 +44,7 @@ _supported_os Linux
 _require_scratch
 # Since xfs_io's fiemap always use SYNC flag and can't be unset,
 # we must use filefrag to call fiemap without SYNC flag.
 _require_scratch
 # Since xfs_io's fiemap always use SYNC flag and can't be unset,
 # we must use filefrag to call fiemap without SYNC flag.
-_require_command "/usr/sbin/filefrag" filefrag
+_require_command "$FILEFRAG_PROG" filefrag
 _require_xfs_io_command "falloc"
 
 filesize=$((10 * 1024 * 1024 * 1024)) #10G size
 _require_xfs_io_command "falloc"
 
 filesize=$((10 * 1024 * 1024 * 1024)) #10G size
@@ -93,9 +77,15 @@ _filter_error() {
 }
 
 fiemap_work() {
 }
 
 fiemap_work() {
+       # Wait for any running 'filefrag' subcommand before exitting so that
+       # after the test kills the subshell running this function, it does not
+       # fail with EBUSY when unmounting the scratch device because the filefrag
+       # subcommand is still running with an open file on the scratch fs.
+       trap "wait; exit" SIGTERM
+
        filename=$1
        while true; do
        filename=$1
        while true; do
-               filefrag $filename 2> $tmp.output 1> /dev/null
+               $FILEFRAG_PROG $filename 2> $tmp.output 1> /dev/null
                ret=$?
                err=`cat $tmp.output | _filter_error`
                if [ $ret -ne 0 -o -n "$err" ]; then
                ret=$?
                err=`cat $tmp.output | _filter_error`
                if [ $ret -ne 0 -o -n "$err" ]; then