Skip to content

Commit dcce768

Browse files
authored
Merge pull request ceph#56986 from cbodley/wip-65551
rgw/account: add bucket_quota to RGWAccountInfo Reviewed-by: Daniel Gryniewicz <[email protected]> Reviewed-by: Oguzhan Ozmen <[email protected]>
2 parents 4122e41 + 9ed8263 commit dcce768

File tree

13 files changed

+91
-16
lines changed

13 files changed

+91
-16
lines changed

doc/radosgw/account.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,13 @@ To view account stats::
153153

154154
To enable an account quota::
155155

156-
radosgw-admin quota set --account-id={accountid} --max-size=10G
157-
radosgw-admin quota enable --account-id={accountid}
156+
radosgw-admin quota set --quota-scope=account --account-id={accountid} --max-size=10G
157+
radosgw-admin quota enable --quota-scope=account --account-id={accountid}
158+
159+
To enable a bucket quota for the account::
160+
161+
radosgw-admin quota set --quota-scope=bucket --account-id={accountid} --max-objects=1000000
162+
radosgw-admin quota enable --quota-scope=bucket --account-id={accountid}
158163

159164
Migrate an existing User into an Account
160165
----------------------------------------

doc/radosgw/admin.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,9 @@ users.** If a default quota is set in the Ceph Object Gateway Config, then that
538538
quota is set for all subsequently-created users, and that quota is enabled. See
539539
``rgw_bucket_default_quota_max_objects``,
540540
``rgw_bucket_default_quota_max_size``, ``rgw_user_default_quota_max_objects``,
541-
and ``rgw_user_default_quota_max_size`` in `Ceph Object Gateway Config
542-
Reference`_
541+
``rgw_user_default_quota_max_size``, ``rgw_account_default_quota_max_objects``,
542+
and ``rgw_account_default_quota_max_size`` in `Ceph Object Gateway Config
543+
Reference`_.
543544

544545
Quota Cache
545546
-----------

doc/radosgw/config-ref.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ instances or all radosgw-admin options can be put into the ``[global]`` or the
5353
.. confval:: rgw_bucket_default_quota_max_size
5454
.. confval:: rgw_user_default_quota_max_objects
5555
.. confval:: rgw_user_default_quota_max_size
56+
.. confval:: rgw_account_default_quota_max_objects
57+
.. confval:: rgw_account_default_quota_max_size
5658
.. confval:: rgw_verify_ssl
5759
.. confval:: rgw_max_chunk_size
5860

src/common/options/rgw.yaml.in

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,31 @@ options:
23002300
services:
23012301
- rgw
23022302
with_legacy: true
2303+
- name: rgw_account_default_quota_max_objects
2304+
type: int
2305+
level: basic
2306+
desc: Account quota max objects
2307+
long_desc: The default quota configuration for total number of objects for a single
2308+
account. A negative number means 'unlimited'.
2309+
fmt_desc: Default max number of objects for a account. This includes all
2310+
objects in all buckets owned by the account. Set on new accounts
2311+
if no other quota is specified. Has no effect on existing accounts.
2312+
default: -1
2313+
services:
2314+
- rgw
2315+
with_legacy: true
2316+
- name: rgw_account_default_quota_max_size
2317+
type: int
2318+
level: basic
2319+
desc: Account quota max size
2320+
long_desc: The default quota configuration for total size of objects for a single
2321+
account. A negative number means 'unlimited'.
2322+
fmt_desc: The value for account max size quota in bytes set on new accounts,
2323+
if no other quota is specified. Has no effect on existing accounts.
2324+
default: -1
2325+
services:
2326+
- rgw
2327+
with_legacy: true
23032328
- name: rgw_multipart_min_part_size
23042329
type: size
23052330
level: advanced

src/rgw/rgw_account.cc

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "common/utf8.h"
2323

2424
#include "rgw_oidc_provider.h"
25+
#include "rgw_quota.h"
2526
#include "rgw_role.h"
2627
#include "rgw_sal.h"
2728

@@ -136,6 +137,10 @@ int create(const DoutPrefixProvider* dpp,
136137
info.max_buckets = *op_state.max_buckets;
137138
}
138139

