rgw: shifting back be_handler and module initialization to svc role

rados.

Signed-off-by: Pritha Srivastava <prsrivas@redhat.com>
This commit is contained in:
Pritha Srivastava 2021-11-19 12:18:47 +05:30
parent 36169ca69f
commit fb1f670fbb
11 changed files with 69 additions and 273 deletions

View File

@ -39,6 +39,8 @@ 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
services/svc_sys_obj_core.cc

View File

@ -233,7 +233,7 @@ 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;
@ -302,7 +302,7 @@ void RGWRoleMetadataHandler::init(RGWSI_Zone *_zone_svc,
base_init(cct, get_be_handler());
}
#if 0
int RGWRoleMetadataHandler::do_start(optional_yield y, const DoutPrefixProvider *dpp)
{
@ -323,14 +323,11 @@ int RGWRoleMetadataHandler::do_start(optional_yield y, const DoutPrefixProvider
#endif
RGWRoleMetadataHandler::RGWRoleMetadataHandler(CephContext *cct, Store* store,
RGWSI_Zone *_zone_svc,
RGWSI_Meta *_meta_svc,
RGWSI_MetaBackend *_meta_be_svc,
RGWSI_SysObj *_sysobj_svc)
RGWSI_Role *role_svc)
{
this->cct = cct;
this->store = store;
init(_zone_svc, _meta_svc, _meta_be_svc, _sysobj_svc);
base_init(role_svc->ctx(), role_svc->get_be_handler());
}
void RGWRoleCompleteInfo::dump(ceph::Formatter *f) const
@ -370,8 +367,9 @@ int RGWRoleMetadataHandler::do_get(RGWSI_MetaBackend_Handler::Op *op,
const DoutPrefixProvider *dpp)
{
RGWRoleCompleteInfo rci;
rci.info = store->get_role(entry).get();
int ret = rci.info->read_info(dpp, y);
std::unique_ptr<rgw::sal::RGWRole> role = store->get_role(entry);
rci.info = role.get();
int ret = rci.info->read_info(dpp, y, false);
if (ret < 0) {
return ret;
}
@ -393,7 +391,7 @@ int RGWRoleMetadataHandler::do_remove(RGWSI_MetaBackend_Handler::Op *op,
const DoutPrefixProvider *dpp)
{
std::unique_ptr<rgw::sal::RGWRole> role = store->get_role(entry);
int ret = role->read_info(dpp, y);
int ret = role->read_info(dpp, y, false);
if (ret < 0) {
return ret == -ENOENT? 0 : ret;
}
@ -423,7 +421,7 @@ public:
auto& rci = mdo->get_rci();
auto mtime = mdo->get_mtime();
rci.info->set_mtime(mtime);
int ret = rci.info->create(dpp, true, y);
int ret = rci.info->create(dpp, true, y, false);
return ret < 0 ? ret : STATUS_APPLIED;
}
};

View File

@ -44,12 +44,12 @@ protected:
real_time mtime;
public:
virtual int store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) = 0;
virtual int store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y, bool addprefix=true) = 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) = 0;
virtual int read_info(const DoutPrefixProvider *dpp, optional_yield y, bool addprefix=true) = 0;
bool validate_input(const DoutPrefixProvider* dpp);
void extract_name_tenant(const std::string& str);
@ -127,7 +127,7 @@ public:
void set_id(const std::string& id) { this->id = id; }
void set_mtime(const real_time& mtime) { this->mtime = mtime; }
virtual int create(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) = 0;
virtual int create(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y, bool addprefix=true) = 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);
@ -177,27 +177,12 @@ public:
class RGWRoleMetadataHandler: public RGWMetadataHandler_GenericMetaBE
{
public:
public:
struct Svc {
RGWSI_Zone *zone{nullptr};
RGWSI_Meta *meta{nullptr};
RGWSI_MetaBackend *meta_be{nullptr};
RGWSI_SysObj *sysobj{nullptr};
RGWSI_Role *role{nullptr};
} svc;
void init(RGWSI_Zone *_zone_svc,
RGWSI_Meta *_meta_svc,
RGWSI_MetaBackend *_meta_be_svc,
RGWSI_SysObj *_sysobj_svc);
RGWSI_MetaBackend_Handler * get_be_handler();
//int do_start(optional_yield y, const DoutPrefixProvider *dpp);
RGWRoleMetadataHandler(CephContext *cct, Store* store,
RGWSI_Zone *_zone_svc,
RGWSI_Meta *_meta_svc,
RGWSI_MetaBackend *_meta_be_svc,
RGWSI_SysObj *_sysobj_svc);
RGWRoleMetadataHandler(CephContext *cct, Store* store, RGWSI_Role *role_svc);
std::string get_type() final { return "roles"; }
@ -227,8 +212,6 @@ public:
bool from_remote_zone) override;
private:
RGWSI_MetaBackend_Handler *be_handler;
std::unique_ptr<RGWSI_MetaBackend::Module> be_module;
Store* store;
CephContext *cct;
};

