From: Yehuda Sadeh Date: Wed, 3 Jul 2019 03:11:42 +0000 (-0700) Subject: rgw: rgw_bucket_parse_bucket_instance returns bucket instance and not key X-Git-Tag: v15.1.0~1898^2^2~17 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=8fabdc1293a292622f6726abbd10fa5fc498dd30;p=ceph-ci.git rgw: rgw_bucket_parse_bucket_instance returns bucket instance and not key rgw_bucket_parse_bucket_instance() was returning a meta key, e.g., bucket:instance and not just 'instance'. This caused issue when using read_bucket_instance_info(). Adjusted other users of this function, now that api changed. Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index e2fe9274ee8..48f4d1b22e3 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -151,23 +151,28 @@ int rgw_read_user_buckets(RGWRados * store, is_truncated, default_amount); } -int rgw_bucket_parse_bucket_instance(const string& bucket_instance, string *target_bucket_instance, int *shard_id) +int rgw_bucket_parse_bucket_instance(const string& bucket_instance, string *bucket_name, string *bucket_id, int *shard_id) { - ssize_t pos = bucket_instance.rfind(':'); - if (pos < 0) { + auto pos = bucket_instance.rfind(':'); + if (pos == string::npos) { return -EINVAL; } string first = bucket_instance.substr(0, pos); string second = bucket_instance.substr(pos + 1); - if (first.find(':') == string::npos) { + pos = first.find(':'); + + if (pos == string::npos) { *shard_id = -1; - *target_bucket_instance = bucket_instance; + *bucket_name = first; + *bucket_id = second; return 0; } - *target_bucket_instance = first; + *bucket_name = first.substr(0, pos); + *bucket_id = first.substr(pos + 1); + string err; *shard_id = strict_strtol(second.c_str(), 10, &err); if (!err.empty()) { diff --git a/src/rgw/rgw_bucket.h b/src/rgw/rgw_bucket.h index 586448874d8..748ed236c4a 100644 --- a/src/rgw/rgw_bucket.h +++ b/src/rgw/rgw_bucket.h @@ -31,7 +31,7 @@ class RGWBucketMetadataHandler; class RGWBucketInstanceMetadataHandler; class RGWUserCtl; -extern int rgw_bucket_parse_bucket_instance(const string& bucket_instance, string *target_bucket_instance, int *shard_id); +extern int rgw_bucket_parse_bucket_instance(const string& bucket_instance, string *bucket_name, string *bucket_id, int *shard_id); extern int rgw_bucket_parse_bucket_key(CephContext *cct, const string& key, rgw_bucket* bucket, int *shard_id); diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 98f1ba3fa34..53167ca2ccd 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -561,7 +561,8 @@ int rgw_build_bucket_policies(RGWRados* store, struct req_state* s) string bi = s->info.args.get(RGW_SYS_PARAM_PREFIX "bucket-instance"); if (!bi.empty()) { - ret = rgw_bucket_parse_bucket_instance(bi, &s->bucket_instance_id, &s->bucket_instance_shard_id); + string bucket_name; + ret = rgw_bucket_parse_bucket_instance(bi, &bucket_name, &s->bucket_instance_id, &s->bucket_instance_shard_id); if (ret < 0) { return ret; } @@ -4875,7 +4876,8 @@ int RGWCopyObj::verify_permission() op_ret = store->get_bucket_info(*s->sysobj_ctx, src_tenant_name, src_bucket_name, src_bucket_info, NULL, s->yield, &src_attrs); } else { /* will only happen in intra region sync where the source and dest bucket is the same */ - op_ret = store->get_bucket_instance_info(*s->sysobj_ctx, s->bucket_instance_id, src_bucket_info, NULL, &src_attrs, s->yield); + rgw_bucket b(rgw_bucket_key(src_tenant_name, src_bucket_name, s->bucket_instance_id)); + op_ret = store->get_bucket_instance_info(*s->sysobj_ctx, b, src_bucket_info, NULL, &src_attrs, s->yield); } if (op_ret < 0) { if (op_ret == -ENOENT) { diff --git a/src/rgw/rgw_rest_log.cc b/src/rgw/rgw_rest_log.cc index 57d8c916bf4..9f3567664ef 100644 --- a/src/rgw/rgw_rest_log.cc +++ b/src/rgw/rgw_rest_log.cc @@ -390,13 +390,15 @@ void RGWOp_BILog_List::execute() { } int shard_id; - http_ret = rgw_bucket_parse_bucket_instance(bucket_instance, &bucket_instance, &shard_id); + string bn; + http_ret = rgw_bucket_parse_bucket_instance(bucket_instance, &bn, &bucket_instance, &shard_id); if (http_ret < 0) { return; } if (!bucket_instance.empty()) { - http_ret = store->get_bucket_instance_info(*s->sysobj_ctx, bucket_instance, bucket_info, NULL, NULL, s->yield); + rgw_bucket b(rgw_bucket_key(tenant_name, bucket_name, bucket_instance)); + http_ret = store->get_bucket_instance_info(*s->sysobj_ctx, b, bucket_info, NULL, NULL, s->yield); if (http_ret < 0) { ldpp_dout(s, 5) << "could not get bucket instance info for bucket instance id=" << bucket_instance << dendl; return; @@ -481,13 +483,15 @@ void RGWOp_BILog_Info::execute() { } int shard_id; - http_ret = rgw_bucket_parse_bucket_instance(bucket_instance, &bucket_instance, &shard_id); + string bn; + http_ret = rgw_bucket_parse_bucket_instance(bucket_instance, &bn, &bucket_instance, &shard_id); if (http_ret < 0) { return; } if (!bucket_instance.empty()) { - http_ret = store->get_bucket_instance_info(*s->sysobj_ctx, bucket_instance, bucket_info, NULL, NULL, s->yield); + rgw_bucket b(rgw_bucket_key(tenant_name, bucket_name, bucket_instance)); + http_ret = store->get_bucket_instance_info(*s->sysobj_ctx, b, bucket_info, NULL, NULL, s->yield); if (http_ret < 0) { ldpp_dout(s, 5) << "could not get bucket instance info for bucket instance id=" << bucket_instance << dendl; return; @@ -543,13 +547,15 @@ void RGWOp_BILog_Delete::execute() { } int shard_id; - http_ret = rgw_bucket_parse_bucket_instance(bucket_instance, &bucket_instance, &shard_id); + string bn; + http_ret = rgw_bucket_parse_bucket_instance(bucket_instance, &bn, &bucket_instance, &shard_id); if (http_ret < 0) { return; } if (!bucket_instance.empty()) { - http_ret = store->get_bucket_instance_info(*s->sysobj_ctx, bucket_instance, bucket_info, NULL, NULL, s->yield); + rgw_bucket b(rgw_bucket_key(tenant_name, bucket_name, bucket_instance)); + http_ret = store->get_bucket_instance_info(*s->sysobj_ctx, b, bucket_info, NULL, NULL, s->yield); if (http_ret < 0) { ldpp_dout(s, 5) << "could not get bucket instance info for bucket instance id=" << bucket_instance << dendl; return;