From: Ali Masarwa Date: Tue, 18 Mar 2025 13:59:43 +0000 (+0200) Subject: RGW/standalone: refactor RGWPeriodConfig with configstore X-Git-Tag: v21.0.0~256^2~760^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=de9073218eef31aea29698e510c946e41e8b2c3a;p=ceph.git RGW/standalone: refactor RGWPeriodConfig with configstore Signed-off-by: Ali Masarwa --- diff --git a/src/rgw/driver/rados/rgw_zone.h b/src/rgw/driver/rados/rgw_zone.h index bf0d2fb968d1..a4c1856047c6 100644 --- a/src/rgw/driver/rados/rgw_zone.h +++ b/src/rgw/driver/rados/rgw_zone.h @@ -517,12 +517,6 @@ struct RGWPeriodConfig void dump(Formatter *f) const; void decode_json(JSONObj *obj); - // the period config must be stored in a local object outside of the period, - // so that it can be used in a default configuration where no realm/period - // exists - int read(const DoutPrefixProvider *dpp, RGWSI_SysObj *sysobj_svc, const std::string& realm_id, optional_yield y); - int write(const DoutPrefixProvider *dpp, RGWSI_SysObj *sysobj_svc, const std::string& realm_id, optional_yield y); - static std::string get_oid(const std::string& realm_id); static rgw_pool get_pool(CephContext *cct); }; diff --git a/src/rgw/rgw_rest_ratelimit.cc b/src/rgw/rgw_rest_ratelimit.cc index 128e44d9a5ae..20b77d049c7e 100644 --- a/src/rgw/rgw_rest_ratelimit.cc +++ b/src/rgw/rgw_rest_ratelimit.cc @@ -1,6 +1,9 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab ft=cpp #include "rgw_rest_ratelimit.h" +#include "rgw_sal.h" +#include "rgw_sal_config.h" + class RGWOp_Ratelimit_Info : public RGWRESTOp { int check_caps(const RGWUserCaps& caps) override { return caps.check_cap("ratelimit", RGW_CAP_READ); @@ -101,7 +104,9 @@ void RGWOp_Ratelimit_Info::execute(optional_yield y) if (global) { std::string realm_id = driver->get_zone()->get_realm_id(); RGWPeriodConfig period_config; - op_ret = period_config.read(this, static_cast(driver)->svc()->sysobj, realm_id, y); + auto config_store_type = g_conf().get_val("rgw_config_store"); + auto cfgstore = DriverManager::create_config_store(this, config_store_type); + op_ret = cfgstore->read_period_config(this, y, realm_id, period_config); if (op_ret && op_ret != -ENOENT) { ldpp_dout(this, 0) << "Error on period config read" << dendl; return; @@ -302,10 +307,13 @@ void RGWOp_Ratelimit_Set::execute(optional_yield y) op_ret = bucket->merge_and_store_attrs(this, attr, y); return; } + + auto config_store_type = g_conf().get_val("rgw_config_store"); + auto cfgstore = DriverManager::create_config_store(s, config_store_type); if (global) { std::string realm_id = driver->get_zone()->get_realm_id(); RGWPeriodConfig period_config; - op_ret = period_config.read(s, static_cast(driver)->svc()->sysobj, realm_id, y); + op_ret = cfgstore->read_period_config(s, y, realm_id, period_config); if (op_ret && op_ret != -ENOENT) { ldpp_dout(this, 0) << "Error on period config read" << dendl; return; @@ -316,7 +324,7 @@ void RGWOp_Ratelimit_Set::execute(optional_yield y) have_max_read_bytes, max_read_bytes, have_max_write_bytes, max_write_bytes, have_enabled, enabled, ratelimit_configured, ratelimit_info); period_config.bucket_ratelimit = ratelimit_info; - op_ret = period_config.write(s, static_cast(driver)->svc()->sysobj, realm_id, y); + op_ret = cfgstore->write_period_config(s, y, false, realm_id, period_config); return; } if (ratelimit_scope == "anon") { @@ -325,7 +333,7 @@ void RGWOp_Ratelimit_Set::execute(optional_yield y) have_max_read_bytes, max_read_bytes, have_max_write_bytes, max_write_bytes, have_enabled, enabled, ratelimit_configured, ratelimit_info); period_config.anon_ratelimit = ratelimit_info; - op_ret = period_config.write(s, static_cast(driver)->svc()->sysobj, realm_id, y); + op_ret = cfgstore->write_period_config(s, y, false, realm_id, period_config); return; } if (ratelimit_scope == "user") { @@ -334,7 +342,7 @@ void RGWOp_Ratelimit_Set::execute(optional_yield y) have_max_read_bytes, max_read_bytes, have_max_write_bytes, max_write_bytes, have_enabled, enabled, ratelimit_configured, ratelimit_info); period_config.user_ratelimit = ratelimit_info; - op_ret = period_config.write(s, static_cast(driver)->svc()->sysobj, realm_id, y); + op_ret = cfgstore->write_period_config(s, y, false, realm_id, period_config); return; } } diff --git a/src/rgw/rgw_zone.cc b/src/rgw/rgw_zone.cc index 44338c0fea81..d2f5d494bca1 100644 --- a/src/rgw/rgw_zone.cc +++ b/src/rgw/rgw_zone.cc @@ -613,43 +613,6 @@ int RGWZoneParams::fix_pool_names(const DoutPrefixProvider *dpp, optional_yield return 0; } -int RGWPeriodConfig::read(const DoutPrefixProvider *dpp, RGWSI_SysObj *sysobj_svc, const std::string& realm_id, - optional_yield y) -{ - const auto& pool = get_pool(sysobj_svc->ctx()); - const auto& oid = get_oid(realm_id); - bufferlist bl; - - auto sysobj = sysobj_svc->get_obj(rgw_raw_obj{pool, oid}); - int ret = sysobj.rop().read(dpp, &bl, y); - if (ret < 0) { - return ret; - } - using ceph::decode; - try { - auto iter = bl.cbegin(); - decode(*this, iter); - } catch (buffer::error& err) { - return -EIO; - } - return 0; -} - -int RGWPeriodConfig::write(const DoutPrefixProvider *dpp, - RGWSI_SysObj *sysobj_svc, - const std::string& realm_id, optional_yield y) -{ - const auto& pool = get_pool(sysobj_svc->ctx()); - const auto& oid = get_oid(realm_id); - bufferlist bl; - using ceph::encode; - encode(*this, bl); - auto sysobj = sysobj_svc->get_obj(rgw_raw_obj{pool, oid}); - return sysobj.wop() - .set_exclusive(false) - .write(dpp, bl, y); -} - void RGWPeriodConfig::decode_json(JSONObj *obj) { JSONDecoder::decode_json("bucket_quota", quota.bucket_quota, obj); diff --git a/src/rgw/services/svc_zone.cc b/src/rgw/services/svc_zone.cc index c7916d7f5b00..9fec53028dd0 100644 --- a/src/rgw/services/svc_zone.cc +++ b/src/rgw/services/svc_zone.cc @@ -291,7 +291,7 @@ int RGWSI_Zone::do_start(optional_yield y, const DoutPrefixProvider *dpp) } // read period_config into current_period auto& period_config = current_period->get_config(); - ret = period_config.read(dpp, sysobj_svc, zonegroup->realm_id, y); + ret = cfgstore->read_period_config(dpp, y, zonegroup->realm_id, period_config); if (ret < 0 && ret != -ENOENT) { ldout(cct, 0) << "ERROR: failed to read period config: " << cpp_strerror(ret) << dendl;