]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
erasure-code: reformat EC plugins 63014/head
authorJamie Pryde <jamiepry@uk.ibm.com>
Thu, 3 Apr 2025 14:54:00 +0000 (15:54 +0100)
committerJamie Pryde <jamiepry@uk.ibm.com>
Mon, 28 Apr 2025 16:30:05 +0000 (17:30 +0100)
Addresses review comments from #61804

Signed-off-by: Jamie Pryde <jamiepry@uk.ibm.com>
(cherry picked from commit 87ff016584e3354f98a7129e760f41870142d262)

src/erasure-code/ErasureCode.cc
src/erasure-code/ErasureCodeInterface.h
src/erasure-code/isa/ErasureCodeIsa.cc
src/erasure-code/jerasure/ErasureCodeJerasure.cc
src/erasure-code/jerasure/ErasureCodeJerasure.h
src/erasure-code/lrc/ErasureCodeLrc.cc
src/erasure-code/shec/ErasureCodeShec.cc
src/osd/ECTypes.h
src/test/erasure-code/ErasureCodeExample.h

index 7184f1dd7142b251c2bce15671807de8c21476ff..f3433c430f2cc5446de43e0e96b89005116dfe97 100644 (file)
@@ -111,7 +111,7 @@ int ErasureCode::sanity_check_k_m(int k, int m, ostream *ss)
     *ss << "m=" << m << " must be >= 1" << std::endl;
     return -EINVAL;
   }
