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