From aeff69c8febacfcbeb25fd1dbfe658d36a155864 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 30 Oct 2017 15:38:23 -0700 Subject: [PATCH] rgw: http req, guard out_headers Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_cr_rest.cc | 11 ++++++----- src/rgw/rgw_rest_client.cc | 12 ++++++++++++ src/rgw/rgw_rest_client.h | 5 ++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/rgw/rgw_cr_rest.cc b/src/rgw/rgw_cr_rest.cc index 8ecfd2dec4b..3c0b597fb97 100644 --- a/src/rgw/rgw_cr_rest.cc +++ b/src/rgw/rgw_cr_rest.cc @@ -117,8 +117,7 @@ bool RGWStreamReadHTTPResourceCRF::has_attrs() void RGWStreamReadHTTPResourceCRF::get_attrs(std::map *attrs) { -#warning need to lock in_req->headers - *attrs = req->get_out_headers(); + req->get_out_headers(attrs); } int RGWStreamReadHTTPResourceCRF::decode_rest_obj(map& headers, bufferlist& extra_data, rgw_rest_obj *info) { @@ -147,7 +146,8 @@ int RGWStreamReadHTTPResourceCRF::read(bufferlist *out, uint64_t max_size, bool continue; } extra_data.claim_append(in_cb->get_extra_data()); - map attrs = req->get_out_headers(); + map attrs; + req->get_out_headers(&attrs); int ret = decode_rest_obj(attrs, extra_data, &rest_obj); if (ret < 0) { ldout(cct, 0) << "ERROR: " << __func__ << " decode_rest_obj() returned ret=" << ret << dendl; @@ -206,8 +206,9 @@ int RGWStreamWriteHTTPResourceCRF::drain_writes(bool *need_retry) *need_retry = !req->is_done(); } -#warning need to lock in_req->headers - handle_headers(req->get_out_headers()); + map headers; + req->get_out_headers(&headers); + handle_headers(headers); return req->get_req_retcode(); } diff --git a/src/rgw/rgw_rest_client.cc b/src/rgw/rgw_rest_client.cc index aa9639534b5..9a791866622 100644 --- a/src/rgw/rgw_rest_client.cc +++ b/src/rgw/rgw_rest_client.cc @@ -43,6 +43,8 @@ int RGWHTTPSimpleRequest::handle_header(const string& name, const string& val) int RGWHTTPSimpleRequest::receive_header(void *ptr, size_t len) { + unique_lock guard(out_headers_lock); + char line[len + 1]; char *s = (char *)ptr, *end = (char *)ptr + len; @@ -208,6 +210,13 @@ void RGWHTTPSimpleRequest::get_params_str(map& extra_args, strin } } +void RGWHTTPSimpleRequest::get_out_headers(map *pheaders) +{ + unique_lock guard(out_headers_lock); + pheaders->swap(out_headers); + out_headers.clear(); +} + static int sign_request(CephContext *cct, RGWAccessKey& key, RGWEnv& env, req_info& info) { /* don't sign if no key is provided */ @@ -670,6 +679,9 @@ int RGWRESTStreamRWRequest::complete_request(string& etag, real_time *mtime, uin if (ret < 0) { return ret; } + + unique_lock guard(out_headers_lock); + set_str_from_headers(out_headers, "ETAG", etag); if (status >= 0) { if (mtime) { diff --git a/src/rgw/rgw_rest_client.h b/src/rgw/rgw_rest_client.h index 5ab40a3cc91..277263bc972 100644 --- a/src/rgw/rgw_rest_client.h +++ b/src/rgw/rgw_rest_client.h @@ -13,6 +13,9 @@ protected: int http_status; int status; + using unique_lock = std::unique_lock; + + std::mutex out_headers_lock; map out_headers; param_vec_t params; @@ -51,7 +54,7 @@ public: bufferlist& get_response() { return response; } - map& get_out_headers() { return out_headers; } + void get_out_headers(map *pheaders); /* modifies out_headers */ int get_http_status() { return http_status; } int get_status(); -- 2.39.5