From: Zhang Shaowen Date: Tue, 17 Jan 2017 02:44:31 +0000 (+0800) Subject: rgw: modify error code in lifecycle to be compatible with S3. X-Git-Tag: v12.0.0~149^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=0781e00389a1a0e82b2fad98b2de68244637feb8;p=ceph-ci.git rgw: modify error code in lifecycle to be compatible with S3. Signed-off-by: Zhang Shaowen --- diff --git a/src/rgw/rgw_lc.cc b/src/rgw/rgw_lc.cc index d311731181a..29bd8ff1b7f 100644 --- a/src/rgw/rgw_lc.cc +++ b/src/rgw/rgw_lc.cc @@ -33,12 +33,12 @@ using namespace librados; bool LCRule::validate() { - if (id.length() > MAX_ID_LEN) + if (id.length() > MAX_ID_LEN) { return false; - else if (status.compare("Enabled") != 0 && status.compare("Disabled") != 0) - return false; - else if (expiration.get_days() <= 0) + } + else if (expiration.get_days() <= 0) { return false; + } return true; } @@ -55,29 +55,33 @@ void RGWLifecycleConfiguration::_add_rule(LCRule *rule) prefix_map[rule->get_prefix()] = rule->get_expiration().get_days(); } -bool RGWLifecycleConfiguration::check_and_add_rule(LCRule *rule) +int RGWLifecycleConfiguration::check_and_add_rule(LCRule *rule) { - if (!rule->validate()) - return false; + if (!rule->validate()) { + return -EINVAL; + } string id; rule->get_id(id); - if (rule_map.find(id) != rule_map.end()) //id shouldn't be the same - return false; + if (rule_map.find(id) != rule_map.end()) { //id shouldn't be the same + return -EINVAL; + } rule_map.insert(pair(id, *rule)); auto ret = prefix_map.insert(pair(rule->get_prefix(), rule->get_expiration().get_days())); //Now prefix shouldn't be the same. When we add noncurrent expiration or other action, prefix may be same. - if (!ret.second) - return false; - return true; + if (!ret.second) { + return -ERR_INVALID_REQUEST; + } + return 0; } //Rules are conflicted: if one rule's prefix starts with other rule's prefix, and these two rules //define same action(now only support expiration days). bool RGWLifecycleConfiguration::validate() { - if (prefix_map.size() < 2) + if (prefix_map.size() < 2) { return true; + } auto next_iter = prefix_map.begin(); auto cur_iter = next_iter++; while (next_iter != prefix_map.end()) { diff --git a/src/rgw/rgw_lc.h b/src/rgw/rgw_lc.h index c33032f1c11..5436abcdf1a 100644 --- a/src/rgw/rgw_lc.h +++ b/src/rgw/rgw_lc.h @@ -165,7 +165,7 @@ public: void add_rule(LCRule* rule); - bool check_and_add_rule(LCRule* rule); + int check_and_add_rule(LCRule* rule); bool validate(); diff --git a/src/rgw/rgw_lc_s3.cc b/src/rgw/rgw_lc_s3.cc index c42b2975c59..98695b88c54 100644 --- a/src/rgw/rgw_lc_s3.cc +++ b/src/rgw/rgw_lc_s3.cc @@ -57,6 +57,8 @@ bool LCRule_S3::xml_end(const char *el) { if (!lc_status) return false; status = lc_status->get_data(); + if (status.compare("Enabled") != 0 && status.compare("Disabled") != 0) + return false; lc_expiration = static_cast(find_first("Expiration")); if (!lc_expiration) @@ -78,15 +80,18 @@ void LCRule_S3::to_xml(CephContext *cct, ostream& out) { int RGWLifecycleConfiguration_S3::rebuild(RGWRados *store, RGWLifecycleConfiguration& dest) { + int ret = 0; multimap::iterator iter; for (iter = rule_map.begin(); iter != rule_map.end(); ++iter) { LCRule& src_rule = iter->second; - if (!dest.check_and_add_rule(&src_rule)) - return -EINVAL; + ret = dest.check_and_add_rule(&src_rule); + if (ret < 0) + return ret; + } + if (!dest.validate()) { + ret = -ERR_INVALID_REQUEST; } - if (!dest.validate()) - return -EINVAL; - return 0; + return ret; } void RGWLifecycleConfiguration_S3::dump_xml(Formatter *f) const diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 9691dcb3c09..8f25240f4e8 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -4236,12 +4236,12 @@ void RGWPutLC::execute() ldout(s->cct, 15) << "read len=" << len << " data=" << (data ? data : "") << dendl; if (!parser.parse(data, len, 1)) { - op_ret = -EINVAL; + op_ret = -ERR_MALFORMED_XML; return; } config = static_cast(parser.find_first("LifecycleConfiguration")); if (!config) { - op_ret = -EINVAL; + op_ret = -ERR_MALFORMED_XML; return; }