From: Gui Hecheng Date: Fri, 10 Mar 2017 09:01:34 +0000 (+0800) Subject: rgw_file: fix non-posix errcode EINVAL to ENAMETOOLONG X-Git-Tag: v12.0.2~271^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c54d85a47c59663f67588ac749ef0c48232a877f;p=ceph.git rgw_file: fix non-posix errcode EINVAL to ENAMETOOLONG When exec the following cmd in RGW FS, we get EINVAL: > mkdir -p Because the path name exceeds 1024 which is the max object name length for s3. Actually we should get ENAMETOOLONG here in posix, so we could wrap the name check functions and check the exact errcode for posix. Signed-off-by: Gui Hecheng --- diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index f1d1ef1649d4..aed44d3667bb 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -44,6 +44,26 @@ namespace rgw { ceph::timer RGWLibFS::write_timer{ ceph::construct_suspended}; + inline int valid_fs_bucket_name(const string& name) { + int rc = valid_s3_bucket_name(name, false /* relaxed */); + if (rc != 0) { + if (name.size() > 255) + return -ENAMETOOLONG; + return -EINVAL; + } + return 0; + } + + inline int valid_fs_object_name(const string& name) { + int rc = valid_s3_object_name(name); + if (rc != 0) { + if (name.size() > 1024) + return -ENAMETOOLONG; + return -EINVAL; + } + return 0; + } + LookupFHResult RGWLibFS::stat_bucket(RGWFileHandle* parent, const char *path, uint32_t flags) { @@ -441,7 +461,7 @@ namespace rgw { /* bucket */ string bname{name}; /* enforce S3 name restrictions */ - rc = valid_s3_bucket_name(bname, false /* relaxed */); + rc = valid_fs_bucket_name(bname); if (rc != 0) { rgw_fh->flags |= RGWFileHandle::FLAG_DELETED; fh_cache.remove(rgw_fh->fh.fh_hk.object, rgw_fh, @@ -449,6 +469,7 @@ namespace rgw { rgw_fh->mtx.unlock(); unref(rgw_fh); get<0>(mkr) = nullptr; + get<1>(mkr) = rc; return mkr; } @@ -475,13 +496,15 @@ namespace rgw { dir_name += "/"; /* need valid S3 name (characters, length <= 1024, etc) */ - if (! valid_s3_object_name(dir_name)) { + rc = valid_fs_object_name(dir_name); + if (rc != 0) { rgw_fh->flags |= RGWFileHandle::FLAG_DELETED; fh_cache.remove(rgw_fh->fh.fh_hk.object, rgw_fh, RGWFileHandle::FHCache::FLAG_LOCK); rgw_fh->mtx.unlock(); unref(rgw_fh); get<0>(mkr) = nullptr; + get<1>(mkr) = rc; return mkr; } @@ -540,8 +563,9 @@ namespace rgw { (obj_name.back() != '/')) obj_name += "/"; obj_name += name; - if (! valid_s3_object_name(obj_name)) { - return MkObjResult{nullptr, -EINVAL}; + rc = valid_fs_object_name(obj_name); + if (rc != 0) { + return MkObjResult{nullptr, rc}; } /* create it */