]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: move lua stuff out of req_state
authorCasey Bodley <cbodley@redhat.com>
Wed, 2 Nov 2022 18:19:10 +0000 (14:19 -0400)
committerCasey Bodley <cbodley@redhat.com>
Fri, 9 Dec 2022 22:24:27 +0000 (17:24 -0500)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_common.h
src/rgw/rgw_lua_data_filter.cc
src/rgw/rgw_lua_request.cc
src/rgw/rgw_op.cc
src/rgw/rgw_process.cc
src/test/rgw/test_rgw_lua.cc

index ac380d7ed4f473c9798f0069013f0356663f3b01..f46fd0dea02253868884819d3cac3447159722fe 100644 (file)
@@ -1218,9 +1218,6 @@ struct req_state : DoutPrefixProvider {
   //Principal tags that come in as part of AssumeRoleWithWebIdentity
   std::vector<std::pair<std::string, std::string>> 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();
 
index 45cb877ad58335e713d60bc37b632512b668691e..2805273901675b986825f1aea1331446dda57d49 100644 (file)
@@ -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 <lua.hpp>
 
 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));
   }
index 4ee66b6a816bdc85c0a29c261e8999a84cca8a42..a902d7345daf9a399af960eabba85dd6e65279b4 100644 (file)
@@ -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));
   }
index 29552560b27cb82dafa109f960a0a5dc927bfe50..8258cffc604d96daa717f80304ee2be2b2372522 100644 (file)
@@ -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<RGWGetObj_Filter>* 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<rgw::sal::DataProcessor>* 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;
index a9a752744d7b9ff8d5d02b96616d0e01e8526660..96e3cecf1a7aead7af8c97f91ed3fb68acfc8914 100644 (file)
@@ -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) {
index 68c1b115940f75710cf06e42fea0b85666d3b986..b68ad922f0e2f041ca2bc1a3c9798c6344e64aa2 100644 (file)
@@ -1,8 +1,8 @@
 #include <gtest/gtest.h>
 #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");