]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/SloppyCRCMap.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / common / SloppyCRCMap.h
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#ifndef CEPH_COMMON_SLOPPYCRCMAP_H
5#define CEPH_COMMON_SLOPPYCRCMAP_H
6
7#include "include/encoding.h"
11fdf7f2
TL
8
9namespace ceph {
10class Formatter;
11}
7c673cae 12
7c673cae
FG
13/**
14 * SloppyCRCMap
15 *
16 * Opportunistically track CRCs on any reads or writes that cover full
17 * blocks. Verify read results when we have CRC data available for
18 * the given extent.
19 */
20class SloppyCRCMap {
21 static const int crc_iv = 0xffffffff;
22
23 std::map<uint64_t, uint32_t> crc_map; // offset -> crc(-1)
24 uint32_t block_size;
25 uint32_t zero_crc;
26
27public:
28 SloppyCRCMap(uint32_t b=0) {
29 set_block_size(b);
30 }
31
32 void set_block_size(uint32_t b) {
33 block_size = b;
34 //zero_crc = ceph_crc32c(0xffffffff, NULL, block_size);
35 if (b) {
f67539c2 36 ceph::buffer::list bl;
7c673cae
FG
37 bl.append_zero(block_size);
38 zero_crc = bl.crc32c(crc_iv);
39 } else {
40 zero_crc = crc_iv;
41 }
42 }
43
44 /// update based on a write
f67539c2 45 void write(uint64_t offset, uint64_t len, const ceph::buffer::list& bl,
7c673cae
FG
46 std::ostream *out = NULL);
47
48 /// update based on a truncate
49 void truncate(uint64_t offset);
50
51 /// update based on a zero/punch_hole
52 void zero(uint64_t offset, uint64_t len);
53
54 /// update based on a zero/punch_hole
55 void clone_range(uint64_t offset, uint64_t len, uint64_t srcoff, const SloppyCRCMap& src,
56 std::ostream *out = NULL);
57
58 /**
59 * validate a read result
60 *
61 * @param offset offset
62 * @param length length
63 * @param bl data read
64 * @param err option ostream to describe errors in detail
65 * @returns error count, 0 for success
66 */
f67539c2 67 int read(uint64_t offset, uint64_t len, const ceph::buffer::list& bl, std::ostream *err);
7c673cae 68
f67539c2
TL
69 void encode(ceph::buffer::list& bl) const;
70 void decode(ceph::buffer::list::const_iterator& bl);
11fdf7f2 71 void dump(ceph::Formatter *f) const;
7c673cae
FG
72 static void generate_test_instances(std::list<SloppyCRCMap*>& ls);
73};
74WRITE_CLASS_ENCODER(SloppyCRCMap)
75
76#endif