From f316bcea60e8292eeca0be4aa580e6cdc593b780 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 2 Nov 2022 14:19:10 -0400 Subject: [PATCH] rgw: move lua stuff out of req_state Signed-off-by: Casey Bodley --- src/rgw/rgw_common.h | 3 --- src/rgw/rgw_lua_data_filter.cc | 5 +++-- src/rgw/rgw_lua_request.cc | 7 ++++--- src/rgw/rgw_op.cc | 5 +++-- src/rgw/rgw_process.cc | 6 ++---- src/test/rgw/test_rgw_lua.cc | 34 +++++++++++++++++----------------- 6 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index ac380d7ed4f..f46fd0dea02 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -1218,9 +1218,6 @@ struct req_state : DoutPrefixProvider { //Principal tags that come in as part of AssumeRoleWithWebIdentity std::vector> principal_tags; - rgw::lua::Background* lua_background = nullptr; - rgw::sal::LuaManager* lua_manager = nullptr; - req_state(CephContext* _cct, const RGWProcessEnv& penv, RGWEnv* e, uint64_t id); ~req_state(); diff --git a/src/rgw/rgw_lua_data_filter.cc b/src/rgw/rgw_lua_data_filter.cc index 45cb877ad58..28052739016 100644 --- a/src/rgw/rgw_lua_data_filter.cc +++ b/src/rgw/rgw_lua_data_filter.cc @@ -2,6 +2,7 @@ #include "rgw_lua_utils.h" #include "rgw_lua_request.h" #include "rgw_lua_background.h" +#include "rgw_process_env.h" #include namespace rgw::lua { @@ -102,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->lua_background) { + if (s->penv.lua_background) { // create the "RGW" table - s->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 4ee66b6a816..a902d7345da 100644 --- a/src/rgw/rgw_lua_request.cc +++ b/src/rgw/rgw_lua_request.cc @@ -7,7 +7,8 @@ #include "rgw_lua.h" #include "rgw_common.h" #include "rgw_log.h" -#include "rgw_process.h" +#include "rgw_op.h" +#include "rgw_process_env.h" #include "rgw_zone.h" #include "rgw_acl.h" #include "rgw_sal_rados.h" @@ -878,8 +879,8 @@ int execute( lua_pushcclosure(L, RequestLog, FOUR_UPVALS); lua_rawset(L, -3); - if (s->lua_background) { - s->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_op.cc b/src/rgw/rgw_op.cc index 29552560b27..8258cffc604 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -47,6 +47,7 @@ #include "rgw_putobj_processor.h" #include "rgw_crypt.h" #include "rgw_perf_counters.h" +#include "rgw_process_env.h" #include "rgw_notify.h" #include "rgw_notify_event_type.h" #include "rgw_sal.h" @@ -2087,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* filter, RGWGetObj_Filter* cb) { std::string script; - const auto rc = rgw::lua::read_script(s, s->lua_manager, 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; @@ -3874,7 +3875,7 @@ static CompressorRef get_compressor_plugin(const req_state *s, int RGWPutObj::get_lua_filter(std::unique_ptr* filter, rgw::sal::DataProcessor* cb) { std::string script; - const auto rc = rgw::lua::read_script(s, s->lua_manager, 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 a9a752744d7..96e3cecf1a7 100644 --- a/src/rgw/rgw_process.cc +++ b/src/rgw/rgw_process.cc @@ -326,12 +326,10 @@ int process_request(const RGWProcessEnv& penv, abort_early(s, NULL, -ERR_METHOD_NOT_ALLOWED, handler, yield); goto done; } - s->lua_background = penv.lua_background; - s->lua_manager = penv.lua_manager.get(); { s->trace_enabled = tracing::rgw::tracer.is_enabled(); std::string script; - auto rc = rgw::lua::read_script(s, s->lua_manager, 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) { @@ -416,7 +414,7 @@ done: } } std::string script; - auto rc = rgw::lua::read_script(s, s->lua_manager, 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/test/rgw/test_rgw_lua.cc b/src/test/rgw/test_rgw_lua.cc index 68c1b115940..b68ad922f0e 100644 --- a/src/test/rgw/test_rgw_lua.cc +++ b/src/test/rgw/test_rgw_lua.cc @@ -1,8 +1,8 @@ #include #include "common/ceph_context.h" #include "rgw_common.h" -#include "rgw_auth.h" -#include "rgw_process.h" +#include "rgw_auth_registry.h" +#include "rgw_process_env.h" #include "rgw_sal_rados.h" #include "rgw_lua_request.h" #include "rgw_lua_background.h" @@ -163,7 +163,7 @@ CctCleaner cleaner(g_cct); tracing::Tracer tracer; -#define DEFINE_REQ_STATE RGWEnv e; req_state s(g_cct, &e, 0); +#define DEFINE_REQ_STATE RGWProcessEnv pe; RGWEnv e; req_state s(g_cct, pe, &e, 0); #define INIT_TRACE tracer.init("test"); \ s.trace = tracer.start_trace("test", true); @@ -774,7 +774,7 @@ TEST(TestRGWLuaBackground, RequestScript) )"; DEFINE_REQ_STATE; - s.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; - s.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; - s.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; - s.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; - s.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; - s.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; - s.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; - s.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; - s.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; - s.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; - s.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; - s.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; - s.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"; - s.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"); -- 2.39.5