]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: http req, guard out_headers
authorYehuda Sadeh <yehuda@redhat.com>
Mon, 30 Oct 2017 22:38:23 +0000 (15:38 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Tue, 10 Apr 2018 15:05:39 +0000 (08:05 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_cr_rest.cc
src/rgw/rgw_rest_client.cc
src/rgw/rgw_rest_client.h

index 8ecfd2dec4b8dba2059d436aef174a057a8706dd..3c0b597fb979b4a42411aa084464833324ecdae2 100644 (file)
@@ -117,8 +117,7 @@ bool RGWStreamReadHTTPResourceCRF::has_attrs()
 
 void RGWStreamReadHTTPResourceCRF::get_attrs(std::map<string, string> *attrs)
 {
-#warning need to lock in_req->headers
-  *attrs = req->get_out_headers();
+  req->get_out_headers(attrs);
 }
 
 int RGWStreamReadHTTPResourceCRF::decode_rest_obj(map<string, string>& 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<string, string> attrs = req->get_out_headers();
+        map<string, string> 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<string, string> headers;
+    req->get_out_headers(&headers);
+    handle_headers(headers);
 
     return req->get_req_retcode();
   }
index aa9639534b555c6bd45c7c758a3ff029e19b2a91..9a791866622bb5062741c7fefcba04f78dc13e2d 100644 (file)
@@ -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<string, string>& extra_args, strin
   }
 }
 
+void RGWHTTPSimpleRequest::get_out_headers(map<string, string> *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) {
index 5ab40a3cc91c4edf3cc648d2f0206bbb629d695d..277263bc9723a322b3a01556eed2e7620c89d3d0 100644 (file)
@@ -13,6 +13,9 @@ protected:
   int http_status;
   int status;
 
+  using unique_lock = std::unique_lock<std::mutex>;
+
+  std::mutex out_headers_lock;
   map<string, string> out_headers;
   param_vec_t params;
 
@@ -51,7 +54,7 @@ public:
 
   bufferlist& get_response() { return response; }
 
-  map<string, string>& get_out_headers() { return out_headers; }
+  void get_out_headers(map<string, string> *pheaders); /* modifies out_headers */
 
   int get_http_status() { return http_status; }
   int get_status();