From patchwork Wed Oct 26 09:52:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaoguang Wang X-Patchwork-Id: 9396501 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 65267600BA for ; Wed, 26 Oct 2016 09:58:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DECE29A1F for ; Wed, 26 Oct 2016 09:58:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1299729A92; Wed, 26 Oct 2016 09:58:53 +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 77EBF29A1F for ; Wed, 26 Oct 2016 09:58:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754365AbcJZJ6u (ORCPT ); Wed, 26 Oct 2016 05:58:50 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:14216 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1750720AbcJZJ6r (ORCPT ); Wed, 26 Oct 2016 05:58:47 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="927831" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 26 Oct 2016 17:58:35 +0800 Received: from localhost.localdomain (unknown [10.167.226.107]) by cn.fujitsu.com (Postfix) with ESMTP id 205C04010D17; Wed, 26 Oct 2016 17:58:35 +0800 (CST) From: Wang Xiaoguang To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org Subject: [PATCH v3] generic: make 17[1-4] work well when btrfs compression is enabled Date: Wed, 26 Oct 2016 17:52:11 +0800 Message-Id: <20161026095211.30091-1-wangxg.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.9.0 MIME-Version: 1.0 X-yoursite-MailScanner-ID: 205C04010D17.AFFFE X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: wangxg.fnst@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When enabling btrfs compression, original codes can not fill fs correctly, here we introduce _fill_fs() in common/rc, which'll keep creating and writing files until enospc error occurs. Note _fill_fs is copied from tests/generic/256, but with some minor modifications. Signed-off-by: Wang Xiaoguang --- V2: In common/, I did't find an existing function suitable for these 4 test cases to fill fs, so I still use _pwrite_byte() with a big enough file length fo fill fs. Note, for btrfs, metadata space still is not full, only data space is full, but it's OK for these 4 test cases. All these 4 cases pass in xfs and btrfs(without compression), if btrfs has compression enabled, these 4 cases will fail for false enospc error, I have sent kernel patches to fix this bug. V3: Introduce _fill_fs in common/rc to fill fs. --- common/rc | 50 ++++++++++++++++++++++++++++++++++++++++++ tests/generic/171 | 4 +--- tests/generic/172 | 4 ++-- tests/generic/173 | 4 +--- tests/generic/174 | 4 +--- tests/generic/256 | 65 +++++-------------------------------------------------- 6 files changed, 60 insertions(+), 71 deletions(-) diff --git a/common/rc b/common/rc index 7a9fc90..0e1ac5d 100644 --- a/common/rc +++ b/common/rc @@ -4003,6 +4003,56 @@ _require_xfs_mkfs_without_validation() fi } +# Fill a file system by repeatedly creating files in the given folder +# starting with the given file size. Files are reduced in size when +# they can no longer fit until no more files can be created. +_fill_fs() +{ + local file_size=$1 + local dir=$2 + local block_size=$3 + local switch_user=$4 + local file_count=1 + local bytes_written=0 + + if [ $# -ne 4 ]; then + echo "Usage: _fill_fs filesize dir blocksize" + exit 1 + fi + + if [ $switch_user -eq 0 ]; then + mkdir -p $dir + else + _user_do "mkdir -p $dir" + fi + + if [ $file_size -lt $block_size ]; then + $file_size = $block_size + fi + + while [ $file_size -ge $block_size ]; do + bytes_written=0 + if [ $switch_user -eq 0 ]; then + $XFS_IO_PROG -f -c "pwrite 0 $file_size" \ + $dir/$file_count > /dev/null + else + _user_do "$XFS_IO_PROG -f -c \"pwrite 0 $file_size\" \ + $dir/$file_count > /dev/null" + fi + + if [ -f $dir/$file_count ]; then + bytes_written=$(stat -c '%s' $dir/$file_count) + fi + + # If there was no room to make the file, then divide it in + # half, and keep going + if [ $bytes_written -lt $file_size ]; then + file_size=$((file_size / 2)) + fi + file_count=$((file_count + 1)) + done +} + init_rc ################################################################################ diff --git a/tests/generic/171 b/tests/generic/171 index a69f798..fde8ef2 100755 --- a/tests/generic/171 +++ b/tests/generic/171 @@ -75,9 +75,7 @@ _cp_reflink $testdir/bigfile $testdir/clonefile sync echo "Allocate the rest of the space" -nr_free=$(stat -f -c '%f' $testdir) -touch $testdir/file0 $testdir/file1 -_pwrite_byte 0x61 0 $((blksz * nr_free)) $testdir/eat_my_space >> $seqres.full 2>&1 +_fill_fs $((32 * 1024 * 1024)) $testdir/space $blksz 0 >> $seqres.full 2>&1 sync echo "CoW the big file" diff --git a/tests/generic/172 b/tests/generic/172 index 8192290..3625546 100755 --- a/tests/generic/172 +++ b/tests/generic/172 @@ -57,6 +57,7 @@ testdir=$SCRATCH_MNT/test-$seq mkdir $testdir echo "Reformat with appropriate size" +blksz="$(get_block_size $testdir)" umount $SCRATCH_MNT file_size=$((168 * 1024 * 1024)) @@ -72,8 +73,7 @@ _cp_reflink $testdir/bigfile $testdir/clonefile sync echo "Allocate the rest of the space" -touch $testdir/file0 $testdir/file1 -_pwrite_byte 0x61 0 $fs_size $testdir/eat_my_space >> $seqres.full 2>&1 +_fill_fs $((32 * 1024 * 1024)) $testdir/space $blksz 0 >> $seqres.full 2>&1 sync echo "CoW the big file" diff --git a/tests/generic/173 b/tests/generic/173 index e35597f..3d583b1 100755 --- a/tests/generic/173 +++ b/tests/generic/173 @@ -75,9 +75,7 @@ _cp_reflink $testdir/bigfile $testdir/clonefile sync echo "Allocate the rest of the space" -nr_free=$(stat -f -c '%f' $testdir) -touch $testdir/file0 $testdir/file1 -_pwrite_byte 0x61 0 $((blksz * nr_free)) $testdir/eat_my_space >> $seqres.full 2>&1 +_fill_fs $((32 * 1024 * 1024)) $testdir/space $blksz 0 >> $seqres.full 2>&1 sync echo "mmap CoW the big file" diff --git a/tests/generic/174 b/tests/generic/174 index e58d64b..bd7fc11 100755 --- a/tests/generic/174 +++ b/tests/generic/174 @@ -76,9 +76,7 @@ _cp_reflink $testdir/bigfile $testdir/clonefile sync echo "Allocate the rest of the space" -nr_free=$(stat -f -c '%f' $testdir) -touch $testdir/file0 $testdir/file1 -_pwrite_byte 0x61 0 $((blksz * nr_free)) $testdir/eat_my_space >> $seqres.full 2>&1 +_fill_fs $((32 * 1024 * 1024)) $testdir/space $blksz 0 >> $seqres.full 2>&1 sync echo "CoW the big file" diff --git a/tests/generic/256 b/tests/generic/256 index cfbf790..9488648 100755 --- a/tests/generic/256 +++ b/tests/generic/256 @@ -53,64 +53,6 @@ _require_test testfile=$TEST_DIR/256.$$ -# _fill_fs() -# -# Fills a file system by repeatedly creating files in the given folder -# starting with the given file size. Files are reduced in size when -# they can no longer fit untill no more files can be created. -# -# This routine is used by _test_full_fs_punch to test that a hole may -# still be punched when the disk is full by borrowing reserved blocks. -# All files are created as a non root user to prevent reserved blocks -# from being consumed. -# -_fill_fs() { - local file_size=$1 - local dir=$2 - local block_size=$3 - local file_count=1 - local bytes_written=0 - - if [ $# -ne 3 ] - then - echo "USAGE: _fill_fs filesize dir block size" - exit 1 - fi - - # Creation of files or folders - # must not be done as root or - # reserved blocks will be consumed - _user_do "mkdir -p $dir &> /dev/null" - if [ $? -ne 0 ] ; then - return 0 - fi - - if [ $file_size -lt $block_size ] - then - $file_size = $block_size - fi - - while [ $file_size -ge $block_size ] - do - bytes_written=0 - _user_do "$XFS_IO_PROG -f -c \"pwrite 0 $file_size\" $dir/$file_count.bin &> /dev/null" - - if [ -f $dir/$file_count.bin ] - then - bytes_written=`$XFS_IO_PROG -c "stat" $dir/$file_count.bin | grep stat.size | cut -d ' ' -f3` - fi - - # If there was no room to make the file, - # then divide it in half, and keep going - if [ $bytes_written -lt $file_size ] - then - file_size=$(( $file_size / 2 )) - fi - file_count=$(( $file_count + 1 )) - - done -} - # _test_full_fs_punch() # # This function will test that a hole may be punched @@ -144,7 +86,10 @@ _test_full_fs_punch() -c "fsync" $file_name &> /dev/null chmod 666 $file_name - _fill_fs $(( 1024 * 1024 * 1024 )) $path/fill $block_size + # All files are created as a non root user to prevent reserved blocks + # from being consumed. + _fill_fs $(( 1024 * 1024 * 1024 )) $path/fill $block_size 1 \ + > /dev/null 2>&1 for (( i=0; i<$iterations; i++ )) do @@ -159,7 +104,7 @@ _test_full_fs_punch() hole_offset=$(( $hole_offset + $hole_len + $hole_interval )) - _fill_fs $hole_len $path/fill.$i $block_size + _fill_fs $hole_len $path/fill.$i $block_size 1 > /dev/null 2>&1 done }