]>
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"
8 #include "common/Formatter.h"
17 * Opportunistically track CRCs on any reads or writes that cover full
18 * blocks. Verify read results when we have CRC data available for
22 static const int crc_iv
= 0xffffffff;
24 std::map
<uint64_t, uint32_t> crc_map
; // offset -> crc(-1)
29 SloppyCRCMap(uint32_t b
=0) {
33 void set_block_size(uint32_t b
) {
35 //zero_crc = ceph_crc32c(0xffffffff, NULL, block_size);
38 bl
.append_zero(block_size
);
39 zero_crc
= bl
.crc32c(crc_iv
);
45 /// update based on a write
46 void write(uint64_t offset
, uint64_t len
, const bufferlist
& bl
,
47 std::ostream
*out
= NULL
);
49 /// update based on a truncate
50 void truncate(uint64_t offset
);
52 /// update based on a zero/punch_hole
53 void zero(uint64_t offset
, uint64_t len
);
55 /// update based on a zero/punch_hole
56 void clone_range(uint64_t offset
, uint64_t len
, uint64_t srcoff
, const SloppyCRCMap
& src
,
57 std::ostream
*out
= NULL
);
60 * validate a read result
62 * @param offset offset
63 * @param length length
65 * @param err option ostream to describe errors in detail
66 * @returns error count, 0 for success
68 int read(uint64_t offset
, uint64_t len
, const bufferlist
& bl
, std::ostream
*err
);
70 void encode(bufferlist
& bl
) const;
71 void decode(bufferlist::iterator
& bl
);
72 void dump(Formatter
*f
) const;
73 static void generate_test_instances(std::list
<SloppyCRCMap
*>& ls
);
75 WRITE_CLASS_ENCODER(SloppyCRCMap
)