diff options
author | Adam Manzanares <nmtadam@gmail.com> | 2013-02-15 15:25:42 -0800 |
---|---|---|
committer | Noah Watkins <noahwatkins@gmail.com> | 2013-08-25 08:58:27 -0700 |
commit | 4e3c9e3ceb902be178c93f7028cf3669f1cc52eb (patch) | |
tree | ef892333204d34c253a39b22fcbe37d45d8d81ec | |
parent | 038688f3610eb2faba72c8246ded865ec46cdced (diff) | |
download | ceph-4e3c9e3ceb902be178c93f7028cf3669f1cc52eb.tar.gz |
lua: support cls_cxx_write and bufferlist::length
Signed-off-by: Adam Manzanares <nmtadam@gmail.com>
Reviewed-by: Noah Watkins <noahwatkins@gmail.com>
-rw-r--r-- | src/cls/lua/cls_lua.cc | 13 | ||||
-rw-r--r-- | src/liblua/src/lua_bufferlist.cc | 11 | ||||
-rw-r--r-- | src/test/cls_lua/test_cls_lua.cc | 19 | ||||
-rw-r--r-- | src/test/cls_lua/test_script.lua | 9 |
4 files changed, 52 insertions, 0 deletions
diff --git a/src/cls/lua/cls_lua.cc b/src/cls/lua/cls_lua.cc index bf4dc6a6e16..d846df3c226 100644 --- a/src/cls/lua/cls_lua.cc +++ b/src/cls/lua/cls_lua.cc @@ -301,6 +301,18 @@ static int clslua_read(lua_State *L) } /* + * cls_cxx_write + */ +static int clslua_write(lua_State *L){ + cls_method_context_t hctx = clslua_get_hctx(L); + int offset = luaL_checkint(L, 1); + int length = luaL_checkint(L, 2); + bufferlist *bl = clslua_checkbufferlist(L, 3); + int ret = cls_cxx_write(hctx, offset, length, bl); + return clslua_opresult(L, (ret == 0), ret, 0); +} + +/* * cls_cxx_map_get_val */ static int clslua_map_get_val(lua_State *L) @@ -334,6 +346,7 @@ static const luaL_Reg clslua_lib[] = { {"remove", clslua_remove}, {"stat", clslua_stat}, {"read", clslua_read}, + {"write", clslua_write}, {"map_get_val", clslua_map_get_val}, {"map_set_val", clslua_map_set_val}, {NULL, NULL} diff --git a/src/liblua/src/lua_bufferlist.cc b/src/liblua/src/lua_bufferlist.cc index bb2b6084633..09abb755d25 100644 --- a/src/liblua/src/lua_bufferlist.cc +++ b/src/liblua/src/lua_bufferlist.cc @@ -78,6 +78,16 @@ static int bl_append(lua_State *L) } /* + * Return the length in bytes of bufferlist + */ +static int bl_length(lua_State *L) +{ + bufferlist *bl = clslua_checkbufferlist(L); + lua_pushinteger(L, bl->length()); + return 1; +} + +/* * Perform byte-for-byte bufferlist equality test */ static int bl_eq(lua_State *L) @@ -104,6 +114,7 @@ static int bl_gc(lua_State *L) static const struct luaL_Reg bufferlist_methods[] = { {"str", bl_str}, {"append", bl_append}, + {"length", bl_length}, {"__gc", bl_gc}, {"__eq", bl_eq}, {NULL, NULL} diff --git a/src/test/cls_lua/test_cls_lua.cc b/src/test/cls_lua/test_cls_lua.cc index e73577f6a8a..666ffa3c2b4 100644 --- a/src/test/cls_lua/test_cls_lua.cc +++ b/src/test/cls_lua/test_cls_lua.cc @@ -123,6 +123,25 @@ librados::IoCtx ClsLua::ioctx; string ClsLua::pool_name; string ClsLua::test_script; +TEST_F(ClsLua, Write) { + /* write some data into object */ + string written = "Hello World"; + bufferlist inbl; + ::encode(written, inbl); + ASSERT_EQ(0, clslua_exec(test_script, &inbl, "write")); + + /* have Lua read out of the object */ + uint64_t size; + bufferlist outbl; + ASSERT_EQ(0, ioctx.stat(oid, &size, NULL)); + ASSERT_EQ(size, (uint64_t)ioctx.read(oid, outbl, size, 0) ); + + /* compare what Lua read to what we wrote */ + string read; + ::decode(read, outbl); + ASSERT_EQ(read, written); +} + TEST_F(ClsLua, SyntaxError) { ASSERT_EQ(-EIO, clslua_exec("-")); } diff --git a/src/test/cls_lua/test_script.lua b/src/test/cls_lua/test_script.lua index 73c602a9087..39f25974c3c 100644 --- a/src/test/cls_lua/test_script.lua +++ b/src/test/cls_lua/test_script.lua @@ -16,6 +16,15 @@ end cls.register(read) -- +-- Write +-- +function write(input, output) + cls.write(0, input:length(), input) +end + +cls.register(write) + +-- -- MsgPack -- function msgpack(input, output) |