summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSara Hartse <sara.hartse@delphix.com>2020-02-03 15:06:13 -0600
committerJason King <jason.king@joyent.com>2020-02-21 12:54:43 -0600
commitb2d2f356e1abcc2a19572314b5084b7b87050604 (patch)
tree89297646677ff8ea814f899982703726555d0f94
parent48d1bcbbf436904298ce3191590b67834ac47dea (diff)
downloadillumos-joyent-b2d2f356e1abcc2a19572314b5084b7b87050604.tar.gz
12308 Support setting user properties in a channel program
Portions contributed by: Jason King <jason.king@joyent.com> Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed by: Matt Ahrens <matt@delphix.com> Reviewed by: C Fraire <cfraire@me.com> Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com> Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r--usr/src/man/man1m/zfs-program.1m25
-rw-r--r--usr/src/pkg/manifests/system-test-zfstest.mf6
-rw-r--r--usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/tst.set_props.ksh40
-rw-r--r--usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/tst.set_props.zcp109
-rw-r--r--usr/src/uts/common/Makefile.files3
-rw-r--r--usr/src/uts/common/fs/zfs/sys/zcp_set.h48
-rw-r--r--usr/src/uts/common/fs/zfs/zcp_set.c100
-rw-r--r--usr/src/uts/common/fs/zfs/zcp_synctask.c40
8 files changed, 368 insertions, 3 deletions
diff --git a/usr/src/man/man1m/zfs-program.1m b/usr/src/man/man1m/zfs-program.1m
index 12802319b0..99fa887aa8 100644
--- a/usr/src/man/man1m/zfs-program.1m
+++ b/usr/src/man/man1m/zfs-program.1m
@@ -12,7 +12,7 @@
.\" Copyright (c) 2018 Datto Inc.
.\" Copyright 2020 Joyent, Inc.
.\"
-.Dd January 15, 2020
+.Dd February 3, 2020
.Dt ZFS-PROGRAM 1M
.Os
.Sh NAME
@@ -156,7 +156,7 @@ can guarantee that it will finish successfully against a similar size system.
If a channel program attempts to return too large a value, the program will
fully execute but exit with a nonzero status code and no return value.
.Pp
-.Em Note:
+.Em Note :
ZFS API functions do not generate Fatal Errors when correctly invoked, they
return an error code and the channel program continues executing.
See the
@@ -409,6 +409,26 @@ filesystem (string)
.Bd -ragged -compact -offset "xxxx"
Filesystem to rollback.
.Ed
+.It Em zfs.sync.set_prop(dataset, property, value)
+Sets the given property on a dataset.
+Currently only user properties are supported.
+Returns 0 if the property was set, or a nonzero error code otherwise.
+.Pp
+dataset (string)
+.Bd -ragged -compact -offset "xxxx"
+The dataset where the property will be set.
+.Ed
+.Pp
+property (string)
+.Bd -ragged -compact -offset "xxxx"
+The property to set.
+Only user properties are supported.
+.Ed
+.Pp
+value (string)
+.Bd -ragged -compact -offset "xxxx"
+The value of the property to be set.
+.Ed
.It Em zfs.sync.snapshot(dataset)
Create a snapshot of a filesystem.
Returns 0 if the snapshot was successfully created,
@@ -441,6 +461,7 @@ The available zfs.check functions are:
.It Em zfs.check.destroy(dataset, [defer=true|false])
.It Em zfs.check.promote(dataset)
.It Em zfs.check.rollback(filesystem)
+.It Em zfs.check.set_property(dataset, property, value)
.It Em zfs.check.snapshot(dataset)
.El
.It Sy zfs.list submodule
diff --git a/usr/src/pkg/manifests/system-test-zfstest.mf b/usr/src/pkg/manifests/system-test-zfstest.mf
index 693f83af3e..6ffc0b4f56 100644
--- a/usr/src/pkg/manifests/system-test-zfstest.mf
+++ b/usr/src/pkg/manifests/system-test-zfstest.mf
@@ -638,6 +638,12 @@ file \
path=opt/zfs-tests/tests/functional/channel_program/synctask_core/tst.rollback_one \
mode=0555
file \
+ path=opt/zfs-tests/tests/functional/channel_program/synctask_core/tst.set_props \
+ mode=0555
+file \
+ path=opt/zfs-tests/tests/functional/channel_program/synctask_core/tst.set_props.zcp \
+ mode=0444
+file \
path=opt/zfs-tests/tests/functional/channel_program/synctask_core/tst.snapshot_destroy \
mode=0555
file \
diff --git a/usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/tst.set_props.ksh b/usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/tst.set_props.ksh
new file mode 100644
index 0000000000..062b2ab579
--- /dev/null
+++ b/usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/tst.set_props.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 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib
+
+#
+# DESCRIPTION:
+# Getting number props should work correctly on filesystems,
+# snapshots and volumes.
+#
+
+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_sync $TESTPOOL $ZCP_ROOT/synctask_core/tst.set_props.zcp $fs
+
+log_pass "Setting props from channel program works correctly."
diff --git a/usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/tst.set_props.zcp b/usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/tst.set_props.zcp
new file mode 100644
index 0000000000..6d2a92d6b2
--- /dev/null
+++ b/usr/src/test/zfs-tests/tests/functional/channel_program/synctask_core/tst.set_props.zcp
@@ -0,0 +1,109 @@
+--
+-- 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.
+-- Copyright 2020 Joyent, Inc.
+--
+
+arg = ...
+fs = arg["argv"][1]
+
+-- values from zfs.h
+maxname = 256 -- ZAP_MAXNAMELEN
+maxvalue = 8192 -- ZAP_MAXVALUELEN
+
+pos_props = {}
+neg_props = {}
+
+-- In lua, strings are immutable, so to avoid a bunch of copies, we
+-- build the value in a table and use concat (which appears to be the
+-- recommended method for such things).
+largeprop = {}
+for i = 0,maxvalue,8
+do
+ table.insert(largeprop, "aaaaaaaa")
+end
+-- add an extra character so we spill over the limit
+table.insert(largeprop, "b")
+
+largepropv = table.concat(largeprop)
+
+largepropname = { "b:" }
+for i = 0,maxname,8
+do
+ table.insert(largepropname, "aaaaaaaa")
+end
+largepropnamev = table.concat(largepropname)
+
+pos_props["a:prop"] = {"hello"}
+
+-- For neg_props, an optional expected error value can be added after the
+-- property value as seen below.
+neg_props["notaproperty"] = {"hello", EINVAL}
+neg_props["a:very.long.property.value"] = { largepropv, E2BIG }
+neg_props[largepropnamev] = {"greetings", ENAMETOOLONG }
+
+-- non-user properties aren't currently supported
+-- Even if they were, the argument must be a string due to requirements of
+-- the ZCP api.
+neg_props["mountpoint"] = {"/foo/bar"}
+neg_props["copies"] = { "2" }
+
+-- read-only properties should never succeed
+neg_props["guid"] = { "12345" }
+
+set_fail = {}
+val_fail = {}
+
+-- Test properties that should work
+for prop, values in pairs(pos_props) do
+ for i, val in ipairs(values) do
+ old_val, src = zfs.get_prop(fs, prop)
+
+ -- Attempt to set the property to the specified value
+ err = zfs.sync.set_prop(fs, prop, val)
+
+ if (err ~= 0) then
+ set_fail[prop] = err -- tuple of prop, val that resulted in error
+ else
+ -- use get_prop to check that the set took effect
+ new_val, src = zfs.get_prop(fs, prop)
+ if (tostring(new_val) ~= tostring(val)) then
+ val_fail[prop] = new_val
+ end
+
+ -- We modified the prop, restore old value (if one existed)
+ if (old_val ~= nil) then
+ err = zfs.sync.set_prop(fs, prop, old_val)
+ if (err ~= 0) then return err end
+ else
+ -- Didn't have an old value, delete (inherit) instead
+ err = zfs.sync.inherit(fs, prop)
+ if (err ~= 0) then return err end
+ end
+ end
+ end
+end
+
+-- Test properties that should fail
+for prop, expected in pairs(neg_props) do
+ exp_val = expected[1]
+ exp_err = expected[2]
+
+ -- Attempt to set the property to the specified value
+ err = zfs.sync.set_prop(fs, prop, exp_val)
+ if (err == 0 or (exp_err ~= nil and err ~= exp_err)) then
+ set_fail[prop] = err -- tuple of prop, val that resulted in error
+ end
+end
+
+return {set_fail, val_fail}
diff --git a/usr/src/uts/common/Makefile.files b/usr/src/uts/common/Makefile.files
index 73479d6743..7cdeffa775 100644
--- a/usr/src/uts/common/Makefile.files
+++ b/usr/src/uts/common/Makefile.files
@@ -25,7 +25,7 @@
# Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
# Copyright 2018 Nexenta Systems, Inc.
# Copyright 2016 Garrett D'Amore <garrett@damore.org>
-# Copyright 2019 Joyent, Inc.
+# Copyright 2020 Joyent, Inc.
# Copyright 2016 OmniTI Computer Consulting, Inc. All rights reserved.
# Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
#
@@ -1411,6 +1411,7 @@ ZFS_COMMON_OBJS += \
zap_micro.o \
zcp.o \
zcp_get.o \
+ zcp_set.o \
zcp_global.o \
zcp_iter.o \
zcp_synctask.o \
diff --git a/usr/src/uts/common/fs/zfs/sys/zcp_set.h b/usr/src/uts/common/fs/zfs/sys/zcp_set.h
new file mode 100644
index 0000000000..3a31da8a05
--- /dev/null
+++ b/usr/src/uts/common/fs/zfs/sys/zcp_set.h
@@ -0,0 +1,48 @@
+/*
+ * CDDL HEADER START
+ *
+ * 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.
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2019 Joyent, Inc.
+ */
+
+#ifndef _SYS_ZCP_SET_H
+#define _SYS_ZCP_SET_H
+
+#include <sys/dmu_tx.h>
+#include <sys/dsl_pool.h>
+
+#include "lua.h"
+#include "lualib.h"
+#include "lauxlib.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct zcp_set_prop_arg {
+ lua_State *state;
+ const char *dsname;
+ const char *prop;
+ const char *val;
+} zcp_set_prop_arg_t;
+
+int zcp_set_prop_check(void *arg, dmu_tx_t *tx);
+void zcp_set_prop_sync(void *arg, dmu_tx_t *tx);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SYS_ZCP_SET_H */
diff --git a/usr/src/uts/common/fs/zfs/zcp_set.c b/usr/src/uts/common/fs/zfs/zcp_set.c
new file mode 100644
index 0000000000..17582421c3
--- /dev/null
+++ b/usr/src/uts/common/fs/zfs/zcp_set.c
@@ -0,0 +1,100 @@
+/*
+ * CDDL HEADER START
+ *
+ * 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.
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright (c) 2016 by Delphix. All rights reserved.
+ * Copyrigh 2020 Joyent, Inc.
+ */
+
+#include "lua.h"
+#include "lualib.h"
+#include "lauxlib.h"
+
+#include <sys/dsl_prop.h>
+#include <sys/dsl_dir.h>
+#include <sys/dsl_synctask.h>
+#include <sys/dsl_dataset.h>
+#include <sys/zcp.h>
+#include <sys/zcp_set.h>
+#include <sys/zcp_iter.h>
+#include <sys/zcp_global.h>
+#include <sys/zvol.h>
+
+#include <zfs_prop.h>
+
+static void
+zcp_set_user_prop(lua_State *state, dsl_pool_t *dp, const char *dsname,
+ const char *prop_name, const char *prop_val, dmu_tx_t *tx)
+{
+ dsl_dataset_t *ds = zcp_dataset_hold(state, dp, dsname, FTAG);
+ if (ds == NULL)
+ return; /* not reached; zcp_dataset_hold() longjmp'd */
+
+ nvlist_t *nvl = fnvlist_alloc();
+ fnvlist_add_string(nvl, prop_name, prop_val);
+
+ dsl_props_set_sync_impl(ds, ZPROP_SRC_LOCAL, nvl, tx);
+
+ fnvlist_free(nvl);
+ dsl_dataset_rele(ds, FTAG);
+}
+
+int
+zcp_set_prop_check(void *arg, dmu_tx_t *tx)
+{
+ zcp_set_prop_arg_t *args = arg;
+ const char *prop_name = args->prop;
+ dsl_props_set_arg_t dpsa = {
+ .dpsa_dsname = args->dsname,
+ .dpsa_source = ZPROP_SRC_LOCAL,
+ };
+ nvlist_t *nvl = NULL;
+ int ret = 0;
+
+ /*
+ * Only user properties are currently supported. When non-user
+ * properties are supported, we will want to use
+ * zfs_valid_proplist() to verify the properties.
+ */
+ if (!zfs_prop_user(prop_name)) {
+ return (EINVAL);
+ }
+
+ nvl = fnvlist_alloc();
+ fnvlist_add_string(nvl, args->prop, args->val);
+ dpsa.dpsa_props = nvl;
+
+ ret = dsl_props_set_check(&dpsa, tx);
+ nvlist_free(nvl);
+
+ return (ret);
+}
+
+void
+zcp_set_prop_sync(void *arg, dmu_tx_t *tx)
+{
+ zcp_set_prop_arg_t *args = arg;
+ zcp_run_info_t *ri = zcp_run_info(args->state);
+ dsl_pool_t *dp = ri->zri_pool;
+
+ const char *dsname = args->dsname;
+ const char *prop_name = args->prop;
+ const char *prop_val = args->val;
+
+ if (zfs_prop_user(prop_name)) {
+ zcp_set_user_prop(args->state, dp, dsname, prop_name,
+ prop_val, tx);
+ }
+}
diff --git a/usr/src/uts/common/fs/zfs/zcp_synctask.c b/usr/src/uts/common/fs/zfs/zcp_synctask.c
index f479a50ea3..09af25c1c9 100644
--- a/usr/src/uts/common/fs/zfs/zcp_synctask.c
+++ b/usr/src/uts/common/fs/zfs/zcp_synctask.c
@@ -22,6 +22,7 @@
#include "lauxlib.h"
#include <sys/zcp.h>
+#include <sys/zcp_set.h>
#include <sys/dsl_dir.h>
#include <sys/dsl_pool.h>
#include <sys/dsl_prop.h>
@@ -360,6 +361,44 @@ zcp_synctask_inherit_prop(lua_State *state, boolean_t sync,
return (err);
}
+static int zcp_synctask_set_prop(lua_State *, boolean_t, nvlist_t *err_details);
+static zcp_synctask_info_t zcp_synctask_set_prop_info = {
+ .name = "set_prop",
+ .func = zcp_synctask_set_prop,
+ .space_check = ZFS_SPACE_CHECK_RESERVED,
+ .blocks_modified = 2,
+ .pargs = {
+ { .za_name = "dataset", .za_lua_type = LUA_TSTRING},
+ { .za_name = "property", .za_lua_type = LUA_TSTRING},
+ { .za_name = "value", .za_lua_type = LUA_TSTRING},
+ { NULL, 0 }
+ },
+ .kwargs = {
+ { NULL, 0 }
+ }
+};
+
+static int
+zcp_synctask_set_prop(lua_State *state, boolean_t sync, nvlist_t *err_details)
+{
+ int err;
+ zcp_set_prop_arg_t args = { 0 };
+
+ const char *dsname = lua_tostring(state, 1);
+ const char *prop = lua_tostring(state, 2);
+ const char *val = lua_tostring(state, 3);
+
+ args.state = state;
+ args.dsname = dsname;
+ args.prop = prop;
+ args.val = val;
+
+ err = zcp_sync_task(state, zcp_set_prop_check, zcp_set_prop_sync,
+ &args, sync, dsname);
+
+ return (err);
+}
+
static int
zcp_synctask_wrapper(lua_State *state)
{
@@ -428,6 +467,7 @@ zcp_load_synctask_lib(lua_State *state, boolean_t sync)
&zcp_synctask_rollback_info,
&zcp_synctask_snapshot_info,
&zcp_synctask_inherit_prop_info,
+ &zcp_synctask_set_prop_info,
NULL
};