]>
git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_remount.ksh
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.
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.
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]
24 # Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
27 .
$STF_SUITE/include
/libtest.shlib
28 .
$STF_SUITE/tests
/functional
/cli_root
/zfs_mount
/zfs_mount.kshlib
32 # Verify remount functionality, expecially on readonly objects.
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
45 verify_runnable
"both"
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
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
61 function readonlyfs
# filesystem
63 typeset filesystem
="$1"
65 file_write
-o create
-f $filesystem/file.dat
67 if [[ $ret != 30 ]]; then
68 log_fail
"Writing to $filesystem did not return EROFS ($ret)."
73 # Verify $dataset is mounted with $option
75 function checkmount
# dataset option
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)"
87 log_note
"Dataset $dataset is mounted with option $option"
91 log_assert
"Verify remount functionality on both filesystem and snapshots"
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
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
110 checkmount
$TESTFS 'ro'
111 log_must mount
-o remount
,rw
$TESTFS $MNTPFS
112 log_must
touch $MNTPFS/file.dat
113 checkmount
$TESTFS 'rw'
115 # 3. Verify we can (re)mount the snapshot readonly
116 log_must mount
-t zfs
$TESTSNAP $MNTPSNAP
118 checkmount
$TESTSNAP 'ro'
119 log_must mount
-o remount
,ro
$TESTSNAP $MNTPSNAP
121 checkmount
$TESTSNAP 'ro'
122 log_must umount
$MNTPSNAP
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
129 checkmount
$TESTSNAP 'ro'
130 log_mustnot mount
-o remount
,rw
$TESTSNAP $MNTPSNAP
132 checkmount
$TESTSNAP 'ro'
133 log_must umount
$MNTPSNAP
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
145 # 6. Re-import the pool readonly
146 log_must zpool
export $TESTPOOL
147 log_must zpool import
-o readonly=on
$TESTPOOL
149 # 7. Verify we can't remount its filesystem read-write
151 checkmount
$TESTFS 'ro'
152 log_mustnot mount
-o remount
,rw
$MNTPFS
154 checkmount
$TESTFS 'ro'
156 log_pass
"Both filesystem and snapshots can be remounted correctly."