summaryrefslogtreecommitdiffstats
path: root/src/crimson/os/seastore/extentmap_manager.h
blob: 7d5223b9481f4ab3dc53b6ef314eb999e55d3fb8 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#pragma once

#include <iosfwd>
#include <list>

#include <boost/intrusive_ptr.hpp>
#include <boost/smart_ptr/intrusive_ref_counter.hpp>

#include <seastar/core/future.hh>

#include "crimson/osd/exceptions.h"
#include "crimson/os/seastore/seastore_types.h"
#include "crimson/os/seastore/transaction_manager.h"

#define PAGE_SIZE 4096
#define EXTMAP_BLOCK_SIZE 4096

namespace crimson::os::seastore {

struct lext_map_val_t {
  laddr_t laddr;
  extent_len_t length = 0;

  lext_map_val_t(
    laddr_t laddr,
    extent_len_t length)
    : laddr(laddr), length(length) {}

};

class extent_mapping_t
{
public:
  objaddr_t logical_offset = 0;  //offset in object
  laddr_t laddr;     // lextent start address aligned with block size.
  extent_len_t length = 0;
  explicit extent_mapping_t(objaddr_t lo) : logical_offset(lo) { }

  extent_mapping_t(
    objaddr_t lo,
    laddr_t laddr,
    extent_len_t length)
    : logical_offset(lo), laddr(laddr), length(length) {}

  ~extent_mapping_t() {}
};

enum class extmap_root_state_t : uint8_t {
  INITIAL = 0,
  MUTATED = 1,
  NONE = 0xFF
};

using extent_map_list_t = std::list<extent_mapping_t>;
std::ostream &operator<<(std::ostream &out, const extent_mapping_t &rhs);
std::ostream &operator<<(std::ostream &out, const extent_map_list_t &rhs);

struct extmap_root_t {
  depth_t depth = 0;
  extmap_root_state_t state;
  laddr_t extmap_root_laddr;
  extmap_root_t(depth_t dep, laddr_t laddr)
  : depth(dep),
    extmap_root_laddr(laddr) { state = extmap_root_state_t::INITIAL; }
};

/**
 * Abstract interface for managing the object inner offset to logical addr mapping
 * each onode has an extentmap tree for a particular onode.
 */
class ExtentMapManager {
public:
  using initialize_extmap_ertr = TransactionManager::alloc_extent_ertr;
  using initialize_extmap_ret = initialize_extmap_ertr::future<extmap_root_t>;
  virtual initialize_extmap_ret initialize_extmap(Transaction &t) = 0;

  /* find_lextents
   *
   * Return a list of all extent_mapping_t overlapping any portion of lo~len.
   * or if not find any overlap extent_mapping_t will return the next extent after the range.
   */
  using find_lextent_ertr = TransactionManager::read_extent_ertr;
  using find_lextent_ret = find_lextent_ertr::future<extent_map_list_t>;
  virtual find_lextent_ret
    find_lextent(const extmap_root_t &extmap_root, Transaction &t, objaddr_t lo, extent_len_t len) = 0;

  /* add_lextent
   *
   * add a new mapping (object offset -> laddr, length) to extent map
   * return the added extent_mapping_t
   */
  using add_lextent_ertr = TransactionManager::read_extent_ertr;
  using add_lextent_ret = add_lextent_ertr::future<extent_mapping_t>;
  virtual add_lextent_ret
    add_lextent(extmap_root_t &extmap_root, Transaction &t, objaddr_t lo, lext_map_val_t val) = 0;

  /* rm_lextent
   *
   * remove an existing extent mapping from extent map
   * return true if the extent mapping is removed, otherwise return false
   */
  using rm_lextent_ertr = TransactionManager::read_extent_ertr;
  using rm_lextent_ret = rm_lextent_ertr::future<bool>;
  virtual rm_lextent_ret rm_lextent(extmap_root_t &extmap_root, Transaction &t, objaddr_t lo, lext_map_val_t val) = 0;

  virtual ~ExtentMapManager() {}
};
using ExtentMapManagerRef = std::unique_ptr<ExtentMapManager>;

namespace extentmap_manager {
/* creat ExtentMapManager for an extentmap
 * if it is a new extmap after create_extentmap_manager need call initialize_extmap
 * to initialize the extent map before use it
 * if it is an exsiting extmap, needn't initialize_extmap
 */
ExtentMapManagerRef create_extentmap_manager(
  TransactionManager &trans_manager);

}

}