diff options
author | Serapheim Dimitropoulos <[email protected]> | 2019-08-12 10:02:34 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2019-08-12 10:02:34 -0700 |
commit | 3b9edd7b171f510b0abb9c885aa5b77114b8169a (patch) | |
tree | 06f48f5ea1d64c1e055adc1ba0afca52372df4a4 /tests | |
parent | 2081db79827e0fbc3088dcd693f8af7d7d0191a4 (diff) |
Introduce getting holds and listing bookmarks through ZCP
Consumers of ZFS Channel Programs can now list bookmarks,
and get holds from datasets. A minor-refactoring was also
applied to distinguish between user and system properties
in ZCP.
Reviewed-by: Paul Dagnelie <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Matt Ahrens <[email protected]>
Reviewed-by: Serapheim Dimitropoulos <[email protected]>
Ported-by: Serapheim Dimitropoulos <[email protected]>
Signed-off-by: Dan Kimmel <[email protected]>
OpenZFS-issue: https://illumos.org/issues/8862
Closes #7902
Diffstat (limited to 'tests')
8 files changed, 313 insertions, 3 deletions
diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index 23ea63335..f8f04d73e 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -82,8 +82,9 @@ tags = ['functional', 'channel_program', 'lua_core'] tests = ['tst.destroy_fs', 'tst.destroy_snap', 'tst.get_count_and_limit', 'tst.get_index_props', 'tst.get_mountpoint', 'tst.get_neg', 'tst.get_number_props', 'tst.get_string_props', 'tst.get_type', - 'tst.get_userquota', 'tst.get_written', 'tst.list_children', - 'tst.list_clones', 'tst.list_snapshots', 'tst.list_system_props', + 'tst.get_userquota', 'tst.get_written', 'tst.list_bookmarks', + 'tst.list_children', 'tst.list_clones', 'tst.list_holds', + 'tst.list_snapshots', 'tst.list_system_props', 'tst.list_user_props', 'tst.parse_args_neg','tst.promote_conflict', 'tst.promote_multiple', 'tst.promote_simple', 'tst.rollback_mult', 'tst.rollback_one', 'tst.snapshot_destroy', 'tst.snapshot_neg', diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib index 5d9e3b361..5d536fda3 100644 --- a/tests/zfs-tests/include/libtest.shlib +++ b/tests/zfs-tests/include/libtest.shlib @@ -742,6 +742,18 @@ function bkmarkexists } # +# Return 0 if a hold exists; $? otherwise +# +# $1 - hold tag +# $2 - snapshot name +# +function holdexists +{ + zfs holds "$2" | awk '{ print $2 }' | grep "$1" > /dev/null 2>&1 + return $? +} + +# # Set a property to a certain value on a dataset. # Sets a property of the dataset to the value as passed in. # @param: diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/Makefile.am b/tests/zfs-tests/tests/functional/channel_program/synctask_core/Makefile.am index cc86a2db9..d9894f682 100644 --- a/tests/zfs-tests/tests/functional/channel_program/synctask_core/Makefile.am +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/Makefile.am @@ -13,8 +13,10 @@ dist_pkgdata_SCRIPTS = \ tst.get_type.ksh \ tst.get_userquota.ksh \ tst.get_written.ksh \ + tst.list_bookmarks.ksh \ tst.list_children.ksh \ tst.list_clones.ksh \ + tst.list_holds.ksh \ tst.list_snapshots.ksh \ tst.list_system_props.ksh \ tst.list_user_props.ksh \ diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/cleanup.ksh b/tests/zfs-tests/tests/functional/channel_program/synctask_core/cleanup.ksh index 281f639a4..59f69ca8b 100755 --- a/tests/zfs-tests/tests/functional/channel_program/synctask_core/cleanup.ksh +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/cleanup.ksh @@ -17,3 +17,4 @@ . $STF_SUITE/include/libtest.shlib default_cleanup +destroy_pool testpool2 diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/setup.ksh b/tests/zfs-tests/tests/functional/channel_program/synctask_core/setup.ksh index 2516b6b8a..5837bf1a1 100755 --- a/tests/zfs-tests/tests/functional/channel_program/synctask_core/setup.ksh +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/setup.ksh @@ -18,4 +18,8 @@ DISK=${DISKS%% *} -default_setup ${DISK} +TESTPOOLDISK=${DISKS%% *} +TESTPOOL2DISK=${DISKS##* } + +default_setup ${TESTPOOLDISK} +create_pool testpool2 ${TESTPOOL2DISK} diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.list_bookmarks.ksh b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.list_bookmarks.ksh new file mode 100755 index 000000000..7456177f7 --- /dev/null +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.list_bookmarks.ksh @@ -0,0 +1,120 @@ +#!/bin/ksh -p +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright (c) 2017 by Delphix. All rights reserved. +# + +. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib + +# +# DESCRIPTION: +# Listing zfs bookmarks should work correctly. +# + +verify_runnable "global" + +TESTBOOK=$TESTPOOL/$TESTFS#testbook +TESTBOOK1=$TESTBOOK-1 +TESTBOOK2=$TESTBOOK-2 +TESTBOOK3=$TESTBOOK-3 + +function cleanup +{ + bkmarkexists $TESTBOOK && log_must zfs destroy $TESTBOOK + bkmarkexists $TESTBOOK1 && log_must zfs destroy $TESTBOOK1 + bkmarkexists $TESTBOOK2 && log_must zfs destroy $TESTBOOK2 + bkmarkexists $TESTBOOK3 && log_must zfs destroy $TESTBOOK3 + destroy_snapshot +} + +log_onexit cleanup + +create_snapshot + +# 0 bookmarks handled correctly +log_must_program $TESTPOOL - <<-EOF + n = 0 + for s in zfs.list.bookmarks("$TESTPOOL/$TESTFS") do + n = n + 1 + end + assert(n == 0) + return 0 +EOF + +# Create a bookmark +log_must zfs bookmark $TESTPOOL/$TESTFS@$TESTSNAP $TESTBOOK + +log_must_program $TESTPOOL - <<-EOF + n = 0 + for s in zfs.list.bookmarks("$TESTPOOL/$TESTFS") do + assert(s == "$TESTBOOK") + n = n + 1 + end + assert(n == 1) + return 0 +EOF + +log_must zfs bookmark $TESTPOOL/$TESTFS@$TESTSNAP $TESTBOOK1 +log_must zfs bookmark $TESTPOOL/$TESTFS@$TESTSNAP $TESTBOOK2 +log_must zfs bookmark $TESTPOOL/$TESTFS@$TESTSNAP $TESTBOOK3 + +# All bookmarks appear exactly once +log_must_program $TESTPOOL - <<-EOF + a = {} + a["$TESTBOOK"] = false + a["$TESTBOOK1"] = false + a["$TESTBOOK2"] = false + a["$TESTBOOK3"] = false + n = 0 + for s in zfs.list.bookmarks("$TESTPOOL/$TESTFS") do + assert(not a[s]) + a[s] = true + n = n + 1 + end + assert(n == 4) + assert(a["$TESTBOOK"] and + a["$TESTBOOK1"] and + a["$TESTBOOK2"] and + a["$TESTBOOK3"]) + return 0 +EOF + +# Nonexistent input +log_mustnot_program $TESTPOOL - <<-EOF + zfs.list.bookmarks("$TESTPOOL/nonexistent-fs") + return 0 +EOF +log_mustnot_program $TESTPOOL - <<-EOF + zfs.list.bookmarks("nonexistent-pool/$TESTFS") + return 0 +EOF + +# Can't look in a different pool than the one specified on command line +log_mustnot_program $TESTPOOL - <<-EOF + zfs.list.bookmarks("testpool2") + return 0 +EOF + +# Can't have bookmarks on snapshots, only on filesystems +log_mustnot_program $TESTPOOL - <<-EOF + zfs.list.bookmarks("$TESTPOOL/$TESTFS@$TESTSNAP") + return 0 +EOF + +# Can't have bookmarks on bookmarks, only on filesystems +log_mustnot_program $TESTPOOL - <<-EOF + zfs.list.bookmarks("$TESTBOOK") + return 0 +EOF + +log_pass "Listing zfs bookmarks should work correctly." diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.list_holds.ksh b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.list_holds.ksh new file mode 100755 index 000000000..2a471bdec --- /dev/null +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.list_holds.ksh @@ -0,0 +1,121 @@ +#!/bin/ksh -p +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright (c) 2017 by Delphix. All rights reserved. +# + +. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib + +# +# DESCRIPTION: +# Listing zfs holds should work correctly. +# + +verify_runnable "global" + +TESTHOLD=testhold-tag +TESTHOLD1=$TESTHOLD-1 +TESTHOLD2=$TESTHOLD-2 +TESTHOLD3=$TESTHOLD-3 +SNAP=$TESTPOOL/$TESTFS@$TESTSNAP + +function cleanup +{ + holdexists $TESTHOLD $SNAP && log_must zfs release $TESTHOLD $SNAP + holdexists $TESTHOLD1 $SNAP && log_must zfs release $TESTHOLD1 $SNAP + holdexists $TESTHOLD2 $SNAP && log_must zfs release $TESTHOLD2 $SNAP + holdexists $TESTHOLD3 $SNAP && log_must zfs release $TESTHOLD3 $SNAP + destroy_snapshot +} + +log_onexit cleanup + +create_snapshot + +# 0 holds handled correctly +log_must_program $TESTPOOL - <<-EOF + n = 0 + for s in zfs.list.holds("$SNAP") do + n = n + 1 + end + assert(n == 0) + return 0 +EOF + +# Create a hold +log_must zfs hold $TESTHOLD $SNAP + +log_must_program $TESTPOOL - <<-EOF + n = 0 + for s in zfs.list.holds("$SNAP") do + assert(s == "$TESTHOLD") + n = n + 1 + end + assert(n == 1) + return 0 +EOF + +log_must zfs hold $TESTHOLD1 $SNAP +log_must zfs hold $TESTHOLD2 $SNAP +log_must zfs hold $TESTHOLD3 $SNAP + +# All holds appear exactly once +log_must_program $TESTPOOL - <<-EOF + a = {} + a["$TESTHOLD"] = false + a["$TESTHOLD1"] = false + a["$TESTHOLD2"] = false + a["$TESTHOLD3"] = false + n = 0 + for s in zfs.list.holds("$SNAP") do + assert(not a[s]) + a[s] = true + n = n + 1 + end + assert(n == 4) + assert(a["$TESTHOLD"] and + a["$TESTHOLD1"] and + a["$TESTHOLD2"] and + a["$TESTHOLD3"]) + return 0 +EOF + +# Nonexistent input +log_mustnot_program $TESTPOOL - <<-EOF + zfs.list.holds("$TESTPOOL/nonexistent-fs@nonexistent-snap") + return 0 +EOF +log_mustnot_program $TESTPOOL - <<-EOF + zfs.list.holds("nonexistent-pool/$TESTFS") + return 0 +EOF + +# Can't look in a different pool than the one specified on command line +log_mustnot_program $TESTPOOL - <<-EOF + zfs.list.holds("testpool2") + return 0 +EOF + +# Can't have holds on filesystems +log_mustnot_program $TESTPOOL - <<-EOF + zfs.list.holds("$TESTPOOL/$TESTFS") + return 0 +EOF + +# Can't have holds on bookmarks +log_mustnot_program $TESTPOOL - <<-EOF + zfs.list.holds("$TESTPOOL/$TESTFS#bookmark") + return 0 +EOF + +log_pass "Listing zfs holds should work correctly." diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.list_user_props.ksh b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.list_user_props.ksh index 910dddc03..34fdbd56d 100755 --- a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.list_user_props.ksh +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.list_user_props.ksh @@ -20,6 +20,9 @@ # DESCRIPTION: # Listing zfs user properties should work correctly. # +# Note, that this file tests both zfs.list.user_properties +# and it's alias zfs.list.properties. +# verify_runnable "global" @@ -39,6 +42,14 @@ TESTVAL4="TOZwOfACvQtmDyiq68elB3a3g9YYyxBjSnLtN3ZyQYNOAKykzIE2khKKOBncJiDx" # 0 properties handled correctly log_must_program $TESTPOOL - <<-EOF n = 0 + for p in zfs.list.user_properties("$TESTPOOL/$TESTFS") do + n = n + 1 + end + assert(n == 0) + return 0 +EOF +log_must_program $TESTPOOL - <<-EOF + n = 0 for p in zfs.list.properties("$TESTPOOL/$TESTFS") do n = n + 1 end @@ -51,6 +62,16 @@ log_must zfs set $TESTPROP="$TESTVAL" $TESTPOOL/$TESTFS log_must_program $TESTPOOL - <<-EOF n = 0 + for p,v in zfs.list.user_properties("$TESTPOOL/$TESTFS") do + assert(p == "$TESTPROP") + assert(v == "$TESTVAL") + n = n + 1 + end + assert(n == 1) + return 0 +EOF +log_must_program $TESTPOOL - <<-EOF + n = 0 for p,v in zfs.list.properties("$TESTPOOL/$TESTFS") do assert(p == "$TESTPROP") assert(v == "$TESTVAL") @@ -80,6 +101,34 @@ log_must_program $TESTPOOL - <<-EOF m["$TESTPROP3"] = "$TESTVAL3" m["$TESTPROP4"] = "$TESTVAL4" n = 0 + for p,v in zfs.list.user_properties("$TESTPOOL/$TESTFS") do + assert(not a[p]) + a[p] = true + assert(v == m[p]) + n = n + 1 + end + assert(n == 5) + assert(a["$TESTPROP"] and + a["$TESTPROP1"] and + a["$TESTPROP2"] and + a["$TESTPROP3"] and + a["$TESTPROP4"]) + return 0 +EOF +log_must_program $TESTPOOL - <<-EOF + a = {} + a["$TESTPROP"] = false + a["$TESTPROP1"] = false + a["$TESTPROP2"] = false + a["$TESTPROP3"] = false + a["$TESTPROP4"] = false + m = {} + m["$TESTPROP"] = "$TESTVAL" + m["$TESTPROP1"] = "$TESTVAL1" + m["$TESTPROP2"] = "$TESTVAL2" + m["$TESTPROP3"] = "$TESTVAL3" + m["$TESTPROP4"] = "$TESTVAL4" + n = 0 for p,v in zfs.list.properties("$TESTPOOL/$TESTFS") do assert(not a[p]) a[p] = true |