]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Zipper - implement set_attrs and delete_attrs in RGWObject
authorDaniel Gryniewicz <dang@redhat.com>
Wed, 1 Jul 2020 19:41:02 +0000 (15:41 -0400)
committerDaniel Gryniewicz <dang@redhat.com>
Mon, 17 Aug 2020 16:30:58 +0000 (12:30 -0400)
Signed-off-by: Daniel Gryniewicz <dang@redhat.com>
src/rgw/rgw_op.cc
src/rgw/rgw_sal.cc
src/rgw/rgw_sal.h

index bfd3fc5a70a5ac7602694b08891d56adedf768fd..2605318f46643f697bccfb6a3c89887be6f7a2a3 100644 (file)
@@ -4556,7 +4556,7 @@ void RGWPutMetadataObject::pre_exec()
 void RGWPutMetadataObject::execute()
 {
   rgw_obj target_obj;
-  map<string, bufferlist> attrs, orig_attrs, rmattrs;
+  rgw::sal::RGWAttrs attrs, rmattrs;
 
   s->object->set_atomic(s->obj_ctx);
 
@@ -4565,7 +4565,7 @@ void RGWPutMetadataObject::execute()
     return;
   }
 
-  op_ret = rgw_get_request_metadata(s->cct, s->info, attrs);
+  op_ret = rgw_get_request_metadata(s->cct, s->info, attrs.attrs);
   if (op_ret < 0) {
     return;
   }
@@ -4575,30 +4575,28 @@ void RGWPutMetadataObject::execute()
   if (op_ret < 0) {
     return;
   }
-  orig_attrs = s->object->get_attrs().attrs;
 
   /* Check whether the object has expired. Swift API documentation
    * stands that we should return 404 Not Found in such case. */
-  if (need_object_expiration() && object_is_expired(orig_attrs)) {
+  if (need_object_expiration() && object_is_expired(s->object->get_attrs().attrs)) {
     op_ret = -ENOENT;
     return;
   }
 
   /* Filter currently existing attributes. */
-  prepare_add_del_attrs(orig_attrs, attrs, rmattrs);
-  populate_with_generic_attrs(s, attrs);
-  encode_delete_at_attr(delete_at, attrs);
+  prepare_add_del_attrs(s->object->get_attrs().attrs, attrs.attrs, rmattrs.attrs);
+  populate_with_generic_attrs(s, attrs.attrs);
+  encode_delete_at_attr(delete_at, attrs.attrs);
 
   if (dlo_manifest) {
-    op_ret = encode_dlo_manifest_attr(dlo_manifest, attrs);
+    op_ret = encode_dlo_manifest_attr(dlo_manifest, attrs.attrs);
     if (op_ret < 0) {
       ldpp_dout(this, 0) << "bad user manifest: " << dlo_manifest << dendl;
       return;
     }
   }
 
-  op_ret = store->getRados()->set_attrs(s->obj_ctx, s->bucket->get_info(), target_obj,
-    attrs, &rmattrs, s->yield);
+  op_ret = s->object->set_obj_attrs(s->obj_ctx, &attrs, &rmattrs, s->yield, &target_obj);
 }
 
 int RGWDeleteObj::handle_slo_manifest(bufferlist& bl)
@@ -6015,6 +6013,7 @@ void RGWCompleteMultipart::execute()
     return;
   }
 
