]>
git.proxmox.com Git - ceph.git/blob - 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
6 #include "common/ceph_context.h"
7 #include "include/Context.h"
9 #define dout_subsys ceph_subsys_rbd_rwl
11 #define dout_prefix *_dout << "librbd::cache::rwl::Types: " << this << " " \
20 DeferredContexts::~DeferredContexts() {
21 finish_contexts(nullptr, contexts
, 0);
24 void DeferredContexts::add(Context
* ctx
) {
25 contexts
.push_back(ctx
);
29 * A BlockExtent identifies a range by first and last.
31 * An Extent ("image extent") identifies a range by start and length.
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"
38 BlockExtent
convert_to_block_extent(const uint64_t offset_bytes
, const uint64_t length_bytes
)
40 return BlockExtent(offset_bytes
,
41 offset_bytes
+ length_bytes
- 1);
44 BlockExtent
WriteLogPmemEntry::block_extent() {
45 return convert_to_block_extent(image_offset_bytes
, write_bytes
);
48 uint64_t WriteLogPmemEntry::get_offset_bytes() {
49 return image_offset_bytes
;
52 uint64_t WriteLogPmemEntry::get_write_bytes() {
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
;
73 template <typename ExtentsType
>
74 ExtentsSummary
<ExtentsType
>::ExtentsSummary(const ExtentsType
&extents
)
75 : total_bytes(0), first_image_byte(0), last_image_byte(0)
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 */
86 total_bytes
+= extent
.second
;
87 if (extent
.first
< first_image_byte
) {
88 first_image_byte
= extent
.first
;
90 if ((extent
.first
+ extent
.second
) > last_image_byte
) {
91 last_image_byte
= extent
.first
+ extent
.second
;
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
<< "";
108 } // namespace librbd