Skip to content

Commit 77a6edf

Browse files
committed
crimson/os/seastore/lba_manager: allow cloning part of the mapping
Signed-off-by: Xuehan Xu <[email protected]>
1 parent 86107a4 commit 77a6edf

File tree

5 files changed

+39
-22
lines changed

5 files changed

+39
-22
lines changed

src/crimson/os/seastore/lba/btree_lba_manager.cc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -427,17 +427,21 @@ BtreeLBAManager::clone_mapping(
427427
LBAMapping pos,
428428
LBAMapping mapping,
429429
laddr_t laddr,
430+
extent_len_t offset,
431+
extent_len_t len,
430432
bool updateref)
431433
{
432434
LOG_PREFIX(BtreeLBAManager::clone_mapping);
433435
assert(pos.is_viewable());
434436
assert(mapping.is_viewable());
435-
DEBUGT("pos={}, mapping={}, laddr={}, updateref={}",
436-
t, pos, mapping, laddr, updateref);
437+
DEBUGT("pos={}, mapping={}, laddr={}, {}~{} updateref={}",
438+
t, pos, mapping, laddr, offset, len, updateref);
439+
assert(offset + len <= mapping.get_length());
437440
struct state_t {
438441
LBAMapping pos;
439442
LBAMapping mapping;
440443
laddr_t laddr;
444+
extent_len_t offset;
441445
extent_len_t len;
442446
};
443447
auto c = get_context(t);
@@ -464,11 +468,10 @@ BtreeLBAManager::clone_mapping(
464468
return update_refcount_iertr::make_ready_future<
465469
LBAMapping>(std::move(mapping));
466470
}
467-
}).si_then([c, this, pos=std::move(pos),
468-
laddr](auto mapping) mutable {
469-
auto len = mapping.get_length();
471+
}).si_then([c, this, pos=std::move(pos), len,
472+
offset, laddr](auto mapping) mutable {
470473
return seastar::do_with(
471-
state_t{std::move(pos), std::move(mapping), laddr, len},
474+
state_t{std::move(pos), std::move(mapping), laddr, offset, len},
472475
[this, c](auto &state) {
473476
return with_btree<LBABtree>(
474477
cache,
@@ -479,17 +482,15 @@ BtreeLBAManager::clone_mapping(
479482
).si_then([&state, c, &btree]() mutable {
480483
auto &cursor = state.pos.get_effective_cursor();
481484
assert(state.laddr + state.len <= cursor.key);
485+
auto inter_key = state.mapping.is_indirect()
486+
? state.mapping.get_intermediate_key()
487+
: state.mapping.get_key();
488+
inter_key = (inter_key + state.offset).checked_to_laddr();
482489
return btree.insert(
483490
c,
484491
btree.make_partial_iter(c, cursor),
485492
state.laddr,
486-
lba_map_val_t{
487-
state.len,
488-
state.mapping.is_indirect()
489-
? state.mapping.get_intermediate_key()
490-
: state.mapping.get_key(),
491-
EXTENT_DEFAULT_REF_COUNT,
492-
0});
493+
lba_map_val_t{state.len, inter_key, EXTENT_DEFAULT_REF_COUNT, 0});
493494
}).si_then([c, &state](auto p) {
494495
auto &[iter, inserted] = p;
495496
auto &leaf_node = *iter.get_leaf_node();

src/crimson/os/seastore/lba/btree_lba_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ class BtreeLBAManager : public LBAManager {
105105
LBAMapping pos,
106106
LBAMapping mapping,
107107
laddr_t laddr,
108+
extent_len_t offset,
109+
extent_len_t len,
108110
bool updateref) final;
109111

110112
#ifdef UNIT_TESTS_BUILT

src/crimson/os/seastore/lba_manager.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,19 @@ class LBAManager {
117117
using clone_mapping_iertr = alloc_extent_iertr;
118118
using clone_mapping_ret = clone_mapping_iertr::future<clone_mapping_ret_t>;
119119
/*
120-
* Clones "mapping" at the position "pos" with new laddr "laddr", if updateref
121-
* is true, update the refcount of the mapping "mapping"
120+
* Clones (part of) "mapping" at the position "pos" with the new lba key "laddr".
122121
*/
123122
virtual clone_mapping_ret clone_mapping(
124123
Transaction &t,
125-
LBAMapping pos,
126-
LBAMapping mapping,
127-
laddr_t laddr,
128-
bool updateref) = 0;
124+
LBAMapping pos, // the destined position
125+
LBAMapping mapping, // the mapping to be cloned
126+
laddr_t laddr, // the new lba key of the cloned mapping
127+
extent_len_t offset, // the offset of the part to be cloned,
128+
// relative to the start of the mapping.
129+
extent_len_t len, // the length of the part to be cloned
130+
bool updateref // whether to update the refcount of the
131+
// direct mapping
132+
) = 0;
129133

130134
virtual alloc_extent_ret reserve_region(
131135
Transaction &t,

src/crimson/os/seastore/transaction_manager.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,24 +584,29 @@ class TransactionManager : public ExtentCallbackInterface {
584584
LBAMapping pos,
585585
LBAMapping mapping,
586586
laddr_t hint,
587+
extent_len_t offset,
588+
extent_len_t len,
587589
bool updateref) {
588590
LOG_PREFIX(TransactionManager::clone_pin);
589591
SUBDEBUGT(seastore_tm, "{} clone to hint {} ... pos={}, updateref={}",
590592
t, mapping, hint, pos, updateref);
591593
return seastar::do_with(
592594
std::move(pos),
593595
std::move(mapping),
594-
[FNAME, this, &t, hint, updateref](auto &pos, auto &mapping) {
596+
[offset, len, FNAME, this, &t, hint, updateref](auto &pos, auto &mapping) {
595597
return pos.refresh(
596598
).si_then([&pos, &mapping](auto m) {
597599
pos = std::move(m);
598600
return mapping.refresh();
599-
}).si_then([FNAME, this, &pos, &t, hint, updateref](auto mapping) {
601+
}).si_then([offset, len, FNAME, this, &pos,
602+
&t, hint, updateref](auto mapping) {
600603
return lba_manager->clone_mapping(
601604
t,
602605
std::move(pos),
603606
std::move(mapping),
604607
hint,
608+
offset,
609+
len,
605610
updateref
606611
).si_then([FNAME, &t](auto ret) {
607612
SUBDEBUGT(seastore_tm, "cloned as {}", t, ret.cloned_mapping);
@@ -664,9 +669,11 @@ class TransactionManager : public ExtentCallbackInterface {
664669
if (mapping.is_real()) {
665670
ret = true;
666671
}
672+
auto len = mapping.get_length();
667673
return clone_pin(
668674
t, std::move(pos), std::move(mapping),
669-
(base + offset).checked_to_laddr(), updateref
675+
(base + offset).checked_to_laddr(),
676+
0, len, updateref
670677
).si_then([&offset, &pos, &mapping](auto ret) {
671678
offset += ret.cloned_mapping.get_length();
672679
return ret.cloned_mapping.next(

src/test/crimson/seastore/test_transaction_manager.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,14 @@ struct transaction_manager_test_t :
708708
laddr_t offset) {
709709
auto key = mapping.get_key();
710710
auto pin = with_trans_intr(*(t.t), [&](auto &trans) {
711+
auto len = mapping.get_length();
711712
return tm->clone_pin(
712713
trans,
713714
std::move(pos),
714715
std::move(mapping),
715716
offset,
717+
0,
718+
len,
716719
true);
717720
}).unsafe_get().cloned_mapping;
718721
EXPECT_EQ(offset, pin.get_key());

0 commit comments

Comments
 (0)