]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: modify error code in lifecycle to be compatible with S3.
authorZhang Shaowen <zhangshaowen@cmss.chinamobile.com>
Tue, 17 Jan 2017 02:44:31 +0000 (10:44 +0800)
committerZhang Shaowen <zhangshaowen@cmss.chinamobile.com>
Tue, 17 Jan 2017 02:44:31 +0000 (10:44 +0800)
Signed-off-by: Zhang Shaowen <zhangshaowen@cmss.chinamobile.com>
src/rgw/rgw_lc.cc
src/rgw/rgw_lc.h
src/rgw/rgw_lc_s3.cc
src/rgw/rgw_op.cc

index d311731181a6b5c9b4c9028daa23a572fc38a2c0..29bd8ff1b7fd13972a9b0fe85b66442d1582ae93 100644 (file)
@@ -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<string, LCRule>(id, *rule));
 
   auto ret = prefix_map.insert(pair<string, int>(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()) {
index c33032f1c11320a438ca97ab6d62bc9f4291a112..5436abcdf1a733ace85b508d4adfb8d23d6e6e2b 100644 (file)
@@ -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();
 
index c42b2975c598414fdb34b30a34bde9291f1288d6..98695b88c54a02fc0591845e2af9b1a0d1011b8f 100644 (file)
@@ -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<LCExpiration_S3 *>(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<string, LCRule>::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
index 9691dcb3c09f6fefb557908869e8c60bce7eda61..8f25240f4e8c6fd9a628a7f5d2cfc3e502fea459 100644 (file)
@@ -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<RGWLifecycleConfiguration_S3 *>(parser.find_first("LifecycleConfiguration"));
   if (!config) {
-    op_ret = -EINVAL;
+    op_ret = -ERR_MALFORMED_XML;
     return;
   }