From: Casey Bodley Date: Wed, 19 Sep 2018 13:38:20 +0000 (-0400) Subject: rgw: add helper functions to apply configured default quotas X-Git-Tag: v14.0.1~173^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=ba83d0c0be3960e8f352c3058cb9a40020de02ae;p=ceph.git rgw: add helper functions to apply configured default quotas Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_quota.cc b/src/rgw/rgw_quota.cc index 4e395c43bc321..01c346f5c12ee 100644 --- a/src/rgw/rgw_quota.cc +++ b/src/rgw/rgw_quota.cc @@ -1006,3 +1006,26 @@ void RGWQuotaHandler::free_handler(RGWQuotaHandler *handler) } +void rgw_apply_default_bucket_quota(RGWQuotaInfo& quota, const ConfigProxy& conf) +{ + if (conf->rgw_bucket_default_quota_max_objects >= 0) { + quota.max_objects = conf->rgw_bucket_default_quota_max_objects; + quota.enabled = true; + } + if (conf->rgw_bucket_default_quota_max_size >= 0) { + quota.max_size = conf->rgw_bucket_default_quota_max_size; + quota.enabled = true; + } +} + +void rgw_apply_default_user_quota(RGWQuotaInfo& quota, const ConfigProxy& conf) +{ + if (conf->rgw_user_default_quota_max_objects >= 0) { + quota.max_objects = conf->rgw_user_default_quota_max_objects; + quota.enabled = true; + } + if (conf->rgw_user_default_quota_max_size >= 0) { + quota.max_size = conf->rgw_user_default_quota_max_size; + quota.enabled = true; + } +} diff --git a/src/rgw/rgw_quota.h b/src/rgw/rgw_quota.h index 5b7bdea778226..167bb17a8acbe 100644 --- a/src/rgw/rgw_quota.h +++ b/src/rgw/rgw_quota.h @@ -16,6 +16,7 @@ #define CEPH_RGW_QUOTA_H #include "include/utime.h" +#include "common/config_fwd.h" #include "common/lru_map.h" #include @@ -114,4 +115,8 @@ public: static void free_handler(RGWQuotaHandler *handler); }; +// apply default quotas from configuration +void rgw_apply_default_bucket_quota(RGWQuotaInfo& quota, const ConfigProxy& conf); +void rgw_apply_default_user_quota(RGWQuotaInfo& quota, const ConfigProxy& conf); + #endif diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index bf5b75a0fb4aa..73a6afe15299c 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -22,6 +22,7 @@ #include "rgw_common.h" #include "rgw_bucket.h" +#include "rgw_quota.h" #define dout_subsys ceph_subsys_rgw @@ -1963,14 +1964,7 @@ int RGWUser::execute_add(RGWUserAdminOpState& op_state, std::string *err_msg) if (op_state.has_bucket_quota()) { user_info.bucket_quota = op_state.get_bucket_quota(); } else { - if (cct->_conf->rgw_bucket_default_quota_max_objects >= 0) { - user_info.bucket_quota.max_objects = cct->_conf->rgw_bucket_default_quota_max_objects; - user_info.bucket_quota.enabled = true; - } - if (cct->_conf->rgw_bucket_default_quota_max_size >= 0) { - user_info.bucket_quota.max_size = cct->_conf->rgw_bucket_default_quota_max_size; - user_info.bucket_quota.enabled = true; - } + rgw_apply_default_bucket_quota(user_info.bucket_quota, cct->_conf); } if (op_state.temp_url_key_specified) { @@ -1984,14 +1978,7 @@ int RGWUser::execute_add(RGWUserAdminOpState& op_state, std::string *err_msg) if (op_state.has_user_quota()) { user_info.user_quota = op_state.get_user_quota(); } else { - if (cct->_conf->rgw_user_default_quota_max_objects >= 0) { - user_info.user_quota.max_objects = cct->_conf->rgw_user_default_quota_max_objects; - user_info.user_quota.enabled = true; - } - if (cct->_conf->rgw_user_default_quota_max_size >= 0) { - user_info.user_quota.max_size = cct->_conf->rgw_user_default_quota_max_size; - user_info.user_quota.enabled = true; - } + rgw_apply_default_user_quota(user_info.user_quota, cct->_conf); } // update the request