-  int max_k_plus_m = std::numeric_limits<decltype(shard_id_t::id)>::max();
+  auto max_k_plus_m = std::numeric_limits<decltype(shard_id_t::id)>::max();
   if (k+m > max_k_plus_m) {
     *ss << "(k+m)=" << (k+m) << " must be <= " << max_k_plus_m << std::endl;
     return -EINVAL;
@@ -136,7 +136,7 @@ int ErasureCode::_minimum_to_decode(const set<int> &want_to_read,
                                    set<int> *minimum)
 {
   if (includes(available_chunks.begin(), available_chunks.end(),
-              want_to_read.begin(), want_to_read.end())) {
+               want_to_read.begin(), want_to_read.end())) {
     *minimum = want_to_read;
   } else {
     unsigned int k = get_data_chunk_count();
@@ -447,7 +447,7 @@ int ErasureCode::_decode(const shard_id_set &want_to_read,
       (*decoded)[i].rebuild_aligned(SIMD_ALIGN);
     }
     bufferlist &bl = (*decoded)[i];
-    if (bl.length() != bl.begin().get_current_ptr().length()) {
+    if (!bl.is_contiguous()) {
       bl.rebuild();
     }
   }
index 695a6683afedbe6e614ad60da9ae904ed40c2683..eb1651a5dbf53142cf00a4b61cdc4926e20101ce 100644 (file)
@@ -309,15 +309,13 @@ namespace ceph {
     virtual int minimum_to_decode(const shard_id_set &want_to_read,
                           const shard_id_set &available,
                           shard_id_set &minimum_set,
-                          mini_flat_map<shard_id_t, std::vector<std::pair<int, int>>>
-                          *minimum_sub_chunks) = 0;
+                          mini_flat_map<shard_id_t, std::vector<std::pair<int, int>>> *minimum_sub_chunks) = 0;
 
     // Interface for legacy EC.
     [[deprecated]]
     virtual int minimum_to_decode(const std::set<int> &want_to_read,
                                   const std::set<int> &available,
-                                  std::map<int, std::vector<std::pair<int, int>>> 
-                                  *minimum) = 0;
+                                  std::map<int, std::vector<std::pair<int, int>>> *minimum) = 0;
 
     /**
      * Compute the smallest subset of **available** chunks that needs
index 78c61fc50b3f353105e91cd6761812f53893bf4c..78f955a3c5f368827c63416be5c8b5d4f64d3bdf 100644 (file)
@@ -104,10 +104,11 @@ int ErasureCodeIsa::decode_chunks(const set<int> &want_to_read,
       erasures[erasures_count] = i;
       erasures_count++;
     }
-    if (i < k)
+    if (i < k) {
       data[i] = (*decoded)[i].c_str();
-    else
+    } else {
       coding[i - k] = (*decoded)[i].c_str();
+    }
   }
   erasures[erasures_count] = -1;
   ceph_assert(erasures_count > 0);
@@ -122,21 +123,29 @@ int ErasureCodeIsa::encode_chunks(const shard_id_map<bufferptr> &in,
   uint64_t size = 0;
 
   for (auto &&[shard, ptr] : in) {
-    if (size == 0) size = ptr.length();
-    else ceph_assert(size == ptr.length());
+    if (size == 0) {
+      size = ptr.length();
+    } else {
+      ceph_assert(size == ptr.length());
+    }
     chunks[static_cast<int>(shard)] = const_cast<char*>(ptr.c_str());
   }
 
   for (auto &&[shard, ptr] : out) {
-    if (size == 0) size = ptr.length();
-    else ceph_assert(size == ptr.length());
+    if (size == 0) {
+      size = ptr.length();
+    } else {
+      ceph_assert(size == ptr.length());
+    }
     chunks[static_cast<int>(shard)] = ptr.c_str();
   }
 
   char *zeros = nullptr;
 
   for (shard_id_t i; i < k + m; ++i) {
-    if (in.contains(i) || out.contains(i)) continue;
+    if (in.contains(i) || out.contains(i)) {
+      continue;
+    }
 
     if (zeros == nullptr) {
       zeros = (char*)malloc(size);
@@ -148,14 +157,16 @@ int ErasureCodeIsa::encode_chunks(const shard_id_map<bufferptr> &in,
 
   isa_encode(&chunks[0], &chunks[k], size);
 
-  if (zeros != nullptr) free(zeros);
+  if (zeros != nullptr) {
+    free(zeros);
+  }
 
   return 0;
 }
 
 int ErasureCodeIsa::decode_chunks(const shard_id_set &want_to_read,
                                   shard_id_map<bufferptr> &in,
-                                 shard_id_map<bufferptr> &out)
+                                  shard_id_map<bufferptr> &out)
 {
   unsigned int size = 0;
   shard_id_set erasures_set;
@@ -169,33 +180,48 @@ int ErasureCodeIsa::decode_chunks(const shard_id_set &want_to_read,
   memset(coding, 0, sizeof(char*) * m);
 
   for (auto &&[shard, ptr] : in) {
-    if (size == 0) size = ptr.length();
-    else ceph_assert(size == ptr.length());
-    if (shard < k) {
-      data[static_cast<int>(shard)] = const_cast<char*>(ptr.c_str());
+    if (size == 0) {
+      size = ptr.length();
+    } else {
+      ceph_assert(size == ptr.length());
     }
-    else {
-      coding[static_cast<int>(shard) - k] = const_cast<char*>(ptr.c_str());
+
+    if (shard < k) {
+      data[static_cast<int>(shard)] = ptr.c_str();
+    } else {
+      coding[static_cast<int>(shard) - k] = ptr.c_str();
     }
     erasures_set.erase(shard);
   }
 
   for (auto &&[shard, ptr] : out) {
-    if (size == 0) size = ptr.length();
-    else ceph_assert(size == ptr.length());
-    if (shard < k) {
-      data[static_cast<int>(shard)] = const_cast<char*>(ptr.c_str());
+    if (size == 0) {
+      size = ptr.length();
+    } else {
+      ceph_assert(size == ptr.length());
     }
-    else {
-      coding[static_cast<int>(shard) - k] = const_cast<char*>(ptr.c_str());
+
+    if (shard < k) {
+      data[static_cast<int>(shard)] = ptr.c_str();
+    } else {
+      coding[static_cast<int>(shard) - k] = ptr.c_str();
     }
+    erasures_set.insert(shard);
   }
 
   for (int i = 0; i < k + m; i++) {
     char **buf = i < k ? &data[i] : &coding[i - k];
     if (*buf == nullptr) {
       *buf = (char *)malloc(size);
+      ceph_assert(buf != nullptr);
       to_free.insert(shard_id_t(i));
+      /* If buffer was not provided, is not an erasure (i.e. in the out map),
+       * and a data shard, then it can be assumed to be zero. This is most
+       * likely due to EC shards being different sizes.
+       */
+      if (i < k && !erasures_set.contains(shard_id_t(i))) {
+        memset(*buf, 0, size);
+      }
     }
   }
 
