]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: handle the situation that get a 409 response from S3 correctly
authorlvshanchun <lvshanchun@gmail.com>
Wed, 29 Nov 2017 13:04:12 +0000 (21:04 +0800)
committerYehuda Sadeh <yehuda@redhat.com>
Thu, 12 Apr 2018 22:38:37 +0000 (15:38 -0700)
pass the http body and use it when creating a bucket

Signed-off-by: lvshanchun <lvshanchun@gmail.com>
src/rgw/rgw_rest_conn.h
src/rgw/rgw_sync_module_aws.cc

index 76a462fa09e1ba753034b8aab230fb8df5ffa2ec..416a63cd0f4cb6aa0496337b161d78a71c33a8d7 100644 (file)
@@ -411,6 +411,7 @@ public:
 
   int wait(bufferlist *pbl) {
     int ret = req.wait();
+    *pbl = bl;
     if (ret < 0) {
       return ret;
     }
@@ -418,7 +419,6 @@ public:
     if (req.get_status() < 0) {
       return req.get_status();
     }
-    *pbl = bl;
     return 0;
   }
 
index 7c1e495a2817b24d7535a75ece1bfcfd4db83716..9d29fbd10e7d0acfd57d49d86f735da6c34dde82 100644 (file)
@@ -767,6 +767,16 @@ class RGWAWSHandleRemoteObjCBCR: public RGWStatRemoteObjCBCR {
   uint32_t src_zone_short_id{0};
   uint64_t src_pg_ver{0};
 
+  bufferlist out_bl;
+
+  struct CreateBucketResult {
+    string code;
+
+    void decode_xml(XMLObj *obj) {
+      RGWXMLDecoder::decode_xml("Code", code, obj);
+    }
+  } result;
+
 public:
   RGWAWSHandleRemoteObjCBCR(RGWDataSyncEnv *_sync_env,
                             RGWBucketInfo& _bucket_info,
@@ -808,12 +818,34 @@ public:
         yield {
           ldout(sync_env->cct,0) << "AWS: creating bucket" << target_bucket_name << dendl;
           bufferlist bl;
-          call(new RGWPutRawRESTResourceCR <int> (sync_env->cct, instance.conn.get(),
+          call(new RGWPutRawRESTResourceCR <bufferlist> (sync_env->cct, instance.conn.get(),
                                                   sync_env->http_manager,
-                                                  target_bucket_name, nullptr, bl, nullptr));
+                                                  target_bucket_name, nullptr, bl, &out_bl));
         }
-        if (retcode < 0) {
-          return set_cr_error(retcode);
+        if (retcode < 0 ) {
+          RGWXMLDecoder::XMLParser parser;
+          if (!parser.init()) {
+            ldout(sync_env->cct, 0) << "ERROR: failed to initialize xml parser for parsing multipart init response from server" << dendl;
+            return set_cr_error(retcode);
+          }
+
+          if (!parser.parse(out_bl.c_str(), out_bl.length(), 1)) {
+            string str(out_bl.c_str(), out_bl.length());
+            ldout(sync_env->cct, 5) << "ERROR: failed to parse xml: " << str << dendl;
+            return set_cr_error(retcode);
+          }
+
+          try {
+            RGWXMLDecoder::decode_xml("Error", result, &parser, true);
+          } catch (RGWXMLDecoder::err& err) {
+            string str(out_bl.c_str(), out_bl.length());
+            ldout(sync_env->cct, 5) << "ERROR: unexpected xml: " << str << dendl;
+            return set_cr_error(retcode);
+          }
+
+          if (result.code != "BucketAlreadyOwnedByYou") {
+            return set_cr_error(retcode);
+          }
         }
 
         bucket_created[target_bucket_name] = true;