[sheepdog] [PATCH] erasure: simplify ec_decode_buffer()

Liu Yuan namei.unix at gmail.com
Sat Oct 19 06:13:02 CEST 2013


- remove strip_size since it can be deduced from passed struct fec *ctx
- remove nr_stripe because nr_stripe for the buffer as a whole is always fixed
  and there is no use case to decode a partial buffer.

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 dog/vdi.c        |    7 ++-----
 include/fec.h    |    3 ++-
 lib/fec.c        |    5 +++--
 sheep/recovery.c |    4 +---
 4 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/dog/vdi.c b/dog/vdi.c
index 08f154e..dc3d1f1 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -1556,7 +1556,6 @@ static void check_erasure_object(struct vdi_check_info *info)
 	int dp = ec_policy_to_dp(info->copy_policy, &d, &p);
 	struct fec *ctx = ec_init(d, dp);
 	int miss_idx[dp], input_idx[dp];
-	size_t strip_size = SD_EC_DATA_STRIPE_SIZE / d;
 	uint64_t oid = info->oid;
 	size_t len = get_store_objsize(info->copy_policy, oid);
 	char *obj = xmalloc(len);
@@ -1584,8 +1583,7 @@ static void check_erasure_object(struct vdi_check_info *info)
 			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);
+			ec_decode_buffer(ctx, ds, idx, obj, d + k);
 			if (memcmp(obj, info->vcw[d + k].buf, len) != 0) {
 				/* TODO repair the inconsistency */
 				sd_err("object %"PRIx64" is inconsistent", oid);
@@ -1603,8 +1601,7 @@ static void check_erasure_object(struct vdi_check_info *info)
 
 			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);
+			ec_decode_buffer(ctx, ds, input_idx, obj, m);
 			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 1a61671..0297f33 100644
--- a/include/fec.h
+++ b/include/fec.h
@@ -63,6 +63,7 @@
 #include <stdint.h>
 
 #include "util.h"
+#include "sheepdog_proto.h"
 
 struct fec {
 	unsigned long magic;
@@ -197,5 +198,5 @@ static inline void ec_destroy(struct fec *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);
+		      char *buf, int idx);
 #endif
diff --git a/lib/fec.c b/lib/fec.c
index 7c1c57d..7d897e4 100644
--- a/lib/fec.c
+++ b/lib/fec.c
@@ -683,11 +683,12 @@ out:
 }
 
 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)
+		      char *buf, int idx)
 {
 	int i, j, d = ctx->d;
+	size_t strip_size = SD_EC_DATA_STRIPE_SIZE / d;
 
-	for (i = 0; i < nr_stripe; i++) {
+	for (i = 0; i < SD_EC_NR_STRIPE_PER_OBJECT; i++) {
 		const uint8_t *in[d];
 		uint8_t out[strip_size];
 
diff --git a/sheep/recovery.c b/sheep/recovery.c
index 37dde3c..39ca2b1 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -423,9 +423,7 @@ static void *rebuild_erasure_object(uint64_t oid, uint8_t idx,
 	}
 
 	/* Rebuild the lost replica */
-	ec_decode_buffer(ctx, bufs, idxs, lost, idx,
-			 SD_EC_DATA_STRIPE_SIZE / ed,
-			 SD_EC_NR_STRIPE_PER_OBJECT);
+	ec_decode_buffer(ctx, bufs, idxs, lost, idx);
 out:
 	ec_destroy(ctx);
 	for (i = 0; i < ed; i++)
-- 
1.7.9.5




More information about the sheepdog mailing list