diff --git a/src/rgw/CMakeLists.txt b/src/rgw/CMakeLists.txt index cf065cedcf849..329b01d2cacce 100644 --- a/src/rgw/CMakeLists.txt +++ b/src/rgw/CMakeLists.txt @@ -40,15 +40,9 @@ set(librgw_common_srcs services/svc_cls.cc services/svc_config_key_rados.cc services/svc_mdlog.cc - services/svc_meta.cc - services/svc_meta_be.cc - services/svc_meta_be_otp.cc - services/svc_meta_be_sobj.cc services/svc_notify.cc - services/svc_otp.cc services/svc_quota.cc services/svc_sync_modules.cc - services/svc_role_rados.cc services/svc_sys_obj.cc services/svc_sys_obj_cache.cc services/svc_sys_obj_core.cc @@ -204,6 +198,7 @@ set(librgw_common_srcs driver/rados/rgw_trim_mdlog.cc driver/rados/rgw_user.cc driver/rados/rgw_zone.cc + driver/rados/role.cc driver/rados/roles.cc driver/rados/sync_fairness.cc driver/rados/topic.cc diff --git a/src/rgw/driver/posix/rgw_sal_posix.cc b/src/rgw/driver/posix/rgw_sal_posix.cc index d676213727e43..0ce02bcff13fd 100644 --- a/src/rgw/driver/posix/rgw_sal_posix.cc +++ b/src/rgw/driver/posix/rgw_sal_posix.cc @@ -20,6 +20,7 @@ #include #include "rgw_multi.h" #include "include/scope_guard.h" +#include "common/errno.h" #define dout_subsys ceph_subsys_rgw #define dout_context g_ceph_context diff --git a/src/rgw/driver/rados/rgw_bucket.cc b/src/rgw/driver/rados/rgw_bucket.cc index 6bb1e9572daa3..21d238d334180 100644 --- a/src/rgw/driver/rados/rgw_bucket.cc +++ b/src/rgw/driver/rados/rgw_bucket.cc @@ -15,6 +15,7 @@ #include "account.h" #include "buckets.h" +#include "rgw_metadata_lister.h" #include "rgw_reshard.h" #include "rgw_pubsub.h" @@ -2163,27 +2164,17 @@ void RGWBucketCompleteInfo::decode_json(JSONObj *obj) { JSONDecoder::decode_json("attrs", attrs, obj); } -class RGWBucketMetadataHandler : public RGWBucketMetadataHandlerBase { -public: +class RGWBucketMetadataHandler : public RGWMetadataHandler { + protected: librados::Rados& rados; - struct Svc { - RGWSI_Bucket *bucket{nullptr}; - } svc; + RGWSI_Bucket* svc_bucket{nullptr}; + RGWBucketCtl *ctl_bucket{nullptr}; - struct Ctl { - RGWBucketCtl *bucket{nullptr}; - } ctl; - - explicit RGWBucketMetadataHandler(librados::Rados& rados) - : rados(rados) {} - - void init(RGWSI_Bucket *bucket_svc, - RGWBucketCtl *bucket_ctl) override { - base_init(bucket_svc->ctx(), - bucket_svc->get_ep_be_handler().get()); - svc.bucket = bucket_svc; - ctl.bucket = bucket_ctl; - } + public: + RGWBucketMetadataHandler(librados::Rados& rados, + RGWSI_Bucket* svc_bucket, + RGWBucketCtl* ctl_bucket) + : rados(rados), svc_bucket(svc_bucket), ctl_bucket(ctl_bucket) {} string get_type() override { return "bucket"; } @@ -2199,150 +2190,77 @@ class RGWBucketMetadataHandler : public RGWBucketMetadataHandlerBase { return new RGWBucketEntryMetadataObject(be, objv, mtime); } - int do_get(RGWSI_MetaBackend_Handler::Op *op, string& entry, RGWMetadataObject **obj, optional_yield y, const DoutPrefixProvider *dpp) override { - RGWObjVersionTracker ot; - RGWBucketEntryPoint be; - - real_time mtime; - map attrs; - - RGWSI_Bucket_EP_Ctx ctx(op->ctx()); - - int ret = svc.bucket->read_bucket_entrypoint_info(ctx, entry, &be, &ot, &mtime, &attrs, y, dpp); - if (ret < 0) - return ret; - - RGWBucketEntryMetadataObject *mdo = new RGWBucketEntryMetadataObject(be, ot.read_version, mtime, std::move(attrs)); - - *obj = mdo; - - return 0; - } - - int do_put(RGWSI_MetaBackend_Handler::Op *op, string& entry, - RGWMetadataObject *obj, - RGWObjVersionTracker& objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp, - RGWMDLogSyncType type, bool from_remote_zone) override; - - int do_remove(RGWSI_MetaBackend_Handler::Op *op, string& entry, RGWObjVersionTracker& objv_tracker, - optional_yield y, const DoutPrefixProvider *dpp) override { - RGWBucketEntryPoint be; - - real_time orig_mtime; - - RGWSI_Bucket_EP_Ctx ctx(op->ctx()); - - int ret = svc.bucket->read_bucket_entrypoint_info(ctx, entry, &be, &objv_tracker, &orig_mtime, nullptr, y, dpp); - if (ret < 0) - return ret; - - /* - * We're unlinking the bucket but we don't want to update the entrypoint here - we're removing - * it immediately and don't want to invalidate our cached objv_version or the bucket obj removal - * will incorrectly fail. - */ - ret = ctl.bucket->unlink_bucket(rados, be.owner, be.bucket, y, dpp, false); - if (ret < 0) { - ldpp_dout(dpp, -1) << "could not unlink bucket=" << entry << " owner=" << be.owner << dendl; - } - - ret = svc.bucket->remove_bucket_entrypoint_info(ctx, entry, &objv_tracker, y, dpp); - if (ret < 0) { - ldpp_dout(dpp, -1) << "could not delete bucket=" << entry << dendl; - } - /* idempotent */ - return 0; - } - - int call(std::function f) { - return call(nullopt, f); - } - - int call(std::optional bectx_params, - std::function f) { - return be_handler->call(bectx_params, [&](RGWSI_MetaBackend_Handler::Op *op) { - RGWSI_Bucket_EP_Ctx ctx(op->ctx()); - return f(ctx); - }); - } + int get(std::string& entry, RGWMetadataObject** obj, optional_yield y, + const DoutPrefixProvider *dpp) override; + int put(std::string& entry, RGWMetadataObject* obj, + RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider* dpp, + RGWMDLogSyncType type, bool from_remote_zone) override; + int remove(std::string& entry, RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider *dpp) override; + + int mutate(const std::string& entry, const ceph::real_time& mtime, + RGWObjVersionTracker* objv_tracker, optional_yield y, + const DoutPrefixProvider* dpp, RGWMDLogStatus op_type, + std::function f) override; + + int list_keys_init(const DoutPrefixProvider* dpp, const std::string& marker, + void** phandle) override; + int list_keys_next(const DoutPrefixProvider* dpp, void* handle, int max, + std::list& keys, bool* truncated) override; + void list_keys_complete(void *handle) override; + std::string get_marker(void *handle) override; }; -class RGWMetadataHandlerPut_Bucket : public RGWMetadataHandlerPut_SObj +int RGWBucketMetadataHandler::get(std::string& entry, RGWMetadataObject** obj, + optional_yield y, const DoutPrefixProvider *dpp) { - RGWBucketMetadataHandler *bhandler; - librados::Rados& rados; - RGWBucketEntryMetadataObject *obj; -public: - RGWMetadataHandlerPut_Bucket(RGWBucketMetadataHandler *_handler, librados::Rados& rados, - RGWSI_MetaBackend_Handler::Op *op, string& entry, - RGWMetadataObject *_obj, RGWObjVersionTracker& objv_tracker, - optional_yield y, - RGWMDLogSyncType type, bool from_remote_zone) - : RGWMetadataHandlerPut_SObj(_handler, op, entry, _obj, objv_tracker, y, type, from_remote_zone), - bhandler(_handler), - rados(rados), - obj(static_cast(_obj)) - {} - - void encode_obj(bufferlist *bl) override { - obj->get_ep().encode(*bl); - } - - int put_checked(const DoutPrefixProvider *dpp) override; - int put_post(const DoutPrefixProvider *dpp) override; -}; + RGWObjVersionTracker ot; + RGWBucketEntryPoint be; + real_time mtime; + map attrs; -int RGWBucketMetadataHandler::do_put(RGWSI_MetaBackend_Handler::Op *op, string& entry, - RGWMetadataObject *obj, - RGWObjVersionTracker& objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp, - RGWMDLogSyncType type, bool from_remote_zone) -{ - RGWMetadataHandlerPut_Bucket put_op(this, rados, op, entry, obj, objv_tracker, - y, type, from_remote_zone); - return do_put_operate(&put_op, dpp); + int ret = svc_bucket->read_bucket_entrypoint_info(entry, &be, &ot, &mtime, + &attrs, y, dpp); + if (ret < 0) { + return ret; + } + + *obj = new RGWBucketEntryMetadataObject(be, ot.read_version, mtime, + std::move(attrs)); + return 0; } -int RGWMetadataHandlerPut_Bucket::put_checked(const DoutPrefixProvider *dpp) +int RGWBucketMetadataHandler::put(std::string& entry, RGWMetadataObject* obj, + RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider* dpp, + RGWMDLogSyncType type, bool from_remote_zone) { - RGWBucketEntryMetadataObject *orig_obj = static_cast(old_obj); - - if (orig_obj) { - obj->set_pattrs(&orig_obj->get_attrs()); + std::optional old_be = RGWBucketEntryPoint{}; + int ret = svc_bucket->read_bucket_entrypoint_info( + entry, &*old_be, &objv_tracker, nullptr, nullptr, y, dpp); + if (ret == -ENOENT) { + old_be = std::nullopt; + } else if (ret < 0) { + return ret; } - auto& be = obj->get_ep(); - auto mtime = obj->get_mtime(); - auto pattrs = obj->get_pattrs(); - - RGWSI_Bucket_EP_Ctx ctx(op->ctx()); + auto* epobj = static_cast(obj); + RGWBucketEntryPoint& new_be = epobj->get_ep(); - return bhandler->svc.bucket->store_bucket_entrypoint_info(ctx, entry, - be, - false, - mtime, - pattrs, - &objv_tracker, - y, - dpp); -} - -int RGWMetadataHandlerPut_Bucket::put_post(const DoutPrefixProvider *dpp) -{ - auto* orig_obj = static_cast(old_obj); - auto* old_be = orig_obj ? &orig_obj->get_ep() : nullptr; - auto& new_be = obj->get_ep(); + ret = svc_bucket->store_bucket_entrypoint_info( + entry, new_be, false, obj->get_mtime(), + obj->get_pattrs(), &objv_tracker, y, dpp); + if (ret < 0) { + return ret; + } - RGWBucketCtl& ctl = *bhandler->ctl.bucket; constexpr bool update_entrypoint = false; if (old_be && (old_be->owner != new_be.owner || // owner changed (old_be->linked && !new_be.linked))) { // linked -> false - int ret = ctl.unlink_bucket(rados, old_be->owner, old_be->bucket, - y, dpp, update_entrypoint); + int ret = ctl_bucket->unlink_bucket(rados, old_be->owner, old_be->bucket, + y, dpp, update_entrypoint); if (ret < 0) { return ret; } @@ -2350,8 +2268,9 @@ int RGWMetadataHandlerPut_Bucket::put_post(const DoutPrefixProvider *dpp) if (new_be.linked && (!old_be || !old_be->linked || // linked -> true old_be->owner != new_be.owner)) { // owner changed - int ret = ctl.link_bucket(rados, new_be.owner, new_be.bucket, - new_be.creation_time, y, dpp, update_entrypoint); + int ret = ctl_bucket->link_bucket(rados, new_be.owner, new_be.bucket, + new_be.creation_time, y, dpp, + update_entrypoint); if (ret < 0) { return ret; } @@ -2361,8 +2280,8 @@ int RGWMetadataHandlerPut_Bucket::put_post(const DoutPrefixProvider *dpp) } int update_bucket_topic_mappings(const DoutPrefixProvider* dpp, - RGWBucketCompleteInfo* orig_bci, - RGWBucketCompleteInfo* current_bci, + const RGWBucketCompleteInfo* orig_bci, + const RGWBucketCompleteInfo* current_bci, rgw::sal::Driver* driver) { const auto decode_attrs = [](const rgw::sal::Attrs& attrs, rgw_pubsub_bucket_topics& bucket_topics) -> int { @@ -2446,6 +2365,71 @@ int update_bucket_topic_mappings(const DoutPrefixProvider* dpp, return ret; } +int RGWBucketMetadataHandler::remove(std::string& entry, RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider *dpp) +{ + RGWBucketEntryPoint be; + int ret = svc_bucket->read_bucket_entrypoint_info(entry, &be, &objv_tracker, + nullptr, nullptr, y, dpp); + if (ret < 0) { + return ret; + } + + constexpr bool update_ep = false; // removing anyway + ret = ctl_bucket->unlink_bucket(rados, be.owner, be.bucket, y, dpp, update_ep); + if (ret < 0) { + ldpp_dout(dpp, -1) << "could not unlink bucket=" << entry << " owner=" << be.owner << dendl; + } + + ret = svc_bucket->remove_bucket_entrypoint_info(entry, &objv_tracker, y, dpp); + if (ret < 0) { + ldpp_dout(dpp, -1) << "could not delete bucket=" << entry << dendl; + } + /* idempotent */ + return 0; +} + +int RGWBucketMetadataHandler::mutate(const std::string& entry, const ceph::real_time& mtime, + RGWObjVersionTracker* objv_tracker, optional_yield y, + const DoutPrefixProvider* dpp, RGWMDLogStatus op_type, + std::function f) +{ + return -ENOTSUP; // unused +} + +int RGWBucketMetadataHandler::list_keys_init(const DoutPrefixProvider* dpp, + const std::string& marker, + void** phandle) +{ + std::unique_ptr lister; + int ret = svc_bucket->create_entrypoint_lister(dpp, marker, lister); + if (ret < 0) { + return ret; + } + *phandle = lister.release(); // release ownership + return 0; +} + +int RGWBucketMetadataHandler::list_keys_next(const DoutPrefixProvider* dpp, + void* handle, int max, + std::list& keys, + bool* truncated) +{ + auto lister = static_cast(handle); + return lister->get_next(dpp, max, keys, truncated); +} + +void RGWBucketMetadataHandler::list_keys_complete(void *handle) +{ + delete static_cast(handle); +} + +std::string RGWBucketMetadataHandler::get_marker(void *handle) +{ + auto lister = static_cast(handle); + return lister->get_marker(); +} + static void get_md5_digest(const RGWBucketEntryPoint *be, string& md5_digest) { char md5[CEPH_CRYPTO_MD5_DIGESTSIZE * 2 + 1]; @@ -2510,15 +2494,16 @@ struct archive_meta_info { WRITE_CLASS_ENCODER(archive_meta_info) class RGWArchiveBucketMetadataHandler : public RGWBucketMetadataHandler { -public: - explicit RGWArchiveBucketMetadataHandler(librados::Rados& rados) - : RGWBucketMetadataHandler(rados) {} - - int do_remove(RGWSI_MetaBackend_Handler::Op *op, string& entry, RGWObjVersionTracker& objv_tracker, - optional_yield y, const DoutPrefixProvider *dpp) override { - auto cct = svc.bucket->ctx(); - - RGWSI_Bucket_EP_Ctx ctx(op->ctx()); + public: + RGWArchiveBucketMetadataHandler(librados::Rados& rados, + RGWSI_Bucket* svc_bucket, + RGWBucketCtl* ctl_bucket) + : RGWBucketMetadataHandler(rados, svc_bucket, ctl_bucket) {} + + int remove(std::string& entry, RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider *dpp) override + { + auto cct = svc_bucket->ctx(); ldpp_dout(dpp, 5) << "SKIP: bucket removal is not allowed on archive zone: bucket:" << entry << " ... proceeding to rename" << dendl; @@ -2534,7 +2519,7 @@ class RGWArchiveBucketMetadataHandler : public RGWBucketMetadataHandler { RGWBucketEntryPoint be; map attrs; - int ret = svc.bucket->read_bucket_entrypoint_info(ctx, entry, &be, &objv_tracker, &mtime, &attrs, y, dpp); + int ret = svc_bucket->read_bucket_entrypoint_info(entry, &be, &objv_tracker, &mtime, &attrs, y, dpp); if (ret < 0) { return ret; } @@ -2547,7 +2532,7 @@ class RGWArchiveBucketMetadataHandler : public RGWBucketMetadataHandler { ceph::real_time orig_mtime; RGWBucketInfo old_bi; - ret = ctl.bucket->read_bucket_instance_info(be.bucket, &old_bi, y, dpp, RGWBucketCtl::BucketInstance::GetParams() + ret = ctl_bucket->read_bucket_instance_info(be.bucket, &old_bi, y, dpp, RGWBucketCtl::BucketInstance::GetParams() .set_mtime(&orig_mtime) .set_attrs(&attrs_m)); if (ret < 0) { @@ -2556,7 +2541,7 @@ class RGWArchiveBucketMetadataHandler : public RGWBucketMetadataHandler { archive_meta_info ami; - if (!ami.from_attrs(svc.bucket->ctx(), attrs_m)) { + if (!ami.from_attrs(svc_bucket->ctx(), attrs_m)) { ami.orig_bucket = old_bi.bucket; ami.store_in_attrs(attrs_m); } @@ -2583,7 +2568,7 @@ class RGWArchiveBucketMetadataHandler : public RGWBucketMetadataHandler { new_be.bucket.name = new_bucket_name; - ret = ctl.bucket->store_bucket_instance_info(new_be.bucket, new_bi, y, dpp, RGWBucketCtl::BucketInstance::PutParams() + ret = ctl_bucket->store_bucket_instance_info(new_be.bucket, new_bi, y, dpp, RGWBucketCtl::BucketInstance::PutParams() .set_exclusive(false) .set_mtime(orig_mtime) .set_attrs(&attrs_m) @@ -2598,7 +2583,7 @@ class RGWArchiveBucketMetadataHandler : public RGWBucketMetadataHandler { RGWObjVersionTracker ot; ot.generate_new_write_ver(cct); - ret = svc.bucket->store_bucket_entrypoint_info(ctx, RGWSI_Bucket::get_entrypoint_meta_key(new_be.bucket), + ret = svc_bucket->store_bucket_entrypoint_info(RGWSI_Bucket::get_entrypoint_meta_key(new_be.bucket), new_be, true, mtime, &attrs, nullptr, y, dpp); if (ret < 0) { ldpp_dout(dpp, 0) << "ERROR: failed to put new bucket entrypoint for bucket=" << new_be.bucket << " ret=" << ret << dendl; @@ -2607,7 +2592,7 @@ class RGWArchiveBucketMetadataHandler : public RGWBucketMetadataHandler { /* link new bucket */ - ret = ctl.bucket->link_bucket(rados, new_be.owner, new_be.bucket, new_be.creation_time, y, dpp, false); + ret = ctl_bucket->link_bucket(rados, new_be.owner, new_be.bucket, new_be.creation_time, y, dpp, false); if (ret < 0) { ldpp_dout(dpp, 0) << "ERROR: failed to link new bucket for bucket=" << new_be.bucket << " ret=" << ret << dendl; return ret; @@ -2615,7 +2600,7 @@ class RGWArchiveBucketMetadataHandler : public RGWBucketMetadataHandler { /* clean up old stuff */ - ret = ctl.bucket->unlink_bucket(rados, be.owner, entry_bucket, y, dpp, false); + ret = ctl_bucket->unlink_bucket(rados, be.owner, entry_bucket, y, dpp, false); if (ret < 0) { ldpp_dout(dpp, -1) << "could not unlink bucket=" << entry << " owner=" << be.owner << dendl; } @@ -2625,8 +2610,7 @@ class RGWArchiveBucketMetadataHandler : public RGWBucketMetadataHandler { // whether it was a newly created bucket entrypoint ... in which case we // should ignore the error and move forward, or whether it is a higher version // of the same bucket instance ... in which we should retry - ret = svc.bucket->remove_bucket_entrypoint_info(ctx, - RGWSI_Bucket::get_entrypoint_meta_key(be.bucket), + ret = svc_bucket->remove_bucket_entrypoint_info(RGWSI_Bucket::get_entrypoint_meta_key(be.bucket), &objv_tracker, y, dpp); @@ -2635,7 +2619,7 @@ class RGWArchiveBucketMetadataHandler : public RGWBucketMetadataHandler { return ret; } - ret = ctl.bucket->remove_bucket_instance_info(be.bucket, old_bi, y, dpp); + ret = ctl_bucket->remove_bucket_instance_info(be.bucket, old_bi, y, dpp); if (ret < 0) { ldpp_dout(dpp, -1) << "could not delete bucket=" << entry << dendl; } @@ -2646,15 +2630,15 @@ class RGWArchiveBucketMetadataHandler : public RGWBucketMetadataHandler { return 0; } - int do_put(RGWSI_MetaBackend_Handler::Op *op, string& entry, - RGWMetadataObject *obj, - RGWObjVersionTracker& objv_tracker, - optional_yield y, const DoutPrefixProvider *dpp, - RGWMDLogSyncType type, bool from_remote_zone) override { + int put(std::string& entry, RGWMetadataObject* obj, + RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider* dpp, + RGWMDLogSyncType type, bool from_remote_zone) override + { if (entry.find("-deleted-") != string::npos) { RGWObjVersionTracker ot; RGWMetadataObject *robj; - int ret = do_get(op, entry, &robj, y, dpp); + int ret = get(entry, &robj, y, dpp); if (ret != -ENOENT) { if (ret < 0) { return ret; @@ -2662,55 +2646,40 @@ class RGWArchiveBucketMetadataHandler : public RGWBucketMetadataHandler { ot.read_version = robj->get_version(); delete robj; - ret = do_remove(op, entry, ot, y, dpp); + ret = remove(entry, ot, y, dpp); if (ret < 0) { return ret; } } } - return RGWBucketMetadataHandler::do_put(op, entry, obj, - objv_tracker, y, dpp, type, from_remote_zone); + return RGWBucketMetadataHandler::put(entry, obj, objv_tracker, y, + dpp, type, from_remote_zone); } - }; -class RGWBucketInstanceMetadataHandler : public RGWBucketInstanceMetadataHandlerBase { - int read_bucket_instance_entry(RGWSI_Bucket_BI_Ctx& ctx, - const string& entry, - RGWBucketCompleteInfo *bi, - ceph::real_time *pmtime, - optional_yield y, - const DoutPrefixProvider *dpp) { - return svc.bucket->read_bucket_instance_info(ctx, - entry, - &bi->info, - pmtime, &bi->attrs, - y, - dpp); - } - -public: - struct Svc { - RGWSI_Zone *zone{nullptr}; - RGWSI_Bucket *bucket{nullptr}; - RGWSI_BucketIndex *bi{nullptr}; - } svc; - +class RGWBucketInstanceMetadataHandler : public RGWMetadataHandler { rgw::sal::Driver* driver; - - RGWBucketInstanceMetadataHandler(rgw::sal::Driver* driver) - : driver(driver) {} - - void init(RGWSI_Zone *zone_svc, - RGWSI_Bucket *bucket_svc, - RGWSI_BucketIndex *bi_svc) override { - base_init(bucket_svc->ctx(), - bucket_svc->get_bi_be_handler().get()); - svc.zone = zone_svc; - svc.bucket = bucket_svc; - svc.bi = bi_svc; - } + RGWSI_Zone* svc_zone{nullptr}; + RGWSI_Bucket* svc_bucket{nullptr}; + RGWSI_BucketIndex* svc_bi{nullptr}; + + int put_prepare(const DoutPrefixProvider* dpp, optional_yield y, + const std::string& entry, RGWBucketCompleteInfo& bci, + const std::optional& old_bci, + const RGWObjVersionTracker& objv_tracker, + bool from_remote_zone); + int put_post(const DoutPrefixProvider* dpp, optional_yield y, + const RGWBucketCompleteInfo& bci, + const std::optional& old_bci, + RGWObjVersionTracker& objv_tracker); + public: + RGWBucketInstanceMetadataHandler(rgw::sal::Driver* driver, + RGWSI_Zone* svc_zone, + RGWSI_Bucket* svc_bucket, + RGWSI_BucketIndex* svc_bi) + : driver(driver), svc_zone(svc_zone), + svc_bucket(svc_bucket), svc_bi(svc_bi) {} string get_type() override { return "bucket.instance"; } @@ -2726,101 +2695,78 @@ class RGWBucketInstanceMetadataHandler : public RGWBucketInstanceMetadataHandler return new RGWBucketInstanceMetadataObject(bci, objv, mtime); } - int do_get(RGWSI_MetaBackend_Handler::Op *op, string& entry, RGWMetadataObject **obj, optional_yield y, const DoutPrefixProvider *dpp) override { - RGWBucketCompleteInfo bci; - real_time mtime; - - RGWSI_Bucket_BI_Ctx ctx(op->ctx()); - - int ret = svc.bucket->read_bucket_instance_info(ctx, entry, &bci.info, &mtime, &bci.attrs, y, dpp); - if (ret < 0) - return ret; - - RGWBucketInstanceMetadataObject *mdo = new RGWBucketInstanceMetadataObject(bci, bci.info.objv_tracker.read_version, mtime); - - *obj = mdo; - - return 0; - } - - int do_put(RGWSI_MetaBackend_Handler::Op *op, string& entry, - RGWMetadataObject *_obj, RGWObjVersionTracker& objv_tracker, - optional_yield y, const DoutPrefixProvider *dpp, - RGWMDLogSyncType sync_type, bool from_remote_zone) override; - - int do_remove(RGWSI_MetaBackend_Handler::Op *op, string& entry, RGWObjVersionTracker& objv_tracker, - optional_yield y, const DoutPrefixProvider *dpp) override { - RGWBucketCompleteInfo bci; - - RGWSI_Bucket_BI_Ctx ctx(op->ctx()); + int get(std::string& entry, RGWMetadataObject** obj, optional_yield y, + const DoutPrefixProvider *dpp) override; + int put(std::string& entry, RGWMetadataObject* obj, + RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider* dpp, + RGWMDLogSyncType type, bool from_remote_zone) override; + int remove(std::string& entry, RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider *dpp) override; + + int mutate(const std::string& entry, const ceph::real_time& mtime, + RGWObjVersionTracker* objv_tracker, optional_yield y, + const DoutPrefixProvider* dpp, RGWMDLogStatus op_type, + std::function f) override; + + int list_keys_init(const DoutPrefixProvider* dpp, const std::string& marker, + void** phandle) override; + int list_keys_next(const DoutPrefixProvider* dpp, void* handle, int max, + std::list& keys, bool* truncated) override; + void list_keys_complete(void *handle) override; + std::string get_marker(void *handle) override; +}; - int ret = read_bucket_instance_entry(ctx, entry, &bci, nullptr, y, dpp); - if (ret < 0 && ret != -ENOENT) - return ret; +int RGWBucketInstanceMetadataHandler::get(std::string& entry, RGWMetadataObject **obj, + optional_yield y, const DoutPrefixProvider *dpp) +{ + RGWBucketCompleteInfo bci; + real_time mtime; - ret = svc.bucket->remove_bucket_instance_info( - ctx, entry, bci.info, &bci.info.objv_tracker, y, dpp); - if (ret < 0) - return ret; - ret = update_bucket_topic_mappings(dpp, &bci, /*current_bci=*/nullptr, - driver); - // update_bucket_topic_mapping error is swallowed. - return 0; + int ret = svc_bucket->read_bucket_instance_info(entry, &bci.info, &mtime, &bci.attrs, y, dpp); + if (ret < 0) { + return ret; } - int call(std::function f) { - return call(nullopt, f); - } + *obj = new RGWBucketInstanceMetadataObject(bci, bci.info.objv_tracker.read_version, mtime); + return 0; +} - int call(std::optional bectx_params, - std::function f) { - return be_handler->call(bectx_params, [&](RGWSI_MetaBackend_Handler::Op *op) { - RGWSI_Bucket_BI_Ctx ctx(op->ctx()); - return f(ctx); - }); +int RGWBucketInstanceMetadataHandler::put(std::string& entry, RGWMetadataObject* obj, + RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider *dpp, + RGWMDLogSyncType sync_type, bool from_remote_zone) +{ + // read existing bucket instance + std::optional old = RGWBucketCompleteInfo{}; + int ret = svc_bucket->read_bucket_instance_info(entry, &old->info, nullptr, + &old->attrs, y, dpp); + if (ret == -ENOENT) { + old = std::nullopt; + } else if (ret < 0) { + return ret; } -}; -class RGWMetadataHandlerPut_BucketInstance : public RGWMetadataHandlerPut_SObj -{ - CephContext *cct; - optional_yield y; - RGWBucketInstanceMetadataHandler *bihandler; - RGWBucketInstanceMetadataObject *obj; -public: - RGWMetadataHandlerPut_BucketInstance(CephContext *_cct, - RGWBucketInstanceMetadataHandler *_handler, - RGWSI_MetaBackend_Handler::Op *_op, string& entry, - RGWMetadataObject *_obj, RGWObjVersionTracker& objv_tracker, - optional_yield y, - RGWMDLogSyncType type, bool from_remote_zone) : RGWMetadataHandlerPut_SObj(_handler, _op, entry, _obj, objv_tracker, y, type, from_remote_zone), - cct(_cct), y(y), bihandler(_handler) { - obj = static_cast(_obj); + auto newobj = static_cast(obj); + RGWBucketCompleteInfo& bci = newobj->get_bci(); - auto& bci = obj->get_bci(); - obj->set_pattrs(&bci.attrs); + // initializate/update the bucket instance info + ret = put_prepare(dpp, y, entry, bci, old, objv_tracker, from_remote_zone); + if (ret < 0) { + return ret; } - void encode_obj(bufferlist *bl) override { - obj->get_bucket_info().encode(*bl); + // write updated instance + RGWBucketInfo* old_info = (old ? &old->info : nullptr); + auto mtime = obj->get_mtime(); + ret = svc_bucket->store_bucket_instance_info(entry, bci.info, old_info, false, + mtime, &bci.attrs, y, dpp); + if (ret < 0) { + return ret; } - int put_check(const DoutPrefixProvider *dpp) override; - int put_checked(const DoutPrefixProvider *dpp) override; - int put_post(const DoutPrefixProvider *dpp) override; -}; - -int RGWBucketInstanceMetadataHandler::do_put(RGWSI_MetaBackend_Handler::Op *op, - string& entry, - RGWMetadataObject *obj, - RGWObjVersionTracker& objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp, - RGWMDLogSyncType type, bool from_remote_zone) -{ - RGWMetadataHandlerPut_BucketInstance put_op(svc.bucket->ctx(), this, op, entry, obj, - objv_tracker, y, type, from_remote_zone); - return do_put_operate(&put_op, dpp); + // update related state on success + return put_post(dpp, y, bci, old, objv_tracker); } void init_default_bucket_layout(CephContext *cct, rgw::BucketLayout& layout, @@ -2845,32 +2791,28 @@ void init_default_bucket_layout(CephContext *cct, rgw::BucketLayout& layout, } } -int RGWMetadataHandlerPut_BucketInstance::put_check(const DoutPrefixProvider *dpp) +int RGWBucketInstanceMetadataHandler::put_prepare( + const DoutPrefixProvider* dpp, optional_yield y, + const std::string& entry, RGWBucketCompleteInfo& bci, + const std::optional& old_bci, + const RGWObjVersionTracker& objv_tracker, + bool from_remote_zone) { - int ret; - - RGWBucketCompleteInfo& bci = obj->get_bci(); - - RGWBucketInstanceMetadataObject *orig_obj = static_cast(old_obj); - - RGWBucketCompleteInfo *old_bci = (orig_obj ? &orig_obj->get_bci() : nullptr); - - const bool exists = (!!orig_obj); - if (from_remote_zone) { - // don't sync bucket layout changes - if (!exists) { + // bucket layout information is local. don't overwrite existing layout with + // information from a remote zone + if (old_bci) { + bci.info.layout = old_bci->info.layout; + } else { // replace peer's layout with default-constructed, then apply our defaults bci.info.layout = rgw::BucketLayout{}; - init_default_bucket_layout(cct, bci.info.layout, - bihandler->svc.zone->get_zone(), + init_default_bucket_layout(dpp->get_cct(), bci.info.layout, + svc_zone->get_zone(), std::nullopt); - } else { - bci.info.layout = old_bci->info.layout; } } - if (!exists || old_bci->info.bucket.bucket_id != bci.info.bucket.bucket_id) { + if (!old_bci || old_bci->info.bucket.bucket_id != bci.info.bucket.bucket_id) { /* a new bucket, we need to select a new bucket placement for it */ string tenant_name; string bucket_name; @@ -2882,8 +2824,8 @@ int RGWMetadataHandlerPut_BucketInstance::put_check(const DoutPrefixProvider *dp bci.info.bucket.bucket_id = bucket_instance; bci.info.bucket.tenant = tenant_name; // if the sync module never writes data, don't require the zone to specify all placement targets - if (bihandler->svc.zone->sync_module_supports_writes()) { - ret = bihandler->svc.zone->select_bucket_location_by_rule(dpp, bci.info.placement_rule, &rule_info, y); + if (svc_zone->sync_module_supports_writes()) { + int ret = svc_zone->select_bucket_location_by_rule(dpp, bci.info.placement_rule, &rule_info, y); if (ret < 0) { ldpp_dout(dpp, 0) << "ERROR: select_bucket_placement() returned " << ret << dendl; return ret; @@ -2897,7 +2839,7 @@ int RGWMetadataHandlerPut_BucketInstance::put_check(const DoutPrefixProvider *dp } //always keep bucket versioning enabled on archive zone - if (bihandler->driver->get_zone()->get_tier_type() == "archive") { + if (driver->get_zone()->get_tier_type() == "archive") { bci.info.flags = (bci.info.flags & ~BUCKET_VERSIONS_SUSPENDED) | BUCKET_VERSIONED; } @@ -2908,74 +2850,52 @@ int RGWMetadataHandlerPut_BucketInstance::put_check(const DoutPrefixProvider *dp return 0; } -int RGWMetadataHandlerPut_BucketInstance::put_checked(const DoutPrefixProvider *dpp) -{ - RGWBucketInstanceMetadataObject *orig_obj = static_cast(old_obj); - - RGWBucketInfo *orig_info = (orig_obj ? &orig_obj->get_bucket_info() : nullptr); - - auto& info = obj->get_bucket_info(); - auto mtime = obj->get_mtime(); - auto pattrs = obj->get_pattrs(); - - RGWSI_Bucket_BI_Ctx ctx(op->ctx()); - - return bihandler->svc.bucket->store_bucket_instance_info(ctx, - entry, - info, - orig_info, - false, - mtime, - pattrs, - y, - dpp); -} - -int RGWMetadataHandlerPut_BucketInstance::put_post(const DoutPrefixProvider *dpp) +int RGWBucketInstanceMetadataHandler::put_post( + const DoutPrefixProvider* dpp, optional_yield y, + const RGWBucketCompleteInfo& bci, + const std::optional& old_bci, + RGWObjVersionTracker& objv_tracker) { - RGWBucketCompleteInfo& bci = obj->get_bci(); - - objv_tracker = bci.info.objv_tracker; - - int ret = bihandler->svc.bi->init_index(dpp, bci.info, bci.info.layout.current_index); + int ret = svc_bi->init_index(dpp, bci.info, bci.info.layout.current_index); if (ret < 0) { return ret; } - /* update lifecyle policy */ + /* update lc list on changes to lifecyle policy */ { - auto bucket = bihandler->driver->get_bucket(bci.info); - - auto lc = bihandler->driver->get_rgwlc(); + auto bucket = driver->get_bucket(bci.info); + auto lc = driver->get_rgwlc(); auto lc_it = bci.attrs.find(RGW_ATTR_LC); if (lc_it != bci.attrs.end()) { ldpp_dout(dpp, 20) << "set lc config for " << bci.info.bucket.name << dendl; ret = lc->set_bucket_config(dpp, y, bucket.get(), bci.attrs, nullptr); if (ret < 0) { - ldpp_dout(dpp, 0) << __func__ << " failed to set lc config for " - << bci.info.bucket.name - << dendl; - return ret; + ldpp_dout(dpp, 0) << __func__ << " failed to set lc config for " + << bci.info.bucket.name + << dendl; + return ret; } - } else { - ldpp_dout(dpp, 20) << "remove lc config for " << bci.info.bucket.name << dendl; - ret = lc->remove_bucket_config(dpp, y, bucket.get(), bci.attrs, false /* cannot merge attrs */); - if (ret < 0) { - ldpp_dout(dpp, 0) << __func__ << " failed to remove lc config for " - << bci.info.bucket.name - << dendl; - return ret; + } else if (old_bci) { + lc_it = old_bci->attrs.find(RGW_ATTR_LC); + if (lc_it != old_bci->attrs.end()) { + ldpp_dout(dpp, 20) << "remove lc config for " << old_bci->info.bucket.name << dendl; + ret = lc->remove_bucket_config(dpp, y, bucket.get(), old_bci->attrs, false /* cannot merge attrs */); + if (ret < 0) { + ldpp_dout(dpp, 0) << __func__ << " failed to remove lc config for " + << old_bci->info.bucket.name + << dendl; + return ret; + } } } } /* update lc */ /* update bucket topic mapping */ { - auto* orig_obj = static_cast(old_obj); - auto* orig_bci = (orig_obj ? &orig_obj->get_bci() : nullptr); - ret = update_bucket_topic_mappings(dpp, orig_bci, &bci, bihandler->driver); + auto* orig_bci = (old_bci ? &*old_bci : nullptr); + ret = update_bucket_topic_mappings(dpp, orig_bci, &bci, driver); if (ret < 0) { ldpp_dout(dpp, 0) << __func__ << " failed to apply bucket topic mapping for " @@ -2986,17 +2906,85 @@ int RGWMetadataHandlerPut_BucketInstance::put_post(const DoutPrefixProvider *dpp << " successfully applied bucket topic mapping for " << bci.info.bucket.name << dendl; } + + objv_tracker = bci.info.objv_tracker; + return STATUS_APPLIED; } +int RGWBucketInstanceMetadataHandler::remove(std::string& entry, RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider *dpp) +{ + RGWBucketCompleteInfo bci; + int ret = svc_bucket->read_bucket_instance_info(entry, &bci.info, nullptr, + &bci.attrs, y, dpp); + if (ret == -ENOENT) { + return 0; + } + if (ret < 0) { + return ret; + } + + ret = svc_bucket->remove_bucket_instance_info( + entry, bci.info, &bci.info.objv_tracker, y, dpp); + if (ret < 0) + return ret; + std::ignore = update_bucket_topic_mappings(dpp, &bci, /*current_bci=*/nullptr, + driver); + return 0; +} + +int RGWBucketInstanceMetadataHandler::mutate(const std::string& entry, const ceph::real_time& mtime, + RGWObjVersionTracker* objv_tracker, optional_yield y, + const DoutPrefixProvider* dpp, RGWMDLogStatus op_type, + std::function f) +{ + return -ENOTSUP; // unused +} + +int RGWBucketInstanceMetadataHandler::list_keys_init(const DoutPrefixProvider* dpp, + const std::string& marker, + void** phandle) +{ + std::unique_ptr lister; + int ret = svc_bucket->create_instance_lister(dpp, marker, lister); + if (ret < 0) { + return ret; + } + *phandle = lister.release(); // release ownership + return 0; +} + +int RGWBucketInstanceMetadataHandler::list_keys_next(const DoutPrefixProvider* dpp, + void* handle, int max, + std::list& keys, + bool* truncated) +{ + auto lister = static_cast(handle); + return lister->get_next(dpp, max, keys, truncated); +} + +void RGWBucketInstanceMetadataHandler::list_keys_complete(void *handle) +{ + delete static_cast(handle); +} + +std::string RGWBucketInstanceMetadataHandler::get_marker(void *handle) +{ + auto lister = static_cast(handle); + return lister->get_marker(); +} + + class RGWArchiveBucketInstanceMetadataHandler : public RGWBucketInstanceMetadataHandler { -public: - RGWArchiveBucketInstanceMetadataHandler(rgw::sal::Driver* driver) - : RGWBucketInstanceMetadataHandler(driver) {} + public: + using RGWBucketInstanceMetadataHandler::RGWBucketInstanceMetadataHandler; - // N.B. replication of lifecycle policy relies on logic in RGWBucketInstanceMetadataHandler::do_put(...), override with caution + // N.B. replication of lifecycle policy relies on logic in RGWBucketInstanceMetadataHandler::put(...), override with caution - int do_remove(RGWSI_MetaBackend_Handler::Op *op, string& entry, RGWObjVersionTracker& objv_tracker, optional_yield y, const DoutPrefixProvider *dpp) override { + int remove(std::string& entry, RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider *dpp) override + { ldpp_dout(dpp, 0) << "SKIP: bucket instance removal is not allowed on archive zone: bucket.instance:" << entry << dendl; return 0; } @@ -3017,51 +3005,31 @@ RGWBucketCtl::RGWBucketCtl(RGWSI_Zone *zone_svc, } void RGWBucketCtl::init(RGWUserCtl *user_ctl, - RGWBucketMetadataHandler *_bm_handler, - RGWBucketInstanceMetadataHandler *_bmi_handler, RGWDataChangesLog *datalog, const DoutPrefixProvider *dpp) { ctl.user = user_ctl; - bm_handler = _bm_handler; - bmi_handler = _bmi_handler; - - bucket_be_handler = bm_handler->get_be_handler(); - bi_be_handler = bmi_handler->get_be_handler(); - datalog->set_bucket_filter( [this](const rgw_bucket& bucket, optional_yield y, const DoutPrefixProvider *dpp) { return bucket_exports_data(bucket, y, dpp); }); } -int RGWBucketCtl::call(std::function f) { - return bm_handler->call([&](RGWSI_Bucket_EP_Ctx& ep_ctx) { - return bmi_handler->call([&](RGWSI_Bucket_BI_Ctx& bi_ctx) { - RGWSI_Bucket_X_Ctx ctx{ep_ctx, bi_ctx}; - return f(ctx); - }); - }); -} - int RGWBucketCtl::read_bucket_entrypoint_info(const rgw_bucket& bucket, RGWBucketEntryPoint *info, optional_yield y, const DoutPrefixProvider *dpp, const Bucket::GetParams& params) { - return bm_handler->call(params.bectx_params, [&](RGWSI_Bucket_EP_Ctx& ctx) { - return svc.bucket->read_bucket_entrypoint_info(ctx, - RGWSI_Bucket::get_entrypoint_meta_key(bucket), - info, - params.objv_tracker, - params.mtime, - params.attrs, - y, - dpp, - params.cache_info, - params.refresh_version); - }); + return svc.bucket->read_bucket_entrypoint_info(RGWSI_Bucket::get_entrypoint_meta_key(bucket), + info, + params.objv_tracker, + params.mtime, + params.attrs, + y, + dpp, + params.cache_info, + params.refresh_version); } int RGWBucketCtl::store_bucket_entrypoint_info(const rgw_bucket& bucket, @@ -3070,17 +3038,14 @@ int RGWBucketCtl::store_bucket_entrypoint_info(const rgw_bucket& bucket, const DoutPrefixProvider *dpp, const Bucket::PutParams& params) { - return bm_handler->call([&](RGWSI_Bucket_EP_Ctx& ctx) { - return svc.bucket->store_bucket_entrypoint_info(ctx, - RGWSI_Bucket::get_entrypoint_meta_key(bucket), - info, - params.exclusive, - params.mtime, - params.attrs, - params.objv_tracker, - y, - dpp); - }); + return svc.bucket->store_bucket_entrypoint_info(RGWSI_Bucket::get_entrypoint_meta_key(bucket), + info, + params.exclusive, + params.mtime, + params.attrs, + params.objv_tracker, + y, + dpp); } int RGWBucketCtl::remove_bucket_entrypoint_info(const rgw_bucket& bucket, @@ -3088,13 +3053,10 @@ int RGWBucketCtl::remove_bucket_entrypoint_info(const rgw_bucket& bucket, const DoutPrefixProvider *dpp, const Bucket::RemoveParams& params) { - return bm_handler->call([&](RGWSI_Bucket_EP_Ctx& ctx) { - return svc.bucket->remove_bucket_entrypoint_info(ctx, - RGWSI_Bucket::get_entrypoint_meta_key(bucket), - params.objv_tracker, - y, - dpp); - }); + return svc.bucket->remove_bucket_entrypoint_info(RGWSI_Bucket::get_entrypoint_meta_key(bucket), + params.objv_tracker, + y, + dpp); } int RGWBucketCtl::read_bucket_instance_info(const rgw_bucket& bucket, @@ -3103,18 +3065,14 @@ int RGWBucketCtl::read_bucket_instance_info(const rgw_bucket& bucket, const DoutPrefixProvider *dpp, const BucketInstance::GetParams& params) { - int ret = bmi_handler->call(params.bectx_params, [&](RGWSI_Bucket_BI_Ctx& ctx) { - return svc.bucket->read_bucket_instance_info(ctx, - RGWSI_Bucket::get_bi_meta_key(bucket), - info, - params.mtime, - params.attrs, - y, - dpp, - params.cache_info, - params.refresh_version); - }); - + int ret = svc.bucket->read_bucket_instance_info(RGWSI_Bucket::get_bi_meta_key(bucket), + info, + params.mtime, + params.attrs, + y, + dpp, + params.cache_info, + params.refresh_version); if (ret < 0) { return ret; } @@ -3141,7 +3099,6 @@ int RGWBucketCtl::read_bucket_info(const rgw_bucket& bucket, ep.emplace(); int r = read_bucket_entrypoint_info(*b, &(*ep), y, dpp, RGWBucketCtl::Bucket::GetParams() - .set_bectx_params(params.bectx_params) .set_objv_tracker(ep_objv_tracker)); if (r < 0) { return r; @@ -3150,17 +3107,13 @@ int RGWBucketCtl::read_bucket_info(const rgw_bucket& bucket, b = &ep->bucket; } - int ret = bmi_handler->call(params.bectx_params, [&](RGWSI_Bucket_BI_Ctx& ctx) { - return svc.bucket->read_bucket_instance_info(ctx, - RGWSI_Bucket::get_bi_meta_key(*b), - info, - params.mtime, - params.attrs, - y, dpp, - params.cache_info, - params.refresh_version); - }); - + int ret = svc.bucket->read_bucket_instance_info(RGWSI_Bucket::get_bi_meta_key(*b), + info, + params.mtime, + params.attrs, + y, dpp, + params.cache_info, + params.refresh_version); if (ret < 0) { return ret; } @@ -3172,19 +3125,17 @@ int RGWBucketCtl::read_bucket_info(const rgw_bucket& bucket, return 0; } -int RGWBucketCtl::do_store_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, - const rgw_bucket& bucket, - RGWBucketInfo& info, - optional_yield y, - const DoutPrefixProvider *dpp, - const BucketInstance::PutParams& params) +int RGWBucketCtl::store_bucket_instance_info(const rgw_bucket& bucket, + RGWBucketInfo& info, + optional_yield y, + const DoutPrefixProvider *dpp, + const BucketInstance::PutParams& params) { if (params.objv_tracker) { info.objv_tracker = *params.objv_tracker; } - return svc.bucket->store_bucket_instance_info(ctx, - RGWSI_Bucket::get_bi_meta_key(bucket), + return svc.bucket->store_bucket_instance_info(RGWSI_Bucket::get_bi_meta_key(bucket), info, params.orig_info, params.exclusive, @@ -3194,17 +3145,6 @@ int RGWBucketCtl::do_store_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, dpp); } -int RGWBucketCtl::store_bucket_instance_info(const rgw_bucket& bucket, - RGWBucketInfo& info, - optional_yield y, - const DoutPrefixProvider *dpp, - const BucketInstance::PutParams& params) -{ - return bmi_handler->call([&](RGWSI_Bucket_BI_Ctx& ctx) { - return do_store_bucket_instance_info(ctx, bucket, info, y, dpp, params); - }); -} - int RGWBucketCtl::remove_bucket_instance_info(const rgw_bucket& bucket, RGWBucketInfo& info, optional_yield y, @@ -3215,18 +3155,14 @@ int RGWBucketCtl::remove_bucket_instance_info(const rgw_bucket& bucket, info.objv_tracker = *params.objv_tracker; } - return bmi_handler->call([&](RGWSI_Bucket_BI_Ctx& ctx) { - return svc.bucket->remove_bucket_instance_info(ctx, - RGWSI_Bucket::get_bi_meta_key(bucket), - info, - &info.objv_tracker, - y, - dpp); - }); + return svc.bucket->remove_bucket_instance_info(RGWSI_Bucket::get_bi_meta_key(bucket), + info, + &info.objv_tracker, + y, + dpp); } -int RGWBucketCtl::do_store_linked_bucket_info(RGWSI_Bucket_X_Ctx& ctx, - RGWBucketInfo& info, +int RGWBucketCtl::do_store_linked_bucket_info(RGWBucketInfo& info, RGWBucketInfo *orig_info, bool exclusive, real_time mtime, obj_version *pep_objv, @@ -3236,8 +3172,7 @@ int RGWBucketCtl::do_store_linked_bucket_info(RGWSI_Bucket_X_Ctx& ctx, { bool create_head = !info.has_instance_obj || create_entry_point; - int ret = svc.bucket->store_bucket_instance_info(ctx.bi, - RGWSI_Bucket::get_bi_meta_key(info.bucket), + int ret = svc.bucket->store_bucket_instance_info(RGWSI_Bucket::get_bi_meta_key(info.bucket), info, orig_info, exclusive, @@ -3264,22 +3199,17 @@ int RGWBucketCtl::do_store_linked_bucket_info(RGWSI_Bucket_X_Ctx& ctx, *pep_objv = ot.write_version; } } - ret = svc.bucket->store_bucket_entrypoint_info(ctx.ep, - RGWSI_Bucket::get_entrypoint_meta_key(info.bucket), - entry_point, - exclusive, - mtime, - pattrs, - &ot, - y, - dpp); - if (ret < 0) - return ret; - - return 0; + return svc.bucket->store_bucket_entrypoint_info(RGWSI_Bucket::get_entrypoint_meta_key(info.bucket), + entry_point, + exclusive, + mtime, + pattrs, + &ot, + y, + dpp); } -int RGWBucketCtl::convert_old_bucket_info(RGWSI_Bucket_X_Ctx& ctx, - const rgw_bucket& bucket, + +int RGWBucketCtl::convert_old_bucket_info(const rgw_bucket& bucket, optional_yield y, const DoutPrefixProvider *dpp) { @@ -3292,8 +3222,7 @@ int RGWBucketCtl::convert_old_bucket_info(RGWSI_Bucket_X_Ctx& ctx, ldpp_dout(dpp, 10) << "RGWRados::convert_old_bucket_info(): bucket=" << bucket << dendl; - int ret = svc.bucket->read_bucket_entrypoint_info(ctx.ep, - RGWSI_Bucket::get_entrypoint_meta_key(bucket), + int ret = svc.bucket->read_bucket_entrypoint_info(RGWSI_Bucket::get_entrypoint_meta_key(bucket), &entry_point, &ot, &ep_mtime, &attrs, y, dpp); if (ret < 0) { ldpp_dout(dpp, 0) << "ERROR: get_bucket_entrypoint_info() returned " << ret << " bucket=" << bucket << dendl; @@ -3309,7 +3238,7 @@ int RGWBucketCtl::convert_old_bucket_info(RGWSI_Bucket_X_Ctx& ctx, ot.generate_new_write_ver(cct); - ret = do_store_linked_bucket_info(ctx, info, nullptr, false, ep_mtime, &ot.write_version, &attrs, true, y, dpp); + ret = do_store_linked_bucket_info(info, nullptr, false, ep_mtime, &ot.write_version, &attrs, true, y, dpp); if (ret < 0) { ldpp_dout(dpp, 0) << "ERROR: failed to put_linked_bucket_info(): " << ret << dendl; return ret; @@ -3324,43 +3253,24 @@ int RGWBucketCtl::set_bucket_instance_attrs(RGWBucketInfo& bucket_info, optional_yield y, const DoutPrefixProvider *dpp) { - return call([&](RGWSI_Bucket_X_Ctx& ctx) { - rgw_bucket& bucket = bucket_info.bucket; + rgw_bucket& bucket = bucket_info.bucket; - if (!bucket_info.has_instance_obj) { - /* an old bucket object, need to convert it */ - int ret = convert_old_bucket_info(ctx, bucket, y, dpp); - if (ret < 0) { - ldpp_dout(dpp, 0) << "ERROR: failed converting old bucket info: " << ret << dendl; - return ret; - } - } + if (!bucket_info.has_instance_obj) { + /* an old bucket object, need to convert it */ + int ret = convert_old_bucket_info(bucket, y, dpp); + if (ret < 0) { + ldpp_dout(dpp, 0) << "ERROR: failed converting old bucket info: " << ret << dendl; + return ret; + } + } - return do_store_bucket_instance_info(ctx.bi, - bucket, - bucket_info, - y, - dpp, - BucketInstance::PutParams().set_attrs(&attrs) - .set_objv_tracker(objv_tracker) - .set_orig_info(&bucket_info)); - }); -} - - -int RGWBucketCtl::link_bucket(librados::Rados& rados, - const rgw_owner& owner, - const rgw_bucket& bucket, - ceph::real_time creation_time, - optional_yield y, - const DoutPrefixProvider *dpp, - bool update_entrypoint, - rgw_ep_info *pinfo) -{ - return bm_handler->call([&](RGWSI_Bucket_EP_Ctx& ctx) { - return do_link_bucket(ctx, rados, owner, bucket, creation_time, - update_entrypoint, pinfo, y, dpp); - }); + return store_bucket_instance_info(bucket, + bucket_info, + y, + dpp, + BucketInstance::PutParams().set_attrs(&attrs) + .set_objv_tracker(objv_tracker) + .set_orig_info(&bucket_info)); } static rgw_raw_obj get_owner_buckets_obj(RGWSI_User* svc_user, @@ -3377,15 +3287,14 @@ static rgw_raw_obj get_owner_buckets_obj(RGWSI_User* svc_user, }), owner); } -int RGWBucketCtl::do_link_bucket(RGWSI_Bucket_EP_Ctx& ctx, - librados::Rados& rados, - const rgw_owner& owner, - const rgw_bucket& bucket, - ceph::real_time creation_time, - bool update_entrypoint, - rgw_ep_info *pinfo, - optional_yield y, - const DoutPrefixProvider *dpp) +int RGWBucketCtl::link_bucket(librados::Rados& rados, + const rgw_owner& owner, + const rgw_bucket& bucket, + ceph::real_time creation_time, + optional_yield y, + const DoutPrefixProvider *dpp, + bool update_entrypoint, + rgw_ep_info *pinfo) { int ret; @@ -3401,8 +3310,7 @@ int RGWBucketCtl::do_link_bucket(RGWSI_Bucket_EP_Ctx& ctx, ep = pinfo->ep; pattrs = &pinfo->attrs; } else { - ret = svc.bucket->read_bucket_entrypoint_info(ctx, - meta_key, + ret = svc.bucket->read_bucket_entrypoint_info(meta_key, &ep, &rot, nullptr, &attrs, y, dpp); @@ -3433,14 +3341,14 @@ int RGWBucketCtl::do_link_bucket(RGWSI_Bucket_EP_Ctx& ctx, ep.owner = owner; ep.bucket = bucket; ret = svc.bucket->store_bucket_entrypoint_info( - ctx, meta_key, ep, false, real_time(), pattrs, &rot, y, dpp); + meta_key, ep, false, real_time(), pattrs, &rot, y, dpp); if (ret < 0) goto done_err; return 0; done_err: - int r = do_unlink_bucket(ctx, rados, owner, bucket, true, y, dpp); + int r = unlink_bucket(rados, owner, bucket, y, dpp, true); if (r < 0) { ldpp_dout(dpp, 0) << "ERROR: failed unlinking bucket on error cleanup: " << cpp_strerror(-r) << dendl; @@ -3451,19 +3359,6 @@ int RGWBucketCtl::do_link_bucket(RGWSI_Bucket_EP_Ctx& ctx, int RGWBucketCtl::unlink_bucket(librados::Rados& rados, const rgw_owner& owner, const rgw_bucket& bucket, optional_yield y, const DoutPrefixProvider *dpp, bool update_entrypoint) -{ - return bm_handler->call([&](RGWSI_Bucket_EP_Ctx& ctx) { - return do_unlink_bucket(ctx, rados, owner, bucket, update_entrypoint, y, dpp); - }); -} - -int RGWBucketCtl::do_unlink_bucket(RGWSI_Bucket_EP_Ctx& ctx, - librados::Rados& rados, - const rgw_owner& owner, - const rgw_bucket& bucket, - bool update_entrypoint, - optional_yield y, - const DoutPrefixProvider *dpp) { const auto& buckets_obj = get_owner_buckets_obj(svc.user, svc.zone, owner); int ret = rgwrados::buckets::remove(dpp, y, rados, buckets_obj, bucket); @@ -3479,7 +3374,7 @@ int RGWBucketCtl::do_unlink_bucket(RGWSI_Bucket_EP_Ctx& ctx, RGWObjVersionTracker ot; map attrs; string meta_key = RGWSI_Bucket::get_entrypoint_meta_key(bucket); - ret = svc.bucket->read_bucket_entrypoint_info(ctx, meta_key, &ep, &ot, nullptr, &attrs, y, dpp); + ret = svc.bucket->read_bucket_entrypoint_info(meta_key, &ep, &ot, nullptr, &attrs, y, dpp); if (ret == -ENOENT) return 0; if (ret < 0) @@ -3494,7 +3389,7 @@ int RGWBucketCtl::do_unlink_bucket(RGWSI_Bucket_EP_Ctx& ctx, } ep.linked = false; - return svc.bucket->store_bucket_entrypoint_info(ctx, meta_key, ep, false, real_time(), &attrs, &ot, y, dpp); + return svc.bucket->store_bucket_entrypoint_info(meta_key, ep, false, real_time(), &attrs, &ot, y, dpp); } int RGWBucketCtl::read_bucket_stats(const rgw_bucket& bucket, @@ -3502,17 +3397,13 @@ int RGWBucketCtl::read_bucket_stats(const rgw_bucket& bucket, optional_yield y, const DoutPrefixProvider *dpp) { - return call([&](RGWSI_Bucket_X_Ctx& ctx) { - return svc.bucket->read_bucket_stats(ctx, bucket, result, y, dpp); - }); + return svc.bucket->read_bucket_stats(bucket, result, y, dpp); } int RGWBucketCtl::read_buckets_stats(std::vector& buckets, optional_yield y, const DoutPrefixProvider *dpp) { - return call([&](RGWSI_Bucket_X_Ctx& ctx) { - return svc.bucket->read_buckets_stats(ctx, buckets, y, dpp); - }); + return svc.bucket->read_buckets_stats(buckets, y, dpp); } int RGWBucketCtl::sync_owner_stats(const DoutPrefixProvider *dpp, @@ -3550,9 +3441,7 @@ int RGWBucketCtl::get_sync_policy_handler(std::optional zone, optional_yield y, const DoutPrefixProvider *dpp) { - int r = call([&](RGWSI_Bucket_X_Ctx& ctx) { - return svc.bucket_sync->get_policy_handler(ctx, zone, bucket, phandler, y, dpp); - }); + int r = svc.bucket_sync->get_policy_handler(zone, bucket, phandler, y, dpp); if (r < 0) { ldpp_dout(dpp, 20) << __func__ << "(): failed to get policy handler for bucket=" << bucket << " (r=" << r << ")" << dendl; return r; @@ -3589,27 +3478,44 @@ int RGWBucketCtl::bucket_imports_data(const rgw_bucket& bucket, return handler->bucket_imports_data(); } -RGWBucketMetadataHandlerBase* RGWBucketMetaHandlerAllocator::alloc(librados::Rados& rados) +auto create_bucket_metadata_handler(librados::Rados& rados, + RGWSI_Bucket* svc_bucket, + RGWBucketCtl* ctl_bucket) + -> std::unique_ptr { - return new RGWBucketMetadataHandler(rados); + return std::make_unique( + rados, svc_bucket, ctl_bucket); } -RGWBucketInstanceMetadataHandlerBase* RGWBucketInstanceMetaHandlerAllocator::alloc(rgw::sal::Driver* driver) +auto create_bucket_instance_metadata_handler(rgw::sal::Driver* driver, + RGWSI_Zone* svc_zone, + RGWSI_Bucket* svc_bucket, + RGWSI_BucketIndex* svc_bi) + -> std::unique_ptr { - return new RGWBucketInstanceMetadataHandler(driver); + return std::make_unique(driver, svc_zone, + svc_bucket, svc_bi); } -RGWBucketMetadataHandlerBase* RGWArchiveBucketMetaHandlerAllocator::alloc(librados::Rados& rados) +auto create_archive_bucket_metadata_handler(librados::Rados& rados, + RGWSI_Bucket* svc_bucket, + RGWBucketCtl* ctl_bucket) + -> std::unique_ptr { - return new RGWArchiveBucketMetadataHandler(rados); + return std::make_unique( + rados, svc_bucket, ctl_bucket); } -RGWBucketInstanceMetadataHandlerBase* RGWArchiveBucketInstanceMetaHandlerAllocator::alloc(rgw::sal::Driver* driver) +auto create_archive_bucket_instance_metadata_handler(rgw::sal::Driver* driver, + RGWSI_Zone* svc_zone, + RGWSI_Bucket* svc_bucket, + RGWSI_BucketIndex* svc_bi) + -> std::unique_ptr { - return new RGWArchiveBucketInstanceMetadataHandler(driver); + return std::make_unique(driver, svc_zone, + svc_bucket, svc_bi); } - void RGWBucketEntryPoint::generate_test_instances(list& o) { RGWBucketEntryPoint *bp = new RGWBucketEntryPoint(); diff --git a/src/rgw/driver/rados/rgw_bucket.h b/src/rgw/driver/rados/rgw_bucket.h index 6bbfba93df215..85434ba7299cb 100644 --- a/src/rgw/driver/rados/rgw_bucket.h +++ b/src/rgw/driver/rados/rgw_bucket.h @@ -26,13 +26,11 @@ #include "rgw_formats.h" -#include "services/svc_bucket_types.h" #include "services/svc_bucket_sync.h" // define as static when RGWBucket implementation completes extern void rgw_get_buckets_obj(const rgw_user& user_id, std::string& buckets_obj_id); -class RGWSI_Meta; class RGWBucketMetadataHandler; class RGWBucketInstanceMetadataHandler; class RGWUserCtl; @@ -171,41 +169,32 @@ class RGWUserBuckets { }; WRITE_CLASS_ENCODER(RGWUserBuckets) -class RGWBucketMetadataHandlerBase : public RGWMetadataHandler_GenericMetaBE { -public: - virtual ~RGWBucketMetadataHandlerBase() {} - virtual void init(RGWSI_Bucket *bucket_svc, - RGWBucketCtl *bucket_ctl) = 0; - -}; - -class RGWBucketInstanceMetadataHandlerBase : public RGWMetadataHandler_GenericMetaBE { -public: - virtual ~RGWBucketInstanceMetadataHandlerBase() {} - virtual void init(RGWSI_Zone *zone_svc, - RGWSI_Bucket *bucket_svc, - RGWSI_BucketIndex *bi_svc) = 0; -}; - -class RGWBucketMetaHandlerAllocator { -public: - static RGWBucketMetadataHandlerBase *alloc(librados::Rados& rados); -}; +// bucket entrypoint metadata handler factory +auto create_bucket_metadata_handler(librados::Rados& rados, + RGWSI_Bucket* svc_bucket, + RGWBucketCtl* ctl_bucket) + -> std::unique_ptr; + +// bucket instance metadata handler factory +auto create_bucket_instance_metadata_handler(rgw::sal::Driver* driver, + RGWSI_Zone* svc_zone, + RGWSI_Bucket* svc_bucket, + RGWSI_BucketIndex* svc_bi) + -> std::unique_ptr; + +// archive bucket entrypoint metadata handler factory +auto create_archive_bucket_metadata_handler(librados::Rados& rados, + RGWSI_Bucket* svc_bucket, + RGWBucketCtl* ctl_bucket) + -> std::unique_ptr; + +// archive bucket instance metadata handler factory +auto create_archive_bucket_instance_metadata_handler(rgw::sal::Driver* driver, + RGWSI_Zone* svc_zone, + RGWSI_Bucket* svc_bucket, + RGWSI_BucketIndex* svc_bi) + -> std::unique_ptr; -class RGWBucketInstanceMetaHandlerAllocator { -public: - static RGWBucketInstanceMetadataHandlerBase *alloc(rgw::sal::Driver* driver); -}; - -class RGWArchiveBucketMetaHandlerAllocator { -public: - static RGWBucketMetadataHandlerBase *alloc(librados::Rados& rados); -}; - -class RGWArchiveBucketInstanceMetaHandlerAllocator { -public: - static RGWBucketInstanceMetadataHandlerBase *alloc(rgw::sal::Driver* driver); -}; extern int rgw_remove_object(const DoutPrefixProvider *dpp, rgw::sal::Driver* driver, rgw::sal::Bucket* bucket, rgw_obj_key& key, optional_yield y); @@ -441,14 +430,6 @@ class RGWBucketCtl { RGWUserCtl *user{nullptr}; } ctl; - RGWBucketMetadataHandler *bm_handler; - RGWBucketInstanceMetadataHandler *bmi_handler; - - RGWSI_Bucket_BE_Handler bucket_be_handler; /* bucket backend handler */ - RGWSI_BucketInstance_BE_Handler bi_be_handler; /* bucket instance backend handler */ - - int call(std::function f); - public: RGWBucketCtl(RGWSI_Zone *zone_svc, RGWSI_Bucket *bucket_svc, @@ -457,8 +438,6 @@ class RGWBucketCtl { RGWSI_User* user_svc); void init(RGWUserCtl *user_ctl, - RGWBucketMetadataHandler *_bm_handler, - RGWBucketInstanceMetadataHandler *_bmi_handler, RGWDataChangesLog *datalog, const DoutPrefixProvider *dpp); @@ -469,7 +448,6 @@ class RGWBucketCtl { std::map *attrs{nullptr}; rgw_cache_entry_info *cache_info{nullptr}; boost::optional refresh_version; - std::optional bectx_params; GetParams() {} @@ -497,11 +475,6 @@ class RGWBucketCtl { refresh_version = _refresh_version; return *this; } - - GetParams& set_bectx_params(std::optional _bectx_params) { - bectx_params = _bectx_params; - return *this; - } }; struct PutParams { @@ -552,7 +525,6 @@ class RGWBucketCtl { rgw_cache_entry_info *cache_info{nullptr}; boost::optional refresh_version; RGWObjVersionTracker *objv_tracker{nullptr}; - std::optional bectx_params; GetParams() {} @@ -580,11 +552,6 @@ class RGWBucketCtl { objv_tracker = _objv_tracker; return *this; } - - GetParams& set_bectx_params(std::optional _bectx_params) { - bectx_params = _bectx_params; - return *this; - } }; struct PutParams { @@ -736,20 +703,11 @@ class RGWBucketCtl { const DoutPrefixProvider *dpp); private: - int convert_old_bucket_info(RGWSI_Bucket_X_Ctx& ctx, - const rgw_bucket& bucket, + int convert_old_bucket_info(const rgw_bucket& bucket, optional_yield y, const DoutPrefixProvider *dpp); - int do_store_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, - const rgw_bucket& bucket, - RGWBucketInfo& info, - optional_yield y, - const DoutPrefixProvider *dpp, - const BucketInstance::PutParams& params); - - int do_store_linked_bucket_info(RGWSI_Bucket_X_Ctx& ctx, - RGWBucketInfo& info, + int do_store_linked_bucket_info(RGWBucketInfo& info, RGWBucketInfo *orig_info, bool exclusive, real_time mtime, obj_version *pep_objv, @@ -757,25 +715,6 @@ class RGWBucketCtl { bool create_entry_point, optional_yield, const DoutPrefixProvider *dpp); - - int do_link_bucket(RGWSI_Bucket_EP_Ctx& ctx, - librados::Rados& rados, - const rgw_owner& owner, - const rgw_bucket& bucket, - ceph::real_time creation_time, - bool update_entrypoint, - rgw_ep_info *pinfo, - optional_yield y, - const DoutPrefixProvider *dpp); - - int do_unlink_bucket(RGWSI_Bucket_EP_Ctx& ctx, - librados::Rados& rados, - const rgw_owner& owner, - const rgw_bucket& bucket, - bool update_entrypoint, - optional_yield y, - const DoutPrefixProvider *dpp); - }; bool rgw_find_bucket_by_id(const DoutPrefixProvider *dpp, CephContext *cct, rgw::sal::Driver* driver, const std::string& marker, diff --git a/src/rgw/driver/rados/rgw_data_sync.cc b/src/rgw/driver/rados/rgw_data_sync.cc index 58f5cd0690c46..b6cc23bd74a6b 100644 --- a/src/rgw/driver/rados/rgw_data_sync.cc +++ b/src/rgw/driver/rados/rgw_data_sync.cc @@ -3120,11 +3120,19 @@ class RGWArchiveSyncModuleInstance : public RGWDefaultSyncModuleInstance { RGWDataSyncModule *get_data_handler() override { return &data_handler; } - RGWMetadataHandler *alloc_bucket_meta_handler(librados::Rados& rados) override { - return RGWArchiveBucketMetaHandlerAllocator::alloc(rados); - } - RGWBucketInstanceMetadataHandlerBase *alloc_bucket_instance_meta_handler(rgw::sal::Driver* driver) override { - return RGWArchiveBucketInstanceMetaHandlerAllocator::alloc(driver); + auto alloc_bucket_meta_handler(librados::Rados& rados, + RGWSI_Bucket* svc_bucket, + RGWBucketCtl* ctl_bucket) + -> std::unique_ptr override { + return create_archive_bucket_metadata_handler(rados, svc_bucket, ctl_bucket); + } + auto alloc_bucket_instance_meta_handler(rgw::sal::Driver* driver, + RGWSI_Zone* svc_zone, + RGWSI_Bucket* svc_bucket, + RGWSI_BucketIndex* svc_bi) + -> std::unique_ptr override { + return create_archive_bucket_instance_metadata_handler( + driver, svc_zone, svc_bucket, svc_bi); } }; diff --git a/src/rgw/driver/rados/rgw_metadata.h b/src/rgw/driver/rados/rgw_metadata.h index c83db7c40437b..30425542a1b96 100644 --- a/src/rgw/driver/rados/rgw_metadata.h +++ b/src/rgw/driver/rados/rgw_metadata.h @@ -15,7 +15,6 @@ #include "cls/log/cls_log_types.h" #include "common/RefCountedObj.h" #include "common/ceph_time.h" -#include "services/svc_meta_be.h" #include "rgw_sal_fwd.h" @@ -54,18 +53,11 @@ class RGWMetadataManager; class RGWMetadataHandler { friend class RGWMetadataManager; -protected: - CephContext *cct; - public: RGWMetadataHandler() {} virtual ~RGWMetadataHandler(); virtual std::string get_type() = 0; - void base_init(CephContext *_cct) { - cct = _cct; - } - virtual RGWMetadataObject *get_meta_obj(JSONObj *jo, const obj_version& objv, const ceph::real_time& mtime) = 0; virtual int get(std::string& entry, RGWMetadataObject **obj, optional_yield, const DoutPrefixProvider *dpp) = 0; @@ -99,132 +91,12 @@ class RGWMetadataHandler { virtual int attach(RGWMetadataManager *manager); }; -class RGWMetadataHandler_GenericMetaBE : public RGWMetadataHandler { - friend class RGWSI_MetaBackend; - friend class RGWMetadataManager; - friend class Put; - -public: - class Put; - -protected: - RGWSI_MetaBackend_Handler *be_handler; - - virtual int do_get(RGWSI_MetaBackend_Handler::Op *op, std::string& entry, RGWMetadataObject **obj, optional_yield y, const DoutPrefixProvider *dpp) = 0; - virtual int do_put(RGWSI_MetaBackend_Handler::Op *op, std::string& entry, RGWMetadataObject *obj, - RGWObjVersionTracker& objv_tracker, optional_yield y, - const DoutPrefixProvider *dpp, RGWMDLogSyncType type, - bool from_remote_zone) = 0; - virtual int do_put_operate(Put *put_op, const DoutPrefixProvider *dpp); - virtual int do_remove(RGWSI_MetaBackend_Handler::Op *op, std::string& entry, RGWObjVersionTracker& objv_tracker, optional_yield y, const DoutPrefixProvider *dpp) = 0; - -public: - RGWMetadataHandler_GenericMetaBE() {} - - void base_init(CephContext *_cct, - RGWSI_MetaBackend_Handler *_be_handler) { - RGWMetadataHandler::base_init(_cct); - be_handler = _be_handler; - } - - RGWSI_MetaBackend_Handler *get_be_handler() { - return be_handler; - } - - class Put { - protected: - RGWMetadataHandler_GenericMetaBE *handler; - RGWSI_MetaBackend_Handler::Op *op; - std::string& entry; - RGWMetadataObject *obj; - RGWObjVersionTracker& objv_tracker; - RGWMDLogSyncType apply_type; - optional_yield y; - bool from_remote_zone{false}; - - int get(RGWMetadataObject **obj, const DoutPrefixProvider *dpp) { - return handler->do_get(op, entry, obj, y, dpp); - } - public: - Put(RGWMetadataHandler_GenericMetaBE *_handler, RGWSI_MetaBackend_Handler::Op *_op, - std::string& _entry, RGWMetadataObject *_obj, - RGWObjVersionTracker& _objv_tracker, optional_yield _y, - RGWMDLogSyncType _type, bool from_remote_zone); - - virtual ~Put() {} - - virtual int put_pre(const DoutPrefixProvider *dpp) { - return 0; - } - virtual int put(const DoutPrefixProvider *dpp) { - return 0; - } - virtual int put_post(const DoutPrefixProvider *dpp) { - return 0; - } - virtual int finalize() { - return 0; - } - }; - - int get(std::string& entry, RGWMetadataObject **obj, optional_yield, const DoutPrefixProvider *dpp) override; - int put(std::string& entry, RGWMetadataObject *obj, RGWObjVersionTracker& objv_tracker, optional_yield, const DoutPrefixProvider *dpp, RGWMDLogSyncType type, bool from_remote_zone) override; - int remove(std::string& entry, RGWObjVersionTracker& objv_tracker, optional_yield, const DoutPrefixProvider *dpp) override; - - int mutate(const std::string& entry, - const ceph::real_time& mtime, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp, - RGWMDLogStatus op_type, - std::function f) override; - - int get_shard_id(const std::string& entry, int *shard_id) override; - - int list_keys_init(const DoutPrefixProvider *dpp, const std::string& marker, void **phandle) override; - int list_keys_next(const DoutPrefixProvider *dpp, void *handle, int max, std::list& keys, bool *truncated) override; - void list_keys_complete(void *handle) override; - - std::string get_marker(void *handle) override; - - /** - * Compare an incoming versus on-disk tag/version+mtime combo against - * the sync mode to see if the new one should replace the on-disk one. - * - * @return true if the update should proceed, false otherwise. - */ - static bool check_versions(bool exists, - const obj_version& ondisk, const real_time& ondisk_time, - const obj_version& incoming, const real_time& incoming_time, - RGWMDLogSyncType sync_mode) { - switch (sync_mode) { - case APPLY_UPDATES: - if ((ondisk.tag != incoming.tag) || - (ondisk.ver >= incoming.ver)) - return false; - break; - case APPLY_NEWER: - if (ondisk_time >= incoming_time) - return false; - break; - case APPLY_EXCLUSIVE: - if (exists) - return false; - break; - case APPLY_ALWAYS: //deliberate fall-thru -- we always apply! - default: break; - } - return true; - } -}; - class RGWMetadataTopHandler; class RGWMetadataManager { friend class RGWMetadataHandler; CephContext *cct; - RGWSI_Meta *meta_svc; std::map handlers; std::unique_ptr md_top_handler; @@ -232,7 +104,7 @@ class RGWMetadataManager { int register_handler(RGWMetadataHandler *handler); public: - RGWMetadataManager(RGWSI_Meta *_meta_svc); + RGWMetadataManager(); ~RGWMetadataManager(); RGWMetadataHandler *get_handler(const std::string& type); @@ -269,29 +141,6 @@ class RGWMetadataManager { int get_shard_id(const std::string& section, const std::string& key, int *shard_id); }; -class RGWMetadataHandlerPut_SObj : public RGWMetadataHandler_GenericMetaBE::Put -{ -protected: - std::unique_ptr oo; - RGWMetadataObject *old_obj{nullptr}; - bool exists{false}; - -public: - RGWMetadataHandlerPut_SObj(RGWMetadataHandler_GenericMetaBE *handler, RGWSI_MetaBackend_Handler::Op *op, - std::string& entry, RGWMetadataObject *obj, RGWObjVersionTracker& objv_tracker, - optional_yield y, - RGWMDLogSyncType type, bool from_remote_zone); - ~RGWMetadataHandlerPut_SObj(); - - int put_pre(const DoutPrefixProvider *dpp) override; - int put(const DoutPrefixProvider *dpp) override; - virtual int put_check(const DoutPrefixProvider *dpp) { - return 0; - } - virtual int put_checked(const DoutPrefixProvider *dpp); - virtual void encode_obj(bufferlist *bl) {} -}; - void rgw_shard_name(const std::string& prefix, unsigned max_shards, const std::string& key, std::string& name, int *shard_id); void rgw_shard_name(const std::string& prefix, unsigned max_shards, const std::string& section, const std::string& key, std::string& name); void rgw_shard_name(const std::string& prefix, unsigned shard_id, std::string& name); diff --git a/src/rgw/driver/rados/rgw_metadata_lister.h b/src/rgw/driver/rados/rgw_metadata_lister.h index 9fbb21ac3b402..3d35fc7bfeddf 100644 --- a/src/rgw/driver/rados/rgw_metadata_lister.h +++ b/src/rgw/driver/rados/rgw_metadata_lister.h @@ -49,6 +49,7 @@ class RGWMetadataLister { int get_next(const DoutPrefixProvider* dpp, int max, std::list& keys, bool* truncated) { + keys.clear(); std::vector oids; int r = listing.get_next(dpp, max, &oids, truncated); if (r == -ENOENT) { diff --git a/src/rgw/driver/rados/rgw_otp.cc b/src/rgw/driver/rados/rgw_otp.cc index 07cc14f113b5f..aac10338d8836 100644 --- a/src/rgw/driver/rados/rgw_otp.cc +++ b/src/rgw/driver/rados/rgw_otp.cc @@ -1,211 +1,157 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab ft=cpp -#include - -#include -#include -#include - -#include "common/errno.h" -#include "common/Formatter.h" -#include "common/ceph_json.h" #include "rgw_otp.h" -#include "rgw_zone.h" +#include +#include +#include "services/svc_cls.h" +#include "services/svc_mdlog.h" +#include "services/svc_sys_obj.h" #include "rgw_metadata.h" +#include "rgw_metadata_lister.h" +#include "rgw_zone.h" -#include "include/types.h" - -#include "rgw_common.h" -#include "rgw_tools.h" - -#include "services/svc_zone.h" -#include "services/svc_meta.h" -#include "services/svc_meta_be.h" -#include "services/svc_meta_be_otp.h" -#include "services/svc_otp.h" - -#define dout_subsys ceph_subsys_rgw - -using namespace std; - - -class RGWOTPMetadataHandler; - -class RGWOTPMetadataObject : public RGWMetadataObject { - friend class RGWOTPMetadataHandler; - otp_devices_list_t devices; +class MetadataObject : public RGWMetadataObject { public: - RGWOTPMetadataObject() {} - RGWOTPMetadataObject(otp_devices_list_t&& _devices, const obj_version& v, const real_time m) { - devices = std::move(_devices); - objv = v; - mtime = m; - } + std::list devices; - void dump(Formatter *f) const override { - encode_json("devices", devices, f); - } + MetadataObject(std::list devices, + const obj_version& v, ceph::real_time m) + : RGWMetadataObject(v, m), devices(std::move(devices)) + {} - otp_devices_list_t& get_devs() { - return devices; + void dump(Formatter* f) const override { + encode_json("devices", devices, f); } }; - -class RGWOTPMetadataHandler : public RGWOTPMetadataHandlerBase { - friend class RGWOTPCtl; - - struct Svc { - RGWSI_Zone *zone; - RGWSI_MetaBackend *meta_be; - RGWSI_OTP *otp; - } svc; - - int init(RGWSI_Zone *zone, - RGWSI_MetaBackend *_meta_be, - RGWSI_OTP *_otp) { - base_init(zone->ctx(), _otp->get_be_handler().get()); - svc.zone = zone; - svc.meta_be = _meta_be; - svc.otp = _otp; - return 0; - } - - int call(std::function f) { - return be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) { - RGWSI_OTP_BE_Ctx ctx(op->ctx()); - return f(ctx); - }); - } - - RGWMetadataObject *get_meta_obj(JSONObj *jo, const obj_version& objv, const ceph::real_time& mtime) override { - otp_devices_list_t devices; +class MetadataHandler : public RGWMetadataHandler { + RGWSI_SysObj& sysobj; + RGWSI_Cls::MFA& mfa; + RGWSI_MDLog& mdlog; + const RGWZoneParams& zone; + public: + MetadataHandler(RGWSI_SysObj& sysobj, RGWSI_Cls::MFA& mfa, + RGWSI_MDLog& mdlog, const RGWZoneParams& zone) + : sysobj(sysobj), mfa(mfa), mdlog(mdlog), zone(zone) {} + + std::string get_type() override { return "otp"; } + + RGWMetadataObject* get_meta_obj(JSONObj* obj, + const obj_version& objv, + const ceph::real_time& mtime) override + { + std::list devices; try { - JSONDecoder::decode_json("devices", devices, jo); - } catch (JSONDecoder::err& e) { + JSONDecoder::decode_json("devices", devices, obj); + } catch (const JSONDecoder::err&) { return nullptr; } - - return new RGWOTPMetadataObject(std::move(devices), objv, mtime); + return new MetadataObject(std::move(devices), objv, mtime); } - int do_get(RGWSI_MetaBackend_Handler::Op *op, string& entry, RGWMetadataObject **obj, optional_yield y, const DoutPrefixProvider *dpp) override { - RGWObjVersionTracker objv_tracker; - - std::unique_ptr mdo(new RGWOTPMetadataObject); - - - RGWSI_OTP_BE_Ctx be_ctx(op->ctx()); + int get(std::string& entry, RGWMetadataObject** obj, + optional_yield y, const DoutPrefixProvider* dpp) override + { + std::list devices; + RGWObjVersionTracker objv; + ceph::real_time mtime; - int ret = svc.otp->read_all(be_ctx, - entry, - &mdo->get_devs(), - &mdo->get_mtime(), - &objv_tracker, - y, - dpp); - if (ret < 0) { - return ret; + int r = mfa.list_mfa(dpp, entry, &devices, &objv, &mtime, y); + if (r < 0) { + return r; } - mdo->objv = objv_tracker.read_version; + *obj = new MetadataObject(std::move(devices), objv.read_version, mtime); + return 0; + } - *obj = mdo.release(); + int put(std::string& entry, RGWMetadataObject* obj, + RGWObjVersionTracker& objv, optional_yield y, + const DoutPrefixProvider* dpp, + RGWMDLogSyncType type, bool from_remote_zone) override + { + auto otp_obj = static_cast(obj); + int r = mfa.set_mfa(dpp, entry, otp_obj->devices, true, + &objv, obj->get_mtime(), y); + if (r < 0) { + return r; + } + return mdlog.complete_entry(dpp, y, "otp", entry, &objv); + } - return 0; + int remove(std::string& entry, RGWObjVersionTracker& objv, + optional_yield y, const DoutPrefixProvider* dpp) override + { + int r = rgw_delete_system_obj(dpp, &sysobj, zone.otp_pool, entry, &objv, y); + if (r < 0) { + return r; + } + return mdlog.complete_entry(dpp, y, "otp", entry, &objv); } - int do_put(RGWSI_MetaBackend_Handler::Op *op, string& entry, - RGWMetadataObject *_obj, RGWObjVersionTracker& objv_tracker, + int mutate(const std::string& entry, + const ceph::real_time& mtime, + RGWObjVersionTracker* objv, optional_yield y, - const DoutPrefixProvider *dpp, - RGWMDLogSyncType type, bool from_remote_zone) override { - RGWOTPMetadataObject *obj = static_cast(_obj); - - RGWSI_OTP_BE_Ctx be_ctx(op->ctx()); - - int ret = svc.otp->store_all(dpp, be_ctx, - entry, - obj->devices, - obj->mtime, - &objv_tracker, - y); - if (ret < 0) { - return ret; + const DoutPrefixProvider* dpp, + RGWMDLogStatus op_type, + std::function f) override + { + int r = f(); + if (r < 0) { + return r; } - - return STATUS_APPLIED; + return mdlog.complete_entry(dpp, y, "otp", entry, objv); } - int do_remove(RGWSI_MetaBackend_Handler::Op *op, string& entry, RGWObjVersionTracker& objv_tracker, - optional_yield y, const DoutPrefixProvider *dpp) override { - RGWSI_MBOTP_RemoveParams params; - RGWSI_OTP_BE_Ctx be_ctx(op->ctx()); + int list_keys_init(const DoutPrefixProvider* dpp, + const std::string& marker, void** phandle) override + { + auto lister = std::make_unique(sysobj.get_pool(zone.otp_pool)); + int r = lister->init(dpp, marker, ""); // no prefix + if (r < 0) { + return r; + } + *phandle = lister.release(); + return 0; + } - return svc.otp->remove_all(dpp, be_ctx, - entry, - &objv_tracker, - y); + int list_keys_next(const DoutPrefixProvider* dpp, void* handle, int max, + std::list& keys, bool* truncated) override + { + auto lister = static_cast(handle); + return lister->get_next(dpp, max, keys, truncated); } -public: - RGWOTPMetadataHandler() {} + void list_keys_complete(void* handle) override + { + delete static_cast(handle); + } - string get_type() override { return "otp"; } + std::string get_marker(void* handle) override + { + auto lister = static_cast(handle); + return lister->get_marker(); + } }; -RGWOTPCtl::RGWOTPCtl(RGWSI_Zone *zone_svc, - RGWSI_OTP *otp_svc) -{ - svc.zone = zone_svc; - svc.otp = otp_svc; -} - - -void RGWOTPCtl::init(RGWOTPMetadataHandler *_meta_handler) -{ - meta_handler = _meta_handler; - be_handler = meta_handler->get_be_handler(); -} +// public interface +namespace rgwrados::otp { -int RGWOTPCtl::read_all(const rgw_user& uid, - RGWOTPInfo *info, - optional_yield y, - const DoutPrefixProvider *dpp, - const GetParams& params) +std::string get_meta_key(const rgw_user& user) { - info->uid = uid; - return meta_handler->call([&](RGWSI_OTP_BE_Ctx& ctx) { - return svc.otp->read_all(ctx, uid, &info->devices, params.mtime, params.objv_tracker, y, dpp); - }); + return fmt::format("otp:user:{}", user.to_str()); } -int RGWOTPCtl::store_all(const DoutPrefixProvider *dpp, - const RGWOTPInfo& info, - optional_yield y, - const PutParams& params) +auto create_metadata_handler(RGWSI_SysObj& sysobj, RGWSI_Cls& cls, + RGWSI_MDLog& mdlog, const RGWZoneParams& zone) + -> std::unique_ptr { - return meta_handler->call([&](RGWSI_OTP_BE_Ctx& ctx) { - return svc.otp->store_all(dpp, ctx, info.uid, info.devices, params.mtime, params.objv_tracker, y); - }); + return std::make_unique(sysobj, cls.mfa, mdlog, zone); } -int RGWOTPCtl::remove_all(const DoutPrefixProvider *dpp, - const rgw_user& uid, - optional_yield y, - const RemoveParams& params) -{ - return meta_handler->call([&](RGWSI_OTP_BE_Ctx& ctx) { - return svc.otp->remove_all(dpp, ctx, uid, params.objv_tracker, y); - }); -} - - -RGWMetadataHandler *RGWOTPMetaHandlerAllocator::alloc() -{ - return new RGWOTPMetadataHandler(); -} +} // namespace rgwrados::otp diff --git a/src/rgw/driver/rados/rgw_otp.h b/src/rgw/driver/rados/rgw_otp.h index 885e8abb8e1d7..72b64d27fd4fc 100644 --- a/src/rgw/driver/rados/rgw_otp.h +++ b/src/rgw/driver/rados/rgw_otp.h @@ -3,108 +3,24 @@ #pragma once -#include "rgw_sal_fwd.h" -#include "cls/otp/cls_otp_types.h" -#include "services/svc_meta_be_otp.h" +#include +#include -#include "rgw_basic_types.h" -#include "rgw_metadata.h" - - -class RGWObjVersionTracker; +struct rgw_user; class RGWMetadataHandler; -class RGWOTPMetadataHandler; -class RGWSI_Zone; -class RGWSI_OTP; -class RGWSI_MetaBackend; - -class RGWOTPMetadataHandlerBase : public RGWMetadataHandler_GenericMetaBE { -public: - virtual ~RGWOTPMetadataHandlerBase() {} - virtual int init(RGWSI_Zone *zone, - RGWSI_MetaBackend *_meta_be, - RGWSI_OTP *_otp) = 0; -}; - -class RGWOTPMetaHandlerAllocator { -public: - static RGWMetadataHandler *alloc(); -}; - -struct RGWOTPInfo { - rgw_user uid; - otp_devices_list_t devices; -}; - - -class RGWOTPCtl -{ - struct Svc { - RGWSI_Zone *zone{nullptr}; - RGWSI_OTP *otp{nullptr}; - } svc; - - RGWOTPMetadataHandler *meta_handler; - RGWSI_MetaBackend_Handler *be_handler; - -public: - RGWOTPCtl(RGWSI_Zone *zone_svc, - RGWSI_OTP *otp_svc); - - void init(RGWOTPMetadataHandler *_meta_handler); - - struct GetParams { - RGWObjVersionTracker *objv_tracker{nullptr}; - ceph::real_time *mtime{nullptr}; - - GetParams() {} - - GetParams& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) { - objv_tracker = _objv_tracker; - return *this; - } - - GetParams& set_mtime(ceph::real_time *_mtime) { - mtime = _mtime; - return *this; - } - }; - - struct PutParams { - RGWObjVersionTracker *objv_tracker{nullptr}; - ceph::real_time mtime; - - PutParams() {} - - PutParams& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) { - objv_tracker = _objv_tracker; - return *this; - } - - PutParams& set_mtime(const ceph::real_time& _mtime) { - mtime = _mtime; - return *this; - } - }; +class RGWSI_Cls; +class RGWSI_MDLog; +class RGWSI_SysObj; +class RGWZoneParams; - struct RemoveParams { - RGWObjVersionTracker *objv_tracker{nullptr}; +namespace rgwrados::otp { - RemoveParams() {} +// return the user's otp metadata key +std::string get_meta_key(const rgw_user& user); - RemoveParams& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) { - objv_tracker = _objv_tracker; - return *this; - } - }; +// otp metadata handler factory +auto create_metadata_handler(RGWSI_SysObj& sysobj, RGWSI_Cls& cls, + RGWSI_MDLog& mdlog, const RGWZoneParams& zone) + -> std::unique_ptr; - int read_all(const rgw_user& uid, RGWOTPInfo *info, optional_yield y, - const DoutPrefixProvider *dpp, - const GetParams& params = {}); - int store_all(const DoutPrefixProvider *dpp, - const RGWOTPInfo& info, optional_yield y, - const PutParams& params = {}); - int remove_all(const DoutPrefixProvider *dpp, - const rgw_user& user, optional_yield y, - const RemoveParams& params = {}); -}; +} // namespace rgwrados::otp diff --git a/src/rgw/driver/rados/rgw_sal_rados.cc b/src/rgw/driver/rados/rgw_sal_rados.cc index e3b435d283919..91b3cc0264887 100644 --- a/src/rgw/driver/rados/rgw_sal_rados.cc +++ b/src/rgw/driver/rados/rgw_sal_rados.cc @@ -28,6 +28,7 @@ #include "common/Clock.h" #include "common/errno.h" +#include "role.h" #include "rgw_sal.h" #include "rgw_sal_rados.h" #include "rgw_bucket.h" @@ -56,8 +57,6 @@ #include "rgw_rest_user.h" #include "services/svc_sys_obj.h" #include "services/svc_mdlog.h" -#include "services/svc_meta.h" -#include "services/svc_meta_be_sobj.h" #include "services/svc_cls.h" #include "services/svc_bilog_rados.h" #include "services/svc_bi_rados.h" @@ -66,7 +65,6 @@ #include "services/svc_quota.h" #include "services/svc_config_key.h" #include "services/svc_zone_utils.h" -#include "services/svc_role_rados.h" #include "services/svc_user.h" #include "services/svc_sys_obj_cache.h" #include "cls/rgw/cls_rgw_client.h" @@ -572,21 +570,18 @@ int RadosBucket::load_bucket(const DoutPrefixProvider* dpp, optional_yield y) { int ret; - RGWSI_MetaBackend_CtxParams bectx_params = RGWSI_MetaBackend_CtxParams_SObj(); RGWObjVersionTracker ep_ot; if (info.bucket.bucket_id.empty()) { ret = store->ctl()->bucket->read_bucket_info(info.bucket, &info, y, dpp, RGWBucketCtl::BucketInstance::GetParams() .set_mtime(&mtime) - .set_attrs(&attrs) - .set_bectx_params(bectx_params), + .set_attrs(&attrs), &ep_ot); } else { ret = store->ctl()->bucket->read_bucket_instance_info(info.bucket, &info, y, dpp, RGWBucketCtl::BucketInstance::GetParams() .set_mtime(&mtime) - .set_attrs(&attrs) - .set_bectx_params(bectx_params)); + .set_attrs(&attrs)); } if (ret != 0) { return ret; @@ -1286,15 +1281,16 @@ int RadosStore::list_account_roles(const DoutPrefixProvider* dpp, // load the role metadata for each for (const auto& id : ids) { - std::unique_ptr role = get_role(id); - r = role->read_info(dpp, y); + RGWRoleInfo info; + r = rgwrados::role::read_by_id(dpp, y, *svc()->sysobj, zone, id, + info, nullptr, nullptr, nullptr); if (r == -ENOENT) { continue; } if (r < 0) { return r; } - listing.roles.push_back(std::move(role->get_info())); + listing.roles.push_back(std::move(info)); } return 0; @@ -2016,67 +2012,10 @@ int RadosStore::list_roles(const DoutPrefixProvider *dpp, uint32_t max_items, RoleList& listing) { - listing.roles.clear(); - - const auto& pool = svc()->zone->get_zone_params().roles_pool; - std::string prefix; - - // List all roles if path prefix is empty - if (! path_prefix.empty()) { - prefix = tenant + RGWRole::role_path_oid_prefix + path_prefix; - } else { - prefix = tenant + RGWRole::role_path_oid_prefix; - } - - //Get the filtered objects - RGWListRawObjsCtx ctx; - int r = rados->list_raw_objects_init(dpp, pool, marker, &ctx); - if (r < 0) { - return r; - } - - bool is_truncated = false; - list oids; - r = rados->list_raw_objects(dpp, pool, prefix, max_items, - ctx, oids, &is_truncated); - if (r == -ENOENT) { - r = 0; - } else if (r < 0) { - return r; - } - - for (const auto& oid : oids) { - const std::string key = oid.substr(RGWRole::role_path_oid_prefix.size()); - - //Find the role oid prefix from the end - size_t pos = key.rfind(RGWRole::role_oid_prefix); - if (pos == std::string::npos) { - continue; - } - // Split the result into path and info_oid + id - std::string path = key.substr(0, pos); - - /*Make sure that prefix is part of path (False results could've been returned) - because of the role info oid + id appended to the path)*/ - if(path_prefix.empty() || path.find(path_prefix) != std::string::npos) { - //Get id from info oid prefix + id - std::string id = key.substr(pos + RGWRole::role_oid_prefix.length()); - - std::unique_ptr role = get_role(id); - r = role->read_info(dpp, y); - if (r < 0) { - return r; - } - listing.roles.push_back(std::move(role->get_info())); - } - } - - if (is_truncated) { - listing.next_marker = rados->list_raw_objs_get_cursor(ctx); - } else { - listing.next_marker.clear(); - } - return 0; + const RGWZoneParams& zone = svc()->zone->get_zone_params(); + return rgwrados::role::list_tenant(dpp, y, *svc()->sysobj, zone, + tenant, marker, max_items, path_prefix, + listing.roles, listing.next_marker); } static constexpr std::string_view oidc_url_oid_prefix = "oidc_url."; @@ -4434,321 +4373,39 @@ std::ostream& RadosLuaManager::PackagesWatcher::gen_prefix(std::ostream& out) co int RadosRole::store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) { - using ceph::encode; - std::string oid; - - oid = info.id; - - bufferlist bl; - encode(this->info, bl); - - if (!this->info.tags.empty()) { - bufferlist bl_tags; - encode(this->info.tags, bl_tags); - map attrs; - attrs.emplace("tagging", bl_tags); - - RGWSI_MBSObj_PutParams params(bl, &attrs, info.mtime, exclusive); - std::unique_ptr ctx(store->svc()->role->svc.meta_be->alloc_ctx()); - ctx->init(store->svc()->role->get_be_handler()); - return store->svc()->role->svc.meta_be->put(ctx.get(), oid, params, &info.objv_tracker, y, dpp); - } else { - RGWSI_MBSObj_PutParams params(bl, nullptr, info.mtime, exclusive); - std::unique_ptr ctx(store->svc()->role->svc.meta_be->alloc_ctx()); - ctx->init(store->svc()->role->get_be_handler()); - return store->svc()->role->svc.meta_be->put(ctx.get(), oid, params, &info.objv_tracker, y, dpp); - } -} - -static std::string role_name_oid(const RGWRoleInfo& r, std::string_view prefix) -{ - if (!r.account_id.empty()) { - // names are case-insensitive, so store them in lower case - std::string lower_name = r.name; - boost::algorithm::to_lower(lower_name); - // use account id as prefix - return string_cat_reserve(r.account_id, prefix, lower_name); - } else { - // use tenant as prefix - return string_cat_reserve(r.tenant, prefix, r.name); - } -} - -int RadosRole::store_name(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) -{ - auto sysobj = store->svc()->sysobj; - RGWNameToId nameToId; - nameToId.obj_id = info.id; - - std::string oid = role_name_oid(info, get_names_oid_prefix()); - - bufferlist bl; - using ceph::encode; - encode(nameToId, bl); - - return rgw_put_system_obj(dpp, sysobj, store->svc()->zone->get_zone_params().roles_pool, oid, bl, exclusive, &info.objv_tracker, real_time(), y); -} - -int RadosRole::store_path(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) -{ - if (!info.account_id.empty()) { - librados::Rados& rados = *store->getRados()->get_rados_handle(); - const RGWZoneParams& zone = store->svc()->zone->get_zone_params(); - const rgw_raw_obj& obj = rgwrados::account::get_roles_obj(zone, info.account_id); - constexpr uint32_t no_limit = std::numeric_limits::max(); - return rgwrados::roles::add(dpp, y, rados, obj, info, false, no_limit); - } - - auto sysobj = store->svc()->sysobj; - std::string oid = info.tenant + get_path_oid_prefix() + info.path + get_info_oid_prefix() + info.id; - - bufferlist bl; - - return rgw_put_system_obj(dpp, sysobj, store->svc()->zone->get_zone_params().roles_pool, oid, bl, exclusive, &info.objv_tracker, real_time(), y); -} - -int RadosRole::read_id(const DoutPrefixProvider *dpp, const std::string& role_name, const std::string& tenant, std::string& role_id, optional_yield y) -{ - auto sysobj = store->svc()->sysobj; - std::string oid = info.tenant + get_names_oid_prefix() + role_name; - bufferlist bl; - - int ret = rgw_get_system_obj(sysobj, store->svc()->zone->get_zone_params().roles_pool, oid, bl, nullptr, nullptr, y, dpp); - if (ret < 0) { - return ret; - } - - RGWNameToId nameToId; - try { - auto iter = bl.cbegin(); - using ceph::decode; - decode(nameToId, iter); - } catch (buffer::error& err) { - ldpp_dout(dpp, 0) << "ERROR: failed to decode role from Role pool: " << role_name << dendl; - return -EIO; - } - role_id = nameToId.obj_id; - return 0; -} - -int RadosRole::read_name(const DoutPrefixProvider *dpp, optional_yield y) -{ - auto sysobj = store->svc()->sysobj; - std::string oid = role_name_oid(info, get_names_oid_prefix()); - bufferlist bl; - - int ret = rgw_get_system_obj(sysobj, store->svc()->zone->get_zone_params().roles_pool, oid, bl, nullptr, nullptr, y, dpp); - if (ret < 0) { - ldpp_dout(dpp, 0) << "ERROR: failed reading role name from Role pool: " << info.name << - ": " << cpp_strerror(-ret) << dendl; - return ret; - } - - RGWNameToId nameToId; - try { - using ceph::decode; - auto iter = bl.cbegin(); - decode(nameToId, iter); - } catch (buffer::error& err) { - ldpp_dout(dpp, 0) << "ERROR: failed to decode role name from Role pool: " << info.name << dendl; - return -EIO; - } - info.id = nameToId.obj_id; - return 0; + librados::Rados& rados = *store->getRados()->get_rados_handle(); + RGWServices* svc = store->svc(); + const RGWZoneParams& zone = svc->zone->get_zone_params(); + return rgwrados::role::write(dpp, y, rados, *svc->sysobj, svc->mdlog, + zone, info, info.objv_tracker, + ceph::real_time{}, exclusive); } -int RadosRole::read_info(const DoutPrefixProvider *dpp, optional_yield y) +int RadosRole::load_by_name(const DoutPrefixProvider *dpp, optional_yield y) { - std::string oid; - - oid = info.id; - ldpp_dout(dpp, 20) << "INFO: oid in read_info is: " << oid << dendl; - - bufferlist bl; - - RGWSI_MBSObj_GetParams params(&bl, &info.attrs, &info.mtime); - std::unique_ptr ctx(store->svc()->role->svc.meta_be->alloc_ctx()); - ctx->init(store->svc()->role->get_be_handler()); - int ret = store->svc()->role->svc.meta_be->get(ctx.get(), oid, params, &info.objv_tracker, y, dpp, true); - if (ret < 0) { - ldpp_dout(dpp, 0) << "ERROR: failed reading role info from Role pool: " << info.id << ": " << cpp_strerror(-ret) << dendl; - return ret; - } - - try { - using ceph::decode; - auto iter = bl.cbegin(); - decode(this->info, iter); - } catch (buffer::error& err) { - ldpp_dout(dpp, 0) << "ERROR: failed to decode role info from Role pool: " << info.id << dendl; - return -EIO; - } - - auto it = info.attrs.find("tagging"); - if (it != info.attrs.end()) { - bufferlist bl_tags = it->second; - try { - using ceph::decode; - auto iter = bl_tags.cbegin(); - decode(info.tags, iter); - } catch (buffer::error& err) { - ldpp_dout(dpp, 0) << "ERROR: failed to decode attrs" << info.id << dendl; - return -EIO; - } - } - - return 0; + RGWServices* svc = store->svc(); + const RGWZoneParams& zone = svc->zone->get_zone_params(); + return rgwrados::role::read_by_name(dpp, y, *svc->sysobj, zone, + info.tenant, info.account_id, + info.name, info, &info.mtime, + &info.objv_tracker); } -int RadosRole::create(const DoutPrefixProvider *dpp, bool exclusive, const std::string& role_id, optional_yield y) +int RadosRole::load_by_id(const DoutPrefixProvider *dpp, optional_yield y) { - int ret; - - if (! validate_input(dpp)) { - return -EINVAL; - } - - if (!role_id.empty()) { - info.id = role_id; - } - - /* check to see the name is not used */ - ret = read_id(dpp, info.name, info.tenant, info.id, y); - if (exclusive && ret == 0) { - ldpp_dout(dpp, 0) << "ERROR: name " << info.name << " already in use for role id " - << info.id << dendl; - return -EEXIST; - } else if ( ret < 0 && ret != -ENOENT) { - ldpp_dout(dpp, 0) << "failed reading role id " << info.id << ": " - << cpp_strerror(-ret) << dendl; - return ret; - } - - if (info.id.empty()) { - /* create unique id */ - uuid_d new_uuid; - char uuid_str[37]; - new_uuid.generate_random(); - new_uuid.print(uuid_str); - info.id = uuid_str; - } - - //arn - std::string_view account = !info.account_id.empty() ? info.account_id : info.tenant; - info.arn = string_cat_reserve(role_arn_prefix, account, ":role", info.path, info.name); - - if (info.creation_date.empty()) { - // Creation time - real_clock::time_point t = real_clock::now(); - - struct timeval tv; - real_clock::to_timeval(t, tv); - - char buf[30]; - struct tm result; - gmtime_r(&tv.tv_sec, &result); - strftime(buf,30,"%Y-%m-%dT%H:%M:%S", &result); - sprintf(buf + strlen(buf),".%03dZ",(int)tv.tv_usec/1000); - info.creation_date.assign(buf, strlen(buf)); - } - - auto& pool = store->svc()->zone->get_zone_params().roles_pool; - ret = store_info(dpp, exclusive, y); - if (ret < 0) { - ldpp_dout(dpp, 0) << "ERROR: storing role info in Role pool: " - << info.id << ": " << cpp_strerror(-ret) << dendl; - return ret; - } - - ret = store_name(dpp, exclusive, y); - if (ret < 0) { - ldpp_dout(dpp, 0) << "ERROR: storing role name in Role pool: " - << info.name << ": " << cpp_strerror(-ret) << dendl; - - //Delete the role info that was stored in the previous call - std::string oid = get_info_oid_prefix() + info.id; - int info_ret = rgw_delete_system_obj(dpp, store->svc()->sysobj, pool, oid, nullptr, y); - if (info_ret < 0) { - ldpp_dout(dpp, 0) << "ERROR: cleanup of role id from Role pool: " - << info.id << ": " << cpp_strerror(-info_ret) << dendl; - } - return ret; - } - - ret = store_path(dpp, exclusive, y); - if (ret < 0) { - ldpp_dout(dpp, 0) << "ERROR: storing role path in Role pool: " - << info.path << ": " << cpp_strerror(-ret) << dendl; - //Delete the role info that was stored in the previous call - std::string oid = get_info_oid_prefix() + info.id; - int info_ret = rgw_delete_system_obj(dpp, store->svc()->sysobj, pool, oid, nullptr, y); - if (info_ret < 0) { - ldpp_dout(dpp, 0) << "ERROR: cleanup of role id from Role pool: " - << info.id << ": " << cpp_strerror(-info_ret) << dendl; - } - //Delete role name that was stored in previous call - oid = role_name_oid(info, get_names_oid_prefix()); - int name_ret = rgw_delete_system_obj(dpp, store->svc()->sysobj, pool, oid, nullptr, y); - if (name_ret < 0) { - ldpp_dout(dpp, 0) << "ERROR: cleanup of role name from Role pool: " - << info.name << ": " << cpp_strerror(-name_ret) << dendl; - } - return ret; - } - return 0; + RGWServices* svc = store->svc(); + const RGWZoneParams& zone = svc->zone->get_zone_params(); + return rgwrados::role::read_by_id(dpp, y, *svc->sysobj, zone, info.id, + info, &info.mtime, &info.objv_tracker); } int RadosRole::delete_obj(const DoutPrefixProvider *dpp, optional_yield y) { - auto& pool = store->svc()->zone->get_zone_params().roles_pool; - - int ret = read_name(dpp, y); - if (ret < 0) { - return ret; - } - - ret = read_info(dpp, y); - if (ret < 0) { - return ret; - } - - // Delete id & insert MD Log - RGWSI_MBSObj_RemoveParams params; - std::unique_ptr ctx(store->svc()->role->svc.meta_be->alloc_ctx()); - ctx->init(store->svc()->role->get_be_handler()); - ret = store->svc()->role->svc.meta_be->remove(ctx.get(), info.id, params, &info.objv_tracker, y, dpp); - if (ret < 0) { - ldpp_dout(dpp, 0) << "ERROR: deleting role id: " << info.id << " failed with code: " << cpp_strerror(-ret) << dendl; - return ret; - } - - // Delete name - std::string oid = role_name_oid(info, get_names_oid_prefix()); - ret = rgw_delete_system_obj(dpp, store->svc()->sysobj, pool, oid, nullptr, y); - if (ret < 0) { - ldpp_dout(dpp, 0) << "ERROR: deleting role name from Role pool: " - << info.name << ": " << cpp_strerror(-ret) << dendl; - } - - // Delete path - if (!info.account_id.empty()) { - librados::Rados& rados = *store->getRados()->get_rados_handle(); - const RGWZoneParams& zone = store->svc()->zone->get_zone_params(); - const rgw_raw_obj& obj = rgwrados::account::get_roles_obj(zone, info.account_id); - ret = rgwrados::roles::remove(dpp, y, rados, obj, info.name); - if (ret < 0) { - ldpp_dout(dpp, 4) << "ERROR: deleting role path from account list: " - << info.path << ": " << cpp_strerror(-ret) << dendl; - } - } else { - oid = info.tenant + get_path_oid_prefix() + info.path + get_info_oid_prefix() + info.id; - ret = rgw_delete_system_obj(dpp, store->svc()->sysobj, pool, oid, nullptr, y); - if (ret < 0) { - ldpp_dout(dpp, 4) << "ERROR: deleting role path from Role pool: " - << info.path << ": " << cpp_strerror(-ret) << dendl; - } - } - return 0; + librados::Rados& rados = *store->getRados()->get_rados_handle(); + RGWServices* svc = store->svc(); + const RGWZoneParams& zone = svc->zone->get_zone_params(); + return rgwrados::role::remove(dpp, y, rados, *svc->sysobj, svc->mdlog, zone, + info.tenant, info.account_id, info.name); } } // namespace rgw::sal diff --git a/src/rgw/driver/rados/rgw_sal_rados.h b/src/rgw/driver/rados/rgw_sal_rados.h index d359f733ab352..0372c5882aa16 100644 --- a/src/rgw/driver/rados/rgw_sal_rados.h +++ b/src/rgw/driver/rados/rgw_sal_rados.h @@ -1164,13 +1164,10 @@ class RadosRole : public RGWRole { RadosRole(RadosStore* _store) : store(_store) {} ~RadosRole() = default; - virtual int store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) override; - virtual int store_name(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) override; - virtual int store_path(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) override; - virtual int read_id(const DoutPrefixProvider *dpp, const std::string& role_name, const std::string& tenant, std::string& role_id, optional_yield y) override; - virtual int read_name(const DoutPrefixProvider *dpp, optional_yield y) override; - virtual int read_info(const DoutPrefixProvider *dpp, optional_yield y) override; - virtual int create(const DoutPrefixProvider *dpp, bool exclusive, const std::string& role_id, optional_yield y) override; - virtual int delete_obj(const DoutPrefixProvider *dpp, optional_yield y) override; + int load_by_name(const DoutPrefixProvider *dpp, optional_yield y) override; + int load_by_id(const DoutPrefixProvider *dpp, optional_yield y) override; + int store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) override; + int delete_obj(const DoutPrefixProvider *dpp, optional_yield y) override; }; + }} // namespace rgw::sal diff --git a/src/rgw/driver/rados/rgw_service.cc b/src/rgw/driver/rados/rgw_service.cc index 5e7dd81c7162f..784fefd0bcba7 100644 --- a/src/rgw/driver/rados/rgw_service.cc +++ b/src/rgw/driver/rados/rgw_service.cc @@ -11,12 +11,7 @@ #include "services/svc_cls.h" #include "services/svc_config_key_rados.h" #include "services/svc_mdlog.h" -#include "services/svc_meta.h" -#include "services/svc_meta_be.h" -#include "services/svc_meta_be_sobj.h" -#include "services/svc_meta_be_otp.h" #include "services/svc_notify.h" -#include "services/svc_otp.h" #include "services/svc_zone.h" #include "services/svc_zone_utils.h" #include "services/svc_quota.h" @@ -25,7 +20,6 @@ #include "services/svc_sys_obj_cache.h" #include "services/svc_sys_obj_core.h" #include "services/svc_user_rados.h" -#include "services/svc_role_rados.h" #include "common/errno.h" @@ -38,7 +32,7 @@ #include "rgw_otp.h" #include "rgw_sal_rados.h" #include "rgw_user.h" -#include "rgw_role.h" +#include "role.h" #include "rgw_pubsub.h" #include "topic.h" @@ -69,11 +63,7 @@ int RGWServices_Def::init(CephContext *cct, config_key_rados = std::make_unique(cct); datalog_rados = std::make_unique(cct); mdlog = std::make_unique(cct, run_sync); - meta = std::make_unique(cct); - meta_be_sobj = std::make_unique(cct); - meta_be_otp = std::make_unique(cct); notify = std::make_unique(cct); - otp = std::make_unique(cct); zone = std::make_unique(cct); zone_utils = std::make_unique(cct); quota = std::make_unique(cct); @@ -81,7 +71,6 @@ int RGWServices_Def::init(CephContext *cct, sysobj = std::make_unique(cct); sysobj_core = std::make_unique(cct); user_rados = std::make_unique(cct); - role_rados = std::make_unique(cct); async_processor = std::make_unique( cct, cct->_conf->rgw_num_async_rados_threads); @@ -89,15 +78,13 @@ int RGWServices_Def::init(CephContext *cct, sysobj_cache = std::make_unique(dpp, cct); } - vector meta_bes{meta_be_sobj.get(), meta_be_otp.get()}; - async_processor->start(); finisher->init(); bi_rados->init(zone.get(), driver->getRados()->get_rados_handle(), bilog_rados.get(), datalog_rados.get()); bilog_rados->init(bi_rados.get()); bucket_sobj->init(zone.get(), sysobj.get(), sysobj_cache.get(), - bi_rados.get(), meta.get(), meta_be_sobj.get(), + bi_rados.get(), mdlog.get(), sync_modules.get(), bucket_sync_sobj.get()); bucket_sync_sobj->init(zone.get(), sysobj.get(), @@ -107,12 +94,8 @@ int RGWServices_Def::init(CephContext *cct, config_key_rados->init(driver->getRados()->get_rados_handle()); mdlog->init(driver->getRados()->get_rados_handle(), zone.get(), sysobj.get(), cls.get(), async_processor.get()); - meta->init(sysobj.get(), mdlog.get(), meta_bes); - meta_be_sobj->init(sysobj.get(), mdlog.get()); - meta_be_otp->init(sysobj.get(), mdlog.get(), cls.get()); notify->init(zone.get(), driver->getRados()->get_rados_handle(), finisher.get()); - otp->init(zone.get(), meta.get(), meta_be_otp.get()); zone->init(sysobj.get(), driver->getRados()->get_rados_handle(), sync_modules.get(), bucket_sync_sobj.get()); zone_utils->init(driver->getRados()->get_rados_handle(), zone.get()); @@ -125,9 +108,9 @@ int RGWServices_Def::init(CephContext *cct, } else { sysobj->init(driver->getRados()->get_rados_handle(), sysobj_core.get()); } - user_rados->init(driver->getRados()->get_rados_handle(), zone.get(), sysobj.get(), sysobj_cache.get(), - meta.get(), meta_be_sobj.get(), sync_modules.get()); - role_rados->init(zone.get(), meta.get(), meta_be_sobj.get(), sysobj.get()); + user_rados->init(driver->getRados()->get_rados_handle(), zone.get(), + mdlog.get(), sysobj.get(), sysobj_cache.get()); + can_shutdown = true; int r = finisher->start(y, dpp); @@ -217,18 +200,6 @@ int RGWServices_Def::init(CephContext *cct, } if (!raw) { - r = meta_be_sobj->start(y, dpp); - if (r < 0) { - ldpp_dout(dpp, 0) << "ERROR: failed to start meta_be_sobj service (" << cpp_strerror(-r) << dendl; - return r; - } - - r = meta->start(y, dpp); - if (r < 0) { - ldpp_dout(dpp, 0) << "ERROR: failed to start meta service (" << cpp_strerror(-r) << dendl; - return r; - } - r = bucket_sobj->start(y, dpp); if (r < 0) { ldpp_dout(dpp, 0) << "ERROR: failed to start bucket service (" << cpp_strerror(-r) << dendl; @@ -246,18 +217,6 @@ int RGWServices_Def::init(CephContext *cct, ldpp_dout(dpp, 0) << "ERROR: failed to start user_rados service (" << cpp_strerror(-r) << dendl; return r; } - - r = otp->start(y, dpp); - if (r < 0) { - ldpp_dout(dpp, 0) << "ERROR: failed to start otp service (" << cpp_strerror(-r) << dendl; - return r; - } - - r = role_rados->start(y, dpp); - if (r < 0) { - ldout(cct, 0) << "ERROR: failed to start role_rados service (" << cpp_strerror(-r) << dendl; - return r; - } } /* cache or core services will be started by sysobj */ @@ -275,15 +234,10 @@ void RGWServices_Def::shutdown() return; } - role_rados->shutdown(); datalog_rados.reset(); user_rados->shutdown(); sync_modules->shutdown(); - otp->shutdown(); notify->shutdown(); - meta_be_otp->shutdown(); - meta_be_sobj->shutdown(); - meta->shutdown(); mdlog->shutdown(); config_key_rados->shutdown(); cls->shutdown(); @@ -330,11 +284,7 @@ int RGWServices::do_init(CephContext *_cct, rgw::sal::RadosStore* driver, bool h config_key = config_key_rados; datalog_rados = _svc.datalog_rados.get(); mdlog = _svc.mdlog.get(); - meta = _svc.meta.get(); - meta_be_sobj = _svc.meta_be_sobj.get(); - meta_be_otp = _svc.meta_be_otp.get(); notify = _svc.notify.get(); - otp = _svc.otp.get(); zone = _svc.zone.get(); zone_utils = _svc.zone_utils.get(); quota = _svc.quota.get(); @@ -343,7 +293,6 @@ int RGWServices::do_init(CephContext *_cct, rgw::sal::RadosStore* driver, bool h cache = _svc.sysobj_cache.get(); core = _svc.sysobj_core.get(); user = _svc.user_rados.get(); - role = _svc.role_rados.get(); async_processor = _svc.async_processor.get(); return 0; @@ -379,38 +328,36 @@ RGWCtlDef::_meta::~_meta() {} int RGWCtlDef::init(RGWServices& svc, rgw::sal::Driver* driver, librados::Rados& rados, const DoutPrefixProvider *dpp) { - meta.mgr.reset(new RGWMetadataManager(svc.meta)); + meta.mgr.reset(new RGWMetadataManager()); - meta.user.reset(RGWUserMetaHandlerAllocator::alloc(svc.user)); + meta.user = create_user_metadata_handler(svc.user); + + bucket.reset(new RGWBucketCtl(svc.zone, + svc.bucket, + svc.bucket_sync, + svc.bi, svc.user)); auto sync_module = svc.sync_modules->get_sync_module(); if (sync_module) { - meta.bucket.reset(sync_module->alloc_bucket_meta_handler(rados)); - meta.bucket_instance.reset(sync_module->alloc_bucket_instance_meta_handler(driver)); + meta.bucket = sync_module->alloc_bucket_meta_handler(rados, svc.bucket, bucket.get()); + meta.bucket_instance = sync_module->alloc_bucket_instance_meta_handler( + driver, svc.zone, svc.bucket, svc.bi); } else { - meta.bucket.reset(RGWBucketMetaHandlerAllocator::alloc(rados)); - meta.bucket_instance.reset(RGWBucketInstanceMetaHandlerAllocator::alloc(driver)); + meta.bucket = create_bucket_metadata_handler(rados, svc.bucket, bucket.get()); + meta.bucket_instance = create_bucket_instance_metadata_handler( + driver, svc.zone, svc.bucket, svc.bi); } - meta.otp.reset(RGWOTPMetaHandlerAllocator::alloc()); - meta.role = std::make_unique(driver, svc.role); + meta.otp = rgwrados::otp::create_metadata_handler( + *svc.sysobj, *svc.cls, *svc.mdlog, svc.zone->get_zone_params()); + meta.role = rgwrados::role::create_metadata_handler( + rados, *svc.sysobj, *svc.mdlog, svc.zone->get_zone_params()); meta.account = rgwrados::account::create_metadata_handler( *svc.sysobj, svc.zone->get_zone_params()); meta.group = rgwrados::group::create_metadata_handler( *svc.sysobj, rados, svc.zone->get_zone_params()); - user.reset(new RGWUserCtl(svc.zone, svc.user, (RGWUserMetadataHandler *)meta.user.get())); - bucket.reset(new RGWBucketCtl(svc.zone, - svc.bucket, - svc.bucket_sync, - svc.bi, svc.user)); - otp.reset(new RGWOTPCtl(svc.zone, svc.otp)); - - RGWBucketMetadataHandlerBase *bucket_meta_handler = static_cast(meta.bucket.get()); - RGWBucketInstanceMetadataHandlerBase *bi_meta_handler = static_cast(meta.bucket_instance.get()); - - bucket_meta_handler->init(svc.bucket, bucket.get()); - bi_meta_handler->init(svc.zone, svc.bucket, svc.bi); + user = std::make_unique(svc.zone, svc.user); meta.topic_cache = std::make_unique>(); meta.topic_cache->init(svc.cache); @@ -419,17 +366,8 @@ int RGWCtlDef::init(RGWServices& svc, rgw::sal::Driver* driver, *svc.sysobj, svc.cache, *svc.mdlog, rados, svc.zone->get_zone_params(), *meta.topic_cache); - RGWOTPMetadataHandlerBase *otp_handler = static_cast(meta.otp.get()); - otp_handler->init(svc.zone, svc.meta_be_otp, svc.otp); - user->init(bucket.get()); - bucket->init(user.get(), - (RGWBucketMetadataHandler *)bucket_meta_handler, - (RGWBucketInstanceMetadataHandler *)bi_meta_handler, - svc.datalog_rados, - dpp); - - otp->init((RGWOTPMetadataHandler *)meta.otp.get()); + bucket->init(user.get(), svc.datalog_rados, dpp); return 0; } @@ -457,7 +395,6 @@ int RGWCtl::init(RGWServices *_svc, rgw::sal::Driver* driver, user = _ctl.user.get(); bucket = _ctl.bucket.get(); - otp = _ctl.otp.get(); r = meta.user->attach(meta.mgr); if (r < 0) { diff --git a/src/rgw/driver/rados/rgw_service.h b/src/rgw/driver/rados/rgw_service.h index ec7f73cf6eb50..202f40d20b31e 100644 --- a/src/rgw/driver/rados/rgw_service.h +++ b/src/rgw/driver/rados/rgw_service.h @@ -62,10 +62,6 @@ class RGWSI_Cls; class RGWSI_ConfigKey; class RGWSI_ConfigKey_RADOS; class RGWSI_MDLog; -class RGWSI_Meta; -class RGWSI_MetaBackend; -class RGWSI_MetaBackend_SObj; -class RGWSI_MetaBackend_OTP; class RGWSI_Notify; class RGWSI_OTP; class RGWSI_Zone; @@ -78,7 +74,6 @@ class RGWSI_SysObj_Cache; class RGWSI_User; class RGWSI_User_RADOS; class RGWDataChangesLog; -class RGWSI_Role_RADOS; class RGWAsyncRadosProcessor; struct RGWServices_Def @@ -94,11 +89,7 @@ struct RGWServices_Def std::unique_ptr cls; std::unique_ptr config_key_rados; std::unique_ptr mdlog; - std::unique_ptr meta; - std::unique_ptr meta_be_sobj; - std::unique_ptr meta_be_otp; std::unique_ptr notify; - std::unique_ptr otp; std::unique_ptr zone; std::unique_ptr zone_utils; std::unique_ptr quota; @@ -108,7 +99,6 @@ struct RGWServices_Def std::unique_ptr sysobj_cache; std::unique_ptr user_rados; std::unique_ptr datalog_rados; - std::unique_ptr role_rados; std::unique_ptr async_processor; RGWServices_Def(); @@ -142,11 +132,7 @@ struct RGWServices RGWSI_ConfigKey *config_key{nullptr}; RGWDataChangesLog *datalog_rados{nullptr}; RGWSI_MDLog *mdlog{nullptr}; - RGWSI_Meta *meta{nullptr}; - RGWSI_MetaBackend *meta_be_sobj{nullptr}; - RGWSI_MetaBackend *meta_be_otp{nullptr}; RGWSI_Notify *notify{nullptr}; - RGWSI_OTP *otp{nullptr}; RGWSI_Zone *zone{nullptr}; RGWSI_ZoneUtils *zone_utils{nullptr}; RGWSI_Quota *quota{nullptr}; @@ -155,7 +141,6 @@ struct RGWServices RGWSI_SysObj_Cache *cache{nullptr}; RGWSI_SysObj_Core *core{nullptr}; RGWSI_User *user{nullptr}; - RGWSI_Role_RADOS *role{nullptr}; RGWAsyncRadosProcessor* async_processor; int do_init(CephContext *cct, rgw::sal::RadosStore* store, bool have_cache, @@ -183,7 +168,6 @@ class RGWMetadataManager; class RGWMetadataHandler; class RGWUserCtl; class RGWBucketCtl; -class RGWOTPCtl; template class RGWChainedCacheImpl; @@ -208,7 +192,6 @@ struct RGWCtlDef { std::unique_ptr user; std::unique_ptr bucket; - std::unique_ptr otp; RGWCtlDef(); ~RGWCtlDef(); @@ -238,7 +221,6 @@ struct RGWCtl { RGWUserCtl *user{nullptr}; RGWBucketCtl *bucket{nullptr}; - RGWOTPCtl *otp{nullptr}; int init(RGWServices *_svc, rgw::sal::Driver* driver, librados::Rados& rados, const DoutPrefixProvider *dpp); diff --git a/src/rgw/driver/rados/rgw_sync_module.cc b/src/rgw/driver/rados/rgw_sync_module.cc index a19248f2e9af5..ca25dc0a44eab 100644 --- a/src/rgw/driver/rados/rgw_sync_module.cc +++ b/src/rgw/driver/rados/rgw_sync_module.cc @@ -16,14 +16,22 @@ #define dout_subsys ceph_subsys_rgw -RGWMetadataHandler *RGWSyncModuleInstance::alloc_bucket_meta_handler(librados::Rados& rados) +auto RGWSyncModuleInstance::alloc_bucket_meta_handler(librados::Rados& rados, + RGWSI_Bucket* svc_bucket, + RGWBucketCtl* ctl_bucket) + -> std::unique_ptr { - return RGWBucketMetaHandlerAllocator::alloc(rados); + return create_bucket_metadata_handler(rados, svc_bucket, ctl_bucket); } -RGWBucketInstanceMetadataHandlerBase* RGWSyncModuleInstance::alloc_bucket_instance_meta_handler(rgw::sal::Driver* driver) +auto RGWSyncModuleInstance::alloc_bucket_instance_meta_handler(rgw::sal::Driver* driver, + RGWSI_Zone* svc_zone, + RGWSI_Bucket* svc_bucket, + RGWSI_BucketIndex* svc_bi) + -> std::unique_ptr { - return RGWBucketInstanceMetaHandlerAllocator::alloc(driver); + return create_bucket_instance_metadata_handler(driver, svc_zone, + svc_bucket, svc_bi); } RGWStatRemoteObjCBCR::RGWStatRemoteObjCBCR(RGWDataSyncCtx *_sc, diff --git a/src/rgw/driver/rados/rgw_sync_module.h b/src/rgw/driver/rados/rgw_sync_module.h index 4ca691ca665d5..cd9b2a1ba16cf 100644 --- a/src/rgw/driver/rados/rgw_sync_module.h +++ b/src/rgw/driver/rados/rgw_sync_module.h @@ -44,6 +44,10 @@ class RGWDataSyncModule { class RGWRESTMgr; class RGWMetadataHandler; class RGWBucketInstanceMetadataHandlerBase; +class RGWSI_Bucket; +class RGWSI_BucketIndex; +class RGWSI_Zone; +class RGWBucketCtl; class RGWSyncModuleInstance { public: @@ -56,8 +60,15 @@ class RGWSyncModuleInstance { virtual bool supports_user_writes() { return false; } - virtual RGWMetadataHandler *alloc_bucket_meta_handler(librados::Rados& rados); - virtual RGWBucketInstanceMetadataHandlerBase *alloc_bucket_instance_meta_handler(rgw::sal::Driver* driver); + virtual auto alloc_bucket_meta_handler(librados::Rados& rados, + RGWSI_Bucket* svc_bucket, + RGWBucketCtl* ctl_bucket) + -> std::unique_ptr; + virtual auto alloc_bucket_instance_meta_handler(rgw::sal::Driver* driver, + RGWSI_Zone* svc_zone, + RGWSI_Bucket* svc_bucket, + RGWSI_BucketIndex* svc_bi) + -> std::unique_ptr; // indication whether the sync module start with full sync (default behavior) // incremental sync would follow anyway diff --git a/src/rgw/driver/rados/rgw_trim_bilog.cc b/src/rgw/driver/rados/rgw_trim_bilog.cc index db9980470055e..d9960289a8519 100644 --- a/src/rgw/driver/rados/rgw_trim_bilog.cc +++ b/src/rgw/driver/rados/rgw_trim_bilog.cc @@ -33,7 +33,6 @@ #include "rgw_bucket.h" #include "services/svc_zone.h" -#include "services/svc_meta.h" #include "services/svc_bilog_rados.h" #include diff --git a/src/rgw/driver/rados/rgw_trim_mdlog.cc b/src/rgw/driver/rados/rgw_trim_mdlog.cc index be513b6e74df1..26b458c406960 100644 --- a/src/rgw/driver/rados/rgw_trim_mdlog.cc +++ b/src/rgw/driver/rados/rgw_trim_mdlog.cc @@ -9,7 +9,6 @@ #include "rgw_cr_rest.h" #include "rgw_zone.h" #include "services/svc_zone.h" -#include "services/svc_meta.h" #include "services/svc_mdlog.h" #include "services/svc_cls.h" diff --git a/src/rgw/driver/rados/rgw_user.cc b/src/rgw/driver/rados/rgw_user.cc index 7a8161e574177..94a18ffcbab75 100644 --- a/src/rgw/driver/rados/rgw_user.cc +++ b/src/rgw/driver/rados/rgw_user.cc @@ -1,17 +1,18 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab ft=cpp +#include "rgw_user.h" #include "common/errno.h" -#include "rgw_user.h" #include "rgw_account.h" #include "rgw_bucket.h" +#include "rgw_metadata.h" +#include "rgw_metadata_lister.h" #include "rgw_quota.h" #include "rgw_rest_iam.h" // validate_iam_user_name() #include "services/svc_user.h" -#include "services/svc_meta.h" #define dout_subsys ceph_subsys_rgw @@ -2701,42 +2702,48 @@ int RGWUserAdminOp_Caps::remove(const DoutPrefixProvider *dpp, return 0; } -class RGWUserMetadataHandler : public RGWMetadataHandler_GenericMetaBE { -public: - struct Svc { - RGWSI_User *user{nullptr}; - } svc; +struct RGWUserCompleteInfo { + RGWUserInfo info; + std::map attrs; + bool has_attrs{false}; - RGWUserMetadataHandler(RGWSI_User *user_svc) { - base_init(user_svc->ctx(), user_svc->get_be_handler()); - svc.user = user_svc; + void dump(Formatter * const f) const { + info.dump(f); + encode_json("attrs", attrs, f); } - ~RGWUserMetadataHandler() {} - - string get_type() override { return "user"; } + void decode_json(JSONObj *obj) { + decode_json_obj(info, obj); + has_attrs = JSONDecoder::decode_json("attrs", attrs, obj); + } +}; - int do_get(RGWSI_MetaBackend_Handler::Op *op, string& entry, RGWMetadataObject **obj, optional_yield y, const DoutPrefixProvider *dpp) override { - RGWUserCompleteInfo uci; - RGWObjVersionTracker objv_tracker; - real_time mtime; +class RGWUserMetadataObject : public RGWMetadataObject { + RGWUserCompleteInfo uci; +public: + RGWUserMetadataObject(const RGWUserCompleteInfo& uci, + const obj_version& v, ceph::real_time m) + : RGWMetadataObject(v, m), uci(uci) {} - rgw_user user = RGWSI_User::user_from_meta_key(entry); + void dump(Formatter *f) const override { + uci.dump(f); + } - int ret = svc.user->read_user_info(op->ctx(), user, &uci.info, &objv_tracker, - &mtime, nullptr, &uci.attrs, - y, dpp); - if (ret < 0) { - return ret; - } + RGWUserCompleteInfo& get_uci() { + return uci; + } +}; - RGWUserMetadataObject *mdo = new RGWUserMetadataObject(uci, objv_tracker.read_version, mtime); - *obj = mdo; +class RGWUserMetadataHandler : public RGWMetadataHandler { + RGWSI_User *svc_user{nullptr}; + public: + explicit RGWUserMetadataHandler(RGWSI_User* svc_user) + : svc_user(svc_user) {} - return 0; - } + string get_type() override { return "user"; } - RGWMetadataObject *get_meta_obj(JSONObj *jo, const obj_version& objv, const ceph::real_time& mtime) override { + RGWMetadataObject *get_meta_obj(JSONObj *jo, const obj_version& objv, + const ceph::real_time& mtime) override { RGWUserCompleteInfo uci; try { @@ -2748,88 +2755,144 @@ class RGWUserMetadataHandler : public RGWMetadataHandler_GenericMetaBE { return new RGWUserMetadataObject(uci, objv, mtime); } - int do_put(RGWSI_MetaBackend_Handler::Op *op, string& entry, - RGWMetadataObject *obj, - RGWObjVersionTracker& objv_tracker, - optional_yield y, const DoutPrefixProvider *dpp, - RGWMDLogSyncType type, bool from_remote_zone) override; - - int do_remove(RGWSI_MetaBackend_Handler::Op *op, string& entry, RGWObjVersionTracker& objv_tracker, - optional_yield y, const DoutPrefixProvider *dpp) override { - RGWUserInfo info; + int get(std::string& entry, RGWMetadataObject** obj, optional_yield y, + const DoutPrefixProvider *dpp) override; + int put(std::string& entry, RGWMetadataObject* obj, + RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider* dpp, + RGWMDLogSyncType type, bool from_remote_zone) override; + int remove(std::string& entry, RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider *dpp) override; + + int mutate(const std::string& entry, const ceph::real_time& mtime, + RGWObjVersionTracker* objv_tracker, optional_yield y, + const DoutPrefixProvider* dpp, RGWMDLogStatus op_type, + std::function f) override; + + int list_keys_init(const DoutPrefixProvider* dpp, const std::string& marker, + void** phandle) override; + int list_keys_next(const DoutPrefixProvider* dpp, void* handle, int max, + std::list& keys, bool* truncated) override; + void list_keys_complete(void *handle) override; + std::string get_marker(void *handle) override; +}; - rgw_user user = RGWSI_User::user_from_meta_key(entry); +int RGWUserMetadataHandler::get(std::string& entry, RGWMetadataObject **obj, + optional_yield y, const DoutPrefixProvider *dpp) +{ + RGWUserCompleteInfo uci; + RGWObjVersionTracker objv_tracker; + real_time mtime; - int ret = svc.user->read_user_info(op->ctx(), user, &info, nullptr, - nullptr, nullptr, nullptr, - y, dpp); - if (ret < 0) { - return ret; - } + rgw_user user = RGWSI_User::user_from_meta_key(entry); - return svc.user->remove_user_info(op->ctx(), info, &objv_tracker, - y, dpp); + int ret = svc_user->read_user_info(user, &uci.info, &objv_tracker, + &mtime, nullptr, &uci.attrs, + y, dpp); + if (ret < 0) { + return ret; } -}; -class RGWMetadataHandlerPut_User : public RGWMetadataHandlerPut_SObj + *obj = new RGWUserMetadataObject(uci, objv_tracker.read_version, mtime); + return 0; +} + +int RGWUserMetadataHandler::put(std::string& entry, RGWMetadataObject *obj, + RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider *dpp, + RGWMDLogSyncType type, bool from_remote_zone) { - RGWUserMetadataHandler *uhandler; - RGWUserMetadataObject *uobj; -public: - RGWMetadataHandlerPut_User(RGWUserMetadataHandler *_handler, - RGWSI_MetaBackend_Handler::Op *op, string& entry, - RGWMetadataObject *obj, RGWObjVersionTracker& objv_tracker, - optional_yield y, - RGWMDLogSyncType type, bool from_remote_zone) : RGWMetadataHandlerPut_SObj(_handler, op, entry, obj, objv_tracker, y, type, from_remote_zone), - uhandler(_handler) { - uobj = static_cast(obj); + const rgw_user user = RGWSI_User::user_from_meta_key(entry); + + // read existing user info + std::optional old = RGWUserCompleteInfo{}; + int ret = svc_user->read_user_info(user, &old->info, &objv_tracker, + nullptr, nullptr, &old->attrs, y, dpp); + if (ret == -ENOENT) { + old = std::nullopt; + } else if (ret < 0) { + return ret; } + RGWUserInfo* pold_info = (old ? &old->info : nullptr); - int put_checked(const DoutPrefixProvider *dpp) override; -}; + // store the updated user info + auto newobj = static_cast(obj); + RGWUserCompleteInfo& uci = newobj->get_uci(); + auto pattrs = (uci.has_attrs ? &uci.attrs : nullptr); + auto mtime = obj->get_mtime(); -int RGWUserMetadataHandler::do_put(RGWSI_MetaBackend_Handler::Op *op, string& entry, - RGWMetadataObject *obj, - RGWObjVersionTracker& objv_tracker, - optional_yield y, const DoutPrefixProvider *dpp, - RGWMDLogSyncType type, bool from_remote_zone) -{ - RGWMetadataHandlerPut_User put_op(this, op, entry, obj, objv_tracker, y, type, from_remote_zone); - return do_put_operate(&put_op, dpp); + ret = svc_user->store_user_info(uci.info, pold_info, &objv_tracker, + mtime, false, pattrs, y, dpp); + if (ret < 0) { + return ret; + } + + return STATUS_APPLIED; } -int RGWMetadataHandlerPut_User::put_checked(const DoutPrefixProvider *dpp) +int RGWUserMetadataHandler::remove(std::string& entry, RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider *dpp) { - RGWUserMetadataObject *orig_obj = static_cast(old_obj); - RGWUserCompleteInfo& uci = uobj->get_uci(); + RGWUserInfo info; - map *pattrs{nullptr}; - if (uci.has_attrs) { - pattrs = &uci.attrs; + rgw_user user = RGWSI_User::user_from_meta_key(entry); + + int ret = svc_user->read_user_info(user, &info, nullptr, + nullptr, nullptr, nullptr, + y, dpp); + if (ret < 0) { + return ret; } - RGWUserInfo *pold_info = (orig_obj ? &orig_obj->get_uci().info : nullptr); + return svc_user->remove_user_info(info, &objv_tracker, y, dpp); +}; - auto mtime = obj->get_mtime(); +int RGWUserMetadataHandler::mutate(const std::string& entry, const ceph::real_time& mtime, + RGWObjVersionTracker* objv_tracker, optional_yield y, + const DoutPrefixProvider* dpp, RGWMDLogStatus op_type, + std::function f) +{ + return -ENOTSUP; // unused +} - int ret = uhandler->svc.user->store_user_info(op->ctx(), uci.info, pold_info, - &objv_tracker, mtime, - false, pattrs, y, dpp); +int RGWUserMetadataHandler::list_keys_init(const DoutPrefixProvider* dpp, + const std::string& marker, + void** phandle) +{ + std::unique_ptr lister; + int ret = svc_user->create_lister(dpp, marker, lister); if (ret < 0) { return ret; } + *phandle = lister.release(); // release ownership + return 0; +} - return STATUS_APPLIED; +int RGWUserMetadataHandler::list_keys_next(const DoutPrefixProvider* dpp, + void* handle, int max, + std::list& keys, + bool* truncated) +{ + auto lister = static_cast(handle); + return lister->get_next(dpp, max, keys, truncated); +} + +void RGWUserMetadataHandler::list_keys_complete(void *handle) +{ + delete static_cast(handle); +} + +std::string RGWUserMetadataHandler::get_marker(void *handle) +{ + auto lister = static_cast(handle); + return lister->get_marker(); } -RGWUserCtl::RGWUserCtl(RGWSI_Zone *zone_svc, - RGWSI_User *user_svc, - RGWUserMetadataHandler *_umhandler) : umhandler(_umhandler) { +RGWUserCtl::RGWUserCtl(RGWSI_Zone *zone_svc, RGWSI_User *user_svc) +{ svc.zone = zone_svc; svc.user = user_svc; - be_handler = umhandler->get_be_handler(); } template @@ -2864,17 +2927,14 @@ int RGWUserCtl::get_info_by_uid(const DoutPrefixProvider *dpp, const GetParams& params) { - return be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) { - return svc.user->read_user_info(op->ctx(), - uid, - info, - params.objv_tracker, - params.mtime, - params.cache_info, - params.attrs, - y, - dpp); - }); + return svc.user->read_user_info(uid, + info, + params.objv_tracker, + params.mtime, + params.cache_info, + params.attrs, + y, + dpp); } int RGWUserCtl::get_info_by_email(const DoutPrefixProvider *dpp, @@ -2883,15 +2943,13 @@ int RGWUserCtl::get_info_by_email(const DoutPrefixProvider *dpp, optional_yield y, const GetParams& params) { - return be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) { - return svc.user->get_user_info_by_email(op->ctx(), email, - info, - params.objv_tracker, - params.attrs, - params.mtime, - y, - dpp); - }); + return svc.user->get_user_info_by_email(email, + info, + params.objv_tracker, + params.attrs, + params.mtime, + y, + dpp); } int RGWUserCtl::get_info_by_swift(const DoutPrefixProvider *dpp, @@ -2900,15 +2958,13 @@ int RGWUserCtl::get_info_by_swift(const DoutPrefixProvider *dpp, optional_yield y, const GetParams& params) { - return be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) { - return svc.user->get_user_info_by_swift(op->ctx(), swift_name, - info, - params.objv_tracker, - params.attrs, - params.mtime, - y, - dpp); - }); + return svc.user->get_user_info_by_swift(swift_name, + info, + params.objv_tracker, + params.attrs, + params.mtime, + y, + dpp); } int RGWUserCtl::get_info_by_access_key(const DoutPrefixProvider *dpp, @@ -2917,15 +2973,13 @@ int RGWUserCtl::get_info_by_access_key(const DoutPrefixProvider *dpp, optional_yield y, const GetParams& params) { - return be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) { - return svc.user->get_user_info_by_access_key(op->ctx(), access_key, - info, - params.objv_tracker, - params.attrs, - params.mtime, - y, - dpp); - }); + return svc.user->get_user_info_by_access_key(access_key, + info, + params.objv_tracker, + params.attrs, + params.mtime, + y, + dpp); } int RGWUserCtl::get_attrs_by_uid(const DoutPrefixProvider *dpp, @@ -2945,18 +2999,14 @@ int RGWUserCtl::store_info(const DoutPrefixProvider *dpp, const RGWUserInfo& info, optional_yield y, const PutParams& params) { - string key = RGWSI_User::get_meta_key(info.user_id); - - return be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) { - return svc.user->store_user_info(op->ctx(), info, - params.old_info, - params.objv_tracker, - params.mtime, - params.exclusive, - params.attrs, - y, - dpp); - }); + return svc.user->store_user_info(info, + params.old_info, + params.objv_tracker, + params.mtime, + params.exclusive, + params.attrs, + y, + dpp); } int RGWUserCtl::remove_info(const DoutPrefixProvider *dpp, @@ -2964,17 +3014,13 @@ int RGWUserCtl::remove_info(const DoutPrefixProvider *dpp, const RemoveParams& params) { - string key = RGWSI_User::get_meta_key(info.user_id); - - return be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) { - return svc.user->remove_user_info(op->ctx(), info, - params.objv_tracker, - y, dpp); - }); + return svc.user->remove_user_info(info, params.objv_tracker, y, dpp); } -RGWMetadataHandler *RGWUserMetaHandlerAllocator::alloc(RGWSI_User *user_svc) { - return new RGWUserMetadataHandler(user_svc); +auto create_user_metadata_handler(RGWSI_User *user_svc) + -> std::unique_ptr +{ + return std::make_unique(user_svc); } void rgw_user::dump(Formatter *f) const diff --git a/src/rgw/driver/rados/rgw_user.h b/src/rgw/driver/rados/rgw_user.h index d3303f96257df..ab157f38e3964 100644 --- a/src/rgw/driver/rados/rgw_user.h +++ b/src/rgw/driver/rados/rgw_user.h @@ -15,7 +15,6 @@ #include "common/Formatter.h" #include "rgw_formats.h" -#include "rgw_metadata.h" #include "rgw_sal_fwd.h" #define RGW_USER_ANON_ID "anonymous" @@ -29,6 +28,8 @@ class RGWUserCtl; class RGWBucketCtl; class RGWUserBuckets; +class RGWMetadataHandler; +class RGWSI_User; // generate a random secret access key of SECRET_KEY_LEN=40 void rgw_generate_secret_key(CephContext* cct, @@ -728,43 +729,6 @@ class RGWUserAdminOp_Caps optional_yield y); }; -struct RGWUserCompleteInfo { - RGWUserInfo info; - std::map attrs; - bool has_attrs{false}; - - void dump(Formatter * const f) const { - info.dump(f); - encode_json("attrs", attrs, f); - } - - void decode_json(JSONObj *obj) { - decode_json_obj(info, obj); - has_attrs = JSONDecoder::decode_json("attrs", attrs, obj); - } -}; - -class RGWUserMetadataObject : public RGWMetadataObject { - RGWUserCompleteInfo uci; -public: - RGWUserMetadataObject() {} - RGWUserMetadataObject(const RGWUserCompleteInfo& _uci, const obj_version& v, real_time m) - : uci(_uci) { - objv = v; - mtime = m; - } - - void dump(Formatter *f) const override { - uci.dump(f); - } - - RGWUserCompleteInfo& get_uci() { - return uci; - } -}; - -class RGWUserMetadataHandler; - class RGWUserCtl { struct Svc { @@ -776,13 +740,8 @@ class RGWUserCtl RGWBucketCtl *bucket{nullptr}; } ctl; - RGWUserMetadataHandler *umhandler; - RGWSI_MetaBackend_Handler *be_handler{nullptr}; - public: - RGWUserCtl(RGWSI_Zone *zone_svc, - RGWSI_User *user_svc, - RGWUserMetadataHandler *_umhandler); + RGWUserCtl(RGWSI_Zone *zone_svc, RGWSI_User *user_svc); void init(RGWBucketCtl *bucket_ctl) { ctl.bucket = bucket_ctl; @@ -894,7 +853,6 @@ class RGWUserCtl const RemoveParams& params = {}); }; -class RGWUserMetaHandlerAllocator { -public: - static RGWMetadataHandler *alloc(RGWSI_User *user_svc); -}; +// user metadata handler factory +auto create_user_metadata_handler(RGWSI_User *user_svc) + -> std::unique_ptr; diff --git a/src/rgw/driver/rados/role.cc b/src/rgw/driver/rados/role.cc new file mode 100644 index 0000000000000..1dd0aba6d7e05 --- /dev/null +++ b/src/rgw/driver/rados/role.cc @@ -0,0 +1,720 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab ft=cpp + +/* + * Ceph - scalable distributed file system + * + * Copyright contributors to the Ceph project + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include "role.h" + +#include +#include + +#include "common/errno.h" +#include "rgw_common.h" +#include "rgw_metadata.h" +#include "rgw_metadata_lister.h" +#include "rgw_role.h" +#include "rgw_string.h" +#include "rgw_tools.h" +#include "rgw_zone.h" +#include "svc_mdlog.h" + +#include "account.h" +#include "roles.h" + +namespace rgwrados::role { + +// RGWRoleInfo is stored in rados objects named "roles.{id}", +// where ids are assumed to be globally unique +static const std::string oid_prefix = "roles."; +// read_by_name() is enabled by rados objects +// "{tenant}role_names.{name}" for tenant roles, or +// "{account}role_names.{name}" for account roles +constexpr std::string_view name_oid_prefix = "role_names."; +// list() by path/prefix is enabled by rados objects +// "{tenant}role_paths.{path}roles.{id}" for tenant roles. +// see rgwrados::roles::list() for account roles +constexpr std::string_view path_oid_prefix = "role_paths."; + + +static rgw_raw_obj get_id_obj(const RGWZoneParams& zone, + std::string_view id) +{ + return {zone.roles_pool, string_cat_reserve(oid_prefix, id)}; +} + +static int read_info(const DoutPrefixProvider* dpp, optional_yield y, + RGWSI_SysObj& sysobj, const rgw_raw_obj& obj, + RGWRoleInfo& info, ceph::real_time* pmtime, + RGWObjVersionTracker* pobjv, + rgw_cache_entry_info* pcache_info) +{ + bufferlist bl; + std::map attrs; + // "tagging" doesn't start with RGW_ATTR_PREFIX, don't filter it out + constexpr bool raw_attrs = true; + int r = rgw_get_system_obj(&sysobj, obj.pool, obj.oid, bl, pobjv, + pmtime, y, dpp, &attrs, pcache_info, + boost::none, raw_attrs); + if (r < 0) { + return r; + } + + try { + auto p = bl.cbegin(); + decode(info, p); + } catch (const buffer::error&) { + return -EIO; + } + + if (auto i = attrs.find("tagging"); i != attrs.end()) { + try { + using ceph::decode; + auto p = i->second.cbegin(); + decode(info.tags, p); + } catch (const buffer::error&) { + ldpp_dout(dpp, 0) << "ERROR: failed to decode attrs " << info.id << dendl; + return -EIO; + } + } + + return 0; +} + +int read_by_id(const DoutPrefixProvider* dpp, optional_yield y, + RGWSI_SysObj& sysobj, const RGWZoneParams& zone, + std::string_view role_id, RGWRoleInfo& info, + ceph::real_time* pmtime, RGWObjVersionTracker* pobjv, + rgw_cache_entry_info* pcache_info) +{ + const rgw_raw_obj& obj = get_id_obj(zone, role_id); + return read_info(dpp, y, sysobj, obj, info, pmtime, pobjv, pcache_info); +} + +static int write_info(const DoutPrefixProvider* dpp, optional_yield y, + RGWSI_SysObj& sysobj, const RGWZoneParams& zone, + const RGWRoleInfo& info, RGWObjVersionTracker& objv, + ceph::real_time mtime, bool exclusive) +{ + std::map attrs; + if (!info.tags.empty()) { + using ceph::encode; + bufferlist tagbl; + encode(info.tags, tagbl); + attrs.emplace("tagging", std::move(tagbl)); + } + + bufferlist bl; + encode(info, bl); + + const rgw_raw_obj& obj = get_id_obj(zone, info.id); + int r = rgw_put_system_obj(dpp, &sysobj, obj.pool, obj.oid, + bl, exclusive, &objv, mtime, y, &attrs); + if (r < 0) { + ldpp_dout(dpp, 1) << "ERROR: failed to write role obj " << obj + << " with: " << cpp_strerror(r) << dendl; + return r; + } + return 0; +} + +struct IndexObj { + rgw_raw_obj obj; + RGWObjVersionTracker objv; +}; + +static rgw_raw_obj get_name_obj(const RGWZoneParams& zone, + std::string_view tenant, + const rgw_account_id& account, + std::string_view name) +{ + if (account.empty()) { + // use tenant as prefix + std::string oid = string_cat_reserve(tenant, name_oid_prefix, name); + return {zone.roles_pool, std::move(oid)}; + } else { + // names are case-insensitive, so store them in lower case + std::string lower_name{name}; + boost::algorithm::to_lower(lower_name); + // use account id as prefix + std::string oid = string_cat_reserve(account, name_oid_prefix, lower_name); + return {zone.roles_pool, std::move(oid)}; + } +} +static rgw_raw_obj get_name_obj(const RGWZoneParams& zone, + const RGWRoleInfo& info) +{ + return get_name_obj(zone, info.tenant, info.account_id, info.name); +} + +static int write_name(const DoutPrefixProvider* dpp, optional_yield y, + RGWSI_SysObj& sysobj, const std::string& role_id, + IndexObj& index) +{ + RGWNameToId nameToId; + nameToId.obj_id = role_id; + + bufferlist bl; + encode(nameToId, bl); + + return rgw_put_system_obj(dpp, &sysobj, index.obj.pool, index.obj.oid, bl, + true, &index.objv, ceph::real_time(), y); +} + +static int read_name(const DoutPrefixProvider* dpp, optional_yield y, + RGWSI_SysObj& sysobj, IndexObj& name, + RGWNameToId& name_to_id) +{ + bufferlist bl; + int r = rgw_get_system_obj(&sysobj, name.obj.pool, name.obj.oid, + bl, &name.objv, nullptr, y, dpp); + if (r < 0) { + ldpp_dout(dpp, 4) << "failed to read role name object " << name.obj + << " with: " << cpp_strerror(r) << dendl; + return r; + } + + try { + auto p = bl.cbegin(); + decode(name_to_id, p); + } catch (const buffer::error& e) { + ldpp_dout(dpp, 4) << "failed to decode role name object: " + << e.what() << dendl; + return -EIO; + } + return 0; +} + +static int remove_index(const DoutPrefixProvider* dpp, optional_yield y, + RGWSI_SysObj& sysobj, IndexObj& index) +{ + int r = rgw_delete_system_obj(dpp, &sysobj, index.obj.pool, + index.obj.oid, &index.objv, y); + if (r < 0) { + ldpp_dout(dpp, 20) << "WARNING: failed to remove " + << index.obj << " with " << cpp_strerror(r) << dendl; + } + return r; +} + +using NameIndex = std::optional; + +static int remove_index(const DoutPrefixProvider* dpp, optional_yield y, + RGWSI_SysObj& sysobj, NameIndex& index) +{ + if (index) { + return remove_index(dpp, y, sysobj, *index); + } + return 0; +} + + +static rgw_raw_obj get_tenant_path_obj(const RGWZoneParams& zone, + const RGWRoleInfo& info) +{ + std::string oid = string_cat_reserve(info.tenant, path_oid_prefix, + info.path, oid_prefix, info.id); + return {zone.roles_pool, std::move(oid)}; +} + +static int write_tenant_path(const DoutPrefixProvider* dpp, optional_yield y, + RGWSI_SysObj& sysobj, IndexObj& path) +{ + bufferlist bl; + return rgw_put_system_obj(dpp, &sysobj, path.obj.pool, path.obj.oid, bl, + true, &path.objv, ceph::real_time(), y); +} + +static int read_tenant_path(const DoutPrefixProvider* dpp, optional_yield y, + RGWSI_SysObj& sysobj, IndexObj& path) +{ + bufferlist bl; + return rgw_get_system_obj(&sysobj, path.obj.pool, path.obj.oid, + bl, &path.objv, nullptr, y, dpp); +} + +struct AccountIndex { + rgw_raw_obj obj; + std::string_view name; +}; + +static int remove_index(const DoutPrefixProvider* dpp, + optional_yield y, librados::Rados& rados, + const AccountIndex& index) +{ + return roles::remove(dpp, y, rados, index.obj, index.name); +} + +using PathIndex = std::variant; + +static int write_path(const DoutPrefixProvider* dpp, optional_yield y, + librados::Rados& rados, RGWSI_SysObj& sysobj, + const RGWZoneParams& zone, const RGWRoleInfo& info, + PathIndex& index) +{ + if (!info.account_id.empty()) { + // add the new role to its account + AccountIndex path; + path.obj = account::get_roles_obj(zone, info.account_id); + path.name = info.name; + + constexpr bool exclusive = true; + constexpr uint32_t no_limit = std::numeric_limits::max(); + int r = roles::add(dpp, y, rados, path.obj, info, exclusive, no_limit); + if (r < 0) { + ldpp_dout(dpp, 1) << "failed to add role to account " + << path.obj << " with: " << cpp_strerror(r) << dendl; + return r; + } + index = std::move(path); + } else { + // write the new path object + IndexObj path; + path.obj = get_tenant_path_obj(zone, info); + path.objv.generate_new_write_ver(dpp->get_cct()); + + int r = write_tenant_path(dpp, y, sysobj, path); + if (r < 0) { + ldpp_dout(dpp, 1) << "failed to write role path obj " + << path.obj << " with: " << cpp_strerror(r) << dendl; + return r; + } + index = std::move(path); + } + return 0; +} + +static int remove_index(const DoutPrefixProvider* dpp, + optional_yield y, librados::Rados& rados, + RGWSI_SysObj& sysobj, PathIndex& index) +{ + return std::visit(fu2::overload( + [&] (std::monostate&) { return 0; }, + [&] (IndexObj& path) { + return remove_index(dpp, y, sysobj, path); + }, + [&] (AccountIndex& path) { + return remove_index(dpp, y, rados, path); + }), index); +} + +int read_by_name(const DoutPrefixProvider* dpp, optional_yield y, + RGWSI_SysObj& sysobj, const RGWZoneParams& zone, + std::string_view tenant, const rgw_account_id& account, + std::string_view name, RGWRoleInfo& info, + ceph::real_time* pmtime, RGWObjVersionTracker* pobjv, + rgw_cache_entry_info* pcache_info) +{ + IndexObj n; + n.obj = get_name_obj(zone, tenant, account, name); + + RGWNameToId name_to_id; + int r = read_name(dpp, y, sysobj, n, name_to_id); + if (r < 0) { + return r; + } + + return read_by_id(dpp, y, sysobj, zone, name_to_id.obj_id, + info, pmtime, pobjv, pcache_info); +} + +int write(const DoutPrefixProvider* dpp, optional_yield y, + librados::Rados& rados, RGWSI_SysObj& sysobj, RGWSI_MDLog* mdlog, + const RGWZoneParams& zone, const RGWRoleInfo& info, + RGWObjVersionTracker& objv, ceph::real_time mtime, + bool exclusive) +{ + int r = 0; + + // read existing info in case we need to remove its name/path + RGWRoleInfo old; + RGWRoleInfo* old_info = nullptr; + if (!exclusive) { + r = read_by_id(dpp, y, sysobj, zone, info.id, old); + if (r == -ENOENT) { + } else if (r < 0) { + return r; + } else { + old_info = &old; + } + } + + const bool same_name = old_info && + old_info->tenant == info.tenant && + old_info->account_id == info.account_id && + old_info->name == info.name; + const bool same_path = old_info && + old_info->tenant == info.tenant && + old_info->account_id == info.account_id && + old_info->path == info.path; + + NameIndex remove_name; + PathIndex remove_path; + if (old_info) { + if (old_info->id != info.id) { + ldpp_dout(dpp, 1) << "ERROR: can't modify role id" << dendl; + return -EINVAL; + } + if (!same_name && !old_info->name.empty()) { + IndexObj name; + name.obj = get_name_obj(zone, *old_info); + RGWNameToId name_to_id; + r = read_name(dpp, y, sysobj, name, name_to_id); + if (r == -ENOENT) { + // leave remove_name empty + } else if (r < 0) { + return r; + } else if (name_to_id.obj_id == info.id) { + remove_name = std::move(name); + } + } + if (!same_path) { + if (!old_info->account_id.empty()) { + AccountIndex path; + path.obj = account::get_roles_obj(zone, old_info->account_id); + path.name = old_info->name; + remove_path = std::move(path); + } else { + // look up tenant path + IndexObj path; + path.obj = get_tenant_path_obj(zone, *old_info); + r = read_tenant_path(dpp, y, sysobj, path); + if (r == -ENOENT) { + // leave remove_path empty + } else if (r < 0) { + return r; + } else { + remove_path = std::move(path); + } + } + } + } // old_info + + // write the new name object, fail on conflict + NameIndex new_name; + if (!same_name && !info.name.empty()) { + IndexObj name; + name.obj = get_name_obj(zone, info); + name.objv.generate_new_write_ver(dpp->get_cct()); + + r = write_name(dpp, y, sysobj, info.id, name); + if (r < 0) { + ldpp_dout(dpp, 1) << "failed to write name obj " + << name.obj << " with: " << cpp_strerror(r) << dendl; + return r; + } + new_name = std::move(name); + } + + // check for path conflict + PathIndex new_path; + if (!same_path) { + r = write_path(dpp, y, rados, sysobj, zone, info, new_path); + if (r < 0) { + // roll back new name object + std::ignore = remove_index(dpp, y, sysobj, new_name); + return r; + } + } + + // write info by id + r = write_info(dpp, y, sysobj, zone, info, objv, mtime, exclusive); + if (r < 0) { + // roll back the new name/path indices + std::ignore = remove_index(dpp, y, sysobj, new_name); + std::ignore = remove_index(dpp, y, rados, sysobj, new_path); + return r; + } + + // remove the old name/path indices + std::ignore = remove_index(dpp, y, sysobj, remove_name); + std::ignore = remove_index(dpp, y, rados, sysobj, remove_path); + + // record in the mdlog on success + if (mdlog) { + return mdlog->complete_entry(dpp, y, "roles", info.id, &objv); + } + return 0; +} + +static int remove_by_id(const DoutPrefixProvider* dpp, optional_yield y, + librados::Rados& rados, RGWSI_SysObj& sysobj, + RGWSI_MDLog* mdlog, const RGWZoneParams& zone, + std::string_view role_id) +{ + const rgw_raw_obj& obj = get_id_obj(zone, role_id); + + RGWRoleInfo info; + int r = read_info(dpp, y, sysobj, obj, info, + nullptr, &info.objv_tracker, nullptr); + if (r < 0) { + return r; + } + + // delete role info + r = rgw_delete_system_obj(dpp, &sysobj, obj.pool, obj.oid, + &info.objv_tracker, y); + if (r < 0) { + ldpp_dout(dpp, 1) << "ERROR: failed to remove role " + << info.id << " with: " << cpp_strerror(r) << dendl; + return r; + } + + // delete the name object + if (!info.name.empty()) { + IndexObj name; + name.obj = get_name_obj(zone, info); + std::ignore = remove_index(dpp, y, sysobj, name); + } + + // delete the path object + if (!info.account_id.empty()) { + AccountIndex path; + path.obj = account::get_roles_obj(zone, info.account_id); + path.name = info.name; + std::ignore = remove_index(dpp, y, rados, path); + } else { + IndexObj path; + path.obj = get_tenant_path_obj(zone, info); + std::ignore = remove_index(dpp, y, sysobj, path); + } + + // record in the mdlog on success + if (mdlog) { + return mdlog->complete_entry(dpp, y, "roles", info.id, &info.objv_tracker); + } + return 0; +} + +int remove(const DoutPrefixProvider* dpp, optional_yield y, + librados::Rados& rados, RGWSI_SysObj& sysobj, RGWSI_MDLog* mdlog, + const RGWZoneParams& zone, std::string_view tenant, + const rgw_account_id& account, std::string_view name) +{ + IndexObj n; + n.obj = get_name_obj(zone, tenant, account, name); + RGWNameToId name_to_id; + + int r = read_name(dpp, y, sysobj, n, name_to_id); + if (r < 0) { + return r; + } + + return remove_by_id(dpp, y, rados, sysobj, mdlog, zone, name_to_id.obj_id); +} + + +int list_tenant(const DoutPrefixProvider* dpp, optional_yield y, + RGWSI_SysObj& sysobj, const RGWZoneParams& zone, + std::string_view tenant, const std::string& marker, + int max_items, std::string_view path_prefix, + std::vector& roles, std::string& next_marker) +{ + // List all roles if path prefix is empty + std::string prefix; + if (!path_prefix.empty()) { + prefix = string_cat_reserve(tenant, path_oid_prefix, path_prefix); + } else { + prefix = string_cat_reserve(tenant, path_oid_prefix, "/"); + } + + auto pool = sysobj.get_pool(zone.roles_pool); + auto listing = pool.op(); + int r = listing.init(dpp, marker, prefix); + if (r < 0) { + return r; + } + + std::vector oids; + bool truncated = false; + r = listing.get_next(dpp, max_items, &oids, &truncated); + if (r < 0) { + return r; + } + + for (auto& oid : oids) { + // remove the entire prefix + oid.erase(0, prefix.size()); + // verify that the entire oid_prefix is still present (path_prefix may have + // matched part of it) + size_t pos = oid.rfind(oid_prefix); + if (pos == std::string::npos) { + continue; + } + // after trimming the oid_prefix, we should be left with just the role id + oid.erase(0, pos + oid_prefix.size()); + + RGWRoleInfo info; + r = read_by_id(dpp, y, sysobj, zone, oid, info, nullptr, nullptr, nullptr); + if (r == -ENOENT) { + continue; // ok, listing race with deletion + } + if (r < 0) { + return r; + } + roles.push_back(std::move(info)); + } + + if (truncated) { + listing.get_marker(&next_marker); + } + return 0; +} + + +class MetadataObject : public RGWMetadataObject { + RGWRoleInfo info; +public: + MetadataObject(const RGWRoleInfo& info, const obj_version& v, real_time m) + : RGWMetadataObject(v, m), info(info) {} + + void dump(Formatter *f) const override { + info.dump(f); + } + + RGWRoleInfo& get_role_info() { + return info; + } +}; + +class MetadataLister : public RGWMetadataLister { + public: + using RGWMetadataLister::RGWMetadataLister; + + virtual void filter_transform(std::vector& oids, + std::list& keys) { + // remove the oid prefix from keys + constexpr auto trim = [] (const std::string& oid) { + return oid.substr(oid_prefix.size()); + }; + std::transform(oids.begin(), oids.end(), + std::back_inserter(keys), + trim); + } +}; + +class MetadataHandler : public RGWMetadataHandler { + librados::Rados& rados; + RGWSI_SysObj& sysobj; + RGWSI_MDLog& mdlog; + const RGWZoneParams& zone; + public: + MetadataHandler(librados::Rados& rados, RGWSI_SysObj& sysobj, + RGWSI_MDLog& mdlog, const RGWZoneParams& zone) + : rados(rados), sysobj(sysobj), mdlog(mdlog), zone(zone) {} + + std::string get_type() final { return "roles"; } + + RGWMetadataObject* get_meta_obj(JSONObj *jo, + const obj_version& objv, + const ceph::real_time& mtime) override + { + RGWRoleInfo info; + + try { + info.decode_json(jo); + } catch (JSONDecoder:: err& e) { + return nullptr; + } + + return new MetadataObject(info, objv, mtime); + } + + int get(std::string& entry, RGWMetadataObject** obj, + optional_yield y, const DoutPrefixProvider* dpp) override + { + RGWRoleInfo info; + int ret = read_by_id(dpp, y, sysobj, zone, entry, info, + &info.mtime, &info.objv_tracker); + if (ret < 0) { + return ret; + } + + *obj = new MetadataObject(info, info.objv_tracker.read_version, info.mtime); + return 0; + } + + int put(std::string& entry, RGWMetadataObject* obj, + RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider* dpp, + RGWMDLogSyncType type, bool from_remote_zone) override + { + auto robj = static_cast(obj); + auto& info = robj->get_role_info(); + info.mtime = robj->get_mtime(); + + constexpr bool exclusive = false; + int ret = write(dpp, y, rados, sysobj, &mdlog, zone, info, + info.objv_tracker, info.mtime, exclusive); + return ret < 0 ? ret : STATUS_APPLIED; + } + + int remove(std::string& entry, RGWObjVersionTracker& objv_tracker, + optional_yield y, const DoutPrefixProvider *dpp) override + { + return remove_by_id(dpp, y, rados, sysobj, &mdlog, zone, entry); + } + + int mutate(const std::string& entry, const ceph::real_time& mtime, + RGWObjVersionTracker* objv_tracker, optional_yield y, + const DoutPrefixProvider* dpp, RGWMDLogStatus op_type, + std::function f) override + { + return -ENOTSUP; // unused + } + + int list_keys_init(const DoutPrefixProvider* dpp, + const std::string& marker, + void** phandle) override + { + const auto& pool = zone.roles_pool; + auto lister = std::make_unique(sysobj.get_pool(pool)); + int ret = lister->init(dpp, marker, oid_prefix); + if (ret < 0) { + return ret; + } + *phandle = lister.release(); // release ownership + return 0; + } + + int list_keys_next(const DoutPrefixProvider* dpp, + void* handle, int max, + std::list& keys, + bool* truncated) override + { + auto lister = static_cast(handle); + return lister->get_next(dpp, max, keys, truncated); + } + + void list_keys_complete(void *handle) override + { + delete static_cast(handle); + } + + std::string get_marker(void *handle) override + { + auto lister = static_cast(handle); + return lister->get_marker(); + } +}; + + +auto create_metadata_handler(librados::Rados& rados, + RGWSI_SysObj& sysobj, + RGWSI_MDLog& mdlog, + const RGWZoneParams& zone) + -> std::unique_ptr +{ + return std::make_unique(rados, sysobj, mdlog, zone); +} + +} // rgwrados::role diff --git a/src/rgw/driver/rados/role.h b/src/rgw/driver/rados/role.h new file mode 100644 index 0000000000000..7dc721c712123 --- /dev/null +++ b/src/rgw/driver/rados/role.h @@ -0,0 +1,81 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab ft=cpp + +/* + * Ceph - scalable distributed file system + * + * Copyright contributors to the Ceph project + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#pragma once + +#include +#include +#include +#include "include/rados/librados_fwd.hpp" +#include "common/ceph_time.h" + +class DoutPrefixProvider; +class optional_yield; +struct rgw_account_id; +struct rgw_cache_entry_info; +class RGWMetadataHandler; +class RGWObjVersionTracker; +struct RGWRoleInfo; +class RGWSI_MDLog; +class RGWSI_SysObj; +class RGWZoneParams; + +namespace rgwrados::role { + +/// Read role info by id. +int read_by_id(const DoutPrefixProvider* dpp, optional_yield y, + RGWSI_SysObj& sysobj, const RGWZoneParams& zone, + std::string_view role_id, RGWRoleInfo& info, + ceph::real_time* pmtime = nullptr, + RGWObjVersionTracker* pobjv = nullptr, + rgw_cache_entry_info* pcache_info = nullptr); + +/// Read role info by name. +int read_by_name(const DoutPrefixProvider* dpp, optional_yield y, + RGWSI_SysObj& sysobj, const RGWZoneParams& zone, + std::string_view tenant, const rgw_account_id& account, + std::string_view name, RGWRoleInfo& info, + ceph::real_time* pmtime = nullptr, + RGWObjVersionTracker* pobjv = nullptr, + rgw_cache_entry_info* pcache_info = nullptr); + +/// Write or overwrite role info and update its name/path objects. +int write(const DoutPrefixProvider* dpp, optional_yield y, + librados::Rados& rados, RGWSI_SysObj& sysobj, RGWSI_MDLog* mdlog, + const RGWZoneParams& zone, const RGWRoleInfo& info, + RGWObjVersionTracker& objv, ceph::real_time mtime, + bool exclusive); + +/// Remove a role by name, including its name/path objects. +int remove(const DoutPrefixProvider* dpp, optional_yield y, + librados::Rados& rados, RGWSI_SysObj& sysobj, RGWSI_MDLog* mdlog, + const RGWZoneParams& zone, std::string_view tenant, + const rgw_account_id& account, std::string_view name); + +/// Return a paginated listing of roles for the given tenant. +int list_tenant(const DoutPrefixProvider* dpp, optional_yield y, + RGWSI_SysObj& sysobj, const RGWZoneParams& zone, + std::string_view tenant, const std::string& marker, + int max_items, std::string_view path_prefix, + std::vector& roles, std::string& next_marker); + +/// Role metadata handler factory. +auto create_metadata_handler(librados::Rados& rados, + RGWSI_SysObj& sysobj, + RGWSI_MDLog& mdlog, + const RGWZoneParams& zone) + -> std::unique_ptr; + +} // rgwrados::role diff --git a/src/rgw/driver/rados/roles.cc b/src/rgw/driver/rados/roles.cc index 62a0aef8aad5f..8503ece576cd2 100644 --- a/src/rgw/driver/rados/roles.cc +++ b/src/rgw/driver/rados/roles.cc @@ -28,7 +28,7 @@ int add(const DoutPrefixProvider* dpp, optional_yield y, librados::Rados& rados, const rgw_raw_obj& obj, - const rgw::sal::RGWRoleInfo& role, + const RGWRoleInfo& role, bool exclusive, uint32_t limit) { resource_metadata meta; diff --git a/src/rgw/driver/rados/roles.h b/src/rgw/driver/rados/roles.h index eb53820039edd..0aeb9ecc75d5e 100644 --- a/src/rgw/driver/rados/roles.h +++ b/src/rgw/driver/rados/roles.h @@ -25,6 +25,7 @@ namespace ceph { class Formatter; } class DoutPrefixProvider; class optional_yield; struct rgw_raw_obj; +struct RGWRoleInfo; namespace rgwrados::roles { @@ -34,7 +35,7 @@ int add(const DoutPrefixProvider* dpp, optional_yield y, librados::Rados& rados, const rgw_raw_obj& obj, - const rgw::sal::RGWRoleInfo& role, + const RGWRoleInfo& role, bool exclusive, uint32_t limit); /// Look up a role's id by name in the list. diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 966e912b05d55..d1b041f2423fe 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -73,7 +73,6 @@ extern "C" { #include "services/svc_cls.h" #include "services/svc_bilog_rados.h" #include "services/svc_mdlog.h" -#include "services/svc_meta_be_otp.h" #include "services/svc_user.h" #include "services/svc_zone.h" @@ -6856,7 +6855,7 @@ int main(int argc, const char **argv) } std::unique_ptr role = driver->get_role(role_name, tenant, account_id, path, assume_role_doc, description, max_session_duration); - ret = role->create(dpp(), true, "", null_yield); + ret = role->create(dpp(), "", null_yield); if (ret < 0) { return -ret; } @@ -6885,7 +6884,7 @@ int main(int argc, const char **argv) return -EINVAL; } std::unique_ptr role = driver->get_role(role_name, tenant, account_id); - ret = role->get(dpp(), null_yield); + ret = role->load_by_name(dpp(), null_yield); if (ret < 0) { return -ret; } @@ -6915,12 +6914,13 @@ int main(int argc, const char **argv) } std::unique_ptr role = driver->get_role(role_name, tenant, account_id); - ret = role->get(dpp(), null_yield); + ret = role->load_by_name(dpp(), null_yield); if (ret < 0) { return -ret; } role->update_trust_policy(assume_role_doc); - ret = role->update(dpp(), null_yield); + constexpr bool exclusive = false; + ret = role->store_info(dpp(), exclusive, null_yield); if (ret < 0) { return -ret; } @@ -7010,12 +7010,13 @@ int main(int argc, const char **argv) } std::unique_ptr role = driver->get_role(role_name, tenant, account_id); - ret = role->get(dpp(), null_yield); + ret = role->load_by_name(dpp(), null_yield); if (ret < 0) { return -ret; } role->set_perm_policy(policy_name, perm_policy_doc); - ret = role->update(dpp(), null_yield); + constexpr bool exclusive = false; + ret = role->store_info(dpp(), exclusive, null_yield); if (ret < 0) { return -ret; } @@ -7029,7 +7030,7 @@ int main(int argc, const char **argv) return -EINVAL; } std::unique_ptr role = driver->get_role(role_name, tenant, account_id); - ret = role->get(dpp(), null_yield); + ret = role->load_by_name(dpp(), null_yield); if (ret < 0) { return -ret; } @@ -7049,7 +7050,7 @@ int main(int argc, const char **argv) return -EINVAL; } std::unique_ptr role = driver->get_role(role_name, tenant, account_id); - int ret = role->get(dpp(), null_yield); + int ret = role->load_by_name(dpp(), null_yield); if (ret < 0) { return -ret; } @@ -7073,7 +7074,7 @@ int main(int argc, const char **argv) return -EINVAL; } std::unique_ptr role = driver->get_role(role_name, tenant, account_id); - ret = role->get(dpp(), null_yield); + ret = role->load_by_name(dpp(), null_yield); if (ret < 0) { return -ret; } @@ -7081,7 +7082,8 @@ int main(int argc, const char **argv) if (ret < 0) { return -ret; } - ret = role->update(dpp(), null_yield); + constexpr bool exclusive = false; + ret = role->store_info(dpp(), exclusive, null_yield); if (ret < 0) { return -ret; } @@ -7110,7 +7112,7 @@ int main(int argc, const char **argv) } std::unique_ptr role = driver->get_role(role_name, tenant, account_id); - ret = role->get(dpp(), null_yield); + ret = role->load_by_id(dpp(), null_yield); if (ret < 0) { return -ret; } @@ -7125,7 +7127,8 @@ int main(int argc, const char **argv) cout << "That managed policy is already attached." << std::endl; return EEXIST; } - ret = role->update(dpp(), null_yield); + constexpr bool exclusive = false; + ret = role->store_info(dpp(), exclusive, null_yield); if (ret < 0) { return -ret; } @@ -7144,7 +7147,7 @@ int main(int argc, const char **argv) } std::unique_ptr role = driver->get_role(role_name, tenant, account_id); - ret = role->get(dpp(), null_yield); + ret = role->load_by_id(dpp(), null_yield); if (ret < 0) { return -ret; } @@ -7157,7 +7160,8 @@ int main(int argc, const char **argv) } policies.arns.erase(i); - ret = role->update(dpp(), null_yield); + constexpr bool exclusive = false; + ret = role->store_info(dpp(), exclusive, null_yield); if (ret < 0) { return -ret; } @@ -7171,7 +7175,7 @@ int main(int argc, const char **argv) return EINVAL; } std::unique_ptr role = driver->get_role(role_name, tenant, account_id); - ret = role->get(dpp(), null_yield); + ret = role->load_by_id(dpp(), null_yield); if (ret < 0) { return -ret; } @@ -7187,7 +7191,7 @@ int main(int argc, const char **argv) } std::unique_ptr role = driver->get_role(role_name, tenant, account_id); - ret = role->get(dpp(), null_yield); + ret = role->load_by_name(dpp(), null_yield); if (ret < 0) { return -ret; } @@ -7196,7 +7200,8 @@ int main(int argc, const char **argv) ret = -EINVAL; return ret; } - ret = role->update(dpp(), null_yield); + constexpr bool exclusive = false; + ret = role->store_info(dpp(), exclusive, null_yield); if (ret < 0) { return -ret; } @@ -10827,13 +10832,13 @@ int main(int argc, const char **argv) } real_time mtime = real_clock::now(); - string oid = static_cast(driver)->svc()->cls->mfa.get_mfa_oid(user->get_id()); - int ret = static_cast(driver)->ctl()->meta.mgr->mutate(RGWSI_MetaBackend_OTP::get_meta_key(user->get_id()), - mtime, &objv_tracker, - null_yield, dpp(), - MDLOG_STATUS_WRITE, - [&] { + int ret = static_cast(driver)->ctl()->meta.mgr->mutate( + rgwrados::otp::get_meta_key(user->get_id()), + mtime, &objv_tracker, + null_yield, dpp(), + MDLOG_STATUS_WRITE, + [&] { return static_cast(driver)->svc()->cls->mfa.create_mfa(dpp(), user->get_id(), config, &objv_tracker, mtime, null_yield); }); if (ret < 0) { @@ -10865,11 +10870,12 @@ int main(int argc, const char **argv) real_time mtime = real_clock::now(); - int ret = static_cast(driver)->ctl()->meta.mgr->mutate(RGWSI_MetaBackend_OTP::get_meta_key(user->get_id()), - mtime, &objv_tracker, - null_yield, dpp(), - MDLOG_STATUS_WRITE, - [&] { + int ret = static_cast(driver)->ctl()->meta.mgr->mutate( + rgwrados::otp::get_meta_key(user->get_id()), + mtime, &objv_tracker, + null_yield, dpp(), + MDLOG_STATUS_WRITE, + [&] { return static_cast(driver)->svc()->cls->mfa.remove_mfa(dpp(), user->get_id(), totp_serial, &objv_tracker, mtime, null_yield); }); if (ret < 0) { @@ -11012,11 +11018,12 @@ int main(int argc, const char **argv) /* now update the backend */ real_time mtime = real_clock::now(); - ret = static_cast(driver)->ctl()->meta.mgr->mutate(RGWSI_MetaBackend_OTP::get_meta_key(user->get_id()), - mtime, &objv_tracker, - null_yield, dpp(), - MDLOG_STATUS_WRITE, - [&] { + ret = static_cast(driver)->ctl()->meta.mgr->mutate( + rgwrados::otp::get_meta_key(user->get_id()), + mtime, &objv_tracker, + null_yield, dpp(), + MDLOG_STATUS_WRITE, + [&] { return static_cast(driver)->svc()->cls->mfa.create_mfa(dpp(), user->get_id(), config, &objv_tracker, mtime, null_yield); }); if (ret < 0) { diff --git a/src/rgw/rgw_mdlog.h b/src/rgw/rgw_mdlog.h index 6c78fd3840858..4817dded9dbec 100644 --- a/src/rgw/rgw_mdlog.h +++ b/src/rgw/rgw_mdlog.h @@ -26,6 +26,9 @@ #define META_LOG_OBJ_PREFIX "meta.log." +class RGWSI_Cls; +class RGWSI_Zone; + struct RGWMetadataLogInfo { std::string marker; real_time last_update; diff --git a/src/rgw/rgw_metadata.cc b/src/rgw/rgw_metadata.cc index a6d75de0eba12..92b03e41bcdc1 100644 --- a/src/rgw/rgw_metadata.cc +++ b/src/rgw/rgw_metadata.cc @@ -5,10 +5,6 @@ #include "rgw_mdlog.h" - -#include "services/svc_meta.h" -#include "services/svc_meta_be_sobj.h" - #define dout_subsys ceph_subsys_rgw using namespace std; @@ -111,214 +107,16 @@ void RGWMetadataLogData::generate_test_instances(std::list l.back()->status = MDLOG_STATUS_WRITE; } -RGWMetadataHandler_GenericMetaBE::Put::Put(RGWMetadataHandler_GenericMetaBE *_handler, - RGWSI_MetaBackend_Handler::Op *_op, - string& _entry, RGWMetadataObject *_obj, - RGWObjVersionTracker& _objv_tracker, - optional_yield _y, - RGWMDLogSyncType _type, bool _from_remote_zone): - handler(_handler), op(_op), - entry(_entry), obj(_obj), - objv_tracker(_objv_tracker), - apply_type(_type), - y(_y), - from_remote_zone(_from_remote_zone) -{ -} - -int RGWMetadataHandler_GenericMetaBE::do_put_operate(Put *put_op, const DoutPrefixProvider *dpp) -{ - int r = put_op->put_pre(dpp); - if (r != 0) { /* r can also be STATUS_NO_APPLY */ - return r; - } - - r = put_op->put(dpp); - if (r != 0) { - return r; - } - - r = put_op->put_post(dpp); - if (r != 0) { /* e.g., -error or STATUS_APPLIED */ - return r; - } - - return 0; -} - -int RGWMetadataHandler_GenericMetaBE::get(string& entry, RGWMetadataObject **obj, optional_yield y, const DoutPrefixProvider *dpp) -{ - return be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) { - return do_get(op, entry, obj, y, dpp); - }); -} - -int RGWMetadataHandler_GenericMetaBE::put(string& entry, RGWMetadataObject *obj, RGWObjVersionTracker& objv_tracker, - optional_yield y, const DoutPrefixProvider *dpp, RGWMDLogSyncType type, bool from_remote_zone) -{ - return be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) { - return do_put(op, entry, obj, objv_tracker, y, dpp, type, from_remote_zone); - }); -} - -int RGWMetadataHandler_GenericMetaBE::remove(string& entry, RGWObjVersionTracker& objv_tracker, optional_yield y, const DoutPrefixProvider *dpp) -{ - return be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) { - return do_remove(op, entry, objv_tracker, y, dpp); - }); -} - -int RGWMetadataHandler_GenericMetaBE::mutate(const string& entry, - const ceph::real_time& mtime, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp, - RGWMDLogStatus op_type, - std::function f) -{ - return be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) { - RGWSI_MetaBackend::MutateParams params(mtime, op_type); - return op->mutate(entry, - params, - objv_tracker, - y, - f, - dpp); - }); -} - -int RGWMetadataHandler_GenericMetaBE::get_shard_id(const string& entry, int *shard_id) -{ - return be_handler->call([&](RGWSI_MetaBackend_Handler::Op *op) { - return op->get_shard_id(entry, shard_id); - }); -} - -int RGWMetadataHandler_GenericMetaBE::list_keys_init(const DoutPrefixProvider *dpp, const string& marker, void **phandle) -{ - auto op = std::make_unique(be_handler); - - int ret = op->list_init(dpp, marker); - if (ret < 0) { - return ret; - } - - *phandle = (void *)op.release(); - - return 0; -} - -int RGWMetadataHandler_GenericMetaBE::list_keys_next(const DoutPrefixProvider *dpp, void *handle, int max, list& keys, bool *truncated) -{ - auto op = static_cast(handle); - - int ret = op->list_next(dpp, max, &keys, truncated); - if (ret < 0 && ret != -ENOENT) { - return ret; - } - if (ret == -ENOENT) { - if (truncated) { - *truncated = false; - } - return 0; - } - - return 0; -} - -void RGWMetadataHandler_GenericMetaBE::list_keys_complete(void *handle) -{ - auto op = static_cast(handle); - delete op; -} - -string RGWMetadataHandler_GenericMetaBE::get_marker(void *handle) -{ - auto op = static_cast(handle); - string marker; - int r = op->list_get_marker(&marker); - if (r < 0) { - ldout(cct, 0) << "ERROR: " << __func__ << "(): list_get_marker() returned: r=" << r << dendl; - /* not much else to do */ - } - - return marker; -} - -RGWMetadataHandlerPut_SObj::RGWMetadataHandlerPut_SObj(RGWMetadataHandler_GenericMetaBE *handler, - RGWSI_MetaBackend_Handler::Op *op, - string& entry, RGWMetadataObject *obj, RGWObjVersionTracker& objv_tracker, - optional_yield y, - RGWMDLogSyncType type, bool from_remote_zone) : Put(handler, op, entry, obj, objv_tracker, y, type, from_remote_zone) { -} - -int RGWMetadataHandlerPut_SObj::put_pre(const DoutPrefixProvider *dpp) -{ - int ret = get(&old_obj, dpp); - if (ret < 0 && ret != -ENOENT) { - return ret; - } - exists = (ret != -ENOENT); - - oo.reset(old_obj); - - auto old_ver = (!old_obj ? obj_version() : old_obj->get_version()); - auto old_mtime = (!old_obj ? ceph::real_time() : old_obj->get_mtime()); - - // are we actually going to perform this put, or is it too old? - if (!handler->check_versions(exists, old_ver, old_mtime, - objv_tracker.write_version, obj->get_mtime(), - apply_type)) { - return STATUS_NO_APPLY; - } - - objv_tracker.read_version = old_ver; /* maintain the obj version we just read */ - - return 0; -} - -int RGWMetadataHandlerPut_SObj::put(const DoutPrefixProvider *dpp) -{ - int ret = put_check(dpp); - if (ret != 0) { - return ret; - } - - return put_checked(dpp); -} - -int RGWMetadataHandlerPut_SObj::put_checked(const DoutPrefixProvider *dpp) -{ - RGWSI_MBSObj_PutParams params(obj->get_pattrs(), obj->get_mtime()); - - encode_obj(¶ms.bl); - - int ret = op->put(entry, params, &objv_tracker, y, dpp); - if (ret < 0) { - return ret; - } - - return 0; -} - class RGWMetadataTopHandler : public RGWMetadataHandler { struct iter_data { set sections; set::iterator iter; }; - struct Svc { - RGWSI_Meta *meta{nullptr}; - } svc; - RGWMetadataManager *mgr; public: - RGWMetadataTopHandler(RGWSI_Meta *meta_svc, - RGWMetadataManager *_mgr) : mgr(_mgr) { - base_init(meta_svc->ctx()); - svc.meta = meta_svc; - } + explicit RGWMetadataTopHandler(RGWMetadataManager *_mgr) : mgr(_mgr) {} string get_type() override { return string(); } @@ -389,8 +187,6 @@ class RGWMetadataTopHandler : public RGWMetadataHandler { } }; -RGWMetadataHandlerPut_SObj::~RGWMetadataHandlerPut_SObj() {} - int RGWMetadataHandler::attach(RGWMetadataManager *manager) { return manager->register_handler(this); @@ -403,10 +199,9 @@ obj_version& RGWMetadataObject::get_version() return objv; } -RGWMetadataManager::RGWMetadataManager(RGWSI_Meta *_meta_svc) - : cct(_meta_svc->ctx()), meta_svc(_meta_svc) +RGWMetadataManager::RGWMetadataManager() { - md_top_handler.reset(new RGWMetadataTopHandler(meta_svc, this)); + md_top_handler.reset(new RGWMetadataTopHandler(this)); } RGWMetadataManager::~RGWMetadataManager() @@ -679,7 +474,6 @@ void RGWMetadataManager::dump_log_entry(cls_log_entry& entry, Formatter *f) encode_json("data", log_data, f); } catch (buffer::error& err) { - lderr(cct) << "failed to decode log entry: " << entry.section << ":" << entry.name<< " ts=" << entry.timestamp << dendl; } f->close_section(); } diff --git a/src/rgw/rgw_quota.cc b/src/rgw/rgw_quota.cc index f55064ff53ffc..063557c8e7e49 100644 --- a/src/rgw/rgw_quota.cc +++ b/src/rgw/rgw_quota.cc @@ -29,7 +29,6 @@ #include "rgw_user.h" #include "services/svc_sys_obj.h" -#include "services/svc_meta.h" #include diff --git a/src/rgw/rgw_rest_iam.h b/src/rgw/rgw_rest_iam.h index 00f6ff7dfc4aa..5a4a8329b2b5d 100644 --- a/src/rgw/rgw_rest_iam.h +++ b/src/rgw/rgw_rest_iam.h @@ -83,7 +83,7 @@ int retry_raced_role_write(const DoutPrefixProvider* dpp, optional_yield y, int r = f(); for (int i = 0; i < 10 && r == -ECANCELED; ++i) { role->get_objv_tracker().clear(); - r = role->get_by_id(dpp, y); + r = role->load_by_id(dpp, y); if (r >= 0) { r = f(); } diff --git a/src/rgw/rgw_rest_role.cc b/src/rgw/rgw_rest_role.cc index b824939582de5..a3733c175cc3c 100644 --- a/src/rgw/rgw_rest_role.cc +++ b/src/rgw/rgw_rest_role.cc @@ -40,7 +40,7 @@ int RGWRestRole::check_caps(const RGWUserCaps& caps) return caps.check_cap("roles", perm); } -static void dump_iam_role(const rgw::sal::RGWRoleInfo& role, Formatter *f) +static void dump_iam_role(const RGWRoleInfo& role, Formatter *f) { encode_json("RoleId", role.id, f); encode_json("RoleName", role.name, f); @@ -114,7 +114,7 @@ static int load_role(const DoutPrefixProvider* dpp, optional_yield y, rgw::ARN& resource, std::string& message) { role = driver->get_role(name, tenant, account_id); - const int r = role->get(dpp, y); + const int r = role->load_by_name(dpp, y); if (r == -ENOENT) { message = "No such RoleName in the tenant"; return -ERR_NO_ROLE_FOUND; @@ -312,7 +312,7 @@ void RGWCreateRole::execute(optional_yield y) ldpp_dout(this, 0) << "role_id decoded from master zonegroup response is " << role_id << dendl; } - op_ret = role->create(s, true, role_id, y); + op_ret = role->create(s, role_id, y); if (op_ret == -EEXIST) { if (site.is_meta_master()) { op_ret = -ERR_ROLE_EXISTS; @@ -489,7 +489,8 @@ void RGWModifyRoleTrustPolicy::execute(optional_yield y) op_ret = retry_raced_role_write(this, y, role.get(), [this, y] { role->update_trust_policy(trust_policy); - return role->update(this, y); + constexpr bool exclusive = false; + return role->store_info(this, exclusive, y); }); s->formatter->open_object_section("UpdateAssumeRolePolicyResponse"); @@ -582,7 +583,7 @@ int RGWPutRolePolicy::init_processing(optional_yield y) try { // non-account identity policy is restricted to the current tenant - const rgw::sal::RGWRoleInfo& info = role->get_info(); + const RGWRoleInfo& info = role->get_info(); const std::string* policy_tenant = account_id.empty() ? &info.tenant : nullptr; const rgw::IAM::Policy p( s->cct, policy_tenant, perm_policy, @@ -625,7 +626,8 @@ void RGWPutRolePolicy::execute(optional_yield y) op_ret = retry_raced_role_write(this, y, role.get(), [this, y] { role->set_perm_policy(policy_name, perm_policy); - return role->update(this, y); + constexpr bool exclusive = false; + return role->store_info(this, exclusive, y); }); if (op_ret == 0) { @@ -766,7 +768,8 @@ void RGWDeleteRolePolicy::execute(optional_yield y) return -ERR_NO_SUCH_ENTITY; } if (r == 0) { - r = role->update(this, y); + constexpr bool exclusive = false; + r = role->store_info(this, exclusive, y); } return r; }); @@ -833,7 +836,8 @@ void RGWTagRole::execute(optional_yield y) [this, y] { int r = role->set_tags(this, tags); if (r == 0) { - r = role->update(this, y); + constexpr bool exclusive = false; + r = role->store_info(this, exclusive, y); } return r; }); @@ -940,7 +944,8 @@ void RGWUntagRole::execute(optional_yield y) op_ret = retry_raced_role_write(this, y, role.get(), [this, y] { role->erase_tags(untag); - return role->update(this, y); + constexpr bool exclusive = false; + return role->store_info(this, exclusive, y); }); if (op_ret == 0) { @@ -1009,15 +1014,18 @@ void RGWUpdateRole::execute(optional_yield y) return -EINVAL; } - return role->update(this, y); + constexpr bool exclusive = false; + return role->store_info(this, exclusive, y); }); - s->formatter->open_object_section("UpdateRoleResponse"); - s->formatter->open_object_section("UpdateRoleResult"); - s->formatter->open_object_section("ResponseMetadata"); - s->formatter->dump_string("RequestId", s->trans_id); - s->formatter->close_section(); - s->formatter->close_section(); + if (op_ret == 0) { + s->formatter->open_object_section("UpdateRoleResponse"); + s->formatter->open_object_section("UpdateRoleResult"); + s->formatter->open_object_section("ResponseMetadata"); + s->formatter->dump_string("RequestId", s->trans_id); + s->formatter->close_section(); + s->formatter->close_section(); + } } static bool validate_policy_arn(const std::string& arn, std::string& err) @@ -1127,7 +1135,8 @@ void RGWAttachRolePolicy_IAM::execute(optional_yield y) if (!policies.arns.insert(policy_arn).second) { return 0; } - return role->update(this, y); + constexpr bool exclusive = false; + return role->store_info(this, exclusive, y); }); if (op_ret == 0) { @@ -1217,7 +1226,9 @@ void RGWDetachRolePolicy_IAM::execute(optional_yield y) return -ERR_NO_SUCH_ENTITY; } policies.arns.erase(p); - return role->update(this, y); + + constexpr bool exclusive = false; + return role->store_info(this, exclusive, y); }); if (op_ret == 0) { diff --git a/src/rgw/rgw_rest_role.h b/src/rgw/rgw_rest_role.h index b7c662c02c66f..97f9deafeb626 100644 --- a/src/rgw/rgw_rest_role.h +++ b/src/rgw/rgw_rest_role.h @@ -85,7 +85,6 @@ class RGWListRoles : public RGWRestRole { std::string path_prefix; std::string marker; int max_items = 100; - std::string next_marker; public: RGWListRoles() : RGWRestRole(rgw::IAM::iamListRoles, RGW_CAP_READ) {} int init_processing(optional_yield y) override; diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 8da355dd8162c..4a50baf1cb201 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -6537,7 +6537,7 @@ rgw::auth::s3::STSEngine::authenticate( rgw::auth::RoleApplier::TokenAttrs t_attrs; if (! token.roleId.empty()) { std::unique_ptr role = driver->get_role(token.roleId); - if (role->get_by_id(dpp, y) < 0) { + if (role->load_by_id(dpp, y) < 0) { return result_t::deny(-EPERM); } r.id = token.roleId; diff --git a/src/rgw/rgw_rest_sts.cc b/src/rgw/rgw_rest_sts.cc index dbe4994cfa528..f2bd9429a5538 100644 --- a/src/rgw/rgw_rest_sts.cc +++ b/src/rgw/rgw_rest_sts.cc @@ -496,7 +496,7 @@ WebTokenEngine::authenticate( const DoutPrefixProvider* dpp, } std::unique_ptr role = driver->get_role(role_name, role_tenant, role_account); - int ret = role->get(dpp, y); + int ret = role->load_by_name(dpp, y); if (ret < 0) { ldpp_dout(dpp, 0) << "Role not found: name:" << role_name << " tenant: " << role_tenant << dendl; return result_t::deny(-EACCES); diff --git a/src/rgw/rgw_role.cc b/src/rgw/rgw_role.cc index bf9fb5d96f214..9a93a10f8c4ba 100644 --- a/src/rgw/rgw_role.cc +++ b/src/rgw/rgw_role.cc @@ -17,26 +17,18 @@ #include "rgw_string.h" #include "rgw_common.h" +#include "rgw_metadata.h" +#include "rgw_metadata_lister.h" #include "rgw_tools.h" #include "rgw_role.h" #include "services/svc_zone.h" #include "services/svc_sys_obj.h" -#include "services/svc_meta_be_sobj.h" -#include "services/svc_meta.h" -#include "services/svc_role_rados.h" #define dout_subsys ceph_subsys_rgw using namespace std; -namespace rgw { namespace sal { - -const string RGWRole::role_name_oid_prefix = "role_names."; -const string RGWRole::role_oid_prefix = "roles."; -const string RGWRole::role_path_oid_prefix = "role_paths."; -const string RGWRole::role_arn_prefix = "arn:aws:iam::"; - void RGWRoleInfo::dump(Formatter *f) const { encode_json("RoleId", id , f); @@ -134,6 +126,10 @@ void RGWRoleInfo::decode_json(JSONObj *obj) } } +namespace rgw::sal { + +const string RGWRole::role_arn_prefix = "arn:aws:iam::"; + RGWRole::RGWRole(std::string name, std::string tenant, rgw_account_id account_id, @@ -166,31 +162,6 @@ RGWRole::RGWRole(std::string id) info.id = std::move(id); } -int RGWRole::get(const DoutPrefixProvider *dpp, optional_yield y) -{ - int ret = read_name(dpp, y); - if (ret < 0) { - return ret; - } - - ret = read_info(dpp, y); - if (ret < 0) { - return ret; - } - - return 0; -} - -int RGWRole::get_by_id(const DoutPrefixProvider *dpp, optional_yield y) -{ - int ret = read_info(dpp, y); - if (ret < 0) { - return ret; - } - - return 0; -} - bool RGWRole::validate_max_session_duration(const DoutPrefixProvider* dpp) { if (info.max_session_duration < SESSION_DURATION_MIN || @@ -239,16 +210,46 @@ void RGWRole::extract_name_tenant(const std::string& str) { } } -int RGWRole::update(const DoutPrefixProvider *dpp, optional_yield y) +int RGWRole::create(const DoutPrefixProvider *dpp, const std::string& role_id, optional_yield y) { - int ret = store_info(dpp, false, y); - if (ret < 0) { - ldpp_dout(dpp, 0) << "ERROR: storing info in Role pool: " - << info.id << ": " << cpp_strerror(-ret) << dendl; - return ret; + if (! validate_input(dpp)) { + return -EINVAL; } - return 0; + if (!role_id.empty()) { + info.id = role_id; + } + + if (info.id.empty()) { + /* create unique id */ + uuid_d new_uuid; + char uuid_str[37]; + new_uuid.generate_random(); + new_uuid.print(uuid_str); + info.id = uuid_str; + } + + //arn + std::string_view account = !info.account_id.empty() ? info.account_id : info.tenant; + info.arn = string_cat_reserve(role_arn_prefix, account, ":role", info.path, info.name); + + if (info.creation_date.empty()) { + // Creation time + real_clock::time_point t = real_clock::now(); + + struct timeval tv; + real_clock::to_timeval(t, tv); + + char buf[30]; + struct tm result; + gmtime_r(&tv.tv_sec, &result); + strftime(buf,30,"%Y-%m-%dT%H:%M:%S", &result); + sprintf(buf + strlen(buf),".%03dZ",(int)tv.tv_usec/1000); + info.creation_date.assign(buf, strlen(buf)); + } + + constexpr bool exclusive = true; + return store_info(dpp, exclusive, y); } void RGWRole::set_perm_policy(const string& policy_name, const string& perm_policy) @@ -332,126 +333,4 @@ void RGWRole::update_max_session_duration(const std::string& max_session_duratio } } -const string& RGWRole::get_names_oid_prefix() -{ - return role_name_oid_prefix; -} - -const string& RGWRole::get_info_oid_prefix() -{ - return role_oid_prefix; -} - -const string& RGWRole::get_path_oid_prefix() -{ - return role_path_oid_prefix; -} - -RGWRoleMetadataHandler::RGWRoleMetadataHandler(Driver* driver, - RGWSI_Role_RADOS *role_svc) -{ - this->driver = driver; - base_init(role_svc->ctx(), role_svc->get_be_handler()); -} - -RGWMetadataObject *RGWRoleMetadataHandler::get_meta_obj(JSONObj *jo, - const obj_version& objv, - const ceph::real_time& mtime) -{ - RGWRoleInfo info; - - try { - info.decode_json(jo); - } catch (JSONDecoder:: err& e) { - return nullptr; - } - - return new RGWRoleMetadataObject(info, objv, mtime, driver); -} - -int RGWRoleMetadataHandler::do_get(RGWSI_MetaBackend_Handler::Op *op, - std::string& entry, - RGWMetadataObject **obj, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - std::unique_ptr role = driver->get_role(entry); - int ret = role->read_info(dpp, y); - if (ret < 0) { - return ret; - } - - RGWObjVersionTracker objv_tracker = role->get_objv_tracker(); - real_time mtime = role->get_mtime(); - - RGWRoleInfo info = role->get_info(); - RGWRoleMetadataObject *rdo = new RGWRoleMetadataObject(info, objv_tracker.read_version, - mtime, driver); - *obj = rdo; - - return 0; -} - -int RGWRoleMetadataHandler::do_remove(RGWSI_MetaBackend_Handler::Op *op, - std::string& entry, - RGWObjVersionTracker& objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - std::unique_ptr role = driver->get_role(entry); - int ret = role->read_info(dpp, y); - if (ret < 0) { - return ret == -ENOENT? 0 : ret; - } - - return role->delete_obj(dpp, y); -} - -class RGWMetadataHandlerPut_Role : public RGWMetadataHandlerPut_SObj -{ - RGWRoleMetadataHandler *rhandler; - RGWRoleMetadataObject *mdo; -public: - RGWMetadataHandlerPut_Role(RGWRoleMetadataHandler *handler, - RGWSI_MetaBackend_Handler::Op *op, - std::string& entry, - RGWMetadataObject *obj, - RGWObjVersionTracker& objv_tracker, - optional_yield y, - RGWMDLogSyncType type, - bool from_remote_zone) : - RGWMetadataHandlerPut_SObj(handler, op, entry, obj, objv_tracker, y, type, from_remote_zone), - rhandler(handler) { - mdo = static_cast(obj); - } - - int put_checked(const DoutPrefixProvider *dpp) override { - auto& info = mdo->get_role_info(); - auto mtime = mdo->get_mtime(); - auto* driver = mdo->get_driver(); - info.mtime = mtime; - std::unique_ptr role = driver->get_role(info); - constexpr bool exclusive = false; - int ret = role->create(dpp, exclusive, info.id, y); - if (ret == -EEXIST) { - ret = role->update(dpp, y); - } - - return ret < 0 ? ret : STATUS_APPLIED; - } -}; - -int RGWRoleMetadataHandler::do_put(RGWSI_MetaBackend_Handler::Op *op, - std::string& entry, - RGWMetadataObject *obj, - RGWObjVersionTracker& objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp, - RGWMDLogSyncType type, - bool from_remote_zone) -{ - RGWMetadataHandlerPut_Role put_op(this, op , entry, obj, objv_tracker, y, type, from_remote_zone); - return do_put_operate(&put_op, dpp); -} - -} } // namespace rgw::sal +} // namespace rgw::sal diff --git a/src/rgw/rgw_role.h b/src/rgw/rgw_role.h index 585f723973573..081259ceaa4db 100644 --- a/src/rgw/rgw_role.h +++ b/src/rgw/rgw_role.h @@ -3,20 +3,18 @@ #pragma once +#include #include +#include "include/encoding.h" #include "common/async/yield_context.h" - -#include "common/ceph_json.h" #include "common/ceph_context.h" -#include "rgw_rados.h" -#include "rgw_metadata.h" +#include "common/ceph_json.h" +#include "common/ceph_time.h" +#include "rgw_common.h" #include "rgw_iam_managed_policy.h" -class RGWRados; - -namespace rgw { namespace sal { -struct RGWRoleInfo +struct RGWRoleInfo // TODO: move to rgw_common.h { std::string id; std::string name; @@ -32,9 +30,8 @@ struct RGWRoleInfo std::string description; uint64_t max_session_duration = 0; std::multimap tags; - std::map attrs; RGWObjVersionTracker objv_tracker; - real_time mtime; + ceph::real_time mtime; rgw_account_id account_id; RGWRoleInfo() = default; @@ -86,12 +83,11 @@ struct RGWRoleInfo }; WRITE_CLASS_ENCODER(RGWRoleInfo) +namespace rgw::sal { + class RGWRole { public: - static const std::string role_name_oid_prefix; - static const std::string role_oid_prefix; - static const std::string role_path_oid_prefix; static const std::string role_arn_prefix; static constexpr int MAX_ROLE_NAME_LEN = 64; static constexpr int MAX_PATH_NAME_LEN = 512; @@ -100,12 +96,6 @@ class RGWRole protected: RGWRoleInfo info; public: - virtual int store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) = 0; - virtual int store_name(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) = 0; - virtual int store_path(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) = 0; - virtual int read_id(const DoutPrefixProvider *dpp, const std::string& role_name, const std::string& tenant, std::string& role_id, optional_yield y) = 0; - virtual int read_name(const DoutPrefixProvider *dpp, optional_yield y) = 0; - virtual int read_info(const DoutPrefixProvider *dpp, optional_yield y) = 0; bool validate_max_session_duration(const DoutPrefixProvider* dpp); bool validate_input(const DoutPrefixProvider* dpp); void extract_name_tenant(const std::string& str); @@ -127,6 +117,12 @@ class RGWRole virtual ~RGWRole() = default; + // virtual interface + virtual int load_by_name(const DoutPrefixProvider *dpp, optional_yield y) = 0; + virtual int load_by_id(const DoutPrefixProvider *dpp, optional_yield y) = 0; + virtual int store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) = 0; + virtual int delete_obj(const DoutPrefixProvider *dpp, optional_yield y) = 0; + const std::string& get_id() const { return info.id; } const std::string& get_name() const { return info.name; } const std::string& get_tenant() const { return info.tenant; } @@ -138,17 +134,12 @@ class RGWRole RGWObjVersionTracker& get_objv_tracker() { return info.objv_tracker; } const RGWObjVersionTracker& get_objv_tracker() const { return info.objv_tracker; } const real_time& get_mtime() const { return info.mtime; } - std::map& get_attrs() { return info.attrs; } RGWRoleInfo& get_info() { return info; } void set_id(const std::string& id) { this->info.id = id; } void set_mtime(const real_time& mtime) { this->info.mtime = mtime; } - virtual int create(const DoutPrefixProvider *dpp, bool exclusive, const std::string &role_id, optional_yield y) = 0; - virtual int delete_obj(const DoutPrefixProvider *dpp, optional_yield y) = 0; - int get(const DoutPrefixProvider *dpp, optional_yield y); - int get_by_id(const DoutPrefixProvider *dpp, optional_yield y); - int update(const DoutPrefixProvider *dpp, optional_yield y); + int create(const DoutPrefixProvider *dpp, const std::string &role_id, optional_yield y); void update_trust_policy(std::string& trust_policy); void set_perm_policy(const std::string& policy_name, const std::string& perm_policy); std::vector get_role_policy_names(); @@ -158,68 +149,6 @@ class RGWRole boost::optional> get_tags(); void erase_tags(const std::vector& tagKeys); void update_max_session_duration(const std::string& max_session_duration_str); - - static const std::string& get_names_oid_prefix(); - static const std::string& get_info_oid_prefix(); - static const std::string& get_path_oid_prefix(); }; -class RGWRoleMetadataObject: public RGWMetadataObject { - RGWRoleInfo info; - Driver* driver; -public: - RGWRoleMetadataObject() = default; - RGWRoleMetadataObject(RGWRoleInfo& info, - const obj_version& v, - real_time m, - Driver* driver) : RGWMetadataObject(v,m), info(info), driver(driver) {} - - void dump(Formatter *f) const override { - info.dump(f); - } - - RGWRoleInfo& get_role_info() { - return info; - } - - Driver* get_driver() { - return driver; - } -}; - -class RGWRoleMetadataHandler: public RGWMetadataHandler_GenericMetaBE -{ -public: - RGWRoleMetadataHandler(Driver* driver, RGWSI_Role_RADOS *role_svc); - - std::string get_type() final { return "roles"; } - - RGWMetadataObject *get_meta_obj(JSONObj *jo, - const obj_version& objv, - const ceph::real_time& mtime); - - int do_get(RGWSI_MetaBackend_Handler::Op *op, - std::string& entry, - RGWMetadataObject **obj, - optional_yield y, - const DoutPrefixProvider *dpp) final; - - int do_remove(RGWSI_MetaBackend_Handler::Op *op, - std::string& entry, - RGWObjVersionTracker& objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp) final; - - int do_put(RGWSI_MetaBackend_Handler::Op *op, - std::string& entr, - RGWMetadataObject *obj, - RGWObjVersionTracker& objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp, - RGWMDLogSyncType type, - bool from_remote_zone) override; - -private: - Driver* driver; -}; -} } // namespace rgw::sal +} // namespace rgw::sal diff --git a/src/rgw/rgw_sal.h b/src/rgw/rgw_sal.h index d6129165689ac..f89aa6f4e6602 100644 --- a/src/rgw/rgw_sal.h +++ b/src/rgw/rgw_sal.h @@ -48,6 +48,7 @@ struct rgw_pubsub_bucket_topics; class RGWZonePlacementInfo; struct rgw_pubsub_topic; struct RGWOIDCProviderInfo; +struct RGWRoleInfo; using RGWBucketListNameFilter = std::function; diff --git a/src/rgw/rgw_sal_dbstore.cc b/src/rgw/rgw_sal_dbstore.cc index 5f8bab7081772..d3af42cf2ec03 100644 --- a/src/rgw/rgw_sal_dbstore.cc +++ b/src/rgw/rgw_sal_dbstore.cc @@ -26,6 +26,8 @@ #include "rgw_sal_dbstore.h" #include "rgw_bucket.h" +#include "driver/rados/rgw_rados.h" // XXX: for RGW_OBJ_NS_MULTIPART, PUT_OBJ_CREATE, etc + #define dout_subsys ceph_subsys_rgw using namespace std; diff --git a/src/rgw/rgw_sal_fwd.h b/src/rgw/rgw_sal_fwd.h index e447cba4aae79..566a933f8ca05 100644 --- a/src/rgw/rgw_sal_fwd.h +++ b/src/rgw/rgw_sal_fwd.h @@ -45,7 +45,6 @@ namespace sal { class ZoneGroup; class Zone; class LuaManager; - struct RGWRoleInfo; class RGWRole; struct RoleList; struct GroupList; diff --git a/src/rgw/rgw_sts.cc b/src/rgw/rgw_sts.cc index f879e0f45c19d..7e8e37b3419d0 100644 --- a/src/rgw/rgw_sts.cc +++ b/src/rgw/rgw_sts.cc @@ -300,7 +300,7 @@ std::tuple STSService::getRoleInfo(const DoutPrefixProv } std::unique_ptr role = driver->get_role(roleName, tenant, account); - if (int ret = role->get(dpp, y); ret < 0) { + if (int ret = role->load_by_name(dpp, y); ret < 0) { if (ret == -ENOENT) { ldpp_dout(dpp, 0) << "Role doesn't exist: " << roleName << dendl; ret = -ERR_NO_ROLE_FOUND; diff --git a/src/rgw/services/svc_bi.h b/src/rgw/services/svc_bi.h index 901c28d59fdb4..3ab61e7421ae9 100644 --- a/src/rgw/services/svc_bi.h +++ b/src/rgw/services/svc_bi.h @@ -30,11 +30,11 @@ class RGWSI_BucketIndex : public RGWServiceInstance virtual ~RGWSI_BucketIndex() {} virtual int init_index(const DoutPrefixProvider *dpp, - RGWBucketInfo& bucket_info, + const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout, bool judge_support_logrecord = false) = 0; virtual int clean_index(const DoutPrefixProvider *dpp, - RGWBucketInfo& bucket_info, + const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout) = 0; virtual int read_stats(const DoutPrefixProvider *dpp, diff --git a/src/rgw/services/svc_bi_rados.cc b/src/rgw/services/svc_bi_rados.cc index 15cd5cd58ed36..61d4edc0c9883 100644 --- a/src/rgw/services/svc_bi_rados.cc +++ b/src/rgw/services/svc_bi_rados.cc @@ -352,7 +352,7 @@ int RGWSI_BucketIndex_RADOS::cls_bucket_head(const DoutPrefixProvider *dpp, } int RGWSI_BucketIndex_RADOS::init_index(const DoutPrefixProvider *dpp, - RGWBucketInfo& bucket_info, + const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout, bool judge_support_logrecord) { @@ -380,7 +380,8 @@ int RGWSI_BucketIndex_RADOS::init_index(const DoutPrefixProvider *dpp, } } -int RGWSI_BucketIndex_RADOS::clean_index(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout) +int RGWSI_BucketIndex_RADOS::clean_index(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, + const rgw::bucket_index_layout_generation& idx_layout) { librados::IoCtx index_pool; diff --git a/src/rgw/services/svc_bi_rados.h b/src/rgw/services/svc_bi_rados.h index 7acf5c088070e..b8990133fe09a 100644 --- a/src/rgw/services/svc_bi_rados.h +++ b/src/rgw/services/svc_bi_rados.h @@ -122,11 +122,11 @@ class RGWSI_BucketIndex_RADOS : public RGWSI_BucketIndex } int init_index(const DoutPrefixProvider *dpp, - RGWBucketInfo& bucket_info, + const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout, bool judge_support_logrecord = false) override; int clean_index(const DoutPrefixProvider *dpp, - RGWBucketInfo& bucket_info, + const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout) override; /* RADOS specific */ diff --git a/src/rgw/services/svc_bucket.h b/src/rgw/services/svc_bucket.h index 5963c54171fbc..6bb00e39a4887 100644 --- a/src/rgw/services/svc_bucket.h +++ b/src/rgw/services/svc_bucket.h @@ -17,9 +17,10 @@ #pragma once +#include #include "rgw_service.h" -#include "svc_bucket_types.h" +class RGWMetadataLister; class RGWSI_Bucket : public RGWServiceInstance { @@ -30,11 +31,14 @@ class RGWSI_Bucket : public RGWServiceInstance static std::string get_entrypoint_meta_key(const rgw_bucket& bucket); static std::string get_bi_meta_key(const rgw_bucket& bucket); - virtual RGWSI_Bucket_BE_Handler& get_ep_be_handler() = 0; - virtual RGWSI_BucketInstance_BE_Handler& get_bi_be_handler() = 0; + virtual int create_entrypoint_lister(const DoutPrefixProvider* dpp, + const std::string& marker, + std::unique_ptr& lister) = 0; + virtual int create_instance_lister(const DoutPrefixProvider* dpp, + const std::string& marker, + std::unique_ptr& lister) = 0; - virtual int read_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx, - const std::string& key, + virtual int read_bucket_entrypoint_info(const std::string& key, RGWBucketEntryPoint *entry_point, RGWObjVersionTracker *objv_tracker, real_time *pmtime, @@ -44,8 +48,7 @@ class RGWSI_Bucket : public RGWServiceInstance rgw_cache_entry_info *cache_info = nullptr, boost::optional refresh_version = boost::none) = 0; - virtual int store_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx, - const std::string& key, + virtual int store_bucket_entrypoint_info(const std::string& key, RGWBucketEntryPoint& info, bool exclusive, real_time mtime, @@ -54,14 +57,12 @@ class RGWSI_Bucket : public RGWServiceInstance optional_yield y, const DoutPrefixProvider *dpp) = 0; - virtual int remove_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx, - const std::string& key, + virtual int remove_bucket_entrypoint_info(const std::string& key, RGWObjVersionTracker *objv_tracker, optional_yield y, const DoutPrefixProvider *dpp) = 0; - virtual int read_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, - const std::string& key, + virtual int read_bucket_instance_info(const std::string& key, RGWBucketInfo *info, real_time *pmtime, std::map *pattrs, @@ -70,8 +71,7 @@ class RGWSI_Bucket : public RGWServiceInstance rgw_cache_entry_info *cache_info = nullptr, boost::optional refresh_version = boost::none) = 0; - virtual int read_bucket_info(RGWSI_Bucket_X_Ctx& ep_ctx, - const rgw_bucket& bucket, + virtual int read_bucket_info(const rgw_bucket& bucket, RGWBucketInfo *info, real_time *pmtime, std::map *pattrs, @@ -79,8 +79,7 @@ class RGWSI_Bucket : public RGWServiceInstance optional_yield y, const DoutPrefixProvider *dpp) = 0; - virtual int store_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, - const std::string& key, + virtual int store_bucket_instance_info(const std::string& key, RGWBucketInfo& info, std::optional orig_info, /* nullopt: orig_info was not fetched, nullptr: orig_info was not found (new bucket instance */ @@ -90,21 +89,18 @@ class RGWSI_Bucket : public RGWServiceInstance optional_yield y, const DoutPrefixProvider *dpp) = 0; - virtual int remove_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, - const std::string& key, + virtual int remove_bucket_instance_info(const std::string& key, const RGWBucketInfo& bucket_info, RGWObjVersionTracker *objv_tracker, optional_yield y, const DoutPrefixProvider *dpp) = 0; - virtual int read_bucket_stats(RGWSI_Bucket_X_Ctx& ctx, - const rgw_bucket& bucket, + virtual int read_bucket_stats(const rgw_bucket& bucket, RGWBucketEnt *ent, optional_yield y, const DoutPrefixProvider *dpp) = 0; - virtual int read_buckets_stats(RGWSI_Bucket_X_Ctx& ctx, - std::vector& buckets, + virtual int read_buckets_stats(std::vector& buckets, optional_yield y, const DoutPrefixProvider *dpp) = 0; }; diff --git a/src/rgw/services/svc_bucket_sobj.cc b/src/rgw/services/svc_bucket_sobj.cc index 41e7b02e17596..ca705c5a44d02 100644 --- a/src/rgw/services/svc_bucket_sobj.cc +++ b/src/rgw/services/svc_bucket_sobj.cc @@ -7,136 +7,60 @@ #include "svc_sys_obj.h" #include "svc_sys_obj_cache.h" #include "svc_bi.h" -#include "svc_meta.h" -#include "svc_meta_be_sobj.h" +#include "svc_mdlog.h" #include "svc_sync_modules.h" #include "rgw_bucket.h" +#include "rgw_metadata_lister.h" +#include "rgw_string.h" #include "rgw_tools.h" #include "rgw_zone.h" #define dout_subsys ceph_subsys_rgw -#define RGW_BUCKET_INSTANCE_MD_PREFIX ".bucket.meta." - using namespace std; -class RGWSI_Bucket_SObj_Module : public RGWSI_MBSObj_Handler_Module { - RGWSI_Bucket_SObj::Svc& svc; - - const string prefix; -public: - RGWSI_Bucket_SObj_Module(RGWSI_Bucket_SObj::Svc& _svc) : RGWSI_MBSObj_Handler_Module("bucket"), - svc(_svc) {} - - void get_pool_and_oid(const string& key, rgw_pool *pool, string *oid) override { - if (pool) { - *pool = svc.zone->get_zone_params().domain_root; - } - if (oid) { - *oid = key; - } - } - - const string& get_oid_prefix() override { - return prefix; - } - - bool is_valid_oid(const string& oid) override { - return (!oid.empty() && oid[0] != '.'); - } - - string key_to_oid(const string& key) override { - return key; - } +static const std::string instance_oid_prefix = ".bucket.meta."; - string oid_to_key(const string& oid) override { - /* should have been called after is_valid_oid(), - * so no need to check for validity */ - return oid; - } -}; - -class RGWSI_BucketInstance_SObj_Module : public RGWSI_MBSObj_Handler_Module { - RGWSI_Bucket_SObj::Svc& svc; - - const string prefix; -public: - RGWSI_BucketInstance_SObj_Module(RGWSI_Bucket_SObj::Svc& _svc) : RGWSI_MBSObj_Handler_Module("bucket.instance"), - svc(_svc), prefix(RGW_BUCKET_INSTANCE_MD_PREFIX) {} +// convert bucket instance oids back to the tenant/ format for metadata keys. +// it's safe to parse 'tenant:' only for oids, because they won't contain the +// optional :shard at the end +static std::string instance_meta_key_to_oid(const std::string& metadata_key) +{ + std::string oid = string_cat_reserve(instance_oid_prefix, metadata_key); - void get_pool_and_oid(const string& key, rgw_pool *pool, string *oid) override { - if (pool) { - *pool = svc.zone->get_zone_params().domain_root; - } - if (oid) { - *oid = key_to_oid(key); - } + // replace tenant/ with tenant: + auto c = oid.find('/', instance_oid_prefix.size()); + if (c != string::npos) { + oid[c] = ':'; } - const string& get_oid_prefix() override { - return prefix; - } + return oid; +} - bool is_valid_oid(const string& oid) override { - return (oid.compare(0, prefix.size(), RGW_BUCKET_INSTANCE_MD_PREFIX) == 0); +// convert bucket instance oids back to the tenant/ format for metadata keys. +// it's safe to parse 'tenant:' only for oids, because they won't contain the +// optional :shard at the end +static std::string instance_oid_to_meta_key(const std::string& oid) +{ + if (oid.size() < instance_oid_prefix.size()) { /* just sanity check */ + return string(); } -// 'tenant/' is used in bucket instance keys for sync to avoid parsing ambiguity -// with the existing instance[:shard] format. once we parse the shard, the / is -// replaced with a : to match the [tenant:]instance format - string key_to_oid(const string& key) override { - string oid = prefix + key; + std::string key = oid.substr(instance_oid_prefix.size()); - // replace tenant/ with tenant: - auto c = oid.find('/', prefix.size()); - if (c != string::npos) { - oid[c] = ':'; + // find first : (could be tenant:bucket or bucket:instance) + auto c = key.find(':'); + if (c != string::npos) { + // if we find another :, the first one was for tenant + if (key.find(':', c + 1) != string::npos) { + key[c] = '/'; } - - return oid; } - // convert bucket instance oids back to the tenant/ format for metadata keys. - // it's safe to parse 'tenant:' only for oids, because they won't contain the - // optional :shard at the end - string oid_to_key(const string& oid) override { - /* this should have been called after oid was checked for validity */ - - if (oid.size() < prefix.size()) { /* just sanity check */ - return string(); - } - - string key = oid.substr(prefix.size()); - - // find first : (could be tenant:bucket or bucket:instance) - auto c = key.find(':'); - if (c != string::npos) { - // if we find another :, the first one was for tenant - if (key.find(':', c + 1) != string::npos) { - key[c] = '/'; - } - } + return key; +} - return key; - } - - /* - * hash entry for mdlog placement. Use the same hash key we'd have for the bucket entry - * point, so that the log entries end up at the same log shard, so that we process them - * in order - */ - string get_hash_key(const string& key) override { - string k = "bucket:"; - int pos = key.find(':'); - if (pos < 0) - k.append(key); - else - k.append(key.substr(0, pos)); - - return k; - } -}; RGWSI_Bucket_SObj::RGWSI_Bucket_SObj(CephContext *cct): RGWSI_Bucket(cct) { } @@ -146,7 +70,7 @@ RGWSI_Bucket_SObj::~RGWSI_Bucket_SObj() { void RGWSI_Bucket_SObj::init(RGWSI_Zone *_zone_svc, RGWSI_SysObj *_sysobj_svc, RGWSI_SysObj_Cache *_cache_svc, RGWSI_BucketIndex *_bi, - RGWSI_Meta *_meta_svc, RGWSI_MetaBackend *_meta_be_svc, + RGWSI_MDLog* mdlog_svc, RGWSI_SyncModules *_sync_modules_svc, RGWSI_Bucket_Sync *_bucket_sync_svc) { @@ -155,8 +79,7 @@ void RGWSI_Bucket_SObj::init(RGWSI_Zone *_zone_svc, RGWSI_SysObj *_sysobj_svc, svc.sysobj = _sysobj_svc; svc.cache = _cache_svc; svc.bi = _bi; - svc.meta = _meta_svc; - svc.meta_be = _meta_be_svc; + svc.mdlog = mdlog_svc; svc.sync_modules = _sync_modules_svc; svc.bucket_sync = _bucket_sync_svc; } @@ -165,48 +88,75 @@ int RGWSI_Bucket_SObj::do_start(optional_yield, const DoutPrefixProvider *dpp) { binfo_cache.reset(new RGWChainedCacheImpl); binfo_cache->init(svc.cache); + return 0; +} - /* create first backend handler for bucket entrypoints */ - RGWSI_MetaBackend_Handler *ep_handler; +class BucketEntrypointLister : public RGWMetadataLister { + public: + using RGWMetadataLister::RGWMetadataLister; - int r = svc.meta->create_be_handler(RGWSI_MetaBackend::Type::MDBE_SOBJ, &ep_handler); + void filter_transform(std::vector& oids, + std::list& keys) override + { + // bucket entrypoints and instances share a namespace, so filter out the + // instances based on prefix + constexpr auto filter = [] (const std::string& oid) { + return oid.starts_with('.'); + }; + // 'oids' is mutable so we can move its elements instead of copying + std::remove_copy_if(std::make_move_iterator(oids.begin()), + std::make_move_iterator(oids.end()), + std::back_inserter(keys), filter); + } +}; + +int RGWSI_Bucket_SObj::create_entrypoint_lister( + const DoutPrefixProvider* dpp, + const std::string& marker, + std::unique_ptr& lister) +{ + const rgw_pool& pool = svc.zone->get_zone_params().domain_root; + auto p = std::make_unique(svc.sysobj->get_pool(pool)); + int r = p->init(dpp, marker, ""); // empty prefix if (r < 0) { - ldpp_dout(dpp, 0) << "ERROR: failed to create be handler: r=" << r << dendl; return r; } + lister = std::move(p); + return 0; +} - ep_be_handler = ep_handler; - - RGWSI_MetaBackend_Handler_SObj *ep_bh = static_cast(ep_handler); - - auto ep_module = new RGWSI_Bucket_SObj_Module(svc); - ep_be_module.reset(ep_module); - ep_bh->set_module(ep_module); - /* create a second backend handler for bucket instance */ +class BucketInstanceLister : public RGWMetadataLister { + public: + using RGWMetadataLister::RGWMetadataLister; - RGWSI_MetaBackend_Handler *bi_handler; + void filter_transform(std::vector& oids, + std::list& keys) override + { + // transform instance oids to metadata keys + std::transform(oids.begin(), oids.end(), + std::back_inserter(keys), + instance_oid_to_meta_key); + } +}; - r = svc.meta->create_be_handler(RGWSI_MetaBackend::Type::MDBE_SOBJ, &bi_handler); +int RGWSI_Bucket_SObj::create_instance_lister( + const DoutPrefixProvider* dpp, + const std::string& marker, + std::unique_ptr& lister) +{ + const rgw_pool& pool = svc.zone->get_zone_params().domain_root; + auto p = std::make_unique(svc.sysobj->get_pool(pool)); + int r = p->init(dpp, marker, instance_oid_prefix); if (r < 0) { - ldpp_dout(dpp, 0) << "ERROR: failed to create be handler: r=" << r << dendl; return r; } - - bi_be_handler = bi_handler; - - RGWSI_MetaBackend_Handler_SObj *bi_bh = static_cast(bi_handler); - - auto bi_module = new RGWSI_BucketInstance_SObj_Module(svc); - bi_be_module.reset(bi_module); - bi_bh->set_module(bi_module); - + lister = std::move(p); return 0; } -int RGWSI_Bucket_SObj::read_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx, - const string& key, +int RGWSI_Bucket_SObj::read_bucket_entrypoint_info(const string& key, RGWBucketEntryPoint *entry_point, RGWObjVersionTracker *objv_tracker, real_time *pmtime, @@ -216,12 +166,11 @@ int RGWSI_Bucket_SObj::read_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx, rgw_cache_entry_info *cache_info, boost::optional refresh_version) { + const rgw_pool& pool = svc.zone->get_zone_params().domain_root; bufferlist bl; - - auto params = RGWSI_MBSObj_GetParams(&bl, pattrs, pmtime).set_cache_info(cache_info) - .set_refresh_version(refresh_version); - - int ret = svc.meta_be->get_entry(ctx.get(), key, params, objv_tracker, y, dpp); + int ret = rgw_get_system_obj(svc.sysobj, pool, key, bl, + objv_tracker, pmtime, y, dpp, + pattrs, cache_info, refresh_version); if (ret < 0) { return ret; } @@ -236,8 +185,7 @@ int RGWSI_Bucket_SObj::read_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx, return 0; } -int RGWSI_Bucket_SObj::store_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx, - const string& key, +int RGWSI_Bucket_SObj::store_bucket_entrypoint_info(const string& key, RGWBucketEntryPoint& info, bool exclusive, real_time mtime, @@ -249,28 +197,31 @@ int RGWSI_Bucket_SObj::store_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx, bufferlist bl; encode(info, bl); - RGWSI_MBSObj_PutParams params(bl, pattrs, mtime, exclusive); - - int ret = svc.meta_be->put(ctx.get(), key, params, objv_tracker, y, dpp); + const rgw_pool& pool = svc.zone->get_zone_params().domain_root; + int ret = rgw_put_system_obj(dpp, svc.sysobj, pool, key, bl, exclusive, + objv_tracker, mtime, y, pattrs); if (ret < 0) { return ret; } - return ret; + return svc.mdlog->complete_entry(dpp, y, "bucket", key, objv_tracker); } -int RGWSI_Bucket_SObj::remove_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx, - const string& key, +int RGWSI_Bucket_SObj::remove_bucket_entrypoint_info(const string& key, RGWObjVersionTracker *objv_tracker, optional_yield y, const DoutPrefixProvider *dpp) { - RGWSI_MBSObj_RemoveParams params; - return svc.meta_be->remove(ctx.get(), key, params, objv_tracker, y, dpp); + const rgw_pool& pool = svc.zone->get_zone_params().domain_root; + int ret = rgw_delete_system_obj(dpp, svc.sysobj, pool, key, objv_tracker, y); + if (ret < 0) { + return ret; + } + + return svc.mdlog->complete_entry(dpp, y, "bucket", key, objv_tracker); } -int RGWSI_Bucket_SObj::read_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, - const string& key, +int RGWSI_Bucket_SObj::read_bucket_instance_info(const string& key, RGWBucketInfo *info, real_time *pmtime, map *pattrs, optional_yield y, @@ -301,9 +252,8 @@ int RGWSI_Bucket_SObj::read_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, bucket_info_cache_entry e; rgw_cache_entry_info ci; - int ret = do_read_bucket_instance_info(ctx, key, - &e.info, &e.mtime, &e.attrs, - &ci, refresh_version, y, dpp); + int ret = do_read_bucket_instance_info(key, &e.info, &e.mtime, &e.attrs, + &ci, refresh_version, y, dpp); *info = e.info; if (ret < 0) { @@ -340,8 +290,7 @@ int RGWSI_Bucket_SObj::read_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, return 0; } -int RGWSI_Bucket_SObj::do_read_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, - const string& key, +int RGWSI_Bucket_SObj::do_read_bucket_instance_info(const string& key, RGWBucketInfo *info, real_time *pmtime, map *pattrs, rgw_cache_entry_info *cache_info, @@ -349,13 +298,13 @@ int RGWSI_Bucket_SObj::do_read_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, optional_yield y, const DoutPrefixProvider *dpp) { + const rgw_pool& pool = svc.zone->get_zone_params().domain_root; + const std::string oid = instance_meta_key_to_oid(key); bufferlist bl; - RGWObjVersionTracker ot; - - auto params = RGWSI_MBSObj_GetParams(&bl, pattrs, pmtime).set_cache_info(cache_info) - .set_refresh_version(refresh_version); + RGWObjVersionTracker objv; - int ret = svc.meta_be->get_entry(ctx.get(), key, params, &ot, y, dpp); + int ret = rgw_get_system_obj(svc.sysobj, pool, oid, bl, &objv, pmtime, y, + dpp, pattrs, cache_info, refresh_version); if (ret < 0) { return ret; } @@ -367,12 +316,11 @@ int RGWSI_Bucket_SObj::do_read_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, ldpp_dout(dpp, 0) << "ERROR: could not decode buffer info, caught buffer::error" << dendl; return -EIO; } - info->objv_tracker = ot; + info->objv_tracker = objv; return 0; } -int RGWSI_Bucket_SObj::read_bucket_info(RGWSI_Bucket_X_Ctx& ctx, - const rgw_bucket& bucket, +int RGWSI_Bucket_SObj::read_bucket_info(const rgw_bucket& bucket, RGWBucketInfo *info, real_time *pmtime, map *pattrs, @@ -383,11 +331,8 @@ int RGWSI_Bucket_SObj::read_bucket_info(RGWSI_Bucket_X_Ctx& ctx, rgw_cache_entry_info cache_info; if (!bucket.bucket_id.empty()) { - return read_bucket_instance_info(ctx.bi, get_bi_meta_key(bucket), - info, - pmtime, pattrs, - y, - dpp, + return read_bucket_instance_info(get_bi_meta_key(bucket), info, + pmtime, pattrs, y, dpp, &cache_info, refresh_version); } @@ -420,10 +365,8 @@ int RGWSI_Bucket_SObj::read_bucket_info(RGWSI_Bucket_X_Ctx& ctx, real_time ep_mtime; RGWObjVersionTracker ot; rgw_cache_entry_info entry_cache_info; - int ret = read_bucket_entrypoint_info(ctx.ep, bucket_entry, - &entry_point, &ot, &ep_mtime, pattrs, - y, - dpp, + int ret = read_bucket_entrypoint_info(bucket_entry, &entry_point, &ot, + &ep_mtime, pattrs, y, dpp, &entry_cache_info, refresh_version); if (ret < 0) { /* only init these fields */ @@ -452,10 +395,8 @@ int RGWSI_Bucket_SObj::read_bucket_info(RGWSI_Bucket_X_Ctx& ctx, bucket_info_cache_entry e; - ret = read_bucket_instance_info(ctx.bi, get_bi_meta_key(entry_point.bucket), - &e.info, &e.mtime, &e.attrs, - y, - dpp, + ret = read_bucket_instance_info(get_bi_meta_key(entry_point.bucket), + &e.info, &e.mtime, &e.attrs, y, dpp, &cache_info, refresh_version); *info = e.info; if (ret < 0) { @@ -486,8 +427,7 @@ int RGWSI_Bucket_SObj::read_bucket_info(RGWSI_Bucket_X_Ctx& ctx, } -int RGWSI_Bucket_SObj::store_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, - const string& key, +int RGWSI_Bucket_SObj::store_bucket_instance_info(const string& key, RGWBucketInfo& info, std::optional orig_info, bool exclusive, @@ -509,12 +449,8 @@ int RGWSI_Bucket_SObj::store_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, * we're here because orig_info wasn't passed in * we don't have info about what was there before, so need to fetch first */ - int r = read_bucket_instance_info(ctx, - key, - &shared_bucket_info, - nullptr, nullptr, - y, - dpp, + int r = read_bucket_instance_info(key, &shared_bucket_info, + nullptr, nullptr, y, dpp, nullptr, boost::none); if (r < 0) { if (r != -ENOENT) { @@ -534,14 +470,18 @@ int RGWSI_Bucket_SObj::store_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, } } - RGWSI_MBSObj_PutParams params(bl, pattrs, mtime, exclusive); - - int ret = svc.meta_be->put(ctx.get(), key, params, &info.objv_tracker, y, dpp); - + const rgw_pool& pool = svc.zone->get_zone_params().domain_root; + const std::string oid = instance_meta_key_to_oid(key); + int ret = rgw_put_system_obj(dpp, svc.sysobj, pool, oid, bl, exclusive, + &info.objv_tracker, mtime, y, pattrs); if (ret >= 0) { - int r = svc.bucket_sync->handle_bi_update(dpp, info, - orig_info.value_or(nullptr), - y); + int r = svc.mdlog->complete_entry(dpp, y, "bucket.instance", + key, &info.objv_tracker); + if (r < 0) { + return r; + } + + r = svc.bucket_sync->handle_bi_update(dpp, info, orig_info.value_or(nullptr), y); if (r < 0) { return r; } @@ -564,16 +504,15 @@ int RGWSI_Bucket_SObj::store_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, return ret; } -int RGWSI_Bucket_SObj::remove_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, - const string& key, +int RGWSI_Bucket_SObj::remove_bucket_instance_info(const string& key, const RGWBucketInfo& info, RGWObjVersionTracker *objv_tracker, optional_yield y, const DoutPrefixProvider *dpp) { - RGWSI_MBSObj_RemoveParams params; - int ret = svc.meta_be->remove_entry(dpp, ctx.get(), key, params, objv_tracker, y); - + const rgw_pool& pool = svc.zone->get_zone_params().domain_root; + const std::string oid = instance_meta_key_to_oid(key); + int ret = rgw_delete_system_obj(dpp, svc.sysobj, pool, oid, objv_tracker, y); if (ret < 0 && ret != -ENOENT) { return ret; @@ -587,7 +526,8 @@ int RGWSI_Bucket_SObj::remove_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, */ } - return 0; + return svc.mdlog->complete_entry(dpp, y, "bucket.instance", + key, objv_tracker); } int RGWSI_Bucket_SObj::read_bucket_stats(const RGWBucketInfo& bucket_info, @@ -610,14 +550,13 @@ int RGWSI_Bucket_SObj::read_bucket_stats(const RGWBucketInfo& bucket_info, return 0; } -int RGWSI_Bucket_SObj::read_bucket_stats(RGWSI_Bucket_X_Ctx& ctx, - const rgw_bucket& bucket, +int RGWSI_Bucket_SObj::read_bucket_stats(const rgw_bucket& bucket, RGWBucketEnt *ent, optional_yield y, const DoutPrefixProvider *dpp) { RGWBucketInfo bucket_info; - int ret = read_bucket_info(ctx, bucket, &bucket_info, nullptr, nullptr, boost::none, y, dpp); + int ret = read_bucket_info(bucket, &bucket_info, nullptr, nullptr, boost::none, y, dpp); if (ret < 0) { return ret; } @@ -625,13 +564,12 @@ int RGWSI_Bucket_SObj::read_bucket_stats(RGWSI_Bucket_X_Ctx& ctx, return read_bucket_stats(bucket_info, ent, y, dpp); } -int RGWSI_Bucket_SObj::read_buckets_stats(RGWSI_Bucket_X_Ctx& ctx, - std::vector& buckets, +int RGWSI_Bucket_SObj::read_buckets_stats(std::vector& buckets, optional_yield y, const DoutPrefixProvider *dpp) { for (auto& ent : buckets) { - int r = read_bucket_stats(ctx, ent.bucket, &ent, y, dpp); + int r = read_bucket_stats(ent.bucket, &ent, y, dpp); if (r < 0) { ldpp_dout(dpp, 0) << "ERROR: " << __func__ << "(): read_bucket_stats returned r=" << r << dendl; return r; diff --git a/src/rgw/services/svc_bucket_sobj.h b/src/rgw/services/svc_bucket_sobj.h index 9b95ca18fa4bd..f245417d1686c 100644 --- a/src/rgw/services/svc_bucket_sobj.h +++ b/src/rgw/services/svc_bucket_sobj.h @@ -19,15 +19,13 @@ #include "rgw_service.h" -#include "svc_meta_be.h" -#include "svc_bucket_types.h" #include "svc_bucket.h" #include "svc_bucket_sync.h" class RGWSI_Zone; class RGWSI_SysObj; class RGWSI_SysObj_Cache; -class RGWSI_Meta; +class RGWSI_MDLog; class RGWSI_SyncModules; struct rgw_cache_entry_info; @@ -46,15 +44,9 @@ class RGWSI_Bucket_SObj : public RGWSI_Bucket using RGWChainedCacheImpl_bucket_info_cache_entry = RGWChainedCacheImpl; std::unique_ptr binfo_cache; - RGWSI_Bucket_BE_Handler ep_be_handler; - std::unique_ptr ep_be_module; - RGWSI_BucketInstance_BE_Handler bi_be_handler; - std::unique_ptr bi_be_module; - int do_start(optional_yield, const DoutPrefixProvider *dpp) override; - int do_read_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, - const std::string& key, + int do_read_bucket_instance_info(const std::string& key, RGWBucketInfo *info, real_time *pmtime, std::map *pattrs, @@ -75,8 +67,7 @@ class RGWSI_Bucket_SObj : public RGWSI_Bucket RGWSI_Zone *zone{nullptr}; RGWSI_SysObj *sysobj{nullptr}; RGWSI_SysObj_Cache *cache{nullptr}; - RGWSI_Meta *meta{nullptr}; - RGWSI_MetaBackend *meta_be{nullptr}; + RGWSI_MDLog *mdlog{nullptr}; RGWSI_SyncModules *sync_modules{nullptr}; RGWSI_Bucket_Sync *bucket_sync{nullptr}; } svc; @@ -84,26 +75,23 @@ class RGWSI_Bucket_SObj : public RGWSI_Bucket RGWSI_Bucket_SObj(CephContext *cct); ~RGWSI_Bucket_SObj(); - RGWSI_Bucket_BE_Handler& get_ep_be_handler() override { - return ep_be_handler; - } - - RGWSI_BucketInstance_BE_Handler& get_bi_be_handler() override { - return bi_be_handler; - } - void init(RGWSI_Zone *_zone_svc, RGWSI_SysObj *_sysobj_svc, RGWSI_SysObj_Cache *_cache_svc, RGWSI_BucketIndex *_bi, - RGWSI_Meta *_meta_svc, - RGWSI_MetaBackend *_meta_be_svc, + RGWSI_MDLog *mdlog_svc, RGWSI_SyncModules *_sync_modules_svc, RGWSI_Bucket_Sync *_bucket_sync_svc); + int create_entrypoint_lister(const DoutPrefixProvider* dpp, + const std::string& marker, + std::unique_ptr& lister) override; + + int create_instance_lister(const DoutPrefixProvider* dpp, + const std::string& marker, + std::unique_ptr& lister) override; - int read_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx, - const std::string& key, + int read_bucket_entrypoint_info(const std::string& key, RGWBucketEntryPoint *entry_point, RGWObjVersionTracker *objv_tracker, real_time *pmtime, @@ -113,8 +101,7 @@ class RGWSI_Bucket_SObj : public RGWSI_Bucket rgw_cache_entry_info *cache_info = nullptr, boost::optional refresh_version = boost::none) override; - int store_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx, - const std::string& key, + int store_bucket_entrypoint_info(const std::string& key, RGWBucketEntryPoint& info, bool exclusive, real_time mtime, @@ -123,14 +110,12 @@ class RGWSI_Bucket_SObj : public RGWSI_Bucket optional_yield y, const DoutPrefixProvider *dpp) override; - int remove_bucket_entrypoint_info(RGWSI_Bucket_EP_Ctx& ctx, - const std::string& key, + int remove_bucket_entrypoint_info(const std::string& key, RGWObjVersionTracker *objv_tracker, optional_yield y, const DoutPrefixProvider *dpp) override; - int read_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, - const std::string& key, + int read_bucket_instance_info(const std::string& key, RGWBucketInfo *info, real_time *pmtime, std::map *pattrs, @@ -139,8 +124,7 @@ class RGWSI_Bucket_SObj : public RGWSI_Bucket rgw_cache_entry_info *cache_info = nullptr, boost::optional refresh_version = boost::none) override; - int read_bucket_info(RGWSI_Bucket_X_Ctx& ep_ctx, - const rgw_bucket& bucket, + int read_bucket_info(const rgw_bucket& bucket, RGWBucketInfo *info, real_time *pmtime, std::map *pattrs, @@ -148,8 +132,7 @@ class RGWSI_Bucket_SObj : public RGWSI_Bucket optional_yield y, const DoutPrefixProvider *dpp) override; - int store_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, - const std::string& key, + int store_bucket_instance_info(const std::string& key, RGWBucketInfo& info, std::optional orig_info, /* nullopt: orig_info was not fetched, nullptr: orig_info was not found (new bucket instance */ @@ -159,21 +142,18 @@ class RGWSI_Bucket_SObj : public RGWSI_Bucket optional_yield y, const DoutPrefixProvider *dpp) override; - int remove_bucket_instance_info(RGWSI_Bucket_BI_Ctx& ctx, - const std::string& key, + int remove_bucket_instance_info(const std::string& key, const RGWBucketInfo& bucket_info, RGWObjVersionTracker *objv_tracker, optional_yield y, const DoutPrefixProvider *dpp) override; - int read_bucket_stats(RGWSI_Bucket_X_Ctx& ctx, - const rgw_bucket& bucket, + int read_bucket_stats(const rgw_bucket& bucket, RGWBucketEnt *ent, optional_yield y, const DoutPrefixProvider *dpp) override; - int read_buckets_stats(RGWSI_Bucket_X_Ctx& ctx, - std::vector& buckets, + int read_buckets_stats(std::vector& buckets, optional_yield y, const DoutPrefixProvider *dpp) override; }; diff --git a/src/rgw/services/svc_bucket_sync.h b/src/rgw/services/svc_bucket_sync.h index 37dada55ecd83..b72740b386dea 100644 --- a/src/rgw/services/svc_bucket_sync.h +++ b/src/rgw/services/svc_bucket_sync.h @@ -19,8 +19,6 @@ #include "driver/rados/rgw_service.h" // FIXME: subclass dependency -#include "svc_bucket_types.h" - class RGWBucketSyncPolicyHandler; using RGWBucketSyncPolicyHandlerRef = std::shared_ptr; @@ -30,8 +28,7 @@ class RGWSI_Bucket_Sync : public RGWServiceInstance public: RGWSI_Bucket_Sync(CephContext *cct) : RGWServiceInstance(cct) {} - virtual int get_policy_handler(RGWSI_Bucket_X_Ctx& ctx, - std::optional zone, + virtual int get_policy_handler(std::optional zone, std::optional bucket, RGWBucketSyncPolicyHandlerRef *handler, optional_yield y, diff --git a/src/rgw/services/svc_bucket_sync_sobj.cc b/src/rgw/services/svc_bucket_sync_sobj.cc index ea3398a3f48c9..cc77ece29aab9 100644 --- a/src/rgw/services/svc_bucket_sync_sobj.cc +++ b/src/rgw/services/svc_bucket_sync_sobj.cc @@ -70,8 +70,7 @@ int RGWSI_Bucket_Sync_SObj::do_start(optional_yield, const DoutPrefixProvider *d return 0; } -void RGWSI_Bucket_Sync_SObj::get_hint_entities(RGWSI_Bucket_X_Ctx& ctx, - const std::set& zones, +void RGWSI_Bucket_Sync_SObj::get_hint_entities(const std::set& zones, const std::set& buckets, std::set *hint_entities, optional_yield y, const DoutPrefixProvider *dpp) @@ -82,7 +81,7 @@ void RGWSI_Bucket_Sync_SObj::get_hint_entities(RGWSI_Bucket_X_Ctx& ctx, for (auto& b : buckets) { RGWBucketInfo hint_bucket_info; - int ret = svc.bucket_sobj->read_bucket_info(ctx, b, &hint_bucket_info, + int ret = svc.bucket_sobj->read_bucket_info(b, &hint_bucket_info, nullptr, nullptr, boost::none, y, dpp); if (ret < 0) { @@ -100,8 +99,7 @@ void RGWSI_Bucket_Sync_SObj::get_hint_entities(RGWSI_Bucket_X_Ctx& ctx, } } -int RGWSI_Bucket_Sync_SObj::resolve_policy_hints(RGWSI_Bucket_X_Ctx& ctx, - rgw_sync_bucket_entity& self_entity, +int RGWSI_Bucket_Sync_SObj::resolve_policy_hints(rgw_sync_bucket_entity& self_entity, RGWBucketSyncPolicyHandlerRef& handler, RGWBucketSyncPolicyHandlerRef& zone_policy_handler, std::map& temp_map, @@ -119,8 +117,8 @@ int RGWSI_Bucket_Sync_SObj::resolve_policy_hints(RGWSI_Bucket_X_Ctx& ctx, std::set hint_entities; - get_hint_entities(ctx, source_zones, handler->get_source_hints(), &hint_entities, y, dpp); - get_hint_entities(ctx, target_zones, handler->get_target_hints(), &hint_entities, y, dpp); + get_hint_entities(source_zones, handler->get_source_hints(), &hint_entities, y, dpp); + get_hint_entities(target_zones, handler->get_target_hints(), &hint_entities, y, dpp); std::set resolved_sources; std::set resolved_dests; @@ -140,7 +138,7 @@ int RGWSI_Bucket_Sync_SObj::resolve_policy_hints(RGWSI_Bucket_X_Ctx& ctx, if (iter != temp_map.end()) { hint_bucket_handler = iter->second; } else { - int r = do_get_policy_handler(ctx, zid, hint_bucket, temp_map, &hint_bucket_handler, y, dpp); + int r = do_get_policy_handler(zid, hint_bucket, temp_map, &hint_bucket_handler, y, dpp); if (r < 0) { ldpp_dout(dpp, 20) << "could not get bucket sync policy handler for hint bucket=" << hint_bucket << " ... skipping" << dendl; continue; @@ -158,8 +156,7 @@ int RGWSI_Bucket_Sync_SObj::resolve_policy_hints(RGWSI_Bucket_X_Ctx& ctx, return 0; } -int RGWSI_Bucket_Sync_SObj::do_get_policy_handler(RGWSI_Bucket_X_Ctx& ctx, - std::optional zone, +int RGWSI_Bucket_Sync_SObj::do_get_policy_handler(std::optional zone, std::optional _bucket, std::map& temp_map, RGWBucketSyncPolicyHandlerRef *handler, @@ -175,8 +172,7 @@ int RGWSI_Bucket_Sync_SObj::do_get_policy_handler(RGWSI_Bucket_X_Ctx& ctx, if (bucket.bucket_id.empty()) { RGWBucketEntryPoint ep_info; - int ret = svc.bucket_sobj->read_bucket_entrypoint_info(ctx.ep, - RGWSI_Bucket::get_entrypoint_meta_key(bucket), + int ret = svc.bucket_sobj->read_bucket_entrypoint_info(RGWSI_Bucket::get_entrypoint_meta_key(bucket), &ep_info, nullptr, /* objv_tracker */ nullptr, /* mtime */ @@ -217,8 +213,7 @@ int RGWSI_Bucket_Sync_SObj::do_get_policy_handler(RGWSI_Bucket_X_Ctx& ctx, RGWBucketInfo bucket_info; map attrs; - int r = svc.bucket_sobj->read_bucket_instance_info(ctx.bi, - bucket_key, + int r = svc.bucket_sobj->read_bucket_instance_info(bucket_key, &bucket_info, nullptr, &attrs, @@ -250,7 +245,7 @@ int RGWSI_Bucket_Sync_SObj::do_get_policy_handler(RGWSI_Bucket_X_Ctx& ctx, rgw_sync_bucket_entity self_entity(zone.value_or(svc.zone->zone_id()), bucket); - r = resolve_policy_hints(ctx, self_entity, + r = resolve_policy_hints(self_entity, e.handler, zone_policy_handler, temp_map, y, dpp); @@ -268,15 +263,14 @@ int RGWSI_Bucket_Sync_SObj::do_get_policy_handler(RGWSI_Bucket_X_Ctx& ctx, return 0; } -int RGWSI_Bucket_Sync_SObj::get_policy_handler(RGWSI_Bucket_X_Ctx& ctx, - std::optional zone, +int RGWSI_Bucket_Sync_SObj::get_policy_handler(std::optional zone, std::optional _bucket, RGWBucketSyncPolicyHandlerRef *handler, optional_yield y, const DoutPrefixProvider *dpp) { std::map temp_map; - return do_get_policy_handler(ctx, zone, _bucket, temp_map, handler, y, dpp); + return do_get_policy_handler(zone, _bucket, temp_map, handler, y, dpp); } static bool diff_sets(std::set& orig_set, diff --git a/src/rgw/services/svc_bucket_sync_sobj.h b/src/rgw/services/svc_bucket_sync_sobj.h index 779df7b996ca6..e4ebccbaad27e 100644 --- a/src/rgw/services/svc_bucket_sync_sobj.h +++ b/src/rgw/services/svc_bucket_sync_sobj.h @@ -19,7 +19,6 @@ #include "rgw_service.h" -#include "svc_meta_be.h" #include "svc_bucket_sync.h" class RGWSI_Zone; @@ -63,20 +62,17 @@ class RGWSI_Bucket_Sync_SObj : public RGWSI_Bucket_Sync } }; - void get_hint_entities(RGWSI_Bucket_X_Ctx& ctx, - const std::set& zone_names, + void get_hint_entities(const std::set& zone_names, const std::set& buckets, std::set *hint_entities, optional_yield y, const DoutPrefixProvider *); - int resolve_policy_hints(RGWSI_Bucket_X_Ctx& ctx, - rgw_sync_bucket_entity& self_entity, + int resolve_policy_hints(rgw_sync_bucket_entity& self_entity, RGWBucketSyncPolicyHandlerRef& handler, RGWBucketSyncPolicyHandlerRef& zone_policy_handler, std::map& temp_map, optional_yield y, const DoutPrefixProvider *dpp); - int do_get_policy_handler(RGWSI_Bucket_X_Ctx& ctx, - std::optional zone, + int do_get_policy_handler(std::optional zone, std::optional _bucket, std::map& temp_map, RGWBucketSyncPolicyHandlerRef *handler, @@ -99,8 +95,7 @@ class RGWSI_Bucket_Sync_SObj : public RGWSI_Bucket_Sync RGWSI_Bucket_SObj *_bucket_sobj_svc); - int get_policy_handler(RGWSI_Bucket_X_Ctx& ctx, - std::optional zone, + int get_policy_handler(std::optional zone, std::optional bucket, RGWBucketSyncPolicyHandlerRef *handler, optional_yield y, diff --git a/src/rgw/services/svc_bucket_types.h b/src/rgw/services/svc_bucket_types.h deleted file mode 100644 index 30e5309d56dad..0000000000000 --- a/src/rgw/services/svc_bucket_types.h +++ /dev/null @@ -1,38 +0,0 @@ - -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab ft=cpp - -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2019 Red Hat, Inc. - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - - -#pragma once - -#include "common/ptr_wrapper.h" - -#include "svc_meta_be.h" -#include "svc_meta_be_types.h" - -class RGWSI_MetaBackend_Handler; - -using RGWSI_Bucket_BE_Handler = ptr_wrapper; -using RGWSI_BucketInstance_BE_Handler = ptr_wrapper; - - -using RGWSI_Bucket_EP_Ctx = ptr_wrapper; -using RGWSI_Bucket_BI_Ctx = ptr_wrapper; - -struct RGWSI_Bucket_X_Ctx { - RGWSI_Bucket_EP_Ctx ep; - RGWSI_Bucket_BI_Ctx bi; -}; - diff --git a/src/rgw/services/svc_mdlog.cc b/src/rgw/services/svc_mdlog.cc index 03a967d12673b..90b9b6611d270 100644 --- a/src/rgw/services/svc_mdlog.cc +++ b/src/rgw/services/svc_mdlog.cc @@ -1,6 +1,8 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab ft=cpp +#include + #include "svc_mdlog.h" #include "svc_zone.h" #include "svc_sys_obj.h" diff --git a/src/rgw/services/svc_mdlog.h b/src/rgw/services/svc_mdlog.h index c8d40b1387428..c627b46af1d44 100644 --- a/src/rgw/services/svc_mdlog.h +++ b/src/rgw/services/svc_mdlog.h @@ -20,8 +20,6 @@ #include "rgw_period_history.h" #include "rgw_period_puller.h" -#include "svc_meta_be.h" - class RGWMetadataLog; class RGWMetadataLogHistory; diff --git a/src/rgw/services/svc_meta.cc b/src/rgw/services/svc_meta.cc deleted file mode 100644 index 735c39f85e89b..0000000000000 --- a/src/rgw/services/svc_meta.cc +++ /dev/null @@ -1,46 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab ft=cpp - - -#include "svc_meta.h" - -#include "rgw_metadata.h" - -#define dout_subsys ceph_subsys_rgw - -using namespace std; - -RGWSI_Meta::RGWSI_Meta(CephContext *cct) : RGWServiceInstance(cct) { -} - -RGWSI_Meta::~RGWSI_Meta() {} - -void RGWSI_Meta::init(RGWSI_SysObj *_sysobj_svc, - RGWSI_MDLog *_mdlog_svc, - vector& _be_svc) -{ - sysobj_svc = _sysobj_svc; - mdlog_svc = _mdlog_svc; - - for (auto& be : _be_svc) { - be_svc[be->get_type()] = be; - } -} - -int RGWSI_Meta::create_be_handler(RGWSI_MetaBackend::Type be_type, - RGWSI_MetaBackend_Handler **phandler) -{ - auto iter = be_svc.find(be_type); - if (iter == be_svc.end()) { - ldout(cct, 0) << __func__ << "(): ERROR: backend type not found" << dendl; - return -EINVAL; - } - - auto handler = iter->second->alloc_be_handler(); - - be_handlers.emplace_back(handler); - *phandler = handler; - - return 0; -} - diff --git a/src/rgw/services/svc_meta.h b/src/rgw/services/svc_meta.h deleted file mode 100644 index b398e27fd26aa..0000000000000 --- a/src/rgw/services/svc_meta.h +++ /dev/null @@ -1,48 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab ft=cpp - -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2019 Red Hat, Inc. - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - - -#pragma once - -#include "svc_meta_be.h" - -#include "rgw_service.h" - - -class RGWMetadataLog; -class RGWCoroutine; - - -class RGWSI_Meta : public RGWServiceInstance -{ - RGWSI_SysObj *sysobj_svc{nullptr}; - RGWSI_MDLog *mdlog_svc{nullptr}; - - std::map be_svc; - - std::vector > be_handlers; - -public: - RGWSI_Meta(CephContext *cct); - ~RGWSI_Meta(); - - void init(RGWSI_SysObj *_sysobj_svc, - RGWSI_MDLog *_mdlog_svc, - std::vector& _be_svc); - - int create_be_handler(RGWSI_MetaBackend::Type be_type, - RGWSI_MetaBackend_Handler **phandler); -}; - diff --git a/src/rgw/services/svc_meta_be.cc b/src/rgw/services/svc_meta_be.cc deleted file mode 100644 index 2cb0365c84463..0000000000000 --- a/src/rgw/services/svc_meta_be.cc +++ /dev/null @@ -1,193 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab ft=cpp - - -#include "svc_meta_be.h" - -#include "rgw_mdlog.h" - -#define dout_subsys ceph_subsys_rgw - -using namespace std; - -RGWSI_MetaBackend::Context::~Context() {} // needed, even though destructor is pure virtual -RGWSI_MetaBackend::Module::~Module() {} // ditto -RGWSI_MetaBackend::PutParams::~PutParams() {} // ... -RGWSI_MetaBackend::GetParams::~GetParams() {} // ... -RGWSI_MetaBackend::RemoveParams::~RemoveParams() {} // ... - -int RGWSI_MetaBackend::pre_modify(const DoutPrefixProvider *dpp, - RGWSI_MetaBackend::Context *ctx, - const string& key, - RGWMetadataLogData& log_data, - RGWObjVersionTracker *objv_tracker, - RGWMDLogStatus op_type, - optional_yield y) -{ - /* if write version has not been set, and there's a read version, set it so that we can - * log it - */ - if (objv_tracker && - objv_tracker->read_version.ver && !objv_tracker->write_version.ver) { - objv_tracker->write_version = objv_tracker->read_version; - objv_tracker->write_version.ver++; - } - - return 0; -} - -int RGWSI_MetaBackend::post_modify(const DoutPrefixProvider *dpp, - RGWSI_MetaBackend::Context *ctx, - const string& key, - RGWMetadataLogData& log_data, - RGWObjVersionTracker *objv_tracker, int ret, - optional_yield y) -{ - return ret; -} - -int RGWSI_MetaBackend::prepare_mutate(RGWSI_MetaBackend::Context *ctx, - const string& key, - const real_time& mtime, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - real_time orig_mtime; - - int ret = call_with_get_params(&orig_mtime, [&](GetParams& params) { - return get_entry(ctx, key, params, objv_tracker, y, dpp); - }); - if (ret < 0 && ret != -ENOENT) { - return ret; - } - - if (objv_tracker->write_version.tag.empty()) { - if (objv_tracker->read_version.tag.empty()) { - objv_tracker->generate_new_write_ver(cct); - } else { - objv_tracker->write_version = objv_tracker->read_version; - objv_tracker->write_version.ver++; - } - } - return 0; -} - -int RGWSI_MetaBackend::do_mutate(RGWSI_MetaBackend::Context *ctx, - const string& key, - const ceph::real_time& mtime, - RGWObjVersionTracker *objv_tracker, - RGWMDLogStatus op_type, - optional_yield y, - std::function f, - bool generic_prepare, - const DoutPrefixProvider *dpp) -{ - int ret; - - if (generic_prepare) { - ret = prepare_mutate(ctx, key, mtime, objv_tracker, y, dpp); - if (ret < 0 || - ret == STATUS_NO_APPLY) { - return ret; - } - } - - RGWMetadataLogData log_data; - ret = pre_modify(dpp, ctx, key, log_data, objv_tracker, op_type, y); - if (ret < 0) { - return ret; - } - - ret = f(); - - /* cascading ret into post_modify() */ - - ret = post_modify(dpp, ctx, key, log_data, objv_tracker, ret, y); - if (ret < 0) - return ret; - - return 0; -} - -int RGWSI_MetaBackend::get(Context *ctx, - const string& key, - GetParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp, - bool get_raw_attrs) -{ - return get_entry(ctx, key, params, objv_tracker, y, dpp, get_raw_attrs); -} - -int RGWSI_MetaBackend::put(Context *ctx, - const string& key, - PutParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - std::function f = [&]() { - return put_entry(dpp, ctx, key, params, objv_tracker, y); - }; - - return do_mutate(ctx, key, params.mtime, objv_tracker, - MDLOG_STATUS_WRITE, - y, - f, - false, - dpp); -} - -int RGWSI_MetaBackend::remove(Context *ctx, - const string& key, - RemoveParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - std::function f = [&]() { - return remove_entry(dpp, ctx, key, params, objv_tracker, y); - }; - - return do_mutate(ctx, key, params.mtime, objv_tracker, - MDLOG_STATUS_REMOVE, - y, - f, - false, - dpp); -} - -int RGWSI_MetaBackend::mutate(Context *ctx, - const std::string& key, - MutateParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - std::function f, - const DoutPrefixProvider *dpp) -{ - return do_mutate(ctx, key, params.mtime, objv_tracker, - params.op_type, y, - f, - false, - dpp); -} - -int RGWSI_MetaBackend_Handler::call(std::optional bectx_params, - std::function f) -{ - return be->call(bectx_params, [&](RGWSI_MetaBackend::Context *ctx) { - ctx->init(this); - Op op(be, ctx); - return f(&op); - }); -} - -RGWSI_MetaBackend_Handler::Op_ManagedCtx::Op_ManagedCtx(RGWSI_MetaBackend_Handler *handler) : Op(handler->be, handler->be->alloc_ctx()) -{ - auto c = ctx(); - c->init(handler); - pctx.reset(c); -} - diff --git a/src/rgw/services/svc_meta_be.h b/src/rgw/services/svc_meta_be.h deleted file mode 100644 index b580d173f2203..0000000000000 --- a/src/rgw/services/svc_meta_be.h +++ /dev/null @@ -1,295 +0,0 @@ - -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab ft=cpp - -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2019 Red Hat, Inc. - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - - -#pragma once - -#include "svc_meta_be_params.h" - -#include "rgw_mdlog_types.h" - -#include "driver/rados/rgw_service.h" // FIXME: subclass dependency - -class RGWMetadataLogData; - -class RGWSI_MDLog; -class RGWSI_Meta; -class RGWObjVersionTracker; -class RGWSI_MetaBackend_Handler; - -class RGWSI_MetaBackend : public RGWServiceInstance -{ - friend class RGWSI_Meta; -public: - class Module; - class Context; -protected: - RGWSI_MDLog *mdlog_svc{nullptr}; - - void base_init(RGWSI_MDLog *_mdlog_svc) { - mdlog_svc = _mdlog_svc; - } - - int prepare_mutate(RGWSI_MetaBackend::Context *ctx, - const std::string& key, - const ceph::real_time& mtime, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp); - - virtual int do_mutate(Context *ctx, - const std::string& key, - const ceph::real_time& mtime, RGWObjVersionTracker *objv_tracker, - RGWMDLogStatus op_type, - optional_yield y, - std::function f, - bool generic_prepare, - const DoutPrefixProvider *dpp); - - virtual int pre_modify(const DoutPrefixProvider *dpp, - Context *ctx, - const std::string& key, - RGWMetadataLogData& log_data, - RGWObjVersionTracker *objv_tracker, - RGWMDLogStatus op_type, - optional_yield y); - virtual int post_modify(const DoutPrefixProvider *dpp, - Context *ctx, - const std::string& key, - RGWMetadataLogData& log_data, - RGWObjVersionTracker *objv_tracker, int ret, - optional_yield y); -public: - class Module { - /* - * Backend specialization module - */ - public: - virtual ~Module() = 0; - }; - - using ModuleRef = std::shared_ptr; - - struct Context { /* - * A single metadata operation context. Will be holding info about - * backend and operation itself; operation might span multiple backend - * calls. - */ - virtual ~Context() = 0; - - virtual void init(RGWSI_MetaBackend_Handler *h) = 0; - }; - - virtual Context *alloc_ctx() = 0; - - struct PutParams { - ceph::real_time mtime; - - PutParams() {} - PutParams(const ceph::real_time& _mtime) : mtime(_mtime) {} - virtual ~PutParams() = 0; - }; - - struct GetParams { - GetParams() {} - GetParams(ceph::real_time *_pmtime) : pmtime(_pmtime) {} - virtual ~GetParams(); - - ceph::real_time *pmtime{nullptr}; - }; - - struct RemoveParams { - virtual ~RemoveParams() = 0; - - ceph::real_time mtime; - }; - - struct MutateParams { - ceph::real_time mtime; - RGWMDLogStatus op_type; - - MutateParams() {} - MutateParams(const ceph::real_time& _mtime, - RGWMDLogStatus _op_type) : mtime(_mtime), op_type(_op_type) {} - virtual ~MutateParams() {} - }; - - enum Type { - MDBE_SOBJ = 0, - MDBE_OTP = 1, - }; - - RGWSI_MetaBackend(CephContext *cct) : RGWServiceInstance(cct) {} - virtual ~RGWSI_MetaBackend() {} - - virtual Type get_type() = 0; - - virtual RGWSI_MetaBackend_Handler *alloc_be_handler() = 0; - virtual int call_with_get_params(ceph::real_time *pmtime, std::function) = 0; - - /* these should be implemented by backends */ - virtual int get_entry(RGWSI_MetaBackend::Context *ctx, - const std::string& key, - RGWSI_MetaBackend::GetParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp, - bool get_raw_attrs=false) = 0; - virtual int put_entry(const DoutPrefixProvider *dpp, - RGWSI_MetaBackend::Context *ctx, - const std::string& key, - RGWSI_MetaBackend::PutParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y) = 0; - virtual int remove_entry(const DoutPrefixProvider *dpp, - Context *ctx, - const std::string& key, - RGWSI_MetaBackend::RemoveParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y) = 0; - - virtual int list_init(const DoutPrefixProvider *dpp, RGWSI_MetaBackend::Context *ctx, const std::string& marker) = 0; - virtual int list_next(const DoutPrefixProvider *dpp, - RGWSI_MetaBackend::Context *ctx, - int max, std::list *keys, - bool *truncated) = 0; - virtual int list_get_marker(RGWSI_MetaBackend::Context *ctx, - std::string *marker) = 0; - - int call(std::function f) { - return call(std::nullopt, f); - } - - virtual int call(std::optional opt, - std::function f) = 0; - - virtual int get_shard_id(RGWSI_MetaBackend::Context *ctx, - const std::string& key, - int *shard_id) = 0; - - /* higher level */ - virtual int get(Context *ctx, - const std::string& key, - GetParams ¶ms, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp, - bool get_raw_attrs=false); - - virtual int put(Context *ctx, - const std::string& key, - PutParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp); - - virtual int remove(Context *ctx, - const std::string& key, - RemoveParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp); - - virtual int mutate(Context *ctx, - const std::string& key, - MutateParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - std::function f, - const DoutPrefixProvider *dpp); -}; - -class RGWSI_MetaBackend_Handler { - RGWSI_MetaBackend *be{nullptr}; - -public: - class Op { - friend class RGWSI_MetaBackend_Handler; - - RGWSI_MetaBackend *be; - RGWSI_MetaBackend::Context *be_ctx; - - Op(RGWSI_MetaBackend *_be, - RGWSI_MetaBackend::Context *_ctx) : be(_be), be_ctx(_ctx) {} - - public: - RGWSI_MetaBackend::Context *ctx() { - return be_ctx; - } - - int get(const std::string& key, - RGWSI_MetaBackend::GetParams ¶ms, - RGWObjVersionTracker *objv_tracker, - optional_yield y, const DoutPrefixProvider *dpp) { - return be->get(be_ctx, key, params, objv_tracker, y, dpp); - } - - int put(const std::string& key, - RGWSI_MetaBackend::PutParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y, const DoutPrefixProvider *dpp) { - return be->put(be_ctx, key, params, objv_tracker, y, dpp); - } - - int remove(const std::string& key, - RGWSI_MetaBackend::RemoveParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y, const DoutPrefixProvider *dpp) { - return be->remove(be_ctx, key, params, objv_tracker, y, dpp); - } - - int mutate(const std::string& key, - RGWSI_MetaBackend::MutateParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - std::function f, - const DoutPrefixProvider *dpp) { - return be->mutate(be_ctx, key, params, objv_tracker, y, f, dpp); - } - - int list_init(const DoutPrefixProvider *dpp, const std::string& marker) { - return be->list_init(dpp, be_ctx, marker); - } - int list_next(const DoutPrefixProvider *dpp, int max, std::list *keys, - bool *truncated) { - return be->list_next(dpp, be_ctx, max, keys, truncated); - } - int list_get_marker(std::string *marker) { - return be->list_get_marker(be_ctx, marker); - } - - int get_shard_id(const std::string& key, int *shard_id) { - return be->get_shard_id(be_ctx, key, shard_id); - } - }; - - class Op_ManagedCtx : public Op { - std::unique_ptr pctx; - public: - Op_ManagedCtx(RGWSI_MetaBackend_Handler *handler); - }; - - RGWSI_MetaBackend_Handler(RGWSI_MetaBackend *_be) : be(_be) {} - virtual ~RGWSI_MetaBackend_Handler() {} - - int call(std::function f) { - return call(std::nullopt, f); - } - - virtual int call(std::optional bectx_params, - std::function f); -}; - diff --git a/src/rgw/services/svc_meta_be_otp.cc b/src/rgw/services/svc_meta_be_otp.cc deleted file mode 100644 index 3cabeb9d0a99e..0000000000000 --- a/src/rgw/services/svc_meta_be_otp.cc +++ /dev/null @@ -1,73 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab ft=cpp - -#include "svc_meta_be_otp.h" - -#include "rgw_tools.h" -#include "rgw_metadata.h" -#include "rgw_mdlog.h" - -#define dout_subsys ceph_subsys_rgw - -using namespace std; - -RGWSI_MetaBackend_OTP::RGWSI_MetaBackend_OTP(CephContext *cct) : RGWSI_MetaBackend_SObj(cct) { -} - -RGWSI_MetaBackend_OTP::~RGWSI_MetaBackend_OTP() { -} - -string RGWSI_MetaBackend_OTP::get_meta_key(const rgw_user& user) -{ - return string("otp:user:") + user.to_str(); -} - -RGWSI_MetaBackend_Handler *RGWSI_MetaBackend_OTP::alloc_be_handler() -{ - return new RGWSI_MetaBackend_Handler_OTP(this); -} - -RGWSI_MetaBackend::Context *RGWSI_MetaBackend_OTP::alloc_ctx() -{ - return new Context_OTP; -} - -int RGWSI_MetaBackend_OTP::call_with_get_params(ceph::real_time *pmtime, std::function cb) -{ - otp_devices_list_t devices; - RGWSI_MBOTP_GetParams params; - params.pdevices = &devices; - params.pmtime = pmtime; - return cb(params); -} - -int RGWSI_MetaBackend_OTP::get_entry(RGWSI_MetaBackend::Context *_ctx, - const string& key, - RGWSI_MetaBackend::GetParams& _params, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp, - bool get_raw_attrs) -{ - RGWSI_MBOTP_GetParams& params = static_cast(_params); - - int r = cls_svc->mfa.list_mfa(dpp, key, params.pdevices, objv_tracker, params.pmtime, y); - if (r < 0) { - return r; - } - - return 0; -} - -int RGWSI_MetaBackend_OTP::put_entry(const DoutPrefixProvider *dpp, - RGWSI_MetaBackend::Context *_ctx, - const string& key, - RGWSI_MetaBackend::PutParams& _params, - RGWObjVersionTracker *objv_tracker, - optional_yield y) -{ - RGWSI_MBOTP_PutParams& params = static_cast(_params); - - return cls_svc->mfa.set_mfa(dpp, key, params.devices, true, objv_tracker, params.mtime, y); -} - diff --git a/src/rgw/services/svc_meta_be_otp.h b/src/rgw/services/svc_meta_be_otp.h deleted file mode 100644 index 7bd9cf652ff8e..0000000000000 --- a/src/rgw/services/svc_meta_be_otp.h +++ /dev/null @@ -1,89 +0,0 @@ - - -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab ft=cpp - -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2019 Red Hat, Inc. - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - - -#pragma once - -#include "rgw_service.h" - -#include "svc_cls.h" -#include "svc_meta_be.h" -#include "svc_meta_be_sobj.h" -#include "svc_sys_obj.h" - - -using RGWSI_MBOTP_Handler_Module = RGWSI_MBSObj_Handler_Module; -using RGWSI_MetaBackend_Handler_OTP = RGWSI_MetaBackend_Handler_SObj; - -using otp_devices_list_t = std::list; - -struct RGWSI_MBOTP_GetParams : public RGWSI_MetaBackend::GetParams { - otp_devices_list_t *pdevices{nullptr}; -}; - -struct RGWSI_MBOTP_PutParams : public RGWSI_MetaBackend::PutParams { - otp_devices_list_t devices; -}; - -using RGWSI_MBOTP_RemoveParams = RGWSI_MBSObj_RemoveParams; - -class RGWSI_MetaBackend_OTP : public RGWSI_MetaBackend_SObj -{ - RGWSI_Cls *cls_svc{nullptr}; - -public: - struct Context_OTP : public RGWSI_MetaBackend_SObj::Context_SObj { - otp_devices_list_t devices; - }; - - RGWSI_MetaBackend_OTP(CephContext *cct); - virtual ~RGWSI_MetaBackend_OTP(); - - RGWSI_MetaBackend::Type get_type() { - return MDBE_OTP; - } - - static std::string get_meta_key(const rgw_user& user); - - void init(RGWSI_SysObj *_sysobj_svc, - RGWSI_MDLog *_mdlog_svc, - RGWSI_Cls *_cls_svc) { - RGWSI_MetaBackend_SObj::init(_sysobj_svc, _mdlog_svc); - cls_svc = _cls_svc; - } - - RGWSI_MetaBackend_Handler *alloc_be_handler() override; - RGWSI_MetaBackend::Context *alloc_ctx() override; - - int call_with_get_params(ceph::real_time *pmtime, std::function cb) override; - - int get_entry(RGWSI_MetaBackend::Context *ctx, - const std::string& key, - RGWSI_MetaBackend::GetParams& _params, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp, - bool get_raw_attrs=false); - int put_entry(const DoutPrefixProvider *dpp, - RGWSI_MetaBackend::Context *ctx, - const std::string& key, - RGWSI_MetaBackend::PutParams& _params, - RGWObjVersionTracker *objv_tracker, - optional_yield y); -}; - - diff --git a/src/rgw/services/svc_meta_be_params.h b/src/rgw/services/svc_meta_be_params.h deleted file mode 100644 index 445f6e18819d2..0000000000000 --- a/src/rgw/services/svc_meta_be_params.h +++ /dev/null @@ -1,25 +0,0 @@ - - -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab ft=cpp - -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2019 Red Hat, Inc. - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - - -#pragma once - -#include - -struct RGWSI_MetaBackend_CtxParams_SObj {}; - -using RGWSI_MetaBackend_CtxParams = std::variant; diff --git a/src/rgw/services/svc_meta_be_sobj.cc b/src/rgw/services/svc_meta_be_sobj.cc deleted file mode 100644 index 45410c182384b..0000000000000 --- a/src/rgw/services/svc_meta_be_sobj.cc +++ /dev/null @@ -1,246 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab ft=cpp - -#include "svc_meta_be_sobj.h" -#include "svc_meta_be_params.h" -#include "svc_mdlog.h" - -#include "rgw_tools.h" -#include "rgw_metadata.h" -#include "rgw_mdlog.h" - -#define dout_subsys ceph_subsys_rgw - -using namespace std; - -RGWSI_MetaBackend_SObj::RGWSI_MetaBackend_SObj(CephContext *cct) : RGWSI_MetaBackend(cct) { -} - -RGWSI_MetaBackend_SObj::~RGWSI_MetaBackend_SObj() { -} - -RGWSI_MetaBackend_Handler *RGWSI_MetaBackend_SObj::alloc_be_handler() -{ - return new RGWSI_MetaBackend_Handler_SObj(this); -} - -RGWSI_MetaBackend::Context *RGWSI_MetaBackend_SObj::alloc_ctx() -{ - return new Context_SObj; -} - -int RGWSI_MetaBackend_SObj::pre_modify(const DoutPrefixProvider *dpp, RGWSI_MetaBackend::Context *_ctx, - const string& key, - RGWMetadataLogData& log_data, - RGWObjVersionTracker *objv_tracker, - RGWMDLogStatus op_type, - optional_yield y) -{ - auto ctx = static_cast(_ctx); - int ret = RGWSI_MetaBackend::pre_modify(dpp, ctx, key, log_data, - objv_tracker, op_type, - y); - if (ret < 0) { - return ret; - } - - /* if write version has not been set, and there's a read version, set it so that we can - * log it - */ - if (objv_tracker) { - log_data.read_version = objv_tracker->read_version; - log_data.write_version = objv_tracker->write_version; - } - - log_data.status = op_type; - - bufferlist logbl; - encode(log_data, logbl); - - ret = mdlog_svc->add_entry(dpp, ctx->module->get_hash_key(key), ctx->module->get_section(), key, logbl, y); - if (ret < 0) - return ret; - - return 0; -} - -int RGWSI_MetaBackend_SObj::post_modify(const DoutPrefixProvider *dpp, - RGWSI_MetaBackend::Context *_ctx, - const string& key, - RGWMetadataLogData& log_data, - RGWObjVersionTracker *objv_tracker, int ret, - optional_yield y) -{ - auto ctx = static_cast(_ctx); - if (ret >= 0) - log_data.status = MDLOG_STATUS_COMPLETE; - else - log_data.status = MDLOG_STATUS_ABORT; - - bufferlist logbl; - encode(log_data, logbl); - - int r = mdlog_svc->add_entry(dpp, ctx->module->get_hash_key(key), ctx->module->get_section(), key, logbl, y); - if (ret < 0) - return ret; - - if (r < 0) - return r; - - return RGWSI_MetaBackend::post_modify(dpp, ctx, key, log_data, objv_tracker, ret, y); -} - -int RGWSI_MetaBackend_SObj::get_shard_id(RGWSI_MetaBackend::Context *_ctx, - const std::string& key, - int *shard_id) -{ - auto ctx = static_cast(_ctx); - *shard_id = mdlog_svc->get_shard_id(ctx->module->get_hash_key(key), shard_id); - return 0; -} - -int RGWSI_MetaBackend_SObj::call(std::optional opt, - std::function f) -{ - RGWSI_MetaBackend_SObj::Context_SObj ctx; - return f(&ctx); -} - -void RGWSI_MetaBackend_SObj::Context_SObj::init(RGWSI_MetaBackend_Handler *h) -{ - RGWSI_MetaBackend_Handler_SObj *handler = static_cast(h); - module = handler->module; -} - -int RGWSI_MetaBackend_SObj::call_with_get_params(ceph::real_time *pmtime, std::function cb) -{ - bufferlist bl; - RGWSI_MBSObj_GetParams params; - params.pmtime = pmtime; - params.pbl = &bl; - return cb(params); -} - -int RGWSI_MetaBackend_SObj::get_entry(RGWSI_MetaBackend::Context *_ctx, - const string& key, - GetParams& _params, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp, - bool get_raw_attrs) -{ - RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast(_ctx); - RGWSI_MBSObj_GetParams& params = static_cast(_params); - - rgw_pool pool; - string oid; - ctx->module->get_pool_and_oid(key, &pool, &oid); - - int ret = 0; - ret = rgw_get_system_obj(sysobj_svc, pool, oid, *params.pbl, - objv_tracker, params.pmtime, - y, dpp, - params.pattrs, params.cache_info, - params.refresh_version, get_raw_attrs); - - return ret; -} - -int RGWSI_MetaBackend_SObj::put_entry(const DoutPrefixProvider *dpp, - RGWSI_MetaBackend::Context *_ctx, - const string& key, - PutParams& _params, - RGWObjVersionTracker *objv_tracker, - optional_yield y) -{ - RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast(_ctx); - RGWSI_MBSObj_PutParams& params = static_cast(_params); - - rgw_pool pool; - string oid; - ctx->module->get_pool_and_oid(key, &pool, &oid); - - return rgw_put_system_obj(dpp, sysobj_svc, pool, oid, params.bl, params.exclusive, - objv_tracker, params.mtime, y, params.pattrs); -} - -int RGWSI_MetaBackend_SObj::remove_entry(const DoutPrefixProvider *dpp, - RGWSI_MetaBackend::Context *_ctx, - const string& key, - RemoveParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y) -{ - RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast(_ctx); - - rgw_pool pool; - string oid; - ctx->module->get_pool_and_oid(key, &pool, &oid); - rgw_raw_obj k(pool, oid); - - auto sysobj = sysobj_svc->get_obj(k); - return sysobj.wop() - .set_objv_tracker(objv_tracker) - .remove(dpp, y); -} - -int RGWSI_MetaBackend_SObj::list_init(const DoutPrefixProvider *dpp, - RGWSI_MetaBackend::Context *_ctx, - const string& marker) -{ - RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast(_ctx); - - rgw_pool pool; - - string no_key; - ctx->module->get_pool_and_oid(no_key, &pool, nullptr); - - ctx->list.pool = sysobj_svc->get_pool(pool); - ctx->list.op.emplace(ctx->list.pool->op()); - - string prefix = ctx->module->get_oid_prefix(); - ctx->list.op->init(dpp, marker, prefix); - - return 0; -} - -int RGWSI_MetaBackend_SObj::list_next(const DoutPrefixProvider *dpp, - RGWSI_MetaBackend::Context *_ctx, - int max, list *keys, - bool *truncated) -{ - RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast(_ctx); - - vector oids; - - keys->clear(); - - int ret = ctx->list.op->get_next(dpp, max, &oids, truncated); - if (ret < 0 && ret != -ENOENT) - return ret; - if (ret == -ENOENT) { - if (truncated) - *truncated = false; - return 0; - } - - auto module = ctx->module; - - for (auto& o : oids) { - if (!module->is_valid_oid(o)) { - continue; - } - keys->emplace_back(module->oid_to_key(o)); - } - - return 0; -} - -int RGWSI_MetaBackend_SObj::list_get_marker(RGWSI_MetaBackend::Context *_ctx, - string *marker) -{ - RGWSI_MetaBackend_SObj::Context_SObj *ctx = static_cast(_ctx); - - return ctx->list.op->get_marker(marker); -} - diff --git a/src/rgw/services/svc_meta_be_sobj.h b/src/rgw/services/svc_meta_be_sobj.h deleted file mode 100644 index bf1ad1e68c740..0000000000000 --- a/src/rgw/services/svc_meta_be_sobj.h +++ /dev/null @@ -1,194 +0,0 @@ - - -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab ft=cpp - -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2019 Red Hat, Inc. - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - - -#pragma once - -#include "rgw_service.h" - -#include "svc_meta_be.h" -#include "svc_sys_obj.h" - - -class RGWSI_MBSObj_Handler_Module : public RGWSI_MetaBackend::Module { -protected: - std::string section; -public: - RGWSI_MBSObj_Handler_Module(const std::string& _section) : section(_section) {} - virtual void get_pool_and_oid(const std::string& key, rgw_pool *pool, std::string *oid) = 0; - virtual const std::string& get_oid_prefix() = 0; - virtual std::string key_to_oid(const std::string& key) = 0; - virtual bool is_valid_oid(const std::string& oid) = 0; - virtual std::string oid_to_key(const std::string& oid) = 0; - - const std::string& get_section() { - return section; - } - - /* key to use for hashing entries for log shard placement */ - virtual std::string get_hash_key(const std::string& key) { - return section + ":" + key; - } -}; - -struct RGWSI_MBSObj_GetParams : public RGWSI_MetaBackend::GetParams { - bufferlist *pbl{nullptr}; - std::map *pattrs{nullptr}; - rgw_cache_entry_info *cache_info{nullptr}; - boost::optional refresh_version; - - RGWSI_MBSObj_GetParams() {} - RGWSI_MBSObj_GetParams(bufferlist *_pbl, - std::map *_pattrs, - ceph::real_time *_pmtime) : RGWSI_MetaBackend::GetParams(_pmtime), - pbl(_pbl), - pattrs(_pattrs) {} - - RGWSI_MBSObj_GetParams& set_cache_info(rgw_cache_entry_info *_cache_info) { - cache_info = _cache_info; - return *this; - } - RGWSI_MBSObj_GetParams& set_refresh_version(boost::optional& _refresh_version) { - refresh_version = _refresh_version; - return *this; - } -}; - -struct RGWSI_MBSObj_PutParams : public RGWSI_MetaBackend::PutParams { - bufferlist bl; - const std::map *pattrs{nullptr}; - bool exclusive{false}; - - RGWSI_MBSObj_PutParams() {} - RGWSI_MBSObj_PutParams(const std::map *_pattrs, - const ceph::real_time& _mtime) : RGWSI_MetaBackend::PutParams(_mtime), - pattrs(_pattrs) {} - RGWSI_MBSObj_PutParams(bufferlist& _bl, - const std::map *_pattrs, - const ceph::real_time& _mtime, - bool _exclusive) : RGWSI_MetaBackend::PutParams(_mtime), - bl(_bl), - pattrs(_pattrs), - exclusive(_exclusive) {} -}; - -struct RGWSI_MBSObj_RemoveParams : public RGWSI_MetaBackend::RemoveParams { -}; - -class RGWSI_MetaBackend_SObj : public RGWSI_MetaBackend -{ -protected: - RGWSI_SysObj *sysobj_svc{nullptr}; - -public: - struct Context_SObj : public RGWSI_MetaBackend::Context { - RGWSI_MBSObj_Handler_Module *module{nullptr}; - struct _list { - std::optional pool; - std::optional op; - } list; - - void init(RGWSI_MetaBackend_Handler *h) override; - }; - - RGWSI_MetaBackend_SObj(CephContext *cct); - virtual ~RGWSI_MetaBackend_SObj(); - - RGWSI_MetaBackend::Type get_type() { - return MDBE_SOBJ; - } - - void init(RGWSI_SysObj *_sysobj_svc, - RGWSI_MDLog *_mdlog_svc) { - base_init(_mdlog_svc); - sysobj_svc = _sysobj_svc; - } - - RGWSI_MetaBackend_Handler *alloc_be_handler() override; - RGWSI_MetaBackend::Context *alloc_ctx() override; - - - int call_with_get_params(ceph::real_time *pmtime, std::function cb) override; - - int pre_modify(const DoutPrefixProvider *dpp, - RGWSI_MetaBackend::Context *ctx, - const std::string& key, - RGWMetadataLogData& log_data, - RGWObjVersionTracker *objv_tracker, - RGWMDLogStatus op_type, - optional_yield y); - int post_modify(const DoutPrefixProvider *dpp, - RGWSI_MetaBackend::Context *ctx, - const std::string& key, - RGWMetadataLogData& log_data, - RGWObjVersionTracker *objv_tracker, int ret, - optional_yield y); - - int get_entry(RGWSI_MetaBackend::Context *ctx, - const std::string& key, - RGWSI_MetaBackend::GetParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp, - bool get_raw_attrs=false) override; - int put_entry(const DoutPrefixProvider *dpp, - RGWSI_MetaBackend::Context *ctx, - const std::string& key, - RGWSI_MetaBackend::PutParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y) override; - int remove_entry(const DoutPrefixProvider *dpp, - RGWSI_MetaBackend::Context *ctx, - const std::string& key, - RGWSI_MetaBackend::RemoveParams& params, - RGWObjVersionTracker *objv_tracker, - optional_yield y) override; - - int list_init(const DoutPrefixProvider *dpp, RGWSI_MetaBackend::Context *_ctx, const std::string& marker) override; - int list_next(const DoutPrefixProvider *dpp, - RGWSI_MetaBackend::Context *_ctx, - int max, std::list *keys, - bool *truncated) override; - int list_get_marker(RGWSI_MetaBackend::Context *ctx, - std::string *marker) override; - - int get_shard_id(RGWSI_MetaBackend::Context *ctx, - const std::string& key, - int *shard_id) override; - - int call(std::optional opt, - std::function f) override; -}; - - -class RGWSI_MetaBackend_Handler_SObj : public RGWSI_MetaBackend_Handler { - friend class RGWSI_MetaBackend_SObj::Context_SObj; - - RGWSI_MBSObj_Handler_Module *module{nullptr}; - -public: - RGWSI_MetaBackend_Handler_SObj(RGWSI_MetaBackend *be) : - RGWSI_MetaBackend_Handler(be) {} - - void set_module(RGWSI_MBSObj_Handler_Module *_module) { - module = _module; - } - - RGWSI_MBSObj_Handler_Module *get_module() { - return module; - } -}; diff --git a/src/rgw/services/svc_meta_be_types.h b/src/rgw/services/svc_meta_be_types.h deleted file mode 100644 index 4a88a8e0b981f..0000000000000 --- a/src/rgw/services/svc_meta_be_types.h +++ /dev/null @@ -1,26 +0,0 @@ - -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab ft=cpp - -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2019 Red Hat, Inc. - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - -#pragma once - -enum RGWSI_META_BE_TYPES { - SOBJ = 1, - OTP = 2, - BUCKET = 3, - BI = 4, - USER = 5, -}; - diff --git a/src/rgw/services/svc_otp.cc b/src/rgw/services/svc_otp.cc deleted file mode 100644 index 81d8d57112eaa..0000000000000 --- a/src/rgw/services/svc_otp.cc +++ /dev/null @@ -1,186 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab ft=cpp - -#include "svc_otp.h" -#include "svc_zone.h" -#include "svc_meta.h" -#include "svc_meta_be_sobj.h" - -#include "rgw_zone.h" - -#define dout_subsys ceph_subsys_rgw - -using namespace std; - -class RGW_MB_Handler_Module_OTP : public RGWSI_MBSObj_Handler_Module { - RGWSI_Zone *zone_svc; - string prefix; -public: - RGW_MB_Handler_Module_OTP(RGWSI_Zone *_zone_svc) : RGWSI_MBSObj_Handler_Module("otp"), - zone_svc(_zone_svc) {} - - void get_pool_and_oid(const string& key, rgw_pool *pool, string *oid) override { - if (pool) { - *pool = zone_svc->get_zone_params().otp_pool; - } - - if (oid) { - *oid = key; - } - } - - const string& get_oid_prefix() override { - return prefix; - } - - bool is_valid_oid(const string& oid) override { - return true; - } - - string key_to_oid(const string& key) override { - return key; - } - - string oid_to_key(const string& oid) override { - return oid; - } -}; - -RGWSI_OTP::RGWSI_OTP(CephContext *cct): RGWServiceInstance(cct) { -} - -RGWSI_OTP::~RGWSI_OTP() { -} - -void RGWSI_OTP::init(RGWSI_Zone *_zone_svc, - RGWSI_Meta *_meta_svc, - RGWSI_MetaBackend *_meta_be_svc) -{ - svc.otp = this; - svc.zone = _zone_svc; - svc.meta = _meta_svc; - svc.meta_be = _meta_be_svc; -} - -int RGWSI_OTP::do_start(optional_yield, const DoutPrefixProvider *dpp) -{ - /* create first backend handler for bucket entrypoints */ - - RGWSI_MetaBackend_Handler *_otp_be_handler; - - int r = svc.meta->create_be_handler(RGWSI_MetaBackend::Type::MDBE_OTP, &_otp_be_handler); - if (r < 0) { - ldout(ctx(), 0) << "ERROR: failed to create be handler: r=" << r << dendl; - return r; - } - - be_handler = _otp_be_handler; - - RGWSI_MetaBackend_Handler_OTP *otp_be_handler = static_cast(_otp_be_handler); - - auto otp_be_module = new RGW_MB_Handler_Module_OTP(svc.zone); - be_module.reset(otp_be_module); - otp_be_handler->set_module(otp_be_module); - - return 0; -} - -int RGWSI_OTP::read_all(RGWSI_OTP_BE_Ctx& ctx, - const string& key, - otp_devices_list_t *devices, - real_time *pmtime, - RGWObjVersionTracker *objv_tracker, - optional_yield y, const DoutPrefixProvider *dpp) -{ - RGWSI_MBOTP_GetParams params; - params.pdevices = devices; - params.pmtime = pmtime; - - int ret = svc.meta_be->get_entry(ctx.get(), key, params, objv_tracker, y, dpp); - if (ret < 0) { - return ret; - } - - return 0; -} - -int RGWSI_OTP::read_all(RGWSI_OTP_BE_Ctx& ctx, - const rgw_user& uid, - otp_devices_list_t *devices, - real_time *pmtime, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - return read_all(ctx, - uid.to_str(), - devices, - pmtime, - objv_tracker, - y, - dpp); -} - -int RGWSI_OTP::store_all(const DoutPrefixProvider *dpp, - RGWSI_OTP_BE_Ctx& ctx, - const string& key, - const otp_devices_list_t& devices, - real_time mtime, - RGWObjVersionTracker *objv_tracker, - optional_yield y) -{ - RGWSI_MBOTP_PutParams params; - params.mtime = mtime; - params.devices = devices; - - int ret = svc.meta_be->put_entry(dpp, ctx.get(), key, params, objv_tracker, y); - if (ret < 0) { - return ret; - } - - return 0; -} - -int RGWSI_OTP::store_all(const DoutPrefixProvider *dpp, - RGWSI_OTP_BE_Ctx& ctx, - const rgw_user& uid, - const otp_devices_list_t& devices, - real_time mtime, - RGWObjVersionTracker *objv_tracker, - optional_yield y) -{ - return store_all(dpp, ctx, - uid.to_str(), - devices, - mtime, - objv_tracker, - y); -} - -int RGWSI_OTP::remove_all(const DoutPrefixProvider *dpp, - RGWSI_OTP_BE_Ctx& ctx, - const string& key, - RGWObjVersionTracker *objv_tracker, - optional_yield y) -{ - RGWSI_MBOTP_RemoveParams params; - - int ret = svc.meta_be->remove_entry(dpp, ctx.get(), key, params, objv_tracker, y); - if (ret < 0) { - return ret; - } - - return 0; -} - -int RGWSI_OTP::remove_all(const DoutPrefixProvider *dpp, - RGWSI_OTP_BE_Ctx& ctx, - const rgw_user& uid, - RGWObjVersionTracker *objv_tracker, - optional_yield y) -{ - return remove_all(dpp,ctx, - uid.to_str(), - objv_tracker, - y); -} diff --git a/src/rgw/services/svc_otp.h b/src/rgw/services/svc_otp.h deleted file mode 100644 index e639c2c923e92..0000000000000 --- a/src/rgw/services/svc_otp.h +++ /dev/null @@ -1,95 +0,0 @@ - -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab ft=cpp - -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2019 Red Hat, Inc. - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - - -#pragma once - -#include "cls/otp/cls_otp_types.h" - -#include "rgw_service.h" - -#include "svc_otp_types.h" -#include "svc_meta_be_otp.h" - -class RGWSI_Zone; - -class RGWSI_OTP : public RGWServiceInstance -{ - RGWSI_OTP_BE_Handler be_handler; - std::unique_ptr be_module; - - int do_start(optional_yield, const DoutPrefixProvider *dpp) override; - -public: - struct Svc { - RGWSI_OTP *otp{nullptr}; - RGWSI_Zone *zone{nullptr}; - RGWSI_Meta *meta{nullptr}; - RGWSI_MetaBackend *meta_be{nullptr}; - } svc; - - RGWSI_OTP(CephContext *cct); - ~RGWSI_OTP(); - - RGWSI_OTP_BE_Handler& get_be_handler() { - return be_handler; - } - - void init(RGWSI_Zone *_zone_svc, - RGWSI_Meta *_meta_svc, - RGWSI_MetaBackend *_meta_be_svc); - - int read_all(RGWSI_OTP_BE_Ctx& ctx, - const std::string& key, - otp_devices_list_t *devices, - real_time *pmtime, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp); - int read_all(RGWSI_OTP_BE_Ctx& ctx, - const rgw_user& uid, - otp_devices_list_t *devices, - real_time *pmtime, - RGWObjVersionTracker *objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp); - int store_all(const DoutPrefixProvider *dpp, - RGWSI_OTP_BE_Ctx& ctx, - const std::string& key, - const otp_devices_list_t& devices, - real_time mtime, - RGWObjVersionTracker *objv_tracker, - optional_yield y); - int store_all(const DoutPrefixProvider *dpp, - RGWSI_OTP_BE_Ctx& ctx, - const rgw_user& uid, - const otp_devices_list_t& devices, - real_time mtime, - RGWObjVersionTracker *objv_tracker, - optional_yield y); - int remove_all(const DoutPrefixProvider *dpp, - RGWSI_OTP_BE_Ctx& ctx, - const std::string& key, - RGWObjVersionTracker *objv_tracker, - optional_yield y); - int remove_all(const DoutPrefixProvider *dpp, - RGWSI_OTP_BE_Ctx& ctx, - const rgw_user& uid, - RGWObjVersionTracker *objv_tracker, - optional_yield y); -}; - - diff --git a/src/rgw/services/svc_otp_types.h b/src/rgw/services/svc_otp_types.h deleted file mode 100644 index 60e2a79d62a3d..0000000000000 --- a/src/rgw/services/svc_otp_types.h +++ /dev/null @@ -1,29 +0,0 @@ - -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab ft=cpp - -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2019 Red Hat, Inc. - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - - -#pragma once - -#include "common/ptr_wrapper.h" - -#include "svc_meta_be.h" -#include "svc_meta_be_types.h" - -class RGWSI_MetaBackend_Handler; - -using RGWSI_OTP_BE_Handler = ptr_wrapper; -using RGWSI_OTP_BE_Ctx = ptr_wrapper; - diff --git a/src/rgw/services/svc_role_rados.cc b/src/rgw/services/svc_role_rados.cc deleted file mode 100644 index a840224978b34..0000000000000 --- a/src/rgw/services/svc_role_rados.cc +++ /dev/null @@ -1,82 +0,0 @@ -#include "svc_role_rados.h" -#include "svc_meta_be_sobj.h" -#include "svc_meta.h" -#include "rgw_role.h" -#include "rgw_zone.h" -#include "svc_zone.h" -#include "rgw_tools.h" - -#define dout_subsys ceph_subsys_rgw - -class RGWSI_Role_Module : public RGWSI_MBSObj_Handler_Module { - RGWSI_Role_RADOS::Svc& svc; - const std::string prefix; -public: - RGWSI_Role_Module(RGWSI_Role_RADOS::Svc& _svc): RGWSI_MBSObj_Handler_Module("roles"), - svc(_svc), - prefix(role_oid_prefix) {} - - void get_pool_and_oid(const std::string& key, - rgw_pool *pool, - std::string *oid) override - { - if (pool) { - *pool = svc.zone->get_zone_params().roles_pool; - } - - if (oid) { - *oid = key_to_oid(key); - } - } - - bool is_valid_oid(const std::string& oid) override { - return boost::algorithm::starts_with(oid, prefix); - } - - std::string key_to_oid(const std::string& key) override { - return prefix + key; - } - - // This is called after `is_valid_oid` and is assumed to be a valid oid - std::string oid_to_key(const std::string& oid) override { - return oid.substr(prefix.size()); - } - - const std::string& get_oid_prefix() { - return prefix; - } -}; - -RGWSI_MetaBackend_Handler* RGWSI_Role_RADOS::get_be_handler() -{ - return be_handler; -} - -void RGWSI_Role_RADOS::init(RGWSI_Zone *_zone_svc, - RGWSI_Meta *_meta_svc, - RGWSI_MetaBackend *_meta_be_svc, - RGWSI_SysObj *_sysobj_svc) -{ - svc.zone = _zone_svc; - svc.meta = _meta_svc; - svc.meta_be = _meta_be_svc; - svc.sysobj = _sysobj_svc; -} - -int RGWSI_Role_RADOS::do_start(optional_yield y, const DoutPrefixProvider *dpp) -{ - - int r = svc.meta->create_be_handler(RGWSI_MetaBackend::Type::MDBE_SOBJ, - &be_handler); - if (r < 0) { - ldout(ctx(), 0) << "ERROR: failed to create be_handler for Roles: r=" - << r <(be_handler); - be_module.reset(module); - bh->set_module(module); - return 0; -} diff --git a/src/rgw/services/svc_role_rados.h b/src/rgw/services/svc_role_rados.h deleted file mode 100644 index d4d3530c278c3..0000000000000 --- a/src/rgw/services/svc_role_rados.h +++ /dev/null @@ -1,50 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab ft=cpp - -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2020 SUSE LLC - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - -#pragma once - -#include "rgw_service.h" -#include "rgw_role.h" -#include "svc_meta_be.h" - -class RGWSI_Role_RADOS: public RGWServiceInstance -{ - public: - struct Svc { - RGWSI_Zone *zone{nullptr}; - RGWSI_Meta *meta{nullptr}; - RGWSI_MetaBackend *meta_be{nullptr}; - RGWSI_SysObj *sysobj{nullptr}; - } svc; - - RGWSI_Role_RADOS(CephContext *cct) : RGWServiceInstance(cct) {} - ~RGWSI_Role_RADOS() {} - - void init(RGWSI_Zone *_zone_svc, - RGWSI_Meta *_meta_svc, - RGWSI_MetaBackend *_meta_be_svc, - RGWSI_SysObj *_sysobj_svc); - - RGWSI_MetaBackend_Handler * get_be_handler(); - int do_start(optional_yield y, const DoutPrefixProvider *dpp) override; - -private: - RGWSI_MetaBackend_Handler *be_handler; - std::unique_ptr be_module; -}; - -static const std::string role_name_oid_prefix = "role_names."; -static const std::string role_oid_prefix = "roles."; -static const std::string role_path_oid_prefix = "role_paths."; diff --git a/src/rgw/services/svc_user.h b/src/rgw/services/svc_user.h index 7149f3e21979f..64c0259956f3f 100644 --- a/src/rgw/services/svc_user.h +++ b/src/rgw/services/svc_user.h @@ -17,11 +17,11 @@ #pragma once -#include "svc_meta_be.h" - +#include #include "rgw_service.h" #include "rgw_sal_fwd.h" +class RGWMetadataLister; struct RGWUID; class RGWSI_User : public RGWServiceInstance @@ -38,14 +38,15 @@ class RGWSI_User : public RGWServiceInstance return rgw_user(key); } - virtual RGWSI_MetaBackend_Handler *get_be_handler() = 0; - /* base svc_user interfaces */ virtual rgw_raw_obj get_buckets_obj(const rgw_user& user_id) const = 0; - virtual int read_user_info(RGWSI_MetaBackend::Context *ctx, - const rgw_user& user, + virtual int create_lister(const DoutPrefixProvider* dpp, + const std::string& marker, + std::unique_ptr& lister) = 0; + + virtual int read_user_info(const rgw_user& user, RGWUserInfo *info, RGWObjVersionTracker * const objv_tracker, real_time * const pmtime, @@ -54,8 +55,7 @@ class RGWSI_User : public RGWServiceInstance optional_yield y, const DoutPrefixProvider *dpp) = 0; - virtual int store_user_info(RGWSI_MetaBackend::Context *ctx, - const RGWUserInfo& info, + virtual int store_user_info(const RGWUserInfo& info, RGWUserInfo *old_info, RGWObjVersionTracker *objv_tracker, const real_time& mtime, @@ -64,29 +64,25 @@ class RGWSI_User : public RGWServiceInstance optional_yield y, const DoutPrefixProvider *dpp) = 0; - virtual int remove_user_info(RGWSI_MetaBackend::Context *ctx, - const RGWUserInfo& info, + virtual int remove_user_info(const RGWUserInfo& info, RGWObjVersionTracker *objv_tracker, optional_yield y, const DoutPrefixProvider *dpp) = 0; - virtual int get_user_info_by_email(RGWSI_MetaBackend::Context *ctx, - const std::string& email, RGWUserInfo *info, + virtual int get_user_info_by_email(const std::string& email, RGWUserInfo *info, RGWObjVersionTracker *objv_tracker, std::map* pattrs, real_time *pmtime, optional_yield y, const DoutPrefixProvider *dpp) = 0; - virtual int get_user_info_by_swift(RGWSI_MetaBackend::Context *ctx, - const std::string& swift_name, + virtual int get_user_info_by_swift(const std::string& swift_name, RGWUserInfo *info, /* out */ RGWObjVersionTracker * const objv_tracker, std::map* pattrs, real_time * const pmtime, optional_yield y, const DoutPrefixProvider *dpp) = 0; - virtual int get_user_info_by_access_key(RGWSI_MetaBackend::Context *ctx, - const std::string& access_key, + virtual int get_user_info_by_access_key(const std::string& access_key, RGWUserInfo *info, RGWObjVersionTracker* objv_tracker, std::map* pattrs, diff --git a/src/rgw/services/svc_user_rados.cc b/src/rgw/services/svc_user_rados.cc index a7cdc08185e32..a77f1168b64bf 100644 --- a/src/rgw/services/svc_user_rados.cc +++ b/src/rgw/services/svc_user_rados.cc @@ -5,16 +5,15 @@ #include "svc_user.h" #include "svc_user_rados.h" +#include "svc_mdlog.h" #include "svc_zone.h" #include "svc_sys_obj.h" #include "svc_sys_obj_cache.h" -#include "svc_meta.h" -#include "svc_meta_be_sobj.h" -#include "svc_sync_modules.h" #include "rgw_user.h" #include "rgw_account.h" #include "rgw_bucket.h" +#include "rgw_metadata_lister.h" #include "rgw_tools.h" #include "rgw_zone.h" #include "rgw_rados.h" @@ -30,41 +29,6 @@ using namespace std; -class RGWSI_User_Module : public RGWSI_MBSObj_Handler_Module { - RGWSI_User_RADOS::Svc& svc; - - const string prefix; -public: - RGWSI_User_Module(RGWSI_User_RADOS::Svc& _svc) : RGWSI_MBSObj_Handler_Module("user"), - svc(_svc) {} - - void get_pool_and_oid(const string& key, rgw_pool *pool, string *oid) override { - if (pool) { - *pool = svc.zone->get_zone_params().user_uid_pool; - } - if (oid) { - *oid = key; - } - } - - const string& get_oid_prefix() override { - return prefix; - } - - bool is_valid_oid(const string& oid) override { - // filter out the user.buckets objects - return !boost::algorithm::ends_with(oid, RGW_BUCKETS_OBJ_SUFFIX); - } - - string key_to_oid(const string& key) override { - return key; - } - - string oid_to_key(const string& oid) override { - return oid; - } -}; - RGWSI_User_RADOS::RGWSI_User_RADOS(CephContext *cct): RGWSI_User(cct) { } @@ -72,37 +36,23 @@ RGWSI_User_RADOS::~RGWSI_User_RADOS() { } void RGWSI_User_RADOS::init(librados::Rados* rados_, - RGWSI_Zone *_zone_svc, RGWSI_SysObj *_sysobj_svc, - RGWSI_SysObj_Cache *_cache_svc, RGWSI_Meta *_meta_svc, - RGWSI_MetaBackend *_meta_be_svc, - RGWSI_SyncModules *_sync_modules_svc) + RGWSI_Zone *_zone_svc, + RGWSI_MDLog *mdlog_svc, + RGWSI_SysObj *_sysobj_svc, + RGWSI_SysObj_Cache *_cache_svc) { svc.user = this; rados = rados_; svc.zone = _zone_svc; + svc.mdlog = mdlog_svc; svc.sysobj = _sysobj_svc; svc.cache = _cache_svc; - svc.meta = _meta_svc; - svc.meta_be = _meta_be_svc; - svc.sync_modules = _sync_modules_svc; } int RGWSI_User_RADOS::do_start(optional_yield, const DoutPrefixProvider *dpp) { uinfo_cache.reset(new RGWChainedCacheImpl); uinfo_cache->init(svc.cache); - - int r = svc.meta->create_be_handler(RGWSI_MetaBackend::Type::MDBE_SOBJ, &be_handler); - if (r < 0) { - ldpp_dout(dpp, 0) << "ERROR: failed to create be handler: r=" << r << dendl; - return r; - } - - RGWSI_MetaBackend_Handler_SObj *bh = static_cast(be_handler); - - auto module = new RGWSI_User_Module(svc); - be_module.reset(module); - bh->set_module(module); return 0; } @@ -112,8 +62,39 @@ rgw_raw_obj RGWSI_User_RADOS::get_buckets_obj(const rgw_user& user) const return rgw_raw_obj(svc.zone->get_zone_params().user_uid_pool, oid); } -int RGWSI_User_RADOS::read_user_info(RGWSI_MetaBackend::Context *ctx, - const rgw_user& user, +class UserLister : public RGWMetadataLister { + public: + using RGWMetadataLister::RGWMetadataLister; + + void filter_transform(std::vector& oids, + std::list& keys) override + { + // filter out the user.buckets objects + constexpr auto filter = [] (const std::string& oid) { + return oid.ends_with(RGW_BUCKETS_OBJ_SUFFIX); + }; + // 'oids' is mutable so we can move its elements instead of copying + std::remove_copy_if(std::make_move_iterator(oids.begin()), + std::make_move_iterator(oids.end()), + std::back_inserter(keys), filter); + } +}; + +int RGWSI_User_RADOS::create_lister(const DoutPrefixProvider* dpp, + const std::string& marker, + std::unique_ptr& lister) +{ + const rgw_pool& pool = svc.zone->get_zone_params().user_uid_pool; + auto p = std::make_unique(svc.sysobj->get_pool(pool)); + int r = p->init(dpp, marker, ""); // empty prefix + if (r < 0) { + return r; + } + lister = std::move(p); + return 0; +} + +int RGWSI_User_RADOS::read_user_info(const rgw_user& user, RGWUserInfo *info, RGWObjVersionTracker * const objv_tracker, real_time * const pmtime, @@ -129,10 +110,11 @@ int RGWSI_User_RADOS::read_user_info(RGWSI_MetaBackend::Context *ctx, bufferlist bl; RGWUID user_id; - RGWSI_MBSObj_GetParams params(&bl, pattrs, pmtime); - params.set_cache_info(cache_info); - - int ret = svc.meta_be->get_entry(ctx, get_meta_key(user), params, objv_tracker, y, dpp); + const rgw_pool& pool = svc.zone->get_zone_params().user_uid_pool; + const std::string key = get_meta_key(user); + int ret = rgw_get_system_obj(svc.sysobj, pool, key, bl, + objv_tracker, pmtime, y, dpp, + pattrs, cache_info); if (ret < 0) { return ret; } @@ -190,7 +172,6 @@ class PutOperation { RGWSI_User_RADOS::Svc& svc; librados::Rados& rados; - RGWSI_MetaBackend_SObj::Context_SObj *ctx; RGWUID ui; const RGWUserInfo& info; RGWUserInfo *old_info; @@ -211,7 +192,6 @@ class PutOperation public: PutOperation(RGWSI_User_RADOS::Svc& svc, librados::Rados& rados, - RGWSI_MetaBackend::Context *_ctx, const RGWUserInfo& info, RGWUserInfo *old_info, RGWObjVersionTracker *objv_tracker, @@ -222,7 +202,6 @@ class PutOperation svc(svc), rados(rados), info(info), old_info(old_info), objv_tracker(objv_tracker), mtime(mtime), exclusive(exclusive), pattrs(pattrs), y(y) { - ctx = static_cast(_ctx); ui.id = info.user_id.to_str(); } @@ -233,7 +212,7 @@ class PutOperation if (ot.write_version.tag.empty()) { if (ot.read_version.tag.empty()) { - ot.generate_new_write_ver(svc.meta_be->ctx()); + ot.generate_new_write_ver(dpp->get_cct()); } else { ot.write_version = ot.read_version; ot.write_version.ver++; @@ -245,7 +224,7 @@ class PutOperation continue; /* check if swift mapping exists */ RGWUserInfo inf; - int r = svc.user->get_user_info_by_swift(ctx, id, &inf, nullptr, nullptr, nullptr, y, dpp); + int r = svc.user->get_user_info_by_swift(id, &inf, nullptr, nullptr, nullptr, y, dpp); if (r >= 0 && inf.user_id != info.user_id && (!old_info || inf.user_id != old_info->user_id)) { ldpp_dout(dpp, 0) << "WARNING: can't store user info, swift id (" << id @@ -261,7 +240,7 @@ class PutOperation if (s3_key_active(old_info, id)) // old key already active continue; RGWUserInfo inf; - int r = svc.user->get_user_info_by_access_key(ctx, id, &inf, nullptr, nullptr, nullptr, y, dpp); + int r = svc.user->get_user_info_by_access_key(id, &inf, nullptr, nullptr, nullptr, y, dpp); if (r >= 0 && inf.user_id != info.user_id && (!old_info || inf.user_id != old_info->user_id)) { ldpp_dout(dpp, 0) << "WARNING: can't store user info, access key already mapped to another user" << dendl; @@ -297,13 +276,14 @@ class PutOperation encode(ui, data_bl); encode(info, data_bl); - RGWSI_MBSObj_PutParams params(data_bl, pattrs, mtime, exclusive); - - int ret = svc.meta_be->put(ctx, RGWSI_User::get_meta_key(info.user_id), params, &ot, y, dpp); - if (ret < 0) - return ret; - - return 0; + const rgw_pool& pool = svc.zone->get_zone_params().user_uid_pool; + const std::string key = RGWSI_User::get_meta_key(info.user_id); + int r = rgw_put_system_obj(dpp, svc.sysobj, pool, key, data_bl, + exclusive, &ot, mtime, y, pattrs); + if (r < 0) { + return r; + } + return svc.mdlog->complete_entry(dpp, y, "user", key, &ot); } int complete(const DoutPrefixProvider *dpp) { @@ -405,7 +385,7 @@ class PutOperation ldpp_dout(dpp, 0) << "ERROR: tenant mismatch: " << old_info.user_id.tenant << " != " << new_info.user_id.tenant << dendl; return -EINVAL; } - ret = svc.user->remove_uid_index(ctx, old_info, nullptr, y, dpp); + ret = svc.user->remove_uid_index(old_info, nullptr, y, dpp); if (ret < 0 && ret != -ENOENT) { set_err_msg("ERROR: could not remove index for uid " + old_info.user_id.to_str()); return ret; @@ -475,8 +455,7 @@ class PutOperation } }; -int RGWSI_User_RADOS::store_user_info(RGWSI_MetaBackend::Context *ctx, - const RGWUserInfo& info, +int RGWSI_User_RADOS::store_user_info(const RGWUserInfo& info, RGWUserInfo *old_info, RGWObjVersionTracker *objv_tracker, const real_time& mtime, @@ -485,12 +464,8 @@ int RGWSI_User_RADOS::store_user_info(RGWSI_MetaBackend::Context *ctx, optional_yield y, const DoutPrefixProvider *dpp) { - PutOperation op(svc, *rados, ctx, - info, old_info, - objv_tracker, - mtime, exclusive, - attrs, - y); + PutOperation op(svc, *rados, info, old_info, objv_tracker, + mtime, exclusive, attrs, y); int r = op.prepare(dpp); if (r < 0) { @@ -548,8 +523,7 @@ int RGWSI_User_RADOS::remove_swift_name_index(const DoutPrefixProvider *dpp, * from the user and user email pools. This leaves the pools * themselves alone, as well as any ACLs embedded in object xattrs. */ -int RGWSI_User_RADOS::remove_user_info(RGWSI_MetaBackend::Context *ctx, - const RGWUserInfo& info, +int RGWSI_User_RADOS::remove_user_info(const RGWUserInfo& info, RGWObjVersionTracker *objv_tracker, optional_yield y, const DoutPrefixProvider *dpp) @@ -621,7 +595,7 @@ int RGWSI_User_RADOS::remove_user_info(RGWSI_MetaBackend::Context *ctx, } } - ret = remove_uid_index(ctx, info, objv_tracker, y, dpp); + ret = remove_uid_index(info, objv_tracker, y, dpp); if (ret < 0 && ret != -ENOENT) { return ret; } @@ -629,22 +603,24 @@ int RGWSI_User_RADOS::remove_user_info(RGWSI_MetaBackend::Context *ctx, return 0; } -int RGWSI_User_RADOS::remove_uid_index(RGWSI_MetaBackend::Context *ctx, const RGWUserInfo& user_info, RGWObjVersionTracker *objv_tracker, +int RGWSI_User_RADOS::remove_uid_index(const RGWUserInfo& user_info, RGWObjVersionTracker *objv_tracker, optional_yield y, const DoutPrefixProvider *dpp) { ldpp_dout(dpp, 10) << "removing user index: " << user_info.user_id << dendl; - RGWSI_MBSObj_RemoveParams params; - int ret = svc.meta_be->remove(ctx, get_meta_key(user_info.user_id), params, objv_tracker, y, dpp); - if (ret < 0 && ret != -ENOENT && ret != -ECANCELED) { - string key; - user_info.user_id.to_str(key); - rgw_raw_obj uid_obj(svc.zone->get_zone_params().user_uid_pool, key); - ldpp_dout(dpp, 0) << "ERROR: could not remove " << user_info.user_id << ":" << uid_obj << ", should be fixed (err=" << ret << ")" << dendl; + const rgw_pool& pool = svc.zone->get_zone_params().user_uid_pool; + const std::string key = get_meta_key(user_info.user_id); + int ret = rgw_delete_system_obj(dpp, svc.sysobj, pool, key, objv_tracker, y); + if (ret == -ENOENT || ret == -ECANCELED) { + return 0; // success but no mdlog entry + } + if (ret < 0) { + ldpp_dout(dpp, 0) << "ERROR: could not remove " << user_info.user_id + << ": " << cpp_strerror(ret) << dendl; return ret; } - return 0; + return svc.mdlog->complete_entry(dpp, y, "user", key, objv_tracker); } static int read_index(const DoutPrefixProvider* dpp, optional_yield y, @@ -667,8 +643,7 @@ static int read_index(const DoutPrefixProvider* dpp, optional_yield y, return 0; } -int RGWSI_User_RADOS::get_user_info_from_index(RGWSI_MetaBackend::Context* ctx, - const string& key, +int RGWSI_User_RADOS::get_user_info_from_index(const string& key, const rgw_pool& pool, RGWUserInfo *info, RGWObjVersionTracker* objv_tracker, @@ -703,7 +678,7 @@ int RGWSI_User_RADOS::get_user_info_from_index(RGWSI_MetaBackend::Context* ctx, } rgw_cache_entry_info cache_info; - ret = read_user_info(ctx, rgw_user{uid.id}, &e.info, &e.objv_tracker, + ret = read_user_info(rgw_user{uid.id}, &e.info, &e.objv_tracker, nullptr, &cache_info, &e.attrs, y, dpp); if (ret < 0) { return ret; @@ -727,8 +702,7 @@ int RGWSI_User_RADOS::get_user_info_from_index(RGWSI_MetaBackend::Context* ctx, * Given an email, finds the user info associated with it. * returns: 0 on success, -ERR# on failure (including nonexistence) */ -int RGWSI_User_RADOS::get_user_info_by_email(RGWSI_MetaBackend::Context *ctx, - const string& email, RGWUserInfo *info, +int RGWSI_User_RADOS::get_user_info_by_email(const string& email, RGWUserInfo *info, RGWObjVersionTracker *objv_tracker, std::map* pattrs, real_time *pmtime, optional_yield y, @@ -736,7 +710,7 @@ int RGWSI_User_RADOS::get_user_info_by_email(RGWSI_MetaBackend::Context *ctx, { std::string oid = email; boost::to_lower(oid); - return get_user_info_from_index(ctx, oid, svc.zone->get_zone_params().user_email_pool, + return get_user_info_from_index(oid, svc.zone->get_zone_params().user_email_pool, info, objv_tracker, pattrs, pmtime, y, dpp); } @@ -744,16 +718,14 @@ int RGWSI_User_RADOS::get_user_info_by_email(RGWSI_MetaBackend::Context *ctx, * Given an swift username, finds the user_info associated with it. * returns: 0 on success, -ERR# on failure (including nonexistence) */ -int RGWSI_User_RADOS::get_user_info_by_swift(RGWSI_MetaBackend::Context *ctx, - const string& swift_name, +int RGWSI_User_RADOS::get_user_info_by_swift(const string& swift_name, RGWUserInfo *info, /* out */ RGWObjVersionTracker * const objv_tracker, std::map* pattrs, real_time * const pmtime, optional_yield y, const DoutPrefixProvider *dpp) { - return get_user_info_from_index(ctx, - swift_name, + return get_user_info_from_index(swift_name, svc.zone->get_zone_params().user_swift_pool, info, objv_tracker, pattrs, pmtime, y, dpp); } @@ -762,16 +734,14 @@ int RGWSI_User_RADOS::get_user_info_by_swift(RGWSI_MetaBackend::Context *ctx, * Given an access key, finds the user info associated with it. * returns: 0 on success, -ERR# on failure (including nonexistence) */ -int RGWSI_User_RADOS::get_user_info_by_access_key(RGWSI_MetaBackend::Context *ctx, - const std::string& access_key, +int RGWSI_User_RADOS::get_user_info_by_access_key(const std::string& access_key, RGWUserInfo *info, RGWObjVersionTracker* objv_tracker, std::map* pattrs, real_time *pmtime, optional_yield y, const DoutPrefixProvider *dpp) { - return get_user_info_from_index(ctx, - access_key, + return get_user_info_from_index(access_key, svc.zone->get_zone_params().user_keys_pool, info, objv_tracker, pattrs, pmtime, y, dpp); } diff --git a/src/rgw/services/svc_user_rados.h b/src/rgw/services/svc_user_rados.h index 406024e6fa891..db2e2042bd460 100644 --- a/src/rgw/services/svc_user_rados.h +++ b/src/rgw/services/svc_user_rados.h @@ -18,17 +18,15 @@ #include "rgw_service.h" -#include "svc_meta_be.h" #include "svc_user.h" #include "driver/rados/rgw_bucket.h" // FIXME: subclass dependency +class RGWSI_MDLog; class RGWSI_Zone; class RGWSI_SysObj; class RGWSI_SysObj_Cache; -class RGWSI_Meta; class RGWSI_SyncModules; -class RGWSI_MetaBackend_Handler; struct rgw_cache_entry_info; @@ -41,9 +39,6 @@ class RGWSI_User_RADOS : public RGWSI_User { friend class PutOperation; - std::unique_ptr be_module; - RGWSI_MetaBackend_Handler *be_handler; - struct user_info_cache_entry { RGWUserInfo info; RGWObjVersionTracker objv_tracker; @@ -56,8 +51,7 @@ class RGWSI_User_RADOS : public RGWSI_User rgw_raw_obj get_buckets_obj(const rgw_user& user_id) const override; - int get_user_info_from_index(RGWSI_MetaBackend::Context *ctx, - const std::string& key, + int get_user_info_from_index(const std::string& key, const rgw_pool& pool, RGWUserInfo *info, RGWObjVersionTracker * const objv_tracker, @@ -66,7 +60,7 @@ class RGWSI_User_RADOS : public RGWSI_User optional_yield y, const DoutPrefixProvider *dpp); - int remove_uid_index(RGWSI_MetaBackend::Context *ctx, const RGWUserInfo& user_info, RGWObjVersionTracker *objv_tracker, + int remove_uid_index(const RGWUserInfo& user_info, RGWObjVersionTracker *objv_tracker, optional_yield y, const DoutPrefixProvider *dpp); int remove_key_index(const DoutPrefixProvider *dpp, const RGWAccessKey& access_key, optional_yield y); @@ -80,28 +74,25 @@ class RGWSI_User_RADOS : public RGWSI_User struct Svc { RGWSI_User_RADOS *user{nullptr}; RGWSI_Zone *zone{nullptr}; + RGWSI_MDLog *mdlog{nullptr}; RGWSI_SysObj *sysobj{nullptr}; RGWSI_SysObj_Cache *cache{nullptr}; - RGWSI_Meta *meta{nullptr}; - RGWSI_MetaBackend *meta_be{nullptr}; - RGWSI_SyncModules *sync_modules{nullptr}; } svc; RGWSI_User_RADOS(CephContext *cct); ~RGWSI_User_RADOS(); void init(librados::Rados* rados_, - RGWSI_Zone *_zone_svc, RGWSI_SysObj *_sysobj_svc, - RGWSI_SysObj_Cache *_cache_svc, RGWSI_Meta *_meta_svc, - RGWSI_MetaBackend *_meta_be_svc, - RGWSI_SyncModules *_sync_modules); + RGWSI_Zone *_zone_svc, + RGWSI_MDLog *mdlog_svc, + RGWSI_SysObj *_sysobj_svc, + RGWSI_SysObj_Cache *_cache_svc); - RGWSI_MetaBackend_Handler *get_be_handler() override { - return be_handler; - } + int create_lister(const DoutPrefixProvider* dpp, + const std::string& marker, + std::unique_ptr& lister) override; - int read_user_info(RGWSI_MetaBackend::Context *ctx, - const rgw_user& user, + int read_user_info(const rgw_user& user, RGWUserInfo *info, RGWObjVersionTracker * const objv_tracker, real_time * const pmtime, @@ -110,8 +101,7 @@ class RGWSI_User_RADOS : public RGWSI_User optional_yield y, const DoutPrefixProvider *dpp) override; - int store_user_info(RGWSI_MetaBackend::Context *ctx, - const RGWUserInfo& info, + int store_user_info(const RGWUserInfo& info, RGWUserInfo *old_info, RGWObjVersionTracker *objv_tracker, const real_time& mtime, @@ -120,29 +110,25 @@ class RGWSI_User_RADOS : public RGWSI_User optional_yield y, const DoutPrefixProvider *dpp) override; - int remove_user_info(RGWSI_MetaBackend::Context *ctx, - const RGWUserInfo& info, + int remove_user_info(const RGWUserInfo& info, RGWObjVersionTracker *objv_tracker, optional_yield y, const DoutPrefixProvider *dpp) override; - int get_user_info_by_email(RGWSI_MetaBackend::Context *ctx, - const std::string& email, RGWUserInfo *info, + int get_user_info_by_email(const std::string& email, RGWUserInfo *info, RGWObjVersionTracker *objv_tracker, std::map* pattrs, real_time *pmtime, optional_yield y, const DoutPrefixProvider *dpp) override; - int get_user_info_by_swift(RGWSI_MetaBackend::Context *ctx, - const std::string& swift_name, + int get_user_info_by_swift(const std::string& swift_name, RGWUserInfo *info, /* out */ RGWObjVersionTracker * const objv_tracker, std::map* pattrs, real_time * const pmtime, optional_yield y, const DoutPrefixProvider *dpp) override; - int get_user_info_by_access_key(RGWSI_MetaBackend::Context *ctx, - const std::string& access_key, + int get_user_info_by_access_key(const std::string& access_key, RGWUserInfo *info, RGWObjVersionTracker* objv_tracker, std::map* pattrs, diff --git a/src/test/rgw/test_rgw_posix_driver.cc b/src/test/rgw/test_rgw_posix_driver.cc index 5f624d770d102..a8b0f9bb348fc 100644 --- a/src/test/rgw/test_rgw_posix_driver.cc +++ b/src/test/rgw/test_rgw_posix_driver.cc @@ -17,6 +17,7 @@ #include #include #include "common/common_init.h" +#include "common/errno.h" #include "global/global_init.h" using namespace rgw::sal;