Skip to content

Commit 7911eea

Browse files
authored
Merge pull request ceph#54878 from yuvalif/wip-yuval-split-rgw-tools
rgw: split RGWDataAccess from rgw_tools.cc Reviewed-by: Daniel Gryniewicz <[email protected]>
2 parents 5252822 + f3cfd02 commit 7911eea

File tree

6 files changed

+348
-325
lines changed

6 files changed

+348
-325
lines changed

src/rgw/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ set(librgw_common_srcs
147147
rgw_bucket_encryption.cc
148148
rgw_tracer.cc
149149
rgw_lua_background.cc
150+
rgw_data_access.cc
150151
driver/rados/cls_fifo_legacy.cc
151152
driver/rados/rgw_bucket.cc
152153
driver/rados/rgw_bucket_sync.cc

src/rgw/driver/rados/rgw_tools.cc

Lines changed: 0 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -280,176 +280,6 @@ void rgw_filter_attrset(map<string, bufferlist>& unfiltered_attrset, const strin
280280
}
281281
}
282282

283-
RGWDataAccess::RGWDataAccess(rgw::sal::Driver* _driver) : driver(_driver)
284-
{
285-
}
286-
287-
288-
int RGWDataAccess::Bucket::finish_init()
289-
{
290-
auto iter = attrs.find(RGW_ATTR_ACL);
291-
if (iter == attrs.end()) {
292-
return 0;
293-
}
294-
295-
bufferlist::const_iterator bliter = iter->second.begin();
296-
try {
297-
policy.decode(bliter);
298-
} catch (buffer::error& err) {
299-
return -EIO;
300-
}
301-
302-
return 0;
303-
}
304-
305-
int RGWDataAccess::Bucket::init(const DoutPrefixProvider *dpp, optional_yield y)
306-
{
307-
std::unique_ptr<rgw::sal::Bucket> bucket;
308-
int ret = sd->driver->load_bucket(dpp, rgw_bucket(tenant, name), &bucket, y);
309-
if (ret < 0) {
310-
return ret;
311-
}
312-
313-
bucket_info = bucket->get_info();
314-
mtime = bucket->get_modification_time();
315-
attrs = bucket->get_attrs();
316-
317-
return finish_init();
318-
}
319-
320-
int RGWDataAccess::Bucket::init(const RGWBucketInfo& _bucket_info,
321-
const map<string, bufferlist>& _attrs)
322-
{
323-
bucket_info = _bucket_info;
324-
attrs = _attrs;
325-
326-
return finish_init();
327-
}
328-
329-
int RGWDataAccess::Bucket::get_object(const rgw_obj_key& key,
330-
ObjectRef *obj) {
331-
obj->reset(new Object(sd, shared_from_this(), key));
332-
return 0;
333-
}
334-
335-
int RGWDataAccess::Object::put(bufferlist& data,
336-
map<string, bufferlist>& attrs,
337-
const DoutPrefixProvider *dpp,
338-
optional_yield y)
339-
{
340-
rgw::sal::Driver* driver = sd->driver;
341-
CephContext *cct = driver->ctx();
342-
343-
string tag;
344-
append_rand_alpha(cct, tag, tag, 32);
345-
346-
RGWBucketInfo& bucket_info = bucket->bucket_info;
347-
348-
rgw::BlockingAioThrottle aio(driver->ctx()->_conf->rgw_put_obj_min_window_size);
349-
350-
std::unique_ptr<rgw::sal::Bucket> b = driver->get_bucket(bucket_info);
351-
std::unique_ptr<rgw::sal::Object> obj = b->get_object(key);
352-
353-
auto& owner = bucket->policy.get_owner();
354-
355-
string req_id = driver->zone_unique_id(driver->get_new_req_id());
356-
357-
std::unique_ptr<rgw::sal::Writer> processor;
358-
processor = driver->get_atomic_writer(dpp, y, obj.get(), owner.id,
359-
nullptr, olh_epoch, req_id);
360-
361-
int ret = processor->prepare(y);
362-
if (ret < 0)
363-
return ret;
364-
365-
rgw::sal::DataProcessor *filter = processor.get();
366-
367-
CompressorRef plugin;
368-
boost::optional<RGWPutObj_Compress> compressor;
369-
370-
const auto& compression_type = driver->get_compression_type(bucket_info.placement_rule);
371-
if (compression_type != "none") {
372-
plugin = Compressor::create(driver->ctx(), compression_type);
373-
if (!plugin) {
374-
ldpp_dout(dpp, 1) << "Cannot load plugin for compression type "
375-
<< compression_type << dendl;
376-
} else {
377-
compressor.emplace(driver->ctx(), plugin, filter);
378-
filter = &*compressor;
379-
}
380-
}
381-
382-
off_t ofs = 0;
383-
auto obj_size = data.length();
384-
385-
RGWMD5Etag etag_calc;
386-
387-
do {
388-
size_t read_len = std::min(data.length(), (unsigned int)cct->_conf->rgw_max_chunk_size);
389-
390-
bufferlist bl;
391-
392-
data.splice(0, read_len, &bl);
393-
etag_calc.update(bl);
394-
395-
ret = filter->process(std::move(bl), ofs);
396-
if (ret < 0)
397-
return ret;
398-
399-
ofs += read_len;
400-
} while (data.length() > 0);
401-
402-
ret = filter->process({}, ofs);
403-
if (ret < 0) {
404-
return ret;
405-
}
406-
bool has_etag_attr = false;
407-
auto iter = attrs.find(RGW_ATTR_ETAG);
408-
if (iter != attrs.end()) {
409-
bufferlist& bl = iter->second;
410-
etag = bl.to_str();
411-
has_etag_attr = true;
412-
}
413-
414-
if (!aclbl) {
415-
RGWAccessControlPolicy policy;
416-
417-
const auto& owner = bucket->policy.get_owner();
418-
policy.create_default(owner.id, owner.display_name); // default private policy
419-
420-
policy.encode(aclbl.emplace());
421-
}
422-
423-
if (etag.empty()) {
424-
etag_calc.finish(&etag);
425-
}
426-
427-
if (!has_etag_attr) {
428-
bufferlist etagbl;
429-
etagbl.append(etag);
430-
attrs[RGW_ATTR_ETAG] = etagbl;
431-
}
432-
attrs[RGW_ATTR_ACL] = *aclbl;
433-
434-
string *puser_data = nullptr;
435-
if (user_data) {
436-
puser_data = &(*user_data);
437-
}
438-
439-
const req_context rctx{dpp, y, nullptr};
440-
return processor->complete(obj_size, etag,
441-
&mtime, mtime,
442-
attrs, delete_at,
443-
nullptr, nullptr,
444-
puser_data,
445-
nullptr, nullptr, rctx);
446-
}
447-
448-
void RGWDataAccess::Object::set_policy(const RGWAccessControlPolicy& policy)
449-
{
450-
policy.encode(aclbl.emplace());
451-
}
452-
453283
void rgw_complete_aio_completion(librados::AioCompletion* c, int r) {
454284
auto pc = c->pc;
455285
librados::CB_AioCompleteAndSafe cb(pc);

src/rgw/driver/rados/rgw_tools.h

Lines changed: 0 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -165,161 +165,6 @@ int rgw_get_rados_ref(const DoutPrefixProvider* dpp, librados::Rados* rados,
165165
int rgw_tools_init(const DoutPrefixProvider *dpp, CephContext *cct);
166166
void rgw_tools_cleanup();
167167

168-
template<class H, size_t S>
169-
class RGWEtag
170-
{
171-
H hash;
172-
173-
public:
174-
RGWEtag() {
175-
if constexpr (std::is_same_v<H, MD5>) {
176-
// Allow use of MD5 digest in FIPS mode for non-cryptographic purposes
177-
hash.SetFlags(EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
178-
}
179-
}
180-
181-
void update(const char *buf, size_t len) {
182-
hash.Update((const unsigned char *)buf, len);
183-
}
184-
185-
void update(bufferlist& bl) {
186-
if (bl.length() > 0) {
187-
update(bl.c_str(), bl.length());
188-
}
189-
}
190-
191-
void update(const std::string& s) {
192-
if (!s.empty()) {
193-
update(s.c_str(), s.size());
194-
}
195-
}
196-
void finish(std::string *etag) {
197-
char etag_buf[S];
198-
char etag_buf_str[S * 2 + 16];
199-
200-
hash.Final((unsigned char *)etag_buf);
201-
buf_to_hex((const unsigned char *)etag_buf, S,
202-
etag_buf_str);
203-
204-
*etag = etag_buf_str;
205-
}
206-
};
207-
208-
using RGWMD5Etag = RGWEtag<MD5, CEPH_CRYPTO_MD5_DIGESTSIZE>;
209-
210-
class RGWDataAccess
211-
{
212-
rgw::sal::Driver* driver;
213-
214-
public:
215-
RGWDataAccess(rgw::sal::Driver* _driver);
216-
217-
class Object;
218-
class Bucket;
219-
220-
using BucketRef = std::shared_ptr<Bucket>;
221-
using ObjectRef = std::shared_ptr<Object>;
222-
223-
class Bucket : public std::enable_shared_from_this<Bucket> {
224-
friend class RGWDataAccess;
225-
friend class Object;
226-
227-
RGWDataAccess *sd{nullptr};
228-
RGWBucketInfo bucket_info;
229-
std::string tenant;
230-
std::string name;
231-
std::string bucket_id;
232-
ceph::real_time mtime;
233-
std::map<std::string, bufferlist> attrs;
234-
235-
RGWAccessControlPolicy policy;
236-
int finish_init();
237-
238-
Bucket(RGWDataAccess *_sd,
239-
const std::string& _tenant,
240-
const std::string& _name,
241-
const std::string& _bucket_id) : sd(_sd),
242-
tenant(_tenant),
243-
name(_name),
244-
bucket_id(_bucket_id) {}
245-
Bucket(RGWDataAccess *_sd) : sd(_sd) {}
246-
int init(const DoutPrefixProvider *dpp, optional_yield y);
247-
int init(const RGWBucketInfo& _bucket_info, const std::map<std::string, bufferlist>& _attrs);
248-
public:
249-
int get_object(const rgw_obj_key& key,
250-
ObjectRef *obj);
251-
252-
};
253-
254-
255-
class Object {
256-
RGWDataAccess *sd{nullptr};
257-
BucketRef bucket;
258-
rgw_obj_key key;
259-
260-
ceph::real_time mtime;
261-
std::string etag;
262-
uint64_t olh_epoch{0};
263-
ceph::real_time delete_at;
264-
std::optional<std::string> user_data;
265-
266-
std::optional<bufferlist> aclbl;
267-
268-
Object(RGWDataAccess *_sd,
269-
BucketRef&& _bucket,
270-
const rgw_obj_key& _key) : sd(_sd),
271-
bucket(_bucket),
272-
key(_key) {}
273-
public:
274-
int put(bufferlist& data, std::map<std::string, bufferlist>& attrs, const DoutPrefixProvider *dpp, optional_yield y); /* might modify attrs */
275-
276-
void set_mtime(const ceph::real_time& _mtime) {
277-
mtime = _mtime;
278-
}
279-
280-
void set_etag(const std::string& _etag) {
281-
etag = _etag;
282-
}
283-
284-
void set_olh_epoch(uint64_t epoch) {
285-
olh_epoch = epoch;
286-
}
287-
288-
void set_delete_at(ceph::real_time _delete_at) {
289-
delete_at = _delete_at;
290-
}
291-
292-
void set_user_data(const std::string& _user_data) {
293-
user_data = _user_data;
294-
}
295-
296-
void set_policy(const RGWAccessControlPolicy& policy);
297-
298-
friend class Bucket;
299-
};
300-
301-
int get_bucket(const DoutPrefixProvider *dpp,
302-
const std::string& tenant,
303-
const std::string name,
304-
const std::string bucket_id,
305-
BucketRef *bucket,
306-
optional_yield y) {
307-
bucket->reset(new Bucket(this, tenant, name, bucket_id));
308-
return (*bucket)->init(dpp, y);
309-
}
310-
311-
int get_bucket(const RGWBucketInfo& bucket_info,
312-
const std::map<std::string, bufferlist>& attrs,
313-
BucketRef *bucket) {
314-
bucket->reset(new Bucket(this));
315-
return (*bucket)->init(bucket_info, attrs);
316-
}
317-
friend class Bucket;
318-
friend class Object;
319-
};
320-
321-
using RGWDataAccessRef = std::shared_ptr<RGWDataAccess>;
322-
323168
/// Complete an AioCompletion. To return error values or otherwise
324169
/// satisfy the caller. Useful for making complicated asynchronous
325170
/// calls and error handling.

src/rgw/rgw_admin.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extern "C" {
6262
#include "rgw_lua.h"
6363
#include "rgw_sal.h"
6464
#include "rgw_sal_config.h"
65+
#include "rgw_data_access.h"
6566

6667
#include "services/svc_sync_modules.h"
6768
#include "services/svc_cls.h"

0 commit comments

Comments
 (0)