From b279f9c93d6b745c003d71faa54646bd2f1b8a6a Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 8 Jan 2018 07:27:30 -0800 Subject: [PATCH] rgw: cloud sync, sync object meta Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_rest_client.cc | 29 +++++++++++++++++++++++------ src/rgw/rgw_rest_client.h | 4 +++- src/rgw/rgw_sync_module_aws.cc | 11 +---------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/rgw/rgw_rest_client.cc b/src/rgw/rgw_rest_client.cc index 1dee8713301..21f1ac4df7c 100644 --- a/src/rgw/rgw_rest_client.cc +++ b/src/rgw/rgw_rest_client.cc @@ -485,27 +485,44 @@ void RGWRESTStreamS3PutObj::send_init(rgw_obj& obj) url = new_url; } -int RGWRESTStreamS3PutObj::send_ready(RGWAccessKey& key, map& attrs, bool send) +int RGWRESTStreamS3PutObj::send_ready(RGWAccessKey& key, map& rgw_attrs, bool send) { + map new_attrs; /* merge send headers */ - for (auto& attr: attrs) { + for (auto& attr: rgw_attrs) { bufferlist& bl = attr.second; const string& name = attr.first; string val = bl.c_str(); if (name.compare(0, sizeof(RGW_ATTR_META_PREFIX) - 1, RGW_ATTR_META_PREFIX) == 0) { string header_name = RGW_AMZ_META_PREFIX; header_name.append(name.substr(sizeof(RGW_ATTR_META_PREFIX) - 1)); - new_env.set(header_name, val); - new_info.x_meta_map[header_name] = val; + new_attrs[header_name] = val; } } + RGWAccessControlPolicy policy; - int ret = rgw_policy_from_attrset(cct, attrs, &policy); + int ret = rgw_policy_from_attrset(cct, rgw_attrs, &policy); if (ret < 0) { ldout(cct, 0) << "ERROR: couldn't get policy ret=" << ret << dendl; return ret; } + return send_ready(key, new_attrs, policy, send); +} + +int RGWRESTStreamS3PutObj::send_ready(RGWAccessKey& key, const map& http_attrs, + RGWAccessControlPolicy& policy, bool send) +{ + /* merge send headers */ + for (auto& attr: http_attrs) { + const string& val = attr.second; + const string& name = lowercase_dash_http_attr(attr.first); + if (name.compare(0, sizeof(RGW_AMZ_META_PREFIX) - 1, RGW_AMZ_META_PREFIX) == 0) { + new_env.set(name, val); + new_info.x_meta_map[name] = val; + } + } + /* update acl headers */ RGWAccessControlList& acl = policy.get_acl(); multimap& grant_map = acl.get_grant_map(); @@ -517,7 +534,7 @@ int RGWRESTStreamS3PutObj::send_ready(RGWAccessKey& key, map grants_by_type_add_perm(grants_by_type, perm.get_permissions(), grant); } add_grants_headers(grants_by_type, new_env, new_info.x_meta_map); - ret = sign_request(cct, key, new_env, new_info); + int ret = sign_request(cct, key, new_env, new_info); if (ret < 0) { ldout(cct, 0) << "ERROR: failed to sign request" << dendl; return ret; diff --git a/src/rgw/rgw_rest_client.h b/src/rgw/rgw_rest_client.h index 728460e62e9..27842e0bda7 100644 --- a/src/rgw/rgw_rest_client.h +++ b/src/rgw/rgw_rest_client.h @@ -190,7 +190,9 @@ public: ~RGWRESTStreamS3PutObj() override; void send_init(rgw_obj& obj); - int send_ready(RGWAccessKey& key, map& attrs, bool send); + int send_ready(RGWAccessKey& key, map& rgw_attrs, bool send); + int send_ready(RGWAccessKey& key, const map& http_attrs, + RGWAccessControlPolicy& policy, bool send); int put_obj_init(RGWAccessKey& key, rgw_obj& obj, uint64_t obj_size, map& attrs, bool send); diff --git a/src/rgw/rgw_sync_module_aws.cc b/src/rgw/rgw_sync_module_aws.cc index 9d29fbd10e7..c027ef7c79b 100644 --- a/src/rgw/rgw_sync_module_aws.cc +++ b/src/rgw/rgw_sync_module_aws.cc @@ -172,20 +172,11 @@ public: void send_ready(const rgw_rest_obj& rest_obj) override { RGWRESTStreamS3PutObj *r = (RGWRESTStreamS3PutObj *)req; - /* here we need to convert rest_obj.attrs to cloud specific representation */ - - map new_attrs; - - for (auto attr : rest_obj.attrs) { - new_attrs[attr.first].append(attr.second); - } - RGWAccessControlPolicy policy; - ::encode(policy, new_attrs[RGW_ATTR_ACL]); r->set_send_length(rest_obj.content_len); - r->send_ready(conn->get_key(), new_attrs, false); + r->send_ready(conn->get_key(), rest_obj.attrs, policy, false); } void handle_headers(const map& headers) { -- 2.47.3