]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librbd: add WriteSameLogEntry
authorYuan Lu <yuan.y.lu@intel.com>
Thu, 23 Apr 2020 05:59:51 +0000 (13:59 +0800)
committerYuan Lu <yuan.y.lu@intel.com>
Wed, 6 May 2020 05:11:41 +0000 (13:11 +0800)
Signed-off-by: Peterson, Scott <scott.d.peterson@intel.com>
Signed-off-by: Li, Xiaoyan <xiaoyan.li@intel.com>
Signed-off-by: Lu, Yuan <yuan.y.lu@intel.com>
Signed-off-by: Chamarthy, Mahati <mahati.chamarthy@intel.com>
src/librbd/cache/rwl/LogEntry.cc
src/librbd/cache/rwl/LogEntry.h

index 9434b7d65716e17781d6d9eeb83957e38f6a3b96..76e1dad6b46263b66c55d0bf8afc530659d5df96 100644 (file)
@@ -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
index d4945679120b66fbd822f2cd22cdaad1754aff2a..36fbf74f0ce845c281b299553234430533b45397 100644 (file)
@@ -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<SyncPointLogEntry> 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