@@ -222,7 +248,7 @@ void
 ErasureCodeIsa::isa_xor(char **data, char *coding, int blocksize, int data_vectors)
 {
   ceph_assert(data_vectors <= MAX_K);
-  char * xor_bufs[MAX_K + 1];
+  char *xor_bufs[MAX_K + 1];
   for (int i = 0; i < data_vectors; i++) {
     xor_bufs[i] = data[i];
   }
@@ -232,7 +258,10 @@ ErasureCodeIsa::isa_xor(char **data, char *coding, int blocksize, int data_vecto
   // Otherwise, use byte_xor()
   bool aligned = true;
   for (int i = 0; i <= data_vectors; i++) {
-    aligned &= is_aligned(xor_bufs[i], EC_ISA_ADDRESS_ALIGNMENT);
+    if (!is_aligned(xor_bufs[i], EC_ISA_ADDRESS_ALIGNMENT)) {
+      aligned = false;
+      break;
+    }
   }
 
   if (aligned) {
@@ -289,13 +318,13 @@ ErasureCodeIsaDefault::encode_delta(const bufferptr &old_data,
                                   const bufferptr &new_data,
                                   bufferptr *delta_maybe_in_place)
 {
-  constexpr int data_vectors = 2;
-  char * data[data_vectors];
+  constexpr int NUM_DATA_VECTORS = 2;
+  char * data[NUM_DATA_VECTORS];
   data[0] = const_cast<char*>(old_data.c_str());
   data[1] = const_cast<char*>(new_data.c_str());
   char * coding = delta_maybe_in_place->c_str();
 
-  isa_xor(data, coding, delta_maybe_in_place->length(), data_vectors);
+  isa_xor(data, coding, delta_maybe_in_place->length(), NUM_DATA_VECTORS);
 }
 
 // -----------------------------------------------------------------------------
@@ -308,23 +337,29 @@ ErasureCodeIsaDefault::apply_delta(const shard_id_map<bufferptr> &in,
   const unsigned blocksize = first->second.length();
 
   for (auto const& [datashard, databuf] : in) {
-    if (datashard < k) {
-      for (auto const& [codingshard, codingbuf] : out) {
-        if (codingshard >= k) {
-          ceph_assert(codingbuf.length() == blocksize);
-          if (m==1) {
-            constexpr int data_vectors = 2;
-            char * data[data_vectors];
-            data[0] = const_cast<char*>(databuf.c_str());
-            data[1] = const_cast<char*>(codingbuf.c_str());
-            char * coding = const_cast<char*>(codingbuf.c_str());
-            isa_xor(data, coding, blocksize, data_vectors);
-          } else {
-            unsigned char* data = reinterpret_cast<unsigned char*>(const_cast<char*>(databuf.c_str()));
-            unsigned char* coding = reinterpret_cast<unsigned char*>(const_cast<char*>(codingbuf.c_str()));
-            ec_encode_data_update(blocksize, k, 1, static_cast<int>(datashard), encode_tbls + (32 * k * (static_cast<int>(codingshard) - k)), data, &coding);
-          }
-        }
+    if (datashard >= k) {
+      continue;
+    }
+    for (auto const& [codingshard, codingbuf] : out) {
+      if (codingshard < k) {
+        continue;
+      }
+      ceph_assert(codingbuf.length() == blocksize);
+      if (m == 1) {
+        constexpr int NUM_DATA_VECTORS = 2;
+        char * data[NUM_DATA_VECTORS];
+        data[0] = const_cast<char*>(databuf.c_str());
+        data[1] = codingbuf.c_str();
+        char * coding = codingbuf.c_str();
+        isa_xor(data, coding, blocksize, NUM_DATA_VECTORS);
+      } else {
+        unsigned char* data = reinterpret_cast<unsigned char*>(const_cast<char*>(databuf.c_str()));
+        unsigned char* coding = reinterpret_cast<unsigned char*>(codingbuf.c_str());
+        // We always update one parity at a time, so specify 1 row, and a pointer to the
+        // correct row in encode_tbls for this particular parity
+        ec_encode_data_update(blocksize, k, 1, static_cast<int>(datashard),
+                              encode_tbls + (32 * k * (static_cast<int>(codingshard) - k)),
+                              data, &coding);
       }
     }
   }
index 7f6f28d0194c401ed4ad5ed7eb6cd54fbb21bfa6..5c498decb60eb5724ae1d565a8082c23940a2e83 100644 (file)
@@ -121,14 +121,20 @@ int ErasureCodeJerasure::encode_chunks(const shard_id_map<bufferptr> &in,
   uint64_t size = 0;
 
   for (auto &&[shard, ptr] : in) {
-    if (size == 0) size = ptr.length();
-    else ceph_assert(size == ptr.length());
+    if (size == 0) {
+      size = ptr.length();
+    } else {
+      ceph_assert(size == ptr.length());
+    }
     chunks[static_cast<int>(shard)] = const_cast<char*>(ptr.c_str());
   }
 
   for (auto &&[shard, ptr] : out) {
-    if (size == 0) size = ptr.length();
-    else ceph_assert(size == ptr.length());
+    if (size == 0) {
+      size = ptr.length();
+    } else {
+      ceph_assert(size == ptr.length());
+    }
     chunks[static_cast<int>(shard)] = ptr.c_str();
   }
 
@@ -167,10 +173,11 @@ int ErasureCodeJerasure::decode_chunks(const set<int> &want_to_read,
       erasures[erasures_count] = i;
       erasures_count++;
     }
-    if (i < k)
+    if (i < k) {
       data[i] = (*decoded)[i].c_str();
-    else
+    } else {
       coding[i - k] = (*decoded)[i].c_str();
+    }
   }
   erasures[erasures_count] = -1;
 
@@ -198,8 +205,7 @@ int ErasureCodeJerasure::decode_chunks(const shard_id_set &want_to_read,
     else ceph_assert(size == ptr.length());
     if (shard < k) {
       data[static_cast<int>(shard)] = const_cast<char*>(ptr.c_str());
-    }
-    else {
+    } else {
       coding[static_cast<int>(shard) - k] = const_cast<char*>(ptr.c_str());
     }
     erasures_set.erase(shard);
@@ -210,10 +216,10 @@ int ErasureCodeJerasure::decode_chunks(const shard_id_set &want_to_read,
     else ceph_assert(size == ptr.length());
     if (shard < k) {
       data[static_cast<int>(shard)] = const_cast<char*>(ptr.c_str());
-    }
-    else {
+    } else {
       coding[static_cast<int>(shard) - k] = const_cast<char*>(ptr.c_str());
     }
+    erasures_set.insert(shard);
   }
 
   for (int i = 0; i < k + m; i++) {
@@ -221,16 +227,19 @@ int ErasureCodeJerasure::decode_chunks(const shard_id_set &want_to_read,
     if (*buf == nullptr) {
       *buf = (char *)malloc(size);
       to_free.insert(shard_id_t(i));
+      /* If we are inventing a buffer for non-erasure shard, its zeros! */
+      if (i < k && !erasures_set.contains(shard_id_t(i))) {
+        memset(*buf, 0, size);
+      }
     }
   }
 
   for (auto && shard : erasures_set) {
     erasures[erasures_count++] = static_cast<int>(shard);
   }
-
-
   erasures[erasures_count] = -1;
   ceph_assert(erasures_count > 0);
+
   int r = jerasure_decode(erasures, data, coding, size);
   for (auto & shard : to_free) {
     int i = static_cast<int>(shard);
@@ -276,28 +285,40 @@ void ErasureCodeJerasure::matrix_apply_delta(const shard_id_map<bufferptr> &in,
   const unsigned blocksize = first->second.length();
 
   for (auto const& [datashard, databuf] : in) {
-    if (datashard < k) {
-      for (auto const& [codingshard, codingbuf] : out) {
-        if (codingshard >= k) {
-          ceph_assert(codingbuf.length() == blocksize);
-          char* input_data = const_cast<char*>(databuf.c_str());
-          char* output_data = const_cast<char*>(codingbuf.c_str());
-          if (static_cast<int>(codingshard) == k) {
-            galois_region_xor(input_data, output_data, blocksize);
-          }
-          else {
-            switch (w) {
-              case 8:
-                galois_w08_region_multiply(input_data, matrix[static_cast<int>(datashard) + (k * (static_cast<int>(codingshard) - k))], blocksize, output_data, 1);
-                break;
-              case 16:
-                galois_w16_region_multiply(input_data, matrix[static_cast<int>(datashard) + (k * (static_cast<int>(codingshard) - k))], blocksize, output_data, 1);
-                break;
-              case 32:
-                galois_w32_region_multiply(input_data, matrix[static_cast<int>(datashard) + (k * (static_cast<int>(codingshard) - k))], blocksize, output_data, 1);
-                break;
-            }
-          }
+    if (datashard >= k) {
+      continue;
+    }
+    for (auto const& [codingshard, codingbuf] : out) {
+      if (codingshard < k) {
+        continue;
+      }
+      ceph_assert(codingbuf.length() == blocksize);
+      char* input_data = const_cast<char*>(databuf.c_str());
+      char* output_data = const_cast<char*>(codingbuf.c_str());
+      if (static_cast<int>(codingshard) == k) {
+        galois_region_xor(input_data, output_data, blocksize);
+      } else {
+        switch (w) {
+          // We always update one parity at a time, so specify the correct row
+          // in the matrix for this particular parity
+          case 8:
+            galois_w08_region_multiply(
+                input_data,
+                matrix[static_cast<int>(datashard) + (k * (static_cast<int>(codingshard) - k))],
+                blocksize, output_data, 1);
+            break;
+          case 16:
+            galois_w16_region_multiply(
+                input_data,
+                matrix[static_cast<int>(datashard) + (k * (static_cast<int>(codingshard) - k))],
+                blocksize, output_data, 1);
+            break;
+          case 32:
+            galois_w32_region_multiply(
+                input_data,
+                matrix[static_cast<int>(datashard) + (k * (static_cast<int>(codingshard) - k))],
+                blocksize, output_data, 1);
+            break;
         }
       }
     }
@@ -328,20 +349,23 @@ void ErasureCodeJerasure::schedule_apply_delta(const shard_id_map<bufferptr> &in
   unsigned int blocksize = first->second.length();
 
   for (auto const& [datashard, databuf] : in) {
-    if (datashard < k) {
-      for (auto const& [codingshard, codingbuf] : out) {
-        if (codingshard >= k) {
-          ceph_assert(codingbuf.length() == blocksize);
-          char * ptr_copy[2];
-          ptr_copy[0] = const_cast<char*>(databuf.c_str());
-          ptr_copy[1] = const_cast<char*>(codingbuf.c_str());
-          unsigned int done;
-          for (done = 0; done < blocksize; done += (packetsize*w)) {
-            do_scheduled_ops(ptr_copy, simple_schedule, packetsize, static_cast<int>(datashard), static_cast<int>(codingshard));
-            ptr_copy[0] += (packetsize*w);
-            ptr_copy[1] += (packetsize*w);
-          }
-        }
+    if (datashard >= k) {
+      continue;
+    }
+    for (auto const& [codingshard, codingbuf] : out) {
+      if (codingshard < k) {
+        continue;
+      }
+      ceph_assert(codingbuf.length() == blocksize);
+      char * ptr_copy[2];
+      ptr_copy[0] = const_cast<char*>(databuf.c_str());
+      ptr_copy[1] = codingbuf.c_str();
+      unsigned int done;
+      for (done = 0; done < blocksize; done += (packetsize*w)) {
+        do_scheduled_ops(ptr_copy, simple_schedule, packetsize,
+                         static_cast<int>(datashard), static_cast<int>(codingshard));
+        ptr_copy[0] += (packetsize*w);
+        ptr_copy[1] += (packetsize*w);
       }
     }
   }
@@ -363,7 +387,7 @@ int ErasureCodeJerasureReedSolomonVandermonde::jerasure_decode(int *erasures,
                                                                 int blocksize)
 {
   return jerasure_matrix_decode(k, m, w, matrix, 1,
-                               erasures, data, coding, blocksize);
+                                erasures, data, coding, blocksize);
 }
 
 void ErasureCodeJerasureReedSolomonVandermonde::apply_delta(const shard_id_map<bufferptr> &in,
@@ -415,9 +439,9 @@ void ErasureCodeJerasureReedSolomonRAID6::jerasure_encode(char **data,
 }
 
 int ErasureCodeJerasureReedSolomonRAID6::jerasure_decode(int *erasures,
-                                                        char **data,
-                                                        char **coding,
-                                                        int blocksize)
+                                                         char **data,
+                                                         char **coding,
+                                                         int blocksize)
 {
   return jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding, blocksize);
 }
@@ -466,20 +490,20 @@ void ErasureCodeJerasureReedSolomonRAID6::prepare()
 // ErasureCodeJerasureCauchy
 //
 void ErasureCodeJerasureCauchy::jerasure_encode(char **data,
-                                               char **coding,
-                                               int blocksize)
+                                                char **coding,
+                                                int blocksize)
 {
   jerasure_schedule_encode(k, m, w, schedule,
-                          data, coding, blocksize, packetsize);
+                           data, coding, blocksize, packetsize);
 }
 
 int ErasureCodeJerasureCauchy::jerasure_decode(int *erasures,
-                                              char **data,
-                                              char **coding,
-                                              int blocksize)
+                                               char **data,
+                                               char **coding,
+                                               int blocksize)
 {
   return jerasure_schedule_decode_lazy(k, m, w, bitmatrix,
-                                      erasures, data, coding, blocksize, packetsize, 1);
+                                       erasures, data, coding, blocksize, packetsize, 1);
 }
 
 void ErasureCodeJerasureCauchy::apply_delta(const shard_id_map<bufferptr> &in,
@@ -501,7 +525,7 @@ unsigned ErasureCodeJerasureCauchy::get_alignment() const
     if ( ((w*packetsize*sizeof(int))%LARGEST_VECTOR_WORDSIZE) )
       alignment = k*w*packetsize*LARGEST_VECTOR_WORDSIZE;
     return alignment;
-  }  
+  }
 }
 
 int ErasureCodeJerasureCauchy::parse(ErasureCodeProfile &profile,
@@ -521,7 +545,7 @@ void ErasureCodeJerasureCauchy::prepare_schedule(int *matrix)
   simple_schedule = jerasure_dumb_bitmatrix_to_schedule(k, m, w, bitmatrix);
 }
 
-ErasureCodeJerasureCauchy::~ErasureCodeJerasureCauchy() 
+ErasureCodeJerasureCauchy::~ErasureCodeJerasureCauchy()
 {
   if (bitmatrix)
     free(bitmatrix);
@@ -569,7 +593,7 @@ void ErasureCodeJerasureLiberation::jerasure_encode(char **data,
                                                     int blocksize)
 {
   jerasure_schedule_encode(k, m, w, schedule, data,
-                          coding, blocksize, packetsize);
+                           coding, blocksize, packetsize);
 }
 
 int ErasureCodeJerasureLiberation::jerasure_decode(int *erasures,
@@ -578,7 +602,7 @@ int ErasureCodeJerasureLiberation::jerasure_decode(int *erasures,
                                                     int blocksize)
 {
   return jerasure_schedule_decode_lazy(k, m, w, bitmatrix, erasures, data,
-                                      coding, blocksize, packetsize, 1);
+                                       coding, blocksize, packetsize, 1);
 }
 
 void ErasureCodeJerasureLiberation::apply_delta(const shard_id_map<bufferptr> &in,
index fac3c1d400e55c37bb8be30a384ab31f8b0d46a6..3bbd5d0448c1046859cf456400139eeabfd4ee00 100644 (file)
@@ -92,7 +92,7 @@ public:
                     ceph::bufferptr *delta_maybe_in_place);
 
   void apply_delta(const shard_id_map<ceph::bufferptr> &in,
-                           shard_id_map<ceph::bufferptr> &out) = 0;
+                   shard_id_map<ceph::bufferptr> &out) = 0;
 
   int init(ceph::ErasureCodeProfile &profile, std::ostream *ss) override;
 
index 278791de3a06489a33c181dc9a137908abeb001e..7b82efeb291bdc4cd43f98fe5830653fb09a75b5 100644 (file)
@@ -1104,8 +1104,11 @@ int ErasureCodeLrc::decode_chunks(const shard_id_set &want_to_read,
   }
 
   for (const auto& [shard, ptr] : out) {
-    if (chunk_size == 0) chunk_size = ptr.length();
-    else ceph_assert(chunk_size == ptr.length());
+    if (chunk_size == 0) {
+      chunk_size = ptr.length();
+    } else {
+      ceph_assert(chunk_size == ptr.length());
+    }
     erasures.insert(shard);
   }
 
@@ -1132,10 +1135,12 @@ int ErasureCodeLrc::decode_chunks(const shard_id_set &want_to_read,
       {
         shard_id_t cs(*c);
         if (!erasures.contains(cs)) {
-          if (in.contains(cs)) layer_in[j] = in[cs];
-          else layer_in[j] = out[cs];
-        }
-        else {
+          if (in.contains(cs)) {
+            layer_in[j] = in[cs];
+          } else {
+            layer_in[j] = out[cs];
+          }
+        } else {
           layer_out[j] = out[cs];
         }
         ++j;
index 4f908f0114bb90e01640dd8bf9a6fc86630b4af3..5bfe24354f7eefdb6594ad2c4cec408081c07a25 100644 (file)
@@ -253,14 +253,20 @@ int ErasureCodeShec::encode_chunks(const shard_id_map<bufferptr> &in,
   uint64_t size = 0;
 
   for (auto &&[shard, ptr] : in) {
-    if (size == 0) size = ptr.length();
-    else ceph_assert(size == ptr.length());
+    if (size == 0) {
+      size = ptr.length();
+    } else {
+      ceph_assert(size == ptr.length());
+    }
     chunks[static_cast<int>(shard)] = const_cast<char*>(ptr.c_str());
   }
 
   for (auto &&[shard, ptr] : out) {
-    if (size == 0) size = ptr.length();
-    else ceph_assert(size == ptr.length());
+    if (size == 0) {
+      size = ptr.length();
+    } else {
+      ceph_assert(size == ptr.length());
+    }
     chunks[static_cast<int>(shard)] = ptr.c_str();
   }
 
@@ -372,7 +378,7 @@ END_IGNORE_DEPRECATED
 
 int ErasureCodeShec::decode_chunks(const shard_id_set &want_to_read,
                                    shard_id_map<bufferptr> &in,
-                                  shard_id_map<bufferptr> &out)
+                                   shard_id_map<bufferptr> &out)
 {
   unsigned int size = 0;
   int erased[k + m];
@@ -382,12 +388,15 @@ int ErasureCodeShec::decode_chunks(const shard_id_set &want_to_read,
   char *coding[m];
 
   for (auto &&[shard, ptr] : in) {
-    if (size == 0) size = ptr.length();
-    else ceph_assert(size == ptr.length());
+    if (size == 0) {
+      size = ptr.length();
+    } else {
+      ceph_assert(size == ptr.length());
+    }
+
     if (shard < k) {
       data[static_cast<int>(shard)] = ptr.c_str();
-    }
-    else {
+    } else {
       coding[static_cast<int>(shard) - k] = ptr.c_str();
     }
     avails[static_cast<int>(shard)] = 1;
@@ -395,20 +404,22 @@ int ErasureCodeShec::decode_chunks(const shard_id_set &want_to_read,
   }
 
   for (auto &&[shard, ptr] : out) {
-    if (size == 0) size = ptr.length();
-    else ceph_assert(size == ptr.length());
+    if (size == 0) {
+      size = ptr.length();
+    } else {
+      ceph_assert(size == ptr.length());
+    }
+
     if (shard < k) {
       data[static_cast<int>(shard)] = ptr.c_str();
-    }
-    else {
+    } else {
       coding[static_cast<int>(shard) - k] = ptr.c_str();
     }
     avails[static_cast<int>(shard)] = 0;
     if (want_to_read.count(shard) > 0) {
       erased[static_cast<int>(shard)] = 1;
       erased_count++;
-    }
-    else {
+    } else {
       erased[static_cast<int>(shard)] = 0;
     }
   }
@@ -459,24 +470,37 @@ void ErasureCodeShecReedSolomonVandermonde::apply_delta(const shard_id_map<buffe
   const unsigned blocksize = first->second.length();
 
   for (auto const& [datashard, databuf] : in) {
-    if (datashard < k) {
-      for (auto const& [codingshard, codingbuf] : out) {
-        if (codingshard >= k) {
-          ceph_assert(codingbuf.length() == blocksize);
-          char* input_data = const_cast<char*>(databuf.c_str());
-          char* output_data = const_cast<char*>(codingbuf.c_str());
-          switch (w) {
-            case 8:
-              galois_w08_region_multiply(input_data, matrix[static_cast<int>(datashard) + (k * (static_cast<int>(codingshard) - k))], blocksize, output_data, 1);
-              break;
-            case 16:
-              galois_w16_region_multiply(input_data, matrix[static_cast<int>(datashard) + (k * (static_cast<int>(codingshard) - k))], blocksize, output_data, 1);
-              break;
-            case 32:
-              galois_w32_region_multiply(input_data, matrix[static_cast<int>(datashard) + (k * (int(codingshard) - k))], blocksize, output_data, 1);
-              break;
-          }
-        }
+    if (datashard >= k) {
+      continue;
+    }
+    for (auto const& [codingshard, codingbuf] : out) {
+      if (codingshard < k) {
+        continue;
+      }
+      ceph_assert(codingbuf.length() == blocksize);
+      char* input_data = const_cast<char*>(databuf.c_str());
+      char* output_data = codingbuf.c_str();
+      switch (w) {
+        // We always update one parity at a time, so specify the correct row
+        // in the matrix for this particular parity
+        case 8:
+          galois_w08_region_multiply(
+              input_data,
+              matrix[static_cast<int>(datashard) + (k * (static_cast<int>(codingshard) - k))],
+              blocksize, output_data, 1);
+          break;
+        case 16:
+          galois_w16_region_multiply(
+              input_data,
+              matrix[static_cast<int>(datashard) + (k * (static_cast<int>(codingshard) - k))],
+              blocksize, output_data, 1);
+          break;
+        case 32:
+          galois_w32_region_multiply(
+              input_data,
+              matrix[static_cast<int>(datashard) + (k * (int(codingshard) - k))],
+              blocksize, output_data, 1);
+          break;
       }
     }
   }
index 325ac5428a19b3af882c1dd14b093f0ee9e92982..a5eede865d43bea50a428074ee20ad220db169d6 100644 (file)
@@ -44,14 +44,6 @@ struct raw_shard_id_t {
 
   const static raw_shard_id_t NO_SHARD;
 
-  void encode(ceph::buffer::list &bl) const {
-    using ceph::encode;
-    encode(id, bl);
-  }
-  void decode(ceph::buffer::list::const_iterator &bl) {
-    using ceph::decode;
-    decode(id, bl);
-  }
   void dump(ceph::Formatter *f) const {
     f->dump_int("id", id);
   }
index 11f4e8f5deff24bfd649307e4a2ec2a1f3f4b5c6..a3e0b71f6223fef6f66c2c1603aa733d585fb926 100644 (file)
@@ -185,9 +185,7 @@ public:
     unsigned int chunk_length = get_chunk_size(in.length());
     bufferlist out(in);
     unsigned int width = get_chunk_count() * get_chunk_size(in.length());
-    bufferptr pad(width - in.length());
-    pad.zero(0, get_data_chunk_count());
-    out.push_back(pad);
+    out.append_zero(width - in.length());
     //
     // compute the coding chunk with first chunk ^ second chunk
     //