Skip to content

Commit de64166

Browse files
committed
rgw/logging: add quota enforcement to bucket logging
Signed-off-by: Yuval Lifshitz <[email protected]>
1 parent b633b6e commit de64166

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/rgw/rgw_bucket_logging.cc

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,12 @@ int commit_logging_object(const configuration& conf,
305305
target_bucket->get_key() << "'. ret = " << ret << dendl;
306306
return ret;
307307
}
308-
return target_bucket->commit_logging_object(obj_name, y, dpp);
308+
if (const auto ret = target_bucket->commit_logging_object(obj_name, y, dpp); ret <0 ) {
309+
ldpp_dout(dpp, 1) << "ERROR: failed to commit logging object '" << obj_name << "' of bucket '" <<
310+
target_bucket->get_key() << "'. ret = " << ret << dendl;
311+
return ret;
312+
}
313+
return 0;
309314
}
310315

311316
int rollover_logging_object(const configuration& conf,
@@ -548,6 +553,32 @@ int log_record(rgw::sal::Driver* driver,
548553
return -EINVAL;
549554
}
550555

556+
// get quota of the owner of the target bucket
557+
RGWQuota user_quota;
558+
if (ret = get_owner_quota_info(dpp, y, driver, target_bucket->get_owner(), user_quota); ret < 0) {
559+
ldpp_dout(dpp, 1) << "ERROR: failed to get quota of owner of target logging bucket '" <<
560+
target_bucket_id << "' failed. ret = " << ret << dendl;
561+
return ret;
562+
}
563+
// start with system default quota
564+
// and combine with the user quota
565+
RGWQuota quota;
566+
driver->get_quota(quota);
567+
if (target_bucket->get_info().quota.enabled) {
568+
quota.bucket_quota = target_bucket->get_info().quota;
569+
} else if (user_quota.bucket_quota.enabled) {
570+
quota.bucket_quota = user_quota.bucket_quota;
571+
}
572+
if (user_quota.user_quota.enabled) {
573+
quota.user_quota = user_quota.user_quota;
574+
}
575+
// verify there is enough quota to write the record
576+
if (ret = target_bucket->check_quota(dpp, quota, record.length(), y); ret < 0) {
577+
ldpp_dout(dpp, 1) << "ERROR: quota check on target logging bucket '" <<
578+
target_bucket_id << "' failed. ret = " << ret << dendl;
579+
return ret;
580+
}
581+
551582
if (ret = target_bucket->write_logging_object(obj_name,
552583
record,
553584
y,

src/rgw/rgw_op.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ int RGWOp::do_aws4_auth_completion()
14961496
return 0;
14971497
}
14981498

1499-
static int get_owner_quota_info(DoutPrefixProvider* dpp,
1499+
int get_owner_quota_info(const DoutPrefixProvider* dpp,
15001500
optional_yield y,
15011501
rgw::sal::Driver* driver,
15021502
const rgw_owner& owner,

src/rgw/rgw_op.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ std::tuple<bool, bool> rgw_check_policy_condition(const DoutPrefixProvider *dpp,
8888

8989
int rgw_iam_add_buckettags(const DoutPrefixProvider *dpp, req_state* s);
9090

91+
int get_owner_quota_info(const DoutPrefixProvider* dpp,
92+
optional_yield y,
93+
rgw::sal::Driver* driver,
94+
const rgw_owner& owner,
95+
RGWQuota& quotas);
96+
9197
class RGWHandler {
9298
protected:
9399
rgw::sal::Driver* driver{nullptr};

0 commit comments

Comments
 (0)