Skip to content

Commit 42b969b

Browse files
authored
Merge pull request ceph#46033 from iqbalredkhan/quota2
rgw: Refactoring Quota Management
2 parents 26ed4f5 + 5e98b8b commit 42b969b

30 files changed

+177
-177
lines changed

src/rgw/rgw_admin.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,9 +1538,9 @@ int set_user_bucket_quota(OPT opt_cmd, RGWUser& user, RGWUserAdminOpState& op_st
15381538
{
15391539
RGWUserInfo& user_info = op_state.get_user_info();
15401540

1541-
set_quota_info(user_info.bucket_quota, opt_cmd, max_size, max_objects, have_max_size, have_max_objects);
1541+
set_quota_info(user_info.quota.bucket_quota, opt_cmd, max_size, max_objects, have_max_size, have_max_objects);
15421542

1543-
op_state.set_bucket_quota(user_info.bucket_quota);
1543+
op_state.set_bucket_quota(user_info.quota.bucket_quota);
15441544

15451545
string err;
15461546
int r = user.modify(dpp(), op_state, null_yield, &err);
@@ -1556,9 +1556,9 @@ int set_user_quota(OPT opt_cmd, RGWUser& user, RGWUserAdminOpState& op_state, in
15561556
{
15571557
RGWUserInfo& user_info = op_state.get_user_info();
15581558

1559-
set_quota_info(user_info.user_quota, opt_cmd, max_size, max_objects, have_max_size, have_max_objects);
1559+
set_quota_info(user_info.quota.user_quota, opt_cmd, max_size, max_objects, have_max_size, have_max_objects);
15601560

1561-
op_state.set_user_quota(user_info.user_quota);
1561+
op_state.set_user_quota(user_info.quota.user_quota);
15621562

15631563
string err;
15641564
int r = user.modify(dpp(), op_state, null_yield, &err);
@@ -4661,19 +4661,19 @@ int main(int argc, const char **argv)
46614661

46624662
formatter->open_object_section("period_config");
46634663
if (quota_scope == "bucket") {
4664-
set_quota_info(period_config.bucket_quota, opt_cmd,
4664+
set_quota_info(period_config.quota.bucket_quota, opt_cmd,
46654665
max_size, max_objects,
46664666
have_max_size, have_max_objects);
4667-
encode_json("bucket quota", period_config.bucket_quota, formatter.get());
4667+
encode_json("bucket quota", period_config.quota.bucket_quota, formatter.get());
46684668
} else if (quota_scope == "user") {
4669-
set_quota_info(period_config.user_quota, opt_cmd,
4669+
set_quota_info(period_config.quota.user_quota, opt_cmd,
46704670
max_size, max_objects,
46714671
have_max_size, have_max_objects);
4672-
encode_json("user quota", period_config.user_quota, formatter.get());
4672+
encode_json("user quota", period_config.quota.user_quota, formatter.get());
46734673
} else if (quota_scope.empty() && opt_cmd == OPT::GLOBAL_QUOTA_GET) {
46744674
// if no scope is given for GET, print both
4675-
encode_json("bucket quota", period_config.bucket_quota, formatter.get());
4676-
encode_json("user quota", period_config.user_quota, formatter.get());
4675+
encode_json("bucket quota", period_config.quota.bucket_quota, formatter.get());
4676+
encode_json("user quota", period_config.quota.user_quota, formatter.get());
46774677
} else {
46784678
cerr << "ERROR: invalid quota scope specification. Please specify "
46794679
"either --quota-scope=bucket, or --quota-scope=user" << std::endl;

src/rgw/rgw_auth.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ void rgw::auth::WebIdentityApplier::create_account(const DoutPrefixProvider* dpp
373373
user->get_info().type = TYPE_WEB;
374374
user->get_info().max_buckets =
375375
cct->_conf.get_val<int64_t>("rgw_user_max_buckets");
376-
rgw_apply_default_bucket_quota(user->get_info().bucket_quota, cct->_conf);
377-
rgw_apply_default_user_quota(user->get_info().user_quota, cct->_conf);
376+
rgw_apply_default_bucket_quota(user->get_info().quota.bucket_quota, cct->_conf);
377+
rgw_apply_default_user_quota(user->get_info().quota.user_quota, cct->_conf);
378378

379379
int ret = user->store_user(dpp, null_yield, true);
380380
if (ret < 0) {
@@ -650,8 +650,8 @@ void rgw::auth::RemoteApplier::create_account(const DoutPrefixProvider* dpp,
650650
}
651651
user->get_info().max_buckets =
652652
cct->_conf.get_val<int64_t>("rgw_user_max_buckets");
653-
rgw_apply_default_bucket_quota(user->get_info().bucket_quota, cct->_conf);
654-
rgw_apply_default_user_quota(user->get_info().user_quota, cct->_conf);
653+
rgw_apply_default_bucket_quota(user->get_info().quota.bucket_quota, cct->_conf);
654+
rgw_apply_default_user_quota(user->get_info().quota.user_quota, cct->_conf);
655655
user_info = user->get_info();
656656

657657
int ret = user->store_user(dpp, null_yield, true);

src/rgw/rgw_common.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,8 +2728,8 @@ void RGWUserInfo::dump(Formatter *f) const
27282728
encode_json("default_placement", default_placement.name, f);
27292729
encode_json("default_storage_class", default_placement.storage_class, f);
27302730
encode_json("placement_tags", placement_tags, f);
2731-
encode_json("bucket_quota", bucket_quota, f);
2732-
encode_json("user_quota", user_quota, f);
2731+
encode_json("bucket_quota", quota.bucket_quota, f);
2732+
encode_json("user_quota", quota.user_quota, f);
27332733
encode_json("temp_url_keys", temp_url_keys, f);
27342734

27352735
string user_source_type;
@@ -2787,8 +2787,8 @@ void RGWUserInfo::decode_json(JSONObj *obj)
27872787
JSONDecoder::decode_json("default_placement", default_placement.name, obj);
27882788
JSONDecoder::decode_json("default_storage_class", default_placement.storage_class, obj);
27892789
JSONDecoder::decode_json("placement_tags", placement_tags, obj);
2790-
JSONDecoder::decode_json("bucket_quota", bucket_quota, obj);
2791-
JSONDecoder::decode_json("user_quota", user_quota, obj);
2790+
JSONDecoder::decode_json("bucket_quota", quota.bucket_quota, obj);
2791+
JSONDecoder::decode_json("user_quota", quota.user_quota, obj);
27922792
JSONDecoder::decode_json("temp_url_keys", temp_url_keys, obj);
27932793

27942794
string user_source_type;

src/rgw/rgw_common.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,8 @@ struct RGWUserInfo
748748
__u8 system;
749749
rgw_placement_rule default_placement;
750750
std::list<std::string> placement_tags;
751-
RGWQuotaInfo bucket_quota;
752751
std::map<int, std::string> temp_url_keys;
753-
RGWQuotaInfo user_quota;
752+
RGWQuota quota;
754753
uint32_t type;
755754
std::set<std::string> mfa_ids;
756755
std::string assumed_role_arn;
@@ -811,9 +810,9 @@ struct RGWUserInfo
811810
encode(system, bl);
812811
encode(default_placement, bl);
813812
encode(placement_tags, bl);
814-
encode(bucket_quota, bl);
813+
encode(quota.bucket_quota, bl);
815814
encode(temp_url_keys, bl);
816-
encode(user_quota, bl);
815+
encode(quota.user_quota, bl);
817816
encode(user_id.tenant, bl);
818817
encode(admin, bl);
819818
encode(type, bl);
@@ -879,13 +878,13 @@ struct RGWUserInfo
879878
decode(placement_tags, bl); /* tags of allowed placement rules */
880879
}
881880
if (struct_v >= 14) {
882-
decode(bucket_quota, bl);
881+
decode(quota.bucket_quota, bl);
883882
}
884883
if (struct_v >= 15) {
885884
decode(temp_url_keys, bl);
886885
}
887886
if (struct_v >= 16) {
888-
decode(user_quota, bl);
887+
decode(quota.user_quota, bl);
889888
}
890889
if (struct_v >= 17) {
891890
decode(user_id.tenant, bl);

src/rgw/rgw_cr_tools.cc

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,35 +56,34 @@ int RGWUserCreateCR::Request::_send_request(const DoutPrefixProvider *dpp)
5656

5757

5858
if (params.apply_quota) {
59-
RGWQuotaInfo bucket_quota;
60-
RGWQuotaInfo user_quota;
59+
RGWQuota quota;
6160

6261
if (cct->_conf->rgw_bucket_default_quota_max_objects >= 0) {
63-
bucket_quota.max_objects = cct->_conf->rgw_bucket_default_quota_max_objects;
64-
bucket_quota.enabled = true;
62+
quota.bucket_quota.max_objects = cct->_conf->rgw_bucket_default_quota_max_objects;
63+
quota.bucket_quota.enabled = true;
6564
}
6665

6766
if (cct->_conf->rgw_bucket_default_quota_max_size >= 0) {
68-
bucket_quota.max_size = cct->_conf->rgw_bucket_default_quota_max_size;
69-
bucket_quota.enabled = true;
67+
quota.bucket_quota.max_size = cct->_conf->rgw_bucket_default_quota_max_size;
68+
quota.bucket_quota.enabled = true;
7069
}
7170

7271
if (cct->_conf->rgw_user_default_quota_max_objects >= 0) {
73-
user_quota.max_objects = cct->_conf->rgw_user_default_quota_max_objects;
74-
user_quota.enabled = true;
72+
quota.user_quota.max_objects = cct->_conf->rgw_user_default_quota_max_objects;
73+
quota.user_quota.enabled = true;
7574
}
7675

7776
if (cct->_conf->rgw_user_default_quota_max_size >= 0) {
78-
user_quota.max_size = cct->_conf->rgw_user_default_quota_max_size;
79-
user_quota.enabled = true;
77+
quota.user_quota.max_size = cct->_conf->rgw_user_default_quota_max_size;
78+
quota.user_quota.enabled = true;
8079
}
8180

82-
if (bucket_quota.enabled) {
83-
op_state.set_bucket_quota(bucket_quota);
81+
if (quota.bucket_quota.enabled) {
82+
op_state.set_bucket_quota(quota.bucket_quota);
8483
}
8584

86-
if (user_quota.enabled) {
87-
op_state.set_user_quota(user_quota);
85+
if (quota.user_quota.enabled) {
86+
op_state.set_user_quota(quota.user_quota);
8887
}
8988
}
9089

src/rgw/rgw_file.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,7 +1904,7 @@ namespace rgw {
19041904
return -EIO;
19051905
}
19061906

1907-
op_ret = state->bucket->check_quota(this, user_quota, bucket_quota, real_ofs, null_yield, true);
1907+
op_ret = state->bucket->check_quota(this, quota, real_ofs, null_yield, true);
19081908
/* max_size exceed */
19091909
if (op_ret < 0)
19101910
return -EIO;
@@ -1946,7 +1946,7 @@ namespace rgw {
19461946
goto done;
19471947
}
19481948

1949-
op_ret = state->bucket->check_quota(this, user_quota, bucket_quota, state->obj_size, null_yield, true);
1949+
op_ret = state->bucket->check_quota(this, quota, state->obj_size, null_yield, true);
19501950
/* max_size exceed */
19511951
if (op_ret < 0) {
19521952
goto done;

src/rgw/rgw_op.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,18 +1357,19 @@ int RGWOp::init_quota()
13571357
if (r < 0)
13581358
return r;
13591359
user = owner_user.get();
1360+
13601361
}
13611362

1362-
store->get_quota(bucket_quota, user_quota);
1363+
store->get_quota(quota);
13631364

13641365
if (s->bucket->get_info().quota.enabled) {
1365-
bucket_quota = s->bucket->get_info().quota;
1366-
} else if (user->get_info().bucket_quota.enabled) {
1367-
bucket_quota = user->get_info().bucket_quota;
1366+
quota.bucket_quota = s->bucket->get_info().quota;
1367+
} else if (user->get_info().quota.bucket_quota.enabled) {
1368+
quota.bucket_quota = user->get_info().quota.bucket_quota;
13681369
}
13691370

1370-
if (user->get_info().user_quota.enabled) {
1371-
user_quota = user->get_info().user_quota;
1371+
if (user->get_info().quota.user_quota.enabled) {
1372+
quota.user_quota = user->get_info().quota.user_quota;
13721373
}
13731374

13741375
return 0;
@@ -3901,7 +3902,7 @@ void RGWPutObj::execute(optional_yield y)
39013902

39023903
if (!chunked_upload) { /* with chunked upload we don't know how big is the upload.
39033904
we also check sizes at the end anyway */
3904-
op_ret = s->bucket->check_quota(this, user_quota, bucket_quota, s->content_length, y);
3905+
op_ret = s->bucket->check_quota(this, quota, s->content_length, y);
39053906
if (op_ret < 0) {
39063907
ldpp_dout(this, 20) << "check_quota() returned ret=" << op_ret << dendl;
39073908
return;
@@ -4124,7 +4125,7 @@ void RGWPutObj::execute(optional_yield y)
41244125
return;
41254126
}
41264127

4127-
op_ret = s->bucket->check_quota(this, user_quota, bucket_quota, s->obj_size, y);
4128+
op_ret = s->bucket->check_quota(this, quota, s->obj_size, y);
41284129
if (op_ret < 0) {
41294130
ldpp_dout(this, 20) << "second check_quota() returned op_ret=" << op_ret << dendl;
41304131
return;
@@ -4344,7 +4345,7 @@ void RGWPostObj::execute(optional_yield y)
43444345
ceph::buffer::list bl, aclbl;
43454346
int len = 0;
43464347

4347-
op_ret = s->bucket->check_quota(this, user_quota, bucket_quota, s->content_length, y);
4348+
op_ret = s->bucket->check_quota(this, quota, s->content_length, y);
43484349
if (op_ret < 0) {
43494350
return;
43504351
}
@@ -4449,7 +4450,7 @@ void RGWPostObj::execute(optional_yield y)
44494450
s->object->set_obj_size(ofs);
44504451

44514452

4452-
op_ret = s->bucket->check_quota(this, user_quota, bucket_quota, s->obj_size, y);
4453+
op_ret = s->bucket->check_quota(this, quota, s->obj_size, y);
44534454
if (op_ret < 0) {
44544455
return;
44554456
}
@@ -4625,7 +4626,7 @@ void RGWPutMetadataAccount::execute(optional_yield y)
46254626

46264627
/* Handle the quota extracted at the verify_permission step. */
46274628
if (new_quota_extracted) {
4628-
s->user->get_info().user_quota = std::move(new_quota);
4629+
s->user->get_info().quota.user_quota = std::move(new_quota);
46294630
}
46304631

46314632
/* We are passing here the current (old) user info to allow the function
@@ -5476,8 +5477,7 @@ void RGWCopyObj::execute(optional_yield y)
54765477
return;
54775478
}
54785479
// enforce quota against the destination bucket owner
5479-
op_ret = dest_bucket->check_quota(this, user_quota, bucket_quota,
5480-
astate->accounted_size, y);
5480+
op_ret = dest_bucket->check_quota(this, quota, astate->accounted_size, y);
54815481
if (op_ret < 0) {
54825482
return;
54835483
}
@@ -7419,7 +7419,7 @@ int RGWBulkUploadOp::handle_file(const std::string_view path,
74197419
return op_ret;
74207420
}
74217421

7422-
op_ret = bucket->check_quota(this, user_quota, bucket_quota, size, y);
7422+
op_ret = bucket->check_quota(this, quota, size, y);
74237423
if (op_ret < 0) {
74247424
return op_ret;
74257425
}
@@ -7497,7 +7497,7 @@ int RGWBulkUploadOp::handle_file(const std::string_view path,
74977497
return op_ret;
74987498
}
74997499

7500-
op_ret = bucket->check_quota(this, user_quota, bucket_quota, size, y);
7500+
op_ret = bucket->check_quota(this, quota, size, y);
75017501
if (op_ret < 0) {
75027502
ldpp_dout(this, 20) << "quota exceeded for path=" << path << dendl;
75037503
return op_ret;

src/rgw/rgw_op.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ class RGWOp : public DoutPrefixProvider {
178178
rgw::sal::Store* store;
179179
RGWCORSConfiguration bucket_cors;
180180
bool cors_exist;
181-
RGWQuotaInfo bucket_quota;
182-
RGWQuotaInfo user_quota;
181+
RGWQuota quota;
183182
int op_ret;
184183
int do_aws4_auth_completion();
185184

src/rgw/rgw_quota.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -903,13 +903,12 @@ class RGWQuotaHandlerImpl : public RGWQuotaHandler {
903903

904904
int check_quota(const DoutPrefixProvider *dpp,
905905
const rgw_user& user,
906-
rgw_bucket& bucket,
907-
RGWQuotaInfo& user_quota,
908-
RGWQuotaInfo& bucket_quota,
909-
uint64_t num_objs,
910-
uint64_t size, optional_yield y) override {
906+
rgw_bucket& bucket,
907+
RGWQuota& quota,
908+
uint64_t num_objs,
909+
uint64_t size, optional_yield y) override {
911910

912-
if (!bucket_quota.enabled && !user_quota.enabled) {
911+
if (!quota.bucket_quota.enabled && !quota.user_quota.enabled) {
913912
return 0;
914913
}
915914

@@ -921,25 +920,25 @@ class RGWQuotaHandlerImpl : public RGWQuotaHandler {
921920
*/
922921

923922
const DoutPrefix dp(store->ctx(), dout_subsys, "rgw quota handler: ");
924-
if (bucket_quota.enabled) {
923+
if (quota.bucket_quota.enabled) {
925924
RGWStorageStats bucket_stats;
926925
int ret = bucket_stats_cache.get_stats(user, bucket, bucket_stats, y, &dp);
927926
if (ret < 0) {
928927
return ret;
929928
}
930-
ret = check_quota(dpp, "bucket", bucket_quota, bucket_stats, num_objs, size);
929+
ret = check_quota(dpp, "bucket", quota.bucket_quota, bucket_stats, num_objs, size);
931930
if (ret < 0) {
932931
return ret;
933932
}
934933
}
935934

936-
if (user_quota.enabled) {
935+
if (quota.user_quota.enabled) {
937936
RGWStorageStats user_stats;
938937
int ret = user_stats_cache.get_stats(user, bucket, user_stats, y, &dp);
939938
if (ret < 0) {
940939
return ret;
941940
}
942-
ret = check_quota(dpp, "user", user_quota, user_stats, num_objs, size);
941+
ret = check_quota(dpp, "user", quota.user_quota, user_stats, num_objs, size);
943942
if (ret < 0) {
944943
return ret;
945944
}

src/rgw/rgw_quota.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace rgw { namespace sal {
3535
class Store;
3636
} }
3737

38+
3839
struct RGWQuotaInfo {
3940
template<class T> friend class RGWQuotaCache;
4041
public:
@@ -89,6 +90,12 @@ struct RGWQuotaInfo {
8990
};
9091
WRITE_CLASS_ENCODER(RGWQuotaInfo)
9192

93+
struct RGWQuota {
94+
RGWQuotaInfo user_quota;
95+
RGWQuotaInfo bucket_quota;
96+
};
97+
98+
9299
struct rgw_bucket;
93100

94101
class RGWQuotaHandler {
@@ -97,7 +104,7 @@ class RGWQuotaHandler {
97104
virtual ~RGWQuotaHandler() {
98105
}
99106
virtual int check_quota(const DoutPrefixProvider *dpp, const rgw_user& bucket_owner, rgw_bucket& bucket,
100-
RGWQuotaInfo& user_quota, RGWQuotaInfo& bucket_quota,
107+
RGWQuota& quota,
101108
uint64_t num_objs, uint64_t size, optional_yield y) = 0;
102109

103110
virtual void check_bucket_shards(const DoutPrefixProvider *dpp, uint64_t max_objs_per_shard, uint64_t num_shards,

0 commit comments

Comments
 (0)