From: lvshanchun Date: Wed, 29 Nov 2017 13:04:12 +0000 (+0800) Subject: rgw: handle the situation that get a 409 response from S3 correctly X-Git-Tag: v13.1.0~270^2~38 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=056738d86365e9d0bb881046e76f91ce98870ed2;p=ceph.git rgw: handle the situation that get a 409 response from S3 correctly pass the http body and use it when creating a bucket Signed-off-by: lvshanchun --- diff --git a/src/rgw/rgw_rest_conn.h b/src/rgw/rgw_rest_conn.h index 76a462fa09e1b..416a63cd0f4cb 100644 --- a/src/rgw/rgw_rest_conn.h +++ b/src/rgw/rgw_rest_conn.h @@ -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; } diff --git a/src/rgw/rgw_sync_module_aws.cc b/src/rgw/rgw_sync_module_aws.cc index 7c1e495a2817b..9d29fbd10e7d0 100644 --- a/src/rgw/rgw_sync_module_aws.cc +++ b/src/rgw/rgw_sync_module_aws.cc @@ -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 (sync_env->cct, instance.conn.get(), + call(new RGWPutRawRESTResourceCR (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;