Skip to content

Commit

Permalink
OpenZFS 8605 - zfs channel programs fix zfs.exists
Browse files Browse the repository at this point in the history
Authored by: Chris Williamson <[email protected]>
Reviewed by: Paul Dagnelie <[email protected]>
Reviewed by: Dan Kimmel <[email protected]>
Reviewed by: Matt Ahrens <[email protected]>
Approved by: Robert Mustacchi <[email protected]>
Ported-by: Don Brady <[email protected]>

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: openzfs/openzfs@1e85e111
  • Loading branch information
cwill authored and behlendorf committed Feb 8, 2018
1 parent d99a015 commit 475eca4
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 3 deletions.
12 changes: 12 additions & 0 deletions man/man8/zfs-program.8
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/zcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ zcp_exists(lua_State *state)
return (luaL_error(state, "unexpected error %d", error));
}

return (0);
return (1);
}

/*
Expand Down
4 changes: 2 additions & 2 deletions tests/runfiles/linux.run
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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'))

0 comments on commit 475eca4

Please sign in to comment.