]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
radosgw-admin: quota commands can set account quota
authorCasey Bodley <cbodley@redhat.com>
Wed, 20 Dec 2023 21:09:09 +0000 (16:09 -0500)
committerCasey Bodley <cbodley@redhat.com>
Wed, 10 Apr 2024 17:09:14 +0000 (13:09 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_account.cc
src/rgw/rgw_account.h
src/rgw/rgw_admin.cc
src/test/cli/radosgw-admin/help.t

index ee7b4aafa6df5aef8d38a57029dd144cd10ddece..dc280ad87a4cd1c208257b493a6ad43cdaceb457 100644 (file)
@@ -225,6 +225,16 @@ int modify(const DoutPrefixProvider* dpp,
     info.max_buckets = *op_state.max_buckets;
   }
 
+  if (op_state.quota_max_size) {
+    info.quota.max_size = *op_state.quota_max_size;
+  }
+  if (op_state.quota_max_objects) {
+    info.quota.max_objects = *op_state.quota_max_objects;
+  }
+  if (op_state.quota_enabled) {
+    info.quota.enabled = *op_state.quota_enabled;
+  }
+
   constexpr bool exclusive = false;
 
   ret = driver->store_account(dpp, y, exclusive, info, &old_info, attrs, objv);
index 04af0b31817c01d19cf713f2346897c719c21561..fca52a73b183387e046777aced63042d4672089c 100644 (file)
@@ -49,6 +49,9 @@ struct AdminOpState {
   std::optional<int32_t> max_groups;
   std::optional<int32_t> max_access_keys;
   std::optional<int32_t> max_buckets;
+  std::optional<int64_t> quota_max_size;
+  std::optional<int64_t> quota_max_objects;
+  std::optional<bool> quota_enabled;
 };
 
 /// create an account
index c5d564656b824c9f31202d776c9d89ee31b7d8b9..ddedb4f22de159001b08ec7fa3601bf5f79c43f4 100644 (file)
@@ -194,9 +194,9 @@ void usage()
   cout << "  period list                      list all periods\n";
   cout << "  period update                    update the staging period\n";
   cout << "  period commit                    commit the staging period\n";
-  cout << "  quota set                        set quota params\n";
-  cout << "  quota enable                     enable quota\n";
-  cout << "  quota disable                    disable quota\n";
+  cout << "  quota set                        set quota params for a user/bucket/account\n";
+  cout << "  quota enable                     enable quota for a user/bucket/account\n";
+  cout << "  quota disable                    disable quota for a user/bucket/account\n";
   cout << "  ratelimit get                    get ratelimit params\n";
   cout << "  ratelimit set                    set ratelimit params\n";
   cout << "  ratelimit enable                 enable ratelimit\n";
@@ -10360,11 +10360,6 @@ next:
   bool quota_op = (opt_cmd == OPT::QUOTA_SET || opt_cmd == OPT::QUOTA_ENABLE || opt_cmd == OPT::QUOTA_DISABLE);
 
   if (quota_op) {
-    if (bucket_name.empty() && rgw::sal::User::empty(user)) {
-      cerr << "ERROR: bucket name or uid is required for quota operation" << std::endl;
-      return EINVAL;
-    }
-
     if (!bucket_name.empty()) {
       if (!quota_scope.empty() && quota_scope != "bucket") {
         cerr << "ERROR: invalid quota scope specification." << std::endl;
@@ -10381,6 +10376,36 @@ next:
         cerr << "ERROR: invalid quota scope specification. Please specify either --quota-scope=bucket, or --quota-scope=user" << std::endl;
         return EINVAL;
       }
+    } else if (!account_id.empty() || !account_name.empty()) {
+      // set account quota
+      rgw::account::AdminOpState op_state;
+      op_state.account_id = account_id;
+      op_state.tenant = tenant;
+      op_state.account_name = account_name;
+
+      if (opt_cmd == OPT::QUOTA_ENABLE) {
+        op_state.quota_enabled = true;
+      } else if (opt_cmd == OPT::QUOTA_DISABLE) {
+        op_state.quota_enabled = false;
+      }
+      if (have_max_objects) {
+        op_state.quota_max_objects = std::max<int64_t>(-1, max_objects);
+      }
+      if (have_max_size) {
+        op_state.quota_max_size = std::max<int64_t>(-1, rgw_rounded_kb(max_size) * 1024);
+      }
+
+      std::string err_msg;
+      ret = rgw::account::modify(dpp(), driver, op_state, err_msg,
+                                 stream_flusher, null_yield);
+      if (ret < 0) {
+        cerr << "ERROR: failed to set account quota with "
+            << cpp_strerror(-ret) << ": " << err_msg << std::endl;
+        return -ret;
+      }
+    } else {
+      cerr << "ERROR: bucket name or uid or account is required for quota operation" << std::endl;
+      return EINVAL;
     }
   }
 
index 7c7870d37f81bc71afa2d16b56d02b2919acecd7..83761b13dfdd5665f0dfe6776d0ec912ccc37ca3 100644 (file)
@@ -61,9 +61,9 @@
     period list                      list all periods
     period update                    update the staging period
     period commit                    commit the staging period
-    quota set                        set quota params
-    quota enable                     enable quota
-    quota disable                    disable quota
+    quota set                        set quota params for a user/bucket/account
+    quota enable                     enable quota for a user/bucket/account
+    quota disable                    disable quota for a user/bucket/account
     ratelimit get                    get ratelimit params
     ratelimit set                    set ratelimit params
     ratelimit enable                 enable ratelimit