From: Radoslaw Zarzynski Date: Tue, 30 May 2017 20:19:58 +0000 (+0200) Subject: rgw: add support for max_meta_name_length of Swift API's /info. X-Git-Tag: v12.2.2~150^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4b82d1e25bf8f7be1915e7467cb822d5beea96a1;p=ceph.git rgw: add support for max_meta_name_length of Swift API's /info. Fixes: http://tracker.ceph.com/issues/17938 Signed-off-by: Radoslaw Zarzynski (cherry picked from commit 593d656dffd477943b8bd15153004d905b4b0d73) --- diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index 83df3ddbf01b..e941ece9269c 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -1449,7 +1449,10 @@ namespace rgw { attrbl.append(val.c_str(), val.size() + 1); } - rgw_get_request_metadata(s->cct, s->info, attrs); + op_ret = rgw_get_request_metadata(s->cct, s->info, attrs); + if (op_ret < 0) { + goto done; + } encode_delete_at_attr(delete_at, attrs); /* Add a custom metadata to expose the information whether an object diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index ac6f7b70081a..cd2e4d682fe1 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -2639,7 +2639,10 @@ void RGWCreateBucket::execute() 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); + op_ret = rgw_get_request_metadata(s->cct, s->info, attrs, false); + if (op_ret < 0) { + return; + } prepare_add_del_attrs(s->bucket_attrs, rmattr_names, attrs); populate_with_generic_attrs(s, attrs); @@ -2732,7 +2735,10 @@ void RGWCreateBucket::execute() attrs.clear(); - rgw_get_request_metadata(s->cct, s->info, attrs, false); + op_ret = rgw_get_request_metadata(s->cct, s->info, attrs, false); + if (op_ret < 0) { + return; + } prepare_add_del_attrs(s->bucket_attrs, rmattr_names, attrs); populate_with_generic_attrs(s, attrs); op_ret = filter_out_quota_info(attrs, rmattr_names, s->bucket_info.quota); @@ -3531,7 +3537,10 @@ void RGWPutObj::execute() emplace_attr(RGW_ATTR_ETAG, std::move(bl)); populate_with_generic_attrs(s, attrs); - rgw_get_request_metadata(s->cct, s->info, attrs); + op_ret = rgw_get_request_metadata(s->cct, s->info, attrs); + if (op_ret < 0) { + goto done; + } encode_delete_at_attr(delete_at, attrs); encode_obj_tags_attr(obj_tags.get(), attrs); @@ -3845,7 +3854,10 @@ int RGWPutMetadataAccount::init_processing() attrs.emplace(RGW_ATTR_ACL, std::move(acl_bl)); } - rgw_get_request_metadata(s->cct, s->info, attrs, false); + op_ret = rgw_get_request_metadata(s->cct, s->info, attrs, false); + if (op_ret < 0) { + return op_ret; + } prepare_add_del_attrs(orig_attrs, rmattr_names, attrs); populate_with_generic_attrs(s, attrs); @@ -3937,7 +3949,10 @@ void RGWPutMetadataBucket::execute() return; } - rgw_get_request_metadata(s->cct, s->info, attrs, false); + op_ret = rgw_get_request_metadata(s->cct, s->info, attrs, false); + if (op_ret < 0) { + return; + } if (!placement_rule.empty() && placement_rule != s->bucket_info.placement_rule) { @@ -4024,7 +4039,11 @@ void RGWPutMetadataObject::execute() return; } - rgw_get_request_metadata(s->cct, s->info, attrs); + op_ret = rgw_get_request_metadata(s->cct, s->info, attrs); + if (op_ret < 0) { + return; + } + /* check if obj exists, read orig attrs */ op_ret = get_obj_attrs(store, s, obj, orig_attrs); if (op_ret < 0) { @@ -4398,7 +4417,10 @@ int RGWCopyObj::init_common() dest_policy.encode(aclbl); emplace_attr(RGW_ATTR_ACL, std::move(aclbl)); - rgw_get_request_metadata(s->cct, s->info, attrs); + op_ret = rgw_get_request_metadata(s->cct, s->info, attrs); + if (op_ret < 0) { + return op_ret; + } populate_with_generic_attrs(s, attrs); return 0; @@ -5108,7 +5130,10 @@ void RGWInitMultipart::execute() if (op_ret != 0) return; - rgw_get_request_metadata(s->cct, s->info, attrs); + op_ret = rgw_get_request_metadata(s->cct, s->info, attrs); + if (op_ret < 0) { + return; + } do { char buf[33]; diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index d9ce2b400011..c8f536acb129 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -1885,12 +1885,14 @@ static inline void format_xattr(std::string &xattr) * map(, where attr_name is RGW_ATTR_PREFIX.HTTP_NAME) * s: The request state * attrs: will be filled up with attrs mapped as + * On success returns 0. + * On failure returns a negative error code. * */ -static inline void rgw_get_request_metadata(CephContext *cct, - struct req_info& info, - map& attrs, - const bool allow_empty_attrs = true) +static inline int rgw_get_request_metadata(CephContext* const cct, + struct req_info& info, + std::map& attrs, + const bool allow_empty_attrs = true) { static const std::set blacklisted_headers = { "x-amz-server-side-encryption-customer-algorithm", @@ -1910,6 +1912,16 @@ static inline void rgw_get_request_metadata(CephContext *cct, format_xattr(xattr); string attr_name(RGW_ATTR_PREFIX); attr_name.append(name); + + /* Check early whether we aren't going behind the limit on attribute + * name. Passing here doesn't guarantee that an OSD will accept that + * as ObjectStore::get_max_attr_name_length() can set the limit even + * lower. However, we're claiming "max_meta_name_length" in /info as + * being dependent on the "osd_max_attr_name_len". */ + if (attr_name.length() > cct->_conf->osd_max_attr_name_len) { + return -ENAMETOOLONG; + } + map::value_type v(attr_name, bufferlist()); std::pair < map::iterator, bool > rval(attrs.insert(v)); @@ -1917,6 +1929,8 @@ static inline void rgw_get_request_metadata(CephContext *cct, bl.append(xattr.c_str(), xattr.size() + 1); } } + + return 0; } /* rgw_get_request_metadata */ static inline void encode_delete_at_attr(boost::optional delete_at, diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index 96f7cb7e5053..728cc57a6506 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -1660,7 +1660,10 @@ void RGWInfo_ObjStore_SWIFT::list_swift_data(Formatter& formatter, string ceph_version(CEPH_GIT_NICE_VER); formatter.dump_string("version", ceph_version); - formatter.dump_int("max_meta_name_length", 81); + + const size_t meta_name_limit = g_conf->osd_max_attr_name_len + - strlen(RGW_ATTR_PREFIX RGW_AMZ_META_PREFIX); + formatter.dump_int("max_meta_name_length", meta_name_limit); formatter.open_array_section("policies"); RGWZoneGroup& zonegroup = store.get_zonegroup();