From 1cfe140bf2dab99517589a82a916f4c75b9492d1 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sun, 11 Aug 2013 14:19:11 -0700 Subject: [PATCH] crush: eliminate CRUSH_MAX_SET result size limitation This is only present to size the temporary scratch arrays that we put on the stack. Let the caller allocate them as they wish and remove the limitation. Signed-off-by: Sage Weil --- src/crush/CrushWrapper.h | 3 ++- src/crush/crush.h | 1 - src/crush/mapper.c | 9 +++++---- src/crush/mapper.h | 16 +++++++++++++++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index b4bb67bb7429b..3c4a4518124e9 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -764,7 +764,8 @@ public: const vector<__u32>& weight) const { Mutex::Locker l(mapper_lock); int rawout[maxout]; - int numrep = crush_do_rule(crush, rule, x, rawout, maxout, &weight[0], weight.size()); + int scratch[maxout * 3]; + int numrep = crush_do_rule(crush, rule, x, rawout, maxout, &weight[0], weight.size(), scratch); if (numrep < 0) numrep = 0; out.resize(numrep); diff --git a/src/crush/crush.h b/src/crush/crush.h index 4adabcbf33109..7a0867744c488 100644 --- a/src/crush/crush.h +++ b/src/crush/crush.h @@ -27,7 +27,6 @@ #define CRUSH_MAX_DEPTH 10 /* max crush hierarchy depth */ -#define CRUSH_MAX_SET 10 /* max size of a mapping result */ #define CRUSH_MAX_DEVICE_WEIGHT (100u * 0x10000u) #define CRUSH_MAX_BUCKET_WEIGHT (65535u * 0x10000u) diff --git a/src/crush/mapper.c b/src/crush/mapper.c index ce23ef7c7115a..8af8810f3d3e4 100644 --- a/src/crush/mapper.c +++ b/src/crush/mapper.c @@ -478,12 +478,13 @@ reject: */ int crush_do_rule(const struct crush_map *map, int ruleno, int x, int *result, int result_max, - const __u32 *weight, int weight_max) + const __u32 *weight, int weight_max, + int *scratch) { int result_len; - int a[CRUSH_MAX_SET]; - int b[CRUSH_MAX_SET]; - int c[CRUSH_MAX_SET]; + int *a = scratch; + int *b = scratch + result_max; + int *c = scratch + result_max*2; int recurse_to_leaf; int *w; int wsize = 0; diff --git a/src/crush/mapper.h b/src/crush/mapper.h index 73f3febbf3e4c..3df32fe084bcc 100644 --- a/src/crush/mapper.h +++ b/src/crush/mapper.h @@ -11,9 +11,23 @@ #include "crush.h" extern int crush_find_rule(const struct crush_map *map, int ruleset, int type, int size); + +/** + * crush_do_rule - execute a crush rule to generate a mapping + * + * @param map pointer to crush map + * @param ruleno rule number + * @param x input + * @param result pointer to result vector + * @param result_max max number of requested results + * @param weights weight vector (for map leaves) + * @param weight_max size of weight vector + * @param scrach scratch vector for private use; must be >= 3 * result_max + */ extern int crush_do_rule(const struct crush_map *map, int ruleno, int x, int *result, int result_max, - const __u32 *weights, int weight_max); + const __u32 *weights, int weight_max, + int *scratch); #endif -- 2.39.5