btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / btrfs / 175
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Facebook.  All Rights Reserved.
4 #
5 # FS QA Test 175
6 #
7 # Test swap file activation on multiple devices.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 . ./common/rc
25 . ./common/filter
26
27 rm -f $seqres.full
28
29 _supported_fs btrfs
30 _require_scratch_dev_pool 2
31 _require_scratch_swapfile
32
33 cycle_swapfile() {
34         local sz=${1:-$(($(get_page_size) * 10))}
35         _format_swapfile "$SCRATCH_MNT/swap" "$sz"
36         swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
37         swapoff "$SCRATCH_MNT/swap" > /dev/null 2>&1
38 }
39
40 echo "RAID 1"
41 _scratch_pool_mkfs -d raid1 -m raid1 >> $seqres.full 2>&1
42 _scratch_mount
43 cycle_swapfile
44 _scratch_unmount
45
46 echo "DUP"
47 _scratch_pool_mkfs -d dup -m dup >> $seqres.full 2>&1
48 _scratch_mount
49 cycle_swapfile
50 _scratch_unmount
51
52 echo "Single on multiple devices"
53 _scratch_pool_mkfs -d single -m raid1 -b $((1024 * 1024 * 1024)) >> $seqres.full 2>&1
54 _scratch_mount
55 # Each device is only 1 GB, so 1.5 GB must be split across multiple devices.
56 cycle_swapfile $((3 * 1024 * 1024 * 1024 / 2))
57 _scratch_unmount
58
59 echo "Single on one device"
60 _scratch_mkfs >> $seqres.full 2>&1
61 _scratch_mount
62 # Create the swap file, then add the device. That way we know it's all on one
63 # device.
64 _format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10))
65 scratch_dev2="$(echo "${SCRATCH_DEV_POOL}" | awk '{ print $2 }')"
66 $BTRFS_UTIL_PROG device add -f "$scratch_dev2" "$SCRATCH_MNT"
67 swapon "$SCRATCH_MNT/swap" 2>&1 | _filter_scratch
68 swapoff "$SCRATCH_MNT/swap" > /dev/null 2>&1
69
70 status=0
71 exit