]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/cache/pwl/rwl/ReadRequest.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / librbd / cache / pwl / rwl / ReadRequest.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 "ReadRequest.h"
5
6 #define dout_subsys ceph_subsys_rbd_pwl
7 #undef dout_prefix
8 #define dout_prefix *_dout << "librbd::cache::pwl::rwl::ReadRequest: " << this << " " \
9 << __func__ << ": "
10
11 namespace librbd {
12 namespace cache {
13 namespace pwl {
14 namespace rwl {
15
16 void C_ReadRequest::finish(int r) {
17 ldout(m_cct, 20) << "(" << get_name() << "): r=" << r << dendl;
18 int hits = 0;
19 int misses = 0;
20 int hit_bytes = 0;
21 int miss_bytes = 0;
22 if (r >= 0) {
23 /*
24 * At this point the miss read has completed. We'll iterate through
25 * read_extents and produce *m_out_bl by assembling pieces of miss_bl
26 * and the individual hit extent bufs in the read extents that represent
27 * hits.
28 */
29 uint64_t miss_bl_offset = 0;
30 for (auto extent : read_extents) {
31 if (extent->m_bl.length()) {
32 /* This was a hit */
33 ceph_assert(extent->second == extent->m_bl.length());
34 ++hits;
35 hit_bytes += extent->second;
36 m_out_bl->claim_append(extent->m_bl);
37 } else {
38 /* This was a miss. */
39 ++misses;
40 miss_bytes += extent->second;
41 bufferlist miss_extent_bl;
42 miss_extent_bl.substr_of(miss_bl, miss_bl_offset, extent->second);
43 /* Add this read miss bufferlist to the output bufferlist */
44 m_out_bl->claim_append(miss_extent_bl);
45 /* Consume these bytes in the read miss bufferlist */
46 miss_bl_offset += extent->second;
47 }
48 }
49 }
50 ldout(m_cct, 20) << "(" << get_name() << "): r=" << r << " bl=" << *m_out_bl << dendl;
51 utime_t now = ceph_clock_now();
52 ceph_assert((int)m_out_bl->length() == hit_bytes + miss_bytes);
53 m_on_finish->complete(r);
54 m_perfcounter->inc(l_librbd_pwl_rd_bytes, hit_bytes + miss_bytes);
55 m_perfcounter->inc(l_librbd_pwl_rd_hit_bytes, hit_bytes);
56 m_perfcounter->tinc(l_librbd_pwl_rd_latency, now - m_arrived_time);
57 if (!misses) {
58 m_perfcounter->inc(l_librbd_pwl_rd_hit_req, 1);
59 m_perfcounter->tinc(l_librbd_pwl_rd_hit_latency, now - m_arrived_time);
60 } else {
61 if (hits) {
62 m_perfcounter->inc(l_librbd_pwl_rd_part_hit_req, 1);
63 }
64 }
65 }
66
67 } // namespace rwl
68 } // namespace pwl
69 } // namespace cache
70 } // namespace librbd