]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/cache/pwl/rwl/Request.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / librbd / cache / pwl / rwl / Request.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 "Request.h"
5 #include "librbd/cache/pwl/AbstractWriteLog.h"
6
7 #define dout_subsys ceph_subsys_rbd_pwl
8 #undef dout_prefix
9 #define dout_prefix *_dout << "librbd::cache::pwl::rwl::Request: " << this \
10 << " " << __func__ << ": "
11
12 namespace librbd {
13 namespace cache {
14 namespace pwl {
15 namespace rwl {
16
17 template <typename T>
18 void C_WriteRequest<T>::setup_buffer_resources(
19 uint64_t *bytes_cached, uint64_t *bytes_dirtied, uint64_t *bytes_allocated,
20 uint64_t *number_lanes, uint64_t *number_log_entries,
21 uint64_t *number_unpublished_reserves) {
22
23 ceph_assert(!this->m_resources.allocated);
24
25 auto image_extents_size = this->image_extents.size();
26 this->m_resources.buffers.reserve(image_extents_size);
27
28 *bytes_cached = 0;
29 *bytes_allocated = 0;
30 *number_lanes = image_extents_size;
31 *number_log_entries = image_extents_size;
32 *number_unpublished_reserves = image_extents_size;
33
34 for (auto &extent : this->image_extents) {
35 this->m_resources.buffers.emplace_back();
36 struct WriteBufferAllocation &buffer = this->m_resources.buffers.back();
37 buffer.allocation_size = MIN_WRITE_ALLOC_SIZE;
38 buffer.allocated = false;
39 *bytes_cached += extent.second;
40 if (extent.second > buffer.allocation_size) {
41 buffer.allocation_size = extent.second;
42 }
43 *bytes_allocated += buffer.allocation_size;
44 }
45 *bytes_dirtied = *bytes_cached;
46 }
47
48 template <typename T>
49 std::ostream &operator<<(std::ostream &os,
50 const C_CompAndWriteRequest<T> &req) {
51 os << (C_WriteRequest<T>&)req
52 << " cmp_bl=" << req.cmp_bl
53 << ", read_bl=" << req.read_bl
54 << ", compare_succeeded=" << req.compare_succeeded
55 << ", mismatch_offset=" << req.mismatch_offset;
56 return os;
57 }
58
59 template <typename T>
60 void C_WriteSameRequest<T>::setup_buffer_resources(
61 uint64_t *bytes_cached, uint64_t *bytes_dirtied, uint64_t *bytes_allocated,
62 uint64_t *number_lanes, uint64_t *number_log_entries,
63 uint64_t *number_unpublished_reserves) {
64 ceph_assert(this->image_extents.size() == 1);
65 *number_log_entries = 1;
66 *bytes_dirtied += this->image_extents[0].second;
67 auto pattern_length = this->bl.length();
68 this->m_resources.buffers.emplace_back();
69 struct WriteBufferAllocation &buffer = this->m_resources.buffers.back();
70 buffer.allocation_size = MIN_WRITE_ALLOC_SIZE;
71 buffer.allocated = false;
72 *bytes_cached += pattern_length;
73 if (pattern_length > buffer.allocation_size) {
74 buffer.allocation_size = pattern_length;
75 }
76 *bytes_allocated += buffer.allocation_size;
77 }
78
79 } // namespace rwl
80 } // namespace pwl
81 } // namespace cache
82 } // namespace librbd
83
84 template class librbd::cache::pwl::rwl::C_WriteRequest<librbd::cache::pwl::AbstractWriteLog<librbd::ImageCtx> >;
85 template class librbd::cache::pwl::rwl::C_WriteSameRequest<librbd::cache::pwl::AbstractWriteLog<librbd::ImageCtx> >;
86 template class librbd::cache::pwl::rwl::C_CompAndWriteRequest<librbd::cache::pwl::AbstractWriteLog<librbd::ImageCtx> >;