Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / os / bluestore / PMEMDevice.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  *  Copyright (C) 2015 Intel <jianpeng.ma@intel.com>
7  *
8  * Author: Jianpeng Ma <jianpeng.ma@intel.com>
9  *
10  * This is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License version 2.1, as published by the Free Software
13  * Foundation.  See file COPYING.
14  *
15  */
16
17 #ifndef CEPH_OS_BLUESTORE_PMEMDEVICE_H
18 #define CEPH_OS_BLUESTORE_PMEMDEVICE_H
19
20 #include <atomic>
21
22 #include "os/fs/FS.h"
23 #include "include/interval_set.h"
24 #include "aio.h"
25 #include "BlockDevice.h"
26
27 class PMEMDevice : public BlockDevice {
28   int fd;
29   char *addr; //the address of mmap
30   uint64_t size;
31   uint64_t block_size;
32   std::string path;
33
34   Mutex debug_lock;
35   interval_set<uint64_t> debug_inflight;
36
37   std::atomic_int injecting_crash;
38   int _lock();
39
40 public:
41   PMEMDevice(CephContext *cct, aio_callback_t cb, void *cbpriv);
42
43
44   void aio_submit(IOContext *ioc) override;
45
46   uint64_t get_size() const override {
47     return size;
48   }
49   uint64_t get_block_size() const override {
50     return block_size;
51   }
52
53   int collect_metadata(std::string prefix, map<std::string,std::string> *pm) const override;
54
55   int read(uint64_t off, uint64_t len, bufferlist *pbl,
56            IOContext *ioc,
57            bool buffered) override;
58   int aio_read(uint64_t off, uint64_t len, bufferlist *pbl,
59                IOContext *ioc) override;
60
61   int read_random(uint64_t off, uint64_t len, char *buf, bool buffered) override;
62   int write(uint64_t off, bufferlist& bl, bool buffered) override;
63   int aio_write(uint64_t off, bufferlist& bl,
64                 IOContext *ioc,
65                 bool buffered) override;
66   int flush() override;
67
68   // for managing buffered readers/writers
69   int invalidate_cache(uint64_t off, uint64_t len) override;
70   int open(const std::string &path) override;
71   void close() override;
72 };
73
74 #endif