From e7449eb7a7fcffb71a1416576b278c7ef005ffd6 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Tue, 7 Mar 2023 17:28:54 -0500 Subject: [PATCH] rgw/sysobj: read() can query size/mtime rgw_get_system_obj() stopped calling stat() before read() in 90aec61298fc378e1733bc76f0d3f95ce8ec135a, which left the optional 'real_time *pmtime' argument uninitialized when requested, read() will add a stat op to initialize size/mtime Signed-off-by: Casey Bodley (cherry picked from commit 20ab42758c8ba0cef867752be3b215064d44a6f2) --- src/rgw/services/svc_sys_obj.cc | 1 + src/rgw/services/svc_sys_obj_cache.cc | 35 ++++++++++++++++++++++++--- src/rgw/services/svc_sys_obj_cache.h | 1 + src/rgw/services/svc_sys_obj_core.cc | 8 ++++++ src/rgw/services/svc_sys_obj_core.h | 1 + 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/rgw/services/svc_sys_obj.cc b/src/rgw/services/svc_sys_obj.cc index d352fb9f4df..310e60514d2 100644 --- a/src/rgw/services/svc_sys_obj.cc +++ b/src/rgw/services/svc_sys_obj.cc @@ -40,6 +40,7 @@ int RGWSI_SysObj::Obj::ROp::read(const DoutPrefixProvider *dpp, return svc->read(dpp, *state, objv_tracker, obj, bl, ofs, end, + lastmod, obj_size, attrs, raw_attrs, cache_info, diff --git a/src/rgw/services/svc_sys_obj_cache.cc b/src/rgw/services/svc_sys_obj_cache.cc index f704e7b1d74..d1b7a3dbb3e 100644 --- a/src/rgw/services/svc_sys_obj_cache.cc +++ b/src/rgw/services/svc_sys_obj_cache.cc @@ -111,6 +111,7 @@ int RGWSI_SysObj_Cache::read(const DoutPrefixProvider *dpp, RGWObjVersionTracker *objv_tracker, const rgw_raw_obj& obj, bufferlist *obl, off_t ofs, off_t end, + ceph::real_time* pmtime, uint64_t* psize, map *attrs, bool raw_attrs, rgw_cache_entry_info *cache_info, @@ -120,8 +121,8 @@ int RGWSI_SysObj_Cache::read(const DoutPrefixProvider *dpp, rgw_pool pool; string oid; if (ofs != 0) { - return RGWSI_SysObj_Core::read(dpp, read_state, objv_tracker, - obj, obl, ofs, end, attrs, raw_attrs, + return RGWSI_SysObj_Core::read(dpp, read_state, objv_tracker, obj, obl, + ofs, end, pmtime, psize, attrs, raw_attrs, cache_info, refresh_version, y); } @@ -133,6 +134,8 @@ int RGWSI_SysObj_Cache::read(const DoutPrefixProvider *dpp, uint32_t flags = (end != 0 ? CACHE_FLAG_DATA : 0); if (objv_tracker) flags |= CACHE_FLAG_OBJV; + if (pmtime || psize) + flags |= CACHE_FLAG_META; if (attrs) flags |= CACHE_FLAG_XATTRS; @@ -151,6 +154,12 @@ int RGWSI_SysObj_Cache::read(const DoutPrefixProvider *dpp, i.copy_all(*obl); if (objv_tracker) objv_tracker->read_version = info.version; + if (pmtime) { + *pmtime = info.meta.mtime; + } + if (psize) { + *psize = info.meta.size; + } if (attrs) { if (raw_attrs) { *attrs = info.xattrs; @@ -163,9 +172,23 @@ int RGWSI_SysObj_Cache::read(const DoutPrefixProvider *dpp, if(r == -ENODATA) return -ENOENT; + // if we only ask for one of mtime or size, ask for the other too so we can + // satisfy CACHE_FLAG_META + uint64_t size = 0; + real_time mtime; + if (pmtime) { + if (!psize) { + psize = &size; + } + } else if (psize) { + if (!pmtime) { + pmtime = &mtime; + } + } + map unfiltered_attrset; r = RGWSI_SysObj_Core::read(dpp, read_state, objv_tracker, - obj, obl, ofs, end, + obj, obl, ofs, end, pmtime, psize, (attrs ? &unfiltered_attrset : nullptr), true, /* cache unfiltered attrs */ cache_info, @@ -194,6 +217,12 @@ int RGWSI_SysObj_Cache::read(const DoutPrefixProvider *dpp, if (objv_tracker) { info.version = objv_tracker->read_version; } + if (pmtime) { + info.meta.mtime = *pmtime; + } + if (psize) { + info.meta.size = *psize; + } if (attrs) { info.xattrs = std::move(unfiltered_attrset); if (raw_attrs) { diff --git a/src/rgw/services/svc_sys_obj_cache.h b/src/rgw/services/svc_sys_obj_cache.h index e1fa9f997b9..f7950843fa9 100644 --- a/src/rgw/services/svc_sys_obj_cache.h +++ b/src/rgw/services/svc_sys_obj_cache.h @@ -48,6 +48,7 @@ protected: RGWObjVersionTracker *objv_tracker, const rgw_raw_obj& obj, bufferlist *bl, off_t ofs, off_t end, + ceph::real_time* pmtime, uint64_t* psize, std::map *attrs, bool raw_attrs, rgw_cache_entry_info *cache_info, diff --git a/src/rgw/services/svc_sys_obj_core.cc b/src/rgw/services/svc_sys_obj_core.cc index c57fbb4eed4..30308969131 100644 --- a/src/rgw/services/svc_sys_obj_core.cc +++ b/src/rgw/services/svc_sys_obj_core.cc @@ -134,6 +134,7 @@ int RGWSI_SysObj_Core::read(const DoutPrefixProvider *dpp, RGWObjVersionTracker *objv_tracker, const rgw_raw_obj& obj, bufferlist *bl, off_t ofs, off_t end, + ceph::real_time* pmtime, uint64_t* psize, map *attrs, bool raw_attrs, rgw_cache_entry_info *cache_info, @@ -143,6 +144,7 @@ int RGWSI_SysObj_Core::read(const DoutPrefixProvider *dpp, auto& read_state = static_cast(_read_state); uint64_t len; + struct timespec mtime_ts; librados::ObjectReadOperation op; if (end < 0) @@ -153,6 +155,9 @@ int RGWSI_SysObj_Core::read(const DoutPrefixProvider *dpp, if (objv_tracker) { objv_tracker->prepare_op_for_read(&op); } + if (psize || pmtime) { + op.stat2(psize, &mtime_ts, nullptr); + } ldpp_dout(dpp, 20) << "rados->read ofs=" << ofs << " len=" << len << dendl; op.read(ofs, len, bl, nullptr); @@ -188,6 +193,9 @@ int RGWSI_SysObj_Core::read(const DoutPrefixProvider *dpp, return -ECANCELED; } + if (pmtime) { + *pmtime = ceph::real_clock::from_timespec(mtime_ts); + } if (attrs && !raw_attrs) { rgw_filter_attrset(unfiltered_attrset, RGW_ATTR_PREFIX, attrs); } diff --git a/src/rgw/services/svc_sys_obj_core.h b/src/rgw/services/svc_sys_obj_core.h index 56b1b6d82e2..d02a37eee8a 100644 --- a/src/rgw/services/svc_sys_obj_core.h +++ b/src/rgw/services/svc_sys_obj_core.h @@ -44,6 +44,7 @@ protected: RGWObjVersionTracker *objv_tracker, const rgw_raw_obj& obj, bufferlist *bl, off_t ofs, off_t end, + ceph::real_time* pmtime, uint64_t* psize, std::map *attrs, bool raw_attrs, rgw_cache_entry_info *cache_info, -- 2.39.5