]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: rgw_bucket_parse_bucket_instance returns bucket instance and not key
authorYehuda Sadeh <yehuda@redhat.com>
Wed, 3 Jul 2019 03:11:42 +0000 (20:11 -0700)
committerCasey Bodley <cbodley@redhat.com>
Mon, 29 Jul 2019 19:20:50 +0000 (15:20 -0400)
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 <yehuda@redhat.com>
src/rgw/rgw_bucket.cc
src/rgw/rgw_bucket.h
src/rgw/rgw_op.cc
src/rgw/rgw_rest_log.cc

index e2fe9274ee847dd8d999a69c61c12f260abd0c7b..48f4d1b22e3cacfe339f29525e8c0efb0fda3ff7 100644 (file)
@@ -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()) {
index 586448874d833990a41bc92c3897eeb394290437..748ed236c4aa548042e5cd382f72b4c3a8c250bc 100644 (file)
@@ -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);
 
index 98f1ba3fa34536196fa68092cef992b177d17e2b..53167ca2ccd17219298544b4a8e0497478ed67c2 100644 (file)
@@ -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) {
index 57d8c916bf4494db9bfcaa8d20f6d508ed2f5ab5..9f3567664ef0a2d39079b683e5941ad1adb875ba 100644 (file)
@@ -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;