From 0532ae8e39eb0b4f6cd416cffbc8941d6a2ca43c Mon Sep 17 00:00:00 2001 From: Yuan Lu Date: Sun, 26 Apr 2020 15:28:32 +0800 Subject: [PATCH] librbd: add DiscardLogEntry Signed-off-by: Peterson, Scott Signed-off-by: Li, Xiaoyan Signed-off-by: Lu, Yuan Signed-off-by: Chamarthy, Mahati --- src/librbd/cache/rwl/LogEntry.cc | 31 ++++++++++++++++++++- src/librbd/cache/rwl/LogEntry.h | 46 ++++++++++++++++++++++++++++---- 2 files changed, 71 insertions(+), 6 deletions(-) diff --git a/src/librbd/cache/rwl/LogEntry.cc b/src/librbd/cache/rwl/LogEntry.cc index 9f72df7d77e62..9434b7d65716e 100644 --- a/src/librbd/cache/rwl/LogEntry.cc +++ b/src/librbd/cache/rwl/LogEntry.cc @@ -47,7 +47,7 @@ std::ostream &operator<<(std::ostream &os, return entry.format(os); } -bool GenericWriteLogEntry::can_writeback() { +bool GenericWriteLogEntry::can_writeback() const { return (this->completed && (ram_entry.sequenced || (sync_point_entry && @@ -163,6 +163,35 @@ std::ostream &operator<<(std::ostream &os, return entry.format(os); } +void DiscardLogEntry::writeback(librbd::cache::ImageWritebackInterface &image_writeback, + Context *ctx) { + image_writeback.aio_discard(ram_entry.image_offset_bytes, ram_entry.write_bytes, + m_discard_granularity_bytes, ctx); +} + +void DiscardLogEntry::init(uint64_t current_sync_gen, bool persist_on_flush, uint64_t last_op_sequence_num) { + ram_entry.sync_gen_number = current_sync_gen; + if (persist_on_flush) { + /* Persist on flush. Sequence #0 is never used. */ + ram_entry.write_sequence_number = 0; + } else { + /* Persist on write */ + ram_entry.write_sequence_number = last_op_sequence_num; + ram_entry.sequenced = 1; + } +} + +std::ostream &DiscardLogEntry::format(std::ostream &os) const { + os << "(Discard) "; + GenericWriteLogEntry::format(os); + return os; +}; + +std::ostream &operator<<(std::ostream &os, + const DiscardLogEntry &entry) { + return entry.format(os); +} + } // namespace rwl } // namespace cache } // namespace librbd diff --git a/src/librbd/cache/rwl/LogEntry.h b/src/librbd/cache/rwl/LogEntry.h index 9e5d3c53403df..d4945679120b6 100644 --- a/src/librbd/cache/rwl/LogEntry.h +++ b/src/librbd/cache/rwl/LogEntry.h @@ -33,10 +33,10 @@ public: virtual ~GenericLogEntry() { }; GenericLogEntry(const GenericLogEntry&) = delete; GenericLogEntry &operator=(const GenericLogEntry&) = delete; - virtual bool can_writeback() { + virtual bool can_writeback() const { return false; } - virtual inline unsigned int bytes_dirty() { + virtual unsigned int bytes_dirty() const { return 0; }; virtual std::shared_ptr get_sync_point_entry() { @@ -88,11 +88,11 @@ public: ~GenericWriteLogEntry() override {}; GenericWriteLogEntry(const GenericWriteLogEntry&) = delete; GenericWriteLogEntry &operator=(const GenericWriteLogEntry&) = delete; - inline unsigned int write_bytes() { + virtual unsigned int write_bytes() const { /* The valid bytes in this ops data buffer. Discard and WS override. */ return ram_entry.write_bytes; }; - inline unsigned int bytes_dirty() override { + unsigned int bytes_dirty() const override { /* The bytes in the image this op makes dirty. Discard and WS override. */ return write_bytes(); }; @@ -104,7 +104,7 @@ public: } void inc_map_ref() { referring_map_entries++; } void dec_map_ref() { referring_map_entries--; } - bool can_writeback() override; + bool can_writeback() const override; std::shared_ptr get_sync_point_entry() override { return sync_point_entry; } @@ -162,6 +162,42 @@ public: const WriteLogEntry &entry); }; +class DiscardLogEntry : public GenericWriteLogEntry { +public: + DiscardLogEntry(std::shared_ptr sync_point_entry, + const uint64_t image_offset_bytes, const uint64_t write_bytes, + uint32_t discard_granularity_bytes) + : GenericWriteLogEntry(sync_point_entry, image_offset_bytes, write_bytes), + m_discard_granularity_bytes(discard_granularity_bytes) { + ram_entry.discard = 1; + }; + DiscardLogEntry(const uint64_t image_offset_bytes, const uint64_t write_bytes) + : GenericWriteLogEntry(nullptr, image_offset_bytes, write_bytes) { + ram_entry.discard = 1; + }; + DiscardLogEntry(const DiscardLogEntry&) = delete; + DiscardLogEntry &operator=(const DiscardLogEntry&) = delete; + unsigned int write_bytes() const override { + /* The valid bytes in this ops data buffer. */ + return 0; + }; + unsigned int bytes_dirty() const override { + /* The bytes in the image this op makes dirty. */ + return ram_entry.write_bytes; + }; + void copy_pmem_bl(bufferlist *out_bl) override { + ceph_assert(false); + } + void writeback(librbd::cache::ImageWritebackInterface &image_writeback, + Context *ctx) override; + void init(uint64_t current_sync_gen, bool persist_on_flush, uint64_t last_op_sequence_num); + std::ostream &format(std::ostream &os) const; + friend std::ostream &operator<<(std::ostream &os, + const DiscardLogEntry &entry); +private: + uint32_t m_discard_granularity_bytes; +}; + } // namespace rwl } // namespace cache } // namespace librbd -- 2.39.5