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: v13.0.1~865^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=593d656dffd477943b8bd15153004d905b4b0d73;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 --- diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index 26bbbe66bbb7..859d74f1066e 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -1452,7 +1452,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 4454c980ca01..96286e52900e 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -2652,7 +2652,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); @@ -2745,7 +2748,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); @@ -3543,7 +3549,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); @@ -3857,7 +3866,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); @@ -3949,7 +3961,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) { @@ -4036,7 +4051,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) { @@ -4410,7 +4429,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; @@ -5114,7 +5136,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 d3a63aee73d1..84f900da0bdf 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -1884,12 +1884,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", @@ -1909,6 +1911,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)); @@ -1916,6 +1928,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 7f41926a1b8b..68bc2053ceb1 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -1661,7 +1661,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();