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