]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: send meta headers with remote PUT request
authorYehuda Sadeh <yehuda@inktank.com>
Mon, 10 Jun 2013 21:27:36 +0000 (14:27 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Mon, 10 Jun 2013 21:28:03 +0000 (14:28 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_rados.cc
src/rgw/rgw_rest_client.cc
src/rgw/rgw_rest_client.h
src/rgw/rgw_rest_conn.cc
src/rgw/rgw_rest_conn.h

index b0ede4ff9df52d364de7f32d76d16b6eff9de43c..0583ba014bcf4b344cd33838fdb01c3c4fc610a8 100644 (file)
@@ -1953,7 +1953,7 @@ int RGWRados::copy_obj(void *ctx,
 
     RGWRESTStreamRequest *out_stream_req;
   
-    int ret = rest_conn->put_obj_init(user_id, dest_obj, astate->size, &out_stream_req);
+    int ret = rest_conn->put_obj_init(user_id, dest_obj, astate->size, attrset, &out_stream_req);
     if (ret < 0)
       return ret;
 
index 1a85aa5c764e835d4434dafd88983d63363f679e..c7e11a95841708b471944d045487bdb95bf4cc47 100644 (file)
@@ -281,10 +281,10 @@ int RGWRESTStreamRequest::add_output_data(bufferlist& bl)
   lock.Unlock();
 
   bool done;
-  return process_request(handle, &done);
+  return process_request(handle, false, &done);
 }
 
-int RGWRESTStreamRequest::put_obj_init(RGWAccessKey& key, rgw_obj& obj, uint64_t obj_size)
+int RGWRESTStreamRequest::put_obj_init(RGWAccessKey& key, rgw_obj& obj, uint64_t obj_size, map<string, bufferlist>& attrs)
 {
   string resource = obj.bucket.name + "/" + obj.object;
   string new_url = url;
@@ -318,6 +318,19 @@ int RGWRESTStreamRequest::put_obj_init(RGWAccessKey& key, rgw_obj& obj, uint64_t
   }
 
   map<string, string>& m = new_env.get_map();
+  map<string, bufferlist>::iterator bliter;
+
+  /* merge send headers */
+  for (bliter = attrs.begin(); bliter != attrs.end(); ++bliter) {
+    bufferlist& bl = bliter->second;
+    const string& name = bliter->first;
+    string val(bl.c_str(), bl.length());
+    if (name.compare(0, sizeof(RGW_ATTR_META_PREFIX) - 1, RGW_ATTR_META_PREFIX) == 0) {
+      string header_name = RGW_AMZ_META_PREFIX;
+      header_name.append(name.substr(sizeof(RGW_ATTR_META_PREFIX) - 1));
+      m[header_name] = val;
+    }
+  }
   map<string, string>::iterator iter;
   for (iter = m.begin(); iter != m.end(); ++iter) {
     headers.push_back(make_pair<string, string>(iter->first, iter->second));
@@ -361,12 +374,14 @@ int RGWRESTStreamRequest::send_data(void *ptr, size_t len)
     sent += send_len;
 
     lock.Lock();
-    pending_send.pop_front();
 
+    bufferlist new_bl;
     if (bl.length() > send_len) {
       bufferptr bp(bl.c_str() + send_len, bl.length() - send_len);
-      bufferlist new_bl;
       new_bl.append(bp);
+    }
+    pending_send.pop_front(); /* need to do this after we copy data from bl */
+    if (new_bl.length()) {
       pending_send.push_front(new_bl);
     }
     iter = next_iter;
index 48a0bf04a1d6cba6161995c12196702e668bbf71..f3f9f7ff91c36d422140689894bd72580a808619 100644 (file)
@@ -46,6 +46,8 @@ public:
 
   int execute(RGWAccessKey& key, const char *method, const char *resource);
   int forward_request(RGWAccessKey& key, req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl);
+
+  map<string, string>& get_out_headers() { return out_headers; }
 };
 
 
@@ -62,7 +64,7 @@ public:
                 list<pair<string, string> > *_params) : RGWRESTSimpleRequest(_cct, _url, _headers, _params),
                 lock("RGWRESTStreamRequest"), handle(NULL), cb(NULL) {}
   ~RGWRESTStreamRequest();
-  int put_obj_init(RGWAccessKey& key, rgw_obj& obj, uint64_t obj_size);
+  int put_obj_init(RGWAccessKey& key, rgw_obj& obj, uint64_t obj_size, map<string, bufferlist>& attrs);
   int complete();
 
   RGWGetDataCB *get_out_cb() { return cb; }
index cba8548d3b4f6e6e03d123cdb77be75caaa1bfb3..8dc2c502d537ef7b0a771b633c1cfd46d7c26421 100644 (file)
@@ -46,7 +46,8 @@ public:
     StreamObjData(rgw_obj& _obj) : obj(_obj) {}
 };
 
-int RGWRegionConnection::put_obj_init(const string& uid, rgw_obj& obj, uint64_t obj_size, RGWRESTStreamRequest **req)
+int RGWRegionConnection::put_obj_init(const string& uid, rgw_obj& obj, uint64_t obj_size,
+                                      map<string, bufferlist>& attrs, RGWRESTStreamRequest **req)
 {
   string url;
   int ret = get_url(url);
@@ -57,7 +58,7 @@ int RGWRegionConnection::put_obj_init(const string& uid, rgw_obj& obj, uint64_t
   params.push_back(make_pair<string, string>(RGW_SYS_PARAM_PREFIX "uid", uid));
   params.push_back(make_pair<string, string>(RGW_SYS_PARAM_PREFIX "region", region));
   *req = new RGWRESTStreamRequest(cct, url, NULL, &params);
-  return (*req)->put_obj_init(key, obj, obj_size);
+  return (*req)->put_obj_init(key, obj, obj_size, attrs);
 }
 
 int RGWRegionConnection::complete_request(RGWRESTStreamRequest *req)
index 1554e513db144a56f8aeeceea7ae1e9932f4e740..5119cdc250e1eeaac324ea218e3f48a42dc34ff5 100644 (file)
@@ -24,7 +24,8 @@ public:
   int forward(const string& uid, req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl);
 
   /* async request */
-  int put_obj_init(const string& uid, rgw_obj& obj, uint64_t obj_size, RGWRESTStreamRequest **req);
+  int put_obj_init(const string& uid, rgw_obj& obj, uint64_t obj_size,
+                   map<string, bufferlist>& attrs, RGWRESTStreamRequest **req);
   int complete_request(RGWRESTStreamRequest *req);
 };