2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2011 Red Hat. All Rights Reserved.
5 # FS QA Test No. btrfs/001
7 # Test btrfs's subvolume and snapshot support
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
22 trap "_cleanup ; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
27 . ./common/filter.btrfs
29 # real QA test starts here
34 _scratch_mkfs > /dev/null 2>&1
37 # First test basic snapshotting
38 echo "Creating file foo in root dir"
39 dd if=/dev/zero of=$SCRATCH_MNT/foo bs=1M count=1 &> /dev/null
42 echo "Creating snapshot of root dir"
43 $BTRFS_UTIL_PROG subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/snap | _filter_scratch
44 echo "List root dir after snapshot"
46 echo "List snapshot dir"
48 rm -f $SCRATCH_MNT/foo
49 echo "List root dir after rm of foo"
51 echo "List snapshot dir"
54 # Test creating a normal subvolme
55 $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol | _filter_scratch
56 echo "Listing root dir"
59 ls $SCRATCH_MNT/subvol
61 # Test setting a default mount
62 echo "Creating file bar in subvol"
63 dd if=/dev/zero of=$SCRATCH_MNT/subvol/bar bs=1M count=1 &> /dev/null
64 echo "Setting subvol to the default"
65 subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT subvol)
66 $BTRFS_UTIL_PROG subvolume set-default $subvolid $SCRATCH_MNT | _filter_scratch
68 echo "List root dir which is now subvol"
71 echo "Mounting sbuvolid=0 for the root dir"
72 _scratch_mount "-o subvolid=0"
75 echo "Setting the root dir as the default again"
76 $BTRFS_UTIL_PROG subvolume set-default 0 $SCRATCH_MNT | _filter_scratch
81 # Test listing the subvolumes
82 echo "Listing subvolumes"
83 $BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | awk '{ print $NF }'
86 $BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/snap | _filter_btrfs_subvol_delete