View File

@ -44,6 +44,7 @@
#include "services/svc_quota.h"
#include "services/svc_config_key.h"
#include "services/svc_zone_utils.h"
#include "services/svc_role_rados.h"
#include "cls/rgw/cls_rgw_client.h"
#include "rgw_pubsub.h"
@ -3061,11 +3062,16 @@ int RadosOIDCProvider::delete_obj(const DoutPrefixProvider *dpp, optional_yield
return ret;
}
int RadosRole::store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y)
int RadosRole::store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y, bool addprefix)
{
using ceph::encode;
//auto obj_ctx = store->svc()->sysobj->init_obj_ctx();
std::string oid = get_info_oid_prefix() + id;
std::string oid;
if (addprefix) {
oid = get_info_oid_prefix() + id;
} else {
oid = id;
}
bufferlist bl;
encode(*this, bl);
@ -3077,14 +3083,9 @@ int RadosRole::store_info(const DoutPrefixProvider *dpp, bool exclusive, optiona
}
RGWSI_MBSObj_PutParams params(bl, &attrs, mtime, exclusive);
return store->svc()->meta_be_sobj->put(store->svc()->meta_be_sobj->alloc_ctx(), oid, params, &objv_tracker, y, dpp);
#if 0
if (!attrs.empty()) {
return rgw_put_system_obj(dpp, obj_ctx, store->get_zone()->get_params().roles_pool, oid, bl, exclusive, nullptr, mtime, y, &attrs);
}
return rgw_put_system_obj(dpp, obj_ctx, store->get_zone()->get_params().roles_pool, oid, bl, exclusive, nullptr, mtime, y);
#endif
std::unique_ptr<RGWSI_MetaBackend::Context> ctx(store->svc()->role->svc.meta_be->alloc_ctx());
ctx->init(store->svc()->role->get_be_handler());
return store->svc()->role->svc.meta_be->put(ctx.get(), oid, params, &objv_tracker, y, dpp);
}
int RadosRole::store_name(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y)
@ -3162,18 +3163,32 @@ int RadosRole::read_name(const DoutPrefixProvider *dpp, optional_yield y)
return 0;
}
int RadosRole::read_info(const DoutPrefixProvider *dpp, optional_yield y)
int RadosRole::read_info(const DoutPrefixProvider *dpp, optional_yield y, bool addprefix)
{
auto obj_ctx = store->svc()->sysobj->init_obj_ctx();
std::string oid = get_info_oid_prefix() + id;
//auto obj_ctx = store->svc()->sysobj->init_obj_ctx();
std::string oid;
if (addprefix) {
oid = get_info_oid_prefix() + id;
} else {
oid = id;
}
bufferlist bl;
int ret = rgw_get_system_obj(obj_ctx, store->svc()->zone->get_zone_params().roles_pool, oid, bl, &objv_tracker, &mtime, null_yield, dpp, &attrs, nullptr, boost::none, true);
RGWSI_MBSObj_GetParams params(&bl, &attrs, &mtime);
std::unique_ptr<RGWSI_MetaBackend::Context> ctx(store->svc()->role->svc.meta_be->alloc_ctx());
ctx->init(store->svc()->role->get_be_handler());
int ret = store->svc()->role->svc.meta_be->get_entry(ctx.get(), oid, params, &objv_tracker, y, dpp);
if (ret < 0) {
return ret;
}
#if 0
int ret = rgw_get_system_obj(obj_ctx, store->get_zone()->get_params().roles_pool, oid, bl, &objv_tracker, &mtime, null_yield, dpp, &attrs, nullptr, boost::none, true);
if (ret < 0) {
ldpp_dout(dpp, 0) << "ERROR: failed reading role info from Role pool: " << id << ": " << cpp_strerror(-ret) << dendl;
return ret;
}
#endif
try {
using ceph::decode;
auto iter = bl.cbegin();
@ -3199,7 +3214,7 @@ int RadosRole::read_info(const DoutPrefixProvider *dpp, optional_yield y)
return 0;
}
int RadosRole::create(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y)
int RadosRole::create(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y, bool addprefix)
{
int ret;
@ -3243,7 +3258,7 @@ int RadosRole::create(const DoutPrefixProvider *dpp, bool exclusive, optional_yi
creation_date.assign(buf, strlen(buf));
auto& pool = store->svc()->zone->get_zone_params().roles_pool;
ret = store_info(dpp, exclusive, y);
ret = store_info(dpp, exclusive, y, addprefix);
if (ret < 0) {
ldpp_dout(dpp, 0) << "ERROR: storing role info in Role pool: "
<< id << ": " << cpp_strerror(-ret) << dendl;

View File

@ -906,13 +906,13 @@ public:
RadosRole(RadosStore* _store) : store(_store) {}
~RadosRole() = default;
virtual int store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y) override;
virtual int store_info(const DoutPrefixProvider *dpp, bool exclusive, optional_yield y, bool addprefix=true) 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) override;
virtual int create(const DoutPrefixProvider *dpp, bool exclusive, 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 delete_obj(const DoutPrefixProvider *dpp, optional_yield y) override;
};
}} // namespace rgw::sal

