rand: add 64-bit tausworthe variant with a 2^258 cycle
[fio.git] / verify.h
1 #ifndef FIO_VERIFY_H
2 #define FIO_VERIFY_H
3
4 #include <stdint.h>
5
6 #define FIO_HDR_MAGIC   0xacca
7
8 enum {
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 */
19         VERIFY_XXHASH,                  /* xxhash sum data blocks */
20         VERIFY_META,                    /* block_num, timestamp etc. */
21         VERIFY_SHA1,                    /* sha1 sum data blocks */
22         VERIFY_PATTERN,                 /* verify specific patterns */
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  */
31 struct verify_header {
32         uint16_t magic;
33         uint16_t verify_type;
34         uint32_t len;
35         uint64_t rand_seed;
36         uint32_t crc32;
37 };
38
39 struct vhdr_md5 {
40         uint32_t md5_digest[4];
41 };
42 struct vhdr_sha512 {
43         uint8_t sha512[128];
44 };
45 struct vhdr_sha256 {
46         uint8_t sha256[64];
47 };
48 struct vhdr_sha1 {
49         uint32_t sha1[5];
50 };
51 struct vhdr_crc64 {
52         uint64_t crc64;
53 };
54 struct vhdr_crc32 {
55         uint32_t crc32;
56 };
57 struct vhdr_crc16 {
58         uint16_t crc16;
59 };
60 struct vhdr_crc7 {
61         uint8_t crc7;
62 };
63 struct 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 };
70 struct vhdr_xxhash {
71         uint32_t hash;
72 };
73
74 /*
75  * Verify helpers
76  */
77 extern void populate_verify_io_u(struct thread_data *, struct io_u *);
78 extern int __must_check get_next_verify(struct thread_data *td, struct io_u *);
79 extern int __must_check verify_io_u(struct thread_data *, struct io_u **);
80 extern int verify_io_u_async(struct thread_data *, struct io_u **);
81 extern void fill_verify_pattern(struct thread_data *td, void *p, unsigned int len, struct io_u *io_u, unsigned long seed, int use_seed);
82 extern void fill_buffer_pattern(struct thread_data *td, void *p, unsigned int len);
83 extern void fio_verify_init(struct thread_data *td);
84
85 /*
86  * Async verify offload
87  */
88 extern int verify_async_init(struct thread_data *);
89 extern void verify_async_exit(struct thread_data *);
90
91 struct thread_rand32_state {
92         uint32_t s[4];
93 };
94
95 struct thread_rand64_state {
96         uint64_t s[6];
97 };
98
99 struct thread_rand_state {
100         uint64_t use64;
101         union {
102                 struct thread_rand32_state state32;
103                 struct thread_rand64_state state64;
104         };
105 };
106
107 /*
108  * For dumping current write state
109  */
110 struct thread_io_list {
111         uint64_t no_comps;
112         uint64_t depth;
113         uint64_t numberio;
114         uint64_t index;
115         struct thread_rand_state rand;
116         uint8_t name[64];
117         uint64_t offsets[0];
118 };
119
120 struct thread_io_list_v1 {
121         uint64_t no_comps;
122         uint64_t depth;
123         uint64_t numberio;
124         uint64_t index;
125         struct thread_rand32_state rand;
126         uint8_t name[64];
127         uint64_t offsets[0];
128 };
129
130 struct all_io_list {
131         uint64_t threads;
132         struct thread_io_list state[0];
133 };
134
135 #define VSTATE_HDR_VERSION_V1   0x01
136 #define VSTATE_HDR_VERSION      0x02
137
138 struct verify_state_hdr {
139         uint64_t version;
140         uint64_t size;
141         uint64_t crc;
142 };
143
144 #define IO_LIST_ALL             0xffffffff
145 extern struct all_io_list *get_all_io_list(int, size_t *);
146 extern void __verify_save_state(struct all_io_list *, const char *);
147 extern void verify_save_state(void);
148 extern int verify_load_state(struct thread_data *, const char *);
149 extern void verify_free_state(struct thread_data *);
150 extern int verify_state_should_stop(struct thread_data *, struct io_u *);
151 extern void verify_convert_assign_state(struct thread_data *, void *, int);
152 extern int verify_state_hdr(struct verify_state_hdr *, struct thread_io_list *,
153                                 int *);
154
155 static inline size_t __thread_io_list_sz(uint64_t depth)
156 {
157         return sizeof(struct thread_io_list) + depth * sizeof(uint64_t);
158 }
159
160 static inline size_t thread_io_list_sz(struct thread_io_list *s)
161 {
162         return __thread_io_list_sz(le64_to_cpu(s->depth));
163 }
164
165 static inline struct thread_io_list *io_list_next(struct thread_io_list *s)
166 {
167         return (void *) s + thread_io_list_sz(s);
168 }
169
170 static inline void verify_state_gen_name(char *out, size_t size,
171                                          const char *name, const char *prefix,
172                                          int num)
173 {
174         snprintf(out, size, "%s-%s-%d-verify.state", prefix, name, num);
175         out[size - 1] = '\0';
176 }
177
178 #endif