rgw/multisite: check location constraint existness

to match the behavior of AWS S3

Signed-off-by: Jiaying Ren <jiaying.ren@umcloud.com>
This commit is contained in:
Jiaying Ren 2017-05-25 20:17:46 +08:00
parent 96db3d7fd0
commit 25e4d1e454
2 changed files with 19 additions and 0 deletions

View File

@ -2394,6 +2394,15 @@ void RGWCreateBucket::execute()
if (op_ret < 0) if (op_ret < 0)
return; return;
if (!location_constraint.empty() &&
!store->has_zonegroup_api(location_constraint)) {
ldout(s->cct, 0) << "location constraint (" << location_constraint << ")"
<< " can't be found." << dendl;
op_ret = -ERR_INVALID_LOCATION_CONSTRAINT;
s->err.message = "The specified location-constraint is not valid";
return;
}
if (!store->get_zonegroup().is_master_zonegroup() && if (!store->get_zonegroup().is_master_zonegroup() &&
store->get_zonegroup().api_name != location_constraint) { store->get_zonegroup().api_name != location_constraint) {
ldout(s->cct, 0) << "location constraint (" << location_constraint << ")" ldout(s->cct, 0) << "location constraint (" << location_constraint << ")"

View File

@ -2465,6 +2465,16 @@ public:
const string& get_current_period_id() { const string& get_current_period_id() {
return current_period.get_id(); return current_period.get_id();
} }
bool has_zonegroup_api(const std::string& api) const {
if (!current_period.get_id().empty()) {
const auto& zonegroups_by_api = current_period.get_map().zonegroups_by_api;
if (zonegroups_by_api.find(api) != zonegroups_by_api.end())
return true;
}
return false;
}
// pulls missing periods for period_history // pulls missing periods for period_history
std::unique_ptr<RGWPeriodPuller> period_puller; std::unique_ptr<RGWPeriodPuller> period_puller;
// maintains a connected history of periods // maintains a connected history of periods