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 | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 8 | |
| 9 | #include "fio.h" |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 10 | |
Jens Axboe | eef6eea | 2007-07-30 12:27:58 +0200 | [diff] [blame] | 11 | #include "crc/md5.h" |
| 12 | #include "crc/crc64.h" |
| 13 | #include "crc/crc32.h" |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame^] | 14 | #include "crc/crc32c.h" |
Jens Axboe | eef6eea | 2007-07-30 12:27:58 +0200 | [diff] [blame] | 15 | #include "crc/crc16.h" |
| 16 | #include "crc/crc7.h" |
| 17 | #include "crc/sha256.h" |
| 18 | #include "crc/sha512.h" |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 19 | |
Jens Axboe | 90059d6 | 2007-07-30 09:33:12 +0200 | [diff] [blame] | 20 | static void fill_random_bytes(struct thread_data *td, void *p, unsigned int len) |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 21 | { |
| 22 | unsigned int todo; |
Jens Axboe | 4c5946c | 2007-07-26 11:55:10 +0200 | [diff] [blame] | 23 | int r; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 24 | |
| 25 | while (len) { |
Jens Axboe | 4c5946c | 2007-07-26 11:55:10 +0200 | [diff] [blame] | 26 | r = os_random_long(&td->verify_state); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * lrand48_r seems to be broken and only fill the bottom |
| 30 | * 32-bits, even on 64-bit archs with 64-bit longs |
| 31 | */ |
| 32 | todo = sizeof(r); |
| 33 | if (todo > len) |
| 34 | todo = len; |
| 35 | |
| 36 | memcpy(p, &r, todo); |
| 37 | |
| 38 | len -= todo; |
| 39 | p += todo; |
| 40 | } |
| 41 | } |
| 42 | |
Jens Axboe | 90059d6 | 2007-07-30 09:33:12 +0200 | [diff] [blame] | 43 | static void fill_pattern(struct thread_data *td, void *p, unsigned int len) |
| 44 | { |
| 45 | switch (td->o.verify_pattern_bytes) { |
| 46 | case 0: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 47 | dprint(FD_VERIFY, "fill random bytes len=%u\n", len); |
Jens Axboe | 90059d6 | 2007-07-30 09:33:12 +0200 | [diff] [blame] | 48 | fill_random_bytes(td, p, len); |
| 49 | break; |
| 50 | case 1: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 51 | dprint(FD_VERIFY, "fill verify pattern b=0 len=%u\n", len); |
Jens Axboe | 90059d6 | 2007-07-30 09:33:12 +0200 | [diff] [blame] | 52 | memset(p, td->o.verify_pattern, len); |
| 53 | break; |
| 54 | case 2: |
| 55 | case 3: |
| 56 | case 4: { |
| 57 | unsigned int pattern = td->o.verify_pattern; |
| 58 | unsigned int i = 0; |
| 59 | unsigned char c1, c2, c3, c4; |
| 60 | unsigned char *b = p; |
| 61 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 62 | dprint(FD_VERIFY, "fill verify pattern b=%d len=%u\n", |
| 63 | td->o.verify_pattern_bytes, len); |
| 64 | |
Jens Axboe | 90059d6 | 2007-07-30 09:33:12 +0200 | [diff] [blame] | 65 | c1 = pattern & 0xff; |
| 66 | pattern >>= 8; |
| 67 | c2 = pattern & 0xff; |
| 68 | pattern >>= 8; |
| 69 | c3 = pattern & 0xff; |
| 70 | pattern >>= 8; |
| 71 | c4 = pattern & 0xff; |
| 72 | |
| 73 | while (i < len) { |
| 74 | b[i++] = c1; |
| 75 | if (i == len) |
| 76 | break; |
| 77 | b[i++] = c2; |
| 78 | if (td->o.verify_pattern_bytes == 2 || i == len) |
| 79 | continue; |
| 80 | b[i++] = c3; |
| 81 | if (td->o.verify_pattern_bytes == 3 || i == len) |
| 82 | continue; |
| 83 | b[i++] = c4; |
| 84 | } |
| 85 | break; |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
Jens Axboe | 4764aec | 2007-08-23 09:03:38 +0200 | [diff] [blame] | 90 | static void memswp(void *buf1, void *buf2, unsigned int len) |
Shawn Lewis | 546a914 | 2007-07-28 21:11:37 +0200 | [diff] [blame] | 91 | { |
Shawn Lewis | dee6de7 | 2007-08-02 22:17:52 +0200 | [diff] [blame] | 92 | char swap[200]; |
| 93 | |
| 94 | assert(len <= sizeof(swap)); |
Jens Axboe | 90059d6 | 2007-07-30 09:33:12 +0200 | [diff] [blame] | 95 | |
Shawn Lewis | 546a914 | 2007-07-28 21:11:37 +0200 | [diff] [blame] | 96 | memcpy(&swap, buf1, len); |
| 97 | memcpy(buf1, buf2, len); |
| 98 | memcpy(buf2, &swap, len); |
| 99 | } |
| 100 | |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 101 | static void hexdump(void *buffer, int len) |
| 102 | { |
| 103 | unsigned char *p = buffer; |
| 104 | int i; |
| 105 | |
| 106 | for (i = 0; i < len; i++) |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame] | 107 | log_info("%02x", p[i]); |
| 108 | log_info("\n"); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 109 | } |
| 110 | |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 111 | /* |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 112 | * Prepare for seperation of verify_header and checksum header |
| 113 | */ |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 114 | static inline unsigned int __hdr_size(int verify_type) |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 115 | { |
Jens Axboe | 5921e80 | 2008-05-30 15:02:38 +0200 | [diff] [blame] | 116 | unsigned int len = len; |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 117 | |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 118 | switch (verify_type) { |
| 119 | case VERIFY_NONE: |
| 120 | case VERIFY_NULL: |
| 121 | len = 0; |
| 122 | break; |
| 123 | case VERIFY_MD5: |
| 124 | len = sizeof(struct vhdr_md5); |
| 125 | break; |
| 126 | case VERIFY_CRC64: |
| 127 | len = sizeof(struct vhdr_crc64); |
| 128 | break; |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame^] | 129 | case VERIFY_CRC32C: |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 130 | case VERIFY_CRC32: |
| 131 | len = sizeof(struct vhdr_crc32); |
| 132 | break; |
| 133 | case VERIFY_CRC16: |
| 134 | len = sizeof(struct vhdr_crc16); |
| 135 | break; |
| 136 | case VERIFY_CRC7: |
| 137 | len = sizeof(struct vhdr_crc7); |
| 138 | break; |
| 139 | case VERIFY_SHA256: |
| 140 | len = sizeof(struct vhdr_sha256); |
| 141 | break; |
| 142 | case VERIFY_SHA512: |
| 143 | len = sizeof(struct vhdr_sha512); |
| 144 | break; |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 145 | case VERIFY_META: |
| 146 | len = sizeof(struct vhdr_meta); |
| 147 | break; |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 148 | default: |
| 149 | log_err("fio: unknown verify header!\n"); |
| 150 | assert(0); |
| 151 | } |
| 152 | |
| 153 | return len + sizeof(struct verify_header); |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | static inline unsigned int hdr_size(struct verify_header *hdr) |
| 157 | { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 158 | return __hdr_size(hdr->verify_type); |
| 159 | } |
| 160 | |
| 161 | static void *hdr_priv(struct verify_header *hdr) |
| 162 | { |
| 163 | void *priv = hdr; |
| 164 | |
| 165 | return priv + sizeof(struct verify_header); |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | /* |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 169 | * Return data area 'header_num' |
| 170 | */ |
| 171 | static inline void *io_u_verify_off(struct verify_header *hdr, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 172 | struct io_u *io_u, unsigned char header_num) |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 173 | { |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 174 | return io_u->buf + header_num * hdr->len + hdr_size(hdr); |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 175 | } |
| 176 | |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 177 | static int verify_io_u_meta(struct verify_header *hdr, struct thread_data *td, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 178 | struct io_u *io_u, unsigned int header_num) |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 179 | { |
| 180 | struct vhdr_meta *vh = hdr_priv(hdr); |
| 181 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 182 | dprint(FD_VERIFY, "meta verify io_u %p, len %u\n", io_u, hdr->len); |
| 183 | |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 184 | if (vh->offset != io_u->offset + header_num * td->o.verify_interval) { |
| 185 | log_err("meta: verify failed at %llu/%u\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 186 | io_u->offset + header_num * hdr->len, hdr->len); |
Jens Axboe | d16d4e0 | 2007-09-06 16:16:44 +0200 | [diff] [blame] | 187 | return EIO; |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 193 | static int verify_io_u_sha512(struct verify_header *hdr, struct io_u *io_u, |
| 194 | unsigned int header_num) |
| 195 | { |
| 196 | void *p = io_u_verify_off(hdr, io_u, header_num); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 197 | struct vhdr_sha512 *vh = hdr_priv(hdr); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 198 | uint8_t sha512[128]; |
| 199 | struct sha512_ctx sha512_ctx = { |
| 200 | .buf = sha512, |
| 201 | }; |
| 202 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 203 | dprint(FD_VERIFY, "sha512 verify io_u %p, len %u\n", io_u, hdr->len); |
| 204 | |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 205 | sha512_init(&sha512_ctx); |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 206 | sha512_update(&sha512_ctx, p, hdr->len - hdr_size(hdr)); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 207 | |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 208 | if (memcmp(vh->sha512, sha512_ctx.buf, sizeof(sha512))) { |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 209 | log_err("sha512: verify failed at %llu/%u\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 210 | io_u->offset + header_num * hdr->len, hdr->len); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 211 | hexdump(vh->sha512, sizeof(vh->sha512)); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 212 | hexdump(sha512_ctx.buf, sizeof(sha512)); |
Jens Axboe | d16d4e0 | 2007-09-06 16:16:44 +0200 | [diff] [blame] | 213 | return EIO; |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | static int verify_io_u_sha256(struct verify_header *hdr, struct io_u *io_u, |
| 220 | unsigned int header_num) |
| 221 | { |
| 222 | void *p = io_u_verify_off(hdr, io_u, header_num); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 223 | struct vhdr_sha256 *vh = hdr_priv(hdr); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 224 | uint8_t sha256[128]; |
| 225 | struct sha256_ctx sha256_ctx = { |
| 226 | .buf = sha256, |
| 227 | }; |
| 228 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 229 | dprint(FD_VERIFY, "sha256 verify io_u %p, len %u\n", io_u, hdr->len); |
| 230 | |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 231 | sha256_init(&sha256_ctx); |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 232 | sha256_update(&sha256_ctx, p, hdr->len - hdr_size(hdr)); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 233 | |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 234 | if (memcmp(vh->sha256, sha256_ctx.buf, sizeof(sha256))) { |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 235 | log_err("sha256: verify failed at %llu/%u\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 236 | io_u->offset + header_num * hdr->len, hdr->len); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 237 | hexdump(vh->sha256, sizeof(vh->sha256)); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 238 | hexdump(sha256_ctx.buf, sizeof(sha256)); |
Jens Axboe | d16d4e0 | 2007-09-06 16:16:44 +0200 | [diff] [blame] | 239 | return EIO; |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 245 | static int verify_io_u_crc7(struct verify_header *hdr, struct io_u *io_u, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 246 | unsigned char header_num) |
Jens Axboe | 1e154bd | 2007-07-27 09:52:40 +0200 | [diff] [blame] | 247 | { |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 248 | void *p = io_u_verify_off(hdr, io_u, header_num); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 249 | struct vhdr_crc7 *vh = hdr_priv(hdr); |
Jens Axboe | 1e154bd | 2007-07-27 09:52:40 +0200 | [diff] [blame] | 250 | unsigned char c; |
| 251 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 252 | dprint(FD_VERIFY, "crc7 verify io_u %p, len %u\n", io_u, hdr->len); |
| 253 | |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 254 | c = crc7(p, hdr->len - hdr_size(hdr)); |
Jens Axboe | 1e154bd | 2007-07-27 09:52:40 +0200 | [diff] [blame] | 255 | |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 256 | if (c != vh->crc7) { |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 257 | log_err("crc7: verify failed at %llu/%u\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 258 | io_u->offset + header_num * hdr->len, hdr->len); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 259 | log_err("crc7: wanted %x, got %x\n", vh->crc7, c); |
Jens Axboe | d16d4e0 | 2007-09-06 16:16:44 +0200 | [diff] [blame] | 260 | return EIO; |
Jens Axboe | 1e154bd | 2007-07-27 09:52:40 +0200 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | return 0; |
| 264 | } |
| 265 | |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 266 | static int verify_io_u_crc16(struct verify_header *hdr, struct io_u *io_u, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 267 | unsigned int header_num) |
Jens Axboe | 969f7ed | 2007-07-27 09:07:17 +0200 | [diff] [blame] | 268 | { |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 269 | void *p = io_u_verify_off(hdr, io_u, header_num); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 270 | struct vhdr_crc16 *vh = hdr_priv(hdr); |
Jens Axboe | 969f7ed | 2007-07-27 09:07:17 +0200 | [diff] [blame] | 271 | unsigned short c; |
| 272 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 273 | dprint(FD_VERIFY, "crc16 verify io_u %p, len %u\n", io_u, hdr->len); |
| 274 | |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 275 | c = crc16(p, hdr->len - hdr_size(hdr)); |
Jens Axboe | 969f7ed | 2007-07-27 09:07:17 +0200 | [diff] [blame] | 276 | |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 277 | if (c != vh->crc16) { |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 278 | log_err("crc16: verify failed at %llu/%u\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 279 | io_u->offset + header_num * hdr->len, hdr->len); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 280 | log_err("crc16: wanted %x, got %x\n", vh->crc16, c); |
Jens Axboe | d16d4e0 | 2007-09-06 16:16:44 +0200 | [diff] [blame] | 281 | return EIO; |
Jens Axboe | 969f7ed | 2007-07-27 09:07:17 +0200 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 287 | static int verify_io_u_crc64(struct verify_header *hdr, struct io_u *io_u, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 288 | unsigned int header_num) |
Jens Axboe | d77a7af | 2007-07-27 15:35:06 +0200 | [diff] [blame] | 289 | { |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 290 | void *p = io_u_verify_off(hdr, io_u, header_num); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 291 | struct vhdr_crc64 *vh = hdr_priv(hdr); |
Jens Axboe | d77a7af | 2007-07-27 15:35:06 +0200 | [diff] [blame] | 292 | unsigned long long c; |
| 293 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 294 | dprint(FD_VERIFY, "crc64 verify io_u %p, len %u\n", io_u, hdr->len); |
| 295 | |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 296 | c = crc64(p, hdr->len - hdr_size(hdr)); |
Jens Axboe | d77a7af | 2007-07-27 15:35:06 +0200 | [diff] [blame] | 297 | |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 298 | if (c != vh->crc64) { |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 299 | log_err("crc64: verify failed at %llu/%u\n", |
| 300 | io_u->offset + header_num * hdr->len, |
| 301 | hdr->len); |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 302 | log_err("crc64: wanted %llx, got %llx\n", |
| 303 | (unsigned long long) vh->crc64, c); |
Jens Axboe | d16d4e0 | 2007-09-06 16:16:44 +0200 | [diff] [blame] | 304 | return EIO; |
Jens Axboe | d77a7af | 2007-07-27 15:35:06 +0200 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 310 | static int verify_io_u_crc32(struct verify_header *hdr, struct io_u *io_u, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 311 | unsigned int header_num) |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 312 | { |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 313 | void *p = io_u_verify_off(hdr, io_u, header_num); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 314 | struct vhdr_crc32 *vh = hdr_priv(hdr); |
| 315 | uint32_t c; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 316 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 317 | dprint(FD_VERIFY, "crc32 verify io_u %p, len %u\n", io_u, hdr->len); |
| 318 | |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 319 | c = crc32(p, hdr->len - hdr_size(hdr)); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 320 | |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 321 | if (c != vh->crc32) { |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 322 | log_err("crc32: verify failed at %llu/%u\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 323 | io_u->offset + header_num * hdr->len, hdr->len); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 324 | log_err("crc32: wanted %x, got %x\n", vh->crc32, c); |
Jens Axboe | d16d4e0 | 2007-09-06 16:16:44 +0200 | [diff] [blame] | 325 | return EIO; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | return 0; |
| 329 | } |
| 330 | |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame^] | 331 | static int verify_io_u_crc32c(struct verify_header *hdr, struct io_u *io_u, |
| 332 | unsigned int header_num) |
| 333 | { |
| 334 | void *p = io_u_verify_off(hdr, io_u, header_num); |
| 335 | struct vhdr_crc32 *vh = hdr_priv(hdr); |
| 336 | uint32_t c; |
| 337 | |
| 338 | dprint(FD_VERIFY, "crc32c verify io_u %p, len %u\n", io_u, hdr->len); |
| 339 | |
| 340 | c = crc32c(p, hdr->len - hdr_size(hdr)); |
| 341 | |
| 342 | if (c != vh->crc32) { |
| 343 | log_err("crc32c: verify failed at %llu/%u\n", |
| 344 | io_u->offset + header_num * hdr->len, hdr->len); |
| 345 | log_err("crc32c: wanted %x, got %x\n", vh->crc32, c); |
| 346 | return EIO; |
| 347 | } |
| 348 | |
| 349 | return 0; |
| 350 | } |
| 351 | |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 352 | static int verify_io_u_md5(struct verify_header *hdr, struct io_u *io_u, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 353 | unsigned int header_num) |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 354 | { |
Jens Axboe | d9f2caf | 2007-07-28 21:22:03 +0200 | [diff] [blame] | 355 | void *p = io_u_verify_off(hdr, io_u, header_num); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 356 | struct vhdr_md5 *vh = hdr_priv(hdr); |
Jens Axboe | 8c43232 | 2007-07-27 13:16:24 +0200 | [diff] [blame] | 357 | uint32_t hash[MD5_HASH_WORDS]; |
| 358 | struct md5_ctx md5_ctx = { |
| 359 | .hash = hash, |
| 360 | }; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 361 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 362 | dprint(FD_VERIFY, "md5 verify io_u %p, len %u\n", io_u, hdr->len); |
| 363 | |
Jens Axboe | 61f821f | 2007-07-30 10:18:06 +0200 | [diff] [blame] | 364 | md5_init(&md5_ctx); |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 365 | md5_update(&md5_ctx, p, hdr->len - hdr_size(hdr)); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 366 | |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 367 | if (memcmp(vh->md5_digest, md5_ctx.hash, sizeof(hash))) { |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 368 | log_err("md5: verify failed at %llu/%u\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 369 | io_u->offset + header_num * hdr->len, hdr->len); |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 370 | hexdump(vh->md5_digest, sizeof(vh->md5_digest)); |
Jens Axboe | 8c43232 | 2007-07-27 13:16:24 +0200 | [diff] [blame] | 371 | hexdump(md5_ctx.hash, sizeof(hash)); |
Jens Axboe | d16d4e0 | 2007-09-06 16:16:44 +0200 | [diff] [blame] | 372 | return EIO; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
Jens Axboe | 3f199b0 | 2007-08-09 10:16:31 +0200 | [diff] [blame] | 378 | static unsigned int hweight8(unsigned int w) |
| 379 | { |
| 380 | unsigned int res = w - ((w >> 1) & 0x55); |
| 381 | |
| 382 | res = (res & 0x33) + ((res >> 2) & 0x33); |
| 383 | return (res + (res >> 4)) & 0x0F; |
| 384 | } |
| 385 | |
Shawn Lewis | a944e33 | 2007-08-02 22:18:29 +0200 | [diff] [blame] | 386 | int verify_io_u_pattern(unsigned long pattern, unsigned long pattern_size, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 387 | char *buf, unsigned int len, unsigned int mod) |
Shawn Lewis | a944e33 | 2007-08-02 22:18:29 +0200 | [diff] [blame] | 388 | { |
| 389 | unsigned int i; |
| 390 | char split_pattern[4]; |
| 391 | |
| 392 | for (i = 0; i < 4; i++) { |
| 393 | split_pattern[i] = pattern & 0xff; |
| 394 | pattern >>= 8; |
| 395 | } |
| 396 | |
| 397 | for (i = 0; i < len; i++) { |
Jens Axboe | 3f199b0 | 2007-08-09 10:16:31 +0200 | [diff] [blame] | 398 | if (buf[i] != split_pattern[mod]) { |
| 399 | unsigned int bits; |
| 400 | |
| 401 | bits = hweight8(buf[i] ^ split_pattern[mod]); |
| 402 | log_err("fio: got pattern %x, wanted %x. Bad bits %d\n", |
| 403 | buf[i], split_pattern[mod], bits); |
| 404 | log_err("fio: bad pattern block offset %u\n", i); |
Jens Axboe | d16d4e0 | 2007-09-06 16:16:44 +0200 | [diff] [blame] | 405 | return EIO; |
Jens Axboe | 3f199b0 | 2007-08-09 10:16:31 +0200 | [diff] [blame] | 406 | } |
Shawn Lewis | a944e33 | 2007-08-02 22:18:29 +0200 | [diff] [blame] | 407 | mod++; |
| 408 | if (mod == pattern_size) |
| 409 | mod = 0; |
| 410 | } |
| 411 | |
| 412 | return 0; |
| 413 | } |
| 414 | |
Jens Axboe | 36690c9 | 2007-03-26 10:23:34 +0200 | [diff] [blame] | 415 | 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] | 416 | { |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 417 | struct verify_header *hdr; |
Shawn Lewis | a944e33 | 2007-08-02 22:18:29 +0200 | [diff] [blame] | 418 | unsigned int hdr_size, hdr_inc, hdr_num = 0; |
Jens Axboe | 9564610 | 2007-07-28 21:17:50 +0200 | [diff] [blame] | 419 | void *p; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 420 | int ret; |
| 421 | |
Shawn Lewis | 1dcc049 | 2007-07-27 08:02:45 +0200 | [diff] [blame] | 422 | if (td->o.verify == VERIFY_NULL || io_u->ddir != DDIR_READ) |
Jens Axboe | 36690c9 | 2007-03-26 10:23:34 +0200 | [diff] [blame] | 423 | return 0; |
| 424 | |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 425 | hdr_inc = io_u->buflen; |
Jens Axboe | a59e170 | 2007-07-30 08:53:27 +0200 | [diff] [blame] | 426 | if (td->o.verify_interval) |
| 427 | hdr_inc = td->o.verify_interval; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 428 | |
Jens Axboe | a12a3b4 | 2007-08-09 10:20:54 +0200 | [diff] [blame] | 429 | ret = 0; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 430 | for (p = io_u->buf; p < io_u->buf + io_u->buflen; |
| 431 | p += hdr_inc, hdr_num++) { |
Jens Axboe | a12a3b4 | 2007-08-09 10:20:54 +0200 | [diff] [blame] | 432 | if (ret && td->o.verify_fatal) { |
| 433 | td->terminate = 1; |
| 434 | break; |
| 435 | } |
Shawn Lewis | a944e33 | 2007-08-02 22:18:29 +0200 | [diff] [blame] | 436 | hdr_size = __hdr_size(td->o.verify); |
Jens Axboe | a59e170 | 2007-07-30 08:53:27 +0200 | [diff] [blame] | 437 | if (td->o.verify_offset) |
Shawn Lewis | a944e33 | 2007-08-02 22:18:29 +0200 | [diff] [blame] | 438 | memswp(p, p + td->o.verify_offset, hdr_size); |
Jens Axboe | 9564610 | 2007-07-28 21:17:50 +0200 | [diff] [blame] | 439 | hdr = p; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 440 | |
Jens Axboe | 3f199b0 | 2007-08-09 10:16:31 +0200 | [diff] [blame] | 441 | if (hdr->fio_magic != FIO_HDR_MAGIC) { |
| 442 | log_err("Bad verify header %x\n", hdr->fio_magic); |
| 443 | return EIO; |
| 444 | } |
| 445 | |
Shawn Lewis | e28218f | 2008-01-16 11:01:33 +0100 | [diff] [blame] | 446 | if (td->o.verify_pattern_bytes) { |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 447 | dprint(FD_VERIFY, "pattern verify io_u %p, len %u\n", |
| 448 | io_u, hdr->len); |
Shawn Lewis | e28218f | 2008-01-16 11:01:33 +0100 | [diff] [blame] | 449 | ret = verify_io_u_pattern(td->o.verify_pattern, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 450 | td->o.verify_pattern_bytes, |
| 451 | p + hdr_size, |
| 452 | hdr_inc - hdr_size, |
| 453 | hdr_size % 4); |
Shawn Lewis | e28218f | 2008-01-16 11:01:33 +0100 | [diff] [blame] | 454 | if (ret) |
| 455 | log_err("fio: verify failed at %llu/%u\n", |
| 456 | io_u->offset + hdr_num * hdr->len, |
| 457 | hdr->len); |
| 458 | continue; |
| 459 | } |
| 460 | |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 461 | switch (hdr->verify_type) { |
| 462 | case VERIFY_MD5: |
| 463 | ret = verify_io_u_md5(hdr, io_u, hdr_num); |
| 464 | break; |
| 465 | case VERIFY_CRC64: |
| 466 | ret = verify_io_u_crc64(hdr, io_u, hdr_num); |
| 467 | break; |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame^] | 468 | case VERIFY_CRC32C: |
| 469 | ret = verify_io_u_crc32c(hdr, io_u, hdr_num); |
| 470 | break; |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 471 | case VERIFY_CRC32: |
| 472 | ret = verify_io_u_crc32(hdr, io_u, hdr_num); |
| 473 | break; |
| 474 | case VERIFY_CRC16: |
| 475 | ret = verify_io_u_crc16(hdr, io_u, hdr_num); |
| 476 | break; |
| 477 | case VERIFY_CRC7: |
| 478 | ret = verify_io_u_crc7(hdr, io_u, hdr_num); |
| 479 | break; |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 480 | case VERIFY_SHA256: |
| 481 | ret = verify_io_u_sha256(hdr, io_u, hdr_num); |
| 482 | break; |
| 483 | case VERIFY_SHA512: |
| 484 | ret = verify_io_u_sha512(hdr, io_u, hdr_num); |
| 485 | break; |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 486 | case VERIFY_META: |
| 487 | ret = verify_io_u_meta(hdr, td, io_u, hdr_num); |
| 488 | break; |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 489 | default: |
| 490 | log_err("Bad verify type %u\n", hdr->verify_type); |
Jens Axboe | d16d4e0 | 2007-09-06 16:16:44 +0200 | [diff] [blame] | 491 | ret = EINVAL; |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 492 | } |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 493 | } |
Jens Axboe | a7dfe86 | 2007-03-12 10:05:08 +0100 | [diff] [blame] | 494 | |
Jens Axboe | a12a3b4 | 2007-08-09 10:20:54 +0200 | [diff] [blame] | 495 | return ret; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 496 | } |
| 497 | |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 498 | static void fill_meta(struct verify_header *hdr, struct thread_data *td, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 499 | struct io_u *io_u, unsigned int header_num) |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 500 | { |
| 501 | struct vhdr_meta *vh = hdr_priv(hdr); |
| 502 | |
| 503 | vh->thread = td->thread_number; |
| 504 | |
| 505 | vh->time_sec = io_u->start_time.tv_sec; |
| 506 | vh->time_usec = io_u->start_time.tv_usec; |
| 507 | |
| 508 | vh->numberio = td->io_issues[DDIR_WRITE]; |
| 509 | |
| 510 | vh->offset = io_u->offset + header_num * td->o.verify_interval; |
| 511 | } |
| 512 | |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 513 | static void fill_sha512(struct verify_header *hdr, void *p, unsigned int len) |
| 514 | { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 515 | struct vhdr_sha512 *vh = hdr_priv(hdr); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 516 | struct sha512_ctx sha512_ctx = { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 517 | .buf = vh->sha512, |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 518 | }; |
| 519 | |
| 520 | sha512_init(&sha512_ctx); |
| 521 | sha512_update(&sha512_ctx, p, len); |
| 522 | } |
| 523 | |
| 524 | static void fill_sha256(struct verify_header *hdr, void *p, unsigned int len) |
| 525 | { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 526 | struct vhdr_sha256 *vh = hdr_priv(hdr); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 527 | struct sha256_ctx sha256_ctx = { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 528 | .buf = vh->sha256, |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 529 | }; |
| 530 | |
| 531 | sha256_init(&sha256_ctx); |
| 532 | sha256_update(&sha256_ctx, p, len); |
| 533 | } |
| 534 | |
Jens Axboe | 1e154bd | 2007-07-27 09:52:40 +0200 | [diff] [blame] | 535 | static void fill_crc7(struct verify_header *hdr, void *p, unsigned int len) |
| 536 | { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 537 | struct vhdr_crc7 *vh = hdr_priv(hdr); |
| 538 | |
| 539 | vh->crc7 = crc7(p, len); |
Jens Axboe | 1e154bd | 2007-07-27 09:52:40 +0200 | [diff] [blame] | 540 | } |
| 541 | |
Jens Axboe | 969f7ed | 2007-07-27 09:07:17 +0200 | [diff] [blame] | 542 | static void fill_crc16(struct verify_header *hdr, void *p, unsigned int len) |
| 543 | { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 544 | struct vhdr_crc16 *vh = hdr_priv(hdr); |
| 545 | |
| 546 | vh->crc16 = crc16(p, len); |
Jens Axboe | 969f7ed | 2007-07-27 09:07:17 +0200 | [diff] [blame] | 547 | } |
| 548 | |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 549 | static void fill_crc32(struct verify_header *hdr, void *p, unsigned int len) |
| 550 | { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 551 | struct vhdr_crc32 *vh = hdr_priv(hdr); |
| 552 | |
| 553 | vh->crc32 = crc32(p, len); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 554 | } |
| 555 | |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame^] | 556 | static void fill_crc32c(struct verify_header *hdr, void *p, unsigned int len) |
| 557 | { |
| 558 | struct vhdr_crc32 *vh = hdr_priv(hdr); |
| 559 | |
| 560 | vh->crc32 = crc32c(p, len); |
| 561 | } |
| 562 | |
Jens Axboe | d77a7af | 2007-07-27 15:35:06 +0200 | [diff] [blame] | 563 | static void fill_crc64(struct verify_header *hdr, void *p, unsigned int len) |
| 564 | { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 565 | struct vhdr_crc64 *vh = hdr_priv(hdr); |
| 566 | |
| 567 | vh->crc64 = crc64(p, len); |
Jens Axboe | d77a7af | 2007-07-27 15:35:06 +0200 | [diff] [blame] | 568 | } |
| 569 | |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 570 | static void fill_md5(struct verify_header *hdr, void *p, unsigned int len) |
| 571 | { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 572 | struct vhdr_md5 *vh = hdr_priv(hdr); |
Jens Axboe | 8c43232 | 2007-07-27 13:16:24 +0200 | [diff] [blame] | 573 | struct md5_ctx md5_ctx = { |
Jens Axboe | 546dfd9 | 2007-07-30 12:23:05 +0200 | [diff] [blame] | 574 | .hash = (uint32_t *) vh->md5_digest, |
Jens Axboe | 8c43232 | 2007-07-27 13:16:24 +0200 | [diff] [blame] | 575 | }; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 576 | |
Jens Axboe | 61f821f | 2007-07-30 10:18:06 +0200 | [diff] [blame] | 577 | md5_init(&md5_ctx); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 578 | md5_update(&md5_ctx, p, len); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | /* |
| 582 | * fill body of io_u->buf with random data and add a header with the |
| 583 | * crc32 or md5 sum of that data. |
| 584 | */ |
| 585 | void populate_verify_io_u(struct thread_data *td, struct io_u *io_u) |
| 586 | { |
Jens Axboe | baefa9b | 2007-07-27 12:57:25 +0200 | [diff] [blame] | 587 | struct verify_header *hdr; |
Jens Axboe | 9564610 | 2007-07-28 21:17:50 +0200 | [diff] [blame] | 588 | void *p = io_u->buf, *data; |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 589 | unsigned int hdr_inc, data_len, header_num = 0; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 590 | |
Jens Axboe | 9cc3d15 | 2007-03-26 10:32:30 +0200 | [diff] [blame] | 591 | if (td->o.verify == VERIFY_NULL) |
| 592 | return; |
| 593 | |
Jens Axboe | 90059d6 | 2007-07-30 09:33:12 +0200 | [diff] [blame] | 594 | fill_pattern(td, p, io_u->buflen); |
Jens Axboe | baefa9b | 2007-07-27 12:57:25 +0200 | [diff] [blame] | 595 | |
Shawn Lewis | 546a914 | 2007-07-28 21:11:37 +0200 | [diff] [blame] | 596 | hdr_inc = io_u->buflen; |
Jens Axboe | a59e170 | 2007-07-30 08:53:27 +0200 | [diff] [blame] | 597 | if (td->o.verify_interval) |
| 598 | hdr_inc = td->o.verify_interval; |
Shawn Lewis | 546a914 | 2007-07-28 21:11:37 +0200 | [diff] [blame] | 599 | |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 600 | for (; p < io_u->buf + io_u->buflen; p += hdr_inc) { |
Jens Axboe | 9564610 | 2007-07-28 21:17:50 +0200 | [diff] [blame] | 601 | hdr = p; |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 602 | |
| 603 | hdr->fio_magic = FIO_HDR_MAGIC; |
| 604 | hdr->verify_type = td->o.verify; |
Shawn Lewis | 546a914 | 2007-07-28 21:11:37 +0200 | [diff] [blame] | 605 | hdr->len = hdr_inc; |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 606 | data_len = hdr_inc - hdr_size(hdr); |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 607 | |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 608 | data = p + hdr_size(hdr); |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 609 | switch (td->o.verify) { |
| 610 | case VERIFY_MD5: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 611 | dprint(FD_VERIFY, "fill md5 io_u %p, len %u\n", |
| 612 | io_u, hdr->len); |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 613 | fill_md5(hdr, data, data_len); |
| 614 | break; |
| 615 | case VERIFY_CRC64: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 616 | dprint(FD_VERIFY, "fill crc64 io_u %p, len %u\n", |
| 617 | io_u, hdr->len); |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 618 | fill_crc64(hdr, data, data_len); |
| 619 | break; |
Jens Axboe | bac39e0 | 2008-06-11 20:46:19 +0200 | [diff] [blame^] | 620 | case VERIFY_CRC32C: |
| 621 | dprint(FD_VERIFY, "fill crc32c io_u %p, len %u\n", |
| 622 | io_u, hdr->len); |
| 623 | fill_crc32c(hdr, data, data_len); |
| 624 | break; |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 625 | case VERIFY_CRC32: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 626 | dprint(FD_VERIFY, "fill crc32 io_u %p, len %u\n", |
| 627 | io_u, hdr->len); |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 628 | fill_crc32(hdr, data, data_len); |
| 629 | break; |
| 630 | case VERIFY_CRC16: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 631 | dprint(FD_VERIFY, "fill crc16 io_u %p, len %u\n", |
| 632 | io_u, hdr->len); |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 633 | fill_crc16(hdr, data, data_len); |
| 634 | break; |
| 635 | case VERIFY_CRC7: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 636 | dprint(FD_VERIFY, "fill crc7 io_u %p, len %u\n", |
| 637 | io_u, hdr->len); |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 638 | fill_crc7(hdr, data, data_len); |
| 639 | break; |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 640 | case VERIFY_SHA256: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 641 | dprint(FD_VERIFY, "fill sha256 io_u %p, len %u\n", |
| 642 | io_u, hdr->len); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 643 | fill_sha256(hdr, data, data_len); |
| 644 | break; |
| 645 | case VERIFY_SHA512: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 646 | dprint(FD_VERIFY, "fill sha512 io_u %p, len %u\n", |
| 647 | io_u, hdr->len); |
Jens Axboe | cd14cc1 | 2007-07-30 10:59:33 +0200 | [diff] [blame] | 648 | fill_sha512(hdr, data, data_len); |
| 649 | break; |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 650 | case VERIFY_META: |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 651 | dprint(FD_VERIFY, "fill meta io_u %p, len %u\n", |
| 652 | io_u, hdr->len); |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 653 | fill_meta(hdr, td, io_u, header_num); |
| 654 | break; |
Shawn Lewis | 3f9f4e2 | 2007-07-28 21:10:37 +0200 | [diff] [blame] | 655 | default: |
| 656 | log_err("fio: bad verify type: %d\n", td->o.verify); |
| 657 | assert(0); |
| 658 | } |
Jens Axboe | a59e170 | 2007-07-30 08:53:27 +0200 | [diff] [blame] | 659 | if (td->o.verify_offset) |
Jens Axboe | 8767783 | 2007-07-30 12:08:14 +0200 | [diff] [blame] | 660 | memswp(p, p + td->o.verify_offset, hdr_size(hdr)); |
Shawn Lewis | 7437ee8 | 2007-08-02 21:05:58 +0200 | [diff] [blame] | 661 | header_num++; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 662 | } |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | int get_next_verify(struct thread_data *td, struct io_u *io_u) |
| 666 | { |
Jens Axboe | 8de8f04 | 2007-03-27 10:36:12 +0200 | [diff] [blame] | 667 | struct io_piece *ipo = NULL; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 668 | |
Jens Axboe | d2d7fa5 | 2007-02-19 13:21:35 +0100 | [diff] [blame] | 669 | /* |
| 670 | * this io_u is from a requeue, we already filled the offsets |
| 671 | */ |
| 672 | if (io_u->file) |
| 673 | return 0; |
| 674 | |
Jens Axboe | 8de8f04 | 2007-03-27 10:36:12 +0200 | [diff] [blame] | 675 | if (!RB_EMPTY_ROOT(&td->io_hist_tree)) { |
| 676 | struct rb_node *n = rb_first(&td->io_hist_tree); |
| 677 | |
Jens Axboe | 4b87898 | 2007-03-26 09:32:22 +0200 | [diff] [blame] | 678 | ipo = rb_entry(n, struct io_piece, rb_node); |
Jens Axboe | 4b87898 | 2007-03-26 09:32:22 +0200 | [diff] [blame] | 679 | rb_erase(n, &td->io_hist_tree); |
Jens Axboe | 01743ee | 2008-06-02 12:19:19 +0200 | [diff] [blame] | 680 | } else if (!flist_empty(&td->io_hist_list)) { |
| 681 | ipo = flist_entry(td->io_hist_list.next, struct io_piece, list); |
| 682 | flist_del(&ipo->list); |
Jens Axboe | 8de8f04 | 2007-03-27 10:36:12 +0200 | [diff] [blame] | 683 | } |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 684 | |
Jens Axboe | 8de8f04 | 2007-03-27 10:36:12 +0200 | [diff] [blame] | 685 | if (ipo) { |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 686 | io_u->offset = ipo->offset; |
| 687 | io_u->buflen = ipo->len; |
Jens Axboe | 36167d8 | 2007-02-18 05:41:31 +0100 | [diff] [blame] | 688 | io_u->file = ipo->file; |
Jens Axboe | 97af62c | 2007-05-22 11:12:13 +0200 | [diff] [blame] | 689 | |
| 690 | if ((io_u->file->flags & FIO_FILE_OPEN) == 0) { |
| 691 | int r = td_io_open_file(td, io_u->file); |
| 692 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 693 | if (r) { |
| 694 | dprint(FD_VERIFY, "failed file %s open\n", |
| 695 | io_u->file->file_name); |
Jens Axboe | 97af62c | 2007-05-22 11:12:13 +0200 | [diff] [blame] | 696 | return 1; |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 697 | } |
Jens Axboe | 97af62c | 2007-05-22 11:12:13 +0200 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | get_file(ipo->file); |
| 701 | assert(io_u->file->flags & FIO_FILE_OPEN); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 702 | io_u->ddir = DDIR_READ; |
Jens Axboe | 36167d8 | 2007-02-18 05:41:31 +0100 | [diff] [blame] | 703 | io_u->xfer_buf = io_u->buf; |
| 704 | io_u->xfer_buflen = io_u->buflen; |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 705 | free(ipo); |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 706 | 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] | 707 | return 0; |
| 708 | } |
| 709 | |
Jens Axboe | bd6f78b | 2008-02-01 20:27:52 +0100 | [diff] [blame] | 710 | dprint(FD_VERIFY, "get_next_verify: empty\n"); |
Jens Axboe | e29d1b7 | 2006-10-18 15:43:15 +0200 | [diff] [blame] | 711 | return 1; |
| 712 | } |