Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua object class support #7338

Merged
merged 2 commits into from
Sep 22, 2016
Merged

Lua object class support #7338

merged 2 commits into from
Sep 22, 2016

Conversation

dotnwat
Copy link
Contributor

@dotnwat dotnwat commented Jan 24, 2016

No description provided.

@yuyuyu101
Copy link
Member

COOL!

Not sure we need to contains lua source in ceph repo. Specify a external directory may better?

@cxwshawn
Copy link

cool! looking forward to being merged !

@liewegas
Copy link
Member

Does it makes sense to use a submodule instead of an extracted tarball for lua?

@dotnwat
Copy link
Contributor Author

dotnwat commented Jan 26, 2016

@yuyuyu101 @liewegas I have no issue with Lua being in a submodule (what's the motivation?) The only important thing is that we control that submodule because we may want to customize the VM in the future, but I'm assuming I target a ceph/lua repo?

@liewegas
Copy link
Member

liewegas commented Jan 26, 2016 via email

@dotnwat
Copy link
Contributor Author

dotnwat commented Jan 26, 2016

sounds good. i'll need to have someone create ceph/lua repo.. looks like I don't have permission.

@liewegas
Copy link
Member

liewegas commented Jan 26, 2016 via email

@dotnwat
Copy link
Contributor Author

dotnwat commented Jan 27, 2016

Thanks. I need push access to that repo. It isn't a vanilla Lua distribution, and its build configuration has been modified to assume cmake, so we'll need to hack it a bit to play nice with automake too.

@batrick
Copy link
Member

batrick commented Jan 28, 2016

Hi @noahdesu, this is an exciting feature! I'm still looking through the code and have yet to try this out but I was wondering why you include Roberto's Lua struct module when Lua 5.3 now has a pack function (which is loosely based on struct).

@dotnwat
Copy link
Contributor Author

dotnwat commented Jan 28, 2016

Hey @batrick thanks for pointing that out! I didn't realize that Lua 5.3 had this function. I wanted to include some useful serialization modules out-of-the-box so people could immediately start using this. It sounds like it might be OK to nuke the struct module for now. Let me know if you have any other questions or issues using cls_lua.

target_include_directories(cephlua
PUBLIC lua/lua-5.3.2/src/
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we move the cmake bits into a lua/CMakeLists.txt please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely. I'm in the process of stuffing Lua into a git submodule and I'll add this to the todo list.

@dotnwat
Copy link
Contributor Author

dotnwat commented Jan 30, 2016

@liewegas mind adding me to ceph/lua so I can push there?

@yehudasa
Copy link
Member

@noahdesu I updated the permissions there

@dotnwat
Copy link
Contributor Author

dotnwat commented Feb 1, 2016

Thanks @yehudasa that worked. @liewegas ok got it all submodule-ified. @cbodley could you take a look at the new cmake files?

@cbodley
Copy link
Contributor

cbodley commented Feb 1, 2016

@noahdesu the cmake looks good, thanks. i'll check it out and make sure it builds for me too

@dotnwat
Copy link
Contributor Author

dotnwat commented Feb 7, 2016

Rebased to remove merge recent merge conflicts.

cls_method_context_t hctx = clslua_get_hctx(L);
const char *key = luaL_checkstring(L, 1);
bufferlist *bl = clslua_pushbufferlist(L, NULL);
int ret = cls_cxx_map_get_val(hctx, key, bl);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe ret needs to be negated on error right? In my tests, it returns a negative value which gives us:

Unknown error -2

in the logs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean negated to resolve to the correct errno string via strerror, or negated to change the logic?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get the correct errno string I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this Patrick. I pushed a fix for it that seems to work (note that I also rebased to fix a merge conflict in master) 50739d7

@athanatos
Copy link
Contributor

There was some discussion of this at one of the recent CDM's. I think one of the main concerns was that we need a mechanism to whitelist classes for users?

@dotnwat
Copy link
Contributor Author

dotnwat commented Jun 27, 2016

@athanatos yes. i just created PR #9972 for review, that adds the loading and caps whitelist changes for object classes.

@ktdreyer
Copy link
Member

ktdreyer commented Aug 4, 2016

Noah, could you build against the system lua instead of bundling it into Ceph? (for example RHEL/CentOS 7 have lua-devel-5.1.4-14.el7)

When we bundle lua's source code into Ceph, the Ceph build time becomes longer, and the Ceph project becomes responsible for fixing CVEs in the bundled version, etc.

@batrick
Copy link
Member

batrick commented Aug 4, 2016

Does RHEL7 have Lua 5.3? Optionally building against the system Lua 5.3 sounds reasonable to me.

Also, Lua's source is pretty small. On my humble laptop a parallel make builds in 2.5 seconds.

@dotnwat
Copy link
Contributor Author

dotnwat commented Aug 4, 2016

I'm not opposed to linking against a system library, but it seems the precedent is to avoid this when embedding the VM mostly due to compatibility and customization issues. For instance Redis disables byte-code execution with a patch to the VM source, and other things are possible like switching out the native numeric data type.

From the Lua documentation: "Different versions are really different. The API is likely to be a little different (but with compatibility switches), and there is no ABI compatibility: applications that embed Lua and C libraries for Lua must be recompiled. The virtual machine is also very likely to be different in a new version: Lua programs that have been precompiled for one version will not load in a different version."

That might be manageable when creating releases, but strikes me as a headache waiting to happen especially for people mixing Lua versions. Thoughts?

@ktdreyer
Copy link
Member

ktdreyer commented Aug 4, 2016

There are pros and cons to bundling, and I wanted to at least have the discussion so I understand why we're doing it in each case. As long as the team is ok maintaining it when security fixes come up, I'm ok with it.

@dotnwat
Copy link
Contributor Author

dotnwat commented Aug 4, 2016

Sounds good. I'm happy to do any tests or research on the issue for everyone to agree on an approach.

@dotnwat
Copy link
Contributor Author

dotnwat commented Aug 9, 2016

the libgmock_main.so problem was caused by some cmake stuff that the lua submodule was doing that was causing various other libraries to be built as shared libraries rather than the expected static variety.

@yuriw anyway, let's give this a shot again. i was able to install from packages on deb/rhel and things are working now.

@tchaikov
Copy link
Contributor

tchaikov commented Aug 9, 2016

the libgmock_main.so problem was caused by some cmake stuff that the lua submodule was doing that was causing various other libraries to be built as shared libraries rather than the expected static variety.

@noahdesu in case you didn't find it, see https://github.com/ceph/lua/blob/lua-5.1/cmake/dist.cmake#L77 . i suffered from this when working with gmock also. we need to reset this variable after including the lua subdirectory, or save and restore it before and after including the lua subdirectory.

@dotnwat
Copy link
Contributor Author

dotnwat commented Aug 9, 2016

@tchaikov nice thanks for the reference, that was a tough one to track down. is there any reason to patch the lua variable? when i was reading through dist.cmake i didn't see anything in there we care about. it was packaging and installation stuff.

@tchaikov
Copy link
Contributor

tchaikov commented Aug 9, 2016

Noah, see https://cmake.org/cmake/help/v3.0/variable/BUILD_SHARED_LIBS.html . this variable changes the default behavior of add_library(). and as we are including lua, not building it as a separated module, this variable actually impacts the whole project, including the gmock, which is also included by us.

@dotnwat dotnwat removed the needs-qa label Aug 9, 2016
@dotnwat
Copy link
Contributor Author

dotnwat commented Aug 9, 2016

@tchaikov cool thanks. i'll get that fixed up tomorrow.

@dotnwat
Copy link
Contributor Author

dotnwat commented Aug 9, 2016

@tchaikov I think I misread your comment. I understand the global impact of the BUILD_SHARED_LIBS variable. I was asking about patching it indirectly: that variable is set in lua/cmake/dist.cmake which contains stuff related to installation and packaging---cmake boilerplate that we do not depend on, including shared library building which doesn't matter since we build lua as a static library. So I disabled the entire inclusion of lua/cmake/dist.cmake, including the BUILD_SHARED_LIBS global variable. This file also sets numerous cmake variables, so we don't need to worry about them clobbering other settings either.

@batrick
Copy link
Member

batrick commented Aug 9, 2016

@noahdesu, have you seen the thread on ceph-devel concerning Lua packaging? I'd link to it but gmane appears down (maybe permanently).

In particular, I'm concerned about including Ceph libraries in the lua submodule. Can those be moved src/cls/lua?

@dotnwat dotnwat removed the needs-qa label Aug 9, 2016
@dotnwat
Copy link
Contributor Author

dotnwat commented Aug 9, 2016

@batrick thanks for the pointer, i'll chime in on the list. about your question here: you are referring to cmsgpack and the bufferlist bindings? absolutely, they can be moved to src/cls/lua. lua was originally moved to a submodule and the reason people wanted that was that it 1) screwed up LOC stats and 2) ostensibly was easier to manage. Since I didn't author cmsgpack it seemed more appropriate there, but its easy to move. The reasoning behind leaving bufferlist bindings there was because it was general purpose.

@tchaikov
Copy link
Contributor

I was asking about patching it indirectly: that variable is set in lua/cmake/dist.cmake which contains stuff related to installation and packaging---cmake boilerplate that we do not depend on, including shared library building which doesn't matter since we build lua as a static library. So I disabled the entire inclusion of lua/cmake/dist.cmake, including the BUILD_SHARED_LIBS global variable.

@noahdesu sorry, i failed to understand your question. ic. i thought a less intrusive way would be easier for maintenance. but when i am looking at https://github.com/ceph/lua/commits/lua-5.3-ceph: well, we have already added a handful of patches on top of lua-5.3 branch, yet another one won't hurt. =)

@michaelsevilla
Copy link
Contributor

What is the status on this?

@dotnwat
Copy link
Contributor Author

dotnwat commented Sep 2, 2016

I need to take another look at the thread on ceph-devel to make sure nothing is missing, but I think we just need to slap needs-qa back on this.

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
Introduces cls_lua that allows object classes to be created dynamically
using the Lua language. Each request is processed in an empty Lua VM
instance, and scripts can be submitted using bufferlist or JSON
encoding.

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
@batrick batrick deleted the cls-lua branch September 23, 2016 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.