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
10 # A full copy of the text of the CDDL should have accompanied this
11 # source. A copy of the CDDL is also available via the Internet at
12 # http://www.illumos.org/license/CDDL.
18 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
21 .
$STF_SUITE/include
/libtest.shlib
25 # Verify 'zfs list -t all -o name,origin,clones' prints the correct
30 # 2. Create recursive snapshots and their clones
31 # 3. Verify zfs clones property displays right information for different
35 verify_runnable
"both"
37 function local_cleanup
40 for ds
in $datasets; do
41 datasetexists
$ds/$TESTCLONE.
$i && \
42 log_must zfs destroy
-rf $ds/$TESTCLONE.
$i
43 datasetexists
$ds && log_must zfs destroy
-Rf $ds
48 # Set up filesystem with clones
52 # create nested datasets
53 log_must zfs create
-p $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3
55 # verify dataset creation
56 for ds
in $datasets; do
57 datasetexists
$ds || log_fail
"Create $ds dataset fail."
60 # create recursive nested snapshot
61 log_must zfs snapshot
-r $TESTPOOL/$TESTFS1@snap
62 for ds
in $datasets; do
63 datasetexists
$ds@snap || \
64 log_fail
"Create $ds@snap snapshot fail."
66 for ds
in $datasets; do
67 for fs
in $datasets; do
68 log_must zfs clone
$ds@snap
$fs/$TESTCLONE.
$i
75 function verify_clones
77 typeset
-i no_clones
=$1
81 for ds
in $datasets; do
82 if [[ -n $clone_snap ]]; then
83 clone_snap
=/$TESTCLONE.
$i
85 snapshot
=$
(echo "$names" |
grep $ds$clone_snap@snap
)
86 actual_clone
=$
(zfs list
-t all
-o clones
$snapshot |
tail -1)
90 for token
in $actual_clone; do
91 clones
=( "${clones[@]}" "$token" )
94 [[ ${#clones[*]} -ne $no_clones ]] && \
95 log_fail
"$snapshot has unexpected number of clones" \
99 if [[ $unexpected -eq 1 ]]; then
100 for fs
in $datasets; do
101 if [[ $fs == $ds ]]; then
102 if [[ -z $clone_snap ]]; then
103 unexpected_clone
=$fs/$TESTCLONE.
$i
104 (for match
in ${clones[@]};do
105 [[ $match != $unexpected_clone ]] && \
106 exit 0; done) || log_fail \
107 "Unexpected clones of the snapshot"
110 unexpected_clone
=$fs/$TESTCLONE.
$i
111 (for match
in ${clones[@]};do
112 [[ $match == $expected_clone ]] && \
113 [[ $match != $unexpected_clone ]] \
114 && exit 0; done) || log_fail \
115 "Unexpected clones of the snapshot"
118 expected_clone
=$fs/$TESTCLONE.
$i
119 (for match
in ${clones[@]};do
120 [[ $match == $expected_clone ]] && \
121 exit 0; done) || log_fail \
122 "Unexpected clones of the snapshot"
126 for fs
in $datasets; do
127 expected_clone
=$fs/$TESTCLONE.
$i
128 (for match
in ${clones[@]};do
129 [[ $match == $expected_clone ]] && exit 0; \
130 done) || log_fail
"Unexpected clones" \
139 log_onexit local_cleanup
140 datasets
="$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS2
141 $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3"
144 typeset
-a deferred_snaps
149 log_note
"Verify zfs clone propery for multiple clones"
150 names
=$
(zfs list
-rt all
-o name
$TESTPOOL)
151 log_must verify_clones
3 0
153 log_note
"verfify clone property for clone deletion"
155 for ds
in $datasets; do
156 log_must zfs destroy
$ds/$TESTCLONE.
$i
159 names
=$
(zfs list
-rt all
-o name
$TESTPOOL)
161 log_must verify_clones
2 1
163 log_must local_cleanup
166 log_note
"verify zfs deferred destroy on clones property"
168 names
=$
(zfs list
-rt all
-o name
$TESTPOOL)
169 for ds
in $datasets; do
170 log_must zfs destroy
-d $ds@snap
171 deferred_snaps
=( "${deferred_snaps[@]}" "$ds@snap" )
174 log_must verify_clones
3 0
176 log_note
"verify zfs deferred destroy by destroying clones on clones property"
179 for ds
in $datasets; do
180 for fs
in $datasets; do
181 log_must zfs destroy
$fs/$TESTCLONE.
$i
182 d_clones
=( "${d_clones[@]}" "$fs/$TESTCLONE.$i" )
186 names
=$
(zfs list
-rtall -o name
$TESTPOOL)
187 for snap
in ${deferred_snaps[@]}; do
188 status
=$
(echo "$names" |
grep $snap)
189 [[ -z $status ]] || \
190 log_fail
"$snap exist after deferred destroy"
192 for dclone
in ${d_clones[@]}; do
193 log_note
"D CLONE = $dclone"
194 status
=$
(echo "$names" |
grep $dclone)
195 [[ -z $status ]] || \
196 log_fail
"$dclone exist after deferred destroy"
199 log_must local_cleanup
201 log_note
"verify clone property for zfs promote"
203 for ds
in $datasets; do
204 log_must zfs promote
$ds/$TESTCLONE.
$i
207 names
=$
(zfs list
-rt all
-o name
,clones
$TESTPOOL)
208 log_must verify_clones
3 1 $TESTCLONE
210 for ds
in $datasets; do
211 log_must zfs promote
$ds
214 log_must local_cleanup
216 log_note
"verify clone list truncated correctly"
219 fs
=$TESTPOOL/$TESTFS1
220 log_must zfs create
$fs
221 log_must zfs snapshot
$fs@snap
223 log_must zfs clone
$fs@snap
$fs/$TESTCLONE$
(python
-c 'print "x" * 200').
$i
227 clone_list
=$
(zfs list
-o clones
$fs@snap
)
228 char_count
=$
(echo "$clone_list" |
tail -1 |
wc |
awk '{print $3}')
229 [[ $char_count -eq 1024 ]] || \
230 log_fail
"Clone list not truncated correctly. Unexpected character count" \
233 log_pass
"'zfs list -o name,origin,clones prints the correct clone information."