summaryrefslogtreecommitdiffstats
path: root/src/rgw/rgw_rest_conn.cc
diff options
context:
space:
mode:
authorYehuda Sadeh <yehuda@redhat.com>2015-07-11 02:10:25 +0200
committerYehuda Sadeh <yehuda@redhat.com>2016-02-09 21:57:08 +0100
commitfe0c78587aa24ada6f990d3c454e7e13f14fc68e (patch)
tree68985b95b94ef3c5e3441e99fcdc0765edd1812f /src/rgw/rgw_rest_conn.cc
parentrgw: more http aio stuff (diff)
downloadceph-fe0c78587aa24ada6f990d3c454e7e13f14fc68e.tar.xz
ceph-fe0c78587aa24ada6f990d3c454e7e13f14fc68e.zip
rgw: add new class to create resource request
RGWRESTReadResource holds the request input and output. Previously we were using stack variables that couldn't be used in the async path. Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
Diffstat (limited to 'src/rgw/rgw_rest_conn.cc')
-rw-r--r--src/rgw/rgw_rest_conn.cc67
1 files changed, 50 insertions, 17 deletions
diff --git a/src/rgw/rgw_rest_conn.cc b/src/rgw/rgw_rest_conn.cc
index ed435995691..815789c9965 100644
--- a/src/rgw/rgw_rest_conn.cc
+++ b/src/rgw/rgw_rest_conn.cc
@@ -30,6 +30,20 @@ int RGWRESTConn::get_url(string& endpoint)
return 0;
}
+string RGWRESTConn::get_url()
+{
+ string endpoint;
+ if (endpoints.empty()) {
+ ldout(cct, 0) << "WARNING: endpoints not configured for upstream zone" << dendl; /* we'll catch this later */
+ return endpoint;
+ }
+
+ int i = counter.inc();
+ endpoint = endpoints[i % endpoints.size()];
+
+ return endpoint;
+}
+
int RGWRESTConn::forward(const rgw_user& uid, req_info& info, obj_version *objv, size_t max_response, bufferlist *inbl, bufferlist *outbl)
{
string url;
@@ -122,16 +136,6 @@ int RGWRESTConn::complete_request(RGWRESTStreamReadRequest *req, string& etag, t
return ret;
}
-class StreamIntoBufferlist : public RGWGetDataCB {
- bufferlist& bl;
-public:
- StreamIntoBufferlist(bufferlist& _bl) : bl(_bl) {}
- int handle_data(bufferlist& inbl, off_t bl_ofs, off_t bl_len) {
- bl.claim_append(inbl);
- return bl_len;
- }
-};
-
int RGWRESTConn::get_resource(const string& resource,
list<pair<string, string> > *extra_params,
map<string, string> *extra_headers,
@@ -154,7 +158,7 @@ int RGWRESTConn::get_resource(const string& resource,
params.push_back(pair<string, string>(RGW_SYS_PARAM_PREFIX "region", region));
- StreamIntoBufferlist cb(bl);
+ RGWStreamIntoBufferlist cb(bl);
RGWRESTStreamReadRequest req(cct, url, &cb, NULL, &params);
@@ -177,11 +181,12 @@ int RGWRESTConn::get_resource(const string& resource,
return req.complete(etag, NULL, attrs);
}
-int RGWRESTConn::send_get_resource(const string& resource, const rgw_http_param_pair *pp,
- bufferlist &bl, RGWHTTPManager *mgr)
-{
- list<pair<string, string> > params;
-
+RGWRESTReadResource::RGWRESTReadResource(RGWRESTConn *_conn,
+ const string& _resource,
+ const rgw_http_param_pair *pp,
+ list<pair<string, string> > *extra_headers,
+ RGWHTTPManager *_mgr) : cct(_conn->get_ctx()), conn(_conn), resource(_resource), cb(bl),
+ mgr(_mgr), req(cct, conn->get_url(), &cb, NULL, NULL) {
while (pp && pp->key) {
string k = pp->key;
string v = (pp->val ? pp->val : "");
@@ -189,8 +194,36 @@ int RGWRESTConn::send_get_resource(const string& resource, const rgw_http_param_
++pp;
}
- int ret = get_resource(resource, &params, NULL, bl, mgr);
+ params.push_back(pair<string, string>(RGW_SYS_PARAM_PREFIX "region", conn->get_region()));
+
+ if (extra_headers) {
+ for (list<pair<string, string> >::iterator iter = extra_headers->begin();
+ iter != extra_headers->end(); ++iter) {
+ headers[iter->first] = iter->second;
+ }
+ }
+
+ req.set_params(&params);
+}
+
+int RGWRESTReadResource::read()
+{
+ int ret = req.get_resource(conn->get_key(), headers, resource, mgr);
+ if (ret < 0) {
+ ldout(cct, 0) << __func__ << ": get_resource() resource=" << resource << " returned ret=" << ret << dendl;
+ return ret;
+ }
+
+ string etag;
+ map<string, string> attrs;
+ return req.complete(etag, NULL, attrs);
+}
+
+int RGWRESTReadResource::aio_read()
+{
+ int ret = req.get_resource(conn->get_key(), headers, resource, mgr);
if (ret < 0) {
+ ldout(cct, 0) << __func__ << ": get_resource() resource=" << resource << " returned ret=" << ret << dendl;
return ret;
}