]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: add DiscardLogEntry
authorYuan Lu <yuan.y.lu@intel.com>
Sun, 26 Apr 2020 07:28:32 +0000 (15:28 +0800)
committerYuan Lu <yuan.y.lu@intel.com>
Wed, 29 Apr 2020 06:44:01 +0000 (14:44 +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 9f72df7d77e6277e99ff54560277ca5b0404f0df..9434b7d65716e17781d6d9eeb83957e38f6a3b96 100644 (file)
@@ -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
index 9e5d3c53403df4b3032f966fbe5a45abab6cdcc3..d4945679120b66fbd822f2cd22cdaad1754aff2a 100644 (file)
@@ -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<SyncPointLogEntry> 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<SyncPointLogEntry> 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<SyncPointLogEntry> 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