]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: make Allocator::device_size atomic and protect BitmapAllocator::expand
authorJoshua Blanch <joshua.blanch@clyso.com>
Tue, 3 Mar 2026 05:44:00 +0000 (05:44 +0000)
committerJoshua Blanch <joshua.blanch@clyso.com>
Thu, 23 Apr 2026 15:05:55 +0000 (15:05 +0000)
Signed-off-by: Joshua Blanch <joshua.blanch@clyso.com>
src/os/bluestore/Allocator.h
src/os/bluestore/BitmapAllocator.cc
src/os/bluestore/BitmapAllocator.h

index df56376433070ef22d3119a78355ef131e7d9fb1..000c7471ef883dd02e5e816a6a467ba50fd4a164 100644 (file)
@@ -13,6 +13,7 @@
 #ifndef CEPH_OS_BLUESTORE_ALLOCATOR_H
 #define CEPH_OS_BLUESTORE_ALLOCATOR_H
 
+#include <atomic>
 #include <functional>
 #include <ostream>
 #include "include/ceph_assert.h"
@@ -84,19 +85,19 @@ public:
   virtual const std::string& get_name() const = 0;
   int64_t get_capacity() const
   {
-    return device_size;
+    return device_size.load();
   }
   int64_t get_block_size() const
   {
     return block_size;
   }
   virtual void expand(int64_t new_size){
-    ceph_assert(new_size >= device_size);
-    device_size = new_size;
+    ceph_assert(new_size >= device_size.load());
+    device_size.store(new_size);
   }
 
 protected:
-  int64_t device_size = 0;
+  std::atomic<int64_t> device_size{0};
   const int64_t block_size = 0;
 };
 
index 8c59c2b1dd0b4c965674117f29d452e8c328c64a..09cc78f2eeddfa548a3aba26043ea7dfaae6e6f7 100644 (file)
@@ -57,7 +57,7 @@ void BitmapAllocator::release(
     for (auto& [offset, len] : release_set) {
       ldout(cct, 10) << __func__ << " 0x" << std::hex << offset << "~" << len
                      << std::dec << dendl;
-      ceph_assert(offset + len <= (uint64_t)device_size);
+      ceph_assert(offset + len <= (uint64_t)device_size.load());
     }
   }
   _free_l2(release_set);
@@ -73,7 +73,7 @@ void BitmapAllocator::init_add_free(uint64_t offset, uint64_t length)
   auto mas = get_min_alloc_size();
   uint64_t offs = round_up_to(offset, mas);
   uint64_t l = p2align(offset + length - offs, mas);
-  ceph_assert(offs + l <= (uint64_t)device_size);
+  ceph_assert(offs + l <= (uint64_t)device_size.load());
 
   _mark_free(offs, l);
   ldout(cct, 10) << __func__ << " done" << dendl;
@@ -85,13 +85,14 @@ void BitmapAllocator::init_rm_free(uint64_t offset, uint64_t length)
   auto mas = get_min_alloc_size();
   uint64_t offs = round_up_to(offset, mas);
   uint64_t l = p2align(offset + length - offs, mas);
-  ceph_assert(offs + l <= (uint64_t)device_size);
+  ceph_assert(offs + l <= (uint64_t)device_size.load());
   _mark_allocated(offs, l);
   ldout(cct, 10) << __func__ << " done" << dendl;
 }
 
 void BitmapAllocator::expand(int64_t new_size)
 {
+  std::lock_guard l(expand_lock);
   int64_t old_size = get_capacity();
   ceph_assert(new_size >= old_size);
 
index 65976eb3c8ad0100697d27ba51ccca7a6eb4d832..3961af228f67def8ddd83baa2159508d3a2b1fdd 100644 (file)
@@ -16,6 +16,7 @@
 class BitmapAllocator : public AllocatorBase,
   public AllocatorLevel02<AllocatorLevel01Loose> {
   CephContext* cct;
+  ceph::mutex expand_lock = ceph::make_mutex("BitmapAllocator::expand_lock");
 public:
   BitmapAllocator(CephContext* _cct, int64_t capacity, int64_t alloc_unit,
                  std::string_view name);