]> git-server-git.apps.pok.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:50:45 +0000 (23:50 -0700)
Fixes: https://tracker.ceph.com/issues/41061
Signed-off-by: Vikhyat Umrao <vikhyat@redhat.com>
(cherry picked from commit 4cd16e13ca0c8709091737ad2cb2b37a3b19840d)

 Conflicts:
src/rgw/rgw_admin.cc
         nautilus uses opt_cmd == OPT_BUCKET_STATS
         nautilus does not have store->ctl()->meta.mgr
         use store->meta_mgr
src/rgw/rgw_bucket.cc
         nautilus has different declaration for RGWBucket::link
         nautlis can not take nullptr in rgw_bucket_parse_bucket_key
         use &shard_id
src/rgw/rgw_bucket.h
         nautilus does not have set_tenant() add set_tenant()
         nautilus does not have get_tenant() add get_tenant()

Signed-off-by: Vikhyat Umrao <vikhyat@redhat.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_bucket.cc
src/rgw/rgw_bucket.h

index 550e649ef7522ba868f20cd56d334e3dc9befb2a..81c2b3ee31991f90484649690ec8d49aa70c0f8e 100644 (file)
@@ -3062,7 +3062,7 @@ int main(int argc, const char **argv)
     } else if (ceph_argparse_witharg(args, i, &val, "--bucket-id", (char*)NULL)) {
       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, "--format", (char*)NULL)) {
@@ -5594,6 +5594,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->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 80ba1ba354bda799819710fe3152116a9cc86387..c314529cdc173213a7ce133fddda7493c8dab894 100644 (file)
@@ -818,6 +818,44 @@ int RGWBucket::init(RGWRados *storage, RGWBucketAdminOpState& op_state)
   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;
+  int shard_id;
+  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, &shard_id);
+        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, std::string *err_msg)
 {
   if (!op_state.is_user_op()) {
index b32049639d446804013eff0a54b6d94ac3ef3d90..63ca130dc82bddac5af1bd39aa6b7093f781fe6c 100644 (file)
@@ -251,6 +251,9 @@ struct RGWBucketAdminOpState {
     if (!user_id.empty())
       uid = user_id;
   }
+  void set_tenant(const std::string& tenant_str) {
+    uid.tenant = tenant_str;
+  }
   void set_bucket_name(const std::string& bucket_str) {
     bucket_name = bucket_str; 
   }
@@ -266,6 +269,7 @@ struct RGWBucketAdminOpState {
   std::string& get_user_display_name() { return display_name; }
   std::string& get_bucket_name() { return bucket_name; }
   std::string& get_object_name() { return object_name; }
+  std::string& get_tenant() { return uid.tenant; }
 
   rgw_bucket& get_bucket() { return bucket; }
   void set_bucket(rgw_bucket& _bucket) {
@@ -564,5 +568,7 @@ public:
   bool going_down();
 };
 
+bool rgw_find_bucket_by_id(CephContext *cct, RGWMetadataManager *mgr, const string& marker,
+                           const string& bucket_id, rgw_bucket* bucket_out);
 
 #endif