]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add helper functions to apply configured default quotas
authorCasey Bodley <cbodley@redhat.com>
Wed, 19 Sep 2018 13:38:20 +0000 (09:38 -0400)
committerNathan Cutler <ncutler@suse.com>
Tue, 13 Nov 2018 10:48:44 +0000 (11:48 +0100)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
(cherry picked from commit ba83d0c0be3960e8f352c3058cb9a40020de02ae)

Conflicts:
    src/rgw/rgw_quota.cc
    src/rgw/rgw_quota.h
- mimic uses "md_config_t" (non-pointer) instead of "ConfigProxy"
(pointer)

src/rgw/rgw_quota.cc
src/rgw/rgw_quota.h
src/rgw/rgw_user.cc

index ce3d1265facd45b8ab2e210511553486e3a7feca..0b73a5bd348b843c7f9b1fe2fee3dc179bb96d76 100644 (file)
@@ -1006,3 +1006,26 @@ void RGWQuotaHandler::free_handler(RGWQuotaHandler *handler)
 }
 
 
+void rgw_apply_default_bucket_quota(RGWQuotaInfo& quota, const md_config_t& 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 md_config_t& 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;
+  }
+}
index 54e2f48a79ae535ff8c8c90e7760b06ede7a6458..b226bd1590f54c2b953556593882a76c3598eb91 100644 (file)
@@ -16,6 +16,7 @@
 #define CEPH_RGW_QUOTA_H
 
 #include "include/utime.h"
+#include "common/config.h"
 #include "common/lru_map.h"
 
 #include <atomic>
@@ -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 md_config_t& conf);
+void rgw_apply_default_user_quota(RGWQuotaInfo& quota, const md_config_t& conf);
+
 #endif
index b94a2d36bb3fb566bb163b5c4659fd7f8fec12f0..c0c2f0b2736f8434cbcfedfa82723d41ff1bd914 100644 (file)
@@ -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