]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | // | |
5 | // A freelist manager for zoned devices. This iteration just keeps the write | |
6 | // pointer per zone. Following iterations will add enough information to enable | |
7 | // cleaning of zones. | |
8 | // | |
9 | // Copyright (C) 2020 Abutalib Aghayev | |
10 | // | |
11 | ||
12 | #ifndef CEPH_OS_BLUESTORE_ZONEDFREELISTMANAGER_H | |
13 | #define CEPH_OS_BLUESTORE_ZONEDFREELISTMANAGER_H | |
14 | ||
15 | #include "FreelistManager.h" | |
16 | ||
17 | #include <string> | |
18 | #include <mutex> | |
19 | ||
20 | #include "common/ceph_mutex.h" | |
21 | #include "include/buffer.h" | |
22 | #include "kv/KeyValueDB.h" | |
23 | ||
24 | using cfg_reader_t = std::function<int(const std::string&, std::string*)>; | |
25 | ||
26 | class ZonedFreelistManager : public FreelistManager { | |
27 | std::string meta_prefix; ///< device size, zone size, etc. | |
28 | std::string info_prefix; ///< per zone write pointer, dead bytes | |
29 | mutable ceph::mutex lock = ceph::make_mutex("ZonedFreelistManager::lock"); | |
30 | ||
31 | uint64_t size; ///< size of sequential region (bytes) | |
32 | uint64_t bytes_per_block; ///< bytes per allocation unit (bytes) | |
33 | uint64_t zone_size; ///< size of a single zone (bytes) | |
34 | uint64_t num_zones; ///< number of sequential zones | |
35 | uint64_t starting_zone_num; ///< the first sequential zone number | |
36 | ||
37 | KeyValueDB::Iterator enumerate_p; | |
38 | uint64_t enumerate_zone_num; | |
39 | ||
40 | void write_zone_state_to_db(uint64_t zone_num, | |
41 | const zone_state_t &zone_state, | |
42 | KeyValueDB::Transaction txn); | |
43 | void load_zone_state_from_db(uint64_t zone_num, | |
44 | zone_state_t &zone_state, | |
45 | KeyValueDB::Iterator &it) const; | |
46 | ||
47 | void init_zone_states(KeyValueDB::Transaction txn); | |
48 | ||
49 | void increment_write_pointer( | |
50 | uint64_t zone, uint64_t length, KeyValueDB::Transaction txn); | |
51 | void increment_num_dead_bytes( | |
52 | uint64_t zone, uint64_t num_bytes, KeyValueDB::Transaction txn); | |
53 | ||
54 | int _read_cfg(cfg_reader_t cfg_reader); | |
55 | ||
56 | public: | |
57 | ZonedFreelistManager(CephContext* cct, | |
58 | std::string meta_prefix, | |
59 | std::string info_prefix); | |
60 | ||
61 | static void setup_merge_operator(KeyValueDB *db, std::string prefix); | |
62 | ||
63 | int create(uint64_t size, | |
64 | uint64_t granularity, | |
65 | KeyValueDB::Transaction txn) override; | |
66 | ||
67 | int init(KeyValueDB *kvdb, | |
68 | bool db_in_read_only, | |
69 | cfg_reader_t cfg_reader) override; | |
70 | ||
71 | void shutdown() override; | |
72 | void sync(KeyValueDB* kvdb) override; | |
73 | void dump(KeyValueDB *kvdb) override; | |
74 | ||
75 | void enumerate_reset() override; | |
76 | bool enumerate_next(KeyValueDB *kvdb, | |
77 | uint64_t *offset, | |
78 | uint64_t *length) override; | |
79 | ||
80 | void allocate(uint64_t offset, | |
81 | uint64_t length, | |
82 | KeyValueDB::Transaction txn) override; | |
83 | ||
84 | void release(uint64_t offset, | |
85 | uint64_t length, | |
86 | KeyValueDB::Transaction txn) override; | |
87 | ||
88 | inline uint64_t get_size() const override { | |
89 | return size; | |
90 | } | |
91 | ||
92 | inline uint64_t get_alloc_units() const override { | |
93 | return size / bytes_per_block; | |
94 | } | |
95 | ||
96 | inline uint64_t get_alloc_size() const override { | |
97 | return bytes_per_block; | |
98 | } | |
99 | ||
100 | void get_meta(uint64_t target_size, | |
101 | std::vector<std::pair<string, string>>*) const override; | |
102 | ||
103 | std::vector<zone_state_t> get_zone_states(KeyValueDB *kvdb) const override; | |
104 | }; | |
105 | ||
106 | #endif |