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 <pcd@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Matt Ahrens <mahrens@delphix.com>
Reviewed-by: Serapheim Dimitropoulos <serapheim@delphix.com>
Ported-by: Serapheim Dimitropoulos <serapheim@delphix.com>
Signed-off-by: Dan Kimmel <dan.kimmel@delphix.com>

OpenZFS-issue: https://illumos.org/issues/8862
Closes #7902
This commit is contained in:
Serapheim Dimitropoulos
2019-08-12 10:02:34 -07:00
committed by Brian Behlendorf
parent 2081db7982
commit 3b9edd7b17
10 changed files with 593 additions and 25 deletions
+3 -2
View File
@@ -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',
+12
View File
@@ -741,6 +741,18 @@ function bkmarkexists
return $?
}
#
# 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.
@@ -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 \
@@ -17,3 +17,4 @@
. $STF_SUITE/include/libtest.shlib
default_cleanup
destroy_pool testpool2
@@ -18,4 +18,8 @@
DISK=${DISKS%% *}
default_setup ${DISK}
TESTPOOLDISK=${DISKS%% *}
TESTPOOL2DISK=${DISKS##* }
default_setup ${TESTPOOLDISK}
create_pool testpool2 ${TESTPOOL2DISK}
@@ -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."
@@ -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."
@@ -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"
@@ -37,6 +40,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
@@ -49,6 +60,16 @@ EOF
# Add a single user property
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
@@ -66,6 +87,34 @@ log_must zfs set $TESTPROP3="$TESTVAL3" $TESTPOOL/$TESTFS
log_must zfs set $TESTPROP4="$TESTVAL4" $TESTPOOL/$TESTFS
# All user properties have correct value and appear exactly once
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.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