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
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.
17 * Copyright (c) 2016, 2017 by Delphix. All rights reserved.
23 #include <sys/dmu_tx.h>
24 #include <sys/dsl_pool.h>
34 #define ZCP_RUN_INFO_KEY "runinfo"
36 extern uint64_t zfs_lua_max_instrlimit;
37 extern uint64_t zfs_lua_max_memlimit;
39 int zcp_argerror(lua_State *, int, const char *, ...);
41 int zcp_eval(const char *, const char *, boolean_t, uint64_t, uint64_t,
42 nvpair_t *, nvlist_t *);
44 int zcp_load_list_lib(lua_State *);
46 int zcp_load_synctask_lib(lua_State *, boolean_t);
48 typedef void (zcp_cleanup_t)(void *);
49 typedef struct zcp_cleanup_handler {
50 zcp_cleanup_t *zch_cleanup_func;
51 void *zch_cleanup_arg;
53 } zcp_cleanup_handler_t;
55 typedef struct zcp_alloc_arg {
56 boolean_t aa_must_succeed;
57 int64_t aa_alloc_remaining;
58 int64_t aa_alloc_limit;
61 typedef struct zcp_run_info {
65 * An estimate of the total amount of space consumed by all
66 * synctasks we have successfully performed so far in this
67 * channel program. Used to generate ENOSPC errors for syncfuncs.
72 * The credentials of the thread which originally invoked the channel
73 * program. Since channel programs are always invoked from the synctask
74 * thread they should always do permissions checks against this cred
75 * rather than the 'current' thread's.
80 * The tx in which this channel program is running.
85 * The maximum number of Lua instructions the channel program is allowed
86 * to execute. If it takes longer than this it will time out. A value
87 * of 0 indicates no instruction limit.
89 uint64_t zri_maxinstrs;
92 * The number of Lua instructions the channel program has executed.
94 uint64_t zri_curinstrs;
97 * Boolean indicating whether or not the channel program exited
98 * because it timed out.
100 boolean_t zri_timed_out;
103 * Channel program was canceled by user
105 boolean_t zri_canceled;
108 * Boolean indicating whether or not we are running in syncing
114 * List of currently registered cleanup handlers, which will be
115 * triggered in the event of a fatal error.
117 list_t zri_cleanup_handlers;
120 * The Lua state context of our channel program.
122 lua_State *zri_state;
125 * Lua memory allocator arguments.
127 zcp_alloc_arg_t *zri_allocargs;
130 * Contains output values from zcp script or error string.
132 nvlist_t *zri_outnvl;
135 * The errno number returned to caller of zcp_eval().
140 zcp_run_info_t *zcp_run_info(lua_State *);
141 zcp_cleanup_handler_t *zcp_register_cleanup(lua_State *, zcp_cleanup_t, void *);
142 void zcp_deregister_cleanup(lua_State *, zcp_cleanup_handler_t *);
143 void zcp_cleanup(lua_State *);
146 * Argument parsing routines for channel program callback functions.
148 typedef struct zcp_arg {
150 * The name of this argument. For keyword arguments this is the name
151 * functions will use to set the argument. For positional arguments
152 * the name has no programatic meaning, but will appear in error
153 * messages and help output.
158 * The Lua type this argument should have (e.g. LUA_TSTRING,
159 * LUA_TBOOLEAN) see the lua_type() function documentation for a
160 * complete list. Calling a function with an argument that does
161 * not match the expected type will result in the program terminating.
163 const int za_lua_type;
166 void zcp_parse_args(lua_State *, const char *, const zcp_arg_t *,
168 int zcp_nvlist_to_lua(lua_State *, nvlist_t *, char *, int);
169 int zcp_dataset_hold_error(lua_State *, dsl_pool_t *, const char *, int);
170 struct dsl_dataset *zcp_dataset_hold(lua_State *, dsl_pool_t *,
171 const char *, void *);
173 typedef int (zcp_lib_func_t)(lua_State *);
174 typedef struct zcp_lib_info {
176 zcp_lib_func_t *func;
177 const zcp_arg_t pargs[4];
178 const zcp_arg_t kwargs[2];
185 #endif /* _SYS_ZCP_H */