]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/cache/pwl/LogEntry.cc
import ceph 16.2.7
[ceph.git] / ceph / src / librbd / cache / pwl / LogEntry.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include <iostream>
5 #include "LogEntry.h"
6 #include "librbd/cache/ImageWriteback.h"
7
8 #define dout_subsys ceph_subsys_rbd_pwl
9 #undef dout_prefix
10 #define dout_prefix *_dout << "librbd::cache::pwl::LogEntry: " << this << " " \
11 << __func__ << ": "
12
13 namespace librbd {
14 namespace cache {
15 namespace pwl {
16
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;
22 return os;
23 }
24
25 std::ostream &operator<<(std::ostream &os,
26 const GenericLogEntry &entry) {
27 return entry.format(os);
28 }
29
30 std::ostream& SyncPointLogEntry::format(std::ostream &os) const {
31 os << "(Sync Point) ";
32 GenericLogEntry::format(os);
33 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;
40 return os;
41 }
42
43 std::ostream &operator<<(std::ostream &os,
44 const SyncPointLogEntry &entry) {
45 return entry.format(os);
46 }
47
48 bool GenericWriteLogEntry::can_writeback() const {
49 return (this->completed &&
50 (ram_entry.sequenced ||
51 (sync_point_entry &&
52 sync_point_entry->completed)));
53 }
54
55 std::ostream& GenericWriteLogEntry::format(std::ostream &os) const {
56 GenericLogEntry::format(os);
57 os << ", "
58 << "sync_point_entry=[";
59 if (sync_point_entry) {
60 os << *sync_point_entry;
61 } else {
62 os << "nullptr";
63 }
64 os << "], "
65 << "referring_map_entries=" << referring_map_entries;
66 return os;
67 }
68
69 std::ostream &operator<<(std::ostream &os,
70 const GenericWriteLogEntry &entry) {
71 return entry.format(os);
72 }
73
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;
82 } else {
83 /* Persist on write */
84 ram_entry.write_sequence_number = last_op_sequence_num;
85 ram_entry.sequenced = 1;
86 }
87 ram_entry.sync_point = 0;
88 ram_entry.discard = 0;
89 }
90
91 std::ostream& WriteLogEntry::format(std::ostream &os) const {
92 os << "(Write) ";
93 GenericWriteLogEntry::format(os);
94 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;
99 return os;
100 }
101
102 std::ostream &operator<<(std::ostream &os,
103 const WriteLogEntry &entry) {
104 return entry.format(os);
105 }
106
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);
112 }
113
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;
120 } else {
121 /* Persist on write */
122 ram_entry.write_sequence_number = last_op_sequence_num;
123 ram_entry.sequenced = 1;
124 }
125 }
126
127 std::ostream &DiscardLogEntry::format(std::ostream &os) const {
128 os << "(Discard) ";
129 GenericWriteLogEntry::format(os);
130 return os;
131 }
132
133 std::ostream &operator<<(std::ostream &os,
134 const DiscardLogEntry &entry) {
135 return entry.format(os);
136 }
137
138 } // namespace pwl
139 } // namespace cache
140 } // namespace librbd