diff --git a/lib/reduce/reduce.c b/lib/reduce/reduce.c index 7874185ea..03ea2ca81 100644 --- a/lib/reduce/reduce.c +++ b/lib/reduce/reduce.c @@ -646,6 +646,8 @@ spdk_reduce_vol_init(struct spdk_reduce_vol_params *params, &init_ctx->backing_cb_args); } +static void destroy_load_cb(void *cb_arg, struct spdk_reduce_vol *vol, int reduce_errno); + static void _load_read_super_and_path_cpl(void *cb_arg, int reduce_errno) { @@ -666,6 +668,18 @@ _load_read_super_and_path_cpl(void *cb_arg, int reduce_errno) goto error; } + /* If the cb_fn is destroy_load_cb, it means we are wanting to destroy this compress bdev. + * So don't bother getting the volume ready to use - invoke the callback immediately + * so destroy_load_cb can delete the metadata off of the block device and delete the + * persistent memory file if it exists. + */ + memcpy(vol->pm_file.path, load_ctx->path, sizeof(vol->pm_file.path)); + if (load_ctx->cb_fn == (*destroy_load_cb)) { + load_ctx->cb_fn(load_ctx->cb_arg, vol, 0); + _init_load_cleanup(NULL, load_ctx); + return; + } + memcpy(&vol->params, &vol->backing_super->params, sizeof(vol->params)); vol->backing_io_units_per_chunk = vol->params.chunk_size / vol->params.backing_io_unit_size; vol->logical_blocks_per_chunk = vol->params.chunk_size / vol->params.logical_block_size; @@ -684,7 +698,6 @@ _load_read_super_and_path_cpl(void *cb_arg, int reduce_errno) goto error; } - memcpy(vol->pm_file.path, load_ctx->path, sizeof(vol->pm_file.path)); vol->pm_file.size = _get_pm_file_size(&vol->params); vol->pm_file.pm_buf = pmem_map_file(vol->pm_file.path, 0, 0, 0, &mapped_len, &vol->pm_file.pm_is_pmem);