]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
erasure-code: add sanity check to guard against k=1 4713/head
authorLoic Dachary <ldachary@redhat.com>
Sun, 17 May 2015 22:29:31 +0000 (00:29 +0200)
committerLoic Dachary <ldachary@redhat.com>
Sat, 6 Jun 2015 21:51:57 +0000 (23:51 +0200)
Add a call to ErasureCode::sanity_check_k for the isa and jerasure
plugins, with associated tests.

http://tracker.ceph.com/issues/10358 Fixes: #10358

Signed-off-by: Loic Dachary <ldachary@redhat.com>
src/erasure-code/isa/ErasureCodeIsa.cc
src/erasure-code/jerasure/ErasureCodeJerasure.cc
src/test/erasure-code/TestErasureCodeIsa.cc
src/test/erasure-code/TestErasureCodeJerasure.cc
src/test/mon/osd-erasure-code-profile.sh

index 50ad57e8eac85749c59bf93753f27af864911e2c..acf63d86f43c881ea82a24ebf6325e611a73867c 100644 (file)
@@ -350,6 +350,7 @@ int ErasureCodeIsaDefault::parse(ErasureCodeProfile &profile,
   int err = ErasureCode::parse(profile, ss);
   err |= to_int("k", profile, &k, DEFAULT_K, ss);
   err |= to_int("m", profile, &m, DEFAULT_M, ss);
+  err |= sanity_check_k(k, ss);
 
   if (matrixtype == kVandermonde) {
     // these are verified safe values evaluated using the
index 8992aa8a89f2fb83f5c5dea491154ec3a3db2885..eb10254c064cce4dc9f8623e6f89cbfaaf904063 100644 (file)
@@ -85,6 +85,7 @@ int ErasureCodeJerasure::parse(ErasureCodeProfile &profile,
     chunk_mapping.clear();
     err = -EINVAL;
   }
+  err |= sanity_check_k(k, ss);
   return err;
 }
 
index ce2b056da4689d6d25cb9c2e6f024581586eeed9..11ec14ebfd7b8ac56881668e2163828fa82aab1a 100644 (file)
@@ -366,6 +366,17 @@ TEST_F(IsaErasureCodeTest, encode)
   }
 }
 
+TEST_F(IsaErasureCodeTest, sanity_check_k)
+{
+  ErasureCodeIsaDefault Isa(tcache);
+  ErasureCodeProfile profile;
+  profile["k"] = "1";
+  profile["m"] = "1";
+  ostringstream errors;
+  EXPECT_EQ(-EINVAL, Isa.init(profile, &errors));
+  EXPECT_NE(std::string::npos, errors.str().find("must be >= 2"));
+}
+
 bool
 DecodeAndVerify(ErasureCodeIsaDefault& Isa, map<int, bufferlist> &degraded, set<int> want_to_decode, buffer::ptr* enc, int length)
 {
index 4cccb5c3f3087643a31326f7a9c9ead554af205c..47b28a02e2386815e85a4e41be4377ed7a7beffc 100644 (file)
@@ -41,6 +41,18 @@ typedef ::testing::Types<
 > JerasureTypes;
 TYPED_TEST_CASE(ErasureCodeTest, JerasureTypes);
 
+TYPED_TEST(ErasureCodeTest, sanity_check_k)
+{
+  TypeParam jerasure;
+  ErasureCodeProfile profile;
+  profile["k"] = "1";
+  profile["m"] = "1";
+  profile["packetsize"] = "8";
+  ostringstream errors;
+  EXPECT_EQ(-EINVAL, jerasure.init(profile, &errors));
+  EXPECT_NE(std::string::npos, errors.str().find("must be >= 2"));
+}
+
 TYPED_TEST(ErasureCodeTest, encode_decode)
 {
   const char *per_chunk_alignments[] = { "false", "true" };
index be5dbfab66480e55b10dd31a4920f1010f1db1d9..ec5bbc4db91f1362d59bcd5cfd71cff7919f4d09 100755 (executable)
@@ -205,6 +205,32 @@ function TEST_format_plain() {
         grep "$expected" || return 1
 }
 
+function TEST_profile_k_sanity() {
+    local dir=$1
+    local profile=profile-sanity
+
+    run_mon $dir a || return 1
+
+    expect_failure $dir 'k must be a multiple of (k + m) / l' \
+        ./ceph osd erasure-code-profile set $profile \
+        plugin=lrc \
+        l=1 \
+        k=1 \
+        m=1 || return 1
+
+    expect_failure $dir 'k=1 must be >= 2' \
+        ./ceph osd erasure-code-profile set $profile \
+        plugin=isa \
+        k=1 \
+        m=1 || return 1
+
+    expect_failure $dir 'k=1 must be >= 2' \
+        ./ceph osd erasure-code-profile set $profile \
+        plugin=jerasure \
+        k=1 \
+        m=1 || return 1
+}
+
 main osd-erasure-code-profile "$@"
 
 # Local Variables: