summaryrefslogtreecommitdiffstats
path: root/src/crimson/os/seastore/lba_mapping.h
blob: 338d4d53f5580d09e8df0543a4a0051b97cf8784 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#pragma once

#include "crimson/os/seastore/cached_extent.h"
#include "crimson/os/seastore/btree/btree_range_pin.h"

namespace crimson::os::seastore {

class LBAMapping;
using LBAMappingRef = std::unique_ptr<LBAMapping>;

class LogicalCachedExtent;

class LBAMapping : public BtreeNodeMapping<laddr_t, paddr_t> {
public:
  LBAMapping(op_context_t<laddr_t> ctx)
    : BtreeNodeMapping<laddr_t, paddr_t>(ctx) {}
  template <typename... T>
  LBAMapping(T&&... t)
    : BtreeNodeMapping<laddr_t, paddr_t>(std::forward<T>(t)...)
  {
    if (!parent->is_pending()) {
      this->child_pos = {parent, pos};
    }
  }

  // An lba pin may be indirect, see comments in lba_manager/btree/btree_lba_manager.h
  virtual bool is_indirect() const = 0;
  virtual laddr_t get_intermediate_key() const = 0;
  virtual laddr_t get_intermediate_base() const = 0;
  virtual extent_len_t get_intermediate_length() const = 0;
  // The start offset of the pin, must be 0 if the pin is not indirect
  virtual extent_len_t get_intermediate_offset() const = 0;

  virtual get_child_ret_t<LogicalCachedExtent>
  get_logical_extent(Transaction &t) = 0;

  void link_child(ChildableCachedExtent *c) {
    ceph_assert(child_pos);
    child_pos->link_child(c);
  }
  virtual LBAMappingRef refresh_with_pending_parent() = 0;

  // For reserved mappings, the return values are
  // undefined although it won't crash
  virtual bool is_stable() const = 0;
  virtual bool is_data_stable() const = 0;
  virtual bool is_clone() const = 0;
  bool is_zero_reserved() const {
    return !get_val().is_real();
  }

  LBAMappingRef duplicate() const;

  virtual ~LBAMapping() {}
protected:
  virtual LBAMappingRef _duplicate(op_context_t<laddr_t>) const = 0;
  std::optional<child_pos_t> child_pos = std::nullopt;
};

std::ostream &operator<<(std::ostream &out, const LBAMapping &rhs);
using lba_pin_list_t = std::list<LBAMappingRef>;

std::ostream &operator<<(std::ostream &out, const lba_pin_list_t &rhs);

} // namespace crimson::os::seastore

#if FMT_VERSION >= 90000
template <> struct fmt::formatter<crimson::os::seastore::LBAMapping> : fmt::ostream_formatter {};
template <> struct fmt::formatter<crimson::os::seastore::lba_pin_list_t> : fmt::ostream_formatter {};
#endif