]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/cache/pwl/LogMap.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / librbd / cache / pwl / LogMap.h
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_LIBRBD_CACHE_RWL_LOG_MAP_H
5 #define CEPH_LIBRBD_CACHE_RWL_LOG_MAP_H
6
7 #include "librbd/BlockGuard.h"
8 #include <list>
9
10 namespace librbd {
11 namespace cache {
12 namespace pwl {
13
14 /**
15 * WriteLogMap: maps block extents to GenericWriteLogEntries
16 *
17 * A WriteLogMapEntry (based on LogMapEntry) refers to a portion of a GenericWriteLogEntry
18 */
19 template <typename T>
20 class LogMapEntry {
21 public:
22 BlockExtent block_extent;
23 std::shared_ptr<T> log_entry;
24
25 LogMapEntry(BlockExtent block_extent,
26 std::shared_ptr<T> log_entry = nullptr);
27 LogMapEntry(std::shared_ptr<T> log_entry);
28
29 template <typename U>
30 friend std::ostream &operator<<(std::ostream &os,
31 LogMapEntry<U> &e);
32 };
33
34 template <typename T>
35 using LogMapEntries = std::list<LogMapEntry<T>>;
36
37 template <typename T>
38 class LogMap {
39 public:
40 LogMap(CephContext *cct);
41 LogMap(const LogMap&) = delete;
42 LogMap &operator=(const LogMap&) = delete;
43
44 void add_log_entry(std::shared_ptr<T> log_entry);
45 void add_log_entries(std::list<std::shared_ptr<T>> &log_entries);
46 void remove_log_entry(std::shared_ptr<T> log_entry);
47 void remove_log_entries(std::list<std::shared_ptr<T>> &log_entries);
48 std::list<std::shared_ptr<T>> find_log_entries(BlockExtent block_extent);
49 LogMapEntries<T> find_map_entries(BlockExtent block_extent);
50
51 private:
52 void add_log_entry_locked(std::shared_ptr<T> log_entry);
53 void remove_log_entry_locked(std::shared_ptr<T> log_entry);
54 void add_map_entry_locked(LogMapEntry<T> &map_entry);
55 void remove_map_entry_locked(LogMapEntry<T> &map_entry);
56 void adjust_map_entry_locked(LogMapEntry<T> &map_entry, BlockExtent &new_extent);
57 void split_map_entry_locked(LogMapEntry<T> &map_entry, BlockExtent &removed_extent);
58 std::list<std::shared_ptr<T>> find_log_entries_locked(const BlockExtent &block_extent);
59 LogMapEntries<T> find_map_entries_locked(const BlockExtent &block_extent);
60
61 using LogMapEntryT = LogMapEntry<T>;
62
63 class LogMapEntryCompare {
64 public:
65 bool operator()(const LogMapEntryT &lhs,
66 const LogMapEntryT &rhs) const;
67 };
68
69 using BlockExtentToLogMapEntries = std::set<LogMapEntryT,
70 LogMapEntryCompare>;
71
72 CephContext *m_cct;
73 ceph::mutex m_lock;
74 BlockExtentToLogMapEntries m_block_to_log_entry_map;
75 };
76
77 } //namespace pwl
78 } //namespace cache
79 } //namespace librbd
80
81 #endif //CEPH_LIBRBD_CACHE_RWL_LOG_MAP_H