btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / btrfs / 012
index cbd3882e42746e05e18b34ae447d061f2d30afb2..2d4cece52b8083c72e41de7d11b37a890891cd41 100755 (executable)
@@ -1,4 +1,7 @@
 #! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2013 Red Hat, Inc.  All Rights Reserved.
+#
 # FS QA Test No. 012
 #
 # Test btrfs-convert
 # 5) roll back conversion to original ext4
 # 6) verify rolled-back fs integrity & contents
 #
-#-----------------------------------------------------------------------
-# Copyright (c) 2013 Red Hat, Inc.  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"
@@ -51,19 +36,17 @@ _cleanup()
 
 # Modify as appropriate.
 _supported_fs btrfs
-_supported_os Linux
 _require_scratch_nocheck
 
-BTRFS_CONVERT_PROG="`set_prog_path btrfs-convert`"
-E2FSCK_PROG="`set_prog_path e2fsck`"
-
 _require_command "$BTRFS_CONVERT_PROG" btrfs-convert
 _require_command "$MKFS_EXT4_PROG" mkfs.ext4
 _require_command "$E2FSCK_PROG" e2fsck
 
+_require_fs_space $SCRATCH_MNT $(du -s /lib/modules/`uname -r` | ${AWK_PROG} '{print $1}')
+
 rm -f $seqres.full
 
-BLOCK_SIZE=`get_block_size $TEST_DIR`
+BLOCK_SIZE=`_get_block_size $TEST_DIR`
 
 # Create & populate an ext4 filesystem
 $MKFS_EXT4_PROG -F -b $BLOCK_SIZE $SCRATCH_DEV > $seqres.full 2>&1 || \
@@ -77,7 +60,7 @@ _scratch_unmount
 # Convert it to btrfs, mount it, verify the data
 $BTRFS_CONVERT_PROG $SCRATCH_DEV >> $seqres.full 2>&1 || \
        _fail "btrfs-convert failed"
-_scratch_mount || _fail "Could not mount new btrfs fs"
+_try_scratch_mount || _fail "Could not mount new btrfs fs"
 # (Ignore the symlinks which may be broken/nonexistent)
 diff -r /lib/modules/`uname -r`/ $SCRATCH_MNT/`uname -r`/ 2>&1 | grep -vw "source\|build"
 
@@ -117,7 +100,7 @@ _scratch_unmount
 # Convert it to btrfs, mount it and delete "ext2_saved"
 $BTRFS_CONVERT_PROG $SCRATCH_DEV >> $seqres.full 2>&1 || \
        _fail "btrfs-convert failed"
-_scratch_mount || _fail "Could not mount new btrfs fs"
+_try_scratch_mount || _fail "Could not mount new btrfs fs"
 $BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/ext2_saved >> $seqres.full 2>&1 ||
        _fail "failed to delete ext2_saved subvolume"
 _scratch_unmount