2 * Lua Bindings for RADOS Object Class
9 #include "include/types.h"
10 #include "objclass/objclass.h"
11 #include "json_spirit/json_spirit.h"
13 #include "cls_lua_ops.h"
19 * Jump point for recovering from Lua panic.
21 static jmp_buf cls_lua_panic_jump;
26 static int cls_lua_atpanic(lua_State *lua)
28 CLS_ERR("error: Lua panic: %s", lua_tostring(lua, -1));
29 longjmp(cls_lua_panic_jump, 1);
39 * Input parameter encoding.
47 struct clslua_err error;
51 cls_method_context_t *hctx;
52 bufferlist *inbl; // raw cls input
53 bufferlist *outbl; // raw cls output
55 string script; // lua script
56 string handler; // lua handler
57 bufferlist input; // lua handler input
60 /* Lua registry key for method context */
61 static char clslua_hctx_reg_key;
64 * Grabs the full method handler context
66 static clslua_hctx *__clslua_get_hctx(lua_State *L)
68 /* lookup registry value */
69 lua_pushlightuserdata(L, &clslua_hctx_reg_key);
70 lua_gettable(L, LUA_REGISTRYINDEX);
72 /* check cls_lua assumptions */
73 assert(!lua_isnil(L, -1));
74 assert(lua_type(L, -1) == LUA_TLIGHTUSERDATA);
76 /* cast and cleanup stack */
77 clslua_hctx *hctx = (struct clslua_hctx *)lua_touserdata(L, -1);
84 * Get the method context out of the registry. This is called at the beginning
85 * of each clx_cxx_* wrapper, and must be set before there is any chance a Lua
86 * script calling a 'cls' module function that requires it.
88 static cls_method_context_t clslua_get_hctx(lua_State *L)
90 struct clslua_hctx *hctx = __clslua_get_hctx(L);
95 * Returns a reference to cls_lua error state from registry.
97 struct clslua_err *clslua_checkerr(lua_State *L)
99 struct clslua_hctx *hctx = __clslua_get_hctx(L);
100 struct clslua_err *err = &hctx->error;
105 /* Registry key for real `pcall` function */
106 static char clslua_pcall_reg_key;
109 * Wrap Lua pcall to check for errors thrown by cls_lua (e.g. I/O errors or
110 * bufferlist decoding errors). The global error is cleared before returning
113 static int clslua_pcall(lua_State *L)
115 int nargs = lua_gettop(L);
116 lua_pushlightuserdata(L, &clslua_pcall_reg_key);
117 lua_gettable(L, LUA_REGISTRYINDEX);
119 lua_call(L, nargs, LUA_MULTRET);
120 struct clslua_err *err = clslua_checkerr(L);
124 lua_pushinteger(L, err->ret);
127 return lua_gettop(L);
134 static int clslua_log(lua_State *L)
136 int nargs = lua_gettop(L);
141 int loglevel = LOG_LEVEL_DEFAULT;
142 bool custom_ll = false;
144 /* check if first arg can be a log level */
145 if (nargs > 1 && lua_isnumber(L, 1)) {
146 int ll = (int)lua_tonumber(L, 1);
153 /* check space for args and seperators (" ") */
154 int nelems = ((nargs - (custom_ll ? 1 : 0)) * 2) - 1;
155 luaL_checkstack(L, nelems, "rados.log(..)");
157 for (int i = custom_ll ? 2 : 1; i <= nargs; i++) {
158 const char *part = lua_tostring(L, i);
160 if (lua_type(L, i) == LUA_TBOOLEAN)
161 part = lua_toboolean(L, i) ? "true" : "false";
163 part = luaL_typename(L, i);
165 lua_pushstring(L, part);
167 lua_pushstring(L, " ");
170 /* join string parts and send to Ceph/reply log */
171 lua_concat(L, nelems);
172 CLS_LOG(loglevel, "%s", lua_tostring(L, -1));
174 /* concat leaves result at top of stack */
178 static char clslua_registered_handle_reg_key;
181 * Register a function to be used as a handler target
183 static int clslua_register(lua_State *L)
185 luaL_checktype(L, 1, LUA_TFUNCTION);
187 /* get table of registered handlers */
188 lua_pushlightuserdata(L, &clslua_registered_handle_reg_key);
189 lua_gettable(L, LUA_REGISTRYINDEX);
190 assert(lua_type(L, -1) == LUA_TTABLE);
192 /* lookup function argument */
196 if (lua_isnil(L, -1)) {
201 lua_pushstring(L, "Cannot register handler more than once");
209 * Check if a function is registered as a handler
211 static void clslua_check_registered_handler(lua_State *L)
213 luaL_checktype(L, -1, LUA_TFUNCTION);
215 /* get table of registered handlers */
216 lua_pushlightuserdata(L, &clslua_registered_handle_reg_key);
217 lua_gettable(L, LUA_REGISTRYINDEX);
218 assert(lua_type(L, -1) == LUA_TTABLE);
220 /* lookup function argument */
221 lua_pushvalue(L, -2);
224 if (!lua_rawequal(L, -1, -3)) {
225 lua_pushstring(L, "Handler is not registered");
233 * Handle result of a cls_cxx_* call. If @ok is non-zero then we return with
234 * the number of Lua return arguments on the stack. Otherwise we save error
235 * information in the registry and throw a Lua error.
237 static int clslua_opresult(lua_State *L, int ok, int ret, int nargs,
238 bool error_on_stack = false)
240 struct clslua_err *err = clslua_checkerr(L);
244 CLS_ERR("error: cls_lua state machine: unexpected error");
248 /* everything is cherry */
252 /* set error in registry */
256 /* push error message */
258 lua_pushfstring(L, "%s", strerror(-ret));
266 static int clslua_create(lua_State *lua)
268 cls_method_context_t hctx = clslua_get_hctx(lua);
269 int exclusive = lua_toboolean(lua, 1);
271 int ret = cls_cxx_create(hctx, exclusive);
272 return clslua_opresult(lua, (ret == 0), ret, 0);
278 static int clslua_remove(lua_State *lua)
280 cls_method_context_t hctx = clslua_get_hctx(lua);
282 int ret = cls_cxx_remove(hctx);
283 return clslua_opresult(lua, (ret == 0), ret, 0);
289 static int clslua_stat(lua_State *L)
291 cls_method_context_t hctx = clslua_get_hctx(L);
295 int ret = cls_cxx_stat(hctx, &size, &mtime);
297 lua_pushinteger(L, size);
298 lua_pushinteger(L, mtime);
300 return clslua_opresult(L, (ret == 0), ret, 2);
306 static int clslua_read(lua_State *L)
308 cls_method_context_t hctx = clslua_get_hctx(L);
309 int offset = luaL_checkinteger(L, 1);
310 int length = luaL_checkinteger(L, 2);
311 bufferlist *bl = clslua_pushbufferlist(L, NULL);
312 int ret = cls_cxx_read(hctx, offset, length, bl);
313 return clslua_opresult(L, (ret >= 0), ret, 1);
319 static int clslua_write(lua_State *L)
321 cls_method_context_t hctx = clslua_get_hctx(L);
322 int offset = luaL_checkinteger(L, 1);
323 int length = luaL_checkinteger(L, 2);
324 bufferlist *bl = clslua_checkbufferlist(L, 3);
325 int ret = cls_cxx_write(hctx, offset, length, bl);
326 return clslua_opresult(L, (ret == 0), ret, 0);
332 static int clslua_write_full(lua_State *L)
334 cls_method_context_t hctx = clslua_get_hctx(L);
335 bufferlist *bl = clslua_checkbufferlist(L, 1);
336 int ret = cls_cxx_write_full(hctx, bl);
337 return clslua_opresult(L, (ret == 0), ret, 0);
343 static int clslua_getxattr(lua_State *L)
345 cls_method_context_t hctx = clslua_get_hctx(L);
346 const char *name = luaL_checkstring(L, 1);
347 bufferlist *bl = clslua_pushbufferlist(L, NULL);
348 int ret = cls_cxx_getxattr(hctx, name, bl);
349 return clslua_opresult(L, (ret >= 0), ret, 1);
355 static int clslua_getxattrs(lua_State *L)
357 cls_method_context_t hctx = clslua_get_hctx(L);
359 map<string, bufferlist> attrs;
360 int ret = cls_cxx_getxattrs(hctx, &attrs);
362 return clslua_opresult(L, 0, ret, 0);
364 lua_createtable(L, 0, attrs.size());
366 for (auto it = attrs.cbegin(); it != attrs.cend(); it++) {
367 lua_pushstring(L, it->first.c_str());
368 bufferlist *bl = clslua_pushbufferlist(L, NULL);
369 *bl = it->second; // xfer ownership... will be GC'd
373 return clslua_opresult(L, 1, ret, 1);
379 static int clslua_setxattr(lua_State *L)
381 cls_method_context_t hctx = clslua_get_hctx(L);
382 const char *name = luaL_checkstring(L, 1);
383 bufferlist *bl = clslua_checkbufferlist(L, 2);
384 int ret = cls_cxx_setxattr(hctx, name, bl);
385 return clslua_opresult(L, (ret == 0), ret, 1);
389 * cls_cxx_map_get_val
391 static int clslua_map_get_val(lua_State *L)
393 cls_method_context_t hctx = clslua_get_hctx(L);
394 const char *key = luaL_checkstring(L, 1);
395 bufferlist *bl = clslua_pushbufferlist(L, NULL);
396 int ret = cls_cxx_map_get_val(hctx, key, bl);
397 return clslua_opresult(L, (ret == 0), ret, 1);
401 * cls_cxx_map_set_val
403 static int clslua_map_set_val(lua_State *L)
405 cls_method_context_t hctx = clslua_get_hctx(L);
406 const char *key = luaL_checkstring(L, 1);
407 bufferlist *val = clslua_checkbufferlist(L, 2);
408 int ret = cls_cxx_map_set_val(hctx, key, val);
409 return clslua_opresult(L, (ret == 0), ret, 0);
415 static int clslua_map_clear(lua_State *L)
417 cls_method_context_t hctx = clslua_get_hctx(L);
418 int ret = cls_cxx_map_clear(hctx);
419 return clslua_opresult(L, (ret == 0), ret, 0);
423 * cls_cxx_map_get_keys
425 static int clslua_map_get_keys(lua_State *L)
427 cls_method_context_t hctx = clslua_get_hctx(L);
428 const char *start_after = luaL_checkstring(L, 1);
429 int max_to_get = luaL_checkinteger(L, 2);
431 std::set<string> keys;
433 int ret = cls_cxx_map_get_keys(hctx, start_after, max_to_get, &keys, &more);
435 return clslua_opresult(L, 0, ret, 0);
437 lua_createtable(L, 0, keys.size());
439 for (auto it = keys.cbegin(); it != keys.cend(); it++) {
440 const std::string& key = *it;
441 lua_pushstring(L, key.c_str());
442 lua_pushboolean(L, 1);
446 return clslua_opresult(L, 1, ret, 1);
450 * cls_cxx_map_get_vals
452 static int clslua_map_get_vals(lua_State *L)
454 cls_method_context_t hctx = clslua_get_hctx(L);
455 const char *start_after = luaL_checkstring(L, 1);
456 const char *filter_prefix= luaL_checkstring(L, 2);
457 int max_to_get = luaL_checkinteger(L, 3);
459 map<string, bufferlist> kvpairs;
461 int ret = cls_cxx_map_get_vals(hctx, start_after, filter_prefix,
462 max_to_get, &kvpairs, &more);
464 return clslua_opresult(L, 0, ret, 0);
466 lua_createtable(L, 0, kvpairs.size());
468 for (auto it = kvpairs.cbegin(); it != kvpairs.cend(); it++) {
469 lua_pushstring(L, it->first.c_str());
470 bufferlist *bl = clslua_pushbufferlist(L, NULL);
471 *bl = it->second; // xfer ownership... will be GC'd
475 return clslua_opresult(L, 1, ret, 1);
479 * cls_cxx_map_read_header
481 static int clslua_map_read_header(lua_State *L)
483 cls_method_context_t hctx = clslua_get_hctx(L);
484 bufferlist *bl = clslua_pushbufferlist(L, NULL);
485 int ret = cls_cxx_map_read_header(hctx, bl);
486 return clslua_opresult(L, (ret >= 0), ret, 1);
490 * cls_cxx_map_write_header
492 static int clslua_map_write_header(lua_State *L)
494 cls_method_context_t hctx = clslua_get_hctx(L);
495 bufferlist *bl = clslua_checkbufferlist(L, 1);
496 int ret = cls_cxx_map_write_header(hctx, bl);
497 return clslua_opresult(L, (ret == 0), ret, 0);
501 * cls_cxx_map_set_vals
503 static int clslua_map_set_vals(lua_State *L)
505 cls_method_context_t hctx = clslua_get_hctx(L);
506 luaL_checktype(L, 1, LUA_TTABLE);
508 map<string, bufferlist> kvpairs;
510 for (lua_pushnil(L); lua_next(L, 1); lua_pop(L, 1)) {
512 * In the case of a numeric key a copy is made on the stack because
513 * converting to a string would otherwise manipulate the original key and
514 * cause problems for iteration.
517 int type_code = lua_type(L, -2);
520 key.assign(lua_tolstring(L, -2, NULL));
524 lua_pushvalue(L, -2);
525 key.assign(lua_tolstring(L, -1, NULL));
530 lua_pushfstring(L, "map_set_vals: invalid key type (%s)",
531 lua_typename(L, type_code));
532 return clslua_opresult(L, 0, -EINVAL, 0, true);
536 type_code = lua_type(L, -1);
541 const char *data = lua_tolstring(L, -1, &len);
542 val.append(data, len);
547 lua_pushfstring(L, "map_set_vals: invalid val type (%s) for key (%s)",
548 lua_typename(L, type_code), key.c_str());
549 return clslua_opresult(L, 0, -EINVAL, 0, true);
555 int ret = cls_cxx_map_set_vals(hctx, &kvpairs);
557 return clslua_opresult(L, (ret == 0), ret, 0);
561 * cls_cxx_map_remove_key
563 static int clslua_map_remove_key(lua_State *L)
565 cls_method_context_t hctx = clslua_get_hctx(L);
566 const char *key = luaL_checkstring(L, 1);
567 int ret = cls_cxx_map_remove_key(hctx, key);
568 return clslua_opresult(L, (ret == 0), ret, 0);
572 * cls_current_version
574 static int clslua_current_version(lua_State *L)
576 cls_method_context_t hctx = clslua_get_hctx(L);
577 uint64_t version = cls_current_version(hctx);
578 lua_pushinteger(L, version);
579 return clslua_opresult(L, 1, 0, 1);
583 * cls_current_subop_num
585 static int clslua_current_subop_num(lua_State *L)
587 cls_method_context_t hctx = clslua_get_hctx(L);
588 int num = cls_current_subop_num(hctx);
589 lua_pushinteger(L, num);
590 return clslua_opresult(L, 1, 0, 1);
594 * cls_current_subop_version
596 static int clslua_current_subop_version(lua_State *L)
598 cls_method_context_t hctx = clslua_get_hctx(L);
600 cls_cxx_subop_version(hctx, &s);
601 lua_pushstring(L, s.c_str());
602 return clslua_opresult(L, 1, 0, 1);
606 * Functions registered in the 'cls' module.
608 static const luaL_Reg clslua_lib[] = {
610 {"register", clslua_register},
614 {"create", clslua_create},
615 {"remove", clslua_remove},
616 {"stat", clslua_stat},
617 {"read", clslua_read},
618 {"write", clslua_write},
619 {"write_full", clslua_write_full},
622 {"getxattr", clslua_getxattr},
623 {"getxattrs", clslua_getxattrs},
624 {"setxattr", clslua_setxattr},
627 {"map_clear", clslua_map_clear},
628 {"map_get_keys", clslua_map_get_keys},
629 {"map_get_vals", clslua_map_get_vals},
630 {"map_read_header", clslua_map_read_header},
631 {"map_write_header", clslua_map_write_header},
632 {"map_get_val", clslua_map_get_val},
633 {"map_set_val", clslua_map_set_val},
634 {"map_set_vals", clslua_map_set_vals},
635 {"map_remove_key", clslua_map_remove_key},
638 {"current_version", clslua_current_version},
639 {"current_subop_num", clslua_current_subop_num},
640 {"current_subop_version", clslua_current_subop_version},
646 * Set const int in table at top of stack
648 #define SET_INT_CONST(var) do { \
649 lua_pushinteger(L, var); \
650 lua_setfield(L, -2, #var); \
656 static int luaopen_objclass(lua_State *L)
661 * Register cls functions (cls.log, etc...)
663 luaL_setfuncs(L, clslua_lib, 0);
666 * Register generic errno values under 'cls'
668 SET_INT_CONST(EPERM);
669 SET_INT_CONST(ENOENT);
670 SET_INT_CONST(ESRCH);
671 SET_INT_CONST(EINTR);
673 SET_INT_CONST(ENXIO);
674 SET_INT_CONST(E2BIG);
675 SET_INT_CONST(ENOEXEC);
676 SET_INT_CONST(EBADF);
677 SET_INT_CONST(ECHILD);
678 SET_INT_CONST(EAGAIN);
679 SET_INT_CONST(ENOMEM);
680 SET_INT_CONST(EACCES);
681 SET_INT_CONST(EFAULT);
682 SET_INT_CONST(EBUSY);
683 SET_INT_CONST(EEXIST);
684 SET_INT_CONST(EXDEV);
685 SET_INT_CONST(ENODEV);
686 SET_INT_CONST(ENOTDIR);
687 SET_INT_CONST(EISDIR);
688 SET_INT_CONST(EINVAL);
689 SET_INT_CONST(ENFILE);
690 SET_INT_CONST(EMFILE);
691 SET_INT_CONST(ENOTTY);
692 SET_INT_CONST(EFBIG);
693 SET_INT_CONST(ENOSPC);
694 SET_INT_CONST(ESPIPE);
695 SET_INT_CONST(EROFS);
696 SET_INT_CONST(EMLINK);
697 SET_INT_CONST(EPIPE);
699 SET_INT_CONST(ERANGE);
705 * Setup the execution environment. Our sandbox currently is not
706 * sophisticated. With a new Lua state per-request we don't need to work about
707 * users stepping on each other, but we do rip out access to the local file
708 * system. All this will change when/if we decide to use some shared Lua
709 * states, most likely for performance reasons.
711 static void clslua_setup_env(lua_State *L)
713 luaL_requiref(L, "_G", luaopen_base, 1);
717 * Wrap `pcall` to intercept errors. First save a reference to the default
718 * Lua `pcall` function, and then replace `pcall` with our version.
720 lua_pushlightuserdata(L, &clslua_pcall_reg_key);
721 lua_getglobal(L, "pcall");
722 lua_settable(L, LUA_REGISTRYINDEX);
724 lua_pushcfunction(L, clslua_pcall);
725 lua_setglobal(L, "pcall");
729 lua_setglobal(L, "loadfile");
733 lua_setglobal(L, "dofile");
735 /* not integrated into our error handling */
737 lua_setglobal(L, "xpcall");
739 luaL_requiref(L, LUA_TABLIBNAME, luaopen_table, 1);
742 luaL_requiref(L, LUA_STRLIBNAME, luaopen_string, 1);
745 luaL_requiref(L, LUA_MATHLIBNAME, luaopen_math, 1);
748 luaL_requiref(L, "objclass", luaopen_objclass, 1);
751 luaL_requiref(L, "bufferlist", luaopen_bufferlist, 1);
760 * "input": "..." # optional
763 static int unpack_json_command(lua_State *L, struct clslua_hctx *ctx,
764 std::string& script, std::string& handler, std::string& input,
767 std::string json_input(ctx->inbl->c_str());
768 json_spirit::mValue value;
770 if (!json_spirit::read(json_input, value)) {
771 CLS_ERR("error: unparseable JSON");
776 if (value.type() != json_spirit::obj_type) {
777 CLS_ERR("error: input not a JSON object");
781 json_spirit::mObject obj = value.get_obj();
784 std::map<std::string, json_spirit::mValue>::const_iterator it = obj.find("script");
785 if (it == obj.end()) {
786 CLS_ERR("error: 'script' field found in JSON object");
791 if (it->second.type() != json_spirit::str_type) {
792 CLS_ERR("error: script is not a string");
796 script = it->second.get_str();
798 // grab the target function/handler name
799 it = obj.find("handler");
800 if (it == obj.end()) {
801 CLS_ERR("error: no target handler found in JSON object");
806 if (it->second.type() != json_spirit::str_type) {
807 CLS_ERR("error: target handler is not a string");
811 handler = it->second.get_str();
813 // grab the input (optional)
814 it = obj.find("input");
815 if (it != obj.end()) {
816 if (it->second.type() != json_spirit::str_type) {
817 CLS_ERR("error: handler input is not a string");
821 input = it->second.get_str();
822 *input_len = input.size();
829 * Runs the script, and calls handler.
831 static int clslua_eval(lua_State *L)
833 struct clslua_hctx *ctx = __clslua_get_hctx(L);
834 ctx->ret = -EIO; /* assume failure */
837 * Load modules, errno value constants, and other environment goodies. Must
838 * be done before loading/compiling the chunk.
843 * Deserialize the input that contains the script, the name of the handler
844 * to call, and the handler input.
846 switch (ctx->in_enc) {
849 std::string input_str;
850 size_t input_str_len = 0;
852 // if there is an error decoding json then ctx->ret will be set and we
853 // return normally from this function.
854 if (unpack_json_command(L, ctx, ctx->script, ctx->handler, input_str,
858 bufferptr bp(input_str.c_str(), input_str_len);
859 ctx->input.push_back(bp);
868 bufferlist::iterator it = ctx->inbl->begin();
870 } catch (const buffer::error &err) {
871 CLS_ERR("error: could not decode ceph encoded input");
876 ctx->script.swap(op.script);
877 ctx->handler.swap(op.handler);
878 ctx->input = op.input;
883 CLS_ERR("error: unknown encoding type");
890 * Create table to hold registered (valid) handlers.
892 * Must be done before running the script for the first time because the
893 * script will immediately try to register one or more handlers using
894 * cls.register(function), which depends on this table.
896 lua_pushlightuserdata(L, &clslua_registered_handle_reg_key);
898 lua_settable(L, LUA_REGISTRYINDEX);
900 /* load and compile chunk */
901 if (luaL_loadstring(L, ctx->script.c_str()))
907 /* no error, but nothing left to do */
908 if (!ctx->handler.size()) {
909 CLS_LOG(10, "no handler name provided");
910 ctx->ret = 0; /* success */
914 lua_getglobal(L, ctx->handler.c_str());
915 if (lua_type(L, -1) != LUA_TFUNCTION) {
916 CLS_ERR("error: unknown handler or not function: %s", ctx->handler.c_str());
917 ctx->ret = -EOPNOTSUPP;
921 /* throw error if function is not registered */
922 clslua_check_registered_handler(L);
924 /* setup the input/output bufferlists */
925 clslua_pushbufferlist(L, &ctx->input);
926 clslua_pushbufferlist(L, ctx->outbl);
929 * Call the target Lua object class handler. If the call is successful then
930 * we will examine the return value here and store it in the context. Errors
931 * that occur are handled in the top-level eval() function.
933 int top = lua_gettop(L);
934 lua_call(L, 2, LUA_MULTRET);
936 /* store return value in context */
937 if (!(lua_gettop(L) + 3 - top))
938 lua_pushinteger(L, 0);
939 ctx->ret = luaL_checkinteger(L, -1);
945 * Main handler. Proxies the Lua VM and the Lua-defined handler.
947 static int eval_generic(cls_method_context_t hctx, bufferlist *in, bufferlist *out,
948 InputEncoding in_enc)
950 struct clslua_hctx ctx;
954 /* stash context for use in Lua VM */
959 ctx.error.error = false;
961 /* build lua vm state */
964 CLS_ERR("error creating new Lua state");
968 /* panic handler for unhandled errors */
969 lua_atpanic(L, &cls_lua_atpanic);
971 if (setjmp(cls_lua_panic_jump) == 0) {
974 * Stash the handler context in the register. It contains the objclass
975 * method context, global error state, and the command and reply structs.
977 lua_pushlightuserdata(L, &clslua_hctx_reg_key);
978 lua_pushlightuserdata(L, &ctx);
979 lua_settable(L, LUA_REGISTRYINDEX);
981 /* Process the input and run the script */
982 lua_pushcfunction(L, clslua_eval);
983 ret = lua_pcall(L, 0, 0, 0);
985 /* Encountered an error? */
987 struct clslua_err *err = clslua_checkerr(L);
989 CLS_ERR("error: cls_lua state machine: unexpected error");
993 /* Error origin a cls_cxx_* method? */
995 ret = err->ret; /* cls_cxx_* return value */
997 /* Errors always abort. Fix up ret and log error */
999 CLS_ERR("error: unexpected handler return value");
1004 ret = -EIO; /* Generic error code */
1006 CLS_ERR("error: %s", lua_tostring(L, -1));
1010 * No Lua error encountered while running the script, but the handler
1011 * may still have returned an error code (e.g. an errno value).
1017 CLS_ERR("error: recovering from Lua panic");
1027 static int eval_json(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
1029 return eval_generic(hctx, in, out, JSON_ENC);
1032 static int eval_bufferlist(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
1034 return eval_generic(hctx, in, out, BUFFERLIST_ENC);
1039 CLS_LOG(20, "Loaded lua class!");
1041 cls_handle_t h_class;
1042 cls_method_handle_t h_eval_json;
1043 cls_method_handle_t h_eval_bufferlist;
1045 cls_register("lua", &h_class);
1047 cls_register_cxx_method(h_class, "eval_json",
1048 CLS_METHOD_RD | CLS_METHOD_WR, eval_json, &h_eval_json);
1050 cls_register_cxx_method(h_class, "eval_bufferlist",
1051 CLS_METHOD_RD | CLS_METHOD_WR, eval_bufferlist, &h_eval_bufferlist);