diff options
-rw-r--r-- | src/Makefile.am | 11 | ||||
-rw-r--r-- | src/cls/lua/cls_lua_client.cc | 47 | ||||
-rw-r--r-- | src/cls/lua/cls_lua_client.hpp | 20 |
3 files changed, 78 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index f811ca22045..53ba26adfb9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -483,6 +483,13 @@ rados_SOURCES = rados.cc rados_import.cc rados_export.cc rados_sync.cc common/ob rados_LDADD = libcls_lock_client.a librados.la $(LIBGLOBAL_LDA) bin_PROGRAMS += rados +libcls_lua_client_la_SOURCES = \ + cls/lua/cls_lua_client.cc \ + cls/lua/cls_lua_client.hpp +libcls_lua_client_la_CXXFLAGS = ${AM_CXXFLAGS} +libcls_lua_client_la_LIBADD = librados.la +lib_LTLIBRARIES += libcls_lua_client.la + if WITH_REST_BENCH rest_bench_SOURCES = tools/rest_bench.cc common/obj_bencher.cc @@ -1472,6 +1479,10 @@ rados_include_DATA = \ $(srcdir)/include/page.h \ $(srcdir)/include/crc32c.h +libcls_lua_client_includedir = $(includedir)/cls_lua +libcls_lua_client_include_DATA = \ + $(srcdir)/cls/lua/cls_lua_client.hpp + #crush_includedir = $(includedir)/crush #crush_include_DATA = \ # $(srcdir)/crush/hash.h \ diff --git a/src/cls/lua/cls_lua_client.cc b/src/cls/lua/cls_lua_client.cc new file mode 100644 index 00000000000..fef12b2b084 --- /dev/null +++ b/src/cls/lua/cls_lua_client.cc @@ -0,0 +1,47 @@ +#include <errno.h> +#include <string> +#include <vector> +#include "include/encoding.h" +#include "include/rados.h" +#include "include/rados/librados.h" +#include "include/types.h" +#include "cls_lua.h" +#include "cls_lua_client.hpp" + +using std::string; +using std::vector; +using librados::IoCtx; +using librados::bufferlist; + +namespace cls_lua_client { + + int exec(IoCtx& ioctx, const string& oid, const string& script, + const string& handler, bufferlist& input, bufferlist& output, + vector<string> *log) + { + struct clslua_cmd cmd; + struct clslua_reply reply; + bufferlist outbl, inbl; + int ret; + + cmd.script = script; + cmd.funcname = handler; + cmd.input = input; + ::encode(cmd, inbl); + + ret = ioctx.exec(oid, "lua", "eval", inbl, outbl); + + try { + ::decode(reply, outbl); + } catch (const buffer::error &err) { + return -EBADMSG; + } + + output = reply.output; + if (log) + log->swap(reply.log); + + return ret; + } + +} diff --git a/src/cls/lua/cls_lua_client.hpp b/src/cls/lua/cls_lua_client.hpp new file mode 100644 index 00000000000..64c7e4f6edd --- /dev/null +++ b/src/cls/lua/cls_lua_client.hpp @@ -0,0 +1,20 @@ +#ifndef CLS_LUA_CLIENT_HPP +#define CLS_LUA_CLIENT_HPP +#include <string> +#include <vector> + +#ifdef __CEPH__ +#include "include/rados/librados.hpp" +#else +# include <rados/librados.hpp> +#endif + +namespace cls_lua_client { + + int exec(librados::IoCtx& ioctx, const std::string& oid, + const std::string& script, const std::string& handler, + librados::bufferlist& inbl, librados::bufferlist& outbl, + std::vector<std::string> *log = NULL); +} + +#endif |