aboutsummaryrefslogtreecommitdiffstats
path: root/module/zfs
diff options
context:
space:
mode:
authorJason King <[email protected]>2020-02-14 15:41:42 -0600
committerGitHub <[email protected]>2020-02-14 13:41:42 -0800
commit13b5a4d5c018f94d04efefcec6205aa73205e05f (patch)
tree8cc7dce83989cd6bceac7735344c651e1b9919c1 /module/zfs
parent4fe3a842bb53e7cebcdcd69deae758ccfb0660e9 (diff)
Support setting user properties in a channel program
This adds support for setting user properties in a zfs channel program by adding 'zfs.sync.set_prop' and 'zfs.check.set_prop' to the ZFS LUA API. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Matt Ahrens <[email protected]> Co-authored-by: Sara Hartse <[email protected]> Contributions-by: Jason King <[email protected]> Signed-off-by: Sara Hartse <[email protected]> Signed-off-by: Jason King <[email protected]> Closes #9950
Diffstat (limited to 'module/zfs')
-rw-r--r--module/zfs/Makefile.in1
-rw-r--r--module/zfs/zcp_set.c100
-rw-r--r--module/zfs/zcp_synctask.c40
3 files changed, 141 insertions, 0 deletions
diff --git a/module/zfs/Makefile.in b/module/zfs/Makefile.in
index 129c83eb7..1ba7db27b 100644
--- a/module/zfs/Makefile.in
+++ b/module/zfs/Makefile.in
@@ -105,6 +105,7 @@ $(MODULE)-objs += zcp.o
$(MODULE)-objs += zcp_get.o
$(MODULE)-objs += zcp_global.o
$(MODULE)-objs += zcp_iter.o
+$(MODULE)-objs += zcp_set.o
$(MODULE)-objs += zcp_synctask.o
$(MODULE)-objs += zfeature.o
$(MODULE)-objs += zfs_byteswap.o
diff --git a/module/zfs/zcp_set.c b/module/zfs/zcp_set.c
new file mode 100644
index 000000000..cebb56a5f
--- /dev/null
+++ b/module/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 <sys/lua/lua.h>
+#include <sys/lua/lualib.h>
+#include <sys/lua/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/module/zfs/zcp_synctask.c b/module/zfs/zcp_synctask.c
index a6f7a04c7..350b1e8e2 100644
--- a/module/zfs/zcp_synctask.c
+++ b/module/zfs/zcp_synctask.c
@@ -23,6 +23,7 @@
#include <sys/lua/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>
@@ -414,6 +415,44 @@ zcp_synctask_bookmark(lua_State *state, boolean_t sync, nvlist_t *err_details)
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)
{
@@ -484,6 +523,7 @@ zcp_load_synctask_lib(lua_State *state, boolean_t sync)
&zcp_synctask_snapshot_info,
&zcp_synctask_inherit_prop_info,
&zcp_synctask_bookmark_info,
+ &zcp_synctask_set_prop_info,
NULL
};