aboutsummaryrefslogtreecommitdiff
path: root/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_nounmount.ksh
blob: 1c707762a72c7748d969959e57f4cf93cc4a1f3a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/ksh -p
#
# CDDL HEADER START
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy is of the CDDL is also available via the Internet
# at http://www.illumos.org/license/CDDL.
#
# CDDL HEADER END
#

#
# Copyright (c) 2019 iXsystems, Inc.
#

. $STF_SUITE/include/libtest.shlib

#
# DESCRIPTION:
#	zfs rename -u should rename datasets without unmounting them
#
# STRATEGY:
#	1. Create a set of nested datasets.
#	2. Verify datasets are mounted.
#	3. Rename with -u and verify all datasets stayed mounted.
#

verify_runnable "both"

function rename_cleanup
{
	cd $back
	zfs destroy -fR $TESTPOOL/rename_test
	zfs destroy -fR $TESTPOOL/renamed
}

back=$(pwd)
log_onexit rename_cleanup

log_must zfs create $TESTPOOL/rename_test
log_must zfs create $TESTPOOL/rename_test/child
log_must zfs create $TESTPOOL/rename_test/child/grandchild

if ! ismounted $TESTPOOL/rename_test; then
	log_fail "$TESTPOOL/rename_test is not mounted"
fi
if ! ismounted $TESTPOOL/rename_test/child; then
	log_fail "$TESTPOOL/rename_test/child is not mounted"
fi
if ! ismounted $TESTPOOL/rename_test/child/grandchild; then
	log_fail "$TESTPOOL/rename_test/child/grandchild is not mounted"
fi

mntp_p=$(get_prop mountpoint $TESTPOOL/rename_test)
mntp_c=$(get_prop mountpoint $TESTPOOL/rename_test/child)
mntp_g=$(get_prop mountpoint $TESTPOOL/rename_test/child/grandchild)

log_must cd $mntp_g
log_mustnot zfs rename $TESTPOOL/rename_test $TESTPOOL/renamed
log_must zfs rename -u $TESTPOOL/rename_test $TESTPOOL/renamed

log_mustnot zfs list $TESTPOOL/rename_test
log_mustnot zfs list $TESTPOOL/rename_test/child
log_mustnot zfs list $TESTPOOL/rename_test/child/grandchild

log_must zfs list $TESTPOOL/renamed
log_must zfs list $TESTPOOL/renamed/child
log_must zfs list $TESTPOOL/renamed/child/grandchild

missing=$(zfs mount | awk -v pat=$TESTPOOL/renamed '$1 ~ pat' | awk \
    -v mntp_p=$mntp_p \
    -v mntp_c=$mntp_c \
    -v mntp_g=$mntp_g '
    BEGIN { p = c = g = 0 }
    $2 == mntp_p { p = 1 }
    $2 == mntp_c { c = 1 }
    $2 == mntp_g { g = 1 }
    END {
	if (p != 1)
		print mntp_p
	if (c != 1)
		print mntp_c
	if (g != 1)
		print mntp_g
    }')
[[ -z "$missing" ]] || log_fail "Mountpoints no longer mounted: $missing"

log_pass "Verified rename -u does not unmount datasets"