Skip to content

Commit d95463c

Browse files
authored
Merge pull request ceph#62993 from cbodley/wip-71098
rgw/multisite: rgw_forward_request_to_master() preserves Error responses Reviewed-by: Seena Fallah <[email protected]> Reviewed-by: Shilpa Jagannath <[email protected]>
2 parents 8407601 + f8a44d9 commit d95463c

21 files changed

+277
-169
lines changed

src/rgw/driver/rados/rgw_bucket.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,8 +1476,9 @@ int RGWBucketAdminOp::remove_bucket(rgw::sal::Driver* driver, const rgw::SiteCon
14761476
env.set("REQUEST_URI", delpath);
14771477
env.set("QUERY_STRING", fmt::format("bucket={}&tenant={}", bucket->get_name(), bucket->get_tenant()));
14781478
req_info req(dpp->get_cct(), &env);
1479+
rgw_err err; // unused
14791480

1480-
ret = rgw_forward_request_to_master(dpp, site, bucket->get_owner(), nullptr, nullptr, req, y);
1481+
ret = rgw_forward_request_to_master(dpp, site, bucket->get_owner(), nullptr, nullptr, req, err, y);
14811482
if (ret < 0) {
14821483
ldpp_dout(dpp, 0) << "ERROR: failed to forward request to master zonegroup: "
14831484
<< ret << dendl;

src/rgw/driver/rados/rgw_rest_bucket.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void RGWOp_Bucket_Link::execute(optional_yield y)
153153
op_state.set_new_bucket_name(new_bucket_name);
154154

155155
op_ret = rgw_forward_request_to_master(this, *s->penv.site, s->user->get_id(),
156-
nullptr, nullptr, s->info, y);
156+
nullptr, nullptr, s->info, s->err, y);
157157
if (op_ret < 0) {
158158
ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl;
159159
return;
@@ -192,7 +192,7 @@ void RGWOp_Bucket_Unlink::execute(optional_yield y)
192192
op_state.set_bucket_name(bucket);
193193

194194
op_ret = rgw_forward_request_to_master(this, *s->penv.site, s->user->get_id(),
195-
nullptr, nullptr, s->info, y);
195+
nullptr, nullptr, s->info, s->err, y);
196196
if (op_ret < 0) {
197197
ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl;
198198
return;

src/rgw/driver/rados/rgw_rest_user.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int fetch_access_keys_from_master(const DoutPrefixProvider* dpp, req_state* s,
2828
bufferlist data;
2929
JSONParser jp;
3030
int ret = rgw_forward_request_to_master(dpp, *s->penv.site, s->user->get_id(),
31-
&data, &jp, s->info, y);
31+
&data, &jp, s->info, s->err, y);
3232
if (ret < 0) {
3333
ldpp_dout(dpp, 0) << "forward_request_to_master returned ret=" << ret << dendl;
3434
return ret;
@@ -480,7 +480,7 @@ void RGWOp_User_Remove::execute(optional_yield y)
480480
op_state.set_purge_data(purge_data);
481481

482482
op_ret = rgw_forward_request_to_master(this, *s->penv.site, s->user->get_id(),
483-
nullptr, nullptr, s->info, y);
483+
nullptr, nullptr, s->info, s->err, y);
484484
if (op_ret < 0) {
485485
ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl;
486486
return;
@@ -555,7 +555,7 @@ void RGWOp_Subuser_Create::execute(optional_yield y)
555555
op_state.set_key_type(key_type);
556556

557557
op_ret = rgw_forward_request_to_master(this, *s->penv.site, s->user->get_id(),
558-
nullptr, nullptr, s->info, y);
558+
nullptr, nullptr, s->info, s->err, y);
559559
if (op_ret < 0) {
560560
ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl;
561561
return;
@@ -622,7 +622,7 @@ void RGWOp_Subuser_Modify::execute(optional_yield y)
622622
op_state.set_key_type(key_type);
623623

624624
op_ret = rgw_forward_request_to_master(this, *s->penv.site, s->user->get_id(),
625-
nullptr, nullptr, s->info, y);
625+
nullptr, nullptr, s->info, s->err, y);
626626
if (op_ret < 0) {
627627
ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl;
628628
return;
@@ -665,7 +665,7 @@ void RGWOp_Subuser_Remove::execute(optional_yield y)
665665
op_state.set_purge_keys();
666666

667667
op_ret = rgw_forward_request_to_master(this, *s->penv.site, s->user->get_id(),
668-
nullptr, nullptr, s->info, y);
668+
nullptr, nullptr, s->info, s->err, y);
669669
if (op_ret < 0) {
670670
ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl;
671671
return;
@@ -812,7 +812,7 @@ void RGWOp_Caps_Add::execute(optional_yield y)
812812
op_state.set_caps(caps);
813813

814814
op_ret = rgw_forward_request_to_master(this, *s->penv.site, s->user->get_id(),
815-
nullptr, nullptr, s->info, y);
815+
nullptr, nullptr, s->info, s->err, y);
816816
if (op_ret < 0) {
817817
ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl;
818818
return;
@@ -850,7 +850,7 @@ void RGWOp_Caps_Remove::execute(optional_yield y)
850850
op_state.set_caps(caps);
851851

852852
op_ret = rgw_forward_request_to_master(this, *s->penv.site, s->user->get_id(),
853-
nullptr, nullptr, s->info, y);
853+
nullptr, nullptr, s->info, s->err, y);
854854
if (op_ret < 0) {
855855
ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl;
856856
return;

src/rgw/radosgw-admin/radosgw-admin.cc

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,14 +1902,21 @@ static int send_to_remote_gateway(RGWRESTConn* conn, req_info& info,
19021902

19031903
ceph::bufferlist response;
19041904
rgw_user user;
1905-
int ret = conn->forward(dpp(), user, info, nullptr, MAX_REST_RESPONSE, &in_data, &response, null_yield);
1905+
auto result = conn->forward(dpp(), user, info, MAX_REST_RESPONSE, &in_data, &response, null_yield);
1906+
if (!result) {
1907+
return result.error();
1908+
}
1909+
int ret = rgw_http_error_to_errno(*result);
1910+
if (ret < 0) {
1911+
return ret;
1912+
}
19061913

1907-
int parse_ret = parser.parse(response.c_str(), response.length());
1908-
if (parse_ret < 0) {
1914+
ret = parser.parse(response.c_str(), response.length());
1915+
if (ret < 0) {
19091916
cerr << "failed to parse response" << std::endl;
1910-
return parse_ret;
1917+
return ret;
19111918
}
1912-
return ret;
1919+
return 0;
19131920
}
19141921

19151922
static int send_to_url(const string& url,
@@ -1930,14 +1937,21 @@ static int send_to_url(const string& url,
19301937
RGWRESTSimpleRequest req(g_ceph_context, info.method, url, NULL, &params, opt_region);
19311938

19321939
bufferlist response;
1933-
int ret = req.forward_request(dpp(), key, info, MAX_REST_RESPONSE, &in_data, &response, null_yield);
1940+
auto result = req.forward_request(dpp(), key, info, MAX_REST_RESPONSE, &in_data, &response, null_yield);
1941+
if (!result) {
1942+
return result.error();
1943+
}
1944+
int ret = rgw_http_error_to_errno(*result);
1945+
if (ret < 0) {
1946+
return ret;
1947+
}
19341948

1935-
int parse_ret = parser.parse(response.c_str(), response.length());
1936-
if (parse_ret < 0) {
1949+
ret = parser.parse(response.c_str(), response.length());
1950+
if (ret < 0) {
19371951
cout << "failed to parse response" << std::endl;
1938-
return parse_ret;
1952+
return ret;
19391953
}
1940-
return ret;
1954+
return 0;
19411955
}
19421956

19431957
static int send_to_remote_or_url(RGWRESTConn *conn, const string& url,

src/rgw/rgw_common.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ void set_req_state_err(struct rgw_err& err, /* out */
337337
err_no = -err_no;
338338

339339
err.ret = -err_no;
340+
if (!err.err_code.empty()) { // request already set the error
341+
return;
342+
}
340343

341344
if (prot_flags & RGW_REST_SWIFT) {
342345
if (search_err(rgw_http_swift_errors, err_no, err.http_ret, err.err_code))

0 commit comments

Comments
 (0)