]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/cache/rwl/Types.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / librbd / cache / rwl / Types.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 <iostream>
5 #include "Types.h"
6 #include "common/ceph_context.h"
7 #include "include/Context.h"
8
9 #define dout_subsys ceph_subsys_rbd_rwl
10 #undef dout_prefix
11 #define dout_prefix *_dout << "librbd::cache::rwl::Types: " << this << " " \
12 << __func__ << ": "
13
14 namespace librbd {
15
16 namespace cache {
17
18 namespace rwl {
19
20 DeferredContexts::~DeferredContexts() {
21 finish_contexts(nullptr, contexts, 0);
22 }
23
24 void DeferredContexts::add(Context* ctx) {
25 contexts.push_back(ctx);
26 }
27
28 /*
29 * A BlockExtent identifies a range by first and last.
30 *
31 * An Extent ("image extent") identifies a range by start and length.
32 *
33 * The ImageCache interface is defined in terms of image extents, and
34 * requires no alignment of the beginning or end of the extent. We
35 * convert between image and block extents here using a "block size"
36 * of 1.
37 */
38 BlockExtent convert_to_block_extent(const uint64_t offset_bytes, const uint64_t length_bytes)
39 {
40 return BlockExtent(offset_bytes,
41 offset_bytes + length_bytes - 1);
42 }
43
44 BlockExtent WriteLogPmemEntry::block_extent() {
45 return convert_to_block_extent(image_offset_bytes, write_bytes);
46 }
47
48 uint64_t WriteLogPmemEntry::get_offset_bytes() {
49 return image_offset_bytes;
50 }
51
52 uint64_t WriteLogPmemEntry::get_write_bytes() {
53 return write_bytes;
54 }
55
56 std::ostream& operator<<(std::ostream& os,
57 const WriteLogPmemEntry &entry) {
58 os << "entry_valid=" << (bool)entry.entry_valid << ", "
59 << "sync_point=" << (bool)entry.sync_point << ", "
60 << "sequenced=" << (bool)entry.sequenced << ", "
61 << "has_data=" << (bool)entry.has_data << ", "
62 << "discard=" << (bool)entry.discard << ", "
63 << "writesame=" << (bool)entry.writesame << ", "
64 << "sync_gen_number=" << entry.sync_gen_number << ", "
65 << "write_sequence_number=" << entry.write_sequence_number << ", "
66 << "image_offset_bytes=" << entry.image_offset_bytes << ", "
67 << "write_bytes=" << entry.write_bytes << ", "
68 << "ws_datalen=" << entry.ws_datalen << ", "
69 << "entry_index=" << entry.entry_index;
70 return os;
71 };
72
73 template <typename ExtentsType>
74 ExtentsSummary<ExtentsType>::ExtentsSummary(const ExtentsType &extents)
75 : total_bytes(0), first_image_byte(0), last_image_byte(0)
76 {
77 if (extents.empty()) return;
78 /* These extents refer to image offsets between first_image_byte
79 * and last_image_byte, inclusive, but we don't guarantee here
80 * that they address all of those bytes. There may be gaps. */
81 first_image_byte = extents.front().first;
82 last_image_byte = first_image_byte + extents.front().second;
83 for (auto &extent : extents) {
84 /* Ignore zero length extents */
85 if (extent.second) {
86 total_bytes += extent.second;
87 if (extent.first < first_image_byte) {
88 first_image_byte = extent.first;
89 }
90 if ((extent.first + extent.second) > last_image_byte) {
91 last_image_byte = extent.first + extent.second;
92 }
93 }
94 }
95 }
96
97 template <typename T>
98 std::ostream &operator<<(std::ostream &os,
99 const ExtentsSummary<T> &s) {
100 os << "total_bytes=" << s.total_bytes << ", "
101 << "first_image_byte=" << s.first_image_byte << ", "
102 << "last_image_byte=" << s.last_image_byte << "";
103 return os;
104 };
105
106 } // namespace rwl
107 } // namespace cache
108 } // namespace librbd