]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: add config for osd_max_attr_name_len = 100
authorSage Weil <sage@redhat.com>
Fri, 18 Jul 2014 17:44:49 +0000 (10:44 -0700)
committerSage Weil <sage@redhat.com>
Fri, 18 Jul 2014 17:44:49 +0000 (10:44 -0700)
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 <haomaiwang@gmail.com>
Signed-off-by: Sage Weil <sage@inktank.com>
src/common/config_opts.h
src/osd/ReplicatedPG.cc
src/test/librados/misc.cc

index 9acdc1a742eaf31915145612cbd948316790ad42..ad566ce39babb04916da9298d2027f75a9de8132 100644 (file)
@@ -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
index c45586c73893d1e083dc8fd925efb677874a716c..2baa290d48fa956dbbcf37dd9edb7c6d9f329097 100644 (file)
@@ -4034,6 +4034,12 @@ int ReplicatedPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& 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);
index f0fee02d9a1c817e47a81f2bc1c033a32e2059ee..3b52cbdf398b3243f2a325615c432ddf52f74a54 100644 (file)
@@ -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)
 {