aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/openzfs/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.list_holds.ksh
blob: 2a471bdecbfcfda4b1a29e7869fe603bed091eef (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/ksh -p
#
# 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 of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright (c) 2017 by Delphix. All rights reserved.
#

. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib

#
# DESCRIPTION:
#       Listing zfs holds should work correctly.
#

verify_runnable "global"

TESTHOLD=testhold-tag
TESTHOLD1=$TESTHOLD-1
TESTHOLD2=$TESTHOLD-2
TESTHOLD3=$TESTHOLD-3
SNAP=$TESTPOOL/$TESTFS@$TESTSNAP

function cleanup
{
	holdexists $TESTHOLD $SNAP && log_must zfs release $TESTHOLD $SNAP
	holdexists $TESTHOLD1 $SNAP && log_must zfs release $TESTHOLD1 $SNAP
	holdexists $TESTHOLD2 $SNAP && log_must zfs release $TESTHOLD2 $SNAP
	holdexists $TESTHOLD3 $SNAP && log_must zfs release $TESTHOLD3 $SNAP
	destroy_snapshot
}

log_onexit cleanup

create_snapshot

# 0 holds handled correctly
log_must_program $TESTPOOL - <<-EOF
	n = 0
	for s in zfs.list.holds("$SNAP") do
		n = n + 1
	end
	assert(n == 0)
	return 0
EOF

# Create a hold
log_must zfs hold $TESTHOLD $SNAP

log_must_program $TESTPOOL - <<-EOF
	n = 0
	for s in zfs.list.holds("$SNAP") do
		assert(s == "$TESTHOLD")
		n = n + 1
	end
	assert(n == 1)
	return 0
EOF

log_must zfs hold $TESTHOLD1 $SNAP
log_must zfs hold $TESTHOLD2 $SNAP
log_must zfs hold $TESTHOLD3 $SNAP

# All holds appear exactly once
log_must_program $TESTPOOL - <<-EOF
	a = {}
	a["$TESTHOLD"] = false
	a["$TESTHOLD1"] = false
	a["$TESTHOLD2"] = false
	a["$TESTHOLD3"] = false
	n = 0
	for s in zfs.list.holds("$SNAP") do
		assert(not a[s])
		a[s] = true
		n = n + 1
	end
	assert(n == 4)
	assert(a["$TESTHOLD"] and
	    a["$TESTHOLD1"] and
	    a["$TESTHOLD2"] and
	    a["$TESTHOLD3"])
	return 0
EOF

# Nonexistent input
log_mustnot_program $TESTPOOL - <<-EOF
	zfs.list.holds("$TESTPOOL/nonexistent-fs@nonexistent-snap")
	return 0
EOF
log_mustnot_program $TESTPOOL - <<-EOF
	zfs.list.holds("nonexistent-pool/$TESTFS")
	return 0
EOF

# Can't look in a different pool than the one specified on command line
log_mustnot_program $TESTPOOL - <<-EOF
	zfs.list.holds("testpool2")
	return 0
EOF

# Can't have holds on filesystems
log_mustnot_program $TESTPOOL - <<-EOF
	zfs.list.holds("$TESTPOOL/$TESTFS")
	return 0
EOF

# Can't have holds on bookmarks
log_mustnot_program $TESTPOOL - <<-EOF
	zfs.list.holds("$TESTPOOL/$TESTFS#bookmark")
	return 0
EOF

log_pass "Listing zfs holds should work correctly."