From: Casey Bodley Date: Thu, 30 Nov 2023 21:55:11 +0000 (-0500) Subject: rgw/rados: generalize RGWUID for accounts X-Git-Tag: v19.1.0~99^2~147 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=19128cfb62afbf941f8329644c2998f744a60bf1;p=ceph.git rgw/rados: generalize RGWUID for accounts Signed-off-by: Casey Bodley (cherry picked from commit c72a51e08c5fb570a270efc3e1a7aff1e0383d16) --- diff --git a/src/rgw/driver/rados/rgw_user.h b/src/rgw/driver/rados/rgw_user.h index ef847df5c1d04..c4585413a3b3a 100644 --- a/src/rgw/driver/rados/rgw_user.h +++ b/src/rgw/driver/rados/rgw_user.h @@ -31,31 +31,28 @@ class RGWBucketCtl; class RGWUserBuckets; /** - * A string wrapper that includes encode/decode functions - * for easily accessing a UID in all forms + * A string wrapper that includes encode/decode functions for easily accessing + * a UID in all forms. In some objects, this may refer to an account id instead + * of a user. */ struct RGWUID { - rgw_user user_id; + std::string id; void encode(bufferlist& bl) const { - std::string s; - user_id.to_str(s); using ceph::encode; - encode(s, bl); + encode(id, bl); } void decode(bufferlist::const_iterator& bl) { - std::string s; using ceph::decode; - decode(s, bl); - user_id.from_str(s); + decode(id, bl); } void dump(Formatter *f) const { - f->dump_string("user_id", user_id.to_str()); + f->dump_string("user_id", id); } static void generate_test_instances(std::list& o) { o.push_back(new RGWUID); o.push_back(new RGWUID); - o.back()->user_id.from_str("test:tester"); + o.back()->id = "test:tester"; } }; WRITE_CLASS_ENCODER(RGWUID) diff --git a/src/rgw/services/svc_user_rados.cc b/src/rgw/services/svc_user_rados.cc index 0d01c96d481ff..9d06d5f13af99 100644 --- a/src/rgw/services/svc_user_rados.cc +++ b/src/rgw/services/svc_user_rados.cc @@ -13,6 +13,7 @@ #include "svc_sync_modules.h" #include "rgw_user.h" +#include "rgw_account.h" #include "rgw_bucket.h" #include "rgw_tools.h" #include "rgw_zone.h" @@ -136,8 +137,8 @@ int RGWSI_User_RADOS::read_user_info(RGWSI_MetaBackend::Context *ctx, auto iter = bl.cbegin(); try { decode(user_id, iter); - if (user_id.user_id != user) { - ldpp_dout(dpp, -1) << "ERROR: rgw_get_user_info_by_uid(): user id mismatch: " << user_id.user_id << " != " << user << dendl; + if (rgw_user{user_id.id} != user) { + ldpp_dout(dpp, -1) << "ERROR: rgw_get_user_info_by_uid(): user id mismatch: " << user_id.id << " != " << user << dendl; return -EIO; } if (!iter.end()) { @@ -202,7 +203,7 @@ public: objv_tracker(objv_tracker), mtime(mtime), exclusive(exclusive), pattrs(pattrs), y(y) { ctx = static_cast(_ctx); - ui.user_id = info.user_id; + ui.id = info.user_id.to_str(); } int prepare(const DoutPrefixProvider *dpp) { @@ -545,21 +546,25 @@ int RGWSI_User_RADOS::get_user_info_from_index(RGWSI_MetaBackend::Context* ctx, rgw_cache_entry_info cache_info; - auto iter = bl.cbegin(); try { + auto iter = bl.cbegin(); decode(uid, iter); - - int ret = read_user_info(ctx, uid.user_id, - &e.info, &e.objv_tracker, nullptr, &cache_info, nullptr, - y, dpp); - if (ret < 0) { - return ret; - } - } catch (buffer::error& err) { + } catch (const buffer::error&) { ldpp_dout(dpp, 0) << "ERROR: failed to decode user info, caught buffer::error" << dendl; return -EIO; } + if (rgw::account::validate_id(uid.id)) { + // this index is used for an account, not a user + return -ENOENT; + } + + ret = read_user_info(ctx, rgw_user{uid.id}, &e.info, &e.objv_tracker, + nullptr, &cache_info, nullptr, y, dpp); + if (ret < 0) { + return ret; + } + uinfo_cache->put(dpp, svc.cache, cache_key, &e, { &cache_info }); *info = e.info;