From: Casey Bodley Date: Wed, 20 Dec 2023 21:09:09 +0000 (-0500) Subject: radosgw-admin: quota commands can set account quota X-Git-Tag: v20.0.0~2159^2~116 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d473305b2fd8760b55c6c7e8149b3cebf49b6e7c;p=ceph.git radosgw-admin: quota commands can set account quota Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_account.cc b/src/rgw/rgw_account.cc index ee7b4aafa6df..dc280ad87a4c 100644 --- a/src/rgw/rgw_account.cc +++ b/src/rgw/rgw_account.cc @@ -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); diff --git a/src/rgw/rgw_account.h b/src/rgw/rgw_account.h index 04af0b31817c..fca52a73b183 100644 --- a/src/rgw/rgw_account.h +++ b/src/rgw/rgw_account.h @@ -49,6 +49,9 @@ struct AdminOpState { std::optional max_groups; std::optional max_access_keys; std::optional max_buckets; + std::optional quota_max_size; + std::optional quota_max_objects; + std::optional quota_enabled; }; /// create an account diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index c5d564656b82..ddedb4f22de1 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -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(-1, max_objects); + } + if (have_max_size) { + op_state.quota_max_size = std::max(-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; } } diff --git a/src/test/cli/radosgw-admin/help.t b/src/test/cli/radosgw-admin/help.t index 7c7870d37f81..83761b13dfdd 100644 --- a/src/test/cli/radosgw-admin/help.t +++ b/src/test/cli/radosgw-admin/help.t @@ -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