Debian Codegraph @

tests/ts/mount/fstab-btrfs

raw
1 #!/bin/bash
2
3 #
4 # Copyright (C) 2016 Stanislav Brabec <[email protected]>
5 #
6 # This file is part of util-linux.
7 #
8 # This file is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This file is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 TS_TOPDIR="${0%/*}/../.."
19 TS_DESC="btrfs (fstab)"
20
21 . "$TS_TOPDIR"/functions.sh
22 ts_init "$*"
23
24 ts_check_test_command "$TS_CMD_MOUNT"
25 ts_check_test_command "$TS_CMD_UMOUNT"
26
27 ts_skip_nonroot
28 ts_check_losetup
29 ts_check_enotty
30 ts_check_prog "mkfs.btrfs"
31 ts_check_prog "btrfs"
32
33 # btrfs feature check
34 if ! btrfs inspect-internal --help &>/dev/null || \
35 btrfs inspect-internal rootid bla 2>&1 | grep -q "unknown token"; then
36 ts_skip "btrfs too old"
37 fi
38
39 TS_MOUNTPOINT_ANY="$TS_MOUNTPOINT"
40 TS_MOUNTPOINT_CREATE="$TS_MOUNTPOINT-create"
41 TS_MOUNTPOINT_DEFAULT="$TS_MOUNTPOINT-default"
42 TS_MOUNTPOINT_SUBVOL="$TS_MOUNTPOINT-subvol"
43 TS_MOUNTPOINT_SUBVOLID="$TS_MOUNTPOINT-subvolid"
44 TS_MOUNTPOINT_BIND="$TS_MOUNTPOINT-bind"
45
46 ts_device_init 50
47 DEVICE=$TS_LODEV
48 [ -d "$TS_MOUNTPOINT_CREATE" ] || mkdir -p "$TS_MOUNTPOINT_CREATE"
49 [ -d "$TS_MOUNTPOINT_DEFAULT" ] || mkdir -p "$TS_MOUNTPOINT_DEFAULT"
50 [ -d "$TS_MOUNTPOINT_SUBVOL" ] || mkdir -p "$TS_MOUNTPOINT_SUBVOL"
51 [ -d "$TS_MOUNTPOINT_SUBVOLID" ] || mkdir -p "$TS_MOUNTPOINT_SUBVOLID"
52 [ -d "$TS_MOUNTPOINT_BIND" ] || mkdir -p "$TS_MOUNTPOINT_BIND"
53 mkfs.btrfs -d single -m single $DEVICE &> /dev/null || ts_die "Cannot make btrfs on $DEVICE"
54
55 btrfs device ready $DEVICE 2>/dev/null || ts_skip "btrfs kernel support is missing"
56
57 $TS_CMD_MOUNT --options loop "$DEVICE" "$TS_MOUNTPOINT_CREATE" &> /dev/null
58 pushd . >/dev/null
59 cd "$TS_MOUNTPOINT_CREATE"
60 mkdir -p d0/dd0/ddd0
61 cd ./d0/dd0/ddd0
62 touch file{1..5}
63 btrfs subvol create s1 >/dev/null
64 cd ./s1
65 touch file{1..5}
66 mkdir bind-point
67 mkdir -p d1/dd1/ddd1
68 cd ./d1/dd1/ddd1
69 btrfs subvol create s2 >/dev/null
70 DEFAULT_SUBVOLID=$(btrfs inspect-internal rootid s2)
71 btrfs subvol set-default $DEFAULT_SUBVOLID . >/dev/null
72 NON_DEFAULT_SUBVOLID=$(btrfs subvol list "$TS_MOUNTPOINT_CREATE" | while read dummy id rest ; do if test $id = $DEFAULT_SUBVOLID ; then continue ; fi ; echo $id ; done)
73 cd ../../../..
74 mkdir -p d2/dd2/ddd2
75 cd ./d2/dd2/ddd2
76 btrfs subvol create s3 >/dev/null
77 mkdir -p s3/bind-mnt
78 popd >/dev/null
79 NON_DEFAULT_SUBVOL=d0/dd0/ddd0/d2/dd2/ddd2/s3
80 $TS_CMD_UMOUNT "$TS_MOUNTPOINT_CREATE"
81
82
83 ts_init_subtest "btrfs"
84 ts_fstab_lock
85 ts_fstab_open
86 # Tests with fs == btrfs
87 # mounting default subvolume, deep in the structure, without entry in fstab
88 ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_DEFAULT" "btrfs" ""
89 # mounting default subvolume, deep in the structure
90 ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_SUBVOL" "btrfs" "subvol=$NON_DEFAULT_SUBVOL"
91 # mounting non-default subvolume
92 ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_SUBVOLID" "btrfs" "subvolid=$NON_DEFAULT_SUBVOLID"
93 # test bind mount pointing to subvolume root
94 ts_fstab_addline "$TS_MOUNTPOINT_SUBVOLID" "$TS_MOUNTPOINT_BIND" "auto" "bind"
95 ts_fstab_close
96
97 $TS_CMD_MOUNT --fstab "$TS_FSTAB" --all >> $TS_OUTPUT 2>> $TS_ERRLOG
98 $TS_CMD_MOUNT --fstab "$TS_FSTAB" --all >> $TS_OUTPUT 2>> $TS_ERRLOG
99
100 $TS_CMD_UMOUNT "$TS_MOUNTPOINT_BIND" >> $TS_OUTPUT 2>> $TS_ERRLOG
101 $TS_CMD_UMOUNT "$TS_MOUNTPOINT_DEFAULT" >> $TS_OUTPUT 2>> $TS_ERRLOG
102 $TS_CMD_UMOUNT "$TS_MOUNTPOINT_SUBVOL" >> $TS_OUTPUT 2>> $TS_ERRLOG
103 $TS_CMD_UMOUNT "$TS_MOUNTPOINT_SUBVOLID" >> $TS_OUTPUT 2>> $TS_ERRLOG
104
105 # check that everything was unmounted
106 $TS_CMD_MOUNT | grep "$TS_MOUNTPOINT_ANY" >> $TS_OUTPUT 2>> $TS_ERRLOG
107
108 ts_fstab_clean # this unlock too
109 ts_log "Success"
110 ts_finalize_subtest
111
112
113 ts_init_subtest "auto"
114 ts_fstab_lock
115 ts_fstab_open
116 # Tests with fs == auto
117 # mounting default subvolume, deep in the structure, without entry in fstab
118 ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_DEFAULT" "auto" ""
119 # mounting default subvolume, deep in the structure
120 ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_SUBVOL" "auto" "subvol=$NON_DEFAULT_SUBVOL"
121 # mounting non-default subvolume
122 ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_SUBVOLID" "auto" "subvolid=$NON_DEFAULT_SUBVOLID"
123 # test bind mount pointing to subvolume sub-directory
124 ts_fstab_addline "$TS_MOUNTPOINT_SUBVOL/bind-mnt" "$TS_MOUNTPOINT_BIND" "auto" "bind"
125 ts_fstab_close
126
127 $TS_CMD_MOUNT --fstab "$TS_FSTAB" --all >> $TS_OUTPUT 2>> $TS_ERRLOG
128 $TS_CMD_MOUNT --fstab "$TS_FSTAB" --all >> $TS_OUTPUT 2>> $TS_ERRLOG
129
130 $TS_CMD_UMOUNT "$TS_MOUNTPOINT_BIND" >> $TS_OUTPUT 2>> $TS_ERRLOG
131 $TS_CMD_UMOUNT "$TS_MOUNTPOINT_DEFAULT" >> $TS_OUTPUT 2>> $TS_ERRLOG
132 $TS_CMD_UMOUNT "$TS_MOUNTPOINT_SUBVOL" >> $TS_OUTPUT 2>> $TS_ERRLOG
133 $TS_CMD_UMOUNT "$TS_MOUNTPOINT_SUBVOLID" >> $TS_OUTPUT 2>> $TS_ERRLOG
134
135 # check that everything was unmounted
136 $TS_CMD_MOUNT | grep "$TS_MOUNTPOINT_ANY" >> $TS_OUTPUT 2>> $TS_ERRLOG
137
138 ts_fstab_clean # this unlock too
139 ts_log "Success"
140 ts_finalize_subtest
141
142
143 ts_finalize
144