From e57e8da3224a5e56b499c59e6ded4b59bde60ee1 Mon Sep 17 00:00:00 2001 From: Pritha Srivastava Date: Thu, 25 Nov 2021 16:24:23 +0530 Subject: [PATCH] rgw: removing svc_role.h and svc_role.cc, and references to RGWSI_Role and cleaning up code. Signed-off-by: Pritha Srivastava --- src/rgw/CMakeLists.txt | 1 - src/rgw/rgw_role.cc | 101 +------- src/rgw/rgw_role.h | 20 +- src/rgw/rgw_sal_rados.cc | 8 +- src/rgw/rgw_sal_rados.h | 6 +- src/rgw/rgw_service.cc | 3 +- src/rgw/rgw_service.h | 1 - src/rgw/services/svc_role.cc | 1 - src/rgw/services/svc_role.h | 33 --- src/rgw/services/svc_role_rados.cc | 357 ----------------------------- src/rgw/services/svc_role_rados.h | 13 +- 11 files changed, 30 insertions(+), 514 deletions(-) delete mode 100644 src/rgw/services/svc_role.cc delete mode 100644 src/rgw/services/svc_role.h diff --git a/src/rgw/CMakeLists.txt b/src/rgw/CMakeLists.txt index 79cf80a4beb..e46dd5fa91c 100644 --- a/src/rgw/CMakeLists.txt +++ b/src/rgw/CMakeLists.txt @@ -39,7 +39,6 @@ set(librgw_common_srcs services/svc_quota.cc services/svc_sync_modules.cc services/svc_rados.cc - services/svc_role.cc services/svc_role_rados.cc services/svc_sys_obj.cc services/svc_sys_obj_cache.cc diff --git a/src/rgw/rgw_role.cc b/src/rgw/rgw_role.cc index 9013889d3da..1d311e8fab7 100644 --- a/src/rgw/rgw_role.cc +++ b/src/rgw/rgw_role.cc @@ -21,9 +21,9 @@ #include "services/svc_zone.h" #include "services/svc_sys_obj.h" -#include "services/svc_role.h" #include "services/svc_meta_be_sobj.h" #include "services/svc_meta.h" +#include "services/svc_role_rados.h" #define dout_subsys ceph_subsys_rgw @@ -271,99 +271,10 @@ const string& RGWRole::get_path_oid_prefix() { return role_path_oid_prefix; } -#if 0 -class RGWSI_Role_Module : public RGWSI_MBSObj_Handler_Module { - RGWRoleMetadataHandler::Svc& svc; - const std::string prefix; -public: - RGWSI_Role_Module(RGWRoleMetadataHandler::Svc& _svc): RGWSI_MBSObj_Handler_Module("roles"), - svc(_svc), - prefix(rgw::sal::RGWRole::get_info_oid_prefix()) {} - - void get_pool_and_oid(const std::string& key, - rgw_pool *pool, - std::string *oid) override - { - if (pool) { - *pool = svc.zone->get_zone_params().roles_pool; - } - - if (oid) { - *oid = key_to_oid(key); - } - } - - bool is_valid_oid(const std::string& oid) override { - return boost::algorithm::starts_with(oid, prefix); - } - - std::string key_to_oid(const std::string& key) override { - return prefix + key; - } - - // This is called after `is_valid_oid` and is assumed to be a valid oid - std::string oid_to_key(const std::string& oid) override { - return oid.substr(prefix.size()); - } - - const std::string& get_oid_prefix() { - return prefix; - } -}; - -RGWSI_MetaBackend_Handler* RGWRoleMetadataHandler::get_be_handler() -{ - return be_handler; -} - -void RGWRoleMetadataHandler::init(RGWSI_Zone *_zone_svc, - RGWSI_Meta *_meta_svc, - RGWSI_MetaBackend *_meta_be_svc, - RGWSI_SysObj *_sysobj_svc) -{ - svc.zone = _zone_svc; - svc.meta = _meta_svc; - svc.meta_be = _meta_be_svc; - svc.sysobj = _sysobj_svc; - int r = svc.meta->create_be_handler(RGWSI_MetaBackend::Type::MDBE_SOBJ, - &be_handler); - if (r < 0) { - //ldout(ctx(), 0) << "ERROR: failed to create be_handler for Roles: r=" - // << r <(be_handler); - be_module.reset(module); - bh->set_module(module); - base_init(cct, get_be_handler()); -} - - -int RGWRoleMetadataHandler::do_start(optional_yield y, const DoutPrefixProvider *dpp) -{ - - int r = svc.meta->create_be_handler(RGWSI_MetaBackend::Type::MDBE_SOBJ, - &be_handler); - if (r < 0) { - //ldout(ctx(), 0) << "ERROR: failed to create be_handler for Roles: r=" - // << r <(be_handler); - be_module.reset(module); - bh->set_module(module); - return 0; -} -#endif -RGWRoleMetadataHandler::RGWRoleMetadataHandler(CephContext *cct, Store* store, - RGWSI_Role *role_svc) +RGWRoleMetadataHandler::RGWRoleMetadataHandler(Store* store, + RGWSI_Role_RADOS *role_svc) { - this->cct = cct; this->store = store; base_init(role_svc->ctx(), role_svc->get_be_handler()); } @@ -390,7 +301,7 @@ int RGWRoleMetadataHandler::do_get(RGWSI_MetaBackend_Handler::Op *op, const DoutPrefixProvider *dpp) { std::unique_ptr role = store->get_role(entry); - int ret = role->read_info(dpp, y, false); + int ret = role->read_info(dpp, y); if (ret < 0) { return ret; } @@ -413,7 +324,7 @@ int RGWRoleMetadataHandler::do_remove(RGWSI_MetaBackend_Handler::Op *op, const DoutPrefixProvider *dpp) { std::unique_ptr role = store->get_role(entry); - int ret = role->read_info(dpp, y, false); + int ret = role->read_info(dpp, y); if (ret < 0) { return ret == -ENOENT? 0 : ret; } @@ -445,7 +356,7 @@ public: auto* store = mdo->get_store(); info.mtime = mtime; std::unique_ptr role = store->get_role(info); - int ret = role->create(dpp, true, y, false); + int ret = role->create(dpp, true, y); return ret < 0 ? ret : STATUS_APPLIED; } }; diff --git a/src/rgw/rgw_role.h b/src/rgw/rgw_role.h index 94106bc3aed..97f517fe0fb 100644 --- a/src/rgw/rgw_role.h +++ b/src/rgw/rgw_role.h @@ -34,7 +34,7 @@ struct RGWRoleInfo RGWRoleInfo() = default; - virtual ~RGWRoleInfo() = default; + ~RGWRoleInfo() = default; void encode(bufferlist& bl) const { ENCODE_START(3, 1, bl); @@ -87,12 +87,12 @@ public: protected: RGWRoleInfo info; public: - virtual int store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y, bool addprefix=true) = 0; + virtual int store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) = 0; virtual int store_name(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) = 0; virtual int store_path(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) = 0; virtual int read_id(const DoutPrefixProvider *dpp, const std::string& role_name, const std::string& tenant, std::string& role_id, optional_yield y) = 0; virtual int read_name(const DoutPrefixProvider *dpp, optional_yield y) = 0; - virtual int read_info(const DoutPrefixProvider *dpp, optional_yield y, bool addprefix=true) = 0; + virtual int read_info(const DoutPrefixProvider *dpp, optional_yield y) = 0; bool validate_input(const DoutPrefixProvider* dpp); void extract_name_tenant(const std::string& str); @@ -103,9 +103,9 @@ public: std::string max_session_duration_str="", std::multimap tags={}); - RGWRole(std::string id); + explicit RGWRole(std::string id); - RGWRole(const RGWRoleInfo& info) : info(info) {} + explicit RGWRole(const RGWRoleInfo& info) : info(info) {} RGWRole() = default; @@ -126,7 +126,7 @@ public: void set_id(const std::string& id) { this->info.id = id; } void set_mtime(const real_time& mtime) { this->info.mtime = mtime; } - virtual int create(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y, bool addprefix=true) = 0; + virtual int create(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) = 0; virtual int delete_obj(const DoutPrefixProvider *dpp, optional_yield y) = 0; int get(const DoutPrefixProvider *dpp, optional_yield y); int get_by_id(const DoutPrefixProvider *dpp, optional_yield y); @@ -173,12 +173,7 @@ public: class RGWRoleMetadataHandler: public RGWMetadataHandler_GenericMetaBE { public: - public: - struct Svc { - RGWSI_Role *role{nullptr}; - } svc; - - RGWRoleMetadataHandler(CephContext *cct, Store* store, RGWSI_Role *role_svc); + RGWRoleMetadataHandler(Store* store, RGWSI_Role_RADOS *role_svc); std::string get_type() final { return "roles"; } @@ -209,7 +204,6 @@ public: private: Store* store; - CephContext *cct; }; } } // namespace rgw::sal diff --git a/src/rgw/rgw_sal_rados.cc b/src/rgw/rgw_sal_rados.cc index 64058bba72e..c7ed4bdd6f6 100644 --- a/src/rgw/rgw_sal_rados.cc +++ b/src/rgw/rgw_sal_rados.cc @@ -3067,7 +3067,7 @@ int RadosOIDCProvider::delete_obj(const DoutPrefixProvider *dpp, optional_yield return ret; } -int RadosRole::store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y, bool addprefix) +int RadosRole::store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) { using ceph::encode; std::string oid; @@ -3164,7 +3164,7 @@ int RadosRole::read_name(const DoutPrefixProvider *dpp, optional_yield y) return 0; } -int RadosRole::read_info(const DoutPrefixProvider *dpp, optional_yield y, bool addprefix) +int RadosRole::read_info(const DoutPrefixProvider *dpp, optional_yield y) { auto obj_ctx = store->svc()->sysobj->init_obj_ctx(); std::string oid; @@ -3208,7 +3208,7 @@ int RadosRole::read_info(const DoutPrefixProvider *dpp, optional_yield y, bool a return 0; } -int RadosRole::create(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y, bool addprefix) +int RadosRole::create(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) { int ret; @@ -3254,7 +3254,7 @@ int RadosRole::create(const DoutPrefixProvider *dpp, bool exclusive, optional_yi info.creation_date.assign(buf, strlen(buf)); auto& pool = store->svc()->zone->get_zone_params().roles_pool; - ret = store_info(dpp, exclusive, y, addprefix); + ret = store_info(dpp, exclusive, y); if (ret < 0) { ldpp_dout(dpp, 0) << "ERROR: storing role info in Role pool: " << info.id << ": " << cpp_strerror(-ret) << dendl; diff --git a/src/rgw/rgw_sal_rados.h b/src/rgw/rgw_sal_rados.h index f9b750e1481..a11ce994360 100644 --- a/src/rgw/rgw_sal_rados.h +++ b/src/rgw/rgw_sal_rados.h @@ -908,13 +908,13 @@ public: RadosRole(RadosStore* _store) : store(_store) {} ~RadosRole() = default; - virtual int store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y, bool addprefix=true) override; + virtual int store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) override; virtual int store_name(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) override; virtual int store_path(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) override; virtual int read_id(const DoutPrefixProvider *dpp, const std::string& role_name, const std::string& tenant, std::string& role_id, optional_yield y) override; virtual int read_name(const DoutPrefixProvider *dpp, optional_yield y) override; - virtual int read_info(const DoutPrefixProvider *dpp, optional_yield y, bool addprefix=true) override; - virtual int create(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y, bool addprefix=true) override; + virtual int read_info(const DoutPrefixProvider *dpp, optional_yield y) override; + virtual int create(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) override; virtual int delete_obj(const DoutPrefixProvider *dpp, optional_yield y) override; }; }} // namespace rgw::sal diff --git a/src/rgw/rgw_service.cc b/src/rgw/rgw_service.cc index 1b072fe998a..7df25a2dba5 100644 --- a/src/rgw/rgw_service.cc +++ b/src/rgw/rgw_service.cc @@ -36,7 +36,6 @@ #include "rgw_otp.h" #include "rgw_user.h" #include "rgw_role.h" -#include "rgw_sal_rados.h" #define dout_subsys ceph_subsys_rgw @@ -373,7 +372,7 @@ int RGWCtlDef::init(RGWServices& svc, rgw::sal::Store* store, const DoutPrefixPr } meta.otp.reset(RGWOTPMetaHandlerAllocator::alloc()); - meta.role = std::make_unique(svc.cct, store, svc.role); + meta.role = std::make_unique(store, svc.role); user.reset(new RGWUserCtl(svc.zone, svc.user, (RGWUserMetadataHandler *)meta.user.get())); bucket.reset(new RGWBucketCtl(svc.zone, diff --git a/src/rgw/rgw_service.h b/src/rgw/rgw_service.h index 128c02dbf50..83475140d16 100644 --- a/src/rgw/rgw_service.h +++ b/src/rgw/rgw_service.h @@ -75,7 +75,6 @@ class RGWSI_SysObj_Cache; class RGWSI_User; class RGWSI_User_RADOS; class RGWDataChangesLog; -class RGWSI_Role; class RGWSI_Role_RADOS; struct RGWServices_Def diff --git a/src/rgw/services/svc_role.cc b/src/rgw/services/svc_role.cc deleted file mode 100644 index 0f62d84e53c..00000000000 --- a/src/rgw/services/svc_role.cc +++ /dev/null @@ -1 +0,0 @@ -#include "svc_role.h" diff --git a/src/rgw/services/svc_role.h b/src/rgw/services/svc_role.h deleted file mode 100644 index d6c18a871db..00000000000 --- a/src/rgw/services/svc_role.h +++ /dev/null @@ -1,33 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab ft=cpp - -/* - * Ceph - scalable distributed file system - * - * Copyright (C) 2020 SUSE LLC - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License version 2.1, as published by the Free Software - * Foundation. See file COPYING. - * - */ - -#pragma once - -#include "rgw/rgw_service.h" -#include "rgw/rgw_role.h" -#include "svc_meta_be.h" - -class RGWSI_Role: public RGWServiceInstance -{ - public: - RGWSI_Role(CephContext *cct) : RGWServiceInstance(cct) {} - virtual ~RGWSI_Role() {} - - virtual RGWSI_MetaBackend_Handler* get_be_handler() = 0; -}; - -static const std::string role_name_oid_prefix = "role_names."; -static const std::string role_oid_prefix = "roles."; -static const std::string role_path_oid_prefix = "role_paths."; diff --git a/src/rgw/services/svc_role_rados.cc b/src/rgw/services/svc_role_rados.cc index 8be953d15a7..a840224978b 100644 --- a/src/rgw/services/svc_role_rados.cc +++ b/src/rgw/services/svc_role_rados.cc @@ -80,360 +80,3 @@ int RGWSI_Role_RADOS::do_start(optional_yield y, const DoutPrefixProvider *dpp) bh->set_module(module); return 0; } -#if 0 -class PutRole -{ - RGWSI_Role_RADOS* svc_role; - RGWSI_Role_RADOS::Svc *svc; - RGWSI_MetaBackend::Context *ctx; - rgw::sal::RGWRole& info; - RGWObjVersionTracker *objv_tracker; - const real_time& mtime; - bool exclusive; - std::map *pattrs; - optional_yield y; - const DoutPrefixProvider *dpp; - -public: - PutRole(RGWSI_Role_RADOS* _svc_role, - RGWSI_Role_RADOS::Svc *_svc, - RGWSI_MetaBackend::Context *_ctx, - rgw::sal::RGWRole& _info, - RGWObjVersionTracker *_ot, - const real_time& _mtime, - bool _exclusive, - std::map *_pattrs, - optional_yield _y, - const DoutPrefixProvider *dpp) : - svc_role(_svc_role), ctx(_ctx), info(_info), objv_tracker(_ot), - mtime(_mtime), exclusive(_exclusive), pattrs(_pattrs), y(_y), dpp(dpp) - {} - - int prepare() { - if (exclusive) { - RGWSI_MetaBackend_SObj::Context_SObj *sys_ctx = static_cast(ctx); - auto& obj_ctx = *sys_ctx->obj_ctx; - - int ret = rgw_stat_system_obj(dpp, obj_ctx, - svc->zone->get_zone_params().roles_pool, - svc_role->get_role_name_meta_key(info.get_name(), info.get_tenant()), - nullptr, nullptr, y); - if (ret == 0) { - ldout(svc_role->ctx(), 0) << "ERROR: name " << info.get_name() - << " already in use for role id " - << info.get_id() << dendl; - return -EEXIST; - } - } - - - return 0; - } - - int put() { - return svc_role->store_info(ctx, info, objv_tracker, - mtime, exclusive, pattrs, y, dpp); - } - - int complete() { - // This creates the ancillary objects for roles, role_names & path - // objv_tracker is set to null for sysobj calls as these aren't tracked via - // the mdlog. A failure in name/path creation means we delete all the - // created objects in the transaction - int r = svc_role->store_name(ctx, info.get_id(), info.get_name(), info.get_tenant(), - nullptr, mtime, exclusive, y, dpp); - - if (r == 0) { - r = svc_role->store_path(ctx, info.get_id(), info.get_path(), info.get_tenant(), - nullptr, mtime, exclusive, y, dpp); - } - - if (r < 0) { - svc_role->delete_info(ctx, info.get_id(), objv_tracker, y, dpp); - svc_role->delete_name(ctx, info.get_name(), info.get_tenant(), objv_tracker, y, dpp); - } - - return r; - } - -}; - - -int RGWSI_Role_RADOS::create(RGWSI_MetaBackend::Context *ctx, - rgw::sal::RGWRole& info, - RGWObjVersionTracker * const objv_tracker, - const real_time& mtime, - bool exclusive, - std::map * pattrs, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - PutRole Op(this, &svc, ctx, info, objv_tracker, mtime, exclusive, pattrs, y, dpp); - - int r = Op.prepare(); - if (r < 0) { - ldout(svc.meta_be->ctx(),0) << __func__ << "ERROR: prepare role failed" << dendl; - return r; - } - - r = Op.put(); - if (r < 0) { - ldout(svc.meta_be->ctx(),0) << __func__ << "ERROR: put role failed" << dendl; - return r; - } - - r = Op.complete(); - if (r < 0) { - ldout(svc.meta_be->ctx(),0) << __func__ << "ERROR: completing PutRole failed" << dendl; - } - return r; -} - -int RGWSI_Role_RADOS::store_info(RGWSI_MetaBackend::Context *ctx, - const rgw::sal::RGWRole& role, - RGWObjVersionTracker * const objv_tracker, - const real_time& mtime, - bool exclusive, - std::map * pattrs, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - bufferlist data_bl; - encode(role, data_bl); - RGWSI_MBSObj_PutParams params(data_bl, pattrs, mtime, exclusive); - - return svc.meta_be->put(ctx, get_role_meta_key(role.get_id()), params, objv_tracker, y, dpp); -} - -int RGWSI_Role_RADOS::store_name(RGWSI_MetaBackend::Context *ctx, - const std::string& role_id, - const std::string& name, - const std::string& tenant, - RGWObjVersionTracker * const objv_tracker, - const real_time& mtime, - bool exclusive, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - RGWNameToId nameToId; - nameToId.obj_id = role_id; - - bufferlist data_bl; - encode(nameToId, data_bl); - - RGWSI_MetaBackend_SObj::Context_SObj *sys_ctx = static_cast(ctx); - auto& obj_ctx = *sys_ctx->obj_ctx; - return rgw_put_system_obj(dpp, obj_ctx, - svc.zone->get_zone_params().roles_pool, - get_role_name_meta_key(name, tenant), - data_bl, - exclusive, - objv_tracker, - mtime, - y); -} - - -int RGWSI_Role_RADOS::store_path(RGWSI_MetaBackend::Context *ctx, - const std::string& role_id, - const std::string& path, - const std::string& tenant, - RGWObjVersionTracker * const objv_tracker, - const real_time& mtime, - bool exclusive, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - bufferlist bl; - RGWSI_MetaBackend_SObj::Context_SObj *sys_ctx = static_cast(ctx); - auto& obj_ctx = *sys_ctx->obj_ctx; - return rgw_put_system_obj(dpp, obj_ctx, - svc.zone->get_zone_params().roles_pool, - get_role_path_meta_key(path, role_id, tenant), - bl, - exclusive, - objv_tracker, - mtime, - y); -} - - -int RGWSI_Role_RADOS::read_info(RGWSI_MetaBackend::Context *ctx, - const std::string& role_id, - rgw::sal::RGWRole *role, - RGWObjVersionTracker * const objv_tracker, - real_time * const pmtime, - std::map * pattrs, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - bufferlist data_bl; - RGWSI_MBSObj_GetParams params(&data_bl, pattrs, pmtime); - - int r = svc.meta_be->get_entry(ctx, get_role_meta_key(role_id), params, objv_tracker, y, dpp); - if (r < 0) - return r; - - auto bl_iter = data_bl.cbegin(); - try { - decode(*role, bl_iter); - } catch (buffer::error& err) { - ldout(svc.meta_be->ctx(),0) << "ERROR: failed to decode RGWRole, caught buffer::err " << dendl; - return -EIO; - } - - return 0; -} - -int RGWSI_Role_RADOS::read_name(RGWSI_MetaBackend::Context *ctx, - const std::string& name, - const std::string& tenant, - std::string& role_id, - RGWObjVersionTracker * const objv_tracker, - real_time * const pmtime, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - - bufferlist data_bl; - RGWSI_MetaBackend_SObj::Context_SObj *sys_ctx = static_cast(ctx); - int r = rgw_get_system_obj(*sys_ctx->obj_ctx, - svc.zone->get_zone_params().roles_pool, - get_role_name_meta_key(name, tenant), - data_bl, - nullptr, - pmtime, - y, - dpp); - if (r < 0) - return r; - - auto bl_iter = data_bl.cbegin(); - RGWNameToId nameToId; - try { - decode(nameToId, bl_iter); - } catch (buffer::error& err) { - ldout(svc.meta_be->ctx(),0) << "ERROR: failed to decode RGWRole name, caught buffer::err " << dendl; - return -EIO; - } - - role_id = nameToId.obj_id; - return 0; -} - -static int delete_oid(RGWSI_Role_RADOS::Svc svc, - RGWSI_MetaBackend::Context *ctx, - const std::string& oid, - RGWObjVersionTracker * const objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - RGWSI_MetaBackend_SObj::Context_SObj *sys_ctx = static_cast(ctx); - rgw_raw_obj obj(svc.zone->get_zone_params().roles_pool, oid); - auto sysobj = sys_ctx->obj_ctx->get_obj(obj); - int r = sysobj.wop().remove(dpp, y); - if (r < 0 && r != -ENOENT && r != -ECANCELED) { - ldout(svc.meta_be->ctx(),0) << "ERROR: RGWSI_Role: could not remove oid = " - << oid << " r = "<< r << dendl; - return r; - } - return 0; -} - -int RGWSI_Role_RADOS::delete_role(RGWSI_MetaBackend::Context *ctx, - const rgw::sal::RGWRole& info, - RGWObjVersionTracker * const objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - //deletes in the reverse order of creates, first delete the path, then the - //name and finally the info object - int r = delete_path(ctx, info.get_id(), info.get_path(), info.get_tenant(), objv_tracker, y, dpp); - if (r < 0) { - return r; - } - - r = delete_name(ctx, info.get_name(), info.get_tenant(), objv_tracker, y, dpp); - if (r < 0) { - return r; - } - - return delete_info(ctx, info.get_id(), objv_tracker, y, dpp); -} - -int RGWSI_Role_RADOS::delete_info(RGWSI_MetaBackend::Context *ctx, - const std::string& role_id, - RGWObjVersionTracker * const objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - RGWSI_MBSObj_RemoveParams params; - int r = svc.meta_be->remove(ctx, role_id, params, objv_tracker, y, dpp); - if (r < 0 && r != -ENOENT && r != -ECANCELED) { - ldout(svc.meta_be->ctx(),0) << "ERROR: RGWSI_Role: could not remove role_id = " - << role_id << " r = "<< r << dendl; - } - - return r; -} - -int RGWSI_Role_RADOS::delete_name(RGWSI_MetaBackend::Context *ctx, - const std::string& name, - const std::string& tenant, - RGWObjVersionTracker * const objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - return delete_oid(svc, ctx, get_role_name_meta_key(name, tenant), - objv_tracker, y, dpp); - -} - -int RGWSI_Role_RADOS::delete_path(RGWSI_MetaBackend::Context *ctx, - const std::string& role_id, - const std::string& path, - const std::string& tenant, - RGWObjVersionTracker * const objv_tracker, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - return delete_oid(svc, ctx, get_role_path_meta_key(path, role_id, tenant), - objv_tracker, y, dpp); - -} - -int RGWSI_Role_RADOS::list_roles_by_path_prefix(RGWSI_MetaBackend::Context *ctx, - const std::string& path_prefix, - const std::string& tenant, - std::vector& roles, - optional_yield y, - const DoutPrefixProvider *dpp) -{ - std::string prefix; - // List all roles if path prefix is empty - if (! path_prefix.empty()) { - prefix = tenant + role_path_oid_prefix + path_prefix; - } else { - prefix = tenant + role_path_oid_prefix; - } - - auto syspool = svc.sysobj->get_pool(svc.zone->get_zone_params().roles_pool); - - syspool.list_prefixed_objs(dpp, prefix, [&](const std::string& oid) { - if (auto pos = oid.rfind(role_oid_prefix); - pos != std::string::npos) { - auto path = oid.substr(0, pos); - if (path_prefix.empty() || path.find(path_prefix) != std::string::npos) { - auto role_id = oid.substr(pos + role_oid_prefix.length()); - rgw::sal::RGWRole role; - RGWObjVersionTracker ot; - int r = read_info(ctx, role_id, &role, &ot, nullptr, nullptr, y, dpp); - if (r == 0) { - roles.emplace_back(role); - } - } - } - }); - return 0; // meta_be function calls have to return an int -} -#endif \ No newline at end of file diff --git a/src/rgw/services/svc_role_rados.h b/src/rgw/services/svc_role_rados.h index 294d5050c58..6acfc2f349c 100644 --- a/src/rgw/services/svc_role_rados.h +++ b/src/rgw/services/svc_role_rados.h @@ -15,10 +15,11 @@ #pragma once -#include "svc_role.h" +#include "rgw/rgw_service.h" +#include "rgw/rgw_role.h" #include "svc_meta_be.h" -class RGWSI_Role_RADOS: public RGWSI_Role +class RGWSI_Role_RADOS: public RGWServiceInstance { public: struct Svc { @@ -28,7 +29,7 @@ class RGWSI_Role_RADOS: public RGWSI_Role RGWSI_SysObj *sysobj{nullptr}; } svc; - RGWSI_Role_RADOS(CephContext *cct) : RGWSI_Role(cct) {} + RGWSI_Role_RADOS(CephContext *cct) : RGWServiceInstance(cct) {} ~RGWSI_Role_RADOS() {} void init(RGWSI_Zone *_zone_svc, @@ -36,10 +37,14 @@ class RGWSI_Role_RADOS: public RGWSI_Role RGWSI_MetaBackend *_meta_be_svc, RGWSI_SysObj *_sysobj_svc); - RGWSI_MetaBackend_Handler * get_be_handler() override; + RGWSI_MetaBackend_Handler * get_be_handler(); int do_start(optional_yield y, const DoutPrefixProvider *dpp) override; private: RGWSI_MetaBackend_Handler *be_handler; std::unique_ptr be_module; }; + +static const std::string role_name_oid_prefix = "role_names."; +static const std::string role_oid_prefix = "roles."; +static const std::string role_path_oid_prefix = "role_paths."; \ No newline at end of file -- 2.39.5