Skip to content

Commit

Permalink
Merge pull request #1714 from krzycz/pmem-is_pmem_fix_1.2
Browse files Browse the repository at this point in the history
pmem: fix wrong is_pmem returned by pmem_map_file
  • Loading branch information
krzycz authored Mar 2, 2017
2 parents 56ef1a2 + d931488 commit d12052f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/libpmem/pmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,18 @@ pmem_map_file(const char *path, size_t len, int flags, mode_t mode,
if ((addr = util_map(fd, len, 0, 0)) == NULL)
goto err; /* util_map() set errno, called LOG */

#ifndef _WIN32
/* XXX only Device DAX regions (PMEM) are tracked so far */
if (is_dev_dax && util_range_register(addr, len) != 0) {
LOG(2, "can't track mapped region");
}
#endif

if (mapped_lenp != NULL)
*mapped_lenp = len;

if (is_pmemp != NULL)
*is_pmemp = pmem_is_pmem(addr, len);
*is_pmemp = is_dev_dax || pmem_is_pmem(addr, len);

LOG(3, "returning %p", addr);

Expand All @@ -677,13 +684,6 @@ pmem_map_file(const char *path, size_t len, int flags, mode_t mode,

(void) close(fd);

#ifndef _WIN32
/* XXX only Device DAX regions (PMEM) are tracked so far */
if (is_dev_dax && util_range_register(addr, len) != 0) {
LOG(2, "can't track mapped region");
}
#endif

return addr;

err:
Expand Down
8 changes: 8 additions & 0 deletions src/test/pmem_map/pmem_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ main(int argc, char *argv[])
}

if (addr) {
/* is_pmem must be true for device DAX */
int is_pmem_check = pmem_is_pmem(addr, mlen);
UT_ASSERT(!is_dev_dax || is_pmem_check);

/* check is_pmem returned from pmem_map_file */
if (use_is_pmem)
UT_ASSERTeq(is_pmem, is_pmem_check);

if ((flags & PMEM_FILE_TMPFILE) == 0 && !is_dev_dax) {
fd = OPEN(argv[i], O_RDWR);

Expand Down

0 comments on commit d12052f

Please sign in to comment.