Skip to content

Commit 78bbf69

Browse files
committed
rgw/metadata: encapsulate role metadata handler in rgw_role.cc
Signed-off-by: Casey Bodley <[email protected]>
1 parent a2b37a1 commit 78bbf69

File tree

10 files changed

+104
-91
lines changed

10 files changed

+104
-91
lines changed

src/rgw/driver/posix/rgw_sal_posix.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <unistd.h>
2121
#include "rgw_multi.h"
2222
#include "include/scope_guard.h"
23+
#include "common/errno.h"
2324

2425
#define dout_subsys ceph_subsys_rgw
2526
#define dout_context g_ceph_context

src/rgw/driver/rados/rgw_service.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ int RGWCtlDef::init(RGWServices& svc, rgw::sal::Driver* driver,
385385

386386
meta.otp = rgwrados::otp::create_metadata_handler(
387387
*svc.sysobj, *svc.cls, *svc.mdlog, svc.zone->get_zone_params());
388-
meta.role = std::make_unique<rgw::sal::RGWRoleMetadataHandler>(driver, svc.role);
388+
meta.role = create_role_metadata_handler(driver, svc.role);
389389
meta.account = rgwrados::account::create_metadata_handler(
390390
*svc.sysobj, svc.zone->get_zone_params());
391391
meta.group = rgwrados::group::create_metadata_handler(

src/rgw/driver/rados/roles.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int add(const DoutPrefixProvider* dpp,
2828
optional_yield y,
2929
librados::Rados& rados,
3030
const rgw_raw_obj& obj,
31-
const rgw::sal::RGWRoleInfo& role,
31+
const RGWRoleInfo& role,
3232
bool exclusive, uint32_t limit)
3333
{
3434
resource_metadata meta;

src/rgw/driver/rados/roles.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace ceph { class Formatter; }
2525
class DoutPrefixProvider;
2626
class optional_yield;
2727
struct rgw_raw_obj;
28+
struct RGWRoleInfo;
2829

2930

3031
namespace rgwrados::roles {
@@ -34,7 +35,7 @@ int add(const DoutPrefixProvider* dpp,
3435
optional_yield y,
3536
librados::Rados& rados,
3637
const rgw_raw_obj& obj,
37-
const rgw::sal::RGWRoleInfo& role,
38+
const RGWRoleInfo& role,
3839
bool exclusive, uint32_t limit);
3940

4041
/// Look up a role's id by name in the list.

src/rgw/rgw_rest_role.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int RGWRestRole::check_caps(const RGWUserCaps& caps)
4040
return caps.check_cap("roles", perm);
4141
}
4242

43-
static void dump_iam_role(const rgw::sal::RGWRoleInfo& role, Formatter *f)
43+
static void dump_iam_role(const RGWRoleInfo& role, Formatter *f)
4444
{
4545
encode_json("RoleId", role.id, f);
4646
encode_json("RoleName", role.name, f);
@@ -582,7 +582,7 @@ int RGWPutRolePolicy::init_processing(optional_yield y)
582582

583583
try {
584584
// non-account identity policy is restricted to the current tenant
585-
const rgw::sal::RGWRoleInfo& info = role->get_info();
585+
const RGWRoleInfo& info = role->get_info();
586586
const std::string* policy_tenant = account_id.empty() ? &info.tenant : nullptr;
587587
const rgw::IAM::Policy p(
588588
s->cct, policy_tenant, perm_policy,

src/rgw/rgw_role.cc

Lines changed: 79 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "rgw_string.h"
1818

1919
#include "rgw_common.h"
20+
#include "rgw_metadata.h"
2021
#include "rgw_tools.h"
2122
#include "rgw_role.h"
2223

@@ -30,13 +31,6 @@
3031

3132
using namespace std;
3233

33-
namespace rgw { namespace sal {
34-
35-
const string RGWRole::role_name_oid_prefix = "role_names.";
36-
const string RGWRole::role_oid_prefix = "roles.";
37-
const string RGWRole::role_path_oid_prefix = "role_paths.";
38-
const string RGWRole::role_arn_prefix = "arn:aws:iam::";
39-
4034
void RGWRoleInfo::dump(Formatter *f) const
4135
{
4236
encode_json("RoleId", id , f);
@@ -134,6 +128,13 @@ void RGWRoleInfo::decode_json(JSONObj *obj)
134128
}
135129
}
136130

131+
namespace rgw::sal {
132+
133+
const string RGWRole::role_name_oid_prefix = "role_names.";
134+
const string RGWRole::role_oid_prefix = "roles.";
135+
const string RGWRole::role_path_oid_prefix = "role_paths.";
136+
const string RGWRole::role_arn_prefix = "arn:aws:iam::";
137+
137138
RGWRole::RGWRole(std::string name,
138139
std::string tenant,
139140
rgw_account_id account_id,
@@ -347,10 +348,64 @@ const string& RGWRole::get_path_oid_prefix()
347348
return role_path_oid_prefix;
348349
}
349350

350-
RGWRoleMetadataHandler::RGWRoleMetadataHandler(Driver* driver,
351-
RGWSI_Role_RADOS *role_svc)
351+
} // namespace rgw::sal
352+
353+
354+
class RGWRoleMetadataObject: public RGWMetadataObject {
355+
RGWRoleInfo info;
356+
public:
357+
RGWRoleMetadataObject(const RGWRoleInfo& info, const obj_version& v, real_time m)
358+
: RGWMetadataObject(v, m), info(info) {}
359+
360+
void dump(Formatter *f) const override {
361+
info.dump(f);
362+
}
363+
364+
RGWRoleInfo& get_role_info() {
365+
return info;
366+
}
367+
};
368+
369+
class RGWRoleMetadataHandler: public RGWMetadataHandler_GenericMetaBE
370+
{
371+
public:
372+
RGWRoleMetadataHandler(rgw::sal::Driver* driver, RGWSI_Role_RADOS *role_svc);
373+
374+
std::string get_type() final { return "roles"; }
375+
376+
RGWMetadataObject *get_meta_obj(JSONObj *jo,
377+
const obj_version& objv,
378+
const ceph::real_time& mtime);
379+
380+
int do_get(RGWSI_MetaBackend_Handler::Op *op,
381+
std::string& entry,
382+
RGWMetadataObject **obj,
383+
optional_yield y,
384+
const DoutPrefixProvider *dpp) final;
385+
386+
int do_remove(RGWSI_MetaBackend_Handler::Op *op,
387+
std::string& entry,
388+
RGWObjVersionTracker& objv_tracker,
389+
optional_yield y,
390+
const DoutPrefixProvider *dpp) final;
391+
392+
int do_put(RGWSI_MetaBackend_Handler::Op *op,
393+
std::string& entr,
394+
RGWMetadataObject *obj,
395+
RGWObjVersionTracker& objv_tracker,
396+
optional_yield y,
397+
const DoutPrefixProvider *dpp,
398+
RGWMDLogSyncType type,
399+
bool from_remote_zone) override;
400+
401+
private:
402+
rgw::sal::Driver* driver;
403+
};
404+
405+
RGWRoleMetadataHandler::RGWRoleMetadataHandler(rgw::sal::Driver* driver,
406+
RGWSI_Role_RADOS *role_svc)
407+
: driver(driver)
352408
{
353-
this->driver = driver;
354409
base_init(role_svc->ctx(), role_svc->get_be_handler());
355410
}
356411

@@ -366,7 +421,7 @@ RGWMetadataObject *RGWRoleMetadataHandler::get_meta_obj(JSONObj *jo,
366421
return nullptr;
367422
}
368423

369-
return new RGWRoleMetadataObject(info, objv, mtime, driver);
424+
return new RGWRoleMetadataObject(info, objv, mtime);
370425
}
371426

372427
int RGWRoleMetadataHandler::do_get(RGWSI_MetaBackend_Handler::Op *op,
@@ -381,13 +436,11 @@ int RGWRoleMetadataHandler::do_get(RGWSI_MetaBackend_Handler::Op *op,
381436
return ret;
382437
}
383438

439+
const RGWRoleInfo& info = role->get_info();
384440
RGWObjVersionTracker objv_tracker = role->get_objv_tracker();
385441
real_time mtime = role->get_mtime();
386442

387-
RGWRoleInfo info = role->get_info();
388-
RGWRoleMetadataObject *rdo = new RGWRoleMetadataObject(info, objv_tracker.read_version,
389-
mtime, driver);
390-
*obj = rdo;
443+
*obj = new RGWRoleMetadataObject(info, objv_tracker.read_version, mtime);
391444

392445
return 0;
393446
}
@@ -409,10 +462,12 @@ int RGWRoleMetadataHandler::do_remove(RGWSI_MetaBackend_Handler::Op *op,
409462

410463
class RGWMetadataHandlerPut_Role : public RGWMetadataHandlerPut_SObj
411464
{
465+
rgw::sal::Driver* driver;
412466
RGWRoleMetadataHandler *rhandler;
413467
RGWRoleMetadataObject *mdo;
414468
public:
415-
RGWMetadataHandlerPut_Role(RGWRoleMetadataHandler *handler,
469+
RGWMetadataHandlerPut_Role(rgw::sal::Driver* driver,
470+
RGWRoleMetadataHandler *handler,
416471
RGWSI_MetaBackend_Handler::Op *op,
417472
std::string& entry,
418473
RGWMetadataObject *obj,
@@ -421,14 +476,13 @@ class RGWMetadataHandlerPut_Role : public RGWMetadataHandlerPut_SObj
421476
RGWMDLogSyncType type,
422477
bool from_remote_zone) :
423478
RGWMetadataHandlerPut_SObj(handler, op, entry, obj, objv_tracker, y, type, from_remote_zone),
424-
rhandler(handler) {
479+
driver(driver), rhandler(handler) {
425480
mdo = static_cast<RGWRoleMetadataObject*>(obj);
426481
}
427482

428483
int put_checked(const DoutPrefixProvider *dpp) override {
429484
auto& info = mdo->get_role_info();
430485
auto mtime = mdo->get_mtime();
431-
auto* driver = mdo->get_driver();
432486
info.mtime = mtime;
433487
std::unique_ptr<rgw::sal::RGWRole> role = driver->get_role(info);
434488
constexpr bool exclusive = false;
@@ -450,8 +504,13 @@ int RGWRoleMetadataHandler::do_put(RGWSI_MetaBackend_Handler::Op *op,
450504
RGWMDLogSyncType type,
451505
bool from_remote_zone)
452506
{
453-
RGWMetadataHandlerPut_Role put_op(this, op , entry, obj, objv_tracker, y, type, from_remote_zone);
507+
RGWMetadataHandlerPut_Role put_op(driver, this, op , entry, obj, objv_tracker, y, type, from_remote_zone);
454508
return do_put_operate(&put_op, dpp);
455509
}
456510

457-
} } // namespace rgw::sal
511+
auto create_role_metadata_handler(rgw::sal::Driver* driver,
512+
RGWSI_Role_RADOS *role_svc)
513+
-> std::unique_ptr<RGWMetadataHandler>
514+
{
515+
return std::make_unique<RGWRoleMetadataHandler>(driver, role_svc);
516+
}

src/rgw/rgw_role.h

Lines changed: 15 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33

44
#pragma once
55

6+
#include <map>
67
#include <string>
78

9+
#include "include/encoding.h"
810
#include "common/async/yield_context.h"
9-
10-
#include "common/ceph_json.h"
1111
#include "common/ceph_context.h"
12-
#include "rgw_rados.h"
13-
#include "rgw_metadata.h"
12+
#include "common/ceph_json.h"
13+
#include "common/ceph_time.h"
14+
#include "rgw_common.h"
1415
#include "rgw_iam_managed_policy.h"
1516

16-
class RGWRados;
17-
18-
namespace rgw { namespace sal {
19-
struct RGWRoleInfo
17+
struct RGWRoleInfo // TODO: move to rgw_common.h
2018
{
2119
std::string id;
2220
std::string name;
@@ -34,7 +32,7 @@ struct RGWRoleInfo
3432
std::multimap<std::string,std::string> tags;
3533
std::map<std::string, bufferlist> attrs;
3634
RGWObjVersionTracker objv_tracker;
37-
real_time mtime;
35+
ceph::real_time mtime;
3836
rgw_account_id account_id;
3937

4038
RGWRoleInfo() = default;
@@ -86,6 +84,8 @@ struct RGWRoleInfo
8684
};
8785
WRITE_CLASS_ENCODER(RGWRoleInfo)
8886

87+
namespace rgw::sal {
88+
8989
class RGWRole
9090
{
9191
public:
@@ -164,62 +164,12 @@ class RGWRole
164164
static const std::string& get_path_oid_prefix();
165165
};
166166

167-
class RGWRoleMetadataObject: public RGWMetadataObject {
168-
RGWRoleInfo info;
169-
Driver* driver;
170-
public:
171-
RGWRoleMetadataObject() = default;
172-
RGWRoleMetadataObject(RGWRoleInfo& info,
173-
const obj_version& v,
174-
real_time m,
175-
Driver* driver) : RGWMetadataObject(v,m), info(info), driver(driver) {}
176-
177-
void dump(Formatter *f) const override {
178-
info.dump(f);
179-
}
167+
} // namespace rgw::sal
180168

181-
RGWRoleInfo& get_role_info() {
182-
return info;
183-
}
184169

185-
Driver* get_driver() {
186-
return driver;
187-
}
188-
};
170+
class RGWMetadataHandler;
171+
class RGWSI_Role_RADOS;
189172

190-
class RGWRoleMetadataHandler: public RGWMetadataHandler_GenericMetaBE
191-
{
192-
public:
193-
RGWRoleMetadataHandler(Driver* driver, RGWSI_Role_RADOS *role_svc);
194-
195-
std::string get_type() final { return "roles"; }
196-
197-
RGWMetadataObject *get_meta_obj(JSONObj *jo,
198-
const obj_version& objv,
199-
const ceph::real_time& mtime);
200-
201-
int do_get(RGWSI_MetaBackend_Handler::Op *op,
202-
std::string& entry,
203-
RGWMetadataObject **obj,
204-
optional_yield y,
205-
const DoutPrefixProvider *dpp) final;
206-
207-
int do_remove(RGWSI_MetaBackend_Handler::Op *op,
208-
std::string& entry,
209-
RGWObjVersionTracker& objv_tracker,
210-
optional_yield y,
211-
const DoutPrefixProvider *dpp) final;
212-
213-
int do_put(RGWSI_MetaBackend_Handler::Op *op,
214-
std::string& entr,
215-
RGWMetadataObject *obj,
216-
RGWObjVersionTracker& objv_tracker,
217-
optional_yield y,
218-
const DoutPrefixProvider *dpp,
219-
RGWMDLogSyncType type,
220-
bool from_remote_zone) override;
221-
222-
private:
223-
Driver* driver;
224-
};
225-
} } // namespace rgw::sal
173+
auto create_role_metadata_handler(rgw::sal::Driver* driver,
174+
RGWSI_Role_RADOS *role_svc)
175+
-> std::unique_ptr<RGWMetadataHandler>;

src/rgw/rgw_sal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct rgw_pubsub_bucket_topics;
4848
class RGWZonePlacementInfo;
4949
struct rgw_pubsub_topic;
5050
struct RGWOIDCProviderInfo;
51+
struct RGWRoleInfo;
5152

5253
using RGWBucketListNameFilter = std::function<bool (const std::string&)>;
5354

src/rgw/rgw_sal_dbstore.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "rgw_sal_dbstore.h"
2727
#include "rgw_bucket.h"
2828

29+
#include "driver/rados/rgw_rados.h" // XXX: for RGW_OBJ_NS_MULTIPART, PUT_OBJ_CREATE, etc
30+
2931
#define dout_subsys ceph_subsys_rgw
3032

3133
using namespace std;

src/rgw/rgw_sal_fwd.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ namespace sal {
4545
class ZoneGroup;
4646
class Zone;
4747
class LuaManager;
48-
struct RGWRoleInfo;
4948
class RGWRole;
5049
struct RoleList;
5150
struct GroupList;

0 commit comments

Comments
 (0)