140+
const ConfigProxy& conf = dpp->get_cct()->_conf;
141+
rgw_apply_default_account_quota(info.quota, conf);
142+
rgw_apply_default_bucket_quota(info.bucket_quota, conf);
143+
139144
// account id is optional, but must be valid
140145
if (op_state.account_id.empty()) {
141146
info.id = generate_id(dpp->get_cct());
@@ -227,14 +232,22 @@ int modify(const DoutPrefixProvider* dpp,
227232
info.max_buckets = *op_state.max_buckets;
228233
}
229234

230-
if (op_state.quota_max_size) {
231-
info.quota.max_size = *op_state.quota_max_size;
232-
}
233-
if (op_state.quota_max_objects) {
234-
info.quota.max_objects = *op_state.quota_max_objects;
235+
RGWQuotaInfo* pquota = nullptr;
236+
if (op_state.quota_scope == "account") {
237+
pquota = &info.quota;
238+
} else if (op_state.quota_scope == "bucket") {
239+
pquota = &info.bucket_quota;
235240
}
236-
if (op_state.quota_enabled) {
237-
info.quota.enabled = *op_state.quota_enabled;
241+
if (pquota) {
242+
if (op_state.quota_max_size) {
243+
pquota->max_size = *op_state.quota_max_size;
244+
}
245+
if (op_state.quota_max_objects) {
246+
pquota->max_objects = *op_state.quota_max_objects;
247+
}
248+
if (op_state.quota_enabled) {
249+
pquota->enabled = *op_state.quota_enabled;
250+
}
238251
}
239252

240253
constexpr bool exclusive = false;

src/rgw/rgw_account.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ struct AdminOpState {
4949
std::optional<int32_t> max_groups;
5050
std::optional<int32_t> max_access_keys;
5151
std::optional<int32_t> max_buckets;
52+
std::string quota_scope;
5253
std::optional<int64_t> quota_max_size;
5354
std::optional<int64_t> quota_max_objects;
5455
std::optional<bool> quota_enabled;

src/rgw/rgw_admin.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ void usage()
468468
cout << "\nQuota options:\n";
469469
cout << " --max-objects specify max objects (negative value to disable)\n";
470470
cout << " --max-size specify max size (in B/K/M/G/T, negative value to disable)\n";
471-
cout << " --quota-scope scope of quota (bucket, user)\n";
471+
cout << " --quota-scope scope of quota (bucket, user, account)\n";
472472
cout << "\nRate limiting options:\n";
473473
cout << " --max-read-ops specify max requests per minute for READ ops per RGW (GET and HEAD request methods), 0 means unlimited\n";
474474
cout << " --max-read-bytes specify max bytes per minute for READ ops per RGW (GET and HEAD request methods), 0 means unlimited\n";
@@ -10673,6 +10673,13 @@ int main(int argc, const char **argv)
1067310673
op_state.tenant = tenant;
1067410674
op_state.account_name = account_name;
1067510675

10676+
if (quota_scope != "bucket" && quota_scope != "account") {
10677+
cerr << "ERROR: invalid quota scope specification. Please specify "
10678+
"either --quota-scope=bucket or --quota-scope=account" << std::endl;
10679+
return EINVAL;
10680+
}
10681+
op_state.quota_scope = quota_scope;
10682+
1067610683
if (opt_cmd == OPT::QUOTA_ENABLE) {
1067710684
op_state.quota_enabled = true;
1067810685
} else if (opt_cmd == OPT::QUOTA_DISABLE) {

src/rgw/rgw_common.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,6 +3018,7 @@ void RGWAccountInfo::dump(Formatter * const f) const
30183018
encode_json("name", name, f);
30193019
encode_json("email", email, f);
30203020
encode_json("quota", quota, f);
3021+
encode_json("bucket_quota", bucket_quota, f);
30213022
encode_json("max_users", max_users, f);
30223023
encode_json("max_roles", max_roles, f);
30233024
encode_json("max_groups", max_groups, f);
@@ -3032,6 +3033,7 @@ void RGWAccountInfo::decode_json(JSONObj* obj)
30323033
JSONDecoder::decode_json("name", name, obj);
30333034
JSONDecoder::decode_json("email", email, obj);
30343035
JSONDecoder::decode_json("quota", quota, obj);
3036+
JSONDecoder::decode_json("bucket_quota", bucket_quota, obj);
30353037
JSONDecoder::decode_json("max_users", max_users, obj);
30363038
JSONDecoder::decode_json("max_roles", max_roles, obj);
30373039
JSONDecoder::decode_json("max_groups", max_groups, obj);

src/rgw/rgw_common.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ struct RGWAccountInfo {
787787
std::string name;
788788
std::string email;
789789
RGWQuotaInfo quota;
790+
RGWQuotaInfo bucket_quota;
790791

791792
static constexpr int32_t DEFAULT_USER_LIMIT = 1000;
792793
int32_t max_users = DEFAULT_USER_LIMIT;
@@ -804,7 +805,7 @@ struct RGWAccountInfo {
804805
int32_t max_access_keys = DEFAULT_ACCESS_KEY_LIMIT;
805806

806807
void encode(bufferlist& bl) const {
807-
ENCODE_START(1, 1, bl);
808+
ENCODE_START(2, 1, bl);
808809
encode(id, bl);
809810
encode(tenant, bl);
810811
encode(name, bl);
@@ -815,11 +816,12 @@ struct RGWAccountInfo {
815816
encode(max_groups, bl);
816817
encode(max_buckets, bl);
817818
encode(max_access_keys, bl);
819+
encode(bucket_quota, bl);
818820
ENCODE_FINISH(bl);
819821
}
820822

821823
void decode(bufferlist::const_iterator& bl) {
822-
DECODE_START(1, bl);
824+
DECODE_START(2, bl);
823825
decode(id, bl);
824826
decode(tenant, bl);
825827
decode(name, bl);
@@ -830,6 +832,9 @@ struct RGWAccountInfo {
830832
decode(max_groups, bl);
831833
decode(max_buckets, bl);
832834
decode(max_access_keys, bl);
835+
if (struct_v >= 2) {
836+
decode(bucket_quota, bl);
837+
}
833838
DECODE_FINISH(bl);
834839
}
835840

src/rgw/rgw_op.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,8 +1408,8 @@ static int get_owner_quota_info(DoutPrefixProvider* dpp,
14081408
RGWObjVersionTracker objv; // ignored
14091409
int r = driver->load_account_by_id(dpp, y, account_id, info, attrs, objv);
14101410
if (r >= 0) {
1411-
// no bucket quota
14121411
quotas.user_quota = info.quota;
1412+
quotas.bucket_quota = info.bucket_quota;
14131413
}
14141414
return r;
14151415
}), owner);

0 commit comments

Comments
 (0)