]> granicus.if.org Git - zfs/commitdiff
OpenZFS 8605 - zfs channel programs fix zfs.exists
authorChris Williamson <chris.williamson@delphix.com>
Thu, 8 Feb 2018 16:17:52 +0000 (09:17 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 8 Feb 2018 23:28:52 +0000 (15:28 -0800)
Authored by: Chris Williamson <chris.williamson@delphix.com>
Reviewed by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Matt Ahrens <mahrens@delphix.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Ported-by: Don Brady <don.brady@delphix.com>
zfs.exists() in channel programs doesn't return any result, and should
have a man page entry. This patch corrects zfs.exists so that it
returns a value indicating if the dataset exists or not. It also adds
documentation about it in the man page.

OpenZFS-issue: https://www.illumos.org/issues/8605
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/1e85e111

man/man8/zfs-program.8
module/zfs/zcp.c
tests/runfiles/linux.run
tests/zfs-tests/tests/functional/channel_program/lua_core/Makefile.am
tests/zfs-tests/tests/functional/channel_program/lua_core/tst.exists.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/channel_program/lua_core/tst.exists.zcp [new file with mode: 0644]

index d84990ca16106eed3285b2d0d3d06d3896b5ef16..2e4e9587d5936574081d9fb15e14c3e447f6f256 100644 (file)
@@ -289,6 +289,18 @@ msg (string)
 .Bd -ragged -compact -offset "xxxx"
 Debug message to be printed.
 .Ed
+.It Em zfs.exists(dataset)
+Returns true if the given dataset exists, or false if it doesn't.
+A fatal error will be thrown if the dataset is not in the target pool.
+That is, in a channel program running on rpool,
+zfs.exists("rpool/nonexistent_fs") returns false, but
+zfs.exists("somepool/fs_that_may_exist") will error.
+.Pp
+dataset (string)
+.Bd -ragged -compact -offset "xxxx"
+Dataset to check for existence.
+Must be in the target pool.
+.Ed
 .It Em zfs.get_prop(dataset, property)
 Returns two values.
 First, a string, number or table containing the property value for the given
index 07f96e298ddf2b3e6cab0ce4124e2f2aa0795cd9..83560309b3ad2c87a22b9bc7f2f8a29861175ee2 100644 (file)
@@ -714,7 +714,7 @@ zcp_exists(lua_State *state)
                return (luaL_error(state, "unexpected error %d", error));
        }
 
-       return (0);
+       return (1);
 }
 
 /*
index 184dd2f9e801baed9f0a5bb31242a184588debd0..04f0163f3fc41843593a5f73be13ac377d483a2a 100644 (file)
@@ -63,8 +63,8 @@ tests = ['case_all_values', 'norm_all_values']
 tags = ['functional', 'casenorm']
 
 [tests/functional/channel_program/lua_core]
-tests = ['tst.args_to_lua', 'tst.divide_by_zero', 'tst.integer_illegal',
-    'tst.integer_overflow', 'tst.language_functions_neg',
+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',
index ff65c2c2f8b75181f7582c381308d16f65e9c558..d733acb0b5dfd256f45f955a5d0e6bcb857ff5cc 100644 (file)
@@ -8,6 +8,8 @@ dist_pkgdata_SCRIPTS = \
        tst.divide_by_zero.err \
        tst.divide_by_zero.ksh \
        tst.divide_by_zero.zcp \
+       tst.exists.ksh \
+       tst.exists.zcp \
        tst.integer_illegal.ksh \
        tst.integer_overflow.ksh \
        tst.language_functions_neg.ksh \
diff --git a/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.exists.ksh b/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.exists.ksh
new file mode 100755 (executable)
index 0000000..e46fe21
--- /dev/null
@@ -0,0 +1,45 @@
+#!/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:
+#       zfs.exists should accurately report whether a dataset exists, and
+#       report an error if a dataset is in another pool.
+
+verify_runnable "global"
+
+# create $TESTSNAP and $TESTCLONE
+create_snapshot
+create_clone
+
+function cleanup
+{
+       datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \
+           log_must zfs destroy -R $TESTPOOL/$TESTFS@$TESTSNAP
+}
+
+log_must_program $TESTPOOL $ZCP_ROOT/lua_core/tst.exists.zcp \
+    $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS@$TESTSNAP \
+    $TESTPOOL/$TESTCLONE
+
+log_mustnot_checkerr_program "not in the target pool" \
+    $TESTPOOL - <<-EOF
+       return zfs.exists('rpool')
+EOF
+
+log_pass "zfs.exists() gives correct results"
diff --git a/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.exists.zcp b/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.exists.zcp
new file mode 100644 (file)
index 0000000..e44cf45
--- /dev/null
@@ -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) 2017 by Delphix. All rights reserved.
+--
+
+-- ensure zfs.exists works as expected.
+
+args = ...
+argv = args['argv']
+pool = argv[1]
+
+for i = 1,4 do
+       assert(zfs.exists(argv[i]))
+end
+
+assert(not zfs.exists(pool .. '/notadataset'))