@@ -221,47 +221,6 @@ void log_t::create()
221
221
(aligned_malloc (OS_FILE_LOG_BLOCK_SIZE, OS_FILE_LOG_BLOCK_SIZE));
222
222
}
223
223
224
- mapped_file_t ::~mapped_file_t () noexcept
225
- {
226
- if (!m_area.empty ())
227
- unmap ();
228
- }
229
-
230
- dberr_t mapped_file_t::map (const char *path, bool read_only,
231
- bool nvme) noexcept
232
- {
233
- auto fd= mysql_file_open (innodb_log_file_key, path,
234
- read_only ? O_RDONLY : O_RDWR, MYF (MY_WME));
235
- if (fd == -1 )
236
- return DB_ERROR;
237
-
238
- const auto file_size= os_file_get_size (path).m_total_size ;
239
-
240
- const int nvme_flag= nvme ? MAP_SYNC : 0 ;
241
- void *ptr= my_mmap (0 , static_cast <size_t >(file_size),
242
- read_only ? PROT_READ : PROT_READ | PROT_WRITE,
243
- MAP_SHARED_VALIDATE | nvme_flag, fd, 0 );
244
- mysql_file_close (fd, MYF (MY_WME));
245
-
246
- if (ptr == MAP_FAILED)
247
- return DB_ERROR;
248
-
249
- m_area= {static_cast <byte *>(ptr),
250
- static_cast <span<byte>::size_type>(file_size)};
251
- return DB_SUCCESS;
252
- }
253
-
254
- dberr_t mapped_file_t::unmap () noexcept
255
- {
256
- ut_ad (!m_area.empty ());
257
-
258
- if (my_munmap (m_area.data (), m_area.size ()))
259
- return DB_ERROR;
260
-
261
- m_area= {};
262
- return DB_SUCCESS;
263
- }
264
-
265
224
file_os_io::file_os_io (file_os_io &&rhs) : m_fd(rhs.m_fd)
266
225
{
267
226
rhs.m_fd = OS_FILE_CLOSED;
@@ -331,6 +290,66 @@ dberr_t file_os_io::flush() noexcept
331
290
332
291
#include < libpmem.h>
333
292
293
+ /* * Memory mapped file */
294
+ class mapped_file_t
295
+ {
296
+ public:
297
+ mapped_file_t ()= default ;
298
+ mapped_file_t (const mapped_file_t &)= delete ;
299
+ mapped_file_t &operator =(const mapped_file_t &)= delete ;
300
+ mapped_file_t (mapped_file_t &&)= delete ;
301
+ mapped_file_t &operator =(mapped_file_t &&)= delete ;
302
+ ~mapped_file_t () noexcept ;
303
+
304
+ dberr_t map (const char *path, bool read_only= false ,
305
+ bool nvme= false ) noexcept ;
306
+ dberr_t unmap () noexcept ;
307
+ byte *data () noexcept { return m_area.data (); }
308
+
309
+ private:
310
+ span<byte> m_area;
311
+ };
312
+
313
+ mapped_file_t ::~mapped_file_t () noexcept
314
+ {
315
+ if (!m_area.empty ())
316
+ unmap ();
317
+ }
318
+
319
+ dberr_t mapped_file_t::map (const char *path, bool read_only,
320
+ bool nvme) noexcept
321
+ {
322
+ auto fd= mysql_file_open (innodb_log_file_key, path,
323
+ read_only ? O_RDONLY : O_RDWR, MYF (MY_WME));
324
+ if (fd == -1 )
325
+ return DB_ERROR;
326
+
327
+ const auto file_size= size_t {os_file_get_size (path).m_total_size };
328
+
329
+ const int nvme_flag= nvme ? MAP_SYNC : 0 ;
330
+ void *ptr=
331
+ my_mmap (0 , file_size, read_only ? PROT_READ : PROT_READ | PROT_WRITE,
332
+ MAP_SHARED_VALIDATE | nvme_flag, fd, 0 );
333
+ mysql_file_close (fd, MYF (MY_WME));
334
+
335
+ if (ptr == MAP_FAILED)
336
+ return DB_ERROR;
337
+
338
+ m_area= {static_cast <byte *>(ptr), file_size};
339
+ return DB_SUCCESS;
340
+ }
341
+
342
+ dberr_t mapped_file_t::unmap () noexcept
343
+ {
344
+ ut_ad (!m_area.empty ());
345
+
346
+ if (my_munmap (m_area.data (), m_area.size ()))
347
+ return DB_ERROR;
348
+
349
+ m_area= {};
350
+ return DB_SUCCESS;
351
+ }
352
+
334
353
static bool is_pmem (const char *path) noexcept
335
354
{
336
355
mapped_file_t mf;
0 commit comments