View File

@ -77,6 +77,7 @@ int RGWServices_Def::init(CephContext *cct,
sysobj = std::make_unique<RGWSI_SysObj>(cct);
sysobj_core = std::make_unique<RGWSI_SysObj_Core>(cct);
user_rados = std::make_unique<RGWSI_User_RADOS>(cct);
role_rados = std::make_unique<RGWSI_Role_RADOS>(cct);
if (have_cache) {
sysobj_cache = std::make_unique<RGWSI_SysObj_Cache>(dpp, cct);
@ -116,6 +117,7 @@ int RGWServices_Def::init(CephContext *cct,
}
user_rados->init(rados.get(), zone.get(), sysobj.get(), sysobj_cache.get(),
meta.get(), meta_be_sobj.get(), sync_modules.get());
role_rados->init(zone.get(), meta.get(), meta_be_sobj.get(), sysobj.get());
can_shutdown = true;
@ -248,6 +250,12 @@ int RGWServices_Def::init(CephContext *cct,
return r;
}
r = role_rados->start(y, dpp);
if (r < 0) {
ldout(cct, 0) << "ERROR: failed to start role_rados service (" << cpp_strerror(-r) << dendl;
return r;
}
}
/* cache or core services will be started by sysobj */
@ -317,6 +325,7 @@ int RGWServices::do_init(CephContext *_cct, bool have_cache, bool raw, bool run_
cache = _svc.sysobj_cache.get();
core = _svc.sysobj_core.get();
user = _svc.user_rados.get();
role = _svc.role_rados.get();
return 0;
}
@ -364,7 +373,7 @@ int RGWCtlDef::init(RGWServices& svc, rgw::sal::Store* store, const DoutPrefixPr
}
meta.otp.reset(RGWOTPMetaHandlerAllocator::alloc());
meta.role = std::make_unique<rgw::sal::RGWRoleMetadataHandler>(svc.cct, store, svc.zone, svc.meta, svc.meta_be_sobj, svc.sysobj);
meta.role = std::make_unique<rgw::sal::RGWRoleMetadataHandler>(svc.cct, store, svc.role);
user.reset(new RGWUserCtl(svc.zone, svc.user, (RGWUserMetadataHandler *)meta.user.get()));
bucket.reset(new RGWBucketCtl(svc.zone,

View File

@ -75,7 +75,8 @@ class RGWSI_SysObj_Cache;
class RGWSI_User;
class RGWSI_User_RADOS;
class RGWDataChangesLog;
class RGWRole;
class RGWSI_Role;
class RGWSI_Role_RADOS;
struct RGWServices_Def
{
@ -105,6 +106,7 @@ struct RGWServices_Def
std::unique_ptr<RGWSI_SysObj_Cache> sysobj_cache;
std::unique_ptr<RGWSI_User_RADOS> user_rados;
std::unique_ptr<RGWDataChangesLog> datalog_rados;
std::unique_ptr<RGWSI_Role_RADOS> role_rados;
RGWServices_Def();
~RGWServices_Def();
@ -147,7 +149,7 @@ struct RGWServices
RGWSI_SysObj_Cache *cache{nullptr};
RGWSI_SysObj_Core *core{nullptr};
RGWSI_User *user{nullptr};
RGWRole *role{nullptr};
RGWSI_Role_RADOS *role{nullptr};
int do_init(CephContext *cct, bool have_cache, bool raw_storage, bool run_sync, optional_yield y, const DoutPrefixProvider *dpp);

View File

@ -1,16 +1 @@
#include "svc_role.h"
std::string RGWSI_Role::get_role_meta_key(const std::string& role_id)
{
return role_oid_prefix + role_id;
}
std::string RGWSI_Role::get_role_name_meta_key(const std::string& role_name, const std::string& tenant)
{
return tenant + role_name_oid_prefix + role_name;
}
std::string RGWSI_Role::get_role_path_meta_key(const std::string& path, const std::string& role_id, const std::string& tenant)
{
return tenant + role_path_oid_prefix + path + role_oid_prefix + role_id;
}

View File

@ -26,108 +26,6 @@ class RGWSI_Role: public RGWServiceInstance
virtual ~RGWSI_Role() {}
virtual RGWSI_MetaBackend_Handler* get_be_handler() = 0;
static std::string get_role_meta_key(const std::string& role_id);
static std::string get_role_name_meta_key(const std::string& role_name, const std::string& tenant);
static std::string get_role_path_meta_key(const std::string& path, const std::string& role_id, const std::string& tenant);
virtual int create(RGWSI_MetaBackend::Context *ctx,
rgw::sal::RGWRole& role,
RGWObjVersionTracker * const objv_tracker,
const real_time& pmtime,
bool exclusive,
std::map<std::string, bufferlist> * pattrs,
optional_yield y,
const DoutPrefixProvider *dpp) = 0;
virtual int store_info(RGWSI_MetaBackend::Context *ctx,
const rgw::sal::RGWRole& role,
RGWObjVersionTracker * const objv_tracker,
const real_time& mtime,
bool exclusive,
std::map<std::string, bufferlist> * pattrs,
optional_yield y,
const DoutPrefixProvider *dpp) = 0;
virtual int 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) = 0;
virtual int 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) = 0;
virtual int read_info(RGWSI_MetaBackend::Context *ctx,
const std::string& role_id,
rgw::sal::RGWRole *role, // out param
RGWObjVersionTracker * const objv_tracker,
real_time * const pmtime,
std::map<std::string, bufferlist> * pattrs,
optional_yield y,
const DoutPrefixProvider *dpp) = 0;
virtual int 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) = 0;
virtual int read_path(RGWSI_MetaBackend::Context *ctx,
std::string& path,
RGWObjVersionTracker * const objv_tracker,
real_time * const pmtime,
optional_yield y,
const DoutPrefixProvider *dpp) = 0;
virtual int delete_info(RGWSI_MetaBackend::Context *ctx,
const std::string& id,
RGWObjVersionTracker * const objv_tracker,
optional_yield y,
const DoutPrefixProvider *dpp) = 0;
// deletes a role from the system and the supporting objects
virtual int delete_role(RGWSI_MetaBackend::Context *ctx,
const rgw::sal::RGWRole& info,
RGWObjVersionTracker * const objv_tracker,
optional_yield y,
const DoutPrefixProvider *dpp) = 0;
virtual int delete_name(RGWSI_MetaBackend::Context *ctx,
const std::string& name,
const std::string& tenant,
RGWObjVersionTracker * const objv_tracker,
optional_yield y,
const DoutPrefixProvider *dpp) = 0;
virtual int 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) = 0;
virtual int list_roles_by_path_prefix(RGWSI_MetaBackend::Context *ctx,
const std::string& path,
const std::string& tenant,
std::vector<rgw::sal::RGWRole>& roles, // out param
optional_yield y,
const DoutPrefixProvider *dpp) = 0;
};
static const std::string role_name_oid_prefix = "role_names.";

