From: Casey Bodley Date: Wed, 2 Nov 2022 18:15:51 +0000 (-0400) Subject: rgw: req_state takes const ref to RGWProcessEnv X-Git-Tag: v18.1.0~650^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=195a4b5170a9c7dc31a5b6580e3b9f4ac141ed1f;p=ceph.git rgw: req_state takes const ref to RGWProcessEnv make the RGWProcessEnv accessible to any call paths that have a req_state Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index 422874b4f4d9..31aa6f92a188 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -269,8 +269,9 @@ void req_info::rebuild_from(req_info& src) } -req_state::req_state(CephContext* _cct, RGWEnv* e, uint64_t id) - : cct(_cct), info(_cct, e), id(id) +req_state::req_state(CephContext* _cct, const RGWProcessEnv& penv, + RGWEnv* e, uint64_t id) + : cct(_cct), penv(penv), info(_cct, e), id(id) { enable_ops_log = e->get_enable_ops_log(); enable_usage_log = e->get_enable_usage_log(); diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 6784f6248280..ac380d7ed4f4 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -56,6 +56,8 @@ namespace rgw::lua { class Background; } +struct RGWProcessEnv; + using ceph::crypto::MD5; #define RGW_ATTR_PREFIX "user.rgw." @@ -1068,6 +1070,7 @@ class RGWObjectCtx; /** Store all the state necessary to complete and respond to an HTTP request*/ struct req_state : DoutPrefixProvider { CephContext *cct; + const RGWProcessEnv& penv; rgw::io::BasicClient *cio{nullptr}; http_op op{OP_UNKNOWN}; RGWOpType op_type{}; @@ -1218,7 +1221,7 @@ struct req_state : DoutPrefixProvider { rgw::lua::Background* lua_background = nullptr; rgw::sal::LuaManager* lua_manager = nullptr; - req_state(CephContext* _cct, RGWEnv* e, uint64_t id); + req_state(CephContext* _cct, const RGWProcessEnv& penv, RGWEnv* e, uint64_t id); ~req_state(); diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index eaaedd4da8b6..54e913f5a54e 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -1659,10 +1659,12 @@ namespace rgw { return -EIO; } + const RGWProcessEnv& penv = g_rgwlib->get_fe()->get_process()->get_env(); + /* start */ std::string object_name = relative_object_name(); f->write_req = - new RGWWriteRequest(g_rgwlib->get_driver(), + new RGWWriteRequest(g_rgwlib->get_driver(), penv, g_rgwlib->get_driver()->get_user(fs->get_user()->user_id), this, bucket_name(), object_name); rc = g_rgwlib->get_fe()->start_req(f->write_req); diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index ef8e7b5ce07d..fbda86ba4cb3 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -2489,11 +2489,11 @@ public: size_t bytes_written; bool eio; - RGWWriteRequest(rgw::sal::Driver* driver, + RGWWriteRequest(rgw::sal::Driver* driver, const RGWProcessEnv& penv, std::unique_ptr _user, RGWFileHandle* _fh, const std::string& _bname, const std::string& _oname) - : RGWLibContinuedReq(driver->ctx(), std::move(_user)), + : RGWLibContinuedReq(driver->ctx(), penv, std::move(_user)), bucket_name(_bname), obj_name(_oname), rgw_fh(_fh), filter(nullptr), timer_id(0), real_ofs(0), bytes_written(0), eio(false) { diff --git a/src/rgw/rgw_lib.cc b/src/rgw/rgw_lib.cc index ccf3da47ee8c..f449cce21c02 100644 --- a/src/rgw/rgw_lib.cc +++ b/src/rgw/rgw_lib.cc @@ -204,7 +204,7 @@ namespace rgw { rgw_env.set("HTTP_HOST", ""); /* XXX and -then- bloat up req_state with string copies from it */ - req_state rstate(req->cct, &rgw_env, req->id); + req_state rstate(req->cct, env, &rgw_env, req->id); req_state *s = &rstate; // XXX fix this diff --git a/src/rgw/rgw_lib.h b/src/rgw/rgw_lib.h index e863aadab3c3..02317ea8e084 100644 --- a/src/rgw/rgw_lib.h +++ b/src/rgw/rgw_lib.h @@ -180,10 +180,10 @@ namespace rgw { req_state rstate; public: - RGWLibContinuedReq(CephContext* _cct, + RGWLibContinuedReq(CephContext* _cct, const RGWProcessEnv& penv, std::unique_ptr _user) : RGWLibRequest(_cct, std::move(_user)), io_ctx(), - rstate(_cct, &io_ctx.get_env(), id) + rstate(_cct, penv, &io_ctx.get_env(), id) { io_ctx.init(_cct); diff --git a/src/rgw/rgw_process.cc b/src/rgw/rgw_process.cc index e7164243c83d..d926a41d5a3f 100644 --- a/src/rgw/rgw_process.cc +++ b/src/rgw/rgw_process.cc @@ -278,7 +278,7 @@ int process_request(const RGWProcessEnv& penv, RGWEnv& rgw_env = client_io->get_env(); - req_state rstate(g_ceph_context, &rgw_env, req->id); + req_state rstate(g_ceph_context, penv, &rgw_env, req->id); req_state *s = &rstate; s->ratelimit_data = penv.ratelimiting->get_active(); diff --git a/src/rgw/rgw_process.h b/src/rgw/rgw_process.h index fad155c0fa0f..470d8f4246f6 100644 --- a/src/rgw/rgw_process.h +++ b/src/rgw/rgw_process.h @@ -110,6 +110,8 @@ public: virtual ~RGWProcess() = default; + const RGWProcessEnv& get_env() const { return env; } + virtual void run() = 0; virtual void handle_request(const DoutPrefixProvider *dpp, RGWRequest *req) = 0; diff --git a/src/test/rgw/test_rgw_iam_policy.cc b/src/test/rgw/test_rgw_iam_policy.cc index 3afe6e1447a1..5d631ebf9176 100644 --- a/src/test/rgw/test_rgw_iam_policy.cc +++ b/src/test/rgw/test_rgw_iam_policy.cc @@ -904,13 +904,14 @@ TEST_F(IPPolicyTest, asNetworkInvalid) { } TEST_F(IPPolicyTest, IPEnvironment) { + RGWProcessEnv penv; // Unfortunately RGWCivetWeb is too tightly tied to civetweb to test RGWCivetWeb::init_env. RGWEnv rgw_env; rgw::sal::RadosStore store; std::unique_ptr user = store.get_user(rgw_user()); rgw_env.set("REMOTE_ADDR", "192.168.1.1"); rgw_env.set("HTTP_HOST", "1.2.3.4"); - req_state rgw_req_state(cct.get(), &rgw_env, 0); + req_state rgw_req_state(cct.get(), penv, &rgw_env, 0); rgw_req_state.set_user(user); rgw_build_iam_environment(&store, &rgw_req_state); auto ip = rgw_req_state.env.find("aws:SourceIp");