From 586ab4aa39ddab9d82f55b6ba41eaf41284953e7 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 18 May 2018 17:10:14 -0500 Subject: [PATCH] crush: create weight-set on demand when doing a choose-args reweight If we try to reweight an item in a choose-args set for a given item but the bucket doesn't have a weight_set yet, create it on the fly, and populate it with the canonical bucket weights. Signed-off-by: Sage Weil (cherry picked from commit d8d08b8cbf5b0ad3646dd1e177a1418e96273244) --- src/crush/CrushWrapper.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 6fde997e07f00..b3cc3c0fc1362 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -3437,11 +3437,20 @@ int CrushWrapper::_choose_args_adjust_item_weight_in_bucket( } crush_choose_arg *carg = &cmap.args[bidx]; if (carg->weight_set == NULL) { - if (ss) - *ss << "no weight-set for bucket " << b->id; - ldout(cct, 10) << __func__ << " no weight_set for bucket " << b->id - << dendl; - return 0; + // create a weight-set for this bucket and populate it with the + // bucket weights + unsigned positions = get_choose_args_positions(cmap); + carg->weight_set_positions = positions; + carg->weight_set = static_cast( + calloc(sizeof(crush_weight_set), positions)); + for (unsigned p = 0; p < positions; ++p) { + carg->weight_set[p].size = b->size; + carg->weight_set[p].weights = (__u32*)calloc(b->size, sizeof(__u32)); + for (unsigned i = 0; i < b->size; ++i) { + carg->weight_set[p].weights[i] = crush_get_bucket_item_weight(b, i); + } + } + changed++; } if (carg->weight_set_positions != weight.size()) { if (ss) -- 2.39.5