From 7d19558c251534444f039768d0475203694ecd98 Mon Sep 17 00:00:00 2001 From: Daniel Gryniewicz Date: Wed, 1 Jul 2020 15:41:02 -0400 Subject: [PATCH] Zipper - implement set_attrs and delete_attrs in RGWObject Signed-off-by: Daniel Gryniewicz --- src/rgw/rgw_op.cc | 30 +++++++++++++------------- src/rgw/rgw_sal.cc | 52 +++++++++++++++++++++++++++++----------------- src/rgw/rgw_sal.h | 16 +++++++------- 3 files changed, 55 insertions(+), 43 deletions(-) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index bfd3fc5a70a5a..2605318f46643 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -4556,7 +4556,7 @@ void RGWPutMetadataObject::pre_exec() void RGWPutMetadataObject::execute() { rgw_obj target_obj; - map 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 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; } diff --git a/src/rgw/rgw_sal.cc b/src/rgw/rgw_sal.cc index 0d680309509ec..bb36d70b9d089 100644 --- a/src/rgw/rgw_sal.cc +++ b/src/rgw/rgw_sal.cc @@ -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 empty; + rgw_obj target = get_obj(); + + if (!target_obj) + target_obj = ⌖ + + 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 attrs; - map 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 diff --git a/src/rgw/rgw_sal.h b/src/rgw/rgw_sal.h index a834d2ffa71fd..43098e4fc37a6 100644 --- a/src/rgw/rgw_sal.h +++ b/src/rgw/rgw_sal.h @@ -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 clone() { return std::unique_ptr(new RGWRadosObject(*this)); -- 2.39.5