diff options
author | Chris Williamson <[email protected]> | 2018-02-08 09:24:39 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2018-02-08 15:29:24 -0800 |
commit | 234c91c50848fa74bd72efff4e555331a25d9fe1 (patch) | |
tree | e93accbb8799995afbc2d3d3714577b1f925471c /tests | |
parent | af0736898669eabe31e47405023c80b9a58e5e6c (diff) |
OpenZFS 8600 - ZFS channel programs - snapshot
Authored by: Chris Williamson <[email protected]>
Reviewed by: Matthew Ahrens <[email protected]>
Reviewed by: John Kennedy <[email protected]>
Reviewed by: Brad Lewis <[email protected]>
Approved by: Robert Mustacchi <[email protected]>
Ported-by: Don Brady <[email protected]>
ZFS channel programs should be able to create snapshots.
In addition to the base snapshot functionality, this entails extra
logic to handle edge cases which were formerly not possible, such as
creating then destroying a snapshot in the same transaction sync.
OpenZFS-issue: https://www.illumos.org/issues/8600
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/68089b8b
Diffstat (limited to 'tests')
13 files changed, 392 insertions, 4 deletions
diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index 0320301d2..a844d6b1b 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -67,8 +67,9 @@ tests = ['tst.args_to_lua', 'tst.divide_by_zero', 'tst.exists', 'tst.integer_illegal', 'tst.integer_overflow', 'tst.language_functions_neg', 'tst.language_functions_pos', 'tst.large_prog', 'tst.memory_limit', 'tst.nested_neg', 'tst.nested_pos', 'tst.nvlist_to_lua', - 'tst.recursive_neg', 'tst.recursive_pos', 'tst.return_nvlist_neg', - 'tst.return_nvlist_pos', 'tst.return_recursive_table', 'tst.timeout'] + 'tst.recursive_neg', 'tst.recursive_pos', 'tst.return_large', + 'tst.return_nvlist_neg', 'tst.return_nvlist_pos', + 'tst.return_recursive_table', 'tst.timeout'] tags = ['functional', 'channel_program', 'lua_core'] [tests/functional/channel_program/synctask_core] @@ -78,7 +79,9 @@ tests = ['tst.destroy_fs', 'tst.destroy_snap', 'tst.get_count_and_limit', 'tst.get_userquota', 'tst.get_written', 'tst.list_children', 'tst.list_clones', 'tst.list_snapshots', 'tst.list_system_props', 'tst.parse_args_neg', 'tst.promote_conflict', 'tst.promote_multiple', - 'tst.promote_simple', 'tst.rollback_mult', 'tst.rollback_one'] + 'tst.promote_simple', 'tst.rollback_mult', 'tst.rollback_one', + 'tst.snapshot_destroy', 'tst.snapshot_neg', 'tst.snapshot_recursive', + 'tst.snapshot_simple'] tags = ['functional', 'channel_program', 'synctask_core'] [tests/functional/chattr] diff --git a/tests/zfs-tests/tests/functional/channel_program/lua_core/Makefile.am b/tests/zfs-tests/tests/functional/channel_program/lua_core/Makefile.am index d733acb0b..dba3da0f1 100644 --- a/tests/zfs-tests/tests/functional/channel_program/lua_core/Makefile.am +++ b/tests/zfs-tests/tests/functional/channel_program/lua_core/Makefile.am @@ -26,6 +26,8 @@ dist_pkgdata_SCRIPTS = \ tst.recursive_neg.ksh \ tst.recursive_pos.ksh \ tst.recursive.zcp \ + tst.return_large.ksh \ + tst.return_large.zcp \ tst.return_nvlist_neg.ksh \ tst.return_nvlist_pos.ksh \ tst.return_recursive_table.ksh \ diff --git a/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.return_large.ksh b/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.return_large.ksh new file mode 100755 index 000000000..369ad846a --- /dev/null +++ b/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.return_large.ksh @@ -0,0 +1,54 @@ +#!/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) 2016, 2017 by Delphix. All rights reserved. +# + +. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib + +# +# DESCRIPTION: Returning very large (up to the memory limit) lists should +# function correctly. +# + +verify_runnable "global" + +fs=$TESTPOOL/$TESTFS/testchild + +function cleanup +{ + datasetexists $fs && log_must zfs destroy -R $fs +} + +log_onexit cleanup + +log_must zfs create $fs + +# +# Actually checking in the ~500kb expected result of this program would be +# awful, so we just make sure it was as long as we expected. +# +output_lines=$(log_must zfs program $TESTPOOL \ + $ZCP_ROOT/lua_core/tst.return_large.zcp | wc -l) + +[[ $output_lines -lt 5000 ]] && + log_fail "Expected return of full list but only got $output_lines lines" + +# +# Make sure we fail if the return is over the memory limit +# +log_mustnot_program $TESTPOOL -m 10000 \ + $ZCP_ROOT/lua_core/tst.return_large.zcp + +log_pass "Large return values work properly" + diff --git a/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.return_large.zcp b/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.return_large.zcp new file mode 100644 index 000000000..0ea9f8930 --- /dev/null +++ b/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.return_large.zcp @@ -0,0 +1,24 @@ +-- +-- 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) 2016, 2017 by Delphix. All rights reserved. +-- + +basestring = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" .. + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + +ret = {} +for i=1,5000 do + table.insert(ret, basestring) +end + +return ret 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 29bd68eee..48b89b578 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 @@ -29,4 +29,12 @@ dist_pkgdata_SCRIPTS = \ tst.promote_multiple.ksh \ tst.promote_simple.ksh \ tst.rollback_mult.ksh \ - tst.rollback_one.ksh + tst.rollback_one.ksh \ + tst.snapshot_destroy.ksh \ + tst.snapshot_destroy.zcp \ + tst.snapshot_neg.ksh \ + tst.snapshot_neg.zcp \ + tst.snapshot_recursive.ksh \ + tst.snapshot_recursive.zcp \ + tst.snapshot_simple.ksh \ + tst.snapshot_simple.zcp diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_destroy.ksh b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_destroy.ksh new file mode 100755 index 000000000..98317db6e --- /dev/null +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_destroy.ksh @@ -0,0 +1,39 @@ +#!/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) 2016, 2017 by Delphix. All rights reserved. +# + +. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib + +# +# DESCRIPTION: Creating and destroying snapshots in the same txg should work. +# + +verify_runnable "global" + +fs=$TESTPOOL/$TESTFS/testchild + +function cleanup +{ + datasetexists $fs && log_must zfs destroy -R $fs +} + +log_onexit cleanup + +log_must zfs create $fs + +log_must_program $TESTPOOL \ + $ZCP_ROOT/synctask_core/tst.snapshot_destroy.zcp $fs + +log_pass "Creating/destroying snapshots in one channel program works" diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_destroy.zcp b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_destroy.zcp new file mode 100644 index 000000000..6fbfb06ad --- /dev/null +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_destroy.zcp @@ -0,0 +1,24 @@ +-- +-- 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) 2016, 2017 by Delphix. All rights reserved. +-- + +args = ... +argv = args["argv"] + +assert(zfs.sync.snapshot(argv[1] .. "@snap1") == 0) +assert(zfs.sync.destroy(argv[1] .. "@snap1") == 0) + +for s in zfs.list.snapshots(argv[1]) do + assert(false) +end diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_neg.ksh b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_neg.ksh new file mode 100755 index 000000000..c3585c938 --- /dev/null +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_neg.ksh @@ -0,0 +1,44 @@ +#!/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) 2016, 2017 by Delphix. All rights reserved. +# + +. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib + +# +# DESCRIPTION: Check various invalid snapshot error cases +# + +verify_runnable "global" + +fs1=$TESTPOOL/$TESTFS/testchild1 +fs2=$TESTPOOL/$TESTFS/testchild2 + +function cleanup +{ + for fs in $fs1 $fs2; do + datasetexists $fs && log_must zfs destroy -R $fs + done +} + +log_onexit cleanup + +log_must zfs create $fs1 +log_must zfs create $fs2 +log_must zfs snapshot $fs1@snap1 + +log_must_program $TESTPOOL $ZCP_ROOT/synctask_core/tst.snapshot_neg.zcp $fs1 $fs2 + +log_pass "zfs.sync.snapshot returns correct errors on invalid input" + diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_neg.zcp b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_neg.zcp new file mode 100644 index 000000000..5cae324bc --- /dev/null +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_neg.zcp @@ -0,0 +1,35 @@ +-- +-- 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) 2016, 2017 by Delphix. All rights reserved. +-- + +args = ... +argv = args["argv"] +fs1 = argv[1] +fs2 = argv[2] + +longstring = "a" +for i=1,9 do + longstring = longstring .. longstring +end + +-- invalid snapshot names +assert(zfs.sync.snapshot("ceci_nest_pas_une_dataset") == EINVAL); +assert(zfs.sync.snapshot(fs1) == EINVAL) +assert(zfs.sync.snapshot(fs1 .. "@" .. longstring) == ENAMETOOLONG) + +assert(zfs.sync.snapshot(fs2 .. "@snap1") == 0) +-- only one snapshot of a filesystem is allowed per TXG. +assert(zfs.sync.snapshot(fs2 .. "@snap2") == EAGAIN) +-- snapshot already exists +assert(zfs.sync.snapshot(fs1 .. "@snap1") == EEXIST) diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_recursive.ksh b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_recursive.ksh new file mode 100755 index 000000000..c0180d90c --- /dev/null +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_recursive.ksh @@ -0,0 +1,61 @@ +#!/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) 2016, 2017 by Delphix. All rights reserved. +# + +. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib + +# +# DESCRIPTION: Construct a set of nested filesystems, then recursively snapshot +# all of them. +# + +verify_runnable "global" + +rootfs=$TESTPOOL/$TESTFS/root +snapname=snap + +function cleanup +{ + datasetexists $rootfs && log_must zfs destroy -R $rootfs +} + +log_onexit cleanup + +filesystems="$rootfs \ +$rootfs/child1 \ +$rootfs/child1/subchild1 \ +$rootfs/child1/subchild2 \ +$rootfs/child1/subchild3 \ +$rootfs/child2 \ +$rootfs/child2/subchild4 \ +$rootfs/child2/subchild5" + +for fs in $filesystems; do + log_must zfs create $fs +done + +log_must_program $TESTPOOL \ + $ZCP_ROOT/synctask_core/tst.snapshot_recursive.zcp $rootfs $snapname + +# +# Make sure all of the snapshots we expect were created. +# +for fs in $filesystems; do + log_must snapexists $fs@$snapname +done + +log_pass "Recursively snapshotting multiple filesystems works." + + diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_recursive.zcp b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_recursive.zcp new file mode 100644 index 000000000..097940d71 --- /dev/null +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_recursive.zcp @@ -0,0 +1,28 @@ +-- +-- 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) 2016, 2017 by Delphix. All rights reserved. +-- + +args = ... +argv = args["argv"] +fs = argv[1] +snap = argv[2] + +function snapshot_recursive(root) + assert(zfs.sync.snapshot(root .. "@" .. snap) == 0) + for child in zfs.list.children(root) do + snapshot_recursive(child) + end +end + +snapshot_recursive(fs) diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_simple.ksh b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_simple.ksh new file mode 100755 index 000000000..e818ce9fc --- /dev/null +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_simple.ksh @@ -0,0 +1,40 @@ +#!/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) 2016, 2017 by Delphix. All rights reserved. +# + +. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib + +# +# DESCRIPTION: Make sure basic snapshot functionality works in channel programs +# + +verify_runnable "global" + +fs=$TESTPOOL/$TESTFS/testchild +snapname=testsnap + +function cleanup +{ + datasetexists $fs && log_must zfs destroy -R $fs +} + +log_onexit cleanup + +log_must zfs create $fs + +log_must_program $TESTPOOL \ + $ZCP_ROOT/synctask_core/tst.snapshot_simple.zcp $fs $snapname + +log_pass "Simple snapshotting works" diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_simple.zcp b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_simple.zcp new file mode 100644 index 000000000..215e013df --- /dev/null +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_simple.zcp @@ -0,0 +1,26 @@ +-- +-- 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) 2016, 2017 by Delphix. All rights reserved. +-- + +-- This program should be invoked as "zfs program <pool> <prog> <fs> <snap>" + +args = ... +argv = args["argv"] +assert(zfs.sync.snapshot(argv[1] .. "@" .. argv[2]) == 0) +snaps = {} +for s in zfs.list.snapshots(argv[1]) do + table.insert(snaps, s) +end +assert(#snaps == 1) +assert(snaps[1] == (argv[1] .. "@" .. argv[2])) |