]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/lua: split out a struct RGWLuaProcessEnv
authorCasey Bodley <cbodley@redhat.com>
Tue, 15 Nov 2022 13:51:44 +0000 (08:51 -0500)
committerCasey Bodley <cbodley@redhat.com>
Tue, 13 Dec 2022 18:52:58 +0000 (13:52 -0500)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_appmain.cc
src/rgw/rgw_lua_data_filter.cc
src/rgw/rgw_lua_request.cc
src/rgw/rgw_main.h
src/rgw/rgw_op.cc
src/rgw/rgw_process.cc
src/rgw/rgw_process_env.h
src/rgw/rgw_realm_reloader.cc
src/test/rgw/test_rgw_lua.cc

index 23c60074c4018e6ed419032e8af9f442ee6b70dc..396cc5b9b416ffe6e4ff41e3110a251584e7b8a4 100644 (file)
@@ -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 */
 
index 2805273901675b986825f1aea1331446dda57d49..9ebaf345388c7a4e7c053760a7bff93669a0e7a2 100644 (file)
@@ -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));
   }
index a902d7345daf9a399af960eabba85dd6e65279b4..53b055bf3883cc4ac74649c5e3fd18fe8fff7c70 100644 (file)
@@ -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));
   }
index d6e6de37a8c299271fe699e9821d3256b4b93e38..321fbfc8009e4c9d2fb202ce11f5a73afe98aa30 100644 (file)
@@ -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
index 8258cffc604d96daa717f80304ee2be2b2372522..a21c4a8aace51d22c03e4c91d777b684bcb9a21c 100644 (file)
@@ -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;
index 96e3cecf1a7aead7af8c97f91ed3fb68acfc8914..8d20251f8f7488abb95088d870f1b49395c54ce4 100644 (file)
@@ -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) {
index 5648add8649c12d5a07c5d5b490ecb546ea3638b..f1577608e3ccc92d89ad6805c864d62afea952a5 100644 (file)
@@ -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;
 };
index bb82c5ccbb60c1940910b135d2e1d4e6fc0a335c..182cf16392f2310b245ef4268a224d6fb9a06828 100644 (file)
@@ -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;
 
index b68ad922f0e2f041ca2bc1a3c9798c6344e64aa2..a539c025b50778d41565a40d97ef1283323d58ab 100644 (file)
@@ -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");