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 children should work correctly. 22# 23 24verify_runnable "global" 25 26log_assert "Listing zfs children should work correctly." 27 28TESTCHILD=$TESTPOOL/$TESTFS/testchild 29TESTCHILD1=$TESTCHILD-1 30TESTCHILD2=$TESTCHILD-2 31TESTCHILD3=$TESTCHILD-3 32 33function cleanup 34{ 35 datasetexists $TESTCHILD && log_must zfs destroy $TESTCHILD 36 datasetexists $TESTCHILD1 && log_must zfs destroy $TESTCHILD1 37 datasetexists $TESTCHILD2 && log_must zfs destroy $TESTCHILD2 38 datasetexists $TESTCHILD3 && log_must zfs destroy $TESTCHILD3 39} 40 41log_onexit cleanup 42 43# 0 children handled correctly 44log_must_program $TESTPOOL - <<-EOF 45 n = 0 46 for s in zfs.list.children("$TESTPOOL/$TESTFS") do 47 n = n + 1 48 end 49 assert(n == 0) 50 return 0 51EOF 52 53log_must_program $TESTPOOL - <<-EOF 54 n = 0 55 for s in zfs.list.children("$TESTPOOL") do 56 assert(s == "$TESTPOOL/$TESTFS") 57 n = n + 1 58 end 59 assert(n == 1) 60 return 0 61EOF 62 63# Create a child fs 64log_must zfs create $TESTCHILD 65 66log_must_program $TESTPOOL - <<-EOF 67 n = 0 68 for s in zfs.list.children("$TESTPOOL/$TESTFS") do 69 assert(s == "$TESTCHILD") 70 n = n + 1 71 end 72 assert(n == 1) 73 return 0 74EOF 75 76log_must zfs create $TESTCHILD1 77log_must zfs create $TESTCHILD2 78log_must zfs create $TESTCHILD3 79 80# All children appear exactly once 81log_must_program $TESTPOOL - <<-EOF 82 a = {} 83 a["$TESTCHILD"] = false 84 a["$TESTCHILD1"] = false 85 a["$TESTCHILD2"] = false 86 a["$TESTCHILD3"] = false 87 n = 0 88 for s in zfs.list.children("$TESTPOOL/$TESTFS") do 89 assert(not a[s]) 90 a[s] = true 91 n = n + 1 92 end 93 assert(n == 4) 94 assert(a["$TESTCHILD"] and 95 a["$TESTCHILD1"] and 96 a["$TESTCHILD2"] and 97 a["$TESTCHILD3"]) 98 return 0 99EOF 100 101# Bad input 102log_mustnot_program $TESTPOOL - <<-EOF 103 zfs.list.children("$TESTPOOL/not-a-fs") 104 return 0 105EOF 106 107log_mustnot_program $TESTPOOL - <<-EOF 108 zfs.list.children("not-a-pool/$TESTFS") 109 return 0 110EOF 111 112# Can't look in a different pool than the one specified on command line 113log_mustnot_program $TESTPOOL - <<-EOF 114 zfs.list.children("rpool") 115 return 0 116EOF 117 118create_snapshot 119log_mustnot_program $TESTPOOL - <<-EOF 120 zfs.list.children("$TESTPOOL/$TESTFS@$TESTSNAP") 121 return 0 122EOF 123destroy_snapshot 124 125log_pass "Listing zfs children should work correctly." 126