]> git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/src/libpmem2/persist_posix.c
import ceph 16.2.7
[ceph.git] / ceph / src / pmdk / src / libpmem2 / persist_posix.c
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2019-2020, Intel Corporation */
3
4 /*
5 * persist_posix.c -- POSIX-specific part of persist implementation
6 */
7
8 #include <errno.h>
9 #include <stdint.h>
10 #include <sys/mman.h>
11
12 #include "out.h"
13 #include "persist.h"
14 #include "pmem2_utils.h"
15 #include "valgrind_internal.h"
16
17 /*
18 * pmem2_flush_file_buffers_os -- flush CPU and OS file caches for the given
19 * range
20 */
21 int
22 pmem2_flush_file_buffers_os(struct pmem2_map *map, const void *addr, size_t len,
23 int autorestart)
24 {
25 /*
26 * msync accepts addresses aligned to the page boundary, so we may sync
27 * more and part of it may have been marked as undefined/inaccessible.
28 * Msyncing such memory is not a bug, so as a workaround temporarily
29 * disable error reporting.
30 */
31 VALGRIND_DO_DISABLE_ERROR_REPORTING;
32 int ret;
33 do {
34 ret = msync((void *)addr, len, MS_SYNC);
35
36 if (ret < 0) {
37 ERR("!msync");
38 } else {
39 /* full flush */
40 VALGRIND_DO_PERSIST((uintptr_t)addr, len);
41 }
42 } while (autorestart && ret < 0 && errno == EINTR);
43
44 VALGRIND_DO_ENABLE_ERROR_REPORTING;
45
46 if (ret)
47 return PMEM2_E_ERRNO;
48
49 return 0;
50 }