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
125
126
127
128
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#pragma once
#include <iosfwd>
#include <boost/intrusive_ptr.hpp>
#include <boost/smart_ptr/intrusive_ref_counter.hpp>
#include <seastar/core/future.hh>
#include "include/ceph_assert.h"
#include "crimson/os/seastore/seastore_types.h"
#include "include/buffer_fwd.h"
#include "crimson/osd/exceptions.h"
namespace crimson::os::seastore {
class Segment : public boost::intrusive_ref_counter<
Segment,
boost::thread_unsafe_counter>{
public:
enum class segment_state_t : uint8_t {
EMPTY = 0,
OPEN = 1,
CLOSED = 2
};
/**
* get_segment_id
*/
virtual segment_id_t get_segment_id() const = 0;
/**
* min next write location
*/
virtual segment_off_t get_write_ptr() const = 0;
/**
* max capacity
*/
virtual segment_off_t get_write_capacity() const = 0;
/**
* close
*
* Closes segment for writes. Won't complete until
* outstanding writes to this segment are complete.
*/
using close_ertr = crimson::errorator<
crimson::ct_error::input_output_error,
crimson::ct_error::invarg,
crimson::ct_error::enoent>;
virtual close_ertr::future<> close() = 0;
/**
* write
*
* @param offset offset of write, must be aligned to <> and >= write pointer, advances
* write pointer
* @param bl buffer to write, will be padded if not aligned
*/
using write_ertr = crimson::errorator<
crimson::ct_error::input_output_error, // media error or corruption
crimson::ct_error::invarg, // if offset is < write pointer or misaligned
crimson::ct_error::ebadf, // segment closed
crimson::ct_error::enospc // write exceeds segment size
>;
virtual write_ertr::future<> write(
segment_off_t offset, ceph::bufferlist bl) = 0;
virtual ~Segment() {}
};
using SegmentRef = boost::intrusive_ptr<Segment>;
constexpr size_t PADDR_SIZE = sizeof(paddr_t);
class SegmentManager {
public:
using open_ertr = crimson::errorator<
crimson::ct_error::input_output_error,
crimson::ct_error::invarg,
crimson::ct_error::enoent>;
virtual open_ertr::future<SegmentRef> open(segment_id_t id) = 0;
using release_ertr = crimson::errorator<
crimson::ct_error::input_output_error,
crimson::ct_error::invarg,
crimson::ct_error::enoent>;
virtual release_ertr::future<> release(segment_id_t id) = 0;
using read_ertr = crimson::errorator<
crimson::ct_error::input_output_error,
crimson::ct_error::invarg,
crimson::ct_error::enoent,
crimson::ct_error::erange>;
virtual read_ertr::future<> read(
paddr_t addr,
size_t len,
ceph::bufferptr &out) = 0;
read_ertr::future<ceph::bufferptr> read(
paddr_t addr,
size_t len) {
auto ptrref = std::make_unique<ceph::bufferptr>(
buffer::create_page_aligned(len));
return read(addr, len, *ptrref).safe_then(
[ptrref=std::move(ptrref)]() mutable {
return read_ertr::make_ready_future<bufferptr>(std::move(*ptrref));
});
}
/* Methods for discovering device geometry, segmentid set, etc */
virtual size_t get_size() const = 0;
virtual segment_off_t get_block_size() const = 0;
virtual segment_off_t get_segment_size() const = 0;
virtual segment_id_t get_num_segments() const {
ceph_assert(get_size() % get_segment_size() == 0);
return ((segment_id_t)(get_size() / get_segment_size()));
}
virtual const seastore_meta_t &get_meta() const = 0;
virtual ~SegmentManager() {}
};
using SegmentManagerRef = std::unique_ptr<SegmentManager>;
}
|