]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
9f95a23c | 2 | // vim: ts=8 sw=2 smarttab ft=cpp |
11fdf7f2 | 3 | |
7c673cae FG |
4 | #ifndef RGW_LIB_H |
5 | #define RGW_LIB_H | |
6 | ||
7 | #include <mutex> | |
8 | #include "include/unordered_map.h" | |
9 | #include "global/global_init.h" | |
10 | #include "rgw_common.h" | |
11 | #include "rgw_client_io.h" | |
12 | #include "rgw_rest.h" | |
13 | #include "rgw_request.h" | |
14 | #include "rgw_frontend.h" | |
15 | #include "rgw_process.h" | |
16 | #include "rgw_rest_s3.h" // RGW_Auth_S3 | |
17 | #include "rgw_ldap.h" | |
11fdf7f2 TL |
18 | #include "services/svc_zone_utils.h" |
19 | #include "include/ceph_assert.h" | |
7c673cae | 20 | |
b3b6e05e TL |
21 | #define dout_subsys ceph_subsys_rgw |
22 | ||
a4b75251 | 23 | class OpsLogSink; |
7c673cae FG |
24 | |
25 | namespace rgw { | |
26 | ||
27 | class RGWLibFrontend; | |
28 | ||
b3b6e05e | 29 | class RGWLib : public DoutPrefixProvider { |
7c673cae FG |
30 | RGWFrontendConfig* fec; |
31 | RGWLibFrontend* fe; | |
a4b75251 | 32 | OpsLogSink* olog; |
224ce89b | 33 | rgw::LDAPHelper* ldh{nullptr}; |
7c673cae | 34 | RGWREST rest; // XXX needed for RGWProcessEnv |
9f95a23c | 35 | rgw::sal::RGWRadosStore* store; |
7c673cae FG |
36 | boost::intrusive_ptr<CephContext> cct; |
37 | ||
38 | public: | |
39 | RGWLib() : fec(nullptr), fe(nullptr), olog(nullptr), store(nullptr) | |
40 | {} | |
41 | ~RGWLib() {} | |
42 | ||
9f95a23c | 43 | rgw::sal::RGWRadosStore* get_store() { return store; } |
7c673cae FG |
44 | |
45 | RGWLibFrontend* get_fe() { return fe; } | |
46 | ||
47 | rgw::LDAPHelper* get_ldh() { return ldh; } | |
48 | ||
b3b6e05e TL |
49 | CephContext *get_cct() const override { return cct.get(); } |
50 | unsigned get_subsys() const { return dout_subsys; } | |
51 | std::ostream& gen_prefix(std::ostream& out) const { return out << "lib rgw: "; } | |
52 | ||
7c673cae FG |
53 | int init(); |
54 | int init(vector<const char *>& args); | |
55 | int stop(); | |
56 | }; | |
57 | ||
58 | extern RGWLib rgwlib; | |
59 | ||
60 | /* request interface */ | |
61 | ||
62 | class RGWLibIO : public rgw::io::BasicClient, | |
63 | public rgw::io::Accounter | |
64 | { | |
65 | RGWUserInfo user_info; | |
66 | RGWEnv env; | |
67 | public: | |
68 | RGWLibIO() { | |
69 | get_env().set("HTTP_HOST", ""); | |
70 | } | |
11fdf7f2 | 71 | explicit RGWLibIO(const RGWUserInfo &_user_info) |
7c673cae FG |
72 | : user_info(_user_info) {} |
73 | ||
3a9019d9 FG |
74 | int init_env(CephContext *cct) override { |
75 | env.init(cct); | |
76 | return 0; | |
77 | } | |
7c673cae FG |
78 | |
79 | const RGWUserInfo& get_user() { | |
80 | return user_info; | |
81 | } | |
82 | ||
9f95a23c | 83 | int set_uid(rgw::sal::RGWRadosStore* store, const rgw_user& uid); |
7c673cae FG |
84 | |
85 | int write_data(const char *buf, int len); | |
86 | int read_data(char *buf, int len); | |
87 | int send_status(int status, const char *status_name); | |
88 | int send_100_continue(); | |
89 | int complete_header(); | |
90 | int send_content_length(uint64_t len); | |
91 | ||
92 | RGWEnv& get_env() noexcept override { | |
93 | return env; | |
94 | } | |
95 | ||
96 | size_t complete_request() override { /* XXX */ | |
97 | return 0; | |
98 | }; | |
99 | ||
100 | void set_account(bool) override { | |
101 | return; | |
102 | } | |
103 | ||
104 | uint64_t get_bytes_sent() const override { | |
105 | return 0; | |
106 | } | |
107 | ||
108 | uint64_t get_bytes_received() const override { | |
109 | return 0; | |
110 | } | |
111 | ||
112 | }; /* RGWLibIO */ | |
113 | ||
114 | /* XXX */ | |
115 | class RGWRESTMgr_Lib : public RGWRESTMgr { | |
116 | public: | |
117 | RGWRESTMgr_Lib() {} | |
118 | ~RGWRESTMgr_Lib() override {} | |
119 | }; /* RGWRESTMgr_Lib */ | |
120 | ||
121 | /* XXX */ | |
122 | class RGWHandler_Lib : public RGWHandler { | |
123 | friend class RGWRESTMgr_Lib; | |
124 | public: | |
125 | ||
f67539c2 | 126 | int authorize(const DoutPrefixProvider *dpp, optional_yield y) override; |
7c673cae FG |
127 | |
128 | RGWHandler_Lib() {} | |
129 | ~RGWHandler_Lib() override {} | |
f67539c2 TL |
130 | static int init_from_header(rgw::sal::RGWRadosStore *store, |
131 | struct req_state *s); | |
7c673cae FG |
132 | }; /* RGWHandler_Lib */ |
133 | ||
134 | class RGWLibRequest : public RGWRequest, | |
135 | public RGWHandler_Lib { | |
f67539c2 TL |
136 | private: |
137 | std::unique_ptr<rgw::sal::RGWUser> tuser; // Don't use this. It's empty except during init. | |
7c673cae FG |
138 | public: |
139 | CephContext* cct; | |
11fdf7f2 | 140 | boost::optional<RGWSysObjectCtx> sysobj_ctx; |
7c673cae FG |
141 | |
142 | /* unambiguiously return req_state */ | |
143 | inline struct req_state* get_state() { return this->RGWRequest::s; } | |
144 | ||
f67539c2 TL |
145 | RGWLibRequest(CephContext* _cct, std::unique_ptr<rgw::sal::RGWUser> _user) |
146 | : RGWRequest(rgwlib.get_store()->getRados()->get_new_req_id()), | |
147 | tuser(std::move(_user)), cct(_cct) | |
7c673cae FG |
148 | {} |
149 | ||
f67539c2 | 150 | int postauth_init(optional_yield) override { return 0; } |
7c673cae FG |
151 | |
152 | /* descendant equivalent of *REST*::init_from_header(...): | |
153 | * prepare request for execute()--should mean, fixup URI-alikes | |
154 | * and any other expected stat vars in local req_state, for | |
155 | * now */ | |
156 | virtual int header_init() = 0; | |
157 | ||
158 | /* descendant initializer responsible to call RGWOp::init()--which | |
159 | * descendants are required to inherit */ | |
160 | virtual int op_init() = 0; | |
161 | ||
162 | using RGWHandler::init; | |
163 | ||
164 | int init(const RGWEnv& rgw_env, RGWObjectCtx* rados_ctx, | |
165 | RGWLibIO* io, struct req_state* _s) { | |
166 | ||
167 | RGWRequest::init_state(_s); | |
11fdf7f2 | 168 | RGWHandler::init(rados_ctx->get_store(), _s, io); |
7c673cae | 169 | |
9f95a23c | 170 | sysobj_ctx.emplace(store->svc()->sysobj); |
7c673cae FG |
171 | |
172 | get_state()->obj_ctx = rados_ctx; | |
11fdf7f2 | 173 | get_state()->sysobj_ctx = &(sysobj_ctx.get()); |
9f95a23c TL |
174 | get_state()->req_id = store->svc()->zone_utils->unique_id(id); |
175 | get_state()->trans_id = store->svc()->zone_utils->unique_trans_id(id); | |
f67539c2 TL |
176 | get_state()->bucket_tenant = tuser->get_tenant(); |
177 | get_state()->set_user(tuser); | |
7c673cae | 178 | |
11fdf7f2 TL |
179 | ldpp_dout(_s, 2) << "initializing for trans_id = " |
180 | << get_state()->trans_id.c_str() << dendl; | |
7c673cae FG |
181 | |
182 | int ret = header_init(); | |
183 | if (ret == 0) { | |
f67539c2 | 184 | ret = init_from_header(rados_ctx->get_store(), _s); |
7c673cae FG |
185 | } |
186 | return ret; | |
187 | } | |
188 | ||
189 | virtual bool only_bucket() = 0; | |
190 | ||
f67539c2 | 191 | int read_permissions(RGWOp *op, optional_yield y) override; |
7c673cae FG |
192 | |
193 | }; /* RGWLibRequest */ | |
194 | ||
195 | class RGWLibContinuedReq : public RGWLibRequest { | |
196 | RGWLibIO io_ctx; | |
197 | struct req_state rstate; | |
198 | RGWObjectCtx rados_ctx; | |
199 | public: | |
200 | ||
f67539c2 TL |
201 | RGWLibContinuedReq(CephContext* _cct, |
202 | std::unique_ptr<rgw::sal::RGWUser> _user) | |
203 | : RGWLibRequest(_cct, std::move(_user)), io_ctx(), | |
204 | rstate(_cct, &io_ctx.get_env(), id), | |
11fdf7f2 | 205 | rados_ctx(rgwlib.get_store(), &rstate) |
7c673cae FG |
206 | { |
207 | io_ctx.init(_cct); | |
208 | ||
209 | RGWRequest::init_state(&rstate); | |
11fdf7f2 | 210 | RGWHandler::init(rados_ctx.get_store(), &rstate, &io_ctx); |
7c673cae | 211 | |
9f95a23c | 212 | sysobj_ctx.emplace(store->svc()->sysobj); |
7c673cae | 213 | |
f67539c2 | 214 | get_state()->cio = &io_ctx; |
7c673cae | 215 | get_state()->obj_ctx = &rados_ctx; |
11fdf7f2 | 216 | get_state()->sysobj_ctx = &(sysobj_ctx.get()); |
9f95a23c TL |
217 | get_state()->req_id = store->svc()->zone_utils->unique_id(id); |
218 | get_state()->trans_id = store->svc()->zone_utils->unique_trans_id(id); | |
7c673cae | 219 | |
11fdf7f2 TL |
220 | ldpp_dout(get_state(), 2) << "initializing for trans_id = " |
221 | << get_state()->trans_id.c_str() << dendl; | |
7c673cae FG |
222 | } |
223 | ||
9f95a23c | 224 | inline rgw::sal::RGWRadosStore* get_store() { return store; } |
f67539c2 TL |
225 | inline RGWLibIO& get_io() { return io_ctx; } |
226 | inline RGWObjectCtx& get_octx() { return rados_ctx; } | |
7c673cae | 227 | |
11fdf7f2 | 228 | virtual int execute() final { ceph_abort(); } |
7c673cae FG |
229 | virtual int exec_start() = 0; |
230 | virtual int exec_continue() = 0; | |
231 | virtual int exec_finish() = 0; | |
232 | ||
233 | }; /* RGWLibContinuedReq */ | |
234 | ||
235 | } /* namespace rgw */ | |
236 | ||
237 | #endif /* RGW_LIB_H */ |