Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
Copyright 2018-2020, Barcelona Supercomputing Center (BSC), Spain
Copyright 2015-2020, Johannes Gutenberg Universitaet Mainz, Germany
This software was partially supported by the
EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).
This software was partially supported by the
ADA-FS project under the SPPEXA project funded by the DFG.
SPDX-License-Identifier: MIT
*/
#ifndef GEKKOFS_DAEMON_DATA_PMDK_POOL_HPP
#define GEKKOFS_DAEMON_DATA_PMDK_POOL_HPP
#include <spdlog/spdlog.h>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
namespace pmdk {
/**
* This class implements a RAII-enabled non-volatile memory pool based on
* Intel's PMDK C library.
*/
class pool {
public:
/**
* Create a pool of non-volatile memory of a fixed `size` under
* `parent_dir`. Give it a random name.
*
* @param[in] parent_dir the parent directory where the memory pool backing
* file will be stored
* @param[in] size the maximum capacity in bytes of the pool
* @returns the newly created pool
*/
pool(const fs::path& parent_dir, std::size_t size) noexcept;
pool(pool&& rhs) = default;
pool(const pool& other) = delete;
pool& operator=(pool&& rhs) = default;
pool& operator=(const pool& other) = delete;
/**
* Destroy an existing pool.
*/
~pool();
/**
* Returns the path to a pool's data storage in the file system.
*
* @returns If the pool was correctly created, the function returns a
* `boost::fylesystem::path` with the path to the file backing the
* pool in the file system. Otherwise, `boost::filesystem::path{}`
* is returned.
*/
fs::path path() const noexcept;
/**
* Returns the address to a pool's data region in non-volatile memory.
*
* @returns If the pool was correctly created, the function returns a
* void pointer to the non-volatile memory region containing the
* pool's data. Otherwise, `nullptr` is returned.
*/
void* data() const noexcept;
/**
* Returns the size of a pool's data region in non-volatile memory.
*
* @returns If the pool was correctly created, the function returns the
* size of the non-volatile memory region containing
* the pool's data. Otherwise, `0` is returned.
*/
std::size_t size() const noexcept;
/**
* Returns whether a pool's data is actually stored in non-volatile
* memory.
*
* @returns The function returns `true` if the pool was correctly created,
* and the pool's data is stored in NVM. Otherwise, `false` is
* returned.
*/
bool is_persistent() const noexcept;
/**
*
* Check whether a pool is valid.
*
* @returns `true` if the pool was correctly created. Otherwise it
* returns `false`.
*/
explicit operator bool() const noexcept;
/**
*
* Check whether a pool is invalid.
*
* @returns `true` if the pool was not correctly created. Otherwise it
* returns `false`.
*/
bool operator!() const noexcept;
/**
*
* Check whether a pool is valid.
*
* @returns `true` if the pool was correctly created. Otherwise it
* returns `false`.
*/
bool valid() const noexcept;
private:
/// Logger instance
std::shared_ptr<spdlog::logger> log_;
/// Path to the pool file in the file system
fs::path path_;
/// Address of the pool's non-volatile memory region
void* data_ = nullptr;
/// Size of the pool's non-volatile memory region
std::size_t size_ = 0;
/// Flag set if the pool file is actually stored in non-volatile memory
bool is_persistent_ = false;
/// Flag set if the pool was created correctly
bool is_valid_ = false;
};
} // namespace pmdk
#endif // GEKKOFS_DAEMON_DATA_PMDK_POOL_HPP