reduce: don't pass size when loading pmem file

libpmem only allows passing a size when CREATE flag
is set.

This requires some updates in the unit test stubs
for pmem_map_file as well.  While here, do some
additional cleanup and add a g_volatile_pm_buf_len to
track the size of the allocated volatile pm buffer.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Ib9fe58fd9946161dd20bb8391be2e9680705ab22

Reviewed-on: https://review.gerrithub.io/435945
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Jim Harris 2018-11-29 18:46:38 -07:00
parent 4cfae03606
commit 1d75aad3ff
2 changed files with 11 additions and 6 deletions

View File

@ -547,8 +547,8 @@ _load_read_super_and_path_cpl(void *cb_arg, int ziperrno)
memcpy(vol->pm_file.path, load_ctx->path, sizeof(vol->pm_file.path));
vol->pm_file.size = spdk_reduce_get_pm_file_size(&vol->params);
vol->pm_file.pm_buf = pmem_map_file(vol->pm_file.path, vol->pm_file.size,
0, 0, &mapped_len, &vol->pm_file.pm_is_pmem);
vol->pm_file.pm_buf = pmem_map_file(vol->pm_file.path, 0, 0, 0, &mapped_len,
&vol->pm_file.pm_is_pmem);
if (vol->pm_file.pm_buf == NULL) {
SPDK_ERRLOG("could not pmem_map_file(%s): %s\n", vol->pm_file.path, strerror(errno));
rc = -errno;

View File

@ -44,6 +44,7 @@ static int g_ziperrno;
static char *g_volatile_pm_buf;
static size_t g_volatile_pm_buf_len;
static char *g_persistent_pm_buf;
static size_t g_persistent_pm_buf_len;
static bool g_backing_dev_closed;
static char *g_backing_dev_buf;
static const char *g_path;
@ -159,18 +160,20 @@ pmem_map_file(const char *path, size_t len, int flags, mode_t mode,
size_t *mapped_lenp, int *is_pmemp)
{
CU_ASSERT(g_volatile_pm_buf == NULL);
g_volatile_pm_buf = calloc(1, len);
g_volatile_pm_buf_len = len;
g_path = path;
SPDK_CU_ASSERT_FATAL(g_volatile_pm_buf != NULL);
*mapped_lenp = len;
*is_pmemp = 1;
if (g_persistent_pm_buf == NULL) {
g_persistent_pm_buf = calloc(1, len);
g_persistent_pm_buf_len = len;
SPDK_CU_ASSERT_FATAL(g_persistent_pm_buf != NULL);
}
*mapped_lenp = g_persistent_pm_buf_len;
g_volatile_pm_buf = calloc(1, g_persistent_pm_buf_len);
SPDK_CU_ASSERT_FATAL(g_volatile_pm_buf != NULL);
g_volatile_pm_buf_len = g_persistent_pm_buf_len;
return g_volatile_pm_buf;
}
@ -181,6 +184,7 @@ pmem_unmap(void *addr, size_t len)
CU_ASSERT(len == g_volatile_pm_buf_len);
free(g_volatile_pm_buf);
g_volatile_pm_buf = NULL;
g_volatile_pm_buf_len = 0;
return 0;
}
@ -191,6 +195,7 @@ persistent_pm_buf_destroy(void)
CU_ASSERT(g_persistent_pm_buf != NULL);
free(g_persistent_pm_buf);
g_persistent_pm_buf = NULL;
g_persistent_pm_buf_len = 0;
}
static void