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