]> git.proxmox.com Git - ceph.git/blame - ceph/src/os/bluestore/ZonedFreelistManager.h
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / os / bluestore / ZonedFreelistManager.h
CommitLineData
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//
20effc67 5// A freelist manager for zoned devices.
f67539c2
TL
6//
7// Copyright (C) 2020 Abutalib Aghayev
8//
9
10#ifndef CEPH_OS_BLUESTORE_ZONEDFREELISTMANAGER_H
11#define CEPH_OS_BLUESTORE_ZONEDFREELISTMANAGER_H
12
13#include "FreelistManager.h"
14
15#include <string>
16#include <mutex>
17
18#include "common/ceph_mutex.h"
19#include "include/buffer.h"
20#include "kv/KeyValueDB.h"
20effc67 21#include "zoned_types.h"
f67539c2
TL
22
23using cfg_reader_t = std::function<int(const std::string&, std::string*)>;
24
25class ZonedFreelistManager : public FreelistManager {
26 std::string meta_prefix; ///< device size, zone size, etc.
27 std::string info_prefix; ///< per zone write pointer, dead bytes
28 mutable ceph::mutex lock = ceph::make_mutex("ZonedFreelistManager::lock");
29
30 uint64_t size; ///< size of sequential region (bytes)
31 uint64_t bytes_per_block; ///< bytes per allocation unit (bytes)
32 uint64_t zone_size; ///< size of a single zone (bytes)
33 uint64_t num_zones; ///< number of sequential zones
34 uint64_t starting_zone_num; ///< the first sequential zone number
35
36 KeyValueDB::Iterator enumerate_p;
37 uint64_t enumerate_zone_num;
38
20effc67
TL
39 void write_zone_state_delta_to_db(uint64_t zone_num,
40 const zone_state_t &zone_state,
41 KeyValueDB::Transaction txn);
42 void write_zone_state_reset_to_db(uint64_t zone_num,
43 const zone_state_t &zone_state,
44 KeyValueDB::Transaction txn);
f67539c2
TL
45 void load_zone_state_from_db(uint64_t zone_num,
46 zone_state_t &zone_state,
47 KeyValueDB::Iterator &it) const;
48
49 void init_zone_states(KeyValueDB::Transaction txn);
50
51 void increment_write_pointer(
52 uint64_t zone, uint64_t length, KeyValueDB::Transaction txn);
53 void increment_num_dead_bytes(
54 uint64_t zone, uint64_t num_bytes, KeyValueDB::Transaction txn);
55
56 int _read_cfg(cfg_reader_t cfg_reader);
57
58public:
59 ZonedFreelistManager(CephContext* cct,
60 std::string meta_prefix,
61 std::string info_prefix);
62
63 static void setup_merge_operator(KeyValueDB *db, std::string prefix);
64
65 int create(uint64_t size,
66 uint64_t granularity,
20effc67
TL
67 uint64_t zone_size,
68 uint64_t first_sequential_zone,
f67539c2
TL
69 KeyValueDB::Transaction txn) override;
70
71 int init(KeyValueDB *kvdb,
72 bool db_in_read_only,
73 cfg_reader_t cfg_reader) override;
74
75 void shutdown() override;
76 void sync(KeyValueDB* kvdb) override;
77 void dump(KeyValueDB *kvdb) override;
78
79 void enumerate_reset() override;
80 bool enumerate_next(KeyValueDB *kvdb,
81 uint64_t *offset,
82 uint64_t *length) override;
83
84 void allocate(uint64_t offset,
85 uint64_t length,
86 KeyValueDB::Transaction txn) override;
87
88 void release(uint64_t offset,
89 uint64_t length,
90 KeyValueDB::Transaction txn) override;
91
92 inline uint64_t get_size() const override {
93 return size;
94 }
95
96 inline uint64_t get_alloc_units() const override {
97 return size / bytes_per_block;
98 }
99
100 inline uint64_t get_alloc_size() const override {
101 return bytes_per_block;
102 }
103
104 void get_meta(uint64_t target_size,
20effc67 105 std::vector<std::pair<std::string, std::string>>*) const override;
f67539c2 106
20effc67
TL
107 std::vector<zone_state_t> get_zone_states(KeyValueDB *kvdb) const;
108
109 void mark_zone_to_clean_free(uint64_t zone,
110 KeyValueDB *kvdb);
f67539c2
TL
111};
112
113#endif