Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 1 | /* |
| 2 | * IO verification helpers |
| 3 | */ |
| 4 | #include <unistd.h> |
| 5 | #include <fcntl.h> |
| 6 | #include <string.h> |
Jens Axboe | 97af62c | 2007-05-22 11:12:13 +0200 | [diff] [blame] | 7 | #include <assert.h> |
Jens Axboe | e8462bd | 2009-07-06 12:59:04 +0200 | [diff] [blame] | 8 | #include <pthread.h> |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 9 | |
| 10 | #include "fio.h" |
Jens Axboe | 4f5af7b | 2009-06-03 08:45:40 +0200 | [diff] [blame] | 11 | #include "verify.h" |
Jens Axboe | e8462bd | 2009-07-06 12:59:04 +0200 | [diff] [blame] | 12 | #include "smalloc.h" |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 13 | |
Jens Axboe | eef6eea | 2007-07-30 12:27:58 +0200 | [diff] [blame] | 14 | #include "crc/md5.h" |
| 15 | #include "crc/crc64.h" |
| 16 | #include "crc/crc32.h" |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame] | 17 | #include "crc/crc32c.h" |
Jens Axboe | eef6eea | 2007-07-30 12:27:58 +0200 | [diff] [blame] | 18 | #include "crc/crc16.h" |
| 19 | #include "crc/crc7.h" |
| 20 | #include "crc/sha256.h" |
| 21 | #include "crc/sha512.h" |
Jens Axboe | 7c353ce | 2009-08-09 22:40:33 +0200 | [diff] [blame] | 22 | #include "crc/sha1.h" |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 23 | |
Jens Axboe | 90059d6 | 2007-07-30 09:33:12 +0200 | [diff] [blame] | 24 | static void fill_random_bytes(struct thread_data *td, void *p, unsigned int len) |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 25 | { |
| 26 | unsigned int todo; |
Jens Axboe | 4c5946c | 2007-07-26 11:55:10 +0200 | [diff] [blame] | 27 | int r; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 28 | |
| 29 | while (len) { |
Jens Axboe | 4c5946c | 2007-07-26 11:55:10 +0200 | [diff] [blame] | 30 | r = os_random_long(&td->verify_state); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * lrand48_r seems to be broken and only fill the bottom |
| 34 | * 32-bits, even on 64-bit archs with 64-bit longs |
| 35 | */ |
| 36 | todo = sizeof(r); |
| 37 | if (todo > len) |
| 38 | todo = len; |
| 39 | |
| 40 | memcpy(p, &r, todo); |
| 41 | |
| 42 | len -= todo; |
| 43 | p += todo; |
| 44 | } |
| 45 | } |
| 46 | |
Jens Axboe | 90059d6 | 2007-07-30 09:33:12 +0200 | [diff] [blame] | 47 | static void fill_pattern(struct thread_data *td, void *p, unsigned int len) |
| 48 | { |
| 49 | switch (td->o.verify_pattern_bytes) { |
| 50 | case 0: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 51 | dprint(FD_VERIFY, "fill random bytes len=%u\n", len); |
Jens Axboe | 90059d6 | 2007-07-30 09:33:12 +0200 | [diff] [blame] | 52 | fill_random_bytes(td, p, len); |
| 53 | break; |
| 54 | case 1: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 55 | dprint(FD_VERIFY, "fill verify pattern b=0 len=%u\n", len); |
Radha Ramachandran | 0e92f87 | 2009-10-27 20:14:27 +0100 | [diff] [blame] | 56 | memset(p, td->o.verify_pattern[0], len); |
Jens Axboe | 90059d6 | 2007-07-30 09:33:12 +0200 | [diff] [blame] | 57 | break; |
Radha Ramachandran | 0e92f87 | 2009-10-27 20:14:27 +0100 | [diff] [blame] | 58 | default: { |
| 59 | unsigned int i = 0, size = 0; |
Jens Axboe | 90059d6 | 2007-07-30 09:33:12 +0200 | [diff] [blame] | 60 | unsigned char *b = p; |
| 61 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 62 | dprint(FD_VERIFY, "fill verify pattern b=%d len=%u\n", |
| 63 | td->o.verify_pattern_bytes, len); |
| 64 | |
Jens Axboe | 90059d6 | 2007-07-30 09:33:12 +0200 | [diff] [blame] | 65 | while (i < len) { |
Radha Ramachandran | 0e92f87 | 2009-10-27 20:14:27 +0100 | [diff] [blame] | 66 | size = td->o.verify_pattern_bytes; |
| 67 | if (size > (len - i)) |
| 68 | size = len - i; |
| 69 | memcpy(b+i, td->o.verify_pattern, size); |
| 70 | i += size; |
Jens Axboe | 90059d6 | 2007-07-30 09:33:12 +0200 | [diff] [blame] | 71 | } |
| 72 | break; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
Jens Axboe | 4764aec | 2007-08-23 09:03:38 +0200 | [diff] [blame] | 77 | static void memswp(void *buf1, void *buf2, unsigned int len) |
Shawn Lewis | 546a914 | 2007-07-28 21:11:37 +0200 | [diff] [blame] | 78 | { |
Shawn Lewis | dee6de7 | 2007-08-02 22:17:52 +0200 | [diff] [blame] | 79 | char swap[200]; |
| 80 | |
| 81 | assert(len <= sizeof(swap)); |
Jens Axboe | 90059d6 | 2007-07-30 09:33:12 +0200 | [diff] [blame] | 82 | |
Shawn Lewis | 546a914 | 2007-07-28 21:11:37 +0200 | [diff] [blame] | 83 | memcpy(&swap, buf1, len); |
| 84 | memcpy(buf1, buf2, len); |
| 85 | memcpy(buf2, &swap, len); |
| 86 | } |
| 87 | |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 88 | static void hexdump(void *buffer, int len) |
| 89 | { |
| 90 | unsigned char *p = buffer; |
| 91 | int i; |
| 92 | |
| 93 | for (i = 0; i < len; i++) |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame] | 94 | log_info("%02x", p[i]); |
| 95 | log_info("\n"); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 96 | } |
| 97 | |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 98 | /* |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 99 | * Prepare for seperation of verify_header and checksum header |
| 100 | */ |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 101 | static inline unsigned int __hdr_size(int verify_type) |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 102 | { |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 103 | unsigned int len = len; |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 104 | |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 105 | switch (verify_type) { |
| 106 | case VERIFY_NONE: |
| 107 | case VERIFY_NULL: |
| 108 | len = 0; |
| 109 | break; |
| 110 | case VERIFY_MD5: |
| 111 | len = sizeof(struct vhdr_md5); |
| 112 | break; |
| 113 | case VERIFY_CRC64: |
| 114 | len = sizeof(struct vhdr_crc64); |
| 115 | break; |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame] | 116 | case VERIFY_CRC32C: |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 117 | case VERIFY_CRC32: |
Jens Axboe | 3845591 | 2008-08-04 15:35:26 +0200 | [diff] [blame] | 118 | case VERIFY_CRC32C_INTEL: |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 119 | len = sizeof(struct vhdr_crc32); |
| 120 | break; |
| 121 | case VERIFY_CRC16: |
| 122 | len = sizeof(struct vhdr_crc16); |
| 123 | break; |
| 124 | case VERIFY_CRC7: |
| 125 | len = sizeof(struct vhdr_crc7); |
| 126 | break; |
| 127 | case VERIFY_SHA256: |
| 128 | len = sizeof(struct vhdr_sha256); |
| 129 | break; |
| 130 | case VERIFY_SHA512: |
| 131 | len = sizeof(struct vhdr_sha512); |
| 132 | break; |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 133 | case VERIFY_META: |
| 134 | len = sizeof(struct vhdr_meta); |
| 135 | break; |
Jens Axboe | 7c353ce | 2009-08-09 22:40:33 +0200 | [diff] [blame] | 136 | case VERIFY_SHA1: |
| 137 | len = sizeof(struct vhdr_sha1); |
| 138 | break; |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 139 | default: |
| 140 | log_err("fio: unknown verify header!\n"); |
| 141 | assert(0); |
| 142 | } |
| 143 | |
| 144 | return len + sizeof(struct verify_header); |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static inline unsigned int hdr_size(struct verify_header *hdr) |
| 148 | { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 149 | return __hdr_size(hdr->verify_type); |
| 150 | } |
| 151 | |
| 152 | static void *hdr_priv(struct verify_header *hdr) |
| 153 | { |
| 154 | void *priv = hdr; |
| 155 | |
| 156 | return priv + sizeof(struct verify_header); |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /* |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 160 | * Return data area 'header_num' |
| 161 | */ |
| 162 | static inline void *io_u_verify_off(struct verify_header *hdr, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 163 | struct io_u *io_u, unsigned char header_num) |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 164 | { |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 165 | return io_u->buf + header_num * hdr->len + hdr_size(hdr); |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 166 | } |
| 167 | |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 168 | static int verify_io_u_meta(struct verify_header *hdr, struct thread_data *td, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 169 | struct io_u *io_u, unsigned int header_num) |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 170 | { |
| 171 | struct vhdr_meta *vh = hdr_priv(hdr); |
| 172 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 173 | dprint(FD_VERIFY, "meta verify io_u %p, len %u\n", io_u, hdr->len); |
| 174 | |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 175 | if (vh->offset != io_u->offset + header_num * td->o.verify_interval) { |
| 176 | log_err("meta: verify failed at %llu/%u\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 177 | io_u->offset + header_num * hdr->len, hdr->len); |
Jens Axboe | 9fd1896 | 2009-05-19 10:35:38 +0200 | [diff] [blame] | 178 | return EILSEQ; |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 184 | static int verify_io_u_sha512(struct verify_header *hdr, struct io_u *io_u, |
| 185 | unsigned int header_num) |
| 186 | { |
| 187 | void *p = io_u_verify_off(hdr, io_u, header_num); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 188 | struct vhdr_sha512 *vh = hdr_priv(hdr); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 189 | uint8_t sha512[128]; |
| 190 | struct sha512_ctx sha512_ctx = { |
| 191 | .buf = sha512, |
| 192 | }; |
| 193 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 194 | dprint(FD_VERIFY, "sha512 verify io_u %p, len %u\n", io_u, hdr->len); |
| 195 | |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 196 | sha512_init(&sha512_ctx); |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 197 | sha512_update(&sha512_ctx, p, hdr->len - hdr_size(hdr)); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 198 | |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 199 | if (memcmp(vh->sha512, sha512_ctx.buf, sizeof(sha512))) { |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 200 | log_err("sha512: verify failed at %llu/%u\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 201 | io_u->offset + header_num * hdr->len, hdr->len); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 202 | hexdump(vh->sha512, sizeof(vh->sha512)); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 203 | hexdump(sha512_ctx.buf, sizeof(sha512)); |
Jens Axboe | 9fd1896 | 2009-05-19 10:35:38 +0200 | [diff] [blame] | 204 | return EILSEQ; |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | static int verify_io_u_sha256(struct verify_header *hdr, struct io_u *io_u, |
| 211 | unsigned int header_num) |
| 212 | { |
| 213 | void *p = io_u_verify_off(hdr, io_u, header_num); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 214 | struct vhdr_sha256 *vh = hdr_priv(hdr); |
Jens Axboe | bc77f56 | 2010-02-23 10:36:21 +0100 | [diff] [blame^] | 215 | uint8_t sha256[64]; |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 216 | struct sha256_ctx sha256_ctx = { |
| 217 | .buf = sha256, |
| 218 | }; |
| 219 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 220 | dprint(FD_VERIFY, "sha256 verify io_u %p, len %u\n", io_u, hdr->len); |
| 221 | |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 222 | sha256_init(&sha256_ctx); |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 223 | sha256_update(&sha256_ctx, p, hdr->len - hdr_size(hdr)); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 224 | |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 225 | if (memcmp(vh->sha256, sha256_ctx.buf, sizeof(sha256))) { |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 226 | log_err("sha256: verify failed at %llu/%u\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 227 | io_u->offset + header_num * hdr->len, hdr->len); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 228 | hexdump(vh->sha256, sizeof(vh->sha256)); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 229 | hexdump(sha256_ctx.buf, sizeof(sha256)); |
Jens Axboe | 9fd1896 | 2009-05-19 10:35:38 +0200 | [diff] [blame] | 230 | return EILSEQ; |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | return 0; |
| 234 | } |
| 235 | |
Jens Axboe | 7c353ce | 2009-08-09 22:40:33 +0200 | [diff] [blame] | 236 | static int verify_io_u_sha1(struct verify_header *hdr, struct io_u *io_u, |
| 237 | unsigned int header_num) |
| 238 | { |
| 239 | void *p = io_u_verify_off(hdr, io_u, header_num); |
| 240 | struct vhdr_sha1 *vh = hdr_priv(hdr); |
| 241 | uint32_t sha1[5]; |
| 242 | struct sha1_ctx sha1_ctx = { |
| 243 | .H = sha1, |
| 244 | }; |
| 245 | |
| 246 | dprint(FD_VERIFY, "sha1 verify io_u %p, len %u\n", io_u, hdr->len); |
| 247 | |
| 248 | sha1_init(&sha1_ctx); |
| 249 | sha1_update(&sha1_ctx, p, hdr->len - hdr_size(hdr)); |
| 250 | |
| 251 | if (memcmp(vh->sha1, sha1_ctx.H, sizeof(sha1))) { |
| 252 | log_err("sha1: verify failed at %llu/%u\n", |
| 253 | io_u->offset + header_num * hdr->len, hdr->len); |
| 254 | hexdump(vh->sha1, sizeof(vh->sha1)); |
| 255 | hexdump(sha1_ctx.H, sizeof(sha1)); |
| 256 | return EILSEQ; |
| 257 | } |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 262 | static int verify_io_u_crc7(struct verify_header *hdr, struct io_u *io_u, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 263 | unsigned char header_num) |
Jens Axboe | 1e154bd | 2007-07-27 09:52:40 +0200 | [diff] [blame] | 264 | { |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 265 | void *p = io_u_verify_off(hdr, io_u, header_num); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 266 | struct vhdr_crc7 *vh = hdr_priv(hdr); |
Jens Axboe | 1e154bd | 2007-07-27 09:52:40 +0200 | [diff] [blame] | 267 | unsigned char c; |
| 268 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 269 | dprint(FD_VERIFY, "crc7 verify io_u %p, len %u\n", io_u, hdr->len); |
| 270 | |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 271 | c = crc7(p, hdr->len - hdr_size(hdr)); |
Jens Axboe | 1e154bd | 2007-07-27 09:52:40 +0200 | [diff] [blame] | 272 | |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 273 | if (c != vh->crc7) { |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 274 | log_err("crc7: verify failed at %llu/%u\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 275 | io_u->offset + header_num * hdr->len, hdr->len); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 276 | log_err("crc7: wanted %x, got %x\n", vh->crc7, c); |
Jens Axboe | 9fd1896 | 2009-05-19 10:35:38 +0200 | [diff] [blame] | 277 | return EILSEQ; |
Jens Axboe | 1e154bd | 2007-07-27 09:52:40 +0200 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 283 | static int verify_io_u_crc16(struct verify_header *hdr, struct io_u *io_u, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 284 | unsigned int header_num) |
Jens Axboe | 969f7ed | 2007-07-27 09:07:17 +0200 | [diff] [blame] | 285 | { |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 286 | void *p = io_u_verify_off(hdr, io_u, header_num); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 287 | struct vhdr_crc16 *vh = hdr_priv(hdr); |
Jens Axboe | 969f7ed | 2007-07-27 09:07:17 +0200 | [diff] [blame] | 288 | unsigned short c; |
| 289 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 290 | dprint(FD_VERIFY, "crc16 verify io_u %p, len %u\n", io_u, hdr->len); |
| 291 | |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 292 | c = crc16(p, hdr->len - hdr_size(hdr)); |
Jens Axboe | 969f7ed | 2007-07-27 09:07:17 +0200 | [diff] [blame] | 293 | |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 294 | if (c != vh->crc16) { |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 295 | log_err("crc16: verify failed at %llu/%u\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 296 | io_u->offset + header_num * hdr->len, hdr->len); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 297 | log_err("crc16: wanted %x, got %x\n", vh->crc16, c); |
Jens Axboe | 9fd1896 | 2009-05-19 10:35:38 +0200 | [diff] [blame] | 298 | return EILSEQ; |
Jens Axboe | 969f7ed | 2007-07-27 09:07:17 +0200 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 304 | static int verify_io_u_crc64(struct verify_header *hdr, struct io_u *io_u, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 305 | unsigned int header_num) |
Jens Axboe | d77a7af | 2007-07-27 15:35:06 +0200 | [diff] [blame] | 306 | { |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 307 | void *p = io_u_verify_off(hdr, io_u, header_num); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 308 | struct vhdr_crc64 *vh = hdr_priv(hdr); |
Jens Axboe | d77a7af | 2007-07-27 15:35:06 +0200 | [diff] [blame] | 309 | unsigned long long c; |
| 310 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 311 | dprint(FD_VERIFY, "crc64 verify io_u %p, len %u\n", io_u, hdr->len); |
| 312 | |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 313 | c = crc64(p, hdr->len - hdr_size(hdr)); |
Jens Axboe | d77a7af | 2007-07-27 15:35:06 +0200 | [diff] [blame] | 314 | |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 315 | if (c != vh->crc64) { |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 316 | log_err("crc64: verify failed at %llu/%u\n", |
| 317 | io_u->offset + header_num * hdr->len, |
| 318 | hdr->len); |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 319 | log_err("crc64: wanted %llx, got %llx\n", |
| 320 | (unsigned long long) vh->crc64, c); |
Jens Axboe | 9fd1896 | 2009-05-19 10:35:38 +0200 | [diff] [blame] | 321 | return EILSEQ; |
Jens Axboe | d77a7af | 2007-07-27 15:35:06 +0200 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 327 | static int verify_io_u_crc32(struct verify_header *hdr, struct io_u *io_u, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 328 | unsigned int header_num) |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 329 | { |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 330 | void *p = io_u_verify_off(hdr, io_u, header_num); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 331 | struct vhdr_crc32 *vh = hdr_priv(hdr); |
| 332 | uint32_t c; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 333 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 334 | dprint(FD_VERIFY, "crc32 verify io_u %p, len %u\n", io_u, hdr->len); |
| 335 | |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 336 | c = crc32(p, hdr->len - hdr_size(hdr)); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 337 | |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 338 | if (c != vh->crc32) { |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 339 | log_err("crc32: verify failed at %llu/%u\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 340 | io_u->offset + header_num * hdr->len, hdr->len); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 341 | log_err("crc32: wanted %x, got %x\n", vh->crc32, c); |
Jens Axboe | 9fd1896 | 2009-05-19 10:35:38 +0200 | [diff] [blame] | 342 | return EILSEQ; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame] | 348 | static int verify_io_u_crc32c(struct verify_header *hdr, struct io_u *io_u, |
| 349 | unsigned int header_num) |
| 350 | { |
| 351 | void *p = io_u_verify_off(hdr, io_u, header_num); |
| 352 | struct vhdr_crc32 *vh = hdr_priv(hdr); |
| 353 | uint32_t c; |
| 354 | |
| 355 | dprint(FD_VERIFY, "crc32c verify io_u %p, len %u\n", io_u, hdr->len); |
| 356 | |
Jens Axboe | 3845591 | 2008-08-04 15:35:26 +0200 | [diff] [blame] | 357 | if (hdr->verify_type == VERIFY_CRC32C_INTEL) |
| 358 | c = crc32c_intel(p, hdr->len - hdr_size(hdr)); |
| 359 | else |
| 360 | c = crc32c(p, hdr->len - hdr_size(hdr)); |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame] | 361 | |
| 362 | if (c != vh->crc32) { |
| 363 | log_err("crc32c: verify failed at %llu/%u\n", |
| 364 | io_u->offset + header_num * hdr->len, hdr->len); |
| 365 | log_err("crc32c: wanted %x, got %x\n", vh->crc32, c); |
Jens Axboe | 9fd1896 | 2009-05-19 10:35:38 +0200 | [diff] [blame] | 366 | return EILSEQ; |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 372 | static int verify_io_u_md5(struct verify_header *hdr, struct io_u *io_u, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 373 | unsigned int header_num) |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 374 | { |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 375 | void *p = io_u_verify_off(hdr, io_u, header_num); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 376 | struct vhdr_md5 *vh = hdr_priv(hdr); |
Jens Axboe | 8c43232 | 2007-07-27 13:16:24 +0200 | [diff] [blame] | 377 | uint32_t hash[MD5_HASH_WORDS]; |
| 378 | struct md5_ctx md5_ctx = { |
| 379 | .hash = hash, |
| 380 | }; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 381 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 382 | dprint(FD_VERIFY, "md5 verify io_u %p, len %u\n", io_u, hdr->len); |
| 383 | |
Jens Axboe | 61f821f | 2007-07-30 10:18:06 +0200 | [diff] [blame] | 384 | md5_init(&md5_ctx); |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 385 | md5_update(&md5_ctx, p, hdr->len - hdr_size(hdr)); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 386 | |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 387 | if (memcmp(vh->md5_digest, md5_ctx.hash, sizeof(hash))) { |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 388 | log_err("md5: verify failed at %llu/%u\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 389 | io_u->offset + header_num * hdr->len, hdr->len); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 390 | hexdump(vh->md5_digest, sizeof(vh->md5_digest)); |
Jens Axboe | 8c43232 | 2007-07-27 13:16:24 +0200 | [diff] [blame] | 391 | hexdump(md5_ctx.hash, sizeof(hash)); |
Jens Axboe | 9fd1896 | 2009-05-19 10:35:38 +0200 | [diff] [blame] | 392 | return EILSEQ; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | return 0; |
| 396 | } |
| 397 | |
Jens Axboe | 3f199b0 | 2007-08-09 10:16:31 +0200 | [diff] [blame] | 398 | static unsigned int hweight8(unsigned int w) |
| 399 | { |
| 400 | unsigned int res = w - ((w >> 1) & 0x55); |
| 401 | |
| 402 | res = (res & 0x33) + ((res >> 2) & 0x33); |
| 403 | return (res + (res >> 4)) & 0x0F; |
| 404 | } |
| 405 | |
Radha Ramachandran | 0e92f87 | 2009-10-27 20:14:27 +0100 | [diff] [blame] | 406 | int verify_io_u_pattern(char *pattern, unsigned long pattern_size, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 407 | char *buf, unsigned int len, unsigned int mod) |
Shawn Lewis | a944e33 | 2007-08-02 22:18:29 +0200 | [diff] [blame] | 408 | { |
| 409 | unsigned int i; |
Shawn Lewis | a944e33 | 2007-08-02 22:18:29 +0200 | [diff] [blame] | 410 | |
| 411 | for (i = 0; i < len; i++) { |
Radha Ramachandran | 0e92f87 | 2009-10-27 20:14:27 +0100 | [diff] [blame] | 412 | if (buf[i] != pattern[mod]) { |
Jens Axboe | 3f199b0 | 2007-08-09 10:16:31 +0200 | [diff] [blame] | 413 | unsigned int bits; |
| 414 | |
Radha Ramachandran | 0e92f87 | 2009-10-27 20:14:27 +0100 | [diff] [blame] | 415 | bits = hweight8(buf[i] ^ pattern[mod]); |
Jens Axboe | 3f199b0 | 2007-08-09 10:16:31 +0200 | [diff] [blame] | 416 | log_err("fio: got pattern %x, wanted %x. Bad bits %d\n", |
Radha Ramachandran | 0e92f87 | 2009-10-27 20:14:27 +0100 | [diff] [blame] | 417 | buf[i], pattern[mod], bits); |
Jens Axboe | 3f199b0 | 2007-08-09 10:16:31 +0200 | [diff] [blame] | 418 | log_err("fio: bad pattern block offset %u\n", i); |
Jens Axboe | 9fd1896 | 2009-05-19 10:35:38 +0200 | [diff] [blame] | 419 | return EILSEQ; |
Jens Axboe | 3f199b0 | 2007-08-09 10:16:31 +0200 | [diff] [blame] | 420 | } |
Shawn Lewis | a944e33 | 2007-08-02 22:18:29 +0200 | [diff] [blame] | 421 | mod++; |
| 422 | if (mod == pattern_size) |
| 423 | mod = 0; |
| 424 | } |
| 425 | |
| 426 | return 0; |
| 427 | } |
| 428 | |
Jens Axboe | e8462bd | 2009-07-06 12:59:04 +0200 | [diff] [blame] | 429 | /* |
| 430 | * Push IO verification to a separate thread |
| 431 | */ |
| 432 | int verify_io_u_async(struct thread_data *td, struct io_u *io_u) |
| 433 | { |
| 434 | if (io_u->file) |
| 435 | put_file_log(td, io_u->file); |
| 436 | |
| 437 | io_u->file = NULL; |
| 438 | |
| 439 | pthread_mutex_lock(&td->io_u_lock); |
Radha Ramachandran | 0c41214 | 2009-11-03 21:45:31 +0100 | [diff] [blame] | 440 | |
| 441 | if (io_u->flags & IO_U_F_IN_CUR_DEPTH) { |
| 442 | td->cur_depth--; |
| 443 | io_u->flags &= ~IO_U_F_IN_CUR_DEPTH; |
| 444 | } |
Jens Axboe | e8462bd | 2009-07-06 12:59:04 +0200 | [diff] [blame] | 445 | flist_del(&io_u->list); |
| 446 | flist_add_tail(&io_u->list, &td->verify_list); |
Jens Axboe | 2ecc1b5 | 2009-11-04 20:58:09 +0100 | [diff] [blame] | 447 | io_u->flags |= IO_U_F_FREE_DEF; |
Jens Axboe | e8462bd | 2009-07-06 12:59:04 +0200 | [diff] [blame] | 448 | pthread_mutex_unlock(&td->io_u_lock); |
| 449 | |
| 450 | pthread_cond_signal(&td->verify_cond); |
Jens Axboe | e8462bd | 2009-07-06 12:59:04 +0200 | [diff] [blame] | 451 | return 0; |
| 452 | } |
| 453 | |
Jens Axboe | 36690c9 | 2007-03-26 10:23:34 +0200 | [diff] [blame] | 454 | int verify_io_u(struct thread_data *td, struct io_u *io_u) |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 455 | { |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 456 | struct verify_header *hdr; |
Shawn Lewis | a944e33 | 2007-08-02 22:18:29 +0200 | [diff] [blame] | 457 | unsigned int hdr_size, hdr_inc, hdr_num = 0; |
Jens Axboe | 9564610 | 2007-07-28 21:17:50 +0200 | [diff] [blame] | 458 | void *p; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 459 | int ret; |
| 460 | |
Shawn Lewis | 1dcc049 | 2007-07-27 08:02:45 +0200 | [diff] [blame] | 461 | if (td->o.verify == VERIFY_NULL || io_u->ddir != DDIR_READ) |
Jens Axboe | 36690c9 | 2007-03-26 10:23:34 +0200 | [diff] [blame] | 462 | return 0; |
| 463 | |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 464 | hdr_inc = io_u->buflen; |
Jens Axboe | a59e170 | 2007-07-30 08:53:27 +0200 | [diff] [blame] | 465 | if (td->o.verify_interval) |
| 466 | hdr_inc = td->o.verify_interval; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 467 | |
Jens Axboe | a12a3b4 | 2007-08-09 10:20:54 +0200 | [diff] [blame] | 468 | ret = 0; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 469 | for (p = io_u->buf; p < io_u->buf + io_u->buflen; |
| 470 | p += hdr_inc, hdr_num++) { |
Jens Axboe | a12a3b4 | 2007-08-09 10:20:54 +0200 | [diff] [blame] | 471 | if (ret && td->o.verify_fatal) { |
| 472 | td->terminate = 1; |
| 473 | break; |
| 474 | } |
Shawn Lewis | a944e33 | 2007-08-02 22:18:29 +0200 | [diff] [blame] | 475 | hdr_size = __hdr_size(td->o.verify); |
Jens Axboe | a59e170 | 2007-07-30 08:53:27 +0200 | [diff] [blame] | 476 | if (td->o.verify_offset) |
Shawn Lewis | a944e33 | 2007-08-02 22:18:29 +0200 | [diff] [blame] | 477 | memswp(p, p + td->o.verify_offset, hdr_size); |
Jens Axboe | 9564610 | 2007-07-28 21:17:50 +0200 | [diff] [blame] | 478 | hdr = p; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 479 | |
Jens Axboe | 3f199b0 | 2007-08-09 10:16:31 +0200 | [diff] [blame] | 480 | if (hdr->fio_magic != FIO_HDR_MAGIC) { |
Radha Ramachandran | b7a3e66 | 2009-11-12 08:42:43 +0100 | [diff] [blame] | 481 | log_err("Bad verify header %x at %llu\n", |
| 482 | hdr->fio_magic, |
| 483 | io_u->offset + hdr_num * hdr->len); |
Jens Axboe | 9fd1896 | 2009-05-19 10:35:38 +0200 | [diff] [blame] | 484 | return EILSEQ; |
Jens Axboe | 3f199b0 | 2007-08-09 10:16:31 +0200 | [diff] [blame] | 485 | } |
| 486 | |
Shawn Lewis | e28218f | 2008-01-16 11:01:33 +0100 | [diff] [blame] | 487 | if (td->o.verify_pattern_bytes) { |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 488 | dprint(FD_VERIFY, "pattern verify io_u %p, len %u\n", |
| 489 | io_u, hdr->len); |
Shawn Lewis | e28218f | 2008-01-16 11:01:33 +0100 | [diff] [blame] | 490 | ret = verify_io_u_pattern(td->o.verify_pattern, |
Radha Ramachandran | 0e92f87 | 2009-10-27 20:14:27 +0100 | [diff] [blame] | 491 | td->o.verify_pattern_bytes, |
| 492 | p + hdr_size, |
| 493 | hdr_inc - hdr_size, |
| 494 | hdr_size % td->o.verify_pattern_bytes); |
Radha Ramachandran | e92d3d7 | 2009-07-27 12:27:55 +0200 | [diff] [blame] | 495 | /* |
| 496 | * Also verify the meta data, if applicable |
| 497 | */ |
| 498 | if (hdr->verify_type == VERIFY_META) |
| 499 | ret |= verify_io_u_meta(hdr, td, io_u, hdr_num); |
| 500 | |
Shawn Lewis | e28218f | 2008-01-16 11:01:33 +0100 | [diff] [blame] | 501 | if (ret) |
| 502 | log_err("fio: verify failed at %llu/%u\n", |
| 503 | io_u->offset + hdr_num * hdr->len, |
| 504 | hdr->len); |
| 505 | continue; |
| 506 | } |
| 507 | |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 508 | switch (hdr->verify_type) { |
| 509 | case VERIFY_MD5: |
| 510 | ret = verify_io_u_md5(hdr, io_u, hdr_num); |
| 511 | break; |
| 512 | case VERIFY_CRC64: |
| 513 | ret = verify_io_u_crc64(hdr, io_u, hdr_num); |
| 514 | break; |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame] | 515 | case VERIFY_CRC32C: |
Jens Axboe | 3845591 | 2008-08-04 15:35:26 +0200 | [diff] [blame] | 516 | case VERIFY_CRC32C_INTEL: |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame] | 517 | ret = verify_io_u_crc32c(hdr, io_u, hdr_num); |
| 518 | break; |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 519 | case VERIFY_CRC32: |
| 520 | ret = verify_io_u_crc32(hdr, io_u, hdr_num); |
| 521 | break; |
| 522 | case VERIFY_CRC16: |
| 523 | ret = verify_io_u_crc16(hdr, io_u, hdr_num); |
| 524 | break; |
| 525 | case VERIFY_CRC7: |
| 526 | ret = verify_io_u_crc7(hdr, io_u, hdr_num); |
| 527 | break; |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 528 | case VERIFY_SHA256: |
| 529 | ret = verify_io_u_sha256(hdr, io_u, hdr_num); |
| 530 | break; |
| 531 | case VERIFY_SHA512: |
| 532 | ret = verify_io_u_sha512(hdr, io_u, hdr_num); |
| 533 | break; |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 534 | case VERIFY_META: |
| 535 | ret = verify_io_u_meta(hdr, td, io_u, hdr_num); |
| 536 | break; |
Jens Axboe | 7c353ce | 2009-08-09 22:40:33 +0200 | [diff] [blame] | 537 | case VERIFY_SHA1: |
| 538 | ret = verify_io_u_sha1(hdr, io_u, hdr_num); |
| 539 | break; |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 540 | default: |
| 541 | log_err("Bad verify type %u\n", hdr->verify_type); |
Jens Axboe | d16d4e0 | 2007-09-06 16:16:44 +0200 | [diff] [blame] | 542 | ret = EINVAL; |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 543 | } |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 544 | } |
Jens Axboe | a7dfe86 | 2007-03-12 10:05:08 +0100 | [diff] [blame] | 545 | |
Jens Axboe | a12a3b4 | 2007-08-09 10:20:54 +0200 | [diff] [blame] | 546 | return ret; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 547 | } |
| 548 | |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 549 | static void fill_meta(struct verify_header *hdr, struct thread_data *td, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 550 | struct io_u *io_u, unsigned int header_num) |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 551 | { |
| 552 | struct vhdr_meta *vh = hdr_priv(hdr); |
| 553 | |
| 554 | vh->thread = td->thread_number; |
| 555 | |
| 556 | vh->time_sec = io_u->start_time.tv_sec; |
| 557 | vh->time_usec = io_u->start_time.tv_usec; |
| 558 | |
| 559 | vh->numberio = td->io_issues[DDIR_WRITE]; |
| 560 | |
| 561 | vh->offset = io_u->offset + header_num * td->o.verify_interval; |
| 562 | } |
| 563 | |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 564 | static void fill_sha512(struct verify_header *hdr, void *p, unsigned int len) |
| 565 | { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 566 | struct vhdr_sha512 *vh = hdr_priv(hdr); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 567 | struct sha512_ctx sha512_ctx = { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 568 | .buf = vh->sha512, |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 569 | }; |
| 570 | |
| 571 | sha512_init(&sha512_ctx); |
| 572 | sha512_update(&sha512_ctx, p, len); |
| 573 | } |
| 574 | |
| 575 | static void fill_sha256(struct verify_header *hdr, void *p, unsigned int len) |
| 576 | { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 577 | struct vhdr_sha256 *vh = hdr_priv(hdr); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 578 | struct sha256_ctx sha256_ctx = { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 579 | .buf = vh->sha256, |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 580 | }; |
| 581 | |
| 582 | sha256_init(&sha256_ctx); |
| 583 | sha256_update(&sha256_ctx, p, len); |
| 584 | } |
| 585 | |
Jens Axboe | 7c353ce | 2009-08-09 22:40:33 +0200 | [diff] [blame] | 586 | static void fill_sha1(struct verify_header *hdr, void *p, unsigned int len) |
| 587 | { |
| 588 | struct vhdr_sha1 *vh = hdr_priv(hdr); |
| 589 | struct sha1_ctx sha1_ctx = { |
| 590 | .H = vh->sha1, |
| 591 | }; |
| 592 | |
| 593 | sha1_init(&sha1_ctx); |
| 594 | sha1_update(&sha1_ctx, p, len); |
| 595 | } |
| 596 | |
Jens Axboe | 1e154bd | 2007-07-27 09:52:40 +0200 | [diff] [blame] | 597 | static void fill_crc7(struct verify_header *hdr, void *p, unsigned int len) |
| 598 | { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 599 | struct vhdr_crc7 *vh = hdr_priv(hdr); |
| 600 | |
| 601 | vh->crc7 = crc7(p, len); |
Jens Axboe | 1e154bd | 2007-07-27 09:52:40 +0200 | [diff] [blame] | 602 | } |
| 603 | |
Jens Axboe | 969f7ed | 2007-07-27 09:07:17 +0200 | [diff] [blame] | 604 | static void fill_crc16(struct verify_header *hdr, void *p, unsigned int len) |
| 605 | { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 606 | struct vhdr_crc16 *vh = hdr_priv(hdr); |
| 607 | |
| 608 | vh->crc16 = crc16(p, len); |
Jens Axboe | 969f7ed | 2007-07-27 09:07:17 +0200 | [diff] [blame] | 609 | } |
| 610 | |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 611 | static void fill_crc32(struct verify_header *hdr, void *p, unsigned int len) |
| 612 | { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 613 | struct vhdr_crc32 *vh = hdr_priv(hdr); |
| 614 | |
| 615 | vh->crc32 = crc32(p, len); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 616 | } |
| 617 | |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame] | 618 | static void fill_crc32c(struct verify_header *hdr, void *p, unsigned int len) |
| 619 | { |
| 620 | struct vhdr_crc32 *vh = hdr_priv(hdr); |
| 621 | |
Jens Axboe | 3845591 | 2008-08-04 15:35:26 +0200 | [diff] [blame] | 622 | if (hdr->verify_type == VERIFY_CRC32C_INTEL) |
| 623 | vh->crc32 = crc32c_intel(p, len); |
| 624 | else |
| 625 | vh->crc32 = crc32c(p, len); |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame] | 626 | } |
| 627 | |
Jens Axboe | d77a7af | 2007-07-27 15:35:06 +0200 | [diff] [blame] | 628 | static void fill_crc64(struct verify_header *hdr, void *p, unsigned int len) |
| 629 | { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 630 | struct vhdr_crc64 *vh = hdr_priv(hdr); |
| 631 | |
| 632 | vh->crc64 = crc64(p, len); |
Jens Axboe | d77a7af | 2007-07-27 15:35:06 +0200 | [diff] [blame] | 633 | } |
| 634 | |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 635 | static void fill_md5(struct verify_header *hdr, void *p, unsigned int len) |
| 636 | { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 637 | struct vhdr_md5 *vh = hdr_priv(hdr); |
Jens Axboe | 8c43232 | 2007-07-27 13:16:24 +0200 | [diff] [blame] | 638 | struct md5_ctx md5_ctx = { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 639 | .hash = (uint32_t *) vh->md5_digest, |
Jens Axboe | 8c43232 | 2007-07-27 13:16:24 +0200 | [diff] [blame] | 640 | }; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 641 | |
Jens Axboe | 61f821f | 2007-07-30 10:18:06 +0200 | [diff] [blame] | 642 | md5_init(&md5_ctx); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 643 | md5_update(&md5_ctx, p, len); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | /* |
| 647 | * fill body of io_u->buf with random data and add a header with the |
| 648 | * crc32 or md5 sum of that data. |
| 649 | */ |
| 650 | void populate_verify_io_u(struct thread_data *td, struct io_u *io_u) |
| 651 | { |
Jens Axboe | baefa9b | 2007-07-27 12:57:25 +0200 | [diff] [blame] | 652 | struct verify_header *hdr; |
Jens Axboe | 9564610 | 2007-07-28 21:17:50 +0200 | [diff] [blame] | 653 | void *p = io_u->buf, *data; |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 654 | unsigned int hdr_inc, data_len, header_num = 0; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 655 | |
Jens Axboe | 9cc3d15 | 2007-03-26 10:32:30 +0200 | [diff] [blame] | 656 | if (td->o.verify == VERIFY_NULL) |
| 657 | return; |
| 658 | |
Jens Axboe | 90059d6 | 2007-07-30 09:33:12 +0200 | [diff] [blame] | 659 | fill_pattern(td, p, io_u->buflen); |
Jens Axboe | baefa9b | 2007-07-27 12:57:25 +0200 | [diff] [blame] | 660 | |
Shawn Lewis | 546a914 | 2007-07-28 21:11:37 +0200 | [diff] [blame] | 661 | hdr_inc = io_u->buflen; |
Jens Axboe | a59e170 | 2007-07-30 08:53:27 +0200 | [diff] [blame] | 662 | if (td->o.verify_interval) |
| 663 | hdr_inc = td->o.verify_interval; |
Shawn Lewis | 546a914 | 2007-07-28 21:11:37 +0200 | [diff] [blame] | 664 | |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 665 | for (; p < io_u->buf + io_u->buflen; p += hdr_inc) { |
Jens Axboe | 9564610 | 2007-07-28 21:17:50 +0200 | [diff] [blame] | 666 | hdr = p; |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 667 | |
| 668 | hdr->fio_magic = FIO_HDR_MAGIC; |
| 669 | hdr->verify_type = td->o.verify; |
Shawn Lewis | 546a914 | 2007-07-28 21:11:37 +0200 | [diff] [blame] | 670 | hdr->len = hdr_inc; |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 671 | data_len = hdr_inc - hdr_size(hdr); |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 672 | |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 673 | data = p + hdr_size(hdr); |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 674 | switch (td->o.verify) { |
| 675 | case VERIFY_MD5: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 676 | dprint(FD_VERIFY, "fill md5 io_u %p, len %u\n", |
| 677 | io_u, hdr->len); |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 678 | fill_md5(hdr, data, data_len); |
| 679 | break; |
| 680 | case VERIFY_CRC64: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 681 | dprint(FD_VERIFY, "fill crc64 io_u %p, len %u\n", |
| 682 | io_u, hdr->len); |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 683 | fill_crc64(hdr, data, data_len); |
| 684 | break; |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame] | 685 | case VERIFY_CRC32C: |
Jens Axboe | 3845591 | 2008-08-04 15:35:26 +0200 | [diff] [blame] | 686 | case VERIFY_CRC32C_INTEL: |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame] | 687 | dprint(FD_VERIFY, "fill crc32c io_u %p, len %u\n", |
| 688 | io_u, hdr->len); |
| 689 | fill_crc32c(hdr, data, data_len); |
| 690 | break; |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 691 | case VERIFY_CRC32: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 692 | dprint(FD_VERIFY, "fill crc32 io_u %p, len %u\n", |
| 693 | io_u, hdr->len); |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 694 | fill_crc32(hdr, data, data_len); |
| 695 | break; |
| 696 | case VERIFY_CRC16: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 697 | dprint(FD_VERIFY, "fill crc16 io_u %p, len %u\n", |
| 698 | io_u, hdr->len); |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 699 | fill_crc16(hdr, data, data_len); |
| 700 | break; |
| 701 | case VERIFY_CRC7: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 702 | dprint(FD_VERIFY, "fill crc7 io_u %p, len %u\n", |
| 703 | io_u, hdr->len); |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 704 | fill_crc7(hdr, data, data_len); |
| 705 | break; |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 706 | case VERIFY_SHA256: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 707 | dprint(FD_VERIFY, "fill sha256 io_u %p, len %u\n", |
| 708 | io_u, hdr->len); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 709 | fill_sha256(hdr, data, data_len); |
| 710 | break; |
| 711 | case VERIFY_SHA512: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 712 | dprint(FD_VERIFY, "fill sha512 io_u %p, len %u\n", |
| 713 | io_u, hdr->len); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 714 | fill_sha512(hdr, data, data_len); |
| 715 | break; |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 716 | case VERIFY_META: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 717 | dprint(FD_VERIFY, "fill meta io_u %p, len %u\n", |
| 718 | io_u, hdr->len); |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 719 | fill_meta(hdr, td, io_u, header_num); |
| 720 | break; |
Jens Axboe | 7c353ce | 2009-08-09 22:40:33 +0200 | [diff] [blame] | 721 | case VERIFY_SHA1: |
| 722 | dprint(FD_VERIFY, "fill sha1 io_u %p, len %u\n", |
| 723 | io_u, hdr->len); |
| 724 | fill_sha1(hdr, data, data_len); |
| 725 | break; |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 726 | default: |
| 727 | log_err("fio: bad verify type: %d\n", td->o.verify); |
| 728 | assert(0); |
| 729 | } |
Jens Axboe | a59e170 | 2007-07-30 08:53:27 +0200 | [diff] [blame] | 730 | if (td->o.verify_offset) |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 731 | memswp(p, p + td->o.verify_offset, hdr_size(hdr)); |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 732 | header_num++; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 733 | } |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | int get_next_verify(struct thread_data *td, struct io_u *io_u) |
| 737 | { |
Jens Axboe | 8de8f04 | 2007-03-27 10:36:12 +0200 | [diff] [blame] | 738 | struct io_piece *ipo = NULL; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 739 | |
Jens Axboe | d2d7fa5 | 2007-02-19 13:21:35 +0100 | [diff] [blame] | 740 | /* |
| 741 | * this io_u is from a requeue, we already filled the offsets |
| 742 | */ |
| 743 | if (io_u->file) |
| 744 | return 0; |
| 745 | |
Jens Axboe | 8de8f04 | 2007-03-27 10:36:12 +0200 | [diff] [blame] | 746 | if (!RB_EMPTY_ROOT(&td->io_hist_tree)) { |
| 747 | struct rb_node *n = rb_first(&td->io_hist_tree); |
| 748 | |
Jens Axboe | 4b87898 | 2007-03-26 09:32:22 +0200 | [diff] [blame] | 749 | ipo = rb_entry(n, struct io_piece, rb_node); |
Jens Axboe | 4b87898 | 2007-03-26 09:32:22 +0200 | [diff] [blame] | 750 | rb_erase(n, &td->io_hist_tree); |
Jens Axboe | 01743ee | 2008-06-02 12:19:19 +0200 | [diff] [blame] | 751 | } else if (!flist_empty(&td->io_hist_list)) { |
| 752 | ipo = flist_entry(td->io_hist_list.next, struct io_piece, list); |
| 753 | flist_del(&ipo->list); |
Jens Axboe | 8de8f04 | 2007-03-27 10:36:12 +0200 | [diff] [blame] | 754 | } |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 755 | |
Jens Axboe | 8de8f04 | 2007-03-27 10:36:12 +0200 | [diff] [blame] | 756 | if (ipo) { |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 757 | io_u->offset = ipo->offset; |
| 758 | io_u->buflen = ipo->len; |
Jens Axboe | 36167d8 | 2007-02-18 05:41:31 +0100 | [diff] [blame] | 759 | io_u->file = ipo->file; |
Jens Axboe | 97af62c | 2007-05-22 11:12:13 +0200 | [diff] [blame] | 760 | |
Jens Axboe | d6aed79 | 2009-06-03 08:41:15 +0200 | [diff] [blame] | 761 | if (!fio_file_open(io_u->file)) { |
Jens Axboe | 97af62c | 2007-05-22 11:12:13 +0200 | [diff] [blame] | 762 | int r = td_io_open_file(td, io_u->file); |
| 763 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 764 | if (r) { |
| 765 | dprint(FD_VERIFY, "failed file %s open\n", |
| 766 | io_u->file->file_name); |
Jens Axboe | 97af62c | 2007-05-22 11:12:13 +0200 | [diff] [blame] | 767 | return 1; |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 768 | } |
Jens Axboe | 97af62c | 2007-05-22 11:12:13 +0200 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | get_file(ipo->file); |
Jens Axboe | d6aed79 | 2009-06-03 08:41:15 +0200 | [diff] [blame] | 772 | assert(fio_file_open(io_u->file)); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 773 | io_u->ddir = DDIR_READ; |
Jens Axboe | 36167d8 | 2007-02-18 05:41:31 +0100 | [diff] [blame] | 774 | io_u->xfer_buf = io_u->buf; |
| 775 | io_u->xfer_buflen = io_u->buflen; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 776 | free(ipo); |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 777 | dprint(FD_VERIFY, "get_next_verify: ret io_u %p\n", io_u); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 778 | return 0; |
| 779 | } |
| 780 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 781 | dprint(FD_VERIFY, "get_next_verify: empty\n"); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 782 | return 1; |
| 783 | } |
Jens Axboe | e8462bd | 2009-07-06 12:59:04 +0200 | [diff] [blame] | 784 | |
| 785 | static void *verify_async_thread(void *data) |
| 786 | { |
| 787 | struct thread_data *td = data; |
| 788 | struct io_u *io_u; |
| 789 | int ret = 0; |
| 790 | |
| 791 | if (td->o.verify_cpumask_set && |
| 792 | fio_setaffinity(td->pid, td->o.verify_cpumask)) { |
| 793 | log_err("fio: failed setting verify thread affinity\n"); |
| 794 | goto done; |
| 795 | } |
| 796 | |
| 797 | do { |
Jens Axboe | e53ab27 | 2009-07-06 13:43:46 +0200 | [diff] [blame] | 798 | FLIST_HEAD(list); |
| 799 | |
Jens Axboe | e8462bd | 2009-07-06 12:59:04 +0200 | [diff] [blame] | 800 | read_barrier(); |
| 801 | if (td->verify_thread_exit) |
| 802 | break; |
| 803 | |
| 804 | pthread_mutex_lock(&td->io_u_lock); |
| 805 | |
| 806 | while (flist_empty(&td->verify_list) && |
| 807 | !td->verify_thread_exit) { |
Jens Axboe | b36e298 | 2009-07-06 14:12:52 +0200 | [diff] [blame] | 808 | ret = pthread_cond_wait(&td->verify_cond, |
| 809 | &td->io_u_lock); |
Jens Axboe | e8462bd | 2009-07-06 12:59:04 +0200 | [diff] [blame] | 810 | if (ret) { |
| 811 | pthread_mutex_unlock(&td->io_u_lock); |
| 812 | break; |
| 813 | } |
| 814 | } |
| 815 | |
Jens Axboe | e53ab27 | 2009-07-06 13:43:46 +0200 | [diff] [blame] | 816 | flist_splice_init(&td->verify_list, &list); |
Jens Axboe | e8462bd | 2009-07-06 12:59:04 +0200 | [diff] [blame] | 817 | pthread_mutex_unlock(&td->io_u_lock); |
| 818 | |
Jens Axboe | e53ab27 | 2009-07-06 13:43:46 +0200 | [diff] [blame] | 819 | if (flist_empty(&list)) |
| 820 | continue; |
| 821 | |
| 822 | while (!flist_empty(&list)) { |
| 823 | io_u = flist_entry(list.next, struct io_u, list); |
| 824 | flist_del_init(&io_u->list); |
| 825 | |
Jens Axboe | d561f2a | 2009-07-06 13:51:05 +0200 | [diff] [blame] | 826 | ret = verify_io_u(td, io_u); |
Jens Axboe | e53ab27 | 2009-07-06 13:43:46 +0200 | [diff] [blame] | 827 | put_io_u(td, io_u); |
Jens Axboe | d561f2a | 2009-07-06 13:51:05 +0200 | [diff] [blame] | 828 | if (!ret) |
| 829 | continue; |
| 830 | if (td->o.continue_on_error && |
| 831 | td_non_fatal_error(ret)) { |
| 832 | update_error_count(td, ret); |
| 833 | td_clear_error(td); |
| 834 | ret = 0; |
| 835 | } |
Jens Axboe | e53ab27 | 2009-07-06 13:43:46 +0200 | [diff] [blame] | 836 | } |
Jens Axboe | e8462bd | 2009-07-06 12:59:04 +0200 | [diff] [blame] | 837 | } while (!ret); |
| 838 | |
Jens Axboe | d561f2a | 2009-07-06 13:51:05 +0200 | [diff] [blame] | 839 | if (ret) { |
| 840 | td_verror(td, ret, "async_verify"); |
| 841 | td->terminate = 1; |
| 842 | } |
| 843 | |
Jens Axboe | e8462bd | 2009-07-06 12:59:04 +0200 | [diff] [blame] | 844 | done: |
| 845 | pthread_mutex_lock(&td->io_u_lock); |
| 846 | td->nr_verify_threads--; |
| 847 | pthread_mutex_unlock(&td->io_u_lock); |
| 848 | |
| 849 | pthread_cond_signal(&td->free_cond); |
| 850 | return NULL; |
| 851 | } |
| 852 | |
| 853 | int verify_async_init(struct thread_data *td) |
| 854 | { |
| 855 | int i, ret; |
| 856 | |
| 857 | td->verify_thread_exit = 0; |
| 858 | |
| 859 | td->verify_threads = malloc(sizeof(pthread_t) * td->o.verify_async); |
| 860 | for (i = 0; i < td->o.verify_async; i++) { |
| 861 | ret = pthread_create(&td->verify_threads[i], NULL, |
| 862 | verify_async_thread, td); |
| 863 | if (ret) { |
| 864 | log_err("fio: async verify creation failed: %s\n", |
| 865 | strerror(ret)); |
| 866 | break; |
| 867 | } |
| 868 | ret = pthread_detach(td->verify_threads[i]); |
| 869 | if (ret) { |
| 870 | log_err("fio: async verify thread detach failed: %s\n", |
| 871 | strerror(ret)); |
| 872 | break; |
| 873 | } |
| 874 | td->nr_verify_threads++; |
| 875 | } |
| 876 | |
| 877 | if (i != td->o.verify_async) { |
Jens Axboe | e40823b | 2009-07-06 14:28:21 +0200 | [diff] [blame] | 878 | log_err("fio: only %d verify threads started, exiting\n", i); |
Jens Axboe | e8462bd | 2009-07-06 12:59:04 +0200 | [diff] [blame] | 879 | td->verify_thread_exit = 1; |
| 880 | write_barrier(); |
| 881 | pthread_cond_broadcast(&td->verify_cond); |
| 882 | return 1; |
| 883 | } |
| 884 | |
| 885 | return 0; |
| 886 | } |
| 887 | |
| 888 | void verify_async_exit(struct thread_data *td) |
| 889 | { |
| 890 | td->verify_thread_exit = 1; |
| 891 | write_barrier(); |
| 892 | pthread_cond_broadcast(&td->verify_cond); |
| 893 | |
| 894 | pthread_mutex_lock(&td->io_u_lock); |
| 895 | |
| 896 | while (td->nr_verify_threads) |
| 897 | pthread_cond_wait(&td->free_cond, &td->io_u_lock); |
| 898 | |
| 899 | pthread_mutex_unlock(&td->io_u_lock); |
| 900 | free(td->verify_threads); |
| 901 | td->verify_threads = NULL; |
| 902 | } |