From 010b3ad04a2911be45d11ba8934af1c13e75a072 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Wed, 2 Feb 2022 15:53:41 -0500 Subject: [PATCH] rgw: Don't erase bucket attributes on trim Writing bucket instance info is surprising, as if you pass a null pointer for the attributes, it just erases all the attributes. To avoid disturbing users and other 'system objects', make a special case that we can pass in explicitly. Signed-off-by: Adam C. Emerson --- src/rgw/rgw_tools.cc | 27 +++++++++++++++++++++------ src/rgw/rgw_tools.h | 7 +++++++ src/rgw/rgw_trim_bilog.cc | 2 +- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/rgw/rgw_tools.cc b/src/rgw/rgw_tools.cc index a6ada43fd3870..84390c3eae309 100644 --- a/src/rgw/rgw_tools.cc +++ b/src/rgw/rgw_tools.cc @@ -101,6 +101,11 @@ int rgw_init_ioctx(const DoutPrefixProvider *dpp, return 0; } +map* no_change_attrs() { + static map no_change; + return &no_change; +} + int rgw_put_system_obj(const DoutPrefixProvider *dpp, RGWSysObjectCtx& obj_ctx, const rgw_pool& pool, const string& oid, bufferlist& data, bool exclusive, RGWObjVersionTracker *objv_tracker, real_time set_mtime, optional_yield y, map *pattrs) @@ -113,12 +118,22 @@ int rgw_put_system_obj(const DoutPrefixProvider *dpp, rgw_raw_obj obj(pool, oid); auto sysobj = obj_ctx.get_obj(obj); - int ret = sysobj.wop() - .set_objv_tracker(objv_tracker) - .set_exclusive(exclusive) - .set_mtime(set_mtime) - .set_attrs(*pattrs) - .write(dpp, data, y); + int ret; + + if (pattrs != no_change_attrs()) { + ret = sysobj.wop() + .set_objv_tracker(objv_tracker) + .set_exclusive(exclusive) + .set_mtime(set_mtime) + .set_attrs(*pattrs) + .write(dpp, data, y); + } else { + ret = sysobj.wop() + .set_objv_tracker(objv_tracker) + .set_exclusive(exclusive) + .set_mtime(set_mtime) + .write_data(dpp, data, y); + } return ret; } diff --git a/src/rgw/rgw_tools.h b/src/rgw/rgw_tools.h index 28ff91835ee5b..3cfa11a493e47 100644 --- a/src/rgw/rgw_tools.h +++ b/src/rgw/rgw_tools.h @@ -257,4 +257,11 @@ using RGWDataAccessRef = std::shared_ptr; /// calls and error handling. void rgw_complete_aio_completion(librados::AioCompletion* c, int r); +/// This returns a static, non-NULL pointer, recognized only by +/// rgw_put_system_obj(). When supplied instead of the attributes, the +/// attributes will be unmodified. +/// +// (Currently providing nullptr will wipe all attributes.) + +std::map* no_change_attrs(); #endif diff --git a/src/rgw/rgw_trim_bilog.cc b/src/rgw/rgw_trim_bilog.cc index 9a65c358bc1c6..038d2a5a79e11 100644 --- a/src/rgw/rgw_trim_bilog.cc +++ b/src/rgw/rgw_trim_bilog.cc @@ -729,7 +729,7 @@ int BucketTrimInstanceCR::operate(const DoutPrefixProvider *dpp) yield call(new RGWPutBucketInstanceInfoCR( store->svc()->rados->get_async_processor(), store, clean_info->first, false, {}, - nullptr, dpp)); + no_change_attrs(), dpp)); // Raced, try again. if (retcode == -ECANCELED) { -- 2.39.5