// -*- 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);
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;
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;
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") {
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") {
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;
}
}
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);