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 24verify_runnable "global" 25 26log_assert "Listing zfs clones should work correctly." 27 28function cleanup 29{ 30 destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP "-R" 31} 32 33log_onexit cleanup 34 35# Take snapshot to test with ($TESTSNAP) 36create_snapshot 37 38# 0 clones handled correctly 39log_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 46EOF 47 48# Create a clone ($TESTCLONE) 49create_clone 50 51log_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 59EOF 60 61TESTCLONE1=${TESTCLONE}-1 62TESTCLONE2=${TESTCLONE}-2 63TESTCLONE3=${TESTCLONE}-3 64create_clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE1 65create_clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE2 66create_clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE3 67 68# All clones appear exactly once 69log_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 87EOF 88 89# Bad input 90log_mustnot_program $TESTPOOL - <<-EOF 91 zfs.list.clones("$TESTPOOL/not-a-fs@$TESTSNAP") 92 return 0 93EOF 94 95log_mustnot_program $TESTPOOL - <<-EOF 96 zfs.list.clones("$TESTPOOL/$TESTFS@not-a-snap") 97 return 0 98EOF 99 100# Can't look in a different pool than the one specified on command line 101log_mustnot_program $TESTPOOL - <<-EOF 102 zfs.list.clones("rpool") 103 return 0 104EOF 105 106log_mustnot_program $TESTPOOL - <<-EOF 107 zfs.list.clones("not-a-pool/$TESTFS@$TESTSNAP") 108 return 0 109EOF 110 111log_mustnot_program $TESTPOOL - <<-EOF 112 zfs.list.clones("$TESTPOOL/$TESTFS") 113 return 0 114EOF 115 116log_pass "Listing zfs clones should work correctly." 117