Skip to content

Commit

Permalink
RGW - Zipper 10: Pull The Thread
Browse files Browse the repository at this point in the history
This commit changes the RGWStoreManager to return a RGWStore* rather
than a RGWRadosStore*.  This is the thread that unravels the rest of the
Zipper work, removing hard-coded uses of the RGWRados* classes.

Signed-off-by: Daniel Gryniewicz <dang@redhat.com>
  • Loading branch information
dang committed Mar 2, 2021
1 parent c52da5d commit 72d1a36
Show file tree
Hide file tree
Showing 119 changed files with 3,750 additions and 3,235 deletions.
18 changes: 11 additions & 7 deletions src/rgw/librgw.cc
Expand Up @@ -236,7 +236,7 @@ namespace rgw {

RGWObjectCtx rados_ctx(store, s); // XXX holds std::map

auto sysobj_ctx = store->svc()->sysobj->init_obj_ctx();
auto sysobj_ctx = static_cast<rgw::sal::RGWRadosStore*>(store)->svc()->sysobj->init_obj_ctx();
s->sysobj_ctx = &sysobj_ctx;

/* XXX and -then- stash req_state pointers everywhere they are needed */
Expand Down Expand Up @@ -336,7 +336,7 @@ namespace rgw {
<< e.what() << dendl;
}
if (should_log) {
rgw_log_op(store->getRados(), nullptr /* !rest */, s,
rgw_log_op(store, nullptr /* !rest */, s,
(op ? op->name() : "unknown"), olog);
}

Expand Down Expand Up @@ -540,6 +540,7 @@ namespace rgw {

const DoutPrefix dp(cct.get(), dout_subsys, "librgw: ");
store = RGWStoreManager::get_storage(&dp, g_ceph_context,
"rados",
run_gc,
run_lc,
run_quota,
Expand All @@ -558,7 +559,7 @@ namespace rgw {

r = rgw_perf_start(g_ceph_context);

rgw_rest_init(g_ceph_context, store->svc()->zone->get_zonegroup());
rgw_rest_init(g_ceph_context, store->get_zonegroup());

mutex.lock();
init_timer.cancel_all_events();
Expand All @@ -581,7 +582,7 @@ namespace rgw {
ldh->init();
ldh->bind();

rgw_log_usage_init(g_ceph_context, store->getRados());
rgw_log_usage_init(g_ceph_context, store);

// XXX ex-RGWRESTMgr_lib, mgr->set_logging(true)

Expand Down Expand Up @@ -613,7 +614,7 @@ namespace rgw {

fe->run();

r = store->getRados()->register_to_service_map("rgw-nfs", service_map_meta);
r = store->register_to_service_map("rgw-nfs", service_map_meta);
if (r < 0) {
derr << "ERROR: failed to register to service map: " << cpp_strerror(-r) << dendl;
/* ignore error */
Expand Down Expand Up @@ -656,14 +657,17 @@ namespace rgw {
return 0;
} /* RGWLib::stop() */

int RGWLibIO::set_uid(rgw::sal::RGWRadosStore *store, const rgw_user& uid)
int RGWLibIO::set_uid(rgw::sal::RGWStore *store, const rgw_user& uid)
{
const DoutPrefix dp(store->ctx(), dout_subsys, "librgw: ");
int ret = store->ctl()->user->get_info_by_uid(&dp, uid, &user_info, null_yield);
std::unique_ptr<rgw::sal::RGWUser> user = store->get_user(uid);
/* object exists, but policy is broken */
int ret = user->load_by_id(&dp, null_yield);
if (ret < 0) {
derr << "ERROR: failed reading user info: uid=" << uid << " ret="
<< ret << dendl;
}
user_info = user->get_info();
return ret;
}

Expand Down
69 changes: 39 additions & 30 deletions src/rgw/rgw_acl_s3.cc
Expand Up @@ -10,6 +10,7 @@

#include "rgw_acl_s3.h"
#include "rgw_user.h"
#include "rgw_sal.h"

#define dout_subsys ceph_subsys_rgw

Expand Down Expand Up @@ -290,34 +291,33 @@ static const char *get_acl_header(const RGWEnv *env,
return env->get(header, NULL);
}

static int parse_grantee_str(const DoutPrefixProvider *dpp, RGWUserCtl *user_ctl, string& grantee_str,
static int parse_grantee_str(const DoutPrefixProvider *dpp, rgw::sal::RGWStore* store, string& grantee_str,
const struct s3_acl_header *perm, ACLGrant& grant)
{
string id_type, id_val_quoted;
int rgw_perm = perm->rgw_perm;
int ret;

RGWUserInfo info;

ret = parse_key_value(grantee_str, id_type, id_val_quoted);
if (ret < 0)
return ret;

string id_val = rgw_trim_quotes(id_val_quoted);

if (strcasecmp(id_type.c_str(), "emailAddress") == 0) {
ret = user_ctl->get_info_by_email(dpp, id_val, &info, null_yield);
std::unique_ptr<rgw::sal::RGWUser> user;
ret = store->get_user_by_email(dpp, id_val, null_yield, &user);
if (ret < 0)
return ret;

grant.set_canon(info.user_id, info.display_name, rgw_perm);
grant.set_canon(user->get_id(), user->get_display_name(), rgw_perm);
} else if (strcasecmp(id_type.c_str(), "id") == 0) {
rgw_user user(id_val);
ret = user_ctl->get_info_by_uid(dpp, user, &info, null_yield);
std::unique_ptr<rgw::sal::RGWUser> user = store->get_user(rgw_user(id_val));
ret = user->load_by_id(dpp, null_yield);
if (ret < 0)
return ret;

grant.set_canon(info.user_id, info.display_name, rgw_perm);
grant.set_canon(user->get_id(), user->get_display_name(), rgw_perm);
} else if (strcasecmp(id_type.c_str(), "uri") == 0) {
ACLGroupTypeEnum gid = grant.uri_to_group(id_val);
if (gid == ACL_GROUP_NONE)
Expand All @@ -331,8 +331,9 @@ static int parse_grantee_str(const DoutPrefixProvider *dpp, RGWUserCtl *user_ctl
return 0;
}

static int parse_acl_header(const DoutPrefixProvider *dpp, RGWUserCtl *user_ctl, const RGWEnv *env,
const struct s3_acl_header *perm, std::list<ACLGrant>& _grants)
static int parse_acl_header(const DoutPrefixProvider *dpp, rgw::sal::RGWStore* store,
const RGWEnv *env, const struct s3_acl_header *perm,
std::list<ACLGrant>& _grants)
{
std::list<string> grantees;
std::string hacl_str;
Expand All @@ -346,7 +347,7 @@ static int parse_acl_header(const DoutPrefixProvider *dpp, RGWUserCtl *user_ctl,

for (list<string>::iterator it = grantees.begin(); it != grantees.end(); ++it) {
ACLGrant grant;
int ret = parse_grantee_str(dpp, user_ctl, *it, perm, grant);
int ret = parse_grantee_str(dpp, store, *it, perm, grant);
if (ret < 0)
return ret;

Expand Down Expand Up @@ -451,13 +452,15 @@ static const s3_acl_header acl_header_perms[] = {
{0, NULL}
};

int RGWAccessControlPolicy_S3::create_from_headers(const DoutPrefixProvider *dpp, RGWUserCtl *user_ctl, const RGWEnv *env, ACLOwner& _owner)
int RGWAccessControlPolicy_S3::create_from_headers(const DoutPrefixProvider *dpp,
rgw::sal::RGWStore* store,
const RGWEnv *env, ACLOwner& _owner)
{
std::list<ACLGrant> grants;
int r = 0;

for (const struct s3_acl_header *p = acl_header_perms; p->rgw_perm; p++) {
r = parse_acl_header(dpp, user_ctl, env, p, grants);
r = parse_acl_header(dpp, store, env, p, grants);
if (r < 0) {
return r;
}
Expand All @@ -474,8 +477,9 @@ int RGWAccessControlPolicy_S3::create_from_headers(const DoutPrefixProvider *dpp
/*
can only be called on object that was parsed
*/
int RGWAccessControlPolicy_S3::rebuild(const DoutPrefixProvider *dpp, RGWUserCtl *user_ctl, ACLOwner *owner, RGWAccessControlPolicy& dest,
std::string &err_msg)
int RGWAccessControlPolicy_S3::rebuild(const DoutPrefixProvider *dpp,
rgw::sal::RGWStore* store, ACLOwner *owner,
RGWAccessControlPolicy& dest, std::string &err_msg)
{
if (!owner)
return -EINVAL;
Expand All @@ -487,15 +491,15 @@ int RGWAccessControlPolicy_S3::rebuild(const DoutPrefixProvider *dpp, RGWUserCtl
return -EPERM;
}

RGWUserInfo owner_info;
if (user_ctl->get_info_by_uid(dpp, owner->get_id(), &owner_info, null_yield) < 0) {
std::unique_ptr<rgw::sal::RGWUser> user = store->get_user(owner->get_id());
if (user->load_by_id(dpp, null_yield) < 0) {
ldout(cct, 10) << "owner info does not exist" << dendl;
err_msg = "Invalid id";
return -EINVAL;
}
ACLOwner& dest_owner = dest.get_owner();
dest_owner.set_id(owner->get_id());
dest_owner.set_name(owner_info.display_name);
dest_owner.set_name(user->get_display_name());

ldpp_dout(dpp, 20) << "owner id=" << owner->get_id() << dendl;
ldpp_dout(dpp, 20) << "dest owner id=" << dest.get_owner().get_id() << dendl;
Expand All @@ -522,11 +526,12 @@ int RGWAccessControlPolicy_S3::rebuild(const DoutPrefixProvider *dpp, RGWUserCtl
}
email = u.id;
ldout(cct, 10) << "grant user email=" << email << dendl;
if (user_ctl->get_info_by_email(dpp, email, &grant_user, null_yield) < 0) {
if (store->get_user_by_email(dpp, email, null_yield, &user) < 0) {
ldout(cct, 10) << "grant user email not found or other error" << dendl;
err_msg = "The e-mail address you provided does not match any account on record.";
return -ERR_UNRESOLVABLE_EMAIL;
}
grant_user = user->get_info();
uid = grant_user.user_id;
}
case ACL_TYPE_CANON_USER:
Expand All @@ -539,18 +544,22 @@ int RGWAccessControlPolicy_S3::rebuild(const DoutPrefixProvider *dpp, RGWUserCtl
}
}

if (grant_user.user_id.empty() && user_ctl->get_info_by_uid(dpp, uid, &grant_user, null_yield) < 0) {
ldout(cct, 10) << "grant user does not exist:" << uid << dendl;
err_msg = "Invalid id";
return -EINVAL;
} else {
ACLPermission& perm = src_grant.get_permission();
new_grant.set_canon(uid, grant_user.display_name, perm.get_permissions());
grant_ok = true;
rgw_user new_id;
new_grant.get_id(new_id);
ldpp_dout(dpp, 10) << "new grant: " << new_id << ":" << grant_user.display_name << dendl;
if (grant_user.user_id.empty()) {
user = store->get_user(uid);
if (user->load_by_id(dpp, null_yield) < 0) {
ldout(cct, 10) << "grant user does not exist:" << uid << dendl;
err_msg = "Invalid id";
return -EINVAL;
} else {
grant_user = user->get_info();
}
}
ACLPermission& perm = src_grant.get_permission();
new_grant.set_canon(uid, grant_user.display_name, perm.get_permissions());
grant_ok = true;
rgw_user new_id;
new_grant.get_id(new_id);
ldout(cct, 10) << "new grant: " << new_id << ":" << grant_user.display_name << dendl;
}
break;
case ACL_TYPE_GROUP:
Expand Down
8 changes: 5 additions & 3 deletions src/rgw/rgw_acl_s3.h
Expand Up @@ -14,6 +14,7 @@
#include "rgw_acl.h"

class RGWUserCtl;
namespace rgw { namespace sal { class RGWStore; } }

class ACLPermission_S3 : public ACLPermission, public XMLObj
{
Expand Down Expand Up @@ -83,8 +84,8 @@ class RGWAccessControlPolicy_S3 : public RGWAccessControlPolicy, public XMLObj
bool xml_end(const char *el) override;

void to_xml(ostream& out);
int rebuild(const DoutPrefixProvider *dpp, RGWUserCtl *user_ctl, ACLOwner *owner, RGWAccessControlPolicy& dest,
std::string &err_msg);
int rebuild(const DoutPrefixProvider *dpp, rgw::sal::RGWStore* store, ACLOwner *owner,
RGWAccessControlPolicy& dest, std::string &err_msg);
bool compare_group_name(string& id, ACLGroupTypeEnum group) override;

virtual int create_canned(ACLOwner& _owner, ACLOwner& bucket_owner, const string& canned_acl) {
Expand All @@ -97,7 +98,8 @@ class RGWAccessControlPolicy_S3 : public RGWAccessControlPolicy, public XMLObj
int ret = _acl.create_canned(owner, bucket_owner, canned_acl);
return ret;
}
int create_from_headers(const DoutPrefixProvider *dpp, RGWUserCtl *user_ctl, const RGWEnv *env, ACLOwner& _owner);
int create_from_headers(const DoutPrefixProvider *dpp, rgw::sal::RGWStore* store,
const RGWEnv *env, ACLOwner& _owner);
};

/**
Expand Down

0 comments on commit 72d1a36

Please sign in to comment.