From a03515de802ff951019e994b582974d4ba31f440 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Tue, 2 Oct 2018 01:37:38 -0700 Subject: [PATCH] reduce: define and initialize pm file regions A pm file consists of: * volume metadata * logical map * chunk maps Define all three of these in struct spdk_reduce_vol. Also define -1ULL to denote an empty entry in the logical map or a chunk map - and initialize the logical map and chunk maps entirely with this value when initializing a new compressed volume. Signed-off-by: Jim Harris Change-Id: I9aae23c73d2fbbdc72050ab103fe9e686907eb40 Reviewed-on: https://review.gerrithub.io/433490 Tested-by: SPDK CI Jenkins Chandler-Test-Pool: SPDK Automated Test System Reviewed-by: Paul Luse Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto --- lib/reduce/reduce.c | 26 ++++++++++++++++++----- test/unit/lib/reduce/reduce.c/reduce_ut.c | 9 ++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/reduce/reduce.c b/lib/reduce/reduce.c index 67384fb71..ce6f20124 100644 --- a/lib/reduce/reduce.c +++ b/lib/reduce/reduce.c @@ -48,6 +48,8 @@ /* Offset into the backing device where the persistent memory file's path is stored. */ #define REDUCE_BACKING_DEV_PATH_OFFSET 4096 +#define REDUCE_EMPTY_MAP_ENTRY -1ULL + /* Structure written to offset 0 of both the pm file and the backing device. */ struct spdk_reduce_vol_superblock { uint8_t signature[8]; @@ -74,6 +76,10 @@ struct spdk_reduce_vol { struct spdk_reduce_pm_file pm_file; struct spdk_reduce_backing_dev *backing_dev; struct spdk_reduce_vol_superblock *backing_super; + + struct spdk_reduce_vol_superblock *pm_super; + uint64_t *pm_logical_map; + uint64_t *pm_chunk_maps; }; /* @@ -228,7 +234,6 @@ spdk_reduce_vol_init(struct spdk_reduce_vol_params *params, spdk_reduce_vol_op_with_handle_complete cb_fn, void *cb_arg) { struct spdk_reduce_vol *vol; - struct spdk_reduce_vol_superblock *pm_super; struct reduce_init_load_ctx *init_ctx; int64_t size, size_needed; size_t mapped_len; @@ -344,13 +349,24 @@ spdk_reduce_vol_init(struct spdk_reduce_vol_params *params, sizeof(vol->backing_super->signature)); memcpy(&vol->backing_super->params, params, sizeof(*params)); - pm_super = (struct spdk_reduce_vol_superblock *)vol->pm_file.pm_buf; - memcpy(pm_super, vol->backing_super, sizeof(*vol->backing_super)); + /* Superblock is at the beginning of the pm file. */ + vol->pm_super = (struct spdk_reduce_vol_superblock *)vol->pm_file.pm_buf; + /* Logical map immediately follows the super block. */ + vol->pm_logical_map = (uint64_t *)(vol->pm_super + 1); + + /* Chunks maps follow the logical map. */ + vol->pm_chunk_maps = vol->pm_logical_map + (params->vol_size / params->chunk_size); + + memcpy(vol->pm_super, vol->backing_super, sizeof(*vol->backing_super)); + /* Writing 0xFF's is equivalent of filling it all with SPDK_EMPTY_MAP_ENTRY. + * Note that this writes 0xFF to not just the logical map but the chunk maps as well. + */ + memset(vol->pm_logical_map, 0xFF, vol->pm_file.size - sizeof(*vol->backing_super)); if (vol->pm_file.pm_is_pmem) { - pmem_persist(pm_super, sizeof(*pm_super)); + pmem_persist(vol->pm_file.pm_buf, vol->pm_file.size); } else { - pmem_msync(pm_super, sizeof(*pm_super)); + pmem_msync(vol->pm_file.pm_buf, vol->pm_file.size); } init_ctx->vol = vol; diff --git a/test/unit/lib/reduce/reduce.c/reduce_ut.c b/test/unit/lib/reduce/reduce.c/reduce_ut.c index 692c5c56e..16ff6c1f1 100644 --- a/test/unit/lib/reduce/reduce.c/reduce_ut.c +++ b/test/unit/lib/reduce/reduce.c/reduce_ut.c @@ -324,6 +324,7 @@ init_md(void) struct spdk_reduce_vol_params *persistent_params; struct spdk_reduce_backing_dev backing_dev = {}; struct spdk_uuid uuid; + uint64_t *entry; params.vol_size = 1024 * 1024; /* 1MB */ params.chunk_size = 16 * 1024; @@ -340,6 +341,14 @@ init_md(void) CU_ASSERT(memcmp(g_persistent_pm_buf, SPDK_REDUCE_SIGNATURE, 8) == 0); persistent_params = (struct spdk_reduce_vol_params *)(g_persistent_pm_buf + 8); CU_ASSERT(memcmp(persistent_params, ¶ms, sizeof(params)) == 0); + /* Now confirm that contents of pm_file after the superblock have been initialized + * to REDUCE_EMPTY_MAP_ENTRY. + */ + entry = (uint64_t *)(g_persistent_pm_buf + sizeof(struct spdk_reduce_vol_superblock)); + while (entry != (uint64_t *)(g_persistent_pm_buf + g_vol->pm_file.size)) { + CU_ASSERT(*entry == REDUCE_EMPTY_MAP_ENTRY); + entry++; + } /* Check that the pm file path was constructed correctly. It should be in * the form: