From: Sage Weil Date: Fri, 18 Jul 2014 17:44:49 +0000 (-0700) Subject: osd: add config for osd_max_attr_name_len = 100 X-Git-Tag: v0.84~84^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=bd3367eafb6568d96c9d1d28653af00d4bd94593;p=ceph.git osd: add config for osd_max_attr_name_len = 100 Set a limit on the length of an attr name. The fs can only take 128 bytes, but we were not imposing any limit. Add a test. Reported-by: Haomai Wang Signed-off-by: Sage Weil --- diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 9acdc1a742eaf..ad566ce39babb 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -597,6 +597,7 @@ OPTION(osd_mon_shutdown_timeout, OPT_DOUBLE, 5) OPTION(osd_max_object_size, OPT_U64, 100*1024L*1024L*1024L) // OSD's maximum object size OPTION(osd_max_object_name_len, OPT_U32, 2048) // max rados object name len +OPTION(osd_max_attr_name_len, OPT_U32, 100) // max rados attr name len; cannot go higher than 100 chars for file system backends OPTION(osd_max_attr_size, OPT_U64, 0) OPTION(osd_objectstore, OPT_STR, "filestore") // ObjectStore backend type diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index c45586c73893d..2baa290d48fa9 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -4034,6 +4034,12 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector& ops) result = -EFBIG; break; } + unsigned max_name_len = MIN(osd->store->get_max_attr_name_length(), + cct->_conf->osd_max_attr_name_len); + if (op.xattr.name_len > max_name_len) { + result = -ENAMETOOLONG; + break; + } if (!obs.exists) { ctx->mod_desc.create(); t->touch(soid); diff --git a/src/test/librados/misc.cc b/src/test/librados/misc.cc index f0fee02d9a1c8..3b52cbdf398b3 100644 --- a/src/test/librados/misc.cc +++ b/src/test/librados/misc.cc @@ -61,6 +61,17 @@ TEST_F(LibRadosMiscPP, LongNamePP) { ASSERT_EQ(-ENAMETOOLONG, ioctx.write(string(maxlen*2, 'a').c_str(), bl, bl.length(), 0)); } +TEST_F(LibRadosMiscPP, LongAttrNamePP) { + bufferlist bl; + bl.append("content"); + int maxlen = g_conf->osd_max_attr_name_len; + ASSERT_EQ(0, ioctx.setxattr("bigattrobj", string(maxlen/2, 'a').c_str(), bl)); + ASSERT_EQ(0, ioctx.setxattr("bigattrobj", string(maxlen-1, 'a').c_str(), bl)); + ASSERT_EQ(0, ioctx.setxattr("bigattrobj", string(maxlen, 'a').c_str(), bl)); + ASSERT_EQ(-ENAMETOOLONG, ioctx.setxattr("bigattrobj", string(maxlen+1, 'a').c_str(), bl)); + ASSERT_EQ(-ENAMETOOLONG, ioctx.setxattr("bigattrobj", string(maxlen*2, 'a').c_str(), bl)); +} + static std::string read_key_from_tmap(IoCtx& ioctx, const std::string &obj, const std::string &key) {