Commit c48101ae92c5ac6f2412ca345d9cc3557add8e47

Authored by aliguori
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 192 " Reads a segment of the currently open file, optionally dumping it to the\n"
193 193 " standard output stream (with -v option) for subsequent inspection.\n"
194 194 " -p, -- use bdrv_pread to read the file\n"
  195 +" -P, -- use a pattern to verify read data\n"
195 196 " -C, -- report statistics in a machine parsable format\n"
196 197 " -v, -- dump buffer to standard output\n"
197 198 " -q, -- quite mode, do not show I/O statistics\n"
... ... @@ -207,8 +208,10 @@ read_f(int argc, char **argv)
207 208 char *buf;
208 209 int64_t offset;
209 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 215 switch (c) {
213 216 case 'C':
214 217 Cflag = 1;
... ... @@ -216,6 +219,10 @@ read_f(int argc, char **argv)
216 219 case 'p':
217 220 pflag = 1;
218 221 break;
  222 + case 'P':
  223 + Pflag = 1;
  224 + pattern = atoi(optarg);
  225 + break;
219 226 case 'q':
220 227 qflag = 1;
221 228 break;
... ... @@ -270,6 +277,17 @@ read_f(int argc, char **argv)
270 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 291 if (qflag)
274 292 return 0;
275 293  
... ... @@ -291,7 +309,7 @@ static const cmdinfo_t read_cmd = {
291 309 .cfunc = read_f,
292 310 .argmin = 2,
293 311 .argmax = -1,
294   - .args = "[-aCpqv] off len",
  312 + .args = "[-aCpqv] [-P pattern ] off len",
295 313 .oneline = "reads a number of bytes at a specified offset",
296 314 .help = read_help,
297 315 };
... ... @@ -312,6 +330,7 @@ readv_help(void)
312 330 " standard output stream (with -v option) for subsequent inspection.\n"
313 331 " Uses multiple iovec buffers if more than one byte range is specified.\n"
314 332 " -C, -- report statistics in a machine parsable format\n"
  333 +" -P, -- use a pattern to verify read data\n"
315 334 " -v, -- dump buffer to standard output\n"
316 335 " -q, -- quite mode, do not show I/O statistics\n"
317 336 "\n");
... ... @@ -328,12 +347,18 @@ readv_f(int argc, char **argv)
328 347 int count = 0, total;
329 348 int nr_iov, i;
330 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 354 switch (c) {
334 355 case 'C':
335 356 Cflag = 1;
336 357 break;
  358 + case 'P':
  359 + Pflag = 1;
  360 + pattern = atoi(optarg);
  361 + break;
337 362 case 'q':
338 363 qflag = 1;
339 364 break;
... ... @@ -406,6 +431,17 @@ readv_f(int argc, char **argv)
406 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 445 if (qflag)
410 446 return 0;
411 447  
... ... @@ -426,7 +462,7 @@ static const cmdinfo_t readv_cmd = {
426 462 .cfunc = readv_f,
427 463 .argmin = 2,
428 464 .argmax = -1,
429   - .args = "[-Cqv] off len [len..]",
  465 + .args = "[-Cqv] [-P pattern ] off len [len..]",
430 466 .oneline = "reads a number of bytes at a specified offset",
431 467 .help = readv_help,
432 468 };
... ...