]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/SloppyCRCMap.h
d8d1561123e1ff04a52d3330fbf777b9b296be6e
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_COMMON_SLOPPYCRCMAP_H
5 #define CEPH_COMMON_SLOPPYCRCMAP_H
7 #include "include/encoding.h"
8 #include "common/Formatter.h"
13 * Opportunistically track CRCs on any reads or writes that cover full
14 * blocks. Verify read results when we have CRC data available for
18 static const int crc_iv
= 0xffffffff;
20 std::map
<uint64_t, uint32_t> crc_map
; // offset -> crc(-1)
25 SloppyCRCMap(uint32_t b
=0) {
29 void set_block_size(uint32_t b
) {
31 //zero_crc = ceph_crc32c(0xffffffff, NULL, block_size);
34 bl
.append_zero(block_size
);
35 zero_crc
= bl
.crc32c(crc_iv
);
41 /// update based on a write
42 void write(uint64_t offset
, uint64_t len
, const bufferlist
& bl
,
43 std::ostream
*out
= NULL
);
45 /// update based on a truncate
46 void truncate(uint64_t offset
);
48 /// update based on a zero/punch_hole
49 void zero(uint64_t offset
, uint64_t len
);
51 /// update based on a zero/punch_hole
52 void clone_range(uint64_t offset
, uint64_t len
, uint64_t srcoff
, const SloppyCRCMap
& src
,
53 std::ostream
*out
= NULL
);
56 * validate a read result
58 * @param offset offset
59 * @param length length
61 * @param err option ostream to describe errors in detail
62 * @returns error count, 0 for success
64 int read(uint64_t offset
, uint64_t len
, const bufferlist
& bl
, std::ostream
*err
);
66 void encode(bufferlist
& bl
) const;
67 void decode(bufferlist::iterator
& bl
);
68 void dump(Formatter
*f
) const;
69 static void generate_test_instances(std::list
<SloppyCRCMap
*>& ls
);
71 WRITE_CLASS_ENCODER(SloppyCRCMap
)