1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
5 #include "librbd/cache/pwl/AbstractWriteLog.h"
7 #define dout_subsys ceph_subsys_rbd_pwl
9 #define dout_prefix *_dout << "librbd::cache::pwl::rwl::Request: " << this \
10 << " " << __func__ << ": "
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
) {
23 ceph_assert(!this->m_resources
.allocated
);
25 auto image_extents_size
= this->image_extents
.size();
26 this->m_resources
.buffers
.reserve(image_extents_size
);
30 *number_lanes
= image_extents_size
;
31 *number_log_entries
= image_extents_size
;
32 *number_unpublished_reserves
= image_extents_size
;
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
;
43 *bytes_allocated
+= buffer
.allocation_size
;
45 *bytes_dirtied
= *bytes_cached
;
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
;
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
;
76 *bytes_allocated
+= buffer
.allocation_size
;
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
> >;