From a992b36efb15851d8598a50e017b89329f05168b Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Fri, 2 Dec 2022 02:49:09 -0500 Subject: [PATCH] rgw: Remove `RGWSI_RADOS` from `RGWSI_Zone_Tools` Simply use the RADOS handle directly. Signed-off-by: Adam C. Emerson --- src/rgw/driver/rados/rgw_service.cc | 2 +- src/rgw/services/svc_zone_utils.cc | 28 +++++++++++++++------------- src/rgw/services/svc_zone_utils.h | 7 +++---- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/rgw/driver/rados/rgw_service.cc b/src/rgw/driver/rados/rgw_service.cc index b9b2d2a8415..cf03d7b220d 100644 --- a/src/rgw/driver/rados/rgw_service.cc +++ b/src/rgw/driver/rados/rgw_service.cc @@ -110,7 +110,7 @@ int RGWServices_Def::init(CephContext *cct, otp->init(zone.get(), meta.get(), meta_be_otp.get()); rados->init(); zone->init(sysobj.get(), radoshandle, sync_modules.get(), bucket_sync_sobj.get()); - zone_utils->init(rados.get(), zone.get()); + zone_utils->init(radoshandle, zone.get()); quota->init(zone.get()); sync_modules->init(zone.get()); sysobj_core->core_init(rados.get(), zone.get()); diff --git a/src/rgw/services/svc_zone_utils.cc b/src/rgw/services/svc_zone_utils.cc index 712bb97c9ba..be9f861f02c 100644 --- a/src/rgw/services/svc_zone_utils.cc +++ b/src/rgw/services/svc_zone_utils.cc @@ -5,6 +5,10 @@ #include "svc_rados.h" #include "svc_zone.h" +#undef FMT_HEADER_ONLY +#define FMT_HEADER_ONLY 1 +#include + #include "rgw_zone.h" using namespace std; @@ -18,26 +22,24 @@ int RGWSI_ZoneUtils::do_start(optional_yield, const DoutPrefixProvider *dpp) string RGWSI_ZoneUtils::gen_host_id() { /* uint64_t needs 16, two '-' separators and a trailing null */ - const string& zone_name = zone_svc->get_zone().name; - const string& zonegroup_name = zone_svc->get_zonegroup().get_name(); - char charbuf[16 + zone_name.size() + zonegroup_name.size() + 2 + 1]; - snprintf(charbuf, sizeof(charbuf), "%llx-%s-%s", (unsigned long long)rados_svc->instance_id(), zone_name.c_str(), zonegroup_name.c_str()); - return string(charbuf); + return fmt::format("{}-{}-{}", rados->get_instance_id(), + zone_svc->get_zone().name, + zone_svc->get_zonegroup().get_name()); } string RGWSI_ZoneUtils::unique_id(uint64_t unique_num) { - char buf[32]; - snprintf(buf, sizeof(buf), ".%llu.%llu", (unsigned long long)rados_svc->instance_id(), (unsigned long long)unique_num); - string s = zone_svc->get_zone_params().get_id() + buf; - return s; + return fmt::format("{}.{}.{}", + zone_svc->get_zone_params().get_id(), + rados->get_instance_id(), + unique_num); } void RGWSI_ZoneUtils::init_unique_trans_id_deps() { - char buf[16 + 2 + 1]; /* uint64_t needs 16, 2 hyphens add further 2 */ - - snprintf(buf, sizeof(buf), "-%llx-", (unsigned long long)rados_svc->instance_id()); - url_encode(string(buf) + zone_svc->get_zone().name, trans_id_suffix); + url_encode(fmt::format("-{}-{}", + rados->get_instance_id(), + zone_svc->get_zone().name), + trans_id_suffix); } /* In order to preserve compatibility with Swift API, transaction ID diff --git a/src/rgw/services/svc_zone_utils.h b/src/rgw/services/svc_zone_utils.h index 43e3fee8d93..41b9400335b 100644 --- a/src/rgw/services/svc_zone_utils.h +++ b/src/rgw/services/svc_zone_utils.h @@ -6,21 +6,20 @@ #include "rgw_service.h" -class RGWSI_RADOS; class RGWSI_Zone; class RGWSI_ZoneUtils : public RGWServiceInstance { friend struct RGWServices_Def; - RGWSI_RADOS *rados_svc{nullptr}; + librados::Rados* rados{nullptr}; RGWSI_Zone *zone_svc{nullptr}; std::string trans_id_suffix; - void init(RGWSI_RADOS *_rados_svc, + void init(librados::Rados* rados_, RGWSI_Zone *_zone_svc) { - rados_svc = _rados_svc; + rados = rados_; zone_svc = _zone_svc; } -- 2.39.5