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>
} 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)) {
} /* 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);
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()) {
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;
}
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) {
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