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
33 _scratch_mkfs > /dev/null 2>&1
36 # First test basic snapshotting
37 echo "Creating file foo in root dir"
38 dd if=/dev/zero of=$SCRATCH_MNT/foo bs=1M count=1 &> /dev/null
41 echo "Creating snapshot of root dir"
42 $BTRFS_UTIL_PROG subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/snap | _filter_scratch
43 echo "List root dir after snapshot"
45 echo "List snapshot dir"
47 rm -f $SCRATCH_MNT/foo
48 echo "List root dir after rm of foo"
50 echo "List snapshot dir"
53 # Test creating a normal subvolme
54 $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol | _filter_scratch
55 echo "Listing root dir"
58 ls $SCRATCH_MNT/subvol
60 # Test setting a default mount
61 echo "Creating file bar in subvol"
62 dd if=/dev/zero of=$SCRATCH_MNT/subvol/bar bs=1M count=1 &> /dev/null
63 echo "Setting subvol to the default"
64 subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT subvol)
65 $BTRFS_UTIL_PROG subvolume set-default $subvolid $SCRATCH_MNT | _filter_scratch
67 echo "List root dir which is now subvol"
70 echo "Mounting sbuvolid=0 for the root dir"
71 _scratch_mount "-o subvolid=0"
74 echo "Setting the root dir as the default again"
75 $BTRFS_UTIL_PROG subvolume set-default 0 $SCRATCH_MNT | _filter_scratch
80 # Test listing the subvolumes
81 echo "Listing subvolumes"
82 $BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | awk '{ print $NF }'
85 $BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/snap | _filter_btrfs_subvol_delete