]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
RGW/standalone: refactor RGWPeriodConfig with configstore
authorAli Masarwa <amasarwa@redhat.com>
Tue, 18 Mar 2025 13:59:43 +0000 (15:59 +0200)
committerAli Masarwa <amasarwa@redhat.com>
Tue, 29 Apr 2025 12:31:09 +0000 (15:31 +0300)
Signed-off-by: Ali Masarwa <amasarwa@redhat.com>
src/rgw/driver/rados/rgw_zone.h
src/rgw/rgw_rest_ratelimit.cc
src/rgw/rgw_zone.cc
src/rgw/services/svc_zone.cc

index bf0d2fb968d147af1cec1f0859d0ff0e64cec3e2..a4c1856047c6137101cd312c639d7c1293a30480 100644 (file)
@@ -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);
 };
index 128e44d9a5ae0032c34719a9d7c6add31d7e7ae7..20b77d049c7ef1eced73c72058159fd01bfd7007 100644 (file)
@@ -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<rgw::sal::RadosStore*>(driver)->svc()->sysobj, realm_id, y);
+    auto config_store_type = g_conf().get_val<std::string>("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<std::string>("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<rgw::sal::RadosStore*>(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<rgw::sal::RadosStore*>(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<rgw::sal::RadosStore*>(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<rgw::sal::RadosStore*>(driver)->svc()->sysobj, realm_id, y);
+      op_ret = cfgstore->write_period_config(s, y, false, realm_id, period_config);
       return;
     }
   }
index 44338c0fea8130179785ed4361108b837c87647d..d2f5d494bca1059c606b4ae56a248328bd76f122 100644 (file)
@@ -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);
index c7916d7f5b00677d1f98f9d3babf790f16f306e4..9fec53028dd076939fc19044dde1e035631fd299 100644 (file)
@@ -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;