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 *, uint64_t, uint64_t, nvpair_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 *);
50 typedef struct zcp_run_info
{
54 * An estimate of the total ammount of space consumed by all
55 * synctasks we have successfully performed so far in this
56 * channel program. Used to generate ENOSPC errors for syncfuncs.
61 * The credentials of the thread which originally invoked the channel
62 * program. Since channel programs are always invoked from the synctask
63 * thread they should always do permissions checks against this cred
64 * rather than the 'current' thread's.
69 * The tx in which this channel program is running.
74 * The maximum number of Lua instructions the channel program is allowed
75 * to execute. If it takes longer than this it will time out. A value
76 * of 0 indicates no instruction limit.
78 uint64_t zri_maxinstrs
;
81 * The number of Lua instructions the channel program has executed.
83 uint64_t zri_curinstrs
;
86 * Boolean indicating whether or not the channel program exited
87 * because it timed out.
89 boolean_t zri_timed_out
;
92 * The currently registered cleanup function, which will be called
93 * with the stored argument if a fatal error occurs.
95 zcp_cleanup_t
*zri_cleanup
;
96 void *zri_cleanup_arg
;
99 zcp_run_info_t
*zcp_run_info(lua_State
*);
100 void zcp_register_cleanup(lua_State
*, zcp_cleanup_t
, void *);
101 void zcp_clear_cleanup(lua_State
*);
102 void zcp_cleanup(lua_State
*);
105 * Argument parsing routines for channel program callback functions.
107 typedef struct zcp_arg
{
109 * The name of this argument. For keyword arguments this is the name
110 * functions will use to set the argument. For positional arguments
111 * the name has no programatic meaning, but will appear in error
112 * messages and help output.
117 * The Lua type this argument should have (e.g. LUA_TSTRING,
118 * LUA_TBOOLEAN) see the lua_type() function documentation for a
119 * complete list. Calling a function with an argument that does
120 * not match the expected type will result in the program terminating.
122 const int za_lua_type
;
125 void zcp_parse_args(lua_State
*, const char *, const zcp_arg_t
*,
127 int zcp_nvlist_to_lua(lua_State
*, nvlist_t
*, char *, int);
128 int zcp_dataset_hold_error(lua_State
*, dsl_pool_t
*, const char *, int);
129 struct dsl_dataset
*zcp_dataset_hold(lua_State
*, dsl_pool_t
*,
130 const char *, void *);
132 typedef int (zcp_lib_func_t
)(lua_State
*);
133 typedef struct zcp_lib_info
{
135 zcp_lib_func_t
*func
;
136 const zcp_arg_t pargs
[4];
137 const zcp_arg_t kwargs
[2];
144 #endif /* _SYS_ZCP_H */