]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #ifndef CEPH_OS_BLUESTORE_BITMAPFREELISTMANAGER_H | |
5 | #define CEPH_OS_BLUESTORE_BITMAPFREELISTMANAGER_H | |
6 | ||
7 | #include "FreelistManager.h" | |
8 | ||
9 | #include <string> | |
10 | #include <mutex> | |
11 | ||
11fdf7f2 | 12 | #include "common/ceph_mutex.h" |
7c673cae FG |
13 | #include "include/buffer.h" |
14 | #include "kv/KeyValueDB.h" | |
15 | ||
16 | class BitmapFreelistManager : public FreelistManager { | |
17 | std::string meta_prefix, bitmap_prefix; | |
11fdf7f2 TL |
18 | std::shared_ptr<KeyValueDB::MergeOperator> merge_op; |
19 | ceph::mutex lock = ceph::make_mutex("BitmapFreelistManager::lock"); | |
7c673cae FG |
20 | |
21 | uint64_t size; ///< size of device (bytes) | |
22 | uint64_t bytes_per_block; ///< bytes per block (bdev_block_size) | |
23 | uint64_t blocks_per_key; ///< blocks (bits) per key/value pair | |
24 | uint64_t bytes_per_key; ///< bytes per key/value pair | |
25 | uint64_t blocks; ///< size of device (blocks, size rounded up) | |
26 | ||
27 | uint64_t block_mask; ///< mask to convert byte offset to block offset | |
28 | uint64_t key_mask; ///< mask to convert offset to key offset | |
29 | ||
f67539c2 | 30 | ceph::buffer::list all_set_bl; |
7c673cae FG |
31 | |
32 | KeyValueDB::Iterator enumerate_p; | |
33 | uint64_t enumerate_offset; ///< logical offset; position | |
f67539c2 | 34 | ceph::buffer::list enumerate_bl; ///< current key at enumerate_offset |
7c673cae FG |
35 | int enumerate_bl_pos; ///< bit position in enumerate_bl |
36 | ||
37 | uint64_t _get_offset(uint64_t key_off, int bit) { | |
38 | return key_off + bit * bytes_per_block; | |
39 | } | |
40 | ||
41 | void _init_misc(); | |
42 | ||
7c673cae FG |
43 | void _xor( |
44 | uint64_t offset, uint64_t length, | |
45 | KeyValueDB::Transaction txn); | |
46 | ||
f67539c2 TL |
47 | int _read_cfg( |
48 | std::function<int(const std::string&, std::string*)> cfg_reader); | |
1911f103 TL |
49 | |
50 | int _expand(uint64_t new_size, KeyValueDB* db); | |
51 | ||
52 | uint64_t size_2_block_count(uint64_t target_size) const; | |
53 | ||
54 | int read_size_meta_from_db(KeyValueDB* kvdb, uint64_t* res); | |
55 | void _sync(KeyValueDB* kvdb, bool read_only); | |
56 | ||
57 | void _load_from_db(KeyValueDB* kvdb); | |
58 | ||
7c673cae | 59 | public: |
f67539c2 TL |
60 | BitmapFreelistManager(CephContext* cct, std::string meta_prefix, |
61 | std::string bitmap_prefix); | |
7c673cae | 62 | |
f67539c2 | 63 | static void setup_merge_operator(KeyValueDB *db, std::string prefix); |
7c673cae | 64 | |
b32b8144 | 65 | int create(uint64_t size, uint64_t granularity, |
20effc67 | 66 | uint64_t zone_size, uint64_t first_sequential_zone, |
3efd9988 | 67 | KeyValueDB::Transaction txn) override; |
7c673cae | 68 | |
f67539c2 TL |
69 | int init(KeyValueDB *kvdb, bool db_in_read_only, |
70 | std::function<int(const std::string&, std::string*)> cfg_reader) override; | |
11fdf7f2 | 71 | |
7c673cae | 72 | void shutdown() override; |
1911f103 | 73 | void sync(KeyValueDB* kvdb) override; |
7c673cae | 74 | |
11fdf7f2 | 75 | void dump(KeyValueDB *kvdb) override; |
7c673cae FG |
76 | |
77 | void enumerate_reset() override; | |
11fdf7f2 | 78 | bool enumerate_next(KeyValueDB *kvdb, uint64_t *offset, uint64_t *length) override; |
7c673cae FG |
79 | |
80 | void allocate( | |
81 | uint64_t offset, uint64_t length, | |
82 | KeyValueDB::Transaction txn) override; | |
83 | void release( | |
84 | uint64_t offset, uint64_t length, | |
85 | KeyValueDB::Transaction txn) override; | |
b32b8144 | 86 | |
11fdf7f2 TL |
87 | inline uint64_t get_size() const override { |
88 | return size; | |
89 | } | |
b32b8144 FG |
90 | inline uint64_t get_alloc_units() const override { |
91 | return size / bytes_per_block; | |
92 | } | |
93 | inline uint64_t get_alloc_size() const override { | |
94 | return bytes_per_block; | |
95 | } | |
1911f103 | 96 | void get_meta(uint64_t target_size, |
20effc67 | 97 | std::vector<std::pair<std::string, std::string>>*) const override; |
7c673cae FG |
98 | }; |
99 | ||
100 | #endif |