]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Don't erase bucket attributes on trim
authorAdam C. Emerson <aemerson@redhat.com>
Wed, 2 Feb 2022 20:53:41 +0000 (15:53 -0500)
committerCasey Bodley <cbodley@redhat.com>
Tue, 8 Feb 2022 21:31:06 +0000 (16:31 -0500)
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 <aemerson@redhat.com>
src/rgw/rgw_tools.cc
src/rgw/rgw_tools.h
src/rgw/rgw_trim_bilog.cc

index 36e9ad1e5ced855dcfd8d2178dde1858fd3193c7..1f6186307fdcd56f3207a143f2fa154dced6ebcb 100644 (file)
@@ -175,6 +175,11 @@ int rgw_parse_list_of_flags(struct rgw_name_to_flag *mapping,
   return 0;
 }
 
+map<string, bufferlist>* no_change_attrs() {
+  static map<string, bufferlist> 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<string, bufferlist> *pattrs)
@@ -187,12 +192,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;
 }
index c447539b7988b266f35793d09444b3fec1488767..975e61321e0fb258b5780fa7ed6af37ac2d7618e 100644 (file)
@@ -268,4 +268,11 @@ using RGWDataAccessRef = std::shared_ptr<RGWDataAccess>;
 /// 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<std::string, ceph::buffer::list>* no_change_attrs();
 #endif
index d75e655aee35cefb1dd8faedf358628c9dd2b58c..8daa78fcee7b90e131249df283c89da8ed49bf56 100644 (file)
@@ -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) {