return entry.format(os);
}
-bool GenericWriteLogEntry::can_writeback() {
+bool GenericWriteLogEntry::can_writeback() const {
return (this->completed &&
(ram_entry.sequenced ||
(sync_point_entry &&
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
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() {
~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();
};
}
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;
}
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