parser: get rid of FIO_OPT_STR_VAL_INT
[fio.git] / verify.c
CommitLineData
e29d1b70
JA
1/*
2 * IO verification helpers
3 */
4#include <unistd.h>
5#include <fcntl.h>
6#include <string.h>
97af62ce 7#include <assert.h>
e29d1b70
JA
8
9#include "fio.h"
4f5af7b2 10#include "verify.h"
e29d1b70 11
eef6eea1
JA
12#include "crc/md5.h"
13#include "crc/crc64.h"
14#include "crc/crc32.h"
bac39e0e 15#include "crc/crc32c.h"
eef6eea1
JA
16#include "crc/crc16.h"
17#include "crc/crc7.h"
18#include "crc/sha256.h"
19#include "crc/sha512.h"
cd14cc10 20
90059d65 21static void fill_random_bytes(struct thread_data *td, void *p, unsigned int len)
e29d1b70
JA
22{
23 unsigned int todo;
4c5946c6 24 int r;
e29d1b70
JA
25
26 while (len) {
4c5946c6 27 r = os_random_long(&td->verify_state);
e29d1b70
JA
28
29 /*
30 * lrand48_r seems to be broken and only fill the bottom
31 * 32-bits, even on 64-bit archs with 64-bit longs
32 */
33 todo = sizeof(r);
34 if (todo > len)
35 todo = len;
36
37 memcpy(p, &r, todo);
38
39 len -= todo;
40 p += todo;
41 }
42}
43
90059d65
JA
44static void fill_pattern(struct thread_data *td, void *p, unsigned int len)
45{
46 switch (td->o.verify_pattern_bytes) {
47 case 0:
bd6f78b2 48 dprint(FD_VERIFY, "fill random bytes len=%u\n", len);
90059d65
JA
49 fill_random_bytes(td, p, len);
50 break;
51 case 1:
bd6f78b2 52 dprint(FD_VERIFY, "fill verify pattern b=0 len=%u\n", len);
90059d65
JA
53 memset(p, td->o.verify_pattern, len);
54 break;
55 case 2:
56 case 3:
57 case 4: {
58 unsigned int pattern = td->o.verify_pattern;
59 unsigned int i = 0;
60 unsigned char c1, c2, c3, c4;
61 unsigned char *b = p;
62
bd6f78b2
JA
63 dprint(FD_VERIFY, "fill verify pattern b=%d len=%u\n",
64 td->o.verify_pattern_bytes, len);
65
90059d65
JA
66 c1 = pattern & 0xff;
67 pattern >>= 8;
68 c2 = pattern & 0xff;
69 pattern >>= 8;
70 c3 = pattern & 0xff;
71 pattern >>= 8;
72 c4 = pattern & 0xff;
73
74 while (i < len) {
75 b[i++] = c1;
76 if (i == len)
77 break;
78 b[i++] = c2;
79 if (td->o.verify_pattern_bytes == 2 || i == len)
80 continue;
81 b[i++] = c3;
82 if (td->o.verify_pattern_bytes == 3 || i == len)
83 continue;
84 b[i++] = c4;
85 }
86 break;
87 }
88 }
89}
90
4764aec9 91static void memswp(void *buf1, void *buf2, unsigned int len)
546a9142 92{
dee6de74
SL
93 char swap[200];
94
95 assert(len <= sizeof(swap));
90059d65 96
546a9142
SL
97 memcpy(&swap, buf1, len);
98 memcpy(buf1, buf2, len);
99 memcpy(buf2, &swap, len);
100}
101
e29d1b70
JA
102static void hexdump(void *buffer, int len)
103{
104 unsigned char *p = buffer;
105 int i;
106
107 for (i = 0; i < len; i++)
6d86144d
JA
108 log_info("%02x", p[i]);
109 log_info("\n");
e29d1b70
JA
110}
111
87677832
JA
112/*
113 * Prepare for seperation of verify_header and checksum header
114 */
546dfd9f 115static inline unsigned int __hdr_size(int verify_type)
87677832 116{
5921e80c 117 unsigned int len = len;
87677832 118
546dfd9f
JA
119 switch (verify_type) {
120 case VERIFY_NONE:
121 case VERIFY_NULL:
122 len = 0;
123 break;
124 case VERIFY_MD5:
125 len = sizeof(struct vhdr_md5);
126 break;
127 case VERIFY_CRC64:
128 len = sizeof(struct vhdr_crc64);
129 break;
bac39e0e 130 case VERIFY_CRC32C:
546dfd9f 131 case VERIFY_CRC32:
3845591f 132 case VERIFY_CRC32C_INTEL:
546dfd9f
JA
133 len = sizeof(struct vhdr_crc32);
134 break;
135 case VERIFY_CRC16:
136 len = sizeof(struct vhdr_crc16);
137 break;
138 case VERIFY_CRC7:
139 len = sizeof(struct vhdr_crc7);
140 break;
141 case VERIFY_SHA256:
142 len = sizeof(struct vhdr_sha256);
143 break;
144 case VERIFY_SHA512:
145 len = sizeof(struct vhdr_sha512);
146 break;
7437ee87
SL
147 case VERIFY_META:
148 len = sizeof(struct vhdr_meta);
149 break;
546dfd9f
JA
150 default:
151 log_err("fio: unknown verify header!\n");
152 assert(0);
153 }
154
155 return len + sizeof(struct verify_header);
87677832
JA
156}
157
158static inline unsigned int hdr_size(struct verify_header *hdr)
159{
546dfd9f
JA
160 return __hdr_size(hdr->verify_type);
161}
162
163static void *hdr_priv(struct verify_header *hdr)
164{
165 void *priv = hdr;
166
167 return priv + sizeof(struct verify_header);
87677832
JA
168}
169
d9f2caf3
JA
170/*
171 * Return data area 'header_num'
172 */
173static inline void *io_u_verify_off(struct verify_header *hdr,
5ec10eaa 174 struct io_u *io_u, unsigned char header_num)
d9f2caf3 175{
87677832 176 return io_u->buf + header_num * hdr->len + hdr_size(hdr);
d9f2caf3
JA
177}
178
7437ee87 179static int verify_io_u_meta(struct verify_header *hdr, struct thread_data *td,
5ec10eaa 180 struct io_u *io_u, unsigned int header_num)
7437ee87
SL
181{
182 struct vhdr_meta *vh = hdr_priv(hdr);
183
bd6f78b2
JA
184 dprint(FD_VERIFY, "meta verify io_u %p, len %u\n", io_u, hdr->len);
185
7437ee87
SL
186 if (vh->offset != io_u->offset + header_num * td->o.verify_interval) {
187 log_err("meta: verify failed at %llu/%u\n",
5ec10eaa 188 io_u->offset + header_num * hdr->len, hdr->len);
9fd18969 189 return EILSEQ;
7437ee87
SL
190 }
191
192 return 0;
193}
194
cd14cc10
JA
195static int verify_io_u_sha512(struct verify_header *hdr, struct io_u *io_u,
196 unsigned int header_num)
197{
198 void *p = io_u_verify_off(hdr, io_u, header_num);
546dfd9f 199 struct vhdr_sha512 *vh = hdr_priv(hdr);
cd14cc10
JA
200 uint8_t sha512[128];
201 struct sha512_ctx sha512_ctx = {
202 .buf = sha512,
203 };
204
bd6f78b2
JA
205 dprint(FD_VERIFY, "sha512 verify io_u %p, len %u\n", io_u, hdr->len);
206
cd14cc10 207 sha512_init(&sha512_ctx);
87677832 208 sha512_update(&sha512_ctx, p, hdr->len - hdr_size(hdr));
cd14cc10 209
546dfd9f 210 if (memcmp(vh->sha512, sha512_ctx.buf, sizeof(sha512))) {
cd14cc10 211 log_err("sha512: verify failed at %llu/%u\n",
5ec10eaa 212 io_u->offset + header_num * hdr->len, hdr->len);
546dfd9f 213 hexdump(vh->sha512, sizeof(vh->sha512));
cd14cc10 214 hexdump(sha512_ctx.buf, sizeof(sha512));
9fd18969 215 return EILSEQ;
cd14cc10
JA
216 }
217
218 return 0;
219}
220
221static int verify_io_u_sha256(struct verify_header *hdr, struct io_u *io_u,
222 unsigned int header_num)
223{
224 void *p = io_u_verify_off(hdr, io_u, header_num);
546dfd9f 225 struct vhdr_sha256 *vh = hdr_priv(hdr);
cd14cc10
JA
226 uint8_t sha256[128];
227 struct sha256_ctx sha256_ctx = {
228 .buf = sha256,
229 };
230
bd6f78b2
JA
231 dprint(FD_VERIFY, "sha256 verify io_u %p, len %u\n", io_u, hdr->len);
232
cd14cc10 233 sha256_init(&sha256_ctx);
87677832 234 sha256_update(&sha256_ctx, p, hdr->len - hdr_size(hdr));
cd14cc10 235
546dfd9f 236 if (memcmp(vh->sha256, sha256_ctx.buf, sizeof(sha256))) {
cd14cc10 237 log_err("sha256: verify failed at %llu/%u\n",
5ec10eaa 238 io_u->offset + header_num * hdr->len, hdr->len);
546dfd9f 239 hexdump(vh->sha256, sizeof(vh->sha256));
cd14cc10 240 hexdump(sha256_ctx.buf, sizeof(sha256));
9fd18969 241 return EILSEQ;
cd14cc10
JA
242 }
243
244 return 0;
245}
246
3f9f4e26 247static int verify_io_u_crc7(struct verify_header *hdr, struct io_u *io_u,
5ec10eaa 248 unsigned char header_num)
1e154bdb 249{
d9f2caf3 250 void *p = io_u_verify_off(hdr, io_u, header_num);
546dfd9f 251 struct vhdr_crc7 *vh = hdr_priv(hdr);
1e154bdb
JA
252 unsigned char c;
253
bd6f78b2
JA
254 dprint(FD_VERIFY, "crc7 verify io_u %p, len %u\n", io_u, hdr->len);
255
87677832 256 c = crc7(p, hdr->len - hdr_size(hdr));
1e154bdb 257
546dfd9f 258 if (c != vh->crc7) {
3f9f4e26 259 log_err("crc7: verify failed at %llu/%u\n",
5ec10eaa 260 io_u->offset + header_num * hdr->len, hdr->len);
546dfd9f 261 log_err("crc7: wanted %x, got %x\n", vh->crc7, c);
9fd18969 262 return EILSEQ;
1e154bdb
JA
263 }
264
265 return 0;
266}
267
3f9f4e26 268static int verify_io_u_crc16(struct verify_header *hdr, struct io_u *io_u,
5ec10eaa 269 unsigned int header_num)
969f7ed3 270{
d9f2caf3 271 void *p = io_u_verify_off(hdr, io_u, header_num);
546dfd9f 272 struct vhdr_crc16 *vh = hdr_priv(hdr);
969f7ed3
JA
273 unsigned short c;
274
bd6f78b2
JA
275 dprint(FD_VERIFY, "crc16 verify io_u %p, len %u\n", io_u, hdr->len);
276
87677832 277 c = crc16(p, hdr->len - hdr_size(hdr));
969f7ed3 278
546dfd9f 279 if (c != vh->crc16) {
3f9f4e26 280 log_err("crc16: verify failed at %llu/%u\n",
5ec10eaa 281 io_u->offset + header_num * hdr->len, hdr->len);
546dfd9f 282 log_err("crc16: wanted %x, got %x\n", vh->crc16, c);
9fd18969 283 return EILSEQ;
969f7ed3
JA
284 }
285
286 return 0;
287}
288
3f9f4e26 289static int verify_io_u_crc64(struct verify_header *hdr, struct io_u *io_u,
5ec10eaa 290 unsigned int header_num)
d77a7af3 291{
d9f2caf3 292 void *p = io_u_verify_off(hdr, io_u, header_num);
546dfd9f 293 struct vhdr_crc64 *vh = hdr_priv(hdr);
d77a7af3
JA
294 unsigned long long c;
295
bd6f78b2
JA
296 dprint(FD_VERIFY, "crc64 verify io_u %p, len %u\n", io_u, hdr->len);
297
87677832 298 c = crc64(p, hdr->len - hdr_size(hdr));
d77a7af3 299
546dfd9f 300 if (c != vh->crc64) {
3f9f4e26
SL
301 log_err("crc64: verify failed at %llu/%u\n",
302 io_u->offset + header_num * hdr->len,
303 hdr->len);
5ec10eaa
JA
304 log_err("crc64: wanted %llx, got %llx\n",
305 (unsigned long long) vh->crc64, c);
9fd18969 306 return EILSEQ;
d77a7af3
JA
307 }
308
309 return 0;
310}
311
3f9f4e26 312static int verify_io_u_crc32(struct verify_header *hdr, struct io_u *io_u,
5ec10eaa 313 unsigned int header_num)
e29d1b70 314{
d9f2caf3 315 void *p = io_u_verify_off(hdr, io_u, header_num);
546dfd9f
JA
316 struct vhdr_crc32 *vh = hdr_priv(hdr);
317 uint32_t c;
e29d1b70 318
bd6f78b2
JA
319 dprint(FD_VERIFY, "crc32 verify io_u %p, len %u\n", io_u, hdr->len);
320
87677832 321 c = crc32(p, hdr->len - hdr_size(hdr));
e29d1b70 322
546dfd9f 323 if (c != vh->crc32) {
3f9f4e26 324 log_err("crc32: verify failed at %llu/%u\n",
5ec10eaa 325 io_u->offset + header_num * hdr->len, hdr->len);
546dfd9f 326 log_err("crc32: wanted %x, got %x\n", vh->crc32, c);
9fd18969 327 return EILSEQ;
e29d1b70
JA
328 }
329
330 return 0;
331}
332
bac39e0e
JA
333static int verify_io_u_crc32c(struct verify_header *hdr, struct io_u *io_u,
334 unsigned int header_num)
335{
336 void *p = io_u_verify_off(hdr, io_u, header_num);
337 struct vhdr_crc32 *vh = hdr_priv(hdr);
338 uint32_t c;
339
340 dprint(FD_VERIFY, "crc32c verify io_u %p, len %u\n", io_u, hdr->len);
341
3845591f
JA
342 if (hdr->verify_type == VERIFY_CRC32C_INTEL)
343 c = crc32c_intel(p, hdr->len - hdr_size(hdr));
344 else
345 c = crc32c(p, hdr->len - hdr_size(hdr));
bac39e0e
JA
346
347 if (c != vh->crc32) {
348 log_err("crc32c: verify failed at %llu/%u\n",
349 io_u->offset + header_num * hdr->len, hdr->len);
350 log_err("crc32c: wanted %x, got %x\n", vh->crc32, c);
9fd18969 351 return EILSEQ;
bac39e0e
JA
352 }
353
354 return 0;
355}
356
3f9f4e26 357static int verify_io_u_md5(struct verify_header *hdr, struct io_u *io_u,
5ec10eaa 358 unsigned int header_num)
e29d1b70 359{
d9f2caf3 360 void *p = io_u_verify_off(hdr, io_u, header_num);
546dfd9f 361 struct vhdr_md5 *vh = hdr_priv(hdr);
8c432325
JA
362 uint32_t hash[MD5_HASH_WORDS];
363 struct md5_ctx md5_ctx = {
364 .hash = hash,
365 };
e29d1b70 366
bd6f78b2
JA
367 dprint(FD_VERIFY, "md5 verify io_u %p, len %u\n", io_u, hdr->len);
368
61f821f1 369 md5_init(&md5_ctx);
87677832 370 md5_update(&md5_ctx, p, hdr->len - hdr_size(hdr));
e29d1b70 371
546dfd9f 372 if (memcmp(vh->md5_digest, md5_ctx.hash, sizeof(hash))) {
3f9f4e26 373 log_err("md5: verify failed at %llu/%u\n",
5ec10eaa 374 io_u->offset + header_num * hdr->len, hdr->len);
546dfd9f 375 hexdump(vh->md5_digest, sizeof(vh->md5_digest));
8c432325 376 hexdump(md5_ctx.hash, sizeof(hash));
9fd18969 377 return EILSEQ;
e29d1b70
JA
378 }
379
380 return 0;
381}
382
3f199b01
JA
383static unsigned int hweight8(unsigned int w)
384{
385 unsigned int res = w - ((w >> 1) & 0x55);
386
387 res = (res & 0x33) + ((res >> 2) & 0x33);
388 return (res + (res >> 4)) & 0x0F;
389}
390
a944e335 391int verify_io_u_pattern(unsigned long pattern, unsigned long pattern_size,
5ec10eaa 392 char *buf, unsigned int len, unsigned int mod)
a944e335
SL
393{
394 unsigned int i;
395 char split_pattern[4];
396
397 for (i = 0; i < 4; i++) {
398 split_pattern[i] = pattern & 0xff;
399 pattern >>= 8;
400 }
401
402 for (i = 0; i < len; i++) {
3f199b01
JA
403 if (buf[i] != split_pattern[mod]) {
404 unsigned int bits;
405
406 bits = hweight8(buf[i] ^ split_pattern[mod]);
407 log_err("fio: got pattern %x, wanted %x. Bad bits %d\n",
408 buf[i], split_pattern[mod], bits);
409 log_err("fio: bad pattern block offset %u\n", i);
9fd18969 410 return EILSEQ;
3f199b01 411 }
a944e335
SL
412 mod++;
413 if (mod == pattern_size)
414 mod = 0;
415 }
416
417 return 0;
418}
419
36690c9b 420int verify_io_u(struct thread_data *td, struct io_u *io_u)
e29d1b70 421{
3f9f4e26 422 struct verify_header *hdr;
a944e335 423 unsigned int hdr_size, hdr_inc, hdr_num = 0;
95646108 424 void *p;
e29d1b70
JA
425 int ret;
426
1dcc0498 427 if (td->o.verify == VERIFY_NULL || io_u->ddir != DDIR_READ)
36690c9b
JA
428 return 0;
429
3f9f4e26 430 hdr_inc = io_u->buflen;
a59e170d
JA
431 if (td->o.verify_interval)
432 hdr_inc = td->o.verify_interval;
e29d1b70 433
a12a3b4d 434 ret = 0;
5ec10eaa
JA
435 for (p = io_u->buf; p < io_u->buf + io_u->buflen;
436 p += hdr_inc, hdr_num++) {
a12a3b4d
JA
437 if (ret && td->o.verify_fatal) {
438 td->terminate = 1;
439 break;
440 }
a944e335 441 hdr_size = __hdr_size(td->o.verify);
a59e170d 442 if (td->o.verify_offset)
a944e335 443 memswp(p, p + td->o.verify_offset, hdr_size);
95646108 444 hdr = p;
e29d1b70 445
3f199b01
JA
446 if (hdr->fio_magic != FIO_HDR_MAGIC) {
447 log_err("Bad verify header %x\n", hdr->fio_magic);
9fd18969 448 return EILSEQ;
3f199b01
JA
449 }
450
e28218f3 451 if (td->o.verify_pattern_bytes) {
bd6f78b2
JA
452 dprint(FD_VERIFY, "pattern verify io_u %p, len %u\n",
453 io_u, hdr->len);
e28218f3 454 ret = verify_io_u_pattern(td->o.verify_pattern,
5ec10eaa
JA
455 td->o.verify_pattern_bytes,
456 p + hdr_size,
457 hdr_inc - hdr_size,
458 hdr_size % 4);
e28218f3
SL
459 if (ret)
460 log_err("fio: verify failed at %llu/%u\n",
461 io_u->offset + hdr_num * hdr->len,
462 hdr->len);
463 continue;
464 }
465
3f9f4e26
SL
466 switch (hdr->verify_type) {
467 case VERIFY_MD5:
468 ret = verify_io_u_md5(hdr, io_u, hdr_num);
469 break;
470 case VERIFY_CRC64:
471 ret = verify_io_u_crc64(hdr, io_u, hdr_num);
472 break;
bac39e0e 473 case VERIFY_CRC32C:
3845591f 474 case VERIFY_CRC32C_INTEL:
bac39e0e
JA
475 ret = verify_io_u_crc32c(hdr, io_u, hdr_num);
476 break;
3f9f4e26
SL
477 case VERIFY_CRC32:
478 ret = verify_io_u_crc32(hdr, io_u, hdr_num);
479 break;
480 case VERIFY_CRC16:
481 ret = verify_io_u_crc16(hdr, io_u, hdr_num);
482 break;
483 case VERIFY_CRC7:
484 ret = verify_io_u_crc7(hdr, io_u, hdr_num);
485 break;
cd14cc10
JA
486 case VERIFY_SHA256:
487 ret = verify_io_u_sha256(hdr, io_u, hdr_num);
488 break;
489 case VERIFY_SHA512:
490 ret = verify_io_u_sha512(hdr, io_u, hdr_num);
491 break;
7437ee87
SL
492 case VERIFY_META:
493 ret = verify_io_u_meta(hdr, td, io_u, hdr_num);
494 break;
3f9f4e26
SL
495 default:
496 log_err("Bad verify type %u\n", hdr->verify_type);
d16d4e09 497 ret = EINVAL;
3f9f4e26 498 }
3f9f4e26 499 }
a7dfe862 500
a12a3b4d 501 return ret;
e29d1b70
JA
502}
503
7437ee87 504static void fill_meta(struct verify_header *hdr, struct thread_data *td,
5ec10eaa 505 struct io_u *io_u, unsigned int header_num)
7437ee87
SL
506{
507 struct vhdr_meta *vh = hdr_priv(hdr);
508
509 vh->thread = td->thread_number;
510
511 vh->time_sec = io_u->start_time.tv_sec;
512 vh->time_usec = io_u->start_time.tv_usec;
513
514 vh->numberio = td->io_issues[DDIR_WRITE];
515
516 vh->offset = io_u->offset + header_num * td->o.verify_interval;
517}
518
cd14cc10
JA
519static void fill_sha512(struct verify_header *hdr, void *p, unsigned int len)
520{
546dfd9f 521 struct vhdr_sha512 *vh = hdr_priv(hdr);
cd14cc10 522 struct sha512_ctx sha512_ctx = {
546dfd9f 523 .buf = vh->sha512,
cd14cc10
JA
524 };
525
526 sha512_init(&sha512_ctx);
527 sha512_update(&sha512_ctx, p, len);
528}
529
530static void fill_sha256(struct verify_header *hdr, void *p, unsigned int len)
531{
546dfd9f 532 struct vhdr_sha256 *vh = hdr_priv(hdr);
cd14cc10 533 struct sha256_ctx sha256_ctx = {
546dfd9f 534 .buf = vh->sha256,
cd14cc10
JA
535 };
536
537 sha256_init(&sha256_ctx);
538 sha256_update(&sha256_ctx, p, len);
539}
540
1e154bdb
JA
541static void fill_crc7(struct verify_header *hdr, void *p, unsigned int len)
542{
546dfd9f
JA
543 struct vhdr_crc7 *vh = hdr_priv(hdr);
544
545 vh->crc7 = crc7(p, len);
1e154bdb
JA
546}
547
969f7ed3
JA
548static void fill_crc16(struct verify_header *hdr, void *p, unsigned int len)
549{
546dfd9f
JA
550 struct vhdr_crc16 *vh = hdr_priv(hdr);
551
552 vh->crc16 = crc16(p, len);
969f7ed3
JA
553}
554
e29d1b70
JA
555static void fill_crc32(struct verify_header *hdr, void *p, unsigned int len)
556{
546dfd9f
JA
557 struct vhdr_crc32 *vh = hdr_priv(hdr);
558
559 vh->crc32 = crc32(p, len);
e29d1b70
JA
560}
561
bac39e0e
JA
562static void fill_crc32c(struct verify_header *hdr, void *p, unsigned int len)
563{
564 struct vhdr_crc32 *vh = hdr_priv(hdr);
565
3845591f
JA
566 if (hdr->verify_type == VERIFY_CRC32C_INTEL)
567 vh->crc32 = crc32c_intel(p, len);
568 else
569 vh->crc32 = crc32c(p, len);
bac39e0e
JA
570}
571
d77a7af3
JA
572static void fill_crc64(struct verify_header *hdr, void *p, unsigned int len)
573{
546dfd9f
JA
574 struct vhdr_crc64 *vh = hdr_priv(hdr);
575
576 vh->crc64 = crc64(p, len);
d77a7af3
JA
577}
578
e29d1b70
JA
579static void fill_md5(struct verify_header *hdr, void *p, unsigned int len)
580{
546dfd9f 581 struct vhdr_md5 *vh = hdr_priv(hdr);
8c432325 582 struct md5_ctx md5_ctx = {
546dfd9f 583 .hash = (uint32_t *) vh->md5_digest,
8c432325 584 };
e29d1b70 585
61f821f1 586 md5_init(&md5_ctx);
e29d1b70 587 md5_update(&md5_ctx, p, len);
e29d1b70
JA
588}
589
590/*
591 * fill body of io_u->buf with random data and add a header with the
592 * crc32 or md5 sum of that data.
593 */
594void populate_verify_io_u(struct thread_data *td, struct io_u *io_u)
595{
baefa9be 596 struct verify_header *hdr;
95646108 597 void *p = io_u->buf, *data;
7437ee87 598 unsigned int hdr_inc, data_len, header_num = 0;
e29d1b70 599
9cc3d150
JA
600 if (td->o.verify == VERIFY_NULL)
601 return;
602
90059d65 603 fill_pattern(td, p, io_u->buflen);
546a9142
SL
604
605 hdr_inc = io_u->buflen;
a59e170d
JA
606 if (td->o.verify_interval)
607 hdr_inc = td->o.verify_interval;
baefa9be 608
5ec10eaa 609 for (; p < io_u->buf + io_u->buflen; p += hdr_inc) {
95646108 610 hdr = p;
3f9f4e26
SL
611
612 hdr->fio_magic = FIO_HDR_MAGIC;
613 hdr->verify_type = td->o.verify;
546a9142 614 hdr->len = hdr_inc;
87677832 615 data_len = hdr_inc - hdr_size(hdr);
3f9f4e26 616
87677832 617 data = p + hdr_size(hdr);
3f9f4e26
SL
618 switch (td->o.verify) {
619 case VERIFY_MD5:
bd6f78b2
JA
620 dprint(FD_VERIFY, "fill md5 io_u %p, len %u\n",
621 io_u, hdr->len);
3f9f4e26
SL
622 fill_md5(hdr, data, data_len);
623 break;
624 case VERIFY_CRC64:
bd6f78b2
JA
625 dprint(FD_VERIFY, "fill crc64 io_u %p, len %u\n",
626 io_u, hdr->len);
3f9f4e26
SL
627 fill_crc64(hdr, data, data_len);
628 break;
bac39e0e 629 case VERIFY_CRC32C:
3845591f 630 case VERIFY_CRC32C_INTEL:
bac39e0e
JA
631 dprint(FD_VERIFY, "fill crc32c io_u %p, len %u\n",
632 io_u, hdr->len);
633 fill_crc32c(hdr, data, data_len);
634 break;
3f9f4e26 635 case VERIFY_CRC32:
bd6f78b2
JA
636 dprint(FD_VERIFY, "fill crc32 io_u %p, len %u\n",
637 io_u, hdr->len);
3f9f4e26
SL
638 fill_crc32(hdr, data, data_len);
639 break;
640 case VERIFY_CRC16:
bd6f78b2
JA
641 dprint(FD_VERIFY, "fill crc16 io_u %p, len %u\n",
642 io_u, hdr->len);
3f9f4e26
SL
643 fill_crc16(hdr, data, data_len);
644 break;
645 case VERIFY_CRC7:
bd6f78b2
JA
646 dprint(FD_VERIFY, "fill crc7 io_u %p, len %u\n",
647 io_u, hdr->len);
3f9f4e26
SL
648 fill_crc7(hdr, data, data_len);
649 break;
cd14cc10 650 case VERIFY_SHA256:
bd6f78b2
JA
651 dprint(FD_VERIFY, "fill sha256 io_u %p, len %u\n",
652 io_u, hdr->len);
cd14cc10
JA
653 fill_sha256(hdr, data, data_len);
654 break;
655 case VERIFY_SHA512:
bd6f78b2
JA
656 dprint(FD_VERIFY, "fill sha512 io_u %p, len %u\n",
657 io_u, hdr->len);
cd14cc10
JA
658 fill_sha512(hdr, data, data_len);
659 break;
7437ee87 660 case VERIFY_META:
bd6f78b2
JA
661 dprint(FD_VERIFY, "fill meta io_u %p, len %u\n",
662 io_u, hdr->len);
7437ee87
SL
663 fill_meta(hdr, td, io_u, header_num);
664 break;
3f9f4e26
SL
665 default:
666 log_err("fio: bad verify type: %d\n", td->o.verify);
667 assert(0);
668 }
a59e170d 669 if (td->o.verify_offset)
87677832 670 memswp(p, p + td->o.verify_offset, hdr_size(hdr));
7437ee87 671 header_num++;
e29d1b70 672 }
e29d1b70
JA
673}
674
675int get_next_verify(struct thread_data *td, struct io_u *io_u)
676{
8de8f047 677 struct io_piece *ipo = NULL;
e29d1b70 678
d2d7fa53
JA
679 /*
680 * this io_u is from a requeue, we already filled the offsets
681 */
682 if (io_u->file)
683 return 0;
684
8de8f047
JA
685 if (!RB_EMPTY_ROOT(&td->io_hist_tree)) {
686 struct rb_node *n = rb_first(&td->io_hist_tree);
e29d1b70 687
8de8f047 688 ipo = rb_entry(n, struct io_piece, rb_node);
4b87898e 689 rb_erase(n, &td->io_hist_tree);
01743ee1
JA
690 } else if (!flist_empty(&td->io_hist_list)) {
691 ipo = flist_entry(td->io_hist_list.next, struct io_piece, list);
692 flist_del(&ipo->list);
8de8f047 693 }
e29d1b70 694
8de8f047 695 if (ipo) {
e29d1b70
JA
696 io_u->offset = ipo->offset;
697 io_u->buflen = ipo->len;
36167d82 698 io_u->file = ipo->file;
97af62ce 699
d6aed795 700 if (!fio_file_open(io_u->file)) {
97af62ce
JA
701 int r = td_io_open_file(td, io_u->file);
702
bd6f78b2
JA
703 if (r) {
704 dprint(FD_VERIFY, "failed file %s open\n",
705 io_u->file->file_name);
97af62ce 706 return 1;
bd6f78b2 707 }
97af62ce
JA
708 }
709
710 get_file(ipo->file);
d6aed795 711 assert(fio_file_open(io_u->file));
e29d1b70 712 io_u->ddir = DDIR_READ;
36167d82
JA
713 io_u->xfer_buf = io_u->buf;
714 io_u->xfer_buflen = io_u->buflen;
e29d1b70 715 free(ipo);
bd6f78b2 716 dprint(FD_VERIFY, "get_next_verify: ret io_u %p\n", io_u);
e29d1b70
JA
717 return 0;
718 }
719
bd6f78b2 720 dprint(FD_VERIFY, "get_next_verify: empty\n");
e29d1b70
JA
721 return 1;
722}