BRT should return EOPNOTSUPP
[zfs.git] / module / zfs / zcp_set.c
blobcebb56a5f181bd1710d31731e19e546460e061c3
1 /*
2 * CDDL HEADER START
4 * This file and its contents are supplied under the terms of the
5 * Common Development and Distribution License ("CDDL"), version 1.0.
6 * You may only use this file in accordance with the terms of version
7 * 1.0 of the CDDL.
9 * A full copy of the text of the CDDL should have accompanied this
10 * source. A copy of the CDDL is also available via the Internet at
11 * http://www.illumos.org/license/CDDL.
13 * CDDL HEADER END
17 * Copyright (c) 2016 by Delphix. All rights reserved.
18 * Copyrigh 2020 Joyent, Inc.
21 #include <sys/lua/lua.h>
22 #include <sys/lua/lualib.h>
23 #include <sys/lua/lauxlib.h>
25 #include <sys/dsl_prop.h>
26 #include <sys/dsl_dir.h>
27 #include <sys/dsl_synctask.h>
28 #include <sys/dsl_dataset.h>
29 #include <sys/zcp.h>
30 #include <sys/zcp_set.h>
31 #include <sys/zcp_iter.h>
32 #include <sys/zcp_global.h>
33 #include <sys/zvol.h>
35 #include <zfs_prop.h>
37 static void
38 zcp_set_user_prop(lua_State *state, dsl_pool_t *dp, const char *dsname,
39 const char *prop_name, const char *prop_val, dmu_tx_t *tx)
41 dsl_dataset_t *ds = zcp_dataset_hold(state, dp, dsname, FTAG);
42 if (ds == NULL)
43 return; /* not reached; zcp_dataset_hold() longjmp'd */
45 nvlist_t *nvl = fnvlist_alloc();
46 fnvlist_add_string(nvl, prop_name, prop_val);
48 dsl_props_set_sync_impl(ds, ZPROP_SRC_LOCAL, nvl, tx);
50 fnvlist_free(nvl);
51 dsl_dataset_rele(ds, FTAG);
54 int
55 zcp_set_prop_check(void *arg, dmu_tx_t *tx)
57 zcp_set_prop_arg_t *args = arg;
58 const char *prop_name = args->prop;
59 dsl_props_set_arg_t dpsa = {
60 .dpsa_dsname = args->dsname,
61 .dpsa_source = ZPROP_SRC_LOCAL,
63 nvlist_t *nvl = NULL;
64 int ret = 0;
67 * Only user properties are currently supported. When non-user
68 * properties are supported, we will want to use
69 * zfs_valid_proplist() to verify the properties.
71 if (!zfs_prop_user(prop_name)) {
72 return (EINVAL);
75 nvl = fnvlist_alloc();
76 fnvlist_add_string(nvl, args->prop, args->val);
77 dpsa.dpsa_props = nvl;
79 ret = dsl_props_set_check(&dpsa, tx);
80 nvlist_free(nvl);
82 return (ret);
85 void
86 zcp_set_prop_sync(void *arg, dmu_tx_t *tx)
88 zcp_set_prop_arg_t *args = arg;
89 zcp_run_info_t *ri = zcp_run_info(args->state);
90 dsl_pool_t *dp = ri->zri_pool;
92 const char *dsname = args->dsname;
93 const char *prop_name = args->prop;
94 const char *prop_val = args->val;
96 if (zfs_prop_user(prop_name)) {
97 zcp_set_user_prop(args->state, dp, dsname, prop_name,
98 prop_val, tx);