]> git.proxmox.com Git - ceph.git/blame - ceph/src/librbd/cache/rwl/LogEntry.cc
bump version to 15.2.11-pve1
[ceph.git] / ceph / src / librbd / cache / rwl / 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"
6
7#define dout_subsys ceph_subsys_rbd_rwl
8#undef dout_prefix
9#define dout_prefix *_dout << "librbd::cache::rwl::LogEntry: " << this << " " \
10 << __func__ << ": "
11
12namespace librbd {
13
14namespace cache {
15
16namespace rwl {
17
18std::ostream& GenericLogEntry::format(std::ostream &os) const {
19 os << "ram_entry=[" << ram_entry << "], "
20 << "pmem_entry=" << (void*)pmem_entry << ", "
21 << "log_entry_index=" << log_entry_index << ", "
22 << "completed=" << completed;
23 return os;
24}
25
26std::ostream &operator<<(std::ostream &os,
27 const GenericLogEntry &entry) {
28 return entry.format(os);
29}
30
31std::ostream& SyncPointLogEntry::format(std::ostream &os) const {
32 os << "(Sync Point) ";
33 GenericLogEntry::format(os);
34 os << ", "
35 << "writes=" << writes << ", "
36 << "bytes=" << bytes << ", "
37 << "writes_completed=" << writes_completed << ", "
38 << "writes_flushed=" << writes_flushed << ", "
39 << "prior_sync_point_flushed=" << prior_sync_point_flushed << ", "
40 << "next_sync_point_entry=" << next_sync_point_entry;
41 return os;
42};
43
44std::ostream &operator<<(std::ostream &os,
45 const SyncPointLogEntry &entry) {
46 return entry.format(os);
47}
48
49std::ostream& GenericWriteLogEntry::format(std::ostream &os) const {
50 GenericLogEntry::format(os);
51 os << ", "
52 << "sync_point_entry=[";
53 if (sync_point_entry) {
54 os << *sync_point_entry;
55 } else {
56 os << "nullptr";
57 }
58 os << "], "
59 << "referring_map_entries=" << referring_map_entries << ", "
60 << "flushing=" << flushing << ", "
61 << "flushed=" << flushed;
62 return os;
63};
64
65std::ostream &operator<<(std::ostream &os,
66 const GenericWriteLogEntry &entry) {
67 return entry.format(os);
68}
69
70void WriteLogEntry::init(bool has_data, std::vector<WriteBufferAllocation>::iterator allocation,
71 uint64_t current_sync_gen, uint64_t last_op_sequence_num, bool persist_on_flush) {
72 ram_entry.has_data = 1;
73 ram_entry.write_data = allocation->buffer_oid;
74 ceph_assert(!TOID_IS_NULL(ram_entry.write_data));
75 pmem_buffer = D_RW(ram_entry.write_data);
76 ram_entry.sync_gen_number = current_sync_gen;
77 if (persist_on_flush) {
78 /* Persist on flush. Sequence #0 is never used. */
79 ram_entry.write_sequence_number = 0;
80 } else {
81 /* Persist on write */
82 ram_entry.write_sequence_number = last_op_sequence_num;
83 ram_entry.sequenced = 1;
84 }
85 ram_entry.sync_point = 0;
86 ram_entry.discard = 0;
87}
88
89void WriteLogEntry::init_pmem_bp() {
90 ceph_assert(!pmem_bp.have_raw());
91 pmem_bp = buffer::ptr(buffer::create_static(this->write_bytes(), (char*)pmem_buffer));
92}
93
94void WriteLogEntry::init_pmem_bl() {
95 pmem_bl.clear();
96 init_pmem_bp();
97 ceph_assert(pmem_bp.have_raw());
98 int before_bl = pmem_bp.raw_nref();
99 this->init_bl(pmem_bp, pmem_bl);
100 int after_bl = pmem_bp.raw_nref();
101 bl_refs = after_bl - before_bl;
102}
103
104unsigned int WriteLogEntry::reader_count() {
105 if (pmem_bp.have_raw()) {
106 return (pmem_bp.raw_nref() - bl_refs - 1);
107 } else {
108 return 0;
109 }
110}
111
112/* Returns a ref to a bl containing bufferptrs to the entry pmem buffer */
113buffer::list& WriteLogEntry::get_pmem_bl() {
114 if (0 == bl_refs) {
115 std::lock_guard locker(m_entry_bl_lock);
116 if (0 == bl_refs) {
117 init_pmem_bl();
118 }
119 ceph_assert(0 != bl_refs);
120 }
121 return pmem_bl;
122};
123
124/* Constructs a new bl containing copies of pmem_bp */
125void WriteLogEntry::copy_pmem_bl(bufferlist *out_bl) {
126 this->get_pmem_bl();
127 /* pmem_bp is now initialized */
128 buffer::ptr cloned_bp(pmem_bp.clone());
129 out_bl->clear();
130 this->init_bl(cloned_bp, *out_bl);
131}
132
133std::ostream& WriteLogEntry::format(std::ostream &os) const {
134 os << "(Write) ";
135 GenericWriteLogEntry::format(os);
136 os << ", "
137 << "pmem_buffer=" << (void*)pmem_buffer << ", ";
138 os << "pmem_bp=" << pmem_bp << ", ";
139 os << "pmem_bl=" << pmem_bl << ", ";
140 os << "bl_refs=" << bl_refs;
141 return os;
142};
143
144std::ostream &operator<<(std::ostream &os,
145 const WriteLogEntry &entry) {
146 return entry.format(os);
147}
148
149} // namespace rwl
150} // namespace cache
151} // namespace librbd