From: Jiaying Ren Date: Thu, 25 May 2017 12:17:46 +0000 (+0800) Subject: rgw/multisite: check location constraint existness X-Git-Tag: v12.1.0~61^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F15333%2Fhead;p=ceph.git rgw/multisite: check location constraint existness to match the behavior of AWS S3 Signed-off-by: Jiaying Ren --- diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 3a2fbdfee3b8..5b98e50fdb68 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -2394,6 +2394,15 @@ void RGWCreateBucket::execute() if (op_ret < 0) 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() && store->get_zonegroup().api_name != location_constraint) { ldout(s->cct, 0) << "location constraint (" << location_constraint << ")" diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 24bb8bb3cb12..4e81cbe4fcf3 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -2465,6 +2465,16 @@ public: const string& get_current_period_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 std::unique_ptr period_puller; // maintains a connected history of periods