+  /* XXX dang fix this and remove function */
   op_ret = get_obj_attrs(store, s, meta_obj, attrs);
 
   if (op_ret < 0) {
@@ -7377,7 +7376,7 @@ void RGWSetAttrs::execute()
 
   if (!rgw::sal::RGWObject::empty(s->object.get())) {
     rgw::sal::RGWAttrs a(attrs);
-    op_ret = s->object->set_attrs(a);
+    op_ret = s->object->set_obj_attrs(s->obj_ctx, &a, nullptr, s->yield);
   } else {
     for (auto& iter : attrs) {
       s->bucket_attrs[iter.first] = std::move(iter.second);
@@ -7977,16 +7976,15 @@ void RGWGetObjLegalHold::execute()
     op_ret = -ERR_INVALID_REQUEST;
     return;
   }
-  rgw_obj obj = s->object->get_obj();
   map<string, bufferlist> attrs;
-  op_ret = get_obj_attrs(store, s, obj, attrs);
+  op_ret = s->object->get_obj_attrs(s->obj_ctx, s->yield);
   if (op_ret < 0) {
-    ldpp_dout(this, 0) << "ERROR: failed to get obj attrs, obj=" << obj
+    ldpp_dout(this, 0) << "ERROR: failed to get obj attrs, obj=" << s->object
                        << " ret=" << op_ret << dendl;
     return;
   }
-  auto aiter = attrs.find(RGW_ATTR_OBJECT_LEGAL_HOLD);
-  if (aiter == attrs.end()) {
+  auto aiter = s->object->get_attrs().attrs.find(RGW_ATTR_OBJECT_LEGAL_HOLD);
+  if (aiter == s->object->get_attrs().attrs.end()) {
     op_ret = -ERR_NO_SUCH_OBJECT_LOCK_CONFIGURATION;
     return;
   }
index 0d680309509ec3bc83821f0a797d5aa139ee46db..bb36d70b9d089065d744b8c0143f9772a99b468e 100644 (file)
@@ -357,7 +357,23 @@ int RGWRadosObject::read_attrs(RGWRados::Object::Read &read_op, optional_yield y
   return read_op.prepare(y);
 }
 
-int RGWRadosObject::get_obj_attrs(RGWObjectCtx *rctx, optional_yield y, rgw_obj *target_obj)
+int RGWRadosObject::set_obj_attrs(RGWObjectCtx* rctx, RGWAttrs* setattrs, RGWAttrs* delattrs, optional_yield y, rgw_obj* target_obj)
+{
+  map<string, bufferlist> empty;
+  rgw_obj target = get_obj();
+
+  if (!target_obj)
+    target_obj = &target;
+
+  return store->getRados()->set_attrs(rctx,
+                       bucket->get_info(),
+                       *target_obj,
+                       setattrs ? setattrs->attrs : empty,
+                       delattrs ? &delattrs->attrs : nullptr,
+                       y);
+}
+
+int RGWRadosObject::get_obj_attrs(RGWObjectCtx *rctx, optional_yield y, rgw_obj* target_obj)
 {
   RGWRados::Object op_target(store->getRados(), bucket->get_info(), *rctx, get_obj());
   RGWRados::Object::Read read_op(&op_target);
@@ -367,14 +383,24 @@ int RGWRadosObject::get_obj_attrs(RGWObjectCtx *rctx, optional_yield y, rgw_obj
 
 int RGWRadosObject::modify_obj_attrs(RGWObjectCtx *rctx, const char *attr_name, bufferlist& attr_val, optional_yield y)
 {
-  rgw_obj target_obj;
-  int r = get_obj_attrs(rctx, y, &target_obj);
+  rgw_obj target = get_obj();
+  int r = get_obj_attrs(rctx, y, &target);
   if (r < 0) {
     return r;
   }
   set_atomic(rctx);
   attrs.attrs[attr_name] = attr_val;
-  return store->getRados()->set_attrs(rctx, bucket->get_info(), target_obj, attrs.attrs, NULL, y);
+  return set_obj_attrs(rctx, &attrs, nullptr, y, &target);
+}
+
+int RGWRadosObject::delete_obj_attrs(RGWObjectCtx *rctx, const char *attr_name, optional_yield y)
+{
+  RGWAttrs rmattr;
+  bufferlist bl;
+
+  set_atomic(rctx);
+  rmattr.attrs[attr_name] = bl;
+  return set_obj_attrs(rctx, nullptr, &rmattr, y);
 }
 
 int RGWRadosObject::copy_obj_data(RGWObjectCtx& rctx, RGWBucket* dest_bucket,
@@ -398,21 +424,9 @@ int RGWRadosObject::copy_obj_data(RGWObjectCtx& rctx, RGWBucket* dest_bucket,
   attrset.erase(RGW_ATTR_TAIL_TAG);
 
   return store->getRados()->copy_obj_data(rctx, dest_bucket,
-                                          dest_bucket->get_info().placement_rule, read_op,
-                                          obj_size - 1, dest_obj, NULL, mtime, attrset, 0, real_time(), NULL,
-                                          dpp, y);
-}
-
-int RGWRadosObject::delete_obj_attrs(RGWObjectCtx *rctx, const char *attr_name, optional_yield y)
-{
-  map <string, bufferlist> attrs;
-  map <string, bufferlist> rmattr;
-  bufferlist bl;
-
-  set_atomic(rctx);
-  rmattr[attr_name] = bl;
-  rgw_obj obj = get_obj();
-  return store->getRados()->set_attrs(rctx, bucket->get_info(), obj, attrs, &rmattr, y);
+                                         dest_bucket->get_info().placement_rule, read_op,
+                                         obj_size - 1, dest_obj, NULL, mtime, attrset, 0,
+                                         real_time(), NULL, dpp, y);
 }
 
 void RGWRadosObject::set_atomic(RGWObjectCtx *rctx) const
index a834d2ffa71fd171e10e9b35d821f323ac302749..43098e4fc37a6983b93f0fb5ca3726b6b47c460e 100644 (file)
@@ -278,7 +278,6 @@ class RGWObject {
     virtual int read(off_t offset, off_t length, std::iostream& stream) = 0;
     virtual int write(off_t offset, off_t length, std::iostream& stream) = 0;
     virtual RGWAttrs& get_attrs(void) = 0;
-    virtual int set_attrs(RGWAttrs& attrs) = 0;
     virtual int delete_object(void) = 0;
     virtual RGWAccessControlPolicy& get_acl(void) = 0;
     virtual int set_acl(const RGWAccessControlPolicy& acl) = 0;
@@ -289,7 +288,8 @@ class RGWObject {
     const std::string &get_name() const { return key.name; }
 
     virtual int get_obj_state(RGWObjectCtx *rctx, RGWBucket& bucket, RGWObjState **state, optional_yield y, bool follow_olh = false) = 0;
-    virtual int get_obj_attrs(RGWObjectCtx *rctx, optional_yield y, rgw_obj *target_obj = nullptr) = 0;
+    virtual int set_obj_attrs(RGWObjectCtx* rctx, RGWAttrs* setattrs, RGWAttrs* delattrs, optional_yield y, rgw_obj* target_obj = NULL) = 0;
+    virtual int get_obj_attrs(RGWObjectCtx *rctx, optional_yield y, rgw_obj* target_obj = NULL) = 0;
     virtual int modify_obj_attrs(RGWObjectCtx *rctx, const char *attr_name, bufferlist& attr_val, optional_yield y) = 0;
     virtual int delete_obj_attrs(RGWObjectCtx *rctx, const char *attr_name, optional_yield y) = 0;
     virtual int copy_obj_data(RGWObjectCtx& rctx, RGWBucket* dest_bucket, RGWObject* dest_obj, uint16_t olh_epoch, std::string* petag, const DoutPrefixProvider *dpp, optional_yield y) = 0;
@@ -388,18 +388,18 @@ class RGWRadosObject : public RGWObject {
     int read(off_t offset, off_t length, std::iostream& stream) { return length; }
     int write(off_t offset, off_t length, std::iostream& stream) { return length; }
     RGWAttrs& get_attrs(void) { return attrs; }
-    int set_attrs(RGWAttrs& a) { attrs = a; return 0; }
     int delete_object(void) { return 0; }
     RGWAccessControlPolicy& get_acl(void) { return acls; }
     int set_acl(const RGWAccessControlPolicy& acl) { acls = acl; return 0; }
     virtual void set_atomic(RGWObjectCtx *rctx) const;
     virtual void set_prefetch_data(RGWObjectCtx *rctx);
 
-    virtual int get_obj_state(RGWObjectCtx *rctx, RGWBucket& bucket, RGWObjState **state, optional_yield y, bool follow_olh = true);
-    virtual int get_obj_attrs(RGWObjectCtx *rctx, optional_yield y, rgw_obj *target_obj = nullptr);
-    virtual int modify_obj_attrs(RGWObjectCtx *rctx, const char *attr_name, bufferlist& attr_val, optional_yield y);
-    virtual int delete_obj_attrs(RGWObjectCtx *rctx, const char *attr_name, optional_yield y);
-    virtual int copy_obj_data(RGWObjectCtx& rctx, RGWBucket* dest_bucket, RGWObject* dest_obj, uint16_t olh_epoch, std::string* petag, const DoutPrefixProvider *dpp, optional_yield y);
+    virtual int get_obj_state(RGWObjectCtx *rctx, RGWBucket& bucket, RGWObjState **state, optional_yield y, bool follow_olh = true) override;
+    virtual int set_obj_attrs(RGWObjectCtx* rctx, RGWAttrs* setattrs, RGWAttrs* delattrs, optional_yield y, rgw_obj* target_obj = NULL) override;
+    virtual int get_obj_attrs(RGWObjectCtx *rctx, optional_yield y, rgw_obj* target_obj = NULL) override;
+    virtual int modify_obj_attrs(RGWObjectCtx *rctx, const char *attr_name, bufferlist& attr_val, optional_yield y) override;
+    virtual int delete_obj_attrs(RGWObjectCtx *rctx, const char *attr_name, optional_yield y) override;
+    virtual int copy_obj_data(RGWObjectCtx& rctx, RGWBucket* dest_bucket, RGWObject* dest_obj, uint16_t olh_epoch, std::string* petag, const DoutPrefixProvider *dpp, optional_yield y) override;
     virtual void gen_rand_obj_instance_name() override;
     virtual std::unique_ptr<RGWObject> clone() {
       return std::unique_ptr<RGWObject>(new RGWRadosObject(*this));