aboutsummaryrefslogtreecommitdiff
path: root/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.list_bookmarks.ksh
blob: 7456177f725b7021cf4f0f516ebc0a16360d1390 (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
#!/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 bookmarks should work correctly.
#

verify_runnable "global"

TESTBOOK=$TESTPOOL/$TESTFS#testbook
TESTBOOK1=$TESTBOOK-1
TESTBOOK2=$TESTBOOK-2
TESTBOOK3=$TESTBOOK-3

function cleanup
{
	bkmarkexists $TESTBOOK && log_must zfs destroy $TESTBOOK
	bkmarkexists $TESTBOOK1 && log_must zfs destroy $TESTBOOK1
	bkmarkexists $TESTBOOK2 && log_must zfs destroy $TESTBOOK2
	bkmarkexists $TESTBOOK3 && log_must zfs destroy $TESTBOOK3
	destroy_snapshot
}

log_onexit cleanup

create_snapshot

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

# Create a bookmark
log_must zfs bookmark $TESTPOOL/$TESTFS@$TESTSNAP $TESTBOOK

log_must_program $TESTPOOL - <<-EOF
	n = 0
	for s in zfs.list.bookmarks("$TESTPOOL/$TESTFS") do
		assert(s == "$TESTBOOK")
		n = n + 1
	end
	assert(n == 1)
	return 0
EOF

log_must zfs bookmark $TESTPOOL/$TESTFS@$TESTSNAP $TESTBOOK1
log_must zfs bookmark $TESTPOOL/$TESTFS@$TESTSNAP $TESTBOOK2
log_must zfs bookmark $TESTPOOL/$TESTFS@$TESTSNAP $TESTBOOK3

# All bookmarks appear exactly once
log_must_program $TESTPOOL - <<-EOF
	a = {}
	a["$TESTBOOK"] = false
	a["$TESTBOOK1"] = false
	a["$TESTBOOK2"] = false
	a["$TESTBOOK3"] = false
	n = 0
	for s in zfs.list.bookmarks("$TESTPOOL/$TESTFS") do
		assert(not a[s])
		a[s] = true
		n = n + 1
	end
	assert(n == 4)
	assert(a["$TESTBOOK"] and
	    a["$TESTBOOK1"] and
	    a["$TESTBOOK2"] and
	    a["$TESTBOOK3"])
	return 0
EOF

# Nonexistent input
log_mustnot_program $TESTPOOL - <<-EOF
	zfs.list.bookmarks("$TESTPOOL/nonexistent-fs")
	return 0
EOF
log_mustnot_program $TESTPOOL - <<-EOF
	zfs.list.bookmarks("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.bookmarks("testpool2")
	return 0
EOF

# Can't have bookmarks on snapshots, only on filesystems
log_mustnot_program $TESTPOOL - <<-EOF
	zfs.list.bookmarks("$TESTPOOL/$TESTFS@$TESTSNAP")
	return 0
EOF

# Can't have bookmarks on bookmarks, only on filesystems
log_mustnot_program $TESTPOOL - <<-EOF
	zfs.list.bookmarks("$TESTBOOK")
	return 0
EOF

log_pass "Listing zfs bookmarks should work correctly."