2 * IO verification helpers
17 #include "crc/crc64.h"
18 #include "crc/crc32.h"
19 #include "crc/crc32c.h"
20 #include "crc/crc16.h"
22 #include "crc/sha256.h"
23 #include "crc/sha512.h"
26 static void populate_hdr(struct thread_data *td, struct io_u *io_u,
27 struct verify_header *hdr, unsigned int header_num,
28 unsigned int header_len);
30 void fill_pattern(struct thread_data *td, void *p, unsigned int len, struct io_u *io_u, unsigned long seed, int use_seed)
32 switch (td->o.verify_pattern_bytes) {
34 dprint(FD_VERIFY, "fill random bytes len=%u\n", len);
36 __fill_random_buf(p, len, seed);
38 io_u->rand_seed = fill_random_buf(p, len);
41 if (io_u->buf_filled_len >= len) {
42 dprint(FD_VERIFY, "using already filled verify pattern b=0 len=%u\n", len);
45 dprint(FD_VERIFY, "fill verify pattern b=0 len=%u\n", len);
46 memset(p, td->o.verify_pattern[0], len);
47 io_u->buf_filled_len = len;
50 unsigned int i = 0, size = 0;
53 if (io_u->buf_filled_len >= len) {
54 dprint(FD_VERIFY, "using already filled verify pattern b=%d len=%u\n",
55 td->o.verify_pattern_bytes, len);
58 dprint(FD_VERIFY, "fill verify pattern b=%d len=%u\n",
59 td->o.verify_pattern_bytes, len);
62 size = td->o.verify_pattern_bytes;
65 memcpy(b+i, td->o.verify_pattern, size);
68 io_u->buf_filled_len = len;
74 static void memswp(void *buf1, void *buf2, unsigned int len)
78 assert(len <= sizeof(swap));
80 memcpy(&swap, buf1, len);
81 memcpy(buf1, buf2, len);
82 memcpy(buf2, &swap, len);
85 static void hexdump(void *buffer, int len)
87 unsigned char *p = buffer;
90 for (i = 0; i < len; i++)
91 log_err("%02x", p[i]);
96 * Prepare for seperation of verify_header and checksum header
98 static inline unsigned int __hdr_size(int verify_type)
100 unsigned int len = 0;
102 switch (verify_type) {
108 len = sizeof(struct vhdr_md5);
111 len = sizeof(struct vhdr_crc64);
115 case VERIFY_CRC32C_INTEL:
116 len = sizeof(struct vhdr_crc32);
119 len = sizeof(struct vhdr_crc16);
122 len = sizeof(struct vhdr_crc7);
125 len = sizeof(struct vhdr_sha256);
128 len = sizeof(struct vhdr_sha512);
131 len = sizeof(struct vhdr_meta);
134 len = sizeof(struct vhdr_sha1);
137 log_err("fio: unknown verify header!\n");
141 return len + sizeof(struct verify_header);
144 static inline unsigned int hdr_size(struct verify_header *hdr)
146 return __hdr_size(hdr->verify_type);
149 static void *hdr_priv(struct verify_header *hdr)
153 return priv + sizeof(struct verify_header);
157 * Verify container, pass info to verify handlers and allow them to
158 * pass info back in case of error
165 unsigned int hdr_num;
166 struct thread_data *td;
169 * Output, only valid in case of error
174 unsigned int crc_len;
177 static void dump_buf(char *buf, unsigned int len, const char *name,
178 unsigned long long offset)
183 sprintf(fname, "%llu.%s", offset, name);
185 fd = open(fname, O_CREAT | O_TRUNC | O_WRONLY, 0644);
187 perror("open verify buf file");
192 ret = write(fd, buf, len);
196 perror("write verify buf file");
204 log_err(" %s data dumped as %s\n", name, fname);
207 static void dump_verify_buffers(struct verify_header *hdr, struct vcont *vc)
209 struct thread_data *td = vc->td;
210 struct io_u *io_u = vc->io_u;
211 unsigned long hdr_offset;
212 unsigned int hdr_inc, header_num;
216 hdr_offset = vc->hdr_num * hdr->len;
218 dump_buf(io_u->buf + hdr_offset, hdr->len, "received",
219 io_u->offset + hdr_offset);
221 buf = p = malloc(io_u->buflen);
223 fill_pattern(td, p, io_u->buflen, &dummy, hdr->rand_seed, 1);
225 hdr_inc = io_u->buflen;
226 if (td->o.verify_interval)
227 hdr_inc = td->o.verify_interval;
230 for (; p < buf + io_u->buflen; p += hdr_inc) {
232 populate_hdr(td, io_u, hdr, header_num, hdr_inc);
236 dump_buf(buf + hdr_offset, hdr->len, "expected",
237 io_u->offset + hdr_offset);
241 static void log_verify_failure(struct verify_header *hdr, struct vcont *vc)
243 unsigned long long offset;
245 offset = vc->io_u->offset;
246 offset += vc->hdr_num * hdr->len;
247 log_err("%.8s: verify failed at file %s offset %llu, length %u\n",
248 vc->name, vc->io_u->file->file_name, offset, hdr->len);
250 if (vc->good_crc && vc->bad_crc) {
251 log_err(" Expected CRC: ");
252 hexdump(vc->good_crc, vc->crc_len);
253 log_err(" Received CRC: ");
254 hexdump(vc->bad_crc, vc->crc_len);
257 dump_verify_buffers(hdr, vc);
261 * Return data area 'header_num'
263 static inline void *io_u_verify_off(struct verify_header *hdr, struct vcont *vc)
265 return vc->io_u->buf + vc->hdr_num * hdr->len + hdr_size(hdr);
268 static int verify_io_u_meta(struct verify_header *hdr, struct thread_data *td,
271 struct vhdr_meta *vh = hdr_priv(hdr);
272 struct io_u *io_u = vc->io_u;
274 dprint(FD_VERIFY, "meta verify io_u %p, len %u\n", io_u, hdr->len);
276 if (vh->offset == io_u->offset + vc->hdr_num * td->o.verify_interval)
280 log_verify_failure(hdr, vc);
284 static int verify_io_u_sha512(struct verify_header *hdr, struct vcont *vc)
286 void *p = io_u_verify_off(hdr, vc);
287 struct vhdr_sha512 *vh = hdr_priv(hdr);
289 struct sha512_ctx sha512_ctx = {
293 dprint(FD_VERIFY, "sha512 verify io_u %p, len %u\n", vc->io_u, hdr->len);
295 sha512_init(&sha512_ctx);
296 sha512_update(&sha512_ctx, p, hdr->len - hdr_size(hdr));
298 if (!memcmp(vh->sha512, sha512_ctx.buf, sizeof(sha512)))
302 vc->good_crc = vh->sha512;
303 vc->bad_crc = sha512_ctx.buf;
304 vc->crc_len = sizeof(vh->sha512);
305 log_verify_failure(hdr, vc);
309 static int verify_io_u_sha256(struct verify_header *hdr, struct vcont *vc)
311 void *p = io_u_verify_off(hdr, vc);
312 struct vhdr_sha256 *vh = hdr_priv(hdr);
314 struct sha256_ctx sha256_ctx = {
318 dprint(FD_VERIFY, "sha256 verify io_u %p, len %u\n", vc->io_u, hdr->len);
320 sha256_init(&sha256_ctx);
321 sha256_update(&sha256_ctx, p, hdr->len - hdr_size(hdr));
323 if (!memcmp(vh->sha256, sha256_ctx.buf, sizeof(sha256)))
327 vc->good_crc = vh->sha256;
328 vc->bad_crc = sha256_ctx.buf;
329 vc->crc_len = sizeof(vh->sha256);
330 log_verify_failure(hdr, vc);
334 static int verify_io_u_sha1(struct verify_header *hdr, struct vcont *vc)
336 void *p = io_u_verify_off(hdr, vc);
337 struct vhdr_sha1 *vh = hdr_priv(hdr);
339 struct sha1_ctx sha1_ctx = {
343 dprint(FD_VERIFY, "sha1 verify io_u %p, len %u\n", vc->io_u, hdr->len);
345 sha1_init(&sha1_ctx);
346 sha1_update(&sha1_ctx, p, hdr->len - hdr_size(hdr));
348 if (!memcmp(vh->sha1, sha1_ctx.H, sizeof(sha1)))
352 vc->good_crc = vh->sha1;
353 vc->bad_crc = sha1_ctx.H;
354 vc->crc_len = sizeof(vh->sha1);
355 log_verify_failure(hdr, vc);
359 static int verify_io_u_crc7(struct verify_header *hdr, struct vcont *vc)
361 void *p = io_u_verify_off(hdr, vc);
362 struct vhdr_crc7 *vh = hdr_priv(hdr);
365 dprint(FD_VERIFY, "crc7 verify io_u %p, len %u\n", vc->io_u, hdr->len);
367 c = crc7(p, hdr->len - hdr_size(hdr));
373 vc->good_crc = &vh->crc7;
376 log_verify_failure(hdr, vc);
380 static int verify_io_u_crc16(struct verify_header *hdr, struct vcont *vc)
382 void *p = io_u_verify_off(hdr, vc);
383 struct vhdr_crc16 *vh = hdr_priv(hdr);
386 dprint(FD_VERIFY, "crc16 verify io_u %p, len %u\n", vc->io_u, hdr->len);
388 c = crc16(p, hdr->len - hdr_size(hdr));
394 vc->good_crc = &vh->crc16;
397 log_verify_failure(hdr, vc);
401 static int verify_io_u_crc64(struct verify_header *hdr, struct vcont *vc)
403 void *p = io_u_verify_off(hdr, vc);
404 struct vhdr_crc64 *vh = hdr_priv(hdr);
405 unsigned long long c;
407 dprint(FD_VERIFY, "crc64 verify io_u %p, len %u\n", vc->io_u, hdr->len);
409 c = crc64(p, hdr->len - hdr_size(hdr));
415 vc->good_crc = &vh->crc64;
418 log_verify_failure(hdr, vc);
422 static int verify_io_u_crc32(struct verify_header *hdr, struct vcont *vc)
424 void *p = io_u_verify_off(hdr, vc);
425 struct vhdr_crc32 *vh = hdr_priv(hdr);
428 dprint(FD_VERIFY, "crc32 verify io_u %p, len %u\n", vc->io_u, hdr->len);
430 c = crc32(p, hdr->len - hdr_size(hdr));
436 vc->good_crc = &vh->crc32;
439 log_verify_failure(hdr, vc);
443 static int verify_io_u_crc32c(struct verify_header *hdr, struct vcont *vc)
445 void *p = io_u_verify_off(hdr, vc);
446 struct vhdr_crc32 *vh = hdr_priv(hdr);
449 dprint(FD_VERIFY, "crc32c verify io_u %p, len %u\n", vc->io_u, hdr->len);
451 if (hdr->verify_type == VERIFY_CRC32C_INTEL)
452 c = crc32c_intel(p, hdr->len - hdr_size(hdr));
454 c = crc32c(p, hdr->len - hdr_size(hdr));
460 vc->good_crc = &vh->crc32;
463 log_verify_failure(hdr, vc);
467 static int verify_io_u_md5(struct verify_header *hdr, struct vcont *vc)
469 void *p = io_u_verify_off(hdr, vc);
470 struct vhdr_md5 *vh = hdr_priv(hdr);
471 uint32_t hash[MD5_HASH_WORDS];
472 struct md5_ctx md5_ctx = {
476 dprint(FD_VERIFY, "md5 verify io_u %p, len %u\n", vc->io_u, hdr->len);
479 md5_update(&md5_ctx, p, hdr->len - hdr_size(hdr));
481 if (!memcmp(vh->md5_digest, md5_ctx.hash, sizeof(hash)))
485 vc->good_crc = vh->md5_digest;
486 vc->bad_crc = md5_ctx.hash;
487 vc->crc_len = sizeof(hash);
488 log_verify_failure(hdr, vc);
492 static unsigned int hweight8(unsigned int w)
494 unsigned int res = w - ((w >> 1) & 0x55);
496 res = (res & 0x33) + ((res >> 2) & 0x33);
497 return (res + (res >> 4)) & 0x0F;
500 int verify_io_u_pattern(char *pattern, unsigned long pattern_size,
501 char *buf, unsigned int len, unsigned int mod)
505 for (i = 0; i < len; i++) {
506 if (buf[i] != pattern[mod]) {
509 bits = hweight8(buf[i] ^ pattern[mod]);
510 log_err("fio: got pattern %x, wanted %x. Bad bits %d\n",
511 buf[i], pattern[mod], bits);
512 log_err("fio: bad pattern block offset %u\n", i);
516 if (mod == pattern_size)
524 * Push IO verification to a separate thread
526 int verify_io_u_async(struct thread_data *td, struct io_u *io_u)
529 put_file_log(td, io_u->file);
533 pthread_mutex_lock(&td->io_u_lock);
535 if (io_u->flags & IO_U_F_IN_CUR_DEPTH) {
537 io_u->flags &= ~IO_U_F_IN_CUR_DEPTH;
539 flist_del(&io_u->list);
540 flist_add_tail(&io_u->list, &td->verify_list);
541 io_u->flags |= IO_U_F_FREE_DEF;
542 pthread_mutex_unlock(&td->io_u_lock);
544 pthread_cond_signal(&td->verify_cond);
548 static int verify_trimmed_io_u(struct thread_data *td, struct io_u *io_u)
550 static char zero_buf[1024];
551 unsigned int this_len, len;
555 if (!td->o.trim_zero)
561 this_len = sizeof(zero_buf);
564 if (memcmp(p, zero_buf, this_len)) {
575 log_err("trim: verify failed at file %s offset %llu, length %lu"
576 ", block offset %lu\n",
577 io_u->file->file_name, io_u->offset, io_u->buflen,
578 (unsigned long) (p - io_u->buf));
582 int verify_io_u(struct thread_data *td, struct io_u *io_u)
584 struct verify_header *hdr;
585 unsigned int hdr_size, hdr_inc, hdr_num = 0;
589 if (td->o.verify == VERIFY_NULL || io_u->ddir != DDIR_READ)
591 if (io_u->flags & IO_U_F_TRIMMED) {
592 ret = verify_trimmed_io_u(td, io_u);
596 hdr_inc = io_u->buflen;
597 if (td->o.verify_interval)
598 hdr_inc = td->o.verify_interval;
601 for (p = io_u->buf; p < io_u->buf + io_u->buflen;
602 p += hdr_inc, hdr_num++) {
609 if (ret && td->o.verify_fatal)
612 hdr_size = __hdr_size(td->o.verify);
613 if (td->o.verify_offset)
614 memswp(p, p + td->o.verify_offset, hdr_size);
617 if (hdr->fio_magic != FIO_HDR_MAGIC) {
618 log_err("verify: bad magic header %x, wanted %x at file %s offset %llu, length %u\n",
619 hdr->fio_magic, FIO_HDR_MAGIC,
620 io_u->file->file_name,
621 io_u->offset + hdr_num * hdr->len, hdr->len);
625 if (td->o.verify_pattern_bytes) {
626 dprint(FD_VERIFY, "pattern verify io_u %p, len %u\n",
628 ret = verify_io_u_pattern(td->o.verify_pattern,
629 td->o.verify_pattern_bytes,
632 hdr_size % td->o.verify_pattern_bytes);
635 log_err("pattern: verify failed at file %s offset %llu, length %u\n",
636 io_u->file->file_name,
637 io_u->offset + hdr_num * hdr->len,
642 * Also verify the meta data, if applicable
644 if (hdr->verify_type == VERIFY_META)
645 ret |= verify_io_u_meta(hdr, td, &vc);
649 switch (hdr->verify_type) {
651 ret = verify_io_u_md5(hdr, &vc);
654 ret = verify_io_u_crc64(hdr, &vc);
657 case VERIFY_CRC32C_INTEL:
658 ret = verify_io_u_crc32c(hdr, &vc);
661 ret = verify_io_u_crc32(hdr, &vc);
664 ret = verify_io_u_crc16(hdr, &vc);
667 ret = verify_io_u_crc7(hdr, &vc);
670 ret = verify_io_u_sha256(hdr, &vc);
673 ret = verify_io_u_sha512(hdr, &vc);
676 ret = verify_io_u_meta(hdr, td, &vc);
679 ret = verify_io_u_sha1(hdr, &vc);
682 log_err("Bad verify type %u\n", hdr->verify_type);
688 if (ret && td->o.verify_fatal)
694 static void fill_meta(struct verify_header *hdr, struct thread_data *td,
695 struct io_u *io_u, unsigned int header_num)
697 struct vhdr_meta *vh = hdr_priv(hdr);
699 vh->thread = td->thread_number;
701 vh->time_sec = io_u->start_time.tv_sec;
702 vh->time_usec = io_u->start_time.tv_usec;
704 vh->numberio = td->io_issues[DDIR_WRITE];
706 vh->offset = io_u->offset + header_num * td->o.verify_interval;
709 static void fill_sha512(struct verify_header *hdr, void *p, unsigned int len)
711 struct vhdr_sha512 *vh = hdr_priv(hdr);
712 struct sha512_ctx sha512_ctx = {
716 sha512_init(&sha512_ctx);
717 sha512_update(&sha512_ctx, p, len);
720 static void fill_sha256(struct verify_header *hdr, void *p, unsigned int len)
722 struct vhdr_sha256 *vh = hdr_priv(hdr);
723 struct sha256_ctx sha256_ctx = {
727 sha256_init(&sha256_ctx);
728 sha256_update(&sha256_ctx, p, len);
731 static void fill_sha1(struct verify_header *hdr, void *p, unsigned int len)
733 struct vhdr_sha1 *vh = hdr_priv(hdr);
734 struct sha1_ctx sha1_ctx = {
738 sha1_init(&sha1_ctx);
739 sha1_update(&sha1_ctx, p, len);
742 static void fill_crc7(struct verify_header *hdr, void *p, unsigned int len)
744 struct vhdr_crc7 *vh = hdr_priv(hdr);
746 vh->crc7 = crc7(p, len);
749 static void fill_crc16(struct verify_header *hdr, void *p, unsigned int len)
751 struct vhdr_crc16 *vh = hdr_priv(hdr);
753 vh->crc16 = crc16(p, len);
756 static void fill_crc32(struct verify_header *hdr, void *p, unsigned int len)
758 struct vhdr_crc32 *vh = hdr_priv(hdr);
760 vh->crc32 = crc32(p, len);
763 static void fill_crc32c(struct verify_header *hdr, void *p, unsigned int len)
765 struct vhdr_crc32 *vh = hdr_priv(hdr);
767 if (hdr->verify_type == VERIFY_CRC32C_INTEL)
768 vh->crc32 = crc32c_intel(p, len);
770 vh->crc32 = crc32c(p, len);
773 static void fill_crc64(struct verify_header *hdr, void *p, unsigned int len)
775 struct vhdr_crc64 *vh = hdr_priv(hdr);
777 vh->crc64 = crc64(p, len);
780 static void fill_md5(struct verify_header *hdr, void *p, unsigned int len)
782 struct vhdr_md5 *vh = hdr_priv(hdr);
783 struct md5_ctx md5_ctx = {
784 .hash = (uint32_t *) vh->md5_digest,
788 md5_update(&md5_ctx, p, len);
791 static void populate_hdr(struct thread_data *td, struct io_u *io_u,
792 struct verify_header *hdr, unsigned int header_num,
793 unsigned int header_len)
795 unsigned int data_len;
800 hdr->fio_magic = FIO_HDR_MAGIC;
801 hdr->len = header_len;
802 hdr->verify_type = td->o.verify;
803 hdr->rand_seed = io_u->rand_seed;
804 data_len = header_len - hdr_size(hdr);
806 data = p + hdr_size(hdr);
807 switch (td->o.verify) {
809 dprint(FD_VERIFY, "fill md5 io_u %p, len %u\n",
811 fill_md5(hdr, data, data_len);
814 dprint(FD_VERIFY, "fill crc64 io_u %p, len %u\n",
816 fill_crc64(hdr, data, data_len);
819 case VERIFY_CRC32C_INTEL:
820 dprint(FD_VERIFY, "fill crc32c io_u %p, len %u\n",
822 fill_crc32c(hdr, data, data_len);
825 dprint(FD_VERIFY, "fill crc32 io_u %p, len %u\n",
827 fill_crc32(hdr, data, data_len);
830 dprint(FD_VERIFY, "fill crc16 io_u %p, len %u\n",
832 fill_crc16(hdr, data, data_len);
835 dprint(FD_VERIFY, "fill crc7 io_u %p, len %u\n",
837 fill_crc7(hdr, data, data_len);
840 dprint(FD_VERIFY, "fill sha256 io_u %p, len %u\n",
842 fill_sha256(hdr, data, data_len);
845 dprint(FD_VERIFY, "fill sha512 io_u %p, len %u\n",
847 fill_sha512(hdr, data, data_len);
850 dprint(FD_VERIFY, "fill meta io_u %p, len %u\n",
852 fill_meta(hdr, td, io_u, header_num);
855 dprint(FD_VERIFY, "fill sha1 io_u %p, len %u\n",
857 fill_sha1(hdr, data, data_len);
860 log_err("fio: bad verify type: %d\n", td->o.verify);
863 if (td->o.verify_offset)
864 memswp(p, p + td->o.verify_offset, hdr_size(hdr));
868 * fill body of io_u->buf with random data and add a header with the
869 * crc32 or md5 sum of that data.
871 void populate_verify_io_u(struct thread_data *td, struct io_u *io_u)
873 struct verify_header *hdr;
874 unsigned int hdr_inc, header_num = 0;
877 if (td->o.verify == VERIFY_NULL)
880 fill_pattern(td, p, io_u->buflen, io_u, 0, 0);
882 hdr_inc = io_u->buflen;
883 if (td->o.verify_interval)
884 hdr_inc = td->o.verify_interval;
886 for (; p < io_u->buf + io_u->buflen; p += hdr_inc) {
888 populate_hdr(td, io_u, hdr, header_num, hdr_inc);
893 int get_next_verify(struct thread_data *td, struct io_u *io_u)
895 struct io_piece *ipo = NULL;
898 * this io_u is from a requeue, we already filled the offsets
903 if (!RB_EMPTY_ROOT(&td->io_hist_tree)) {
904 struct rb_node *n = rb_first(&td->io_hist_tree);
906 ipo = rb_entry(n, struct io_piece, rb_node);
907 rb_erase(n, &td->io_hist_tree);
908 assert(ipo->flags & IP_F_ONRB);
909 ipo->flags &= ~IP_F_ONRB;
910 } else if (!flist_empty(&td->io_hist_list)) {
911 ipo = flist_entry(td->io_hist_list.next, struct io_piece, list);
912 flist_del(&ipo->list);
913 assert(ipo->flags & IP_F_ONLIST);
914 ipo->flags &= ~IP_F_ONLIST;
920 io_u->offset = ipo->offset;
921 io_u->buflen = ipo->len;
922 io_u->file = ipo->file;
924 if (ipo->flags & IP_F_TRIMMED)
925 io_u->flags |= IO_U_F_TRIMMED;
927 if (!fio_file_open(io_u->file)) {
928 int r = td_io_open_file(td, io_u->file);
931 dprint(FD_VERIFY, "failed file %s open\n",
932 io_u->file->file_name);
938 assert(fio_file_open(io_u->file));
939 io_u->ddir = DDIR_READ;
940 io_u->xfer_buf = io_u->buf;
941 io_u->xfer_buflen = io_u->buflen;
943 remove_trim_entry(td, ipo);
945 dprint(FD_VERIFY, "get_next_verify: ret io_u %p\n", io_u);
949 dprint(FD_VERIFY, "get_next_verify: empty\n");
953 static void *verify_async_thread(void *data)
955 struct thread_data *td = data;
959 if (td->o.verify_cpumask_set &&
960 fio_setaffinity(td->pid, td->o.verify_cpumask)) {
961 log_err("fio: failed setting verify thread affinity\n");
969 if (td->verify_thread_exit)
972 pthread_mutex_lock(&td->io_u_lock);
974 while (flist_empty(&td->verify_list) &&
975 !td->verify_thread_exit) {
976 ret = pthread_cond_wait(&td->verify_cond,
979 pthread_mutex_unlock(&td->io_u_lock);
984 flist_splice_init(&td->verify_list, &list);
985 pthread_mutex_unlock(&td->io_u_lock);
987 if (flist_empty(&list))
990 while (!flist_empty(&list)) {
991 io_u = flist_entry(list.next, struct io_u, list);
992 flist_del_init(&io_u->list);
994 ret = verify_io_u(td, io_u);
998 if (td->o.continue_on_error &&
999 td_non_fatal_error(ret)) {
1000 update_error_count(td, ret);
1008 td_verror(td, ret, "async_verify");
1009 if (td->o.verify_fatal)
1014 pthread_mutex_lock(&td->io_u_lock);
1015 td->nr_verify_threads--;
1016 pthread_mutex_unlock(&td->io_u_lock);
1018 pthread_cond_signal(&td->free_cond);
1022 int verify_async_init(struct thread_data *td)
1025 pthread_attr_t attr;
1027 pthread_attr_init(&attr);
1028 pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
1030 td->verify_thread_exit = 0;
1032 td->verify_threads = malloc(sizeof(pthread_t) * td->o.verify_async);
1033 for (i = 0; i < td->o.verify_async; i++) {
1034 ret = pthread_create(&td->verify_threads[i], &attr,
1035 verify_async_thread, td);
1037 log_err("fio: async verify creation failed: %s\n",
1041 ret = pthread_detach(td->verify_threads[i]);
1043 log_err("fio: async verify thread detach failed: %s\n",
1047 td->nr_verify_threads++;
1050 pthread_attr_destroy(&attr);
1052 if (i != td->o.verify_async) {
1053 log_err("fio: only %d verify threads started, exiting\n", i);
1054 td->verify_thread_exit = 1;
1056 pthread_cond_broadcast(&td->verify_cond);
1063 void verify_async_exit(struct thread_data *td)
1065 td->verify_thread_exit = 1;
1067 pthread_cond_broadcast(&td->verify_cond);
1069 pthread_mutex_lock(&td->io_u_lock);
1071 while (td->nr_verify_threads)
1072 pthread_cond_wait(&td->free_cond, &td->io_u_lock);
1074 pthread_mutex_unlock(&td->io_u_lock);
1075 free(td->verify_threads);
1076 td->verify_threads = NULL;