Skip to content

Commit 07b7407

Browse files
committed
crimson/os/seastore/onode: add the "need_cow" field to indicate whether
the onode's object data space needs to do clone before modification At present, it's only when the onode's object data space is sharing its own direct lba mappings with other onodes that the "need_cow" field would be true. Signed-off-by: Xuehan Xu <[email protected]>
1 parent f42d7db commit 07b7407

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed

src/crimson/os/seastore/onode.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ struct onode_layout_t {
4040

4141
char oi[MAX_OI_LENGTH] = {0};
4242
char ss[MAX_SS_LENGTH] = {0};
43+
/**
44+
* needs_cow
45+
*
46+
* If true, all lba mappings for onode must be cloned
47+
* to a new range prior to mutation. See ObjectDataHandler::copy_on_write,
48+
* do_clone, do_clonerange
49+
*/
50+
bool need_cow = false;
4351

4452
onode_layout_t() : omap_root(omap_type_t::OMAP), log_root(omap_type_t::LOG),
4553
xattr_root(omap_type_t::XATTR) {}
@@ -94,6 +102,8 @@ class Onode : public boost::intrusive_ref_counter<
94102
virtual void update_snapset(Transaction&, ceph::bufferlist&) = 0;
95103
virtual void clear_object_info(Transaction&) = 0;
96104
virtual void clear_snapset(Transaction&) = 0;
105+
virtual void set_need_cow(Transaction&) = 0;
106+
virtual void unset_need_cow(Transaction&) = 0;
97107

98108
laddr_t get_metadata_hint(uint64_t block_size) const {
99109
assert(default_metadata_offset);

src/crimson/os/seastore/onode_manager/staged-fltree/fltree_onode_manager.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ void FLTreeOnode::Recorder::apply_value_delta(
2020
ceph::decode(op, bliter);
2121
auto &mlayout = *reinterpret_cast<onode_layout_t*>(value.get_write());
2222
switch (op) {
23+
case delta_op_t::UNSET_NEED_COW:
24+
DEBUG("setting need_cow");
25+
bliter.copy(
26+
sizeof(mlayout.need_cow),
27+
(char *)&mlayout.need_cow);
28+
break;
29+
case delta_op_t::SET_NEED_COW:
30+
DEBUG("setting need_cow");
31+
bliter.copy(
32+
sizeof(mlayout.need_cow),
33+
(char *)&mlayout.need_cow);
34+
break;
2335
case delta_op_t::UPDATE_ONODE_SIZE:
2436
DEBUG("update onode size");
2537
bliter.copy(sizeof(mlayout.size), (char *)&mlayout.size);
@@ -80,6 +92,18 @@ void FLTreeOnode::Recorder::encode_update(
8092
auto &encoded = get_encoded(payload_mut);
8193
ceph::encode(op, encoded);
8294
switch(op) {
95+
case delta_op_t::UNSET_NEED_COW:
96+
DEBUG("setting need_cow");
97+
encoded.append(
98+
(const char *)&layout.need_cow,
99+
sizeof(layout.need_cow));
100+
break;
101+
case delta_op_t::SET_NEED_COW:
102+
DEBUG("setting need_cow");
103+
encoded.append(
104+
(const char *)&layout.need_cow,
105+
sizeof(layout.need_cow));
106+
break;
83107
case delta_op_t::UPDATE_ONODE_SIZE:
84108
DEBUG("update onode size");
85109
encoded.append(

src/crimson/os/seastore/onode_manager/staged-fltree/fltree_onode_manager.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ struct FLTreeOnode final : Onode, Value {
5656
UPDATE_SNAPSET,
5757
CLEAR_OBJECT_INFO,
5858
CLEAR_SNAPSET,
59-
CREATE_DEFAULT
59+
CREATE_DEFAULT,
60+
SET_NEED_COW,
61+
UNSET_NEED_COW
6062
};
6163
Recorder(bufferlist &bl) : ValueDeltaRecorder(bl) {}
6264

@@ -105,6 +107,34 @@ struct FLTreeOnode final : Onode, Value {
105107
});
106108
}
107109

110+
void set_need_cow(Transaction &t) final {
111+
with_mutable_layout(
112+
t,
113+
[](NodeExtentMutable &payload_mut, Recorder *recorder) {
114+
auto &mlayout = *reinterpret_cast<onode_layout_t*>(
115+
payload_mut.get_write());
116+
mlayout.need_cow = true;
117+
if (recorder) {
118+
recorder->encode_update(
119+
payload_mut, Recorder::delta_op_t::SET_NEED_COW);
120+
}
121+
});
122+
}
123+
124+
void unset_need_cow(Transaction &t) final {
125+
with_mutable_layout(
126+
t,
127+
[](NodeExtentMutable &payload_mut, Recorder *recorder) {
128+
auto &mlayout = *reinterpret_cast<onode_layout_t*>(
129+
payload_mut.get_write());
130+
mlayout.need_cow = false;
131+
if (recorder) {
132+
recorder->encode_update(
133+
payload_mut, Recorder::delta_op_t::UNSET_NEED_COW);
134+
}
135+
});
136+
}
137+
108138
void update_onode_size(Transaction &t, uint32_t size) final {
109139
with_mutable_layout(
110140
t,

src/test/crimson/seastore/test_object_data_handler.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ class TestOnode final : public Onode {
3939
laddr_t get_hint() const final {return L_ADDR_MIN; }
4040
~TestOnode() final = default;
4141

42+
void set_need_cow(Transaction &t) final {
43+
with_mutable_layout(t, [](onode_layout_t &mlayout) {
44+
mlayout.need_cow = true;
45+
});
46+
}
47+
48+
void unset_need_cow(Transaction &t) final {
49+
with_mutable_layout(t, [](onode_layout_t &mlayout) {
50+
mlayout.need_cow = false;
51+
});
52+
}
53+
4254
void update_onode_size(Transaction &t, uint32_t size) final {
4355
with_mutable_layout(t, [size](onode_layout_t &mlayout) {
4456
mlayout.size = size;

0 commit comments

Comments
 (0)