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) 2017 by Delphix. All rights reserved. 15# 16 17. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib 18 19# 20# DESCRIPTION: 21# Listing zfs bookmarks should work correctly. 22# 23 24verify_runnable "global" 25 26TESTBOOK=$TESTPOOL/$TESTFS#testbook 27TESTBOOK1=$TESTBOOK-1 28TESTBOOK2=$TESTBOOK-2 29TESTBOOK3=$TESTBOOK-3 30 31function cleanup 32{ 33 bkmarkexists $TESTBOOK && log_must zfs destroy $TESTBOOK 34 bkmarkexists $TESTBOOK1 && log_must zfs destroy $TESTBOOK1 35 bkmarkexists $TESTBOOK2 && log_must zfs destroy $TESTBOOK2 36 bkmarkexists $TESTBOOK3 && log_must zfs destroy $TESTBOOK3 37 destroy_snapshot 38} 39 40log_onexit cleanup 41 42create_snapshot 43 44# 0 bookmarks handled correctly 45log_must_program $TESTPOOL - <<-EOF 46 n = 0 47 for s in zfs.list.bookmarks("$TESTPOOL/$TESTFS") do 48 n = n + 1 49 end 50 assert(n == 0) 51 return 0 52EOF 53 54# Create a bookmark 55log_must zfs bookmark $TESTPOOL/$TESTFS@$TESTSNAP $TESTBOOK 56 57log_must_program $TESTPOOL - <<-EOF 58 n = 0 59 for s in zfs.list.bookmarks("$TESTPOOL/$TESTFS") do 60 assert(s == "$TESTBOOK") 61 n = n + 1 62 end 63 assert(n == 1) 64 return 0 65EOF 66 67log_must zfs bookmark $TESTPOOL/$TESTFS@$TESTSNAP $TESTBOOK1 68log_must zfs bookmark $TESTPOOL/$TESTFS@$TESTSNAP $TESTBOOK2 69log_must zfs bookmark $TESTPOOL/$TESTFS@$TESTSNAP $TESTBOOK3 70 71# All bookmarks appear exactly once 72log_must_program $TESTPOOL - <<-EOF 73 a = {} 74 a["$TESTBOOK"] = false 75 a["$TESTBOOK1"] = false 76 a["$TESTBOOK2"] = false 77 a["$TESTBOOK3"] = false 78 n = 0 79 for s in zfs.list.bookmarks("$TESTPOOL/$TESTFS") do 80 assert(not a[s]) 81 a[s] = true 82 n = n + 1 83 end 84 assert(n == 4) 85 assert(a["$TESTBOOK"] and 86 a["$TESTBOOK1"] and 87 a["$TESTBOOK2"] and 88 a["$TESTBOOK3"]) 89 return 0 90EOF 91 92# Nonexistent input 93log_mustnot_program $TESTPOOL - <<-EOF 94 zfs.list.bookmarks("$TESTPOOL/nonexistent-fs") 95 return 0 96EOF 97log_mustnot_program $TESTPOOL - <<-EOF 98 zfs.list.bookmarks("nonexistent-pool/$TESTFS") 99 return 0 100EOF 101 102# Can't look in a different pool than the one specified on command line 103log_mustnot_program $TESTPOOL - <<-EOF 104 zfs.list.bookmarks("testpool2") 105 return 0 106EOF 107 108# Can't have bookmarks on snapshots, only on filesystems 109log_mustnot_program $TESTPOOL - <<-EOF 110 zfs.list.bookmarks("$TESTPOOL/$TESTFS@$TESTSNAP") 111 return 0 112EOF 113 114# Can't have bookmarks on bookmarks, only on filesystems 115log_mustnot_program $TESTPOOL - <<-EOF 116 zfs.list.bookmarks("$TESTBOOK") 117 return 0 118EOF 119 120log_pass "Listing zfs bookmarks should work correctly." 121