1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
6 #include "librbd/cache/ImageWriteback.h"
8 #define dout_subsys ceph_subsys_rbd_pwl
10 #define dout_prefix *_dout << "librbd::cache::pwl::LogEntry: " << this << " " \
17 std::ostream
& GenericLogEntry::format(std::ostream
&os
) const {
18 os
<< "ram_entry=[" << ram_entry
<< "], "
19 << "cache_entry=" << (void*)cache_entry
<< ", "
20 << "log_entry_index=" << log_entry_index
<< ", "
21 << "completed=" << completed
;
25 std::ostream
&operator<<(std::ostream
&os
,
26 const GenericLogEntry
&entry
) {
27 return entry
.format(os
);
30 std::ostream
& SyncPointLogEntry::format(std::ostream
&os
) const {
31 os
<< "(Sync Point) ";
32 GenericLogEntry::format(os
);
34 << "writes=" << writes
<< ", "
35 << "bytes=" << bytes
<< ", "
36 << "writes_completed=" << writes_completed
<< ", "
37 << "writes_flushed=" << writes_flushed
<< ", "
38 << "prior_sync_point_flushed=" << prior_sync_point_flushed
<< ", "
39 << "next_sync_point_entry=" << next_sync_point_entry
;
43 std::ostream
&operator<<(std::ostream
&os
,
44 const SyncPointLogEntry
&entry
) {
45 return entry
.format(os
);
48 bool GenericWriteLogEntry::can_writeback() const {
49 return (this->completed
&&
50 (ram_entry
.sequenced
||
52 sync_point_entry
->completed
)));
55 std::ostream
& GenericWriteLogEntry::format(std::ostream
&os
) const {
56 GenericLogEntry::format(os
);
58 << "sync_point_entry=[";
59 if (sync_point_entry
) {
60 os
<< *sync_point_entry
;
65 << "referring_map_entries=" << referring_map_entries
;
69 std::ostream
&operator<<(std::ostream
&os
,
70 const GenericWriteLogEntry
&entry
) {
71 return entry
.format(os
);
74 void WriteLogEntry::init(bool has_data
,
75 uint64_t current_sync_gen
,
76 uint64_t last_op_sequence_num
, bool persist_on_flush
) {
77 ram_entry
.has_data
= 1;
78 ram_entry
.sync_gen_number
= current_sync_gen
;
79 if (persist_on_flush
) {
80 /* Persist on flush. Sequence #0 is never used. */
81 ram_entry
.write_sequence_number
= 0;
83 /* Persist on write */
84 ram_entry
.write_sequence_number
= last_op_sequence_num
;
85 ram_entry
.sequenced
= 1;
87 ram_entry
.sync_point
= 0;
88 ram_entry
.discard
= 0;
91 std::ostream
& WriteLogEntry::format(std::ostream
&os
) const {
93 GenericWriteLogEntry::format(os
);
95 << "cache_buffer=" << (void*)cache_buffer
<< ", ";
96 os
<< "cache_bp=" << cache_bp
<< ", ";
97 os
<< "cache_bl=" << cache_bl
<< ", ";
98 os
<< "bl_refs=" << bl_refs
;
102 std::ostream
&operator<<(std::ostream
&os
,
103 const WriteLogEntry
&entry
) {
104 return entry
.format(os
);
107 void DiscardLogEntry::writeback(
108 librbd::cache::ImageWritebackInterface
&image_writeback
, Context
*ctx
) {
109 image_writeback
.aio_discard(ram_entry
.image_offset_bytes
,
110 ram_entry
.write_bytes
,
111 m_discard_granularity_bytes
, ctx
);
114 void DiscardLogEntry::init(uint64_t current_sync_gen
, bool persist_on_flush
,
115 uint64_t last_op_sequence_num
) {
116 ram_entry
.sync_gen_number
= current_sync_gen
;
117 if (persist_on_flush
) {
118 /* Persist on flush. Sequence #0 is never used. */
119 ram_entry
.write_sequence_number
= 0;
121 /* Persist on write */
122 ram_entry
.write_sequence_number
= last_op_sequence_num
;
123 ram_entry
.sequenced
= 1;
127 std::ostream
&DiscardLogEntry::format(std::ostream
&os
) const {
129 GenericWriteLogEntry::format(os
);
133 std::ostream
&operator<<(std::ostream
&os
,
134 const DiscardLogEntry
&entry
) {
135 return entry
.format(os
);
140 } // namespace librbd