]> git.proxmox.com Git - mirror_zfs.git/blame - tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_mountpoints.ksh
zfs_mount_all_mountpoints: cleanup_all should leave pool root mounted
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zfs_mount / zfs_mount_all_mountpoints.ksh
CommitLineData
a10d50f9
SR
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 'zfs mount -a' succeeds given a set of filesystems
26# whose mountpoints have a parent/child relationship which is
27# counter to the filesystem parent/child relationship.
28#
29# STRATEGY:
30# 1. Create zfs filesystems within the given pool.
31# 2. Unmount all the filesystems.
32# 3. Verify that 'zfs mount -a' command succeed,
33# and all available ZFS filesystems are mounted.
34# 4. Verify that 'zfs mount' is identical with 'df -F zfs'
35#
36
37verify_runnable "both"
38
39typeset -a filesystems
40
41function setup_all
42{
43 typeset path=${TEST_BASE_DIR%%/}/testroot$$/$TESTPOOL
44 typeset fscount=10
45
46 #
47 # Generate an array of filesystem names that represent a deep
48 # hierarchy as such:
49 #
50 # 0
51 # 0/1
52 # 0/1/2
53 # 0/1/2/3
54 # 0/1/2/3/4
55 # ...
56 #
57 fs=0
58 for ((i=0; i<$fscount; i++)); do
59 if [[ $i -gt 0 ]]; then
60 fs=$fs/$i
61 fi
62 filesystems+=($fs)
63 done
64
65 # Create all of the above filesystems
66 for ((i=0; i<$fscount; i++)); do
67 fs=${filesystems[$i]}
68 setup_filesystem "$DISKS" "$TESTPOOL" "$fs" "$path/$i" ctr
69 done
70
71 zfs list -r $TESTPOOL
72
73 #
74 # Unmount all of the above so that we can setup our convoluted
75 # mount paths.
76 #
77 export __ZFS_POOL_RESTRICT="$TESTPOOL"
78 log_must zfs $unmountall
79 unset __ZFS_POOL_RESTRICT
80
81 #
82 # Configure the mount paths so that each mountpoint is contained
83 # in a child filesystem. We should end up with something like the
84 # following structure (modulo the number of filesystems):
85 #
86 # NAME MOUNTPOINT
87 # testpool /testpool
88 # testpool/0 /testroot25416/testpool/0/1/2/3/4/5/6
89 # testpool/0/1 /testroot25416/testpool/0/1/2/3/4/5
90 # testpool/0/1/2 /testroot25416/testpool/0/1/2/3/4
91 # testpool/0/1/2/3 /testroot25416/testpool/0/1/2/3
92 # testpool/0/1/2/3/4 /testroot25416/testpool/0/1/2
93 # testpool/0/1/2/3/4/5 /testroot25416/testpool/0/1
94 # testpool/0/1/2/3/4/5/6 /testroot25416/testpool/0
95 #
96 for ((i=0; i<$fscount; i++)); do
97 fs=$TESTPOOL/${filesystems[$(($fscount - $i - 1))]}
98 mnt=$path/${filesystems[$i]}
99 zfs set mountpoint=$mnt $fs
100 done
101
102 zfs list -r $TESTPOOL
103
104 return 0
105}
106
107function cleanup_all
108{
109 export __ZFS_POOL_RESTRICT="$TESTPOOL"
110 log_must zfs $unmountall
111 unset __ZFS_POOL_RESTRICT
4016ad70
TS
112 # make sure we leave $TESTPOOL mounted
113 log_must zfs mount $TESTPOOL
a10d50f9
SR
114
115 for fs in ${filesystems[@]}; do
116 cleanup_filesystem "$TESTPOOL" "$fs"
117 done
118 [[ -d ${TEST_BASE_DIR%%/}/testroot$$ ]] && \
119 rm -rf ${TEST_BASE_DIR%%/}/testroot$$
120}
121
122#
123# This function takes a single true/false argument. If true it will verify that
124# all file systems are mounted. If false it will verify that they are not
125# mounted.
126#
127function verify_all
128{
129 if $1; then
130 logfunc=log_must
131 else
132 logfunc=log_mustnot
133 fi
134
135 for fs in ${filesystems[@]}; do
136 $logfunc mounted "$TESTPOOL/$fs"
137 done
138
139 return 0
140}
141
142log_onexit cleanup_all
143
144log_must setup_all
145
146export __ZFS_POOL_RESTRICT="$TESTPOOL"
147log_must zfs $unmountall
148unset __ZFS_POOL_RESTRICT
149
150verify_all false
151
152export __ZFS_POOL_RESTRICT="$TESTPOOL"
153log_must zfs $mountall
154unset __ZFS_POOL_RESTRICT
155
156verify_all true
157
158log_note "Verify that 'zfs $mountcmd' will display " \
159 "all ZFS filesystems currently mounted."
160
161verify_mount_display
162
163log_pass "'zfs $mountall' succeeds as root, " \
164 "and all available ZFS filesystems are mounted."