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