]> git.proxmox.com Git - ceph.git/blame - ceph/src/librbd/cache/pwl/LogEntry.cc
import ceph quincy 17.2.1
[ceph.git] / ceph / src / librbd / cache / pwl / LogEntry.cc
CommitLineData
9f95a23c
TL
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"
f67539c2 6#include "librbd/cache/ImageWriteback.h"
9f95a23c 7
f67539c2 8#define dout_subsys ceph_subsys_rbd_pwl
9f95a23c 9#undef dout_prefix
f67539c2 10#define dout_prefix *_dout << "librbd::cache::pwl::LogEntry: " << this << " " \
9f95a23c
TL
11 << __func__ << ": "
12
13namespace librbd {
9f95a23c 14namespace cache {
f67539c2 15namespace pwl {
9f95a23c
TL
16
17std::ostream& GenericLogEntry::format(std::ostream &os) const {
20effc67
TL
18 os << "ram_entry=[" << ram_entry
19 << "], cache_entry=" << (void*)cache_entry
20 << ", log_entry_index=" << log_entry_index
21 << ", completed=" << completed;
9f95a23c
TL
22 return os;
23}
24
25std::ostream &operator<<(std::ostream &os,
26 const GenericLogEntry &entry) {
27 return entry.format(os);
28}
29
30std::ostream& SyncPointLogEntry::format(std::ostream &os) const {
31 os << "(Sync Point) ";
32 GenericLogEntry::format(os);
20effc67
TL
33 os << ", writes=" << writes
34 << ", bytes=" << bytes
35 << ", writes_completed=" << writes_completed
36 << ", writes_flushed=" << writes_flushed
37 << ", prior_sync_point_flushed=" << prior_sync_point_flushed
38 << ", next_sync_point_entry=" << next_sync_point_entry;
9f95a23c 39 return os;
f67539c2 40}
9f95a23c
TL
41
42std::ostream &operator<<(std::ostream &os,
43 const SyncPointLogEntry &entry) {
44 return entry.format(os);
45}
46
f67539c2
TL
47bool GenericWriteLogEntry::can_writeback() const {
48 return (this->completed &&
33c7a0ef 49 (ram_entry.is_sequenced() ||
f67539c2
TL
50 (sync_point_entry &&
51 sync_point_entry->completed)));
52}
53
9f95a23c
TL
54std::ostream& GenericWriteLogEntry::format(std::ostream &os) const {
55 GenericLogEntry::format(os);
20effc67 56 os << ", sync_point_entry=[";
9f95a23c
TL
57 if (sync_point_entry) {
58 os << *sync_point_entry;
59 } else {
60 os << "nullptr";
61 }
20effc67 62 os << "], referring_map_entries=" << referring_map_entries;
9f95a23c 63 return os;
f67539c2 64}
9f95a23c
TL
65
66std::ostream &operator<<(std::ostream &os,
67 const GenericWriteLogEntry &entry) {
68 return entry.format(os);
69}
70
f67539c2
TL
71void WriteLogEntry::init(bool has_data,
72 uint64_t current_sync_gen,
73 uint64_t last_op_sequence_num, bool persist_on_flush) {
33c7a0ef 74 ram_entry.set_has_data(has_data);
9f95a23c
TL
75 ram_entry.sync_gen_number = current_sync_gen;
76 if (persist_on_flush) {
77 /* Persist on flush. Sequence #0 is never used. */
78 ram_entry.write_sequence_number = 0;
79 } else {
80 /* Persist on write */
81 ram_entry.write_sequence_number = last_op_sequence_num;
33c7a0ef 82 ram_entry.set_sequenced(true);
9f95a23c 83 }
33c7a0ef
TL
84 ram_entry.set_sync_point(false);
85 ram_entry.set_discard(false);
9f95a23c
TL
86}
87
9f95a23c
TL
88std::ostream& WriteLogEntry::format(std::ostream &os) const {
89 os << "(Write) ";
90 GenericWriteLogEntry::format(os);
20effc67
TL
91 os << ", cache_buffer=" << (void*)cache_buffer;
92 os << ", cache_bp=" << cache_bp;
93 os << ", bl_refs=" << bl_refs;
9f95a23c 94 return os;
f67539c2 95}
9f95a23c
TL
96
97std::ostream &operator<<(std::ostream &os,
98 const WriteLogEntry &entry) {
99 return entry.format(os);
100}
101
f67539c2
TL
102void DiscardLogEntry::writeback(
103 librbd::cache::ImageWritebackInterface &image_writeback, Context *ctx) {
104 image_writeback.aio_discard(ram_entry.image_offset_bytes,
105 ram_entry.write_bytes,
106 m_discard_granularity_bytes, ctx);
107}
108
109void DiscardLogEntry::init(uint64_t current_sync_gen, bool persist_on_flush,
110 uint64_t last_op_sequence_num) {
111 ram_entry.sync_gen_number = current_sync_gen;
112 if (persist_on_flush) {
113 /* Persist on flush. Sequence #0 is never used. */
114 ram_entry.write_sequence_number = 0;
115 } else {
116 /* Persist on write */
117 ram_entry.write_sequence_number = last_op_sequence_num;
33c7a0ef 118 ram_entry.set_sequenced(true);
f67539c2
TL
119 }
120}
121
122std::ostream &DiscardLogEntry::format(std::ostream &os) const {
123 os << "(Discard) ";
124 GenericWriteLogEntry::format(os);
125 return os;
126}
127
128std::ostream &operator<<(std::ostream &os,
129 const DiscardLogEntry &entry) {
130 return entry.format(os);
131}
132
133} // namespace pwl
9f95a23c
TL
134} // namespace cache
135} // namespace librbd