]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_nounmount.ksh
ZFS: MFV 2.0-rc1-gfd20a8
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / tests / zfs-tests / tests / functional / cli_root / zfs_rename / zfs_rename_nounmount.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) 2019 iXsystems, Inc.
19 #
20
21 . $STF_SUITE/include/libtest.shlib
22
23 #
24 # DESCRIPTION:
25 #       zfs rename -u should rename datasets without unmounting them
26 #
27 # STRATEGY:
28 #       1. Create a set of nested datasets.
29 #       2. Verify datasets are mounted.
30 #       3. Rename with -u and verify all datasets stayed mounted.
31 #
32
33 verify_runnable "both"
34
35 function rename_cleanup
36 {
37         cd $back
38         zfs destroy -fR $TESTPOOL/rename_test
39         zfs destroy -fR $TESTPOOL/renamed
40 }
41
42 back=$(pwd)
43 log_onexit rename_cleanup
44
45 log_must zfs create $TESTPOOL/rename_test
46 log_must zfs create $TESTPOOL/rename_test/child
47 log_must zfs create $TESTPOOL/rename_test/child/grandchild
48
49 if ! ismounted $TESTPOOL/rename_test; then
50         log_fail "$TESTPOOL/rename_test is not mounted"
51 fi
52 if ! ismounted $TESTPOOL/rename_test/child; then
53         log_fail "$TESTPOOL/rename_test/child is not mounted"
54 fi
55 if ! ismounted $TESTPOOL/rename_test/child/grandchild; then
56         log_fail "$TESTPOOL/rename_test/child/grandchild is not mounted"
57 fi
58
59 mntp_p=$(get_prop mountpoint $TESTPOOL/rename_test)
60 mntp_c=$(get_prop mountpoint $TESTPOOL/rename_test/child)
61 mntp_g=$(get_prop mountpoint $TESTPOOL/rename_test/child/grandchild)
62
63 log_must cd $mntp_g
64 log_mustnot zfs rename $TESTPOOL/rename_test $TESTPOOL/renamed
65 log_must zfs rename -u $TESTPOOL/rename_test $TESTPOOL/renamed
66
67 log_mustnot zfs list $TESTPOOL/rename_test
68 log_mustnot zfs list $TESTPOOL/rename_test/child
69 log_mustnot zfs list $TESTPOOL/rename_test/child/grandchild
70
71 log_must zfs list $TESTPOOL/renamed
72 log_must zfs list $TESTPOOL/renamed/child
73 log_must zfs list $TESTPOOL/renamed/child/grandchild
74
75 missing=$(zfs mount | awk -v pat=$TESTPOOL/renamed '$1 ~ pat' | awk \
76     -v mntp_p=$mntp_p \
77     -v mntp_c=$mntp_c \
78     -v mntp_g=$mntp_g '
79     BEGIN { p = c = g = 0 }
80     $2 == mntp_p { p = 1 }
81     $2 == mntp_c { c = 1 }
82     $2 == mntp_g { g = 1 }
83     END {
84         if (p != 1)
85                 print mntp_p
86         if (c != 1)
87                 print mntp_c
88         if (g != 1)
89                 print mntp_g
90     }')
91 [[ -z "$missing" ]] || log_fail "Mountpoints no longer mounted: $missing"
92
93 log_pass "Verified rename -u does not unmount datasets"