View File

@ -80,7 +80,7 @@ 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;
@ -436,3 +436,4 @@ int RGWSI_Role_RADOS::list_roles_by_path_prefix(RGWSI_MetaBackend::Context *ctx,
});
return 0; // meta_be function calls have to return an int
}
#endif

View File

@ -39,103 +39,6 @@ class RGWSI_Role_RADOS: public RGWSI_Role
RGWSI_MetaBackend_Handler * get_be_handler() override;
int do_start(optional_yield y, const DoutPrefixProvider *dpp) override;
int store_info(RGWSI_MetaBackend::Context *ctx,
const rgw::sal::RGWRole& role,
RGWObjVersionTracker * const objv_tracker,
const real_time& pmtime,
bool exclusive,
std::map<std::string, bufferlist> * pattrs,
optional_yield y,
const DoutPrefixProvider *dpp) override;
int create(RGWSI_MetaBackend::Context *ctx,
rgw::sal::RGWRole& role,
RGWObjVersionTracker * const objv_tracker,
const real_time& pmtime,
bool exclusive,
std::map<std::string, bufferlist> * pattrs,
optional_yield y,
const DoutPrefixProvider *dpp) override;
int 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) override;
int 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) override;
int 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<std::string, bufferlist> * pattrs,
optional_yield y,
const DoutPrefixProvider *dpp) override;
int 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) override;
int read_path(RGWSI_MetaBackend::Context *ctx,
std::string& path,
RGWObjVersionTracker * const objv_tracker,
real_time * const pmtime,
optional_yield y,
const DoutPrefixProvider *dpp) override { return 0; } // TODO impl me
int delete_role(RGWSI_MetaBackend::Context *ctx,
const rgw::sal::RGWRole& info,
RGWObjVersionTracker * const objv_tracker,
optional_yield y,
const DoutPrefixProvider *dpp) override;
int delete_info(RGWSI_MetaBackend::Context *ctx,
const std::string& role_id,
RGWObjVersionTracker * const objv_tracker,
optional_yield y,
const DoutPrefixProvider *dpp) override;
int delete_name(RGWSI_MetaBackend::Context *ctx,
const std::string& name,
const std::string& tenant,
RGWObjVersionTracker * const objv_tracker,
optional_yield y,
const DoutPrefixProvider *dpp) override;
int 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) override;
int list_roles_by_path_prefix(RGWSI_MetaBackend::Context *ctx,
const std::string& path,
const std::string& tenant,
std::vector<rgw::sal::RGWRole>& roles,
optional_yield y,
const DoutPrefixProvider *dpp) override;
private:
RGWSI_MetaBackend_Handler *be_handler;
std::unique_ptr<RGWSI_MetaBackend::Module> be_module;