From d912dba2cbab12f122028a1a0bdff8d1d1e3e131 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Mon, 1 Oct 2018 12:30:03 -0700 Subject: [PATCH] reduce: close backing dev during unload Signed-off-by: Jim Harris Change-Id: Id94095d2b7069a811ac63123ddd8c5d94f4b53a7 Reviewed-on: https://review.gerrithub.io/432502 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker --- lib/reduce/reduce.c | 8 ++++++++ test/unit/lib/reduce/reduce.c/reduce_ut.c | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/reduce/reduce.c b/lib/reduce/reduce.c index 71643bd46..5fa10f47e 100644 --- a/lib/reduce/reduce.c +++ b/lib/reduce/reduce.c @@ -205,6 +205,12 @@ spdk_reduce_vol_init(struct spdk_reduce_vol_params *params, return; } + if (backing_dev->close == NULL) { + SPDK_ERRLOG("backing_dev function pointer not specified\n"); + cb_fn(cb_arg, NULL, -EINVAL); + return; + } + vol = calloc(1, sizeof(*vol)); if (vol == NULL) { cb_fn(cb_arg, NULL, -ENOMEM); @@ -243,6 +249,8 @@ spdk_reduce_vol_unload(struct spdk_reduce_vol *vol, vol->pm_file.close(&vol->pm_file); } + vol->backing_dev->close(vol->backing_dev); + free(vol); cb_fn(cb_arg, 0); } diff --git a/test/unit/lib/reduce/reduce.c/reduce_ut.c b/test/unit/lib/reduce/reduce.c/reduce_ut.c index 5f69b5ea6..37b255402 100644 --- a/test/unit/lib/reduce/reduce.c/reduce_ut.c +++ b/test/unit/lib/reduce/reduce.c/reduce_ut.c @@ -43,6 +43,7 @@ static struct spdk_reduce_vol *g_vol; static int g_ziperrno; static char *g_volatile_pm_buf; static char *g_persistent_pm_buf; +static bool g_backing_dev_closed; static void sync_pm_buf(const void *addr, size_t length) @@ -240,11 +241,18 @@ init_failure(void) pm_file_destroy(); } +static void +backing_dev_close(struct spdk_reduce_backing_dev *backing_dev) +{ + g_backing_dev_closed = true; +} + static void backing_dev_init(struct spdk_reduce_backing_dev *backing_dev, struct spdk_reduce_vol_params *params) { backing_dev->blocklen = params->backing_io_unit_size; backing_dev->blockcnt = spdk_reduce_get_backing_device_size(params) / backing_dev->blocklen; + backing_dev->close = backing_dev_close; } static void @@ -274,8 +282,10 @@ init_md(void) CU_ASSERT(memcmp(persistent_params, ¶ms, sizeof(params)) == 0); g_ziperrno = -1; + g_backing_dev_closed = false; spdk_reduce_vol_unload(g_vol, unload_cb, NULL); CU_ASSERT(g_ziperrno == 0); + CU_ASSERT(g_backing_dev_closed == true); CU_ASSERT(g_volatile_pm_buf == NULL); pm_file_destroy();