]> git.ipfire.org Git - thirdparty/util-linux.git/blame - tests/ts/mount/fstab-btrfs
tests: enlarge backing file for fstab-btrfs
[thirdparty/util-linux.git] / tests / ts / mount / fstab-btrfs
CommitLineData
c4af75a8
SB
1#!/bin/bash
2
3#
4# Copyright (C) 2016 Stanislav Brabec <sbrabec@suse.cz>
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#
18TS_TOPDIR="${0%/*}/../.."
19TS_DESC="btrfs (fstab)"
20
21. $TS_TOPDIR/functions.sh
22ts_init "$*"
23
24ts_check_test_command "$TS_CMD_MOUNT"
25ts_check_test_command "$TS_CMD_UMOUNT"
26
27ts_skip_nonroot
28ts_check_losetup
29ts_check_prog "mkfs.btrfs"
30ts_check_prog "btrfs"
31
370d31f7 32# btrfs feature check
131e5437
RM
33if ! btrfs inspect-internal --help &>/dev/null || \
34 btrfs inspect-internal rootid bla 2>&1 | grep -q "unknown token"; then
35 ts_skip "btrfs too old"
36fi
370d31f7 37
c4af75a8
SB
38TS_MOUNTPOINT_ANY="$TS_MOUNTPOINT"
39TS_MOUNTPOINT_CREATE="$TS_MOUNTPOINT-create"
40TS_MOUNTPOINT_DEFAULT="$TS_MOUNTPOINT-default"
41TS_MOUNTPOINT_SUBVOL="$TS_MOUNTPOINT-subvol"
42TS_MOUNTPOINT_SUBVOLID="$TS_MOUNTPOINT-subvolid"
43TS_MOUNTPOINT_BIND="$TS_MOUNTPOINT-bind"
44
7e927e1d 45ts_device_init 50
c4af75a8
SB
46DEVICE=$TS_LODEV
47[ -d "$TS_MOUNTPOINT_CREATE" ] || mkdir -p "$TS_MOUNTPOINT_CREATE"
48[ -d "$TS_MOUNTPOINT_DEFAULT" ] || mkdir -p "$TS_MOUNTPOINT_DEFAULT"
49[ -d "$TS_MOUNTPOINT_SUBVOL" ] || mkdir -p "$TS_MOUNTPOINT_SUBVOL"
50[ -d "$TS_MOUNTPOINT_SUBVOLID" ] || mkdir -p "$TS_MOUNTPOINT_SUBVOLID"
51[ -d "$TS_MOUNTPOINT_BIND" ] || mkdir -p "$TS_MOUNTPOINT_BIND"
1c280706 52mkfs.btrfs -d single -m single $DEVICE &> /dev/null || ts_die "Cannot make btrfs on $DEVICE"
c4af75a8
SB
53
54$TS_CMD_MOUNT -o loop "$DEVICE" "$TS_MOUNTPOINT_CREATE"
55pushd . >/dev/null
56cd "$TS_MOUNTPOINT_CREATE"
57mkdir -p d0/dd0/ddd0
58cd ./d0/dd0/ddd0
59touch file{1..5}
60btrfs subvol create s1 >/dev/null
61cd ./s1
62touch file{1..5}
63mkdir bind-point
64mkdir -p d1/dd1/ddd1
65cd ./d1/dd1/ddd1
66btrfs subvol create s2 >/dev/null
131e5437 67DEFAULT_SUBVOLID=$(btrfs inspect-internal rootid s2)
c4af75a8
SB
68btrfs subvol set-default $DEFAULT_SUBVOLID . >/dev/null
69NON_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)
70cd ../../../..
71mkdir -p d2/dd2/ddd2
72cd ./d2/dd2/ddd2
73btrfs subvol create s3 >/dev/null
74mkdir -p s3/bind-mnt
75popd >/dev/null
76NON_DEFAULT_SUBVOL=d0/dd0/ddd0/d2/dd2/ddd2/s3
77$TS_CMD_UMOUNT "$TS_MOUNTPOINT_CREATE"
78
79
80ts_init_subtest "btrfs"
e140506a
KZ
81ts_fstab_lock
82ts_fstab_open
c4af75a8
SB
83# Tests with fs == btrfs
84# mounting default subvolume, deep in the structure, without entry in fstab
e140506a 85ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_DEFAULT" "btrfs" ""
c4af75a8 86# mounting default subvolume, deep in the structure
e140506a 87ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_SUBVOL" "btrfs" "subvol=$NON_DEFAULT_SUBVOL"
c4af75a8 88# mounting non-default subvolume
e140506a 89ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_SUBVOLID" "btrfs" "subvolid=$NON_DEFAULT_SUBVOLID"
c4af75a8 90# test bind mount pointing to subvolume root
e140506a
KZ
91ts_fstab_addline "$TS_MOUNTPOINT_SUBVOLID" "$TS_MOUNTPOINT_BIND" "auto" "bind"
92ts_fstab_close
c4af75a8 93
b59c3bf2
SB
94$TS_CMD_MOUNT -a >> $TS_OUTPUT 2>&1
95$TS_CMD_MOUNT -a >> $TS_OUTPUT 2>&1
c4af75a8 96
b59c3bf2
SB
97$TS_CMD_UMOUNT "$TS_MOUNTPOINT_BIND" >> $TS_OUTPUT 2>&1
98$TS_CMD_UMOUNT "$TS_MOUNTPOINT_DEFAULT" >> $TS_OUTPUT 2>&1
99$TS_CMD_UMOUNT "$TS_MOUNTPOINT_SUBVOL" >> $TS_OUTPUT 2>&1
100$TS_CMD_UMOUNT "$TS_MOUNTPOINT_SUBVOLID" >> $TS_OUTPUT 2>&1
c4af75a8
SB
101
102# check that everything was unmounted
b59c3bf2 103$TS_CMD_MOUNT | grep "$TS_MOUNTPOINT_ANY" >> $TS_OUTPUT 2>&1
c4af75a8 104
e140506a 105ts_fstab_clean # this unlock too
c4af75a8
SB
106ts_log "Success"
107ts_finalize_subtest
108
e140506a 109
c4af75a8 110ts_init_subtest "auto"
e140506a
KZ
111ts_fstab_lock
112ts_fstab_open
c4af75a8
SB
113# Tests with fs == auto
114# mounting default subvolume, deep in the structure, without entry in fstab
e140506a 115ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_DEFAULT" "auto" ""
c4af75a8 116# mounting default subvolume, deep in the structure
e140506a 117ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_SUBVOL" "auto" "subvol=$NON_DEFAULT_SUBVOL"
c4af75a8 118# mounting non-default subvolume
e140506a 119ts_fstab_addline "$DEVICE" "$TS_MOUNTPOINT_SUBVOLID" "auto" "subvolid=$NON_DEFAULT_SUBVOLID"
c4af75a8 120# test bind mount pointing to subvolume sub-directory
e140506a
KZ
121ts_fstab_addline "$TS_MOUNTPOINT_SUBVOL/bind-mnt" "$TS_MOUNTPOINT_BIND" "auto" "bind"
122ts_fstab_close
c4af75a8 123
b59c3bf2
SB
124$TS_CMD_MOUNT -a >> $TS_OUTPUT 2>&1
125$TS_CMD_MOUNT -a >> $TS_OUTPUT 2>&1
c4af75a8 126
b59c3bf2
SB
127$TS_CMD_UMOUNT "$TS_MOUNTPOINT_BIND" >> $TS_OUTPUT 2>&1
128$TS_CMD_UMOUNT "$TS_MOUNTPOINT_DEFAULT" >> $TS_OUTPUT 2>&1
129$TS_CMD_UMOUNT "$TS_MOUNTPOINT_SUBVOL" >> $TS_OUTPUT 2>&1
130$TS_CMD_UMOUNT "$TS_MOUNTPOINT_SUBVOLID" >> $TS_OUTPUT 2>&1
c4af75a8
SB
131
132# check that everything was unmounted
b59c3bf2 133$TS_CMD_MOUNT | grep "$TS_MOUNTPOINT_ANY" >> $TS_OUTPUT 2>&1
c4af75a8 134
e140506a 135ts_fstab_clean # this unlock too
c4af75a8
SB
136ts_log "Success"
137ts_finalize_subtest
138
139
140ts_finalize
141