]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore/BlueFS: align bluefs' owned extents to alloc_size
authorSage Weil <sage@redhat.com>
Sat, 1 Feb 2020 17:42:19 +0000 (11:42 -0600)
committerSage Weil <sage@redhat.com>
Fri, 7 Feb 2020 21:56:10 +0000 (15:56 -0600)
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 <sage@redhat.com>
src/os/bluestore/BlueFS.cc
src/os/bluestore/BlueFS.h

index 7664b713260ea2d4d4e673fb628c328379302667..56663666221e67ff9492a4d4d193757f5e42c414 100644 (file)
@@ -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],
index 0a597aea1eb6d57903832e355a00abed4457d9d9..733bc55e3ff5c6dfea8b172bd4ea6aa82c7700c0 100644 (file)
@@ -412,6 +412,8 @@ private:
     size_t dev_count,
     boost::dynamic_bitset<uint64_t>* owned_blocks,
     boost::dynamic_bitset<uint64_t>* 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);