|
3 | 3 |
|
4 | 4 | #include "rgw_zone.h" |
5 | 5 | #include "rgw_rest_conn.h" |
| 6 | +#include "rgw_http_errors.h" |
6 | 7 | #include "rgw_sal.h" |
7 | 8 | #include "rgw_rados.h" |
8 | 9 |
|
@@ -153,57 +154,63 @@ void RGWRESTConn::populate_params(param_vec_t& params, const rgw_owner* uid, con |
153 | 154 | populate_zonegroup(params, zonegroup); |
154 | 155 | } |
155 | 156 |
|
156 | | -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) |
| 157 | +auto RGWRESTConn::forward(const DoutPrefixProvider *dpp, const rgw_owner& uid, |
| 158 | + const req_info& info, size_t max_response, |
| 159 | + bufferlist *inbl, bufferlist *outbl, optional_yield y) |
| 160 | + -> tl::expected<int, int> |
157 | 161 | { |
158 | | - int ret = 0; |
159 | | - |
160 | 162 | static constexpr int NUM_ENPOINT_IOERROR_RETRIES = 20; |
161 | 163 | for (int tries = 0; tries < NUM_ENPOINT_IOERROR_RETRIES; tries++) { |
162 | 164 | string url; |
163 | | - ret = get_url(url); |
164 | | - if (ret < 0) |
165 | | - return ret; |
| 165 | + int ret = get_url(url); |
| 166 | + if (ret < 0) { |
| 167 | + return tl::unexpected(ret); |
| 168 | + } |
166 | 169 | param_vec_t params; |
167 | 170 | populate_params(params, &uid, self_zone_group); |
168 | 171 | RGWRESTSimpleRequest req(cct, info.method, url, NULL, ¶ms, api_name); |
169 | | - ret = req.forward_request(dpp, key, info, max_response, inbl, outbl, y); |
170 | | - if (ret == -EIO) { |
171 | | - set_url_unconnectable(url); |
172 | | - if (tries < NUM_ENPOINT_IOERROR_RETRIES - 1) { |
173 | | - ldpp_dout(dpp, 20) << __func__ << "(): failed to forward request. retries=" << tries << dendl; |
174 | | - continue; |
175 | | - } |
| 172 | + auto result = req.forward_request(dpp, key, info, max_response, inbl, outbl, y); |
| 173 | + if (result) { |
| 174 | + return result; |
| 175 | + } else if (result.error() != -EIO) { |
| 176 | + return result; |
| 177 | + } |
| 178 | + set_url_unconnectable(url); |
| 179 | + if (tries < NUM_ENPOINT_IOERROR_RETRIES - 1) { |
| 180 | + ldpp_dout(dpp, 20) << __func__ << "(): failed to forward request. retries=" << tries << dendl; |
176 | 181 | } |
177 | | - break; |
178 | 182 | } |
179 | | - return ret; |
| 183 | + return tl::unexpected(-EIO); |
180 | 184 | } |
181 | 185 |
|
182 | | -int RGWRESTConn::forward_iam_request(const DoutPrefixProvider *dpp, const req_info& info, size_t max_response, bufferlist *inbl, bufferlist *outbl, optional_yield y) |
| 186 | +auto RGWRESTConn::forward_iam(const DoutPrefixProvider *dpp, const req_info& info, |
| 187 | + size_t max_response, bufferlist *inbl, |
| 188 | + bufferlist *outbl, optional_yield y) |
| 189 | + -> tl::expected<int, int> |
183 | 190 | { |
184 | | - int ret = 0; |
185 | | - |
186 | 191 | static constexpr int NUM_ENPOINT_IOERROR_RETRIES = 20; |
187 | 192 | for (int tries = 0; tries < NUM_ENPOINT_IOERROR_RETRIES; tries++) { |
188 | 193 | string url; |
189 | | - ret = get_url(url); |
190 | | - if (ret < 0) |
191 | | - return ret; |
| 194 | + int ret = get_url(url); |
| 195 | + if (ret < 0) { |
| 196 | + return tl::unexpected(ret); |
| 197 | + } |
192 | 198 | param_vec_t params; |
193 | 199 | std::string service = "iam"; |
194 | 200 | RGWRESTSimpleRequest req(cct, info.method, url, NULL, ¶ms, api_name); |
195 | 201 | // coverity[uninit_use_in_call:SUPPRESS] |
196 | | - ret = req.forward_request(dpp, key, info, max_response, inbl, outbl, y, service); |
197 | | - if (ret == -EIO) { |
198 | | - set_url_unconnectable(url); |
199 | | - if (tries < NUM_ENPOINT_IOERROR_RETRIES - 1) { |
200 | | - ldpp_dout(dpp, 20) << __func__ << "(): failed to forward request. retries=" << tries << dendl; |
201 | | - continue; |
202 | | - } |
| 202 | + auto result = req.forward_request(dpp, key, info, max_response, inbl, outbl, y, service); |
| 203 | + if (result) { |
| 204 | + return result; |
| 205 | + } else if (result.error() != -EIO) { |
| 206 | + return result; |
| 207 | + } |
| 208 | + set_url_unconnectable(url); |
| 209 | + if (tries < NUM_ENPOINT_IOERROR_RETRIES - 1) { |
| 210 | + ldpp_dout(dpp, 20) << __func__ << "(): failed to forward request. retries=" << tries << dendl; |
203 | 211 | } |
204 | | - break; |
205 | 212 | } |
206 | | - return ret; |
| 213 | + return tl::unexpected(-EIO); |
207 | 214 | } |
208 | 215 |
|
209 | 216 | int RGWRESTConn::put_obj_send_init(const rgw_obj& obj, const rgw_http_param_pair *extra_params, RGWRESTStreamS3PutObj **req) |
|
0 commit comments