From 7e13ac8e4e9912eed24680ec66eabc5d20ff8381 Mon Sep 17 00:00:00 2001 From: Ray Lv Date: Wed, 10 Sep 2014 15:33:22 +0800 Subject: [PATCH] rgw: Export user stats in get-user-info Adminops API Fixes: #9359 Signed-off-by: Ray Lv --- src/rgw/rgw_common.h | 2 ++ src/rgw/rgw_json_enc.cc | 7 +++++++ src/rgw/rgw_rest_user.cc | 3 +++ src/rgw/rgw_user.cc | 19 +++++++++++++++++-- src/rgw/rgw_user.h | 5 +++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 1170650b56aae..69d04ac27ba13 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -827,6 +827,8 @@ struct RGWStorageStats uint64_t num_objects; RGWStorageStats() : category(RGW_OBJ_CATEGORY_NONE), num_kb(0), num_kb_rounded(0), num_objects(0) {} + + void dump(Formatter *f) const; }; struct req_state; diff --git a/src/rgw/rgw_json_enc.cc b/src/rgw/rgw_json_enc.cc index 44db537c5ed72..b70b613f49a99 100644 --- a/src/rgw/rgw_json_enc.cc +++ b/src/rgw/rgw_json_enc.cc @@ -528,6 +528,13 @@ void RGWBucketEntryPoint::decode_json(JSONObj *obj) { } } +void RGWStorageStats::dump(Formatter *f) const +{ + encode_json("num_kb", num_kb, f); + encode_json("num_kb_rounded", num_kb_rounded, f); + encode_json("num_objects", num_objects, f); +} + void RGWBucketInfo::dump(Formatter *f) const { encode_json("bucket", bucket, f); diff --git a/src/rgw/rgw_rest_user.cc b/src/rgw/rgw_rest_user.cc index c95ea46986439..ea35d6f4dcf39 100644 --- a/src/rgw/rgw_rest_user.cc +++ b/src/rgw/rgw_rest_user.cc @@ -30,10 +30,13 @@ void RGWOp_User_Info::execute() RGWUserAdminOpState op_state; std::string uid; + bool fetch_stats; RESTArgs::get_string(s, "uid", uid, &uid); + RESTArgs::get_bool(s, "stats", false, &fetch_stats); op_state.set_user_id(uid); + op_state.set_fetch_stats(fetch_stats); http_ret = RGWUserAdminOp_User::info(store, op_state, flusher); } diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index 18ce41ecd574d..4f373585c56c2 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -621,7 +621,8 @@ static void dump_swift_keys_info(Formatter *f, RGWUserInfo &info) f->close_section(); } -static void dump_user_info(Formatter *f, RGWUserInfo &info) +static void dump_user_info(Formatter *f, RGWUserInfo &info, + RGWStorageStats *stats = NULL) { f->open_object_section("user_info"); @@ -635,6 +636,9 @@ static void dump_user_info(Formatter *f, RGWUserInfo &info) dump_access_keys_info(f, info); dump_swift_keys_info(f, info); info.caps.dump(f); + if (stats) { + encode_json("stats", *stats, f); + } f->close_section(); } @@ -2128,9 +2132,20 @@ int RGWUserAdminOp_User::info(RGWRados *store, RGWUserAdminOpState& op_state, if (ret < 0) return ret; + RGWStorageStats stats; + RGWStorageStats *arg_stats = NULL; + if (op_state.fetch_stats) { + int ret = store->get_user_stats(info.user_id, stats); + if (ret < 0) { + return ret; + } + + arg_stats = &stats; + } + flusher.start(0); - dump_user_info(formatter, info); + dump_user_info(formatter, info, arg_stats); flusher.flush(); return 0; diff --git a/src/rgw/rgw_user.h b/src/rgw/rgw_user.h index f13c241abbb55..317cd06cd3112 100644 --- a/src/rgw/rgw_user.h +++ b/src/rgw/rgw_user.h @@ -134,6 +134,7 @@ struct RGWUserAdminOpState { __u8 suspended; __u8 system; __u8 exclusive; + __u8 fetch_stats; std::string caps; RGWObjVersionTracker objv; uint32_t op_mask; @@ -273,6 +274,9 @@ struct RGWUserAdminOpState { void set_exclusive(__u8 is_exclusive) { exclusive = is_exclusive; } + void set_fetch_stats(__u8 is_fetch_stats) { + fetch_stats = is_fetch_stats; + } void set_user_info(RGWUserInfo& user_info) { user_id = user_info.user_id; info = user_info; @@ -411,6 +415,7 @@ struct RGWUserAdminOpState { suspended = 0; system = 0; exclusive = 0; + fetch_stats = 0; op_mask = 0; existing_user = false; -- 2.39.5