From ef039b27df93bf89c95724d13ba82324813c3aae Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Fri, 22 Nov 2019 14:50:11 -0500 Subject: [PATCH] rgw: factor out decode_olh_info() Signed-off-by: Casey Bodley --- src/rgw/rgw_rados.cc | 49 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 2cc9b78d7dc1c..12e341f0fc059 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -6769,6 +6769,18 @@ int RGWRados::bucket_index_clear_olh(const RGWBucketInfo& bucket_info, RGWObjSta return 0; } +static int decode_olh_info(CephContext* cct, const bufferlist& bl, RGWOLHInfo *olh) +{ + try { + auto biter = bl.cbegin(); + decode(*olh, biter); + return 0; + } catch (buffer::error& err) { + ldout(cct, 0) << "ERROR: failed to decode olh info" << dendl; + return -EIO; + } +} + int RGWRados::apply_olh_log(RGWObjectCtx& obj_ctx, RGWObjState& state, const RGWBucketInfo& bucket_info, const rgw_obj& obj, bufferlist& olh_tag, map >& log, uint64_t *plast_ver, rgw_zone_set* zones_trace) @@ -7076,35 +7088,22 @@ void RGWRados::gen_rand_obj_instance_name(rgw_obj *target_obj) int RGWRados::get_olh(const RGWBucketInfo& bucket_info, const rgw_obj& obj, RGWOLHInfo *olh) { - map unfiltered_attrset; + map attrset; ObjectReadOperation op; - op.getxattrs(&unfiltered_attrset, NULL); + op.getxattrs(&attrset, NULL); - bufferlist outbl; int r = obj_operate(bucket_info, obj, &op); - if (r < 0) { return r; } - map attrset; - rgw_filter_attrset(unfiltered_attrset, RGW_ATTR_OLH_PREFIX, &attrset); - - map::iterator iter = attrset.find(RGW_ATTR_OLH_INFO); + auto iter = attrset.find(RGW_ATTR_OLH_INFO); if (iter == attrset.end()) { /* not an olh */ return -EINVAL; } - try { - auto biter = iter->second.cbegin(); - decode(*olh, biter); - } catch (buffer::error& err) { - ldout(cct, 0) << "ERROR: failed to decode olh info" << dendl; - return -EIO; - } - - return 0; + return decode_olh_info(cct, iter->second, olh); } void RGWRados::check_pending_olh_entries(map& pending_entries, @@ -7195,15 +7194,15 @@ int RGWRados::follow_olh(const RGWBucketInfo& bucket_info, RGWObjectCtx& obj_ctx } } - map::iterator iter = state->attrset.find(RGW_ATTR_OLH_INFO); - ceph_assert(iter != state->attrset.end()); + auto iter = state->attrset.find(RGW_ATTR_OLH_INFO); + if (iter == state->attrset.end()) { + return -EINVAL; + } + RGWOLHInfo olh; - try { - auto biter = iter->second.cbegin(); - decode(olh, biter); - } catch (buffer::error& err) { - ldout(cct, 0) << "ERROR: failed to decode olh info" << dendl; - return -EIO; + int ret = decode_olh_info(cct, iter->second, &olh); + if (ret < 0) { + return ret; } if (olh.removed) { -- 2.39.5