From d8f8f4ce119ed6bd449689eb3142ea4ddca29afd Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 1 Feb 2020 11:42:19 -0600 Subject: [PATCH] os/bluestore/BlueFS: align bluefs' owned extents to alloc_size If bluefs is allocated an extent, adjust it to align it to the allocator's granularity before adding it. Note that the BitmapAllocator actuall does this in init_*_alloc(), but doing it here in the caller fixes the allocation check that follows. Fixes: https://tracker.ceph.com/issues/43904 Signed-off-by: Sage Weil --- src/os/bluestore/BlueFS.cc | 35 +++++++++++++++++++++++++++++++---- src/os/bluestore/BlueFS.h | 2 ++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index 7664b713260..56663666221 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -832,6 +832,29 @@ int BlueFS::_check_new_allocations(const bluefs_fnode_t& fnode, return 0; } +int BlueFS::_adjust_granularity( + __u8 id, uint64_t *offset, uint64_t *length, const char *op) +{ + auto oldo = *offset; + auto oldl = *length; + if (*offset & (alloc_size[id] - 1)) { + *offset &= ~(alloc_size[id] - 1); + *offset += alloc_size[id]; + if (*length > *offset - oldo) { + *length -= (*offset - oldo); + } else { + *length = 0; + } + } + *length &= ~(alloc_size[id] - 1); + if (oldo != *offset || oldl != *length) { + derr << __func__ << " " << op << " " + << (int)id << ":" << std::hex << oldo << "~" << oldl + << " -> " << (int)id << ":" << *offset << "~" << *length << dendl; + } + return 0; +} + int BlueFS::_replay(bool noop, bool to_stdout) { dout(10) << __func__ << (noop ? " NO-OP" : "") << dendl; @@ -1051,10 +1074,12 @@ int BlueFS::_replay(bool noop, bool to_stdout) << ":0x" << std::hex << offset << "~" << length << std::dec << std::endl; } - if (!noop) { block_all[id].insert(offset, length); - alloc[id]->init_add_free(offset, length); + _adjust_granularity(id, &offset, &length, "op_alloc_add"); + if (length) { + alloc[id]->init_add_free(offset, length); + } if (cct->_conf->bluefs_log_replay_check_allocations) { bool fail = false; @@ -1108,10 +1133,12 @@ int BlueFS::_replay(bool noop, bool to_stdout) << ":0x" << std::hex << offset << "~" << length << std::dec << std::endl; } - if (!noop) { block_all[id].erase(offset, length); - alloc[id]->init_rm_free(offset, length); + _adjust_granularity(id, &offset, &length, "op_alloc_rm"); + if (length) { + alloc[id]->init_rm_free(offset, length); + } if (cct->_conf->bluefs_log_replay_check_allocations) { bool fail = false; apply_for_bitset_range(offset, length, alloc_size[id], owned_blocks[id], diff --git a/src/os/bluestore/BlueFS.h b/src/os/bluestore/BlueFS.h index 0a597aea1eb..733bc55e3ff 100644 --- a/src/os/bluestore/BlueFS.h +++ b/src/os/bluestore/BlueFS.h @@ -412,6 +412,8 @@ private: size_t dev_count, boost::dynamic_bitset* owned_blocks, boost::dynamic_bitset* used_blocks); + int _adjust_granularity( + __u8 id, uint64_t *offset, uint64_t *length, const char *op); int _replay(bool noop, bool to_stdout = false); ///< replay journal FileWriter *_create_writer(FileRef f); -- 2.39.5