diff options
author | Casey Bodley <cbodley@redhat.com> | 2022-11-15 14:51:44 +0100 |
---|---|---|
committer | Casey Bodley <cbodley@redhat.com> | 2022-12-13 19:52:58 +0100 |
commit | 9b13b835217eb7e2141a8158317557df692e17a5 (patch) | |
tree | 5feafc8078bd5ebfb155be75df0a48fd0149ffa7 /src | |
parent | rgw: move lua stuff out of req_state (diff) | |
download | ceph-9b13b835217eb7e2141a8158317557df692e17a5.tar.xz ceph-9b13b835217eb7e2141a8158317557df692e17a5.zip |
rgw/lua: split out a struct RGWLuaProcessEnv
Signed-off-by: Casey Bodley <cbodley@redhat.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/rgw/rgw_appmain.cc | 9 | ||||
-rw-r--r-- | src/rgw/rgw_lua_data_filter.cc | 4 | ||||
-rw-r--r-- | src/rgw/rgw_lua_request.cc | 4 | ||||
-rw-r--r-- | src/rgw/rgw_main.h | 3 | ||||
-rw-r--r-- | src/rgw/rgw_op.cc | 4 | ||||
-rw-r--r-- | src/rgw/rgw_process.cc | 4 | ||||
-rw-r--r-- | src/rgw/rgw_process_env.h | 8 | ||||
-rw-r--r-- | src/rgw/rgw_realm_reloader.cc | 1 | ||||
-rw-r--r-- | src/test/rgw/test_rgw_lua.cc | 28 |
9 files changed, 36 insertions, 29 deletions
diff --git a/src/rgw/rgw_appmain.cc b/src/rgw/rgw_appmain.cc index 23c60074c40..396cc5b9b41 100644 --- a/src/rgw/rgw_appmain.cc +++ b/src/rgw/rgw_appmain.cc @@ -407,8 +407,6 @@ int rgw::AppMain::init_frontends2(RGWLib* rgwlib) env.auth_registry = rgw::auth::StrategyRegistry::create( dpp->get_cct(), *implicit_tenant_context, env.driver); env.ratelimiting = ratelimiter.get(); - env.lua_background = lua_background.get(); - env.lua_manager = env.driver->get_lua_manager(); int fe_count = 0; for (multimap<string, RGWFrontendConfig *>::iterator fiter = fe_map.begin(); @@ -472,8 +470,8 @@ int rgw::AppMain::init_frontends2(RGWLib* rgwlib) fe_pauser = std::make_unique<RGWFrontendPauser>(fes, pusher.get()); rgw_pauser = std::make_unique<RGWPauser>(); rgw_pauser->add_pauser(fe_pauser.get()); - if (lua_background) { - rgw_pauser->add_pauser(lua_background.get()); + if (env.lua.background) { + rgw_pauser->add_pauser(env.lua.background); } reloader = std::make_unique<RGWRealmReloader>( env, *implicit_tenant_context, service_map_meta, rgw_pauser.get()); @@ -536,10 +534,13 @@ void rgw::AppMain::init_lua() } #endif + env.lua.manager = env.driver->get_lua_manager(); + if (driver->get_name() == "rados") { /* Supported for only RadosStore */ lua_background = std::make_unique< rgw::lua::Background>(driver, dpp->get_cct(), driver->get_luarocks_path()); lua_background->start(); + env.lua.background = lua_background.get(); } } /* init_lua */ diff --git a/src/rgw/rgw_lua_data_filter.cc b/src/rgw/rgw_lua_data_filter.cc index 28052739016..9ebaf345388 100644 --- a/src/rgw/rgw_lua_data_filter.cc +++ b/src/rgw/rgw_lua_data_filter.cc @@ -103,9 +103,9 @@ int RGWObjFilter::execute(bufferlist& bl, off_t offset, const char* op_name) con lua_pushinteger(L, offset); lua_setglobal(L, "Offset"); - if (s->penv.lua_background) { + if (s->penv.lua.background) { // create the "RGW" table - s->penv.lua_background->create_background_metatable(L); + s->penv.lua.background->create_background_metatable(L); lua_getglobal(L, rgw::lua::RGWTable::TableName().c_str()); ceph_assert(lua_istable(L, -1)); } diff --git a/src/rgw/rgw_lua_request.cc b/src/rgw/rgw_lua_request.cc index a902d7345da..53b055bf388 100644 --- a/src/rgw/rgw_lua_request.cc +++ b/src/rgw/rgw_lua_request.cc @@ -879,8 +879,8 @@ int execute( lua_pushcclosure(L, RequestLog, FOUR_UPVALS); lua_rawset(L, -3); - if (s->penv.lua_background) { - s->penv.lua_background->create_background_metatable(L); + if (s->penv.lua.background) { + s->penv.lua.background->create_background_metatable(L); lua_getglobal(L, rgw::lua::RGWTable::TableName().c_str()); ceph_assert(lua_istable(L, -1)); } diff --git a/src/rgw/rgw_main.h b/src/rgw/rgw_main.h index d6e6de37a8c..321fbfc8009 100644 --- a/src/rgw/rgw_main.h +++ b/src/rgw/rgw_main.h @@ -25,7 +25,6 @@ #include "rgw_realm_reloader.h" #include "rgw_ldap.h" #include "rgw_lua.h" -#include "rgw_lua_background.h" #include "rgw_dmclock_scheduler_ctx.h" #include "rgw_ratelimit.h" @@ -51,6 +50,8 @@ public: namespace rgw { +namespace lua { class Background; } + class RGWLib; class AppMain { /* several components should be initalized only if librgw is diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 8258cffc604..a21c4a8aace 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -2088,7 +2088,7 @@ int RGWGetObj::get_data_cb(bufferlist& bl, off_t bl_ofs, off_t bl_len) int RGWGetObj::get_lua_filter(std::unique_ptr<RGWGetObj_Filter>* filter, RGWGetObj_Filter* cb) { std::string script; - const auto rc = rgw::lua::read_script(s, s->penv.lua_manager.get(), s->bucket_tenant, s->yield, rgw::lua::context::getData, script); + const auto rc = rgw::lua::read_script(s, s->penv.lua.manager.get(), s->bucket_tenant, s->yield, rgw::lua::context::getData, script); if (rc == -ENOENT) { // no script, nothing to do return 0; @@ -3875,7 +3875,7 @@ static CompressorRef get_compressor_plugin(const req_state *s, int RGWPutObj::get_lua_filter(std::unique_ptr<rgw::sal::DataProcessor>* filter, rgw::sal::DataProcessor* cb) { std::string script; - const auto rc = rgw::lua::read_script(s, s->penv.lua_manager.get(), s->bucket_tenant, s->yield, rgw::lua::context::putData, script); + const auto rc = rgw::lua::read_script(s, s->penv.lua.manager.get(), s->bucket_tenant, s->yield, rgw::lua::context::putData, script); if (rc == -ENOENT) { // no script, nothing to do return 0; diff --git a/src/rgw/rgw_process.cc b/src/rgw/rgw_process.cc index 96e3cecf1a7..8d20251f8f7 100644 --- a/src/rgw/rgw_process.cc +++ b/src/rgw/rgw_process.cc @@ -329,7 +329,7 @@ int process_request(const RGWProcessEnv& penv, { s->trace_enabled = tracing::rgw::tracer.is_enabled(); std::string script; - auto rc = rgw::lua::read_script(s, penv.lua_manager.get(), s->bucket_tenant, s->yield, rgw::lua::context::preRequest, script); + auto rc = rgw::lua::read_script(s, penv.lua.manager.get(), s->bucket_tenant, s->yield, rgw::lua::context::preRequest, script); if (rc == -ENOENT) { // no script, nothing to do } else if (rc < 0) { @@ -414,7 +414,7 @@ done: } } std::string script; - auto rc = rgw::lua::read_script(s, penv.lua_manager.get(), s->bucket_tenant, s->yield, rgw::lua::context::postRequest, script); + auto rc = rgw::lua::read_script(s, penv.lua.manager.get(), s->bucket_tenant, s->yield, rgw::lua::context::postRequest, script); if (rc == -ENOENT) { // no script, nothing to do } else if (rc < 0) { diff --git a/src/rgw/rgw_process_env.h b/src/rgw/rgw_process_env.h index 5648add8649..f1577608e3c 100644 --- a/src/rgw/rgw_process_env.h +++ b/src/rgw/rgw_process_env.h @@ -20,12 +20,16 @@ namespace rgw::sal { class LuaManager; } +struct RGWLuaProcessEnv { + rgw::lua::Background* background = nullptr; + std::unique_ptr<rgw::sal::LuaManager> manager; +}; + struct RGWProcessEnv { + RGWLuaProcessEnv lua; rgw::sal::Driver* driver = nullptr; RGWREST *rest = nullptr; OpsLogSink *olog = nullptr; std::unique_ptr<rgw::auth::StrategyRegistry> auth_registry; ActiveRateLimiter* ratelimiting = nullptr; - rgw::lua::Background* lua_background = nullptr; - std::unique_ptr<rgw::sal::LuaManager> lua_manager; }; diff --git a/src/rgw/rgw_realm_reloader.cc b/src/rgw/rgw_realm_reloader.cc index bb82c5ccbb6..182cf16392f 100644 --- a/src/rgw/rgw_realm_reloader.cc +++ b/src/rgw/rgw_realm_reloader.cc @@ -180,6 +180,7 @@ void RGWRealmReloader::reload() * the dynamic reconfiguration. */ env.auth_registry = rgw::auth::StrategyRegistry::create( cct, implicit_tenants, env.driver); + env.lua.manager = env.driver->get_lua_manager(); ldpp_dout(&dp, 1) << "Resuming frontends with new realm configuration." << dendl; diff --git a/src/test/rgw/test_rgw_lua.cc b/src/test/rgw/test_rgw_lua.cc index b68ad922f0e..a539c025b50 100644 --- a/src/test/rgw/test_rgw_lua.cc +++ b/src/test/rgw/test_rgw_lua.cc @@ -774,7 +774,7 @@ TEST(TestRGWLuaBackground, RequestScript) )"; DEFINE_REQ_STATE; - pe.lua_background = &lua_background; + pe.lua.background = &lua_background; // to make sure test is consistent we have to puase the background lua_background.pause(); @@ -925,7 +925,7 @@ TEST(TestRGWLuaBackground, TableValues) )"; DEFINE_REQ_STATE; - pe.lua_background = &lua_background; + pe.lua.background = &lua_background; const auto rc = lua::request::execute(nullptr, nullptr, nullptr, &s, nullptr, request_script); ASSERT_EQ(rc, 0); @@ -946,7 +946,7 @@ TEST(TestRGWLuaBackground, TablePersist) )"; DEFINE_REQ_STATE; - pe.lua_background = &lua_background; + pe.lua.background = &lua_background; auto rc = lua::request::execute(nullptr, nullptr, nullptr, &s, nullptr, request_script); ASSERT_EQ(rc, 0); @@ -980,7 +980,7 @@ TEST(TestRGWLuaBackground, TableValuesFromRequest) )"; DEFINE_REQ_STATE; - pe.lua_background = &lua_background; + pe.lua.background = &lua_background; s.tagset.add_tag("key1", "val1"); s.tagset.add_tag("key2", "val1"); @@ -1010,7 +1010,7 @@ TEST(TestRGWLuaBackground, TableInvalidValue) )"; DEFINE_REQ_STATE; - pe.lua_background = &lua_background; + pe.lua.background = &lua_background; s.tagset.add_tag("key1", "val1"); s.tagset.add_tag("key2", "val2"); @@ -1036,7 +1036,7 @@ TEST(TestRGWLuaBackground, TableErase) )"; DEFINE_REQ_STATE; - pe.lua_background = &lua_background; + pe.lua.background = &lua_background; auto rc = lua::request::execute(nullptr, nullptr, nullptr, &s, nullptr, request_script); ASSERT_EQ(rc, 0); @@ -1078,7 +1078,7 @@ TEST(TestRGWLuaBackground, TableIterate) )"; DEFINE_REQ_STATE; - pe.lua_background = &lua_background; + pe.lua.background = &lua_background; const auto rc = lua::request::execute(nullptr, nullptr, nullptr, &s, nullptr, request_script); ASSERT_EQ(rc, 0); @@ -1104,7 +1104,7 @@ TEST(TestRGWLuaBackground, TableIncrement) )"; DEFINE_REQ_STATE; - pe.lua_background = &lua_background; + pe.lua.background = &lua_background; const auto rc = lua::request::execute(nullptr, nullptr, nullptr, &s, nullptr, request_script); ASSERT_EQ(rc, 0); @@ -1127,7 +1127,7 @@ TEST(TestRGWLuaBackground, TableIncrementBy) )"; DEFINE_REQ_STATE; - pe.lua_background = &lua_background; + pe.lua.background = &lua_background; const auto rc = lua::request::execute(nullptr, nullptr, nullptr, &s, nullptr, request_script); ASSERT_EQ(rc, 0); @@ -1148,7 +1148,7 @@ TEST(TestRGWLuaBackground, TableDecrement) )"; DEFINE_REQ_STATE; - pe.lua_background = &lua_background; + pe.lua.background = &lua_background; const auto rc = lua::request::execute(nullptr, nullptr, nullptr, &s, nullptr, request_script); ASSERT_EQ(rc, 0); @@ -1171,7 +1171,7 @@ TEST(TestRGWLuaBackground, TableDecrementBy) )"; DEFINE_REQ_STATE; - pe.lua_background = &lua_background; + pe.lua.background = &lua_background; const auto rc = lua::request::execute(nullptr, nullptr, nullptr, &s, nullptr, request_script); ASSERT_EQ(rc, 0); @@ -1189,7 +1189,7 @@ TEST(TestRGWLuaBackground, TableIncrementValueError) )"; DEFINE_REQ_STATE; - pe.lua_background = &lua_background; + pe.lua.background = &lua_background; auto rc = lua::request::execute(nullptr, nullptr, nullptr, &s, nullptr, request_script); ASSERT_NE(rc, 0); @@ -1225,7 +1225,7 @@ TEST(TestRGWLuaBackground, TableIncrementError) )"; DEFINE_REQ_STATE; - pe.lua_background = &lua_background; + pe.lua.background = &lua_background; auto rc = lua::request::execute(nullptr, nullptr, nullptr, &s, nullptr, request_script); ASSERT_NE(rc, 0); @@ -1309,7 +1309,7 @@ TEST(TestRGWLua, Data) TestBackground lua_background(store.get(), ""); DEFINE_REQ_STATE; s.host_id = "foo"; - pe.lua_background = &lua_background; + pe.lua.background = &lua_background; lua::RGWObjFilter filter(&s, script); bufferlist bl; bl.append("The quick brown fox jumps over the lazy dog"); |