Commit c48101ae92c5ac6f2412ca345d9cc3557add8e47
1 parent
838ab728
qemu-io: Verify read data by patterns (Kevin Wolf)
This patch adds a -P option to read and readv which allows to compare the read data to a given pattern. This can be used to verify data written by write -P. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7182 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
40 additions
and
4 deletions
qemu-io.c
@@ -192,6 +192,7 @@ read_help(void) | @@ -192,6 +192,7 @@ read_help(void) | ||
192 | " Reads a segment of the currently open file, optionally dumping it to the\n" | 192 | " Reads a segment of the currently open file, optionally dumping it to the\n" |
193 | " standard output stream (with -v option) for subsequent inspection.\n" | 193 | " standard output stream (with -v option) for subsequent inspection.\n" |
194 | " -p, -- use bdrv_pread to read the file\n" | 194 | " -p, -- use bdrv_pread to read the file\n" |
195 | +" -P, -- use a pattern to verify read data\n" | ||
195 | " -C, -- report statistics in a machine parsable format\n" | 196 | " -C, -- report statistics in a machine parsable format\n" |
196 | " -v, -- dump buffer to standard output\n" | 197 | " -v, -- dump buffer to standard output\n" |
197 | " -q, -- quite mode, do not show I/O statistics\n" | 198 | " -q, -- quite mode, do not show I/O statistics\n" |
@@ -207,8 +208,10 @@ read_f(int argc, char **argv) | @@ -207,8 +208,10 @@ read_f(int argc, char **argv) | ||
207 | char *buf; | 208 | char *buf; |
208 | int64_t offset; | 209 | int64_t offset; |
209 | int count, total; | 210 | int count, total; |
211 | + int pattern = 0; | ||
212 | + int Pflag = 0; | ||
210 | 213 | ||
211 | - while ((c = getopt(argc, argv, "Cpqv")) != EOF) { | 214 | + while ((c = getopt(argc, argv, "CpP:qv")) != EOF) { |
212 | switch (c) { | 215 | switch (c) { |
213 | case 'C': | 216 | case 'C': |
214 | Cflag = 1; | 217 | Cflag = 1; |
@@ -216,6 +219,10 @@ read_f(int argc, char **argv) | @@ -216,6 +219,10 @@ read_f(int argc, char **argv) | ||
216 | case 'p': | 219 | case 'p': |
217 | pflag = 1; | 220 | pflag = 1; |
218 | break; | 221 | break; |
222 | + case 'P': | ||
223 | + Pflag = 1; | ||
224 | + pattern = atoi(optarg); | ||
225 | + break; | ||
219 | case 'q': | 226 | case 'q': |
220 | qflag = 1; | 227 | qflag = 1; |
221 | break; | 228 | break; |
@@ -270,6 +277,17 @@ read_f(int argc, char **argv) | @@ -270,6 +277,17 @@ read_f(int argc, char **argv) | ||
270 | return 0; | 277 | return 0; |
271 | } | 278 | } |
272 | 279 | ||
280 | + if (Pflag) { | ||
281 | + void* cmp_buf = malloc(count); | ||
282 | + memset(cmp_buf, pattern, count); | ||
283 | + if (memcmp(buf, cmp_buf, count)) { | ||
284 | + printf("Pattern verification failed at offset %lld, " | ||
285 | + "%d bytes\n", | ||
286 | + (long long) offset, count); | ||
287 | + } | ||
288 | + free(cmp_buf); | ||
289 | + } | ||
290 | + | ||
273 | if (qflag) | 291 | if (qflag) |
274 | return 0; | 292 | return 0; |
275 | 293 | ||
@@ -291,7 +309,7 @@ static const cmdinfo_t read_cmd = { | @@ -291,7 +309,7 @@ static const cmdinfo_t read_cmd = { | ||
291 | .cfunc = read_f, | 309 | .cfunc = read_f, |
292 | .argmin = 2, | 310 | .argmin = 2, |
293 | .argmax = -1, | 311 | .argmax = -1, |
294 | - .args = "[-aCpqv] off len", | 312 | + .args = "[-aCpqv] [-P pattern ] off len", |
295 | .oneline = "reads a number of bytes at a specified offset", | 313 | .oneline = "reads a number of bytes at a specified offset", |
296 | .help = read_help, | 314 | .help = read_help, |
297 | }; | 315 | }; |
@@ -312,6 +330,7 @@ readv_help(void) | @@ -312,6 +330,7 @@ readv_help(void) | ||
312 | " standard output stream (with -v option) for subsequent inspection.\n" | 330 | " standard output stream (with -v option) for subsequent inspection.\n" |
313 | " Uses multiple iovec buffers if more than one byte range is specified.\n" | 331 | " Uses multiple iovec buffers if more than one byte range is specified.\n" |
314 | " -C, -- report statistics in a machine parsable format\n" | 332 | " -C, -- report statistics in a machine parsable format\n" |
333 | +" -P, -- use a pattern to verify read data\n" | ||
315 | " -v, -- dump buffer to standard output\n" | 334 | " -v, -- dump buffer to standard output\n" |
316 | " -q, -- quite mode, do not show I/O statistics\n" | 335 | " -q, -- quite mode, do not show I/O statistics\n" |
317 | "\n"); | 336 | "\n"); |
@@ -328,12 +347,18 @@ readv_f(int argc, char **argv) | @@ -328,12 +347,18 @@ readv_f(int argc, char **argv) | ||
328 | int count = 0, total; | 347 | int count = 0, total; |
329 | int nr_iov, i; | 348 | int nr_iov, i; |
330 | QEMUIOVector qiov; | 349 | QEMUIOVector qiov; |
350 | + int pattern = 0; | ||
351 | + int Pflag = 0; | ||
331 | 352 | ||
332 | - while ((c = getopt(argc, argv, "Cqv")) != EOF) { | 353 | + while ((c = getopt(argc, argv, "CP:qv")) != EOF) { |
333 | switch (c) { | 354 | switch (c) { |
334 | case 'C': | 355 | case 'C': |
335 | Cflag = 1; | 356 | Cflag = 1; |
336 | break; | 357 | break; |
358 | + case 'P': | ||
359 | + Pflag = 1; | ||
360 | + pattern = atoi(optarg); | ||
361 | + break; | ||
337 | case 'q': | 362 | case 'q': |
338 | qflag = 1; | 363 | qflag = 1; |
339 | break; | 364 | break; |
@@ -406,6 +431,17 @@ readv_f(int argc, char **argv) | @@ -406,6 +431,17 @@ readv_f(int argc, char **argv) | ||
406 | return 0; | 431 | return 0; |
407 | } | 432 | } |
408 | 433 | ||
434 | + if (Pflag) { | ||
435 | + void* cmp_buf = malloc(count); | ||
436 | + memset(cmp_buf, pattern, count); | ||
437 | + if (memcmp(buf, cmp_buf, count)) { | ||
438 | + printf("Pattern verification failed at offset %lld, " | ||
439 | + "%d bytes\n", | ||
440 | + (long long) offset, count); | ||
441 | + } | ||
442 | + free(cmp_buf); | ||
443 | + } | ||
444 | + | ||
409 | if (qflag) | 445 | if (qflag) |
410 | return 0; | 446 | return 0; |
411 | 447 | ||
@@ -426,7 +462,7 @@ static const cmdinfo_t readv_cmd = { | @@ -426,7 +462,7 @@ static const cmdinfo_t readv_cmd = { | ||
426 | .cfunc = readv_f, | 462 | .cfunc = readv_f, |
427 | .argmin = 2, | 463 | .argmin = 2, |
428 | .argmax = -1, | 464 | .argmax = -1, |
429 | - .args = "[-Cqv] off len [len..]", | 465 | + .args = "[-Cqv] [-P pattern ] off len [len..]", |
430 | .oneline = "reads a number of bytes at a specified offset", | 466 | .oneline = "reads a number of bytes at a specified offset", |
431 | .help = readv_help, | 467 | .help = readv_help, |
432 | }; | 468 | }; |