3edbb25a72a8b353c7c95b6e7f3caf04a0644fe1
[xfstests-dev.git] / tests / btrfs / 006
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/006
6 #
7 # run basic btrfs information commands in various ways
8 # sanity tests: filesystem show, label, sync, and device stats
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "== QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21     cd /
22     rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter.btrfs
28
29 # real QA test starts here
30
31 # Modify as appropriate.
32 _supported_fs btrfs
33 _supported_os Linux
34 _require_scratch
35 _require_scratch_dev_pool
36
37 rm -f $seqres.full
38
39 FIRST_POOL_DEV=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
40 LAST_POOL_DEV=`echo $SCRATCH_DEV_POOL | awk '{print $NF}'`
41 TOTAL_DEVS=`echo $SCRATCH_DEV_POOL | wc -w`
42 LABEL=TestLabel.$seq
43
44 echo "Scratch $SCRATCH_DEV First $FIRST_POOL_DEV last $LAST_POOL_DEV Total $TOTAL_DEVS" > $seqres.full
45
46 _scratch_pool_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
47
48 # These have to be done unmounted...?
49 echo "== Set filesystem label to $LABEL"
50 $BTRFS_UTIL_PROG filesystem label $SCRATCH_DEV $LABEL
51 echo "== Get filesystem label"
52 $BTRFS_UTIL_PROG filesystem label $SCRATCH_DEV
53
54 echo "== Mount."
55 _scratch_mount
56
57 echo "== Show filesystem by label"
58 $BTRFS_UTIL_PROG filesystem show $LABEL | _filter_btrfs_filesystem_show $TOTAL_DEVS
59 UUID=`$BTRFS_UTIL_PROG filesystem show $LABEL | grep uuid: | awk '{print $NF}'`
60
61 echo "UUID $UUID" >> $seqres.full
62
63 echo "== Show filesystem by UUID"
64 $BTRFS_UTIL_PROG filesystem show $UUID | _filter_btrfs_filesystem_show $TOTAL_DEVS $UUID
65
66 echo "== Sync filesystem"
67 $BTRFS_UTIL_PROG filesystem sync $SCRATCH_MNT > /dev/null
68
69 echo "== Show device stats by mountpoint"
70 $BTRFS_UTIL_PROG device stats $SCRATCH_MNT | \
71     _filter_btrfs_device_stats $TOTAL_DEVS | \
72     _filter_spaces
73 echo "== Show device stats by first/scratch dev"
74 $BTRFS_UTIL_PROG device stats $SCRATCH_DEV | \
75     _filter_btrfs_device_stats | \
76     _filter_spaces
77 echo "== Show device stats by second dev"
78 $BTRFS_UTIL_PROG device stats $FIRST_POOL_DEV | \
79     sed -e "s,$FIRST_POOL_DEV,FIRST_POOL_DEV,g" | \
80     _filter_spaces
81 echo "== Show device stats by last dev"
82 $BTRFS_UTIL_PROG device stats $LAST_POOL_DEV | \
83     sed -e "s,$LAST_POOL_DEV,LAST_POOL_DEV,g" | \
84     _filter_spaces
85
86 # success, all done
87 status=0
88 exit