From: Casey Bodley Date: Wed, 22 Nov 2023 17:32:14 +0000 (-0500) Subject: cls/rgw: cls_bucket_head_async uses intrusive_ptr for RGWGetDirHeader_CB X-Git-Tag: v19.0.0~25^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=131d49a9852d2003b605f92308abcd9abc07e441;p=ceph.git cls/rgw: cls_bucket_head_async uses intrusive_ptr for RGWGetDirHeader_CB Signed-off-by: Casey Bodley --- diff --git a/src/cls/rgw/cls_rgw_client.cc b/src/cls/rgw/cls_rgw_client.cc index 5e7fba88f24a..aa576129252a 100644 --- a/src/cls/rgw/cls_rgw_client.cc +++ b/src/cls/rgw/cls_rgw_client.cc @@ -751,12 +751,11 @@ int CLSRGWIssueBucketBILogStop::issue_op(const int shard_id, const string& oid) } class GetDirHeaderCompletion : public ObjectOperationCompletion { - RGWGetDirHeader_CB *ret_ctx; + boost::intrusive_ptr cb; public: - explicit GetDirHeaderCompletion(RGWGetDirHeader_CB *_ctx) : ret_ctx(_ctx) {} - ~GetDirHeaderCompletion() override { - ret_ctx->put(); - } + explicit GetDirHeaderCompletion(boost::intrusive_ptr cb) + : cb(std::move(cb)) {} + void handle_completion(int r, bufferlist& outbl) override { rgw_cls_list_ret ret; try { @@ -765,20 +764,20 @@ public: } catch (ceph::buffer::error& err) { r = -EIO; } - - ret_ctx->handle_response(r, ret.dir.header); + cb->handle_response(r, ret.dir.header); } }; -int cls_rgw_get_dir_header_async(IoCtx& io_ctx, string& oid, RGWGetDirHeader_CB *ctx) +int cls_rgw_get_dir_header_async(IoCtx& io_ctx, const string& oid, + boost::intrusive_ptr cb) { bufferlist in, out; rgw_cls_list_op call; call.num_entries = 0; encode(call, in); ObjectReadOperation op; - GetDirHeaderCompletion *cb = new GetDirHeaderCompletion(ctx); - op.exec(RGW_CLASS, RGW_BUCKET_LIST, in, cb); + op.exec(RGW_CLASS, RGW_BUCKET_LIST, in, + new GetDirHeaderCompletion(std::move(cb))); AioCompletion *c = librados::Rados::aio_create_completion(nullptr, nullptr); int r = io_ctx.aio_operate(oid, c, &op, NULL); c->release(); diff --git a/src/cls/rgw/cls_rgw_client.h b/src/cls/rgw/cls_rgw_client.h index 1ae49c877bb4..4ef10245404b 100644 --- a/src/cls/rgw/cls_rgw_client.h +++ b/src/cls/rgw/cls_rgw_client.h @@ -3,6 +3,8 @@ #pragma once +#include +#include #include "include/str_list.h" #include "include/rados/librados.hpp" #include "cls_rgw_ops.h" @@ -151,10 +153,10 @@ public: } }; -class RGWGetDirHeader_CB : public RefCountedObject { +class RGWGetDirHeader_CB : public boost::intrusive_ref_counter { public: - ~RGWGetDirHeader_CB() override {} - virtual void handle_response(int r, rgw_bucket_dir_header& header) = 0; + virtual ~RGWGetDirHeader_CB() {} + virtual void handle_response(int r, const rgw_bucket_dir_header& header) = 0; }; class BucketIndexShardsManager { @@ -572,7 +574,8 @@ public: virtual ~CLSRGWIssueBucketBILogStop() override {} }; -int cls_rgw_get_dir_header_async(librados::IoCtx& io_ctx, std::string& oid, RGWGetDirHeader_CB *ctx); +int cls_rgw_get_dir_header_async(librados::IoCtx& io_ctx, const std::string& oid, + boost::intrusive_ptr cb); void cls_rgw_encode_suggestion(char op, rgw_bucket_dir_entry& dirent, ceph::buffer::list& updates); diff --git a/src/rgw/driver/rados/rgw_rados.cc b/src/rgw/driver/rados/rgw_rados.cc index 06ddda412271..0d11fc10e44e 100644 --- a/src/rgw/driver/rados/rgw_rados.cc +++ b/src/rgw/driver/rados/rgw_rados.cc @@ -8479,7 +8479,7 @@ public: : cb(std::move(cb)), pendings(_pendings), stats(), ret_code(0), should_cb(true) {} - void handle_response(int r, rgw_bucket_dir_header& header) override { + void handle_response(int r, const rgw_bucket_dir_header& header) override { std::lock_guard l{lock}; if (should_cb) { if (r >= 0) { @@ -8510,15 +8510,13 @@ public: int RGWRados::get_bucket_stats_async(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout, int shard_id, boost::intrusive_ptr cb) { int num_aio = 0; - RGWGetBucketStatsContext *get_ctx = new RGWGetBucketStatsContext(std::move(cb), bucket_info.layout.current_index.layout.normal.num_shards ? : 1); - ceph_assert(get_ctx); - int r = cls_bucket_head_async(dpp, bucket_info, idx_layout, shard_id, get_ctx, &num_aio); + boost::intrusive_ptr headercb = new RGWGetBucketStatsContext(std::move(cb), bucket_info.layout.current_index.layout.normal.num_shards ? : 1); + int r = cls_bucket_head_async(dpp, bucket_info, idx_layout, shard_id, headercb, &num_aio); if (r < 0) { if (num_aio) { - get_ctx->unset_cb(); + headercb->unset_cb(); } } - get_ctx->put(); return r; } @@ -10045,7 +10043,9 @@ int RGWRados::cls_bucket_head(const DoutPrefixProvider *dpp, const RGWBucketInfo return 0; } -int RGWRados::cls_bucket_head_async(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout, int shard_id, RGWGetDirHeader_CB *ctx, int *num_aio) +int RGWRados::cls_bucket_head_async(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, + const rgw::bucket_index_layout_generation& idx_layout, int shard_id, + boost::intrusive_ptr cb, int *num_aio) { RGWSI_RADOS::Pool index_pool; map bucket_objs; @@ -10053,17 +10053,14 @@ int RGWRados::cls_bucket_head_async(const DoutPrefixProvider *dpp, const RGWBuck if (r < 0) return r; - map::iterator iter = bucket_objs.begin(); - for (; iter != bucket_objs.end(); ++iter) { - r = cls_rgw_get_dir_header_async(index_pool.ioctx(), iter->second, static_cast(ctx->get())); + for (auto& pair : bucket_objs) { + r = cls_rgw_get_dir_header_async(index_pool.ioctx(), pair.second, cb); if (r < 0) { - ctx->put(); - break; - } else { - (*num_aio)++; + return r; } + (*num_aio)++; } - return r; + return 0; } int RGWRados::check_bucket_shards(const RGWBucketInfo& bucket_info, diff --git a/src/rgw/driver/rados/rgw_rados.h b/src/rgw/driver/rados/rgw_rados.h index 19916992b9d5..38e69048e914 100644 --- a/src/rgw/driver/rados/rgw_rados.h +++ b/src/rgw/driver/rados/rgw_rados.h @@ -1474,7 +1474,7 @@ public: int cls_bucket_head_async(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout, - int shard_id, RGWGetDirHeader_CB *ctx, int *num_aio); + int shard_id, boost::intrusive_ptr cb, int *num_aio); int bi_get_instance(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj, rgw_bucket_dir_entry *dirent, optional_yield y); int bi_get_olh(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj, rgw_bucket_olh_entry *olh, optional_yield y); int bi_get(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj, BIIndexType index_type, rgw_cls_bi_entry *entry, optional_yield y);