]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_lib.h
63f34cf3d7942e5d94a0b593d05664345efcd3bf
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
8 #include "include/unordered_map.h"
9 #include "global/global_init.h"
10 #include "rgw_common.h"
11 #include "rgw_client_io.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
18 #include "services/svc_zone_utils.h"
19 #include "include/ceph_assert.h"
28 RGWFrontendConfig
* fec
;
31 rgw::LDAPHelper
* ldh
{nullptr};
32 RGWREST rest
; // XXX needed for RGWProcessEnv
33 rgw::sal::RGWRadosStore
* store
;
34 boost::intrusive_ptr
<CephContext
> cct
;
37 RGWLib() : fec(nullptr), fe(nullptr), olog(nullptr), store(nullptr)
41 rgw::sal::RGWRadosStore
* get_store() { return store
; }
43 RGWLibFrontend
* get_fe() { return fe
; }
45 rgw::LDAPHelper
* get_ldh() { return ldh
; }
48 int init(vector
<const char *>& args
);
54 /* request interface */
56 class RGWLibIO
: public rgw::io::BasicClient
,
57 public rgw::io::Accounter
59 RGWUserInfo user_info
;
63 get_env().set("HTTP_HOST", "");
65 explicit RGWLibIO(const RGWUserInfo
&_user_info
)
66 : user_info(_user_info
) {}
68 int init_env(CephContext
*cct
) override
{
73 const RGWUserInfo
& get_user() {
77 int set_uid(rgw::sal::RGWRadosStore
* store
, const rgw_user
& uid
);
79 int write_data(const char *buf
, int len
);
80 int read_data(char *buf
, int len
);
81 int send_status(int status
, const char *status_name
);
82 int send_100_continue();
83 int complete_header();
84 int send_content_length(uint64_t len
);
86 RGWEnv
& get_env() noexcept override
{
90 size_t complete_request() override
{ /* XXX */
94 void set_account(bool) override
{
98 uint64_t get_bytes_sent() const override
{
102 uint64_t get_bytes_received() const override
{
109 class RGWRESTMgr_Lib
: public RGWRESTMgr
{
112 ~RGWRESTMgr_Lib() override
{}
113 }; /* RGWRESTMgr_Lib */
116 class RGWHandler_Lib
: public RGWHandler
{
117 friend class RGWRESTMgr_Lib
;
120 int authorize(const DoutPrefixProvider
*dpp
, optional_yield y
) override
;
123 ~RGWHandler_Lib() override
{}
124 static int init_from_header(rgw::sal::RGWRadosStore
*store
,
125 struct req_state
*s
);
126 }; /* RGWHandler_Lib */
128 class RGWLibRequest
: public RGWRequest
,
129 public RGWHandler_Lib
{
131 std::unique_ptr
<rgw::sal::RGWUser
> tuser
; // Don't use this. It's empty except during init.
134 boost::optional
<RGWSysObjectCtx
> sysobj_ctx
;
136 /* unambiguiously return req_state */
137 inline struct req_state
* get_state() { return this->RGWRequest::s
; }
139 RGWLibRequest(CephContext
* _cct
, std::unique_ptr
<rgw::sal::RGWUser
> _user
)
140 : RGWRequest(rgwlib
.get_store()->getRados()->get_new_req_id()),
141 tuser(std::move(_user
)), cct(_cct
)
144 int postauth_init(optional_yield
) override
{ return 0; }
146 /* descendant equivalent of *REST*::init_from_header(...):
147 * prepare request for execute()--should mean, fixup URI-alikes
148 * and any other expected stat vars in local req_state, for
150 virtual int header_init() = 0;
152 /* descendant initializer responsible to call RGWOp::init()--which
153 * descendants are required to inherit */
154 virtual int op_init() = 0;
156 using RGWHandler::init
;
158 int init(const RGWEnv
& rgw_env
, RGWObjectCtx
* rados_ctx
,
159 RGWLibIO
* io
, struct req_state
* _s
) {
161 RGWRequest::init_state(_s
);
162 RGWHandler::init(rados_ctx
->get_store(), _s
, io
);
164 sysobj_ctx
.emplace(store
->svc()->sysobj
);
166 get_state()->obj_ctx
= rados_ctx
;
167 get_state()->sysobj_ctx
= &(sysobj_ctx
.get());
168 get_state()->req_id
= store
->svc()->zone_utils
->unique_id(id
);
169 get_state()->trans_id
= store
->svc()->zone_utils
->unique_trans_id(id
);
170 get_state()->bucket_tenant
= tuser
->get_tenant();
171 get_state()->set_user(tuser
);
173 ldpp_dout(_s
, 2) << "initializing for trans_id = "
174 << get_state()->trans_id
.c_str() << dendl
;
176 int ret
= header_init();
178 ret
= init_from_header(rados_ctx
->get_store(), _s
);
183 virtual bool only_bucket() = 0;
185 int read_permissions(RGWOp
*op
, optional_yield y
) override
;
187 }; /* RGWLibRequest */
189 class RGWLibContinuedReq
: public RGWLibRequest
{
191 struct req_state rstate
;
192 RGWObjectCtx rados_ctx
;
195 RGWLibContinuedReq(CephContext
* _cct
,
196 std::unique_ptr
<rgw::sal::RGWUser
> _user
)
197 : RGWLibRequest(_cct
, std::move(_user
)), io_ctx(),
198 rstate(_cct
, &io_ctx
.get_env(), id
),
199 rados_ctx(rgwlib
.get_store(), &rstate
)
203 RGWRequest::init_state(&rstate
);
204 RGWHandler::init(rados_ctx
.get_store(), &rstate
, &io_ctx
);
206 sysobj_ctx
.emplace(store
->svc()->sysobj
);
208 get_state()->cio
= &io_ctx
;
209 get_state()->obj_ctx
= &rados_ctx
;
210 get_state()->sysobj_ctx
= &(sysobj_ctx
.get());
211 get_state()->req_id
= store
->svc()->zone_utils
->unique_id(id
);
212 get_state()->trans_id
= store
->svc()->zone_utils
->unique_trans_id(id
);
214 ldpp_dout(get_state(), 2) << "initializing for trans_id = "
215 << get_state()->trans_id
.c_str() << dendl
;
218 inline rgw::sal::RGWRadosStore
* get_store() { return store
; }
219 inline RGWLibIO
& get_io() { return io_ctx
; }
220 inline RGWObjectCtx
& get_octx() { return rados_ctx
; }
222 virtual int execute() final
{ ceph_abort(); }
223 virtual int exec_start() = 0;
224 virtual int exec_continue() = 0;
225 virtual int exec_finish() = 0;
227 }; /* RGWLibContinuedReq */
229 } /* namespace rgw */
231 #endif /* RGW_LIB_H */