Skip to content

Commit 1ee35a7

Browse files
zhscnMatan-B
authored andcommitted
crimson/os/seastore/BtreeLBAManager: cleanup the impl of alloc mapping and remap
Signed-off-by: Zhang Song <[email protected]> (cherry picked from commit d143fa7)
1 parent 66f29b7 commit 1ee35a7

File tree

4 files changed

+174
-203
lines changed

4 files changed

+174
-203
lines changed

src/crimson/os/seastore/lba_manager.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class LBAManager {
4545
* lba value.
4646
*/
4747
using get_mappings_iertr = base_iertr;
48-
using get_mappings_ret = get_mappings_iertr::future<lba_pin_list_t>;
48+
using get_mappings_ret = get_mappings_iertr::future<lba_mapping_list_t>;
4949
virtual get_mappings_ret get_mappings(
5050
Transaction &t,
5151
laddr_t offset, extent_len_t length) = 0;
@@ -59,7 +59,7 @@ class LBAManager {
5959
*/
6060
using get_mapping_iertr = base_iertr::extend<
6161
crimson::ct_error::enoent>;
62-
using get_mapping_ret = get_mapping_iertr::future<LBAMappingRef>;
62+
using get_mapping_ret = get_mapping_iertr::future<LBAMapping>;
6363
virtual get_mapping_ret get_mapping(
6464
Transaction &t,
6565
laddr_t offset) = 0;
@@ -72,15 +72,15 @@ class LBAManager {
7272
* is called on the LBAMapping.
7373
*/
7474
using alloc_extent_iertr = base_iertr;
75-
using alloc_extent_ret = alloc_extent_iertr::future<LBAMappingRef>;
75+
using alloc_extent_ret = alloc_extent_iertr::future<LBAMapping>;
7676
virtual alloc_extent_ret alloc_extent(
7777
Transaction &t,
7878
laddr_t hint,
7979
LogicalChildNode &nextent,
8080
extent_ref_count_t refcount) = 0;
8181

8282
using alloc_extents_ret = alloc_extent_iertr::future<
83-
std::vector<LBAMappingRef>>;
83+
std::vector<LBAMapping>>;
8484
virtual alloc_extents_ret alloc_extents(
8585
Transaction &t,
8686
laddr_t hint,
@@ -126,12 +126,8 @@ class LBAManager {
126126
len = _len;
127127
}
128128
};
129-
struct lba_remap_ret_t {
130-
ref_update_result_t ruret;
131-
std::vector<LBAMappingRef> remapped_mappings;
132-
};
133129
using remap_iertr = ref_iertr;
134-
using remap_ret = remap_iertr::future<lba_remap_ret_t>;
130+
using remap_ret = remap_iertr::future<std::vector<LBAMapping>>;
135131

136132
/**
137133
* remap_mappings
@@ -141,7 +137,7 @@ class LBAManager {
141137
*/
142138
virtual remap_ret remap_mappings(
143139
Transaction &t,
144-
LBAMappingRef orig_mapping,
140+
LBAMapping orig_mapping,
145141
std::vector<remap_entry_t> remaps,
146142
std::vector<LogicalChildNodeRef> extents // Required if and only
147143
// if pin isn't indirect

src/crimson/os/seastore/lba_manager/btree/btree_lba_manager.cc

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,106 @@ BtreeLBAManager::_decref_intermediate(
788788
});
789789
}
790790

791+
BtreeLBAManager::remap_ret
792+
BtreeLBAManager::remap_mappings(
793+
Transaction &t,
794+
LBAMapping orig_mapping,
795+
std::vector<remap_entry_t> remaps,
796+
std::vector<LogicalChildNodeRef> extents)
797+
{
798+
LOG_PREFIX(BtreeLBAManager::remap_mappings);
799+
struct state_t {
800+
LBAMapping orig_mapping;
801+
std::vector<remap_entry_t> remaps;
802+
std::vector<LogicalChildNodeRef> extents;
803+
std::vector<alloc_mapping_info_t> alloc_infos;
804+
std::vector<LBAMapping> ret;
805+
};
806+
return seastar::do_with(
807+
state_t(std::move(orig_mapping), std::move(remaps), std::move(extents), {}, {}),
808+
[this, &t, FNAME](state_t &state)
809+
{
810+
return update_refcount(
811+
t, state.orig_mapping.get_key(), -1, false
812+
).si_then([this, &t, &state, FNAME](auto ret) {
813+
// Remapping the shared direct mapping is prohibited,
814+
// the refcount of indirect mapping should always be 1.
815+
ceph_assert(ret.is_removed_mapping());
816+
817+
auto orig_laddr = state.orig_mapping.get_key();
818+
if (!state.orig_mapping.is_indirect()) {
819+
auto &addr = ret.get_removed_mapping().map_value.pladdr;
820+
ceph_assert(addr.is_paddr() && !addr.get_paddr().is_zero());
821+
return alloc_extents(
822+
t,
823+
(state.remaps.front().offset + orig_laddr).checked_to_laddr(),
824+
std::move(state.extents),
825+
EXTENT_DEFAULT_REF_COUNT
826+
).si_then([&state](auto ret) {
827+
state.ret = std::move(ret);
828+
return remap_iertr::make_ready_future();
829+
});
830+
}
831+
832+
extent_len_t orig_len = state.orig_mapping.get_length();
833+
auto intermediate_key = state.orig_mapping.get_intermediate_key();
834+
ceph_assert(intermediate_key != L_ADDR_NULL);
835+
DEBUGT("remap indirect mapping {}", t, state.orig_mapping);
836+
for (auto &remap : state.remaps) {
837+
DEBUGT("remap 0x{:x}~0x{:x}", t, remap.offset, remap.len);
838+
ceph_assert(remap.len != 0);
839+
ceph_assert(remap.offset + remap.len <= orig_len);
840+
auto remapped_laddr = (orig_laddr + remap.offset)
841+
.checked_to_laddr();
842+
auto remapped_intermediate_key = (intermediate_key + remap.offset)
843+
.checked_to_laddr();
844+
state.alloc_infos.emplace_back(
845+
alloc_mapping_info_t::create_indirect(
846+
remapped_laddr, remap.len, remapped_intermediate_key));
847+
}
848+
849+
return alloc_sparse_mappings(
850+
t, state.alloc_infos.front().key, state.alloc_infos,
851+
alloc_policy_t::deterministic
852+
).si_then([&t, &state, this](std::list<LBACursorRef> cursors) {
853+
return seastar::futurize_invoke([&t, &state, this] {
854+
if (state.remaps.size() > 1) {
855+
auto base = state.orig_mapping.get_intermediate_base();
856+
return update_refcount(
857+
t, base, state.remaps.size() - 1, false
858+
).si_then([](update_mapping_ret_bare_t ret) {
859+
return ret.take_cursor();
860+
});
861+
} else {
862+
return remap_iertr::make_ready_future<
863+
LBACursorRef>(state.orig_mapping.direct_cursor->duplicate());
864+
}
865+
}).si_then([&state, cursors=std::move(cursors)](auto direct) mutable {
866+
for (auto &cursor : cursors) {
867+
state.ret.emplace_back(LBAMapping::create_indirect(
868+
direct->duplicate(), std::move(cursor)));
869+
}
870+
return remap_iertr::make_ready_future();
871+
});
872+
});
873+
}).si_then([&state] {
874+
assert(state.ret.size() == state.remaps.size());
875+
#ifndef NDEBUG
876+
auto mapping_it = state.ret.begin();
877+
auto remap_it = state.remaps.begin();
878+
for (;mapping_it != state.ret.end(); mapping_it++, remap_it++) {
879+
auto &mapping = *mapping_it;
880+
auto &remap = *remap_it;
881+
assert(mapping.get_key() == state.orig_mapping.get_key() + remap.offset);
882+
assert(mapping.get_length() == remap.len);
883+
}
884+
#endif
885+
return remap_iertr::make_ready_future<
886+
std::vector<LBAMapping>>(std::move(state.ret));
887+
});
888+
});
889+
}
890+
791891
BtreeLBAManager::update_refcount_ret
792892
BtreeLBAManager::update_refcount(
793893
Transaction &t,

0 commit comments

Comments
 (0)