]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_fail.ksh
Update ZTS to work on FreeBSD
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zfs_mount / zfs_mount_all_fail.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # This file and its contents are supplied under the terms of the
6 # Common Development and Distribution License ("CDDL"), version 1.0.
7 # You may only use this file in accordance with the terms of version
8 # 1.0 of the CDDL.
9 #
10 # A full copy of the text of the CDDL should have accompanied this
11 # source. A copy of the CDDL is also available via the Internet at
12 # http://www.illumos.org/license/CDDL.
13 #
14 # CDDL HEADER END
15 #
16
17 #
18 # Copyright (c) 2017 by Delphix. All rights reserved.
19 #
20
21 . $STF_SUITE/include/libtest.shlib
22 . $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib
23
24 # DESCRIPTION:
25 # Verify that if 'zfs mount -a' fails to mount one filesystem,
26 # the command fails with a non-zero error code, but all other
27 # filesystems are mounted.
28 #
29 # STRATEGY:
30 # 1. Create zfs filesystems
31 # 2. Unmount a leaf filesystem
32 # 3. Create a file in the above filesystem's mountpoint
33 # 4. Verify that 'zfs mount -a' fails to mount the above if on Linux
34 # or succeeds if on FreeBSD
35 # 5. Verify that all other filesystems were mounted
36 #
37
38 verify_runnable "both"
39
40 typeset -a filesystems
41 typeset path=${TEST_BASE_DIR%%/}/testroot$$/$TESTPOOL
42 typeset fscount=10
43
44 function setup_all
45 {
46 # Create $fscount filesystems at the top level of $path
47 for ((i=0; i<$fscount; i++)); do
48 setup_filesystem "$DISKS" "$TESTPOOL" $i "$path/$i" ctr
49 done
50
51 zfs list -r $TESTPOOL
52
53 return 0
54 }
55
56 function cleanup_all
57 {
58 export __ZFS_POOL_RESTRICT="$TESTPOOL"
59 log_must zfs $unmountall
60 unset __ZFS_POOL_RESTRICT
61
62 [[ -d ${TEST_BASE_DIR%%/}/testroot$$ ]] && \
63 rm -rf ${TEST_BASE_DIR%%/}/testroot$$
64 }
65
66 log_onexit cleanup_all
67
68 log_must setup_all
69
70 #
71 # Unmount all of the above so that we can create the stray file
72 # in one of the mountpoint directories.
73 #
74 export __ZFS_POOL_RESTRICT="$TESTPOOL"
75 log_must zfs $unmountall
76 unset __ZFS_POOL_RESTRICT
77
78 # All of our filesystems should be unmounted at this point
79 for ((i=0; i<$fscount; i++)); do
80 log_mustnot mounted "$TESTPOOL/$i"
81 done
82
83 # Create a stray file in one filesystem's mountpoint
84 touch $path/0/strayfile
85
86 # Verify that zfs mount -a fails on Linux or succeeds on FreeBSD
87 export __ZFS_POOL_RESTRICT="$TESTPOOL"
88 if is_linux; then
89 log_mustnot zfs $mountall
90 log_mustnot mounted "$TESTPOOL/0"
91 typeset behaved="failed"
92 else
93 log_must zfs $mountall
94 log_must mounted "$TESTPOOL/0"
95 typeset behaved="succeeded"
96 fi
97 unset __ZFS_POOL_RESTRICT
98
99 # All other filesystems should be mounted
100 for ((i=1; i<$fscount; i++)); do
101 log_must mounted "$TESTPOOL/$i"
102 done
103
104 log_pass "'zfs $mountall' $behaved as expected."