diff options
author | Kaleb S. KEITHLEY <kkeithle@redhat.com> | 2022-08-01 23:30:32 +0200 |
---|---|---|
committer | Kaleb S. KEITHLEY <kkeithle@redhat.com> | 2022-08-02 23:09:44 +0200 |
commit | 10bc82fb00e50472689660f8ea705a1f9135508d (patch) | |
tree | 5cbaa759935870cdd68d71c9966cf6ef09a0b26a /src/rgw/rgw_lua.cc | |
parent | Merge pull request #47334 from s0nea/wip-osd-objectstore-types-fix (diff) | |
download | ceph-10bc82fb00e50472689660f8ea705a1f9135508d.tar.xz ceph-10bc82fb00e50472689660f8ea705a1f9135508d.zip |
rgw: lua, add support for lua packages to the lua manager
Refactor lua manager, adding new {add,remove}_package(), and
list_packages() methods; and changing get(), put(), del() methods
to {get,put,del}_script(). Renaming class from *LuaScriptManager
to *LuaManager to be consistent with dual *script and *package
functionality.
Note: I considered keeping the existing *LuaScriptManager classes
as is and adding *LuaPackageManager classes, but that seemed/seems
like overkill to me.
Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
Diffstat (limited to 'src/rgw/rgw_lua.cc')
-rw-r--r-- | src/rgw/rgw_lua.cc | 96 |
1 files changed, 23 insertions, 73 deletions
diff --git a/src/rgw/rgw_lua.cc b/src/rgw/rgw_lua.cc index 323cc5ed0f6..e0f61049b60 100644 --- a/src/rgw/rgw_lua.cc +++ b/src/rgw/rgw_lua.cc @@ -8,7 +8,6 @@ #ifdef WITH_RADOSGW_LUA_PACKAGES #include <filesystem> #include <boost/process.hpp> -#include "rgw_lua_version.h" #endif #define dout_subsys ceph_subsys_rgw @@ -70,32 +69,31 @@ std::string script_oid(context ctx, const std::string& tenant) { int read_script(const DoutPrefixProvider *dpp, rgw::sal::Store* store, const std::string& tenant, optional_yield y, context ctx, std::string& script) { - auto lua_script = store->get_lua_script_manager(); + auto lua_mgr = store->get_lua_manager(); - return lua_script->get(dpp, y, script_oid(ctx, tenant), script); + return lua_mgr->get_script(dpp, y, script_oid(ctx, tenant), script); } int write_script(const DoutPrefixProvider *dpp, rgw::sal::Store* store, const std::string& tenant, optional_yield y, context ctx, const std::string& script) { - auto lua_script = store->get_lua_script_manager(); + auto lua_mgr = store->get_lua_manager(); - return lua_script->put(dpp, y, script_oid(ctx, tenant), script); + return lua_mgr->put_script(dpp, y, script_oid(ctx, tenant), script); } int delete_script(const DoutPrefixProvider *dpp, rgw::sal::Store* store, const std::string& tenant, optional_yield y, context ctx) { - auto lua_script = store->get_lua_script_manager(); + auto lua_mgr = store->get_lua_manager(); - return lua_script->del(dpp, y, script_oid(ctx, tenant)); + return lua_mgr->del_script(dpp, y, script_oid(ctx, tenant)); } #ifdef WITH_RADOSGW_LUA_PACKAGES -const std::string PACKAGE_LIST_OBJECT_NAME = "lua_package_allowlist"; - namespace bp = boost::process; -int add_package(const DoutPrefixProvider *dpp, rgw::sal::RadosStore* store, optional_yield y, const std::string& package_name, bool allow_compilation) { +int add_package(const DoutPrefixProvider *dpp, rgw::sal::Store* store, optional_yield y, const std::string& package_name, bool allow_compilation) +{ // verify that luarocks can load this package const auto p = bp::search_path("luarocks"); if (p.empty()) { @@ -122,7 +120,7 @@ int add_package(const DoutPrefixProvider *dpp, rgw::sal::RadosStore* store, opti if (!package_found) { return -EINVAL; } - + //replace previous versions of the package const std::string package_name_no_version = package_name.substr(0, package_name.find(" ")); ret = remove_package(dpp, store, y, package_name_no_version); @@ -130,76 +128,28 @@ int add_package(const DoutPrefixProvider *dpp, rgw::sal::RadosStore* store, opti return ret; } - // add package to list - const bufferlist empty_bl; - std::map<std::string, bufferlist> new_package{{package_name, empty_bl}}; - librados::ObjectWriteOperation op; - op.omap_set(new_package); - ret = rgw_rados_operate(dpp, *(store->getRados()->get_lc_pool_ctx()), - PACKAGE_LIST_OBJECT_NAME, &op, y); + auto lua_mgr = store->get_lua_manager(); - if (ret < 0) { - return ret; - } - return 0; + return lua_mgr->add_package(dpp, y, package_name); } -int remove_package(const DoutPrefixProvider *dpp, rgw::sal::RadosStore* store, optional_yield y, const std::string& package_name) { - librados::ObjectWriteOperation op; - size_t pos = package_name.find(" "); - if (pos != package_name.npos) { - // remove specfic version of the the package - op.omap_rm_keys(std::set<std::string>({package_name})); - auto ret = rgw_rados_operate(dpp, *(store->getRados()->get_lc_pool_ctx()), - PACKAGE_LIST_OBJECT_NAME, &op, y); - if (ret < 0) { - return ret; - } - return 0; - } - // otherwise, remove any existing versions of the package - packages_t packages; - auto ret = list_packages(dpp, store, y, packages); - if (ret < 0 && ret != -ENOENT) { - return ret; - } - for(const auto& package : packages) { - const std::string package_no_version = package.substr(0, package.find(" ")); - if (package_no_version.compare(package_name) == 0) { - op.omap_rm_keys(std::set<std::string>({package})); - ret = rgw_rados_operate(dpp, *(store->getRados()->get_lc_pool_ctx()), - PACKAGE_LIST_OBJECT_NAME, &op, y); - if (ret < 0) { - return ret; - } - } - } - return 0; +int remove_package(const DoutPrefixProvider *dpp, rgw::sal::Store* store, optional_yield y, const std::string& package_name) +{ + auto lua_mgr = store->get_lua_manager(); + + return lua_mgr->remove_package(dpp, y, package_name); } -int list_packages(const DoutPrefixProvider *dpp, rgw::sal::RadosStore* store, optional_yield y, packages_t& packages) { - constexpr auto max_chunk = 1024U; - std::string start_after; - bool more = true; - int rval; - while (more) { - librados::ObjectReadOperation op; - packages_t packages_chunk; - op.omap_get_keys2(start_after, max_chunk, &packages_chunk, &more, &rval); - const auto ret = rgw_rados_operate(dpp, *(store->getRados()->get_lc_pool_ctx()), - PACKAGE_LIST_OBJECT_NAME, &op, nullptr, y); - - if (ret < 0) { - return ret; - } +namespace bp = boost::process; - packages.merge(packages_chunk); - } - - return 0; +int list_packages(const DoutPrefixProvider *dpp, rgw::sal::Store* store, optional_yield y, packages_t& packages) +{ + auto lua_mgr = store->get_lua_manager(); + + return lua_mgr->list_packages(dpp, y, packages); } -int install_packages(const DoutPrefixProvider *dpp, rgw::sal::RadosStore* store, optional_yield y, packages_t& failed_packages, std::string& output) { +int install_packages(const DoutPrefixProvider *dpp, rgw::sal::Store* store, optional_yield y, packages_t& failed_packages, std::string& output) { // luarocks directory cleanup std::error_code ec; const auto& luarocks_path = store->get_luarocks_path(); |