]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd/cache/pwl/ssd: Fix a race between get_cache_bl() and remove_cache_bl()
authorJianpeng Ma <jianpeng.ma@intel.com>
Tue, 7 Sep 2021 02:00:53 +0000 (10:00 +0800)
committerDeepika Upadhyay <dupadhya@redhat.com>
Fri, 5 Nov 2021 09:22:02 +0000 (14:52 +0530)
In fact, although in get_cache_bl it use lock to protect, it can't
protect function "list& operator= (const list& other)".
So we should use copy_cache_bl.

Fixes: https://tracker.ceph.com/issues/52400
Signed-off-by: Jianpeng Ma <jianpeng.ma@intel.com>
(cherry picked from commit fe72b3953735329441397f257d5dd18f6819187d)

src/librbd/cache/pwl/LogEntry.h
src/librbd/cache/pwl/ssd/LogEntry.cc
src/librbd/cache/pwl/ssd/LogEntry.h
src/librbd/cache/pwl/ssd/WriteLog.cc

index b0d27b5aefacc7f506cf08cbe43145d4dd79db37..766b5500767f616c2d9ca85a6fb119b8d672a3b1 100644 (file)
@@ -219,7 +219,6 @@ public:
   BlockExtent block_extent();
   virtual unsigned int reader_count() const = 0;
   /* Constructs a new bl containing copies of cache_bp */
-  void copy_cache_bl(bufferlist *out_bl) override {};
   bool can_retire() const override {
     return (this->completed && this->get_flushed() && (0 == reader_count()));
   }
index 71f77f55031795c1141783045d85f6bcc1e7901d..0e6edd87b35c6877fa58525d87f836967f30acb6 100644 (file)
@@ -24,6 +24,11 @@ buffer::list& WriteLogEntry::get_cache_bl() {
   return cache_bl;
 }
 
+void  WriteLogEntry::copy_cache_bl(bufferlist *out) {
+  std::lock_guard locker(m_entry_bl_lock);
+  *out = cache_bl;
+}
+
 void WriteLogEntry::remove_cache_bl() {
     std::lock_guard locker(m_entry_bl_lock);
     cache_bl.clear();
index 86121473b82edb07225a9f71c87880bc8db4c3f9..8e26f661ff8caa6b81e7cea898eaa52100480ec5 100644 (file)
@@ -38,6 +38,7 @@ public:
                  Context *ctx, ceph::bufferlist &&bl) override;
   void init_cache_bl(bufferlist &src_bl, uint64_t off, uint64_t len) override;
   buffer::list &get_cache_bl() override;
+  void copy_cache_bl(bufferlist *out) override;
   void remove_cache_bl() override;
   unsigned int get_aligned_data_size() const override;
   void inc_bl_refs() { bl_refs++; };
index 7e7fc42e865650f2de950fb847dc05d459d983e8..e0d9a13199abd8ffe972242445c903075c14c3a1 100644 (file)
@@ -85,7 +85,7 @@ void WriteLog<I>::collect_read_extents(
   ldout(m_image_ctx.cct, 5) << dendl;
   auto write_entry = static_pointer_cast<WriteLogEntry>(map_entry.log_entry);
   buffer::list hit_bl;
-  hit_bl = write_entry->get_cache_bl();
+  write_entry->copy_cache_bl(&hit_bl);
   bool writesame = write_entry->is_writesame_entry();
   auto hit_extent_buf = std::make_shared<ImageExtentBuf>(
       hit_extent, hit_bl, true, read_buffer_offset, writesame);