OpenZFS 8605 - zfs channel programs fix zfs.exists
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
This commit is contained in:
parent
d99a015343
commit
475eca4908
|
@ -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
|
||||
|
|
|
@ -714,7 +714,7 @@ zcp_exists(lua_State *state)
|
|||
return (luaL_error(state, "unexpected error %d", error));
|
||||
}
|
||||
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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"
|
|
@ -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'))
|
Loading…
Reference in New Issue