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