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