]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_multi_mount.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_mount / zfs_multi_mount.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 is of the CDDL is also available via the Internet
12 # at http://www.illumos.org/license/CDDL.
13 #
14 # CDDL HEADER END
15 #
16
17 #
18 # Copyright(c) 2018 Datto Inc.
19 #
20
21 . $STF_SUITE/include/libtest.shlib
22
23 #
24 # DESCRIPTION:
25 # Verify multi mount functionality
26 #
27 # STRATEGY:
28 # 1. Create fs
29 # 2. Create and hold open file in filesystem
30 # 3. Lazy unmount
31 # 4. Verify remounting fs that was lazily unmounted is possible
32 # 5. Verify multiple mounts of the same dataset are possible
33 # 6. Verify bind mount doesn't prevent rename
34 #
35
36 verify_runnable "both"
37
38 function cleanup
39 {
40         ismounted $MNTPFS && log_must umount $MNTPFS
41         ismounted $MNTPFS2 && log_must umount $MNTPFS2
42         ismounted $MNTPFS3 && log_must umount $MNTPFS3
43         ismounted $MNTPFS4 && log_must umount $MNTPFS4
44         ismounted $RENAMEMNT && log_must umount $RENAMEMNT
45         datasetexists $TESTDS && log_must destroy_dataset "$TESTDS" "-f"
46 }
47 log_onexit cleanup
48
49 log_assert "Verify multiple mounts into one namespace are possible"
50
51 # 1. Create fs
52 TESTDS="$TESTPOOL/multi-mount-test"
53 log_must zfs create $TESTDS
54
55 # 2. Create and hold open file in filesystem
56 MNTPFS="$(get_prop mountpoint $TESTDS)"
57 FILENAME="$MNTPFS/file"
58 log_must mkfile 128k $FILENAME
59 log_must exec 9<> $FILENAME # open file
60
61 # 3. Lazy umount
62 if is_freebsd; then
63         # FreeBSD does not support lazy unmount
64         log_must umount $MNTPFS
65 else
66         log_must umount -l $MNTPFS
67 fi
68 if [ -f $FILENAME ]; then
69         log_fail "Lazy unmount failed"
70 fi
71
72 # 4. Verify remounting fs that was lazily unmounted is possible
73 log_must zfs mount $TESTDS
74 if [ ! -f $FILENAME ]; then
75         log_fail "Lazy remount failed"
76 fi
77 log_must exec 9>&- # close fd
78
79 # 5. Verify multiple mounts of the same dataset are possible
80 MNTPFS2="$MNTPFS-second"
81 FILENAME="$MNTPFS2/file"
82 log_must mkdir $MNTPFS2
83 log_must mount -t zfs -o zfsutil $TESTDS $MNTPFS2
84 if [ ! -f $FILENAME ]; then
85         log_fail "First multi mount failed"
86 fi
87
88 MNTPFS3="$MNTPFS-third"
89 FILENAME="$MNTPFS3/file"
90 log_must mkdir $MNTPFS3
91 log_must mount -t zfs -o zfsutil $TESTDS $MNTPFS3
92 if [ ! -f $FILENAME ]; then
93         log_fail "Second multi mount failed"
94 fi
95
96 # 6. Verify bind mount doesn't prevent rename
97 RENAMEFS="$TESTDS-newname"
98 MNTPFS4="$MNTPFS-fourth"
99 log_must mkdir $MNTPFS4
100 log_must mount --bind $MNTPFS $MNTPFS4
101 log_must zfs rename $TESTDS $RENAMEFS
102 RENAMEMNT="$(get_prop mountpoint $RENAMEFS)"
103 FILENAME="$RENAMEMNT/file"
104 if [ ! -f $FILENAME ]; then
105         log_fail "Rename failed"
106 fi
107 log_must zfs rename $RENAMEFS $TESTDS
108
109 log_pass "Multiple mounts are possible"