From d0ff231e36d2a6e38bf891867431293816ac777c Mon Sep 17 00:00:00 2001 From: Seth Howell Date: Mon, 16 Dec 2019 16:20:49 -0700 Subject: [PATCH] lib/reduce: move _alloc_zero_buf earlier in init stage. In the reduce_dev_destroy case, we were not calling alloc_zero_buf in the load path because of a built in short circuit. This resulted in us decrementing the g_vol_count variable past 0 in cases where we were destroying a reduce volume that we had already freed. This resulted in us failing to allocate the g_zero_buf the next time we loaded a reduce volume. Change-Id: I429cbac1454bdcda502038af659d5302627ecab2 Signed-off-by: Seth Howell Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/478127 Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Tested-by: SPDK CI Jenkins --- lib/reduce/reduce.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/reduce/reduce.c b/lib/reduce/reduce.c index 6b43672f1..6188f6c6c 100644 --- a/lib/reduce/reduce.c +++ b/lib/reduce/reduce.c @@ -662,6 +662,11 @@ _load_read_super_and_path_cpl(void *cb_arg, int reduce_errno) uint32_t j; int rc; + rc = _alloc_zero_buff(); + if (rc) { + goto error; + } + if (memcmp(vol->backing_super->signature, SPDK_REDUCE_SIGNATURE, sizeof(vol->backing_super->signature)) != 0) { @@ -738,11 +743,6 @@ _load_read_super_and_path_cpl(void *cb_arg, int reduce_errno) } } - rc = _alloc_zero_buff(); - if (rc) { - goto error; - } - load_ctx->cb_fn(load_ctx->cb_arg, vol, 0); /* Only clean up the ctx - the vol has been passed to the application * for use now that volume load was successful. @@ -834,6 +834,7 @@ spdk_reduce_vol_unload(struct spdk_reduce_vol *vol, if (--g_vol_count == 0) { spdk_free(g_zero_buf); } + assert(g_vol_count >= 0); _init_load_cleanup(vol, NULL); cb_fn(cb_arg, 0); }