Skip to content

Commit 9ae2d8c

Browse files
committed
rgw: call RGWBucketAdminOp::remove_bucket by RGWOp_Bucket_Remove
To align same functionality for bucket deletion from both API and rgw-admin, use the same function from RGWBucketAdminOp. Signed-off-by: Seena Fallah <[email protected]>
1 parent e975658 commit 9ae2d8c

File tree

5 files changed

+38
-28
lines changed

5 files changed

+38
-28
lines changed

doc/radosgw/adminops.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,13 +1510,27 @@ Request Parameters
15101510
:Example: ``foo_bucket``
15111511
:Required: Yes
15121512

1513+
``tenant``
1514+
1515+
:Description: The tenant under which the bucket is to be removed.
1516+
:Type: String
1517+
:Example: ``tenant1``
1518+
:Required: No
1519+
15131520
``purge-objects``
15141521

15151522
:Description: Remove a buckets objects before deletion.
15161523
:Type: Boolean
15171524
:Example: True [False]
15181525
:Required: No
15191526

1527+
``bypass-gc``
1528+
1529+
:Description: Bypass garbage collection.
1530+
:Type: Boolean
1531+
:Example: True [False]
1532+
:Required: No
1533+
15201534
Response Entities
15211535
~~~~~~~~~~~~~~~~~
15221536

src/rgw/driver/rados/rgw_bucket.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ int RGWBucketAdminOp::check_index(rgw::sal::Driver* driver,
14351435

14361436
int RGWBucketAdminOp::remove_bucket(rgw::sal::Driver* driver, RGWBucketAdminOpState& op_state,
14371437
optional_yield y, const DoutPrefixProvider *dpp,
1438-
bool bypass_gc, bool keep_index_consistent)
1438+
bool bypass_gc, bool keep_index_consistent, bool forwarded_request)
14391439
{
14401440
std::unique_ptr<rgw::sal::Bucket> bucket;
14411441

@@ -1445,6 +1445,14 @@ int RGWBucketAdminOp::remove_bucket(rgw::sal::Driver* driver, RGWBucketAdminOpSt
14451445
if (ret < 0)
14461446
return ret;
14471447

1448+
// check if the bucket is owned by my zonegroup, if not, refuse to remove it
1449+
if (!forwarded_request && bucket->get_info().zonegroup != driver->get_zone()->get_zonegroup().get_id()) {
1450+
ldpp_dout(dpp, 0) << "ERROR: The bucket's zonegroup does not match. "
1451+
<< "Removal is not allowed. Please execute this operation "
1452+
<< "on the bucket's zonegroup: " << bucket->get_info().zonegroup << dendl;
1453+
return -ERR_PERMANENT_REDIRECT;
1454+
}
1455+
14481456
if (bypass_gc)
14491457
ret = bucket->remove_bypass_gc(op_state.get_max_aio(), keep_index_consistent, y, dpp);
14501458
else

src/rgw/driver/rados/rgw_bucket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ class RGWBucketAdminOp {
385385
RGWFormatterFlusher& flusher, const DoutPrefixProvider *dpp);
386386

387387
static int remove_bucket(rgw::sal::Driver* driver, RGWBucketAdminOpState& op_state, optional_yield y,
388-
const DoutPrefixProvider *dpp, bool bypass_gc = false, bool keep_index_consistent = true);
388+
const DoutPrefixProvider *dpp, bool bypass_gc = false, bool keep_index_consistent = true, bool forwarded_request = false);
389389
static int remove_object(rgw::sal::Driver* driver, RGWBucketAdminOpState& op_state, const DoutPrefixProvider *dpp, optional_yield y);
390390
static int info(rgw::sal::Driver* driver, RGWBucketAdminOpState& op_state, RGWFormatterFlusher& flusher, optional_yield y, const DoutPrefixProvider *dpp);
391391
static int limit_check(rgw::sal::Driver* driver, RGWBucketAdminOpState& op_state,

src/rgw/driver/rados/rgw_rest_bucket.cc

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -216,36 +216,24 @@ class RGWOp_Bucket_Remove : public RGWRESTOp {
216216

217217
void RGWOp_Bucket_Remove::execute(optional_yield y)
218218
{
219-
std::string bucket_name;
220-
bool delete_children;
221-
std::unique_ptr<rgw::sal::Bucket> bucket;
219+
std::string bucket_name, tenant;
220+
bool delete_children, bypass_gc;
222221

223222
RESTArgs::get_string(s, "bucket", bucket_name, &bucket_name);
223+
RESTArgs::get_string(s, "tenant", tenant, &tenant);
224224
RESTArgs::get_bool(s, "purge-objects", false, &delete_children);
225+
RESTArgs::get_bool(s, "bypass-gc", false, &bypass_gc);
225226

226-
op_ret = rgw_forward_request_to_master(this, *s->penv.site, s->user->get_id(),
227-
nullptr, nullptr, s->info, y);
228-
if (op_ret < 0) {
229-
ldpp_dout(this, 0) << "forward_request_to_master returned ret=" << op_ret << dendl;
230-
if (op_ret == -ENOENT) {
231-
/* adjust error, we want to return with NoSuchBucket and not
232-
* NoSuchKey */
233-
op_ret = -ERR_NO_SUCH_BUCKET;
234-
}
235-
return;
236-
}
227+
RGWBucketAdminOpState op_state;
228+
op_state.set_bucket_name(bucket_name);
229+
op_state.set_tenant(tenant);
230+
op_state.set_delete_children(delete_children);
237231

238-
op_ret = driver->load_bucket(s, rgw_bucket("", bucket_name),
239-
&bucket, y);
240-
if (op_ret < 0) {
241-
ldpp_dout(this, 0) << "get_bucket returned ret=" << op_ret << dendl;
242-
if (op_ret == -ENOENT) {
243-
op_ret = -ERR_NO_SUCH_BUCKET;
244-
}
245-
return;
246-
}
232+
// Check if the request is being forwarded by looking for the "rgwx-zonegroup" argument
233+
// As this is an admin endpoint, checking by system_request is not sufficient
234+
const bool is_forwarded = s->info.args.exists(RGW_SYS_PARAM_PREFIX "zonegroup");
247235

248-
op_ret = bucket->remove(s, delete_children, s->yield);
236+
op_ret = RGWBucketAdminOp::remove_bucket(driver, *s->penv.site, op_state, y, s, bypass_gc, true, is_forwarded);
249237
}
250238

251239
class RGWOp_Set_Bucket_Quota : public RGWRESTOp {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8975,14 +8975,14 @@ int main(int argc, const char **argv)
89758975

89768976
if (opt_cmd == OPT::BUCKET_RM) {
89778977
if (!inconsistent_index) {
8978-
RGWBucketAdminOp::remove_bucket(driver, bucket_op, null_yield, dpp(), bypass_gc, true);
8978+
RGWBucketAdminOp::remove_bucket(driver, bucket_op, null_yield, dpp(), bypass_gc, true, false);
89798979
} else {
89808980
if (!yes_i_really_mean_it) {
89818981
cerr << "using --inconsistent_index can corrupt the bucket index " << std::endl
89828982
<< "do you really mean it? (requires --yes-i-really-mean-it)" << std::endl;
89838983
return 1;
89848984
}
8985-
RGWBucketAdminOp::remove_bucket(driver, bucket_op, null_yield, dpp(), bypass_gc, false);
8985+
RGWBucketAdminOp::remove_bucket(driver, bucket_op, null_yield, dpp(), bypass_gc, false, false);
89868986
}
89878987
}
89888988

0 commit comments

Comments
 (0)