]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/SloppyCRCMap.h
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"
16 * Opportunistically track CRCs on any reads or writes that cover full
17 * blocks. Verify read results when we have CRC data available for
21 static const int crc_iv
= 0xffffffff;
23 std::map
<uint64_t, uint32_t> crc_map
; // offset -> crc(-1)
28 SloppyCRCMap(uint32_t b
=0) {
32 void set_block_size(uint32_t b
) {
34 //zero_crc = ceph_crc32c(0xffffffff, NULL, block_size);
36 ceph::buffer::list bl
;
37 bl
.append_zero(block_size
);
38 zero_crc
= bl
.crc32c(crc_iv
);
44 /// update based on a write
45 void write(uint64_t offset
, uint64_t len
, const ceph::buffer::list
& bl
,
46 std::ostream
*out
= NULL
);
48 /// update based on a truncate
49 void truncate(uint64_t offset
);
51 /// update based on a zero/punch_hole
52 void zero(uint64_t offset
, uint64_t len
);
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
);
59 * validate a read result
61 * @param offset offset
62 * @param length length
64 * @param err option ostream to describe errors in detail
65 * @returns error count, 0 for success
67 int read(uint64_t offset
, uint64_t len
, const ceph::buffer::list
& bl
, std::ostream
*err
);
69 void encode(ceph::buffer::list
& bl
) const;
70 void decode(ceph::buffer::list::const_iterator
& bl
);
71 void dump(ceph::Formatter
*f
) const;
72 static void generate_test_instances(std::list
<SloppyCRCMap
*>& ls
);
74 WRITE_CLASS_ENCODER(SloppyCRCMap
)