[sheepdog] [PATCH v3 6/6] erasure: add ec_decode_buffer() helper

Liu Yuan namei.unix at gmail.com
Fri Oct 18 20:34:26 CEST 2013


Since there are multiple places tries to decode the whole object, it is nice to
have a helper function to do it.

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 dog/vdi.c        |   31 +++++++++++--------------------
 include/fec.h    |    2 ++
 lib/fec.c        |   16 ++++++++++++++++
 sheep/recovery.c |   13 +++----------
 4 files changed, 32 insertions(+), 30 deletions(-)

diff --git a/dog/vdi.c b/dog/vdi.c
index a716d1c..08f154e 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -1581,16 +1581,11 @@ static void check_erasure_object(struct vdi_check_info *info)
 			idx[i] = i;
 
 		for (k = 0; k < p; k++) {
-			for (i = 0; i < SD_EC_NR_STRIPE_PER_OBJECT; i++) {
-				const uint8_t *ds[d];
-				uint8_t out[strip_size];
-
-				for (j = 0; j < d; j++)
-					ds[j] = info->vcw[j].buf + strip_size
-						* i;
-				ec_decode(ctx, ds, idx, out, d + k);
-				memcpy(obj + strip_size * i, out, strip_size);
-			}
+			uint8_t *ds[d];
+			for (j = 0; j < d; j++)
+				ds[j] = info->vcw[j].buf;
+			ec_decode_buffer(ctx, ds, idx, obj, d + k, strip_size,
+					 SD_EC_NR_STRIPE_PER_OBJECT);
 			if (memcmp(obj, info->vcw[d + k].buf, len) != 0) {
 				/* TODO repair the inconsistency */
 				sd_err("object %"PRIx64" is inconsistent", oid);
@@ -1603,17 +1598,13 @@ static void check_erasure_object(struct vdi_check_info *info)
 		goto out;
 	} else {
 		for (k = 0; k < j; k++) {
-			int m = miss_idx[k], n;
-
-			for (i = 0; i < SD_EC_NR_STRIPE_PER_OBJECT; i++) {
-				const uint8_t *ds[d];
-				uint8_t out[strip_size];
+			int m = miss_idx[k];
+			uint8_t *ds[d];
 
-				for (n = 0; n < d; n++)
-					ds[n] = input[n] + strip_size * i;
-				ec_decode(ctx, ds, input_idx, out, m);
-				memcpy(obj + strip_size * i, out, strip_size);
-			}
+			for (i = 0; i < d; i++)
+				ds[i] = input[i];
+			ec_decode_buffer(ctx, ds, input_idx, obj, m, strip_size,
+					 SD_EC_NR_STRIPE_PER_OBJECT);
 			write_object_to(info->vcw[m].vnode, oid, obj, true,
 					info->vcw[m].ec_index);
 			fprintf(stdout, "fixed missing %"PRIx64", "
diff --git a/include/fec.h b/include/fec.h
index c8b5d5c..1a61671 100644
--- a/include/fec.h
+++ b/include/fec.h
@@ -196,4 +196,6 @@ static inline void ec_destroy(struct fec *ctx)
 	fec_free(ctx);
 }
 
+void ec_decode_buffer(struct fec *ctx, uint8_t *input[], const int in_idx[],
+		      char *buf, int idx, size_t strip_size, int nr_stripe);
 #endif
diff --git a/lib/fec.c b/lib/fec.c
index 1d60e8b..7c1c57d 100644
--- a/lib/fec.c
+++ b/lib/fec.c
@@ -681,3 +681,19 @@ void ec_decode(struct fec *ctx, const uint8_t *input[], const int inidx[],
 out:
 	memcpy(output, dp[idx], strip_size);
 }
+
+void ec_decode_buffer(struct fec *ctx, uint8_t *input[], const int in_idx[],
+		      char *buf, int idx, size_t strip_size, int nr_stripe)
+{
+	int i, j, d = ctx->d;
+
+	for (i = 0; i < nr_stripe; i++) {
+		const uint8_t *in[d];
+		uint8_t out[strip_size];
+
+		for (j = 0; j < d; j++)
+			in[j] = input[j] + strip_size * i;
+		ec_decode(ctx, in, in_idx, out, idx);
+		memcpy(buf + strip_size * i, out, strip_size);
+	}
+}
diff --git a/sheep/recovery.c b/sheep/recovery.c
index 790bca8..37dde3c 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -423,16 +423,9 @@ static void *rebuild_erasure_object(uint64_t oid, uint8_t idx,
 	}
 
 	/* Rebuild the lost replica */
-	for (i = 0; i < SD_EC_NR_STRIPE_PER_OBJECT; i++) {
-		const uint8_t *in[ed];
-		int strip_size = SD_EC_DATA_STRIPE_SIZE / ed;
-		uint8_t out[strip_size];
-
-		for (j = 0; j < ed; j++)
-			in[j] = bufs[j] + strip_size * i;
-		ec_decode(ctx, in, idxs, out, idx);
-		memcpy(lost + strip_size * i, out, strip_size);
-	}
+	ec_decode_buffer(ctx, bufs, idxs, lost, idx,
+			 SD_EC_DATA_STRIPE_SIZE / ed,
+			 SD_EC_NR_STRIPE_PER_OBJECT);
 out:
 	ec_destroy(ctx);
 	for (i = 0; i < ed; i++)
-- 
1.7.9.5




More information about the sheepdog mailing list