Fix wrong index bug
[fio.git] / verify.h
CommitLineData
4f5af7b2
JA
1#ifndef FIO_VERIFY_H
2#define FIO_VERIFY_H
3
03e20d68
BC
4#include <stdint.h>
5
d3a173a9 6#define FIO_HDR_MAGIC 0xacca
4f5af7b2
JA
7
8enum {
9 VERIFY_NONE = 0, /* no verification */
10 VERIFY_MD5, /* md5 sum data blocks */
11 VERIFY_CRC64, /* crc64 sum data blocks */
12 VERIFY_CRC32, /* crc32 sum data blocks */
13 VERIFY_CRC32C, /* crc32c sum data blocks */
14 VERIFY_CRC32C_INTEL, /* crc32c sum data blocks with hw */
15 VERIFY_CRC16, /* crc16 sum data blocks */
16 VERIFY_CRC7, /* crc7 sum data blocks */
17 VERIFY_SHA256, /* sha256 sum data blocks */
18 VERIFY_SHA512, /* sha512 sum data blocks */
844ea602 19 VERIFY_XXHASH, /* xxhash sum data blocks */
4f5af7b2 20 VERIFY_META, /* block_num, timestamp etc. */
7c353ceb 21 VERIFY_SHA1, /* sha1 sum data blocks */
92bf48d5 22 VERIFY_PATTERN, /* verify specific patterns */
4f5af7b2
JA
23 VERIFY_NULL, /* pretend to verify */
24};
25
26/*
27 * A header structure associated with each checksummed data block. It is
28 * followed by a checksum specific header that contains the verification
29 * data.
30 */
31struct verify_header {
d3a173a9
JA
32 uint16_t magic;
33 uint16_t verify_type;
f65d1c26 34 uint32_t len;
f65d1c26 35 uint64_t rand_seed;
f65d1c26 36 uint32_t crc32;
4f5af7b2
JA
37};
38
39struct vhdr_md5 {
34644af5 40 uint32_t md5_digest[4];
4f5af7b2
JA
41};
42struct vhdr_sha512 {
43 uint8_t sha512[128];
44};
45struct vhdr_sha256 {
bc77f56f 46 uint8_t sha256[64];
4f5af7b2 47};
7c353ceb
JA
48struct vhdr_sha1 {
49 uint32_t sha1[5];
50};
4f5af7b2
JA
51struct vhdr_crc64 {
52 uint64_t crc64;
53};
54struct vhdr_crc32 {
55 uint32_t crc32;
56};
57struct vhdr_crc16 {
58 uint16_t crc16;
59};
60struct vhdr_crc7 {
61 uint8_t crc7;
62};
63struct vhdr_meta {
64 uint64_t offset;
65 unsigned char thread;
66 unsigned short numberio;
67 unsigned long time_sec;
68 unsigned long time_usec;
69};
844ea602
JA
70struct vhdr_xxhash {
71 uint32_t hash;
72};
4f5af7b2
JA
73
74/*
75 * Verify helpers
76 */
77extern void populate_verify_io_u(struct thread_data *, struct io_u *);
78extern int __must_check get_next_verify(struct thread_data *td, struct io_u *);
f8b0bd10
JA
79extern int __must_check verify_io_u(struct thread_data *, struct io_u **);
80extern int verify_io_u_async(struct thread_data *, struct io_u **);
ce35b1ec
JA
81extern void fill_verify_pattern(struct thread_data *td, void *p, unsigned int len, struct io_u *io_u, unsigned long seed, int use_seed);
82extern void fill_buffer_pattern(struct thread_data *td, void *p, unsigned int len);
dc5bfbb2 83extern void fio_verify_init(struct thread_data *td);
e8462bd8
JA
84
85/*
86 * Async verify offload
87 */
88extern int verify_async_init(struct thread_data *);
89extern void verify_async_exit(struct thread_data *);
4f5af7b2 90
ca09be4b
JA
91struct thread_rand_state {
92 uint32_t s[4];
93};
94
95/*
96 * For dumping current write state
97 */
98struct thread_io_list {
99 uint64_t no_comps;
100 uint64_t depth;
101 uint64_t numberio;
102 uint64_t index;
103 struct thread_rand_state rand;
104 uint8_t name[64];
105 uint64_t offsets[0];
106};
107
108struct all_io_list {
109 uint64_t threads;
110 struct thread_io_list state[0];
111};
112
113#define VSTATE_HDR_VERSION 0x01
114
115struct verify_state_hdr {
116 uint64_t version;
117 uint64_t size;
118 uint64_t crc;
119};
120
121#define IO_LIST_ALL 0xffffffff
122extern struct all_io_list *get_all_io_list(int, size_t *);
123extern void __verify_save_state(struct all_io_list *, const char *);
124extern void verify_save_state(void);
125extern int verify_load_state(struct thread_data *, const char *);
126extern void verify_free_state(struct thread_data *);
127extern int verify_state_should_stop(struct thread_data *, struct io_u *);
128extern void verify_convert_assign_state(struct thread_data *, struct thread_io_list *);
129extern int verify_state_hdr(struct verify_state_hdr *, struct thread_io_list *);
130
131static inline size_t thread_io_list_sz(struct thread_io_list *s)
132{
133 return sizeof(*s) + le64_to_cpu(s->depth) * sizeof(uint64_t);
134}
135
136static inline struct thread_io_list *io_list_next(struct thread_io_list *s)
137{
138 return (void *) s + thread_io_list_sz(s);
139}
140
e499aedc
JA
141static inline void verify_state_gen_name(char *out, size_t size,
142 const char *name, const char *prefix,
143 int num)
ca09be4b 144{
e499aedc
JA
145 snprintf(out, size, "%s-%s-%d-verify.state", prefix, name, num);
146 out[size - 1] = '\0';
ca09be4b
JA
147}
148
4f5af7b2 149#endif