From d9e4727b7e6ffa1cb2918b610381d41439a056e8 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Sun, 22 May 2016 15:32:19 +0200 Subject: [PATCH 1/2] rgw: Fix updating CORS/ACLs during POST on Swift's container. Introduced in: 7a7de9b75265b978ba4e53966f614fac033972cb Fixes: http://tracker.ceph.com/issues/15976 Signed-off-by: Radoslaw Zarzynski --- src/rgw/rgw_op.cc | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 76a408cdcd2..01feb876a75 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -1849,6 +1849,14 @@ static void prepare_add_del_attrs(const map& orig_attrs, } } +/* Fuse resource metadata basing on original attributes in @orig_attrs, set + * of _custom_ attribute names to remove in @rmattr_names and attributes in + * @out_attrs. Place results in @out_attrs. + * + * NOTE: it's supposed that all special attrs already present in @out_attrs + * will be preserved without any change. Special attributes are those which + * names start with RGW_ATTR_META_PREFIX. They're complement to custom ones + * used for X-Account-Meta-*, X-Container-Meta-*, X-Amz-Meta and so on. */ static void prepare_add_del_attrs(const map& orig_attrs, const set& rmattr_names, map& out_attrs) @@ -1980,12 +1988,9 @@ void RGWCreateBucket::execute() } } - if (need_metadata_upload()) { - rgw_get_request_metadata(s->cct, s->info, attrs, false); - prepare_add_del_attrs(s->bucket_attrs, rmattr_names, attrs); - populate_with_generic_attrs(s, attrs); - } - + /* Encode special metadata first as we're using std::map::emplace under + * the hood. This method will add the new items only if the map doesn't + * contain such keys yet. */ policy.encode(aclbl); emplace_attr(RGW_ATTR_ACL, std::move(aclbl)); @@ -1993,6 +1998,15 @@ void RGWCreateBucket::execute() cors_config.encode(corsbl); emplace_attr(RGW_ATTR_CORS, std::move(corsbl)); } + + if (need_metadata_upload()) { + /* It's supposed that following functions WILL NOT change any special + * attributes (like RGW_ATTR_ACL) if they are already present in attrs. */ + rgw_get_request_metadata(s->cct, s->info, attrs, false); + prepare_add_del_attrs(s->bucket_attrs, rmattr_names, attrs); + populate_with_generic_attrs(s, attrs); + } + s->bucket.tenant = s->bucket_tenant; /* ignored if bucket exists */ s->bucket.name = s->bucket_name; op_ret = store->create_bucket(*(s->user), s->bucket, zonegroup_id, @@ -2860,10 +2874,9 @@ void RGWPutMetadataBucket::execute() return; } - orig_attrs = s->bucket_attrs; /* XXX map copy */ - prepare_add_del_attrs(orig_attrs, rmattr_names, attrs); - populate_with_generic_attrs(s, attrs); - + /* Encode special metadata first as we're using std::map::emplace under + * the hood. This method will add the new items only if the map doesn't + * contain such keys yet. */ if (has_policy) { buffer::list bl; policy.encode(bl); @@ -2876,6 +2889,12 @@ void RGWPutMetadataBucket::execute() emplace_attr(RGW_ATTR_CORS, std::move(bl)); } + /* It's supposed that following functions WILL NOT change any special + * attributes (like RGW_ATTR_ACL) if they are already present in attrs. */ + orig_attrs = s->bucket_attrs; /* XXX map copy */ + prepare_add_del_attrs(orig_attrs, rmattr_names, attrs); + populate_with_generic_attrs(s, attrs); + s->bucket_info.swift_ver_location = swift_ver_location; s->bucket_info.swift_versioning = (!swift_ver_location.empty()); From 19c12bbc233a118496f8ad5d640d19bb0e2c5d05 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Mon, 23 May 2016 13:27:24 +0200 Subject: [PATCH 2/2] rgw: remove unnecessary data copying in RGWPutMetadataBucket. Signed-off-by: Radoslaw Zarzynski --- src/rgw/rgw_op.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 01feb876a75..dfe09dc2ce2 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -2859,8 +2859,6 @@ void RGWPutMetadataBucket::pre_exec() void RGWPutMetadataBucket::execute() { - map orig_attrs; - op_ret = get_params(); if (op_ret < 0) { return; @@ -2891,8 +2889,7 @@ void RGWPutMetadataBucket::execute() /* It's supposed that following functions WILL NOT change any special * attributes (like RGW_ATTR_ACL) if they are already present in attrs. */ - orig_attrs = s->bucket_attrs; /* XXX map copy */ - prepare_add_del_attrs(orig_attrs, rmattr_names, attrs); + prepare_add_del_attrs(s->bucket_attrs, rmattr_names, attrs); populate_with_generic_attrs(s, attrs); s->bucket_info.swift_ver_location = swift_ver_location;