From 715a026d12b5f5799f63b76dcee2f6babde7e42a Mon Sep 17 00:00:00 2001 From: Daniel Gryniewicz Date: Tue, 19 Jan 2021 13:13:37 -0500 Subject: [PATCH] RGW Zipper - Clean up get_user* APIs. The main get_user() function doesn't query the cluster, but the rest of them do. Rename the functions to match, and add comments to clarify. Signed-off-by: Daniel Gryniewicz --- src/rgw/rgw_admin.cc | 2 +- src/rgw/rgw_file.h | 4 ++-- src/rgw/rgw_lua.cc | 14 +++++--------- src/rgw/rgw_lua.h | 2 +- src/rgw/rgw_op.cc | 3 ++- src/rgw/rgw_process.cc | 4 ++-- src/rgw/rgw_rest_s3.cc | 9 ++++----- src/rgw/rgw_sal.h | 8 ++++++-- src/rgw/rgw_sal_rados.cc | 21 +++++++++++++++------ src/rgw/rgw_sal_rados.h | 4 ++-- src/rgw/rgw_user.cc | 18 ++++++++++-------- 11 files changed, 50 insertions(+), 39 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 373f7300d35a1..94ee98bbbf3f0 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -9255,7 +9255,7 @@ next: return EINVAL; } std::string script; - const auto rc = rgw::lua::read_script(store, tenant, null_yield, script_ctx, script); + const auto rc = rgw::lua::read_script(dpp(), store, tenant, null_yield, script_ctx, script); if (rc == -ENOENT) { std::cout << "no script exists for context: " << *str_script_ctx << (tenant.empty() ? "" : (" in tenant: " + tenant)) << std::endl; diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index b43eff8f17aa7..b63bca1047104 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -985,7 +985,7 @@ namespace rgw { } int authorize(const DoutPrefixProvider *dpp, rgw::sal::RGWStore* store) { - int ret = store->get_user(dpp, key, null_yield, &user); + int ret = store->get_user_by_access_key(dpp, key.id, null_yield, &user); if (ret == 0) { RGWAccessKey* k = user->get_info().get_key(key.id); if (!k || (k->key != key.key)) @@ -1297,7 +1297,7 @@ namespace rgw { RGWUserInfo* get_user() { return &user->get_info(); } void update_user(const DoutPrefixProvider *dpp) { - (void) rgwlib.get_store()->get_user(dpp, key, null_yield, &user); + (void) rgwlib.get_store()->get_user_by_access_key(dpp, key.id, null_yield, &user); } void close(); diff --git a/src/rgw/rgw_lua.cc b/src/rgw/rgw_lua.cc index c86642181e4be..8eed171da7fb5 100644 --- a/src/rgw/rgw_lua.cc +++ b/src/rgw/rgw_lua.cc @@ -63,17 +63,16 @@ std::string script_oid(context ctx, const std::string& tenant) { } -int read_script(rgw::sal::RGWStore* store, const std::string& tenant, optional_yield y, context ctx, std::string& script) +int read_script(const DoutPrefixProvider *dpp, rgw::sal::RGWStore* store, const std::string& tenant, optional_yield y, context ctx, std::string& script) { - RGWSysObjectCtx obj_ctx(static_cast(store)->svc()->sysobj->init_obj_ctx()); RGWObjVersionTracker objv_tracker; rgw_raw_obj obj(store->get_zone_params().log_pool, script_oid(ctx, tenant)); bufferlist bl; - const auto rc = rgw_get_system_obj( - obj_ctx, + const auto rc = store->get_system_obj( + dpp, obj.pool, obj.oid, bl, @@ -99,7 +98,6 @@ int read_script(rgw::sal::RGWStore* store, const std::string& tenant, optional_y int write_script(rgw::sal::RGWStore* store, const std::string& tenant, optional_yield y, context ctx, const std::string& script) { - RGWSysObjectCtx obj_ctx(static_cast(store)->svc()->sysobj->init_obj_ctx()); RGWObjVersionTracker objv_tracker; rgw_raw_obj obj(store->get_zone_params().log_pool, script_oid(ctx, tenant)); @@ -107,8 +105,7 @@ int write_script(rgw::sal::RGWStore* store, const std::string& tenant, optional_ bufferlist bl; ceph::encode(script, bl); - const auto rc = rgw_put_system_obj( - obj_ctx, + const auto rc = store->put_system_obj( obj.pool, obj.oid, bl, @@ -130,8 +127,7 @@ int delete_script(rgw::sal::RGWStore* store, const std::string& tenant, optional rgw_raw_obj obj(store->get_zone_params().log_pool, script_oid(ctx, tenant)); - const auto rc = rgw_delete_system_obj( - static_cast(store)->svc()->sysobj, + const auto rc = store->delete_system_obj( obj.pool, obj.oid, &objv_tracker, diff --git a/src/rgw/rgw_lua.h b/src/rgw/rgw_lua.h index 296b9a71d57dd..73ed5178702e5 100644 --- a/src/rgw/rgw_lua.h +++ b/src/rgw/rgw_lua.h @@ -29,7 +29,7 @@ bool verify(const std::string& script, std::string& err_msg); int write_script(rgw::sal::RGWStore* store, const std::string& tenant, optional_yield y, context ctx, const std::string& script); // read the stored lua script from a context -int read_script(rgw::sal::RGWStore* store, const std::string& tenant, optional_yield y, context ctx, std::string& script); +int read_script(const DoutPrefixProvider *dpp, rgw::sal::RGWStore* store, const std::string& tenant, optional_yield y, context ctx, std::string& script); // delete the stored lua script from a context int delete_script(rgw::sal::RGWStore* store, const std::string& tenant, optional_yield y, context ctx); diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 8ccbfce34670b..335399324d4f4 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -4405,10 +4405,11 @@ int RGWPutMetadataAccount::verify_permission(optional_yield y) void RGWPutMetadataAccount::execute(optional_yield y) { /* Params have been extracted earlier. See init_processing(). */ - op_ret = s->user->load_by_id(this, y, RGWUserCtl::GetParams().set_objv_tracker(&acct_op_tracker)); + op_ret = s->user->load_by_id(this, y); if (op_ret < 0) { return; } + acct_op_tracker = s->user->get_version_tracker(); /* Handle the TempURL-related stuff. */ if (!temp_url_keys.empty()) { diff --git a/src/rgw/rgw_process.cc b/src/rgw/rgw_process.cc index d60c9c5a11c84..6800ff0e5e049 100644 --- a/src/rgw/rgw_process.cc +++ b/src/rgw/rgw_process.cc @@ -240,7 +240,7 @@ int process_request(rgw::sal::RGWStore* const store, } { std::string script; - auto rc = rgw::lua::read_script(store, s->bucket_tenant, s->yield, rgw::lua::context::preRequest, script); + auto rc = rgw::lua::read_script(s, store, s->bucket_tenant, s->yield, rgw::lua::context::preRequest, script); if (rc == -ENOENT) { // no script, nothing to do } else if (rc < 0) { @@ -308,7 +308,7 @@ int process_request(rgw::sal::RGWStore* const store, done: if (op) { std::string script; - auto rc = rgw::lua::read_script(store, s->bucket_tenant, s->yield, rgw::lua::context::postRequest, script); + auto rc = rgw::lua::read_script(s, store, s->bucket_tenant, s->yield, rgw::lua::context::postRequest, script); if (rc == -ENOENT) { // no script, nothing to do } else if (rc < 0) { diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 989c8fe31a448..85c55ba1071c0 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -5721,11 +5721,10 @@ rgw::auth::s3::LocalEngine::authenticate( { /* get the user info */ std::unique_ptr user; + const std::string access_key_id(_access_key_id); /* TODO(rzarzynski): we need to have string-view taking variant. */ - RGWAccessKey access_key; - access_key.id = _access_key_id; - if (store->get_user(dpp, access_key, y, &user) < 0) { - ldpp_dout(dpp, 5) << "error reading user info, uid=" << access_key.id + if (store->get_user_by_access_key(dpp, access_key_id, y, &user) < 0) { + ldpp_dout(dpp, 5) << "error reading user info, uid=" << access_key_id << " can't authenticate" << dendl; return result_t::deny(-ERR_INVALID_ACCESS_KEY); } @@ -5738,7 +5737,7 @@ rgw::auth::s3::LocalEngine::authenticate( } }*/ - const auto iter = user->get_info().access_keys.find(access_key.id); + const auto iter = user->get_info().access_keys.find(access_key_id); if (iter == std::end(user->get_info().access_keys)) { ldpp_dout(dpp, 0) << "ERROR: access key not encoded in user info" << dendl; return result_t::deny(-EPERM); diff --git a/src/rgw/rgw_sal.h b/src/rgw/rgw_sal.h index eaa090ac9ff9f..7a742f3c9c413 100644 --- a/src/rgw/rgw_sal.h +++ b/src/rgw/rgw_sal.h @@ -126,8 +126,10 @@ class RGWStore { RGWStore() {} virtual ~RGWStore() = default; + /* This one does not query the cluster for info */ virtual std::unique_ptr get_user(const rgw_user& u) = 0; - virtual int get_user(const DoutPrefixProvider *dpp, const RGWAccessKey& key, optional_yield y, std::unique_ptr* user) = 0; + /* These three do query the cluster for info */ + virtual int get_user_by_access_key(const DoutPrefixProvider *dpp, const std::string& key, optional_yield y, std::unique_ptr* user) = 0; virtual int get_user_by_email(const DoutPrefixProvider *dpp, const std::string& email, optional_yield y, std::unique_ptr* user) = 0; virtual int get_user_by_swift(const DoutPrefixProvider *dpp, const std::string& user_str, optional_yield y, std::unique_ptr* user) = 0; virtual std::unique_ptr get_object(const rgw_obj_key& k) = 0; @@ -228,6 +230,7 @@ class RGWStore { class RGWUser { protected: RGWUserInfo info; + RGWObjVersionTracker objv_tracker; public: RGWUser() : info() {} @@ -265,9 +268,10 @@ class RGWUser { bool *is_truncated, RGWUsageIter& usage_iter, map& usage) = 0; virtual int trim_usage(uint64_t start_epoch, uint64_t end_epoch) = 0; + virtual RGWObjVersionTracker& get_version_tracker() { return objv_tracker; } /* Placeholders */ - virtual int load_by_id(const DoutPrefixProvider *dpp, optional_yield y, const RGWUserCtl::GetParams& params = {}) = 0; + virtual int load_by_id(const DoutPrefixProvider *dpp, optional_yield y) = 0; virtual int store_info(const DoutPrefixProvider *dpp, optional_yield y, const RGWUserCtl::PutParams& params = {}) = 0; /* dang temporary; will be removed when User is complete */ diff --git a/src/rgw/rgw_sal_rados.cc b/src/rgw/rgw_sal_rados.cc index 3fc2e12e3133b..5f4b385bc2f3d 100644 --- a/src/rgw/rgw_sal_rados.cc +++ b/src/rgw/rgw_sal_rados.cc @@ -187,9 +187,9 @@ int RGWRadosUser::trim_usage(uint64_t start_epoch, uint64_t end_epoch) return store->getRados()->trim_usage(get_id(), bucket_name, start_epoch, end_epoch); } -int RGWRadosUser::load_by_id(const DoutPrefixProvider *dpp, optional_yield y, const RGWUserCtl::GetParams& params) +int RGWRadosUser::load_by_id(const DoutPrefixProvider *dpp, optional_yield y) { - return store->ctl()->user->get_info_by_uid(dpp, info.user_id, &info, y, params); + return store->ctl()->user->get_info_by_uid(dpp, info.user_id, &info, y, RGWUserCtl::GetParams().set_objv_tracker(&objv_tracker)); } int RGWRadosUser::store_info(const DoutPrefixProvider *dpp, optional_yield y, const RGWUserCtl::PutParams& params) @@ -573,12 +573,13 @@ std::unique_ptr RGWRadosStore::get_user(const rgw_user &u) return std::unique_ptr(new RGWRadosUser(this, u)); } -int RGWRadosStore::get_user(const DoutPrefixProvider *dpp, const RGWAccessKey& key, optional_yield y, std::unique_ptr* user) +int RGWRadosStore::get_user_by_access_key(const DoutPrefixProvider *dpp, const std::string& key, optional_yield y, std::unique_ptr* user) { RGWUserInfo uinfo; RGWUser *u; + RGWObjVersionTracker objv_tracker; - int r = ctl()->user->get_info_by_access_key(dpp, key.id, &uinfo, y); + int r = ctl()->user->get_info_by_access_key(dpp, key, &uinfo, y, RGWUserCtl::GetParams().set_objv_tracker(&objv_tracker)); if (r < 0) return r; @@ -586,6 +587,8 @@ int RGWRadosStore::get_user(const DoutPrefixProvider *dpp, const RGWAccessKey& k if (!u) return -ENOMEM; + u->get_version_tracker() = objv_tracker; + user->reset(u); return 0; } @@ -594,8 +597,9 @@ int RGWRadosStore::get_user_by_email(const DoutPrefixProvider *dpp, const std::s { RGWUserInfo uinfo; RGWUser *u; + RGWObjVersionTracker objv_tracker; - int r = ctl()->user->get_info_by_email(dpp, email, &uinfo, y); + int r = ctl()->user->get_info_by_email(dpp, email, &uinfo, y, RGWUserCtl::GetParams().set_objv_tracker(&objv_tracker)); if (r < 0) return r; @@ -603,6 +607,8 @@ int RGWRadosStore::get_user_by_email(const DoutPrefixProvider *dpp, const std::s if (!u) return -ENOMEM; + u->get_version_tracker() = objv_tracker; + user->reset(u); return 0; } @@ -611,8 +617,9 @@ int RGWRadosStore::get_user_by_swift(const DoutPrefixProvider *dpp, const std::s { RGWUserInfo uinfo; RGWUser *u; + RGWObjVersionTracker objv_tracker; - int r = ctl()->user->get_info_by_swift(dpp, user_str, &uinfo, y); + int r = ctl()->user->get_info_by_swift(dpp, user_str, &uinfo, y, RGWUserCtl::GetParams().set_objv_tracker(&objv_tracker)); if (r < 0) return r; @@ -620,6 +627,8 @@ int RGWRadosStore::get_user_by_swift(const DoutPrefixProvider *dpp, const std::s if (!u) return -ENOMEM; + u->get_version_tracker() = objv_tracker; + user->reset(u); return 0; } diff --git a/src/rgw/rgw_sal_rados.h b/src/rgw/rgw_sal_rados.h index 9464b5252b55d..9899cbb4456b4 100644 --- a/src/rgw/rgw_sal_rados.h +++ b/src/rgw/rgw_sal_rados.h @@ -62,7 +62,7 @@ class RGWRadosUser : public RGWUser { virtual int trim_usage(uint64_t start_epoch, uint64_t end_epoch) override; /* Placeholders */ - virtual int load_by_id(const DoutPrefixProvider *dpp, optional_yield y, const RGWUserCtl::GetParams& params = {}) override; + virtual int load_by_id(const DoutPrefixProvider *dpp, optional_yield y) override; virtual int store_info(const DoutPrefixProvider *dpp, optional_yield y, const RGWUserCtl::PutParams& params = {}) override; friend class RGWRadosBucket; @@ -343,7 +343,7 @@ class RGWRadosStore : public RGWStore { } virtual std::unique_ptr get_user(const rgw_user& u) override; - virtual int get_user(const DoutPrefixProvider *dpp, const RGWAccessKey& key, optional_yield y, std::unique_ptr* user) override; + virtual int get_user_by_access_key(const DoutPrefixProvider *dpp, const std::string& key, optional_yield y, std::unique_ptr* user) override; virtual int get_user_by_email(const DoutPrefixProvider *dpp, const std::string& email, optional_yield y, std::unique_ptr* user) override; virtual int get_user_by_swift(const DoutPrefixProvider *dpp, const std::string& user_str, optional_yield y, std::unique_ptr* user) override; virtual std::unique_ptr get_object(const rgw_obj_key& k) override; diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index 93de8df5d1f0e..643258a9410ff 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -1472,7 +1472,7 @@ int RGWUser::init(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, access_key.clear(); } - RGWUserInfo user_info; + std::unique_ptr user; clear_populated(); @@ -1485,35 +1485,37 @@ int RGWUser::init(const DoutPrefixProvider *dpp, RGWUserAdminOpState& op_state, } if (!user_id.empty() && (user_id.compare(RGW_USER_ANON_ID) != 0)) { - found = (rgw_get_user_info_by_uid(dpp, user_ctl, user_id, user_info, y, &op_state.objv) >= 0); + user = store->get_user(user_id); + found = (user->load_by_id(dpp, y) >= 0); op_state.found_by_uid = found; } if (store->ctx()->_conf.get_val("rgw_user_unique_email")) { if (!user_email.empty() && !found) { - found = (rgw_get_user_info_by_email(dpp, user_ctl, user_email, user_info, y, &op_state.objv) >= 0); + found = (store->get_user_by_email(dpp, user_email, y, &user) >= 0); op_state.found_by_email = found; } } if (!swift_user.empty() && !found) { - found = (rgw_get_user_info_by_swift(dpp, user_ctl, swift_user, user_info, y, &op_state.objv) >= 0); + found = (store->get_user_by_swift(dpp, swift_user, y, &user) >= 0); op_state.found_by_key = found; } if (!access_key.empty() && !found) { - found = (rgw_get_user_info_by_access_key(dpp, user_ctl, access_key, user_info, y, &op_state.objv) >= 0); + found = (store->get_user_by_access_key(dpp, access_key, y, &user) >= 0); op_state.found_by_key = found; } op_state.set_existing_user(found); if (found) { - op_state.set_user_info(user_info); + op_state.set_user_info(user->get_info()); op_state.set_populated(); + op_state.objv = user->get_version_tracker(); - old_info = user_info; + old_info = user->get_info(); set_populated(); } if (user_id.empty()) { - user_id = user_info.user_id; + user_id = user->get_id(); } op_state.set_initialized(); -- 2.39.5