From e2764ffe34ea1d68c7a283a3d93649d72c6807a2 Mon Sep 17 00:00:00 2001 From: Yuan Lu Date: Thu, 23 Apr 2020 13:59:51 +0800 Subject: [PATCH] librbd: add WriteSameLogEntry 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 | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/src/librbd/cache/rwl/LogEntry.cc b/src/librbd/cache/rwl/LogEntry.cc index 9434b7d6571..76e1dad6b46 100644 --- a/src/librbd/cache/rwl/LogEntry.cc +++ b/src/librbd/cache/rwl/LogEntry.cc @@ -192,6 +192,37 @@ std::ostream &operator<<(std::ostream &os, return entry.format(os); } +void WriteSameLogEntry::init_bl(buffer::ptr &bp, buffer::list &bl) { + for (uint64_t i = 0; i < ram_entry.write_bytes / ram_entry.ws_datalen; i++) { + bl.append(bp); + } + int trailing_partial = ram_entry.write_bytes % ram_entry.ws_datalen; + if (trailing_partial) { + bl.append(bp, 0, trailing_partial); + } +}; + +void WriteSameLogEntry::writeback(librbd::cache::ImageWritebackInterface &image_writeback, + Context *ctx) { + bufferlist entry_bl; + buffer::list entry_bl_copy; + copy_pmem_bl(&entry_bl_copy); + entry_bl_copy.begin(0).copy(write_bytes(), entry_bl); + image_writeback.aio_writesame(ram_entry.image_offset_bytes, ram_entry.write_bytes, + std::move(entry_bl), 0, ctx); +} + +std::ostream &WriteSameLogEntry::format(std::ostream &os) const { + os << "(WriteSame) "; + WriteLogEntry::format(os); + return os; +}; + +std::ostream &operator<<(std::ostream &os, + const WriteSameLogEntry &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 d4945679120..36fbf74f0ce 100644 --- a/src/librbd/cache/rwl/LogEntry.h +++ b/src/librbd/cache/rwl/LogEntry.h @@ -198,6 +198,41 @@ private: uint32_t m_discard_granularity_bytes; }; +class WriteSameLogEntry : public WriteLogEntry { +protected: + void init_bl(buffer::ptr &bp, buffer::list &bl) override; + +public: + WriteSameLogEntry(std::shared_ptr sync_point_entry, + const uint64_t image_offset_bytes, const uint64_t write_bytes, + const uint32_t data_length) + : WriteLogEntry(sync_point_entry, image_offset_bytes, write_bytes) { + ram_entry.writesame = 1; + ram_entry.ws_datalen = data_length; + }; + WriteSameLogEntry(const uint64_t image_offset_bytes, const uint64_t write_bytes, + const uint32_t data_length) + : WriteLogEntry(nullptr, image_offset_bytes, write_bytes) { + ram_entry.writesame = 1; + ram_entry.ws_datalen = data_length; + }; + WriteSameLogEntry(const WriteSameLogEntry&) = delete; + WriteSameLogEntry &operator=(const WriteSameLogEntry&) = delete; + unsigned int write_bytes() const override { + /* The valid bytes in this ops data buffer. */ + return ram_entry.ws_datalen; + }; + unsigned int bytes_dirty() const override { + /* The bytes in the image this op makes dirty. */ + return ram_entry.write_bytes; + }; + void writeback(librbd::cache::ImageWritebackInterface &image_writeback, + Context *ctx) override; + std::ostream &format(std::ostream &os) const; + friend std::ostream &operator<<(std::ostream &os, + const WriteSameLogEntry &entry); +}; + } // namespace rwl } // namespace cache } // namespace librbd -- 2.39.5