]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
radosgw-admin: add support for --bucket-id in bucket stats command
authorVikhyat Umrao <vumrao@redhat.com>
Fri, 30 Aug 2019 07:16:46 +0000 (00:16 -0700)
committerVikhyat Umrao <vikhyat@redhat.com>
Mon, 4 May 2020 06:34:32 +0000 (23:34 -0700)
Fixes: https://tracker.ceph.com/issues/41061
Signed-off-by: Vikhyat Umrao <vikhyat@redhat.com>
(cherry picked from commit 4cd16e13ca0c8709091737ad2cb2b37a3b19840d)

src/rgw/rgw_admin.cc
src/rgw/rgw_bucket.cc
src/rgw/rgw_bucket.h

index 99285b4444346307a162e750eb406159ae1883ec..fb463ea88c9da5fe7dae22d7421c24be9d0046b4 100644 (file)
@@ -3401,7 +3401,7 @@ int main(int argc, const char **argv)
       bucket_id = val;
       opt_bucket_id = val;
       if (bucket_id.empty()) {
-        cerr << "bad bucket-id" << std::endl;
+        cerr << "no value for bucket-id" << std::endl;
         exit(1);
       }
     } else if (ceph_argparse_witharg(args, i, &val, "--bucket-new-name", (char*)NULL)) {
@@ -6077,6 +6077,15 @@ int main(int argc, const char **argv)
   } /* OPT::BUCKETS_LIST */
 
   if (opt_cmd == OPT::BUCKET_STATS) {
+    if (bucket_name.empty() && !bucket_id.empty()) {
+      rgw_bucket bucket;
+      if (!rgw_find_bucket_by_id(store->ctx(), store->ctl()->meta.mgr, marker, bucket_id, &bucket)) {
+        cerr << "failure: no such bucket id" << std::endl;
+        return -ENOENT;
+      }
+      bucket_op.set_tenant(bucket.tenant);
+      bucket_op.set_bucket_name(bucket.name);
+    }
     bucket_op.set_fetch_stats(true);
 
     int r = RGWBucketAdminOp::info(store, bucket_op, f);
index 108b1c13e2d1c5278f7ae8fb5f4310e393a52aa7..58b22827a59a439589239752288720ba814f8d4e 100644 (file)
@@ -635,6 +635,43 @@ int RGWBucket::init(rgw::sal::RGWRadosStore *storage, RGWBucketAdminOpState& op_
   return 0;
 }
 
+bool rgw_find_bucket_by_id(CephContext *cct, RGWMetadataManager *mgr,
+                           const string& marker, const string& bucket_id, rgw_bucket* bucket_out)
+{
+  void *handle = NULL;
+  bool truncated = false;
+  string s;
+
+  int ret = mgr->list_keys_init("bucket.instance", marker, &handle);
+  if (ret < 0) {
+    cerr << "ERROR: can't get key: " << cpp_strerror(-ret) << std::endl;
+    mgr->list_keys_complete(handle);
+    return -ret;
+  }
+  do {
+      list<string> keys;
+      ret = mgr->list_keys_next(handle, 1000, keys, &truncated);
+      if (ret < 0) {
+        cerr << "ERROR: lists_keys_next(): " << cpp_strerror(-ret) << std::endl;
+        mgr->list_keys_complete(handle);
+        return -ret;
+      }
+      for (list<string>::iterator iter = keys.begin(); iter != keys.end(); ++iter) {
+        s = *iter;
+        ret = rgw_bucket_parse_bucket_key(cct, s, bucket_out, nullptr);
+        if (ret < 0) {
+          continue;
+        }
+        if (bucket_id == bucket_out->bucket_id) {
+          mgr->list_keys_complete(handle);
+          return true;
+        }
+      }
+  } while (truncated);
+  mgr->list_keys_complete(handle);
+  return false;
+}
+
 int RGWBucket::link(RGWBucketAdminOpState& op_state, optional_yield y,
                     map<string, bufferlist>& attrs, std::string *err_msg)
 {
index d30f410fddcf56d2c1648e261443f075dbcd4489..797a46cdb171b3e3cdf37ef1a07d638522acdaa5 100644 (file)
@@ -939,5 +939,7 @@ private:
 
 };
 
+bool rgw_find_bucket_by_id(CephContext *cct, RGWMetadataManager *mgr, const string& marker,
+                           const string& bucket_id, rgw_bucket* bucket_out);
 
 #endif