ceph::bufferlist response;
rgw_user user;
- int ret = conn->forward(dpp(), user, info, MAX_REST_RESPONSE, &in_data, &response, null_yield);
+ auto result = conn->forward(dpp(), user, info, MAX_REST_RESPONSE, &in_data, &response, null_yield);
+ if (!result) {
+ return result.error();
+ }
+ int ret = rgw_http_error_to_errno(*result);
+ if (ret < 0) {
+ return ret;
+ }
- int parse_ret = parser.parse(response.c_str(), response.length());
- if (parse_ret < 0) {
+ ret = parser.parse(response.c_str(), response.length());
+ if (ret < 0) {
cerr << "failed to parse response" << std::endl;
- return parse_ret;
+ return ret;
}
- return ret;
+ return 0;
}
static int send_to_url(const string& url,
RGWRESTSimpleRequest req(g_ceph_context, info.method, url, NULL, ¶ms, opt_region);
bufferlist response;
- int ret = req.forward_request(dpp(), key, info, MAX_REST_RESPONSE, &in_data, &response, null_yield);
+ auto result = req.forward_request(dpp(), key, info, MAX_REST_RESPONSE, &in_data, &response, null_yield);
+ if (!result) {
+ return result.error();
+ }
+ int ret = rgw_http_error_to_errno(*result);
+ if (ret < 0) {
+ return ret;
+ }
- int parse_ret = parser.parse(response.c_str(), response.length());
- if (parse_ret < 0) {
+ ret = parser.parse(response.c_str(), response.length());
+ if (ret < 0) {
cout << "failed to parse response" << std::endl;
- return parse_ret;
+ return ret;
}
- return ret;
+ return 0;
}
static int send_to_remote_or_url(RGWRESTConn *conn, const string& url,
creds, site.get_zonegroup().id, zg->second.api_name};
bufferlist outdata;
constexpr size_t max_response_size = 128 * 1024; // we expect a very small response
- int ret = conn.forward(dpp, effective_owner, req,
- max_response_size, indata, &outdata, y);
+ auto result = conn.forward(dpp, effective_owner, req,
+ max_response_size, indata, &outdata, y);
+ if (!result) {
+ return result.error();
+ }
+ int ret = rgw_http_error_to_errno(*result);
if (ret < 0) {
return ret;
}
#include "rgw_rados.h"
#include "rgw_zone.h"
#include "rgw_rest_conn.h"
+#include "rgw_http_errors.h"
#include "common/ceph_json.h"
#include "common/errno.h"
bufferlist data;
#define MAX_REST_RESPONSE (128 * 1024)
- int r = conn->forward(dpp, user, info, MAX_REST_RESPONSE, nullptr, &data, y);
+ auto result = conn->forward(dpp, user, info, MAX_REST_RESPONSE, nullptr, &data, y);
+ if (!result) {
+ return result.error();
+ }
+ int r = rgw_http_error_to_errno(*result);
if (r < 0) {
return r;
}
}
}
-int RGWRESTSimpleRequest::forward_request(const DoutPrefixProvider *dpp, const RGWAccessKey& key, const req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl, optional_yield y, std::string service)
+auto RGWRESTSimpleRequest::forward_request(const DoutPrefixProvider *dpp, const RGWAccessKey& key, const req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl, optional_yield y, std::string service)
+ -> tl::expected<int, int>
{
string date_str;
int ret = sign_request(dpp, key, region, s, new_env, new_info, nullptr);
if (ret < 0) {
ldpp_dout(dpp, 0) << "ERROR: failed to sign request" << dendl;
- return ret;
+ return tl::unexpected(ret);
}
if (s == "iam") {
method = new_info.method;
url = new_url;
- int r = process(dpp, y);
- if (r < 0) {
- if (http_status == 0) {
- // no http status, generally means the service is not available
- r = -ERR_SERVICE_UNAVAILABLE;
- }
- return r;
+ std::ignore = process(dpp, y);
+
+ if (http_status == 0) {
+ // no http status, generally means the service is not available
+ return tl::unexpected(-ERR_SERVICE_UNAVAILABLE);
}
response.append((char)0); /* NULL terminate response */
*outbl = std::move(response);
}
- return status;
+ return http_status;
}
class RGWRESTStreamOutCB : public RGWGetDataCB {
#pragma once
+#include "include/expected.hpp"
#include "rgw_http_client.h"
class RGWGetDataCB;
param_vec_t *_headers, param_vec_t *_params,
std::optional<std::string> _api_name) : RGWHTTPSimpleRequest(_cct, _method, _url, _headers, _params), api_name(_api_name) {}
- int forward_request(const DoutPrefixProvider *dpp, const RGWAccessKey& key, const req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl, optional_yield y, std::string service="");
+ // return the http status of the response or an error code from the transport
+ auto forward_request(const DoutPrefixProvider *dpp, const RGWAccessKey& key, const req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl, optional_yield y, std::string service="")
+ -> tl::expected<int, int>;
};
class RGWWriteDrainCB {
#include "rgw_zone.h"
#include "rgw_rest_conn.h"
+#include "rgw_http_errors.h"
#include "rgw_sal.h"
#include "rgw_rados.h"
populate_zonegroup(params, zonegroup);
}
-int RGWRESTConn::forward(const DoutPrefixProvider *dpp, const rgw_owner& uid, const req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl, optional_yield y)
+auto RGWRESTConn::forward(const DoutPrefixProvider *dpp, const rgw_owner& uid,
+ const req_info& info, size_t max_response,
+ bufferlist *inbl, bufferlist *outbl, optional_yield y)
+ -> tl::expected<int, int>
{
- int ret = 0;
-
static constexpr int NUM_ENPOINT_IOERROR_RETRIES = 20;
for (int tries = 0; tries < NUM_ENPOINT_IOERROR_RETRIES; tries++) {
string url;
- ret = get_url(url);
- if (ret < 0)
- return ret;
+ int ret = get_url(url);
+ if (ret < 0) {
+ return tl::unexpected(ret);
+ }
param_vec_t params;
populate_params(params, &uid, self_zone_group);
RGWRESTSimpleRequest req(cct, info.method, url, NULL, ¶ms, api_name);
- ret = req.forward_request(dpp, key, info, max_response, inbl, outbl, y);
- if (ret == -EIO) {
- set_url_unconnectable(url);
- if (tries < NUM_ENPOINT_IOERROR_RETRIES - 1) {
- ldpp_dout(dpp, 20) << __func__ << "(): failed to forward request. retries=" << tries << dendl;
- continue;
- }
+ auto result = req.forward_request(dpp, key, info, max_response, inbl, outbl, y);
+ if (result) {
+ return result;
+ } else if (result.error() != -EIO) {
+ return result;
+ }
+ set_url_unconnectable(url);
+ if (tries < NUM_ENPOINT_IOERROR_RETRIES - 1) {
+ ldpp_dout(dpp, 20) << __func__ << "(): failed to forward request. retries=" << tries << dendl;
}
- break;
}
- return ret;
+ return tl::unexpected(-EIO);
}
-int RGWRESTConn::forward_iam_request(const DoutPrefixProvider *dpp, const req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl, optional_yield y)
+auto RGWRESTConn::forward_iam(const DoutPrefixProvider *dpp, const req_info& info,
+ size_t max_response, bufferlist *inbl,
+ bufferlist *outbl, optional_yield y)
+ -> tl::expected<int, int>
{
- int ret = 0;
-
static constexpr int NUM_ENPOINT_IOERROR_RETRIES = 20;
for (int tries = 0; tries < NUM_ENPOINT_IOERROR_RETRIES; tries++) {
string url;
- ret = get_url(url);
- if (ret < 0)
- return ret;
+ int ret = get_url(url);
+ if (ret < 0) {
+ return tl::unexpected(ret);
+ }
param_vec_t params;
std::string service = "iam";
RGWRESTSimpleRequest req(cct, info.method, url, NULL, ¶ms, api_name);
// coverity[uninit_use_in_call:SUPPRESS]
- ret = req.forward_request(dpp, key, info, max_response, inbl, outbl, y, service);
- if (ret == -EIO) {
- set_url_unconnectable(url);
- if (tries < NUM_ENPOINT_IOERROR_RETRIES - 1) {
- ldpp_dout(dpp, 20) << __func__ << "(): failed to forward request. retries=" << tries << dendl;
- continue;
- }
+ auto result = req.forward_request(dpp, key, info, max_response, inbl, outbl, y, service);
+ if (result) {
+ return result;
+ } else if (result.error() != -EIO) {
+ return result;
+ }
+ set_url_unconnectable(url);
+ if (tries < NUM_ENPOINT_IOERROR_RETRIES - 1) {
+ ldpp_dout(dpp, 20) << __func__ << "(): failed to forward request. retries=" << tries << dendl;
}
- break;
}
- return ret;
+ return tl::unexpected(-EIO);
}
int RGWRESTConn::put_obj_send_init(const rgw_obj& obj, const rgw_http_param_pair *extra_params, RGWRESTStreamS3PutObj **req)
virtual void populate_params(param_vec_t& params, const rgw_owner* uid, const std::string& zonegroup);
/* sync request */
- int forward(const DoutPrefixProvider *dpp, const rgw_owner& uid, const req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl, optional_yield y);
+ auto forward(const DoutPrefixProvider *dpp, const rgw_owner& uid,
+ const req_info& info, size_t max_response,
+ bufferlist *inbl, bufferlist *outbl, optional_yield y)
+ -> tl::expected<int, int>;
/* sync request */
- int forward_iam_request(const DoutPrefixProvider *dpp, const req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl, optional_yield y);
-
+ auto forward_iam(const DoutPrefixProvider *dpp, const req_info& info,
+ size_t max_response, bufferlist *inbl,
+ bufferlist *outbl, optional_yield y)
+ -> tl::expected<int, int>;
/* async requests */
int put_obj_send_init(const rgw_obj& obj, const rgw_http_param_pair *extra_params, RGWRESTStreamS3PutObj **req);
std::move(creds), zg->second.id, zg->second.api_name};
bufferlist outdata;
constexpr size_t max_response_size = 128 * 1024; // we expect a very small response
- int ret = conn.forward_iam_request(dpp, req, max_response_size,
- &indata, &outdata, y);
+ auto result = conn.forward_iam(dpp, req, max_response_size,
+ &indata, &outdata, y);
+ if (!result) {
+ return result.error();
+ }
+ int ret = rgw_http_error_to_errno(*result);
if (ret < 0) {
return ret;
}