]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.list_clones.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / channel_program / synctask_core / tst.list_clones.ksh
1 #!/bin/ksh -p
2 #
3 # This file and its contents are supplied under the terms of the
4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 # You may only use this file in accordance with the terms of version
6 # 1.0 of the CDDL.
7 #
8 # A full copy of the text of the CDDL should have accompanied this
9 # source.  A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
11 #
12
13 #
14 # Copyright (c) 2016 by Delphix. All rights reserved.
15 #
16
17 . $STF_SUITE/tests/functional/channel_program/channel_common.kshlib
18
19 #
20 # DESCRIPTION:
21 #       Listing zfs clones should work correctly.
22 #
23
24 verify_runnable "global"
25
26 log_assert "Listing zfs clones should work correctly."
27
28 function cleanup
29 {
30         destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP "-R"
31 }
32
33 log_onexit cleanup
34
35 # Take snapshot to test with ($TESTSNAP)
36 create_snapshot
37
38 # 0 clones handled correctly
39 log_must_program $TESTPOOL - <<-EOF
40         n = 0
41         for s in zfs.list.clones("$TESTPOOL/$TESTFS@$TESTSNAP") do
42                 n = n + 1
43         end
44         assert(n == 0)
45         return 0
46 EOF
47
48 # Create a clone ($TESTCLONE)
49 create_clone
50
51 log_must_program $TESTPOOL - <<-EOF
52         n = 0
53         for s in zfs.list.clones("$TESTPOOL/$TESTFS@$TESTSNAP") do
54                 assert(s == "$TESTPOOL/$TESTCLONE")
55                 n = n + 1
56         end
57         assert(n == 1)
58         return 0
59 EOF
60
61 TESTCLONE1=${TESTCLONE}-1
62 TESTCLONE2=${TESTCLONE}-2
63 TESTCLONE3=${TESTCLONE}-3
64 create_clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE1
65 create_clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE2
66 create_clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE3
67
68 # All clones appear exactly once
69 log_must_program $TESTPOOL - <<-EOF
70         a = {}
71         a["$TESTPOOL/$TESTCLONE"] = false
72         a["$TESTPOOL/$TESTCLONE1"] = false
73         a["$TESTPOOL/$TESTCLONE2"] = false
74         a["$TESTPOOL/$TESTCLONE3"] = false
75         n = 0
76         for s in zfs.list.clones("$TESTPOOL/$TESTFS@$TESTSNAP") do
77                 assert(not a[s])
78                 a[s] = true
79                 n = n + 1
80         end
81         assert(n == 4)
82         assert(a["$TESTPOOL/$TESTCLONE"] and
83             a["$TESTPOOL/$TESTCLONE1"] and
84             a["$TESTPOOL/$TESTCLONE2"] and
85             a["$TESTPOOL/$TESTCLONE3"])
86         return 0
87 EOF
88
89 # Bad input
90 log_mustnot_program $TESTPOOL - <<-EOF
91         zfs.list.clones("$TESTPOOL/not-a-fs@$TESTSNAP")
92         return 0
93 EOF
94
95 log_mustnot_program $TESTPOOL - <<-EOF
96         zfs.list.clones("$TESTPOOL/$TESTFS@not-a-snap")
97         return 0
98 EOF
99
100 # Can't look in a different pool than the one specified on command line
101 log_mustnot_program $TESTPOOL - <<-EOF
102         zfs.list.clones("rpool")
103         return 0
104 EOF
105
106 log_mustnot_program $TESTPOOL - <<-EOF
107         zfs.list.clones("not-a-pool/$TESTFS@$TESTSNAP")
108         return 0
109 EOF
110
111 log_mustnot_program $TESTPOOL - <<-EOF
112         zfs.list.clones("$TESTPOOL/$TESTFS")
113         return 0
114 EOF
115
116 log_pass "Listing zfs clones should work correctly."