]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_remount.ksh
Always wait for txg sync when umounting dataset
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zfs_mount / zfs_mount_remount.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22
23 #
24 # Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
25 #
26
27 . $STF_SUITE/include/libtest.shlib
28 . $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
29
30 #
31 # DESCRIPTION:
32 # Verify remount functionality, expecially on readonly objects.
33 #
34 # STRATEGY:
35 # 1. Prepare a filesystem and a snapshot
36 # 2. Verify we can (re)mount the dataset readonly/read-write
37 # 3. Verify we can mount the snapshot and it's mounted readonly
38 # 4. Verify we can't remount it read-write
39 # 5. Verify we can remount a dataset readonly and unmount it with
40 # encryption=on and sync=disabled (issue #7753)
41 # 6. Re-import the pool readonly
42 # 7. Verify we can't remount its filesystem read-write
43 #
44
45 verify_runnable "both"
46
47 function cleanup
48 {
49 log_must_busy zpool export $TESTPOOL
50 log_must zpool import $TESTPOOL
51 snapexists $TESTSNAP && log_must zfs destroy $TESTSNAP
52 [[ -d $MNTPSNAP ]] && log_must rmdir $MNTPSNAP
53 return 0
54 }
55
56 #
57 # Verify the $filesystem is mounted readonly
58 # This is preferred over "log_mustnot touch $fs" because we actually want to
59 # verify the error returned is EROFS
60 #
61 function readonlyfs # filesystem
62 {
63 typeset filesystem="$1"
64
65 file_write -o create -f $filesystem/file.dat
66 ret=$?
67 if [[ $ret != 30 ]]; then
68 log_fail "Writing to $filesystem did not return EROFS ($ret)."
69 fi
70 }
71
72 #
73 # Verify $dataset is mounted with $option
74 #
75 function checkmount # dataset option
76 {
77 typeset dataset="$1"
78 typeset option="$2"
79
80 options="$(awk -v ds="$dataset" '$1 == ds { print $4 }' /proc/mounts)"
81 if [[ "$options" == '' ]]; then
82 log_fail "Dataset $dataset is not mounted"
83 elif [[ ! -z "${options##*$option*}" ]]; then
84 log_fail "Dataset $dataset is not mounted with expected "\
85 "option $option ($options)"
86 else
87 log_note "Dataset $dataset is mounted with option $option"
88 fi
89 }
90
91 log_assert "Verify remount functionality on both filesystem and snapshots"
92
93 log_onexit cleanup
94
95 # 1. Prepare a filesystem and a snapshot
96 TESTFS=$TESTPOOL/$TESTFS
97 TESTSNAP="$TESTFS@snap"
98 datasetexists $TESTFS || log_must zfs create $TESTFS
99 snapexists $TESTSNAP || log_must zfs snapshot $TESTSNAP
100 log_must zfs set readonly=off $TESTFS
101 MNTPFS="$(get_prop mountpoint $TESTFS)"
102 MNTPSNAP="$TESTDIR/zfs_snap_mount"
103 log_must mkdir -p $MNTPSNAP
104
105 # 2. Verify we can (re)mount the dataset readonly/read-write
106 log_must touch $MNTPFS/file.dat
107 checkmount $TESTFS 'rw'
108 log_must mount -o remount,ro $TESTFS $MNTPFS
109 readonlyfs $MNTPFS
110 checkmount $TESTFS 'ro'
111 log_must mount -o remount,rw $TESTFS $MNTPFS
112 log_must touch $MNTPFS/file.dat
113 checkmount $TESTFS 'rw'
114
115 # 3. Verify we can (re)mount the snapshot readonly
116 log_must mount -t zfs $TESTSNAP $MNTPSNAP
117 readonlyfs $MNTPSNAP
118 checkmount $TESTSNAP 'ro'
119 log_must mount -o remount,ro $TESTSNAP $MNTPSNAP
120 readonlyfs $MNTPSNAP
121 checkmount $TESTSNAP 'ro'
122 log_must umount $MNTPSNAP
123
124 # 4. Verify we can't remount a snapshot read-write
125 # The "mount -o rw" command will succeed but the snapshot is mounted readonly.
126 # The "mount -o remount,rw" command must fail with an explicit error.
127 log_must mount -t zfs -o rw $TESTSNAP $MNTPSNAP
128 readonlyfs $MNTPSNAP
129 checkmount $TESTSNAP 'ro'
130 log_mustnot mount -o remount,rw $TESTSNAP $MNTPSNAP
131 readonlyfs $MNTPSNAP
132 checkmount $TESTSNAP 'ro'
133 log_must umount $MNTPSNAP
134
135 # 5. Verify we can remount a dataset readonly and unmount it with
136 # encryption=on and sync=disabled (issue #7753)
137 log_must eval "echo 'password' | zfs create -o sync=disabled \
138 -o encryption=on -o keyformat=passphrase $TESTFS/crypt"
139 CRYPT_MNTPFS="$(get_prop mountpoint $TESTFS/crypt)"
140 log_must touch $CRYPT_MNTPFS/file.dat
141 log_must mount -o remount,ro $TESTFS/crypt $CRYPT_MNTPFS
142 log_must umount -f $CRYPT_MNTPFS
143 zpool sync $TESTPOOL
144
145 # 6. Re-import the pool readonly
146 log_must zpool export $TESTPOOL
147 log_must zpool import -o readonly=on $TESTPOOL
148
149 # 7. Verify we can't remount its filesystem read-write
150 readonlyfs $MNTPFS
151 checkmount $TESTFS 'ro'
152 log_mustnot mount -o remount,rw $MNTPFS
153 readonlyfs $MNTPFS
154 checkmount $TESTFS 'ro'
155
156 log_pass "Both filesystem and snapshots can be remounted correctly."