Commit ca94dbc753ecc7318f329106f55712f1faaa7cf2
Committed by
Anthony Liguori
1 parent
bf4e5d92
qemu-io: Implement bdrv_load_vmstate/bdrv_save_vmstate
The load_vmstate and save_vmstate functions are implemented as a variation of the normal read/write operation, enabled by the -b option. This is the same mechanism as is used to switch from read/write to pread/pwrite. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing
1 changed file
with
44 additions
and
6 deletions
qemu-io.c
| @@ -187,6 +187,22 @@ static int do_pwrite(char *buf, int64_t offset, int count, int *total) | @@ -187,6 +187,22 @@ static int do_pwrite(char *buf, int64_t offset, int count, int *total) | ||
| 187 | return 1; | 187 | return 1; |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | +static int do_load_vmstate(char *buf, int64_t offset, int count, int *total) | ||
| 191 | +{ | ||
| 192 | + *total = bdrv_load_vmstate(bs, (uint8_t *)buf, offset, count); | ||
| 193 | + if (*total < 0) | ||
| 194 | + return *total; | ||
| 195 | + return 1; | ||
| 196 | +} | ||
| 197 | + | ||
| 198 | +static int do_save_vmstate(char *buf, int64_t offset, int count, int *total) | ||
| 199 | +{ | ||
| 200 | + *total = bdrv_save_vmstate(bs, (uint8_t *)buf, offset, count); | ||
| 201 | + if (*total < 0) | ||
| 202 | + return *total; | ||
| 203 | + return 1; | ||
| 204 | +} | ||
| 205 | + | ||
| 190 | #define NOT_DONE 0x7fffffff | 206 | #define NOT_DONE 0x7fffffff |
| 191 | static void aio_rw_done(void *opaque, int ret) | 207 | static void aio_rw_done(void *opaque, int ret) |
| 192 | { | 208 | { |
| @@ -242,6 +258,7 @@ read_help(void) | @@ -242,6 +258,7 @@ read_help(void) | ||
| 242 | "\n" | 258 | "\n" |
| 243 | " Reads a segment of the currently open file, optionally dumping it to the\n" | 259 | " Reads a segment of the currently open file, optionally dumping it to the\n" |
| 244 | " standard output stream (with -v option) for subsequent inspection.\n" | 260 | " standard output stream (with -v option) for subsequent inspection.\n" |
| 261 | +" -b, -- read from the VM state rather than the virtual disk\n" | ||
| 245 | " -C, -- report statistics in a machine parsable format\n" | 262 | " -C, -- report statistics in a machine parsable format\n" |
| 246 | " -l, -- length for pattern verification (only with -P)\n" | 263 | " -l, -- length for pattern verification (only with -P)\n" |
| 247 | " -p, -- use bdrv_pread to read the file\n" | 264 | " -p, -- use bdrv_pread to read the file\n" |
| @@ -257,7 +274,7 @@ read_f(int argc, char **argv) | @@ -257,7 +274,7 @@ read_f(int argc, char **argv) | ||
| 257 | { | 274 | { |
| 258 | struct timeval t1, t2; | 275 | struct timeval t1, t2; |
| 259 | int Cflag = 0, pflag = 0, qflag = 0, vflag = 0; | 276 | int Cflag = 0, pflag = 0, qflag = 0, vflag = 0; |
| 260 | - int Pflag = 0, sflag = 0, lflag = 0; | 277 | + int Pflag = 0, sflag = 0, lflag = 0, bflag = 0; |
| 261 | int c, cnt; | 278 | int c, cnt; |
| 262 | char *buf; | 279 | char *buf; |
| 263 | int64_t offset; | 280 | int64_t offset; |
| @@ -266,8 +283,11 @@ read_f(int argc, char **argv) | @@ -266,8 +283,11 @@ read_f(int argc, char **argv) | ||
| 266 | int total = 0; | 283 | int total = 0; |
| 267 | int pattern = 0, pattern_offset = 0, pattern_count = 0; | 284 | int pattern = 0, pattern_offset = 0, pattern_count = 0; |
| 268 | 285 | ||
| 269 | - while ((c = getopt(argc, argv, "Cl:pP:qs:v")) != EOF) { | 286 | + while ((c = getopt(argc, argv, "bCl:pP:qs:v")) != EOF) { |
| 270 | switch (c) { | 287 | switch (c) { |
| 288 | + case 'b': | ||
| 289 | + bflag = 1; | ||
| 290 | + break; | ||
| 271 | case 'C': | 291 | case 'C': |
| 272 | Cflag = 1; | 292 | Cflag = 1; |
| 273 | break; | 293 | break; |
| @@ -308,6 +328,11 @@ read_f(int argc, char **argv) | @@ -308,6 +328,11 @@ read_f(int argc, char **argv) | ||
| 308 | if (optind != argc - 2) | 328 | if (optind != argc - 2) |
| 309 | return command_usage(&read_cmd); | 329 | return command_usage(&read_cmd); |
| 310 | 330 | ||
| 331 | + if (bflag && pflag) { | ||
| 332 | + printf("-b and -p cannot be specified at the same time\n"); | ||
| 333 | + return 0; | ||
| 334 | + } | ||
| 335 | + | ||
| 311 | offset = cvtnum(argv[optind]); | 336 | offset = cvtnum(argv[optind]); |
| 312 | if (offset < 0) { | 337 | if (offset < 0) { |
| 313 | printf("non-numeric length argument -- %s\n", argv[optind]); | 338 | printf("non-numeric length argument -- %s\n", argv[optind]); |
| @@ -352,6 +377,8 @@ read_f(int argc, char **argv) | @@ -352,6 +377,8 @@ read_f(int argc, char **argv) | ||
| 352 | gettimeofday(&t1, NULL); | 377 | gettimeofday(&t1, NULL); |
| 353 | if (pflag) | 378 | if (pflag) |
| 354 | cnt = do_pread(buf, offset, count, &total); | 379 | cnt = do_pread(buf, offset, count, &total); |
| 380 | + else if (bflag) | ||
| 381 | + cnt = do_load_vmstate(buf, offset, count, &total); | ||
| 355 | else | 382 | else |
| 356 | cnt = do_read(buf, offset, count, &total); | 383 | cnt = do_read(buf, offset, count, &total); |
| 357 | gettimeofday(&t2, NULL); | 384 | gettimeofday(&t2, NULL); |
| @@ -394,7 +421,7 @@ static const cmdinfo_t read_cmd = { | @@ -394,7 +421,7 @@ static const cmdinfo_t read_cmd = { | ||
| 394 | .cfunc = read_f, | 421 | .cfunc = read_f, |
| 395 | .argmin = 2, | 422 | .argmin = 2, |
| 396 | .argmax = -1, | 423 | .argmax = -1, |
| 397 | - .args = "[-aCpqv] [-P pattern [-s off] [-l len]] off len", | 424 | + .args = "[-abCpqv] [-P pattern [-s off] [-l len]] off len", |
| 398 | .oneline = "reads a number of bytes at a specified offset", | 425 | .oneline = "reads a number of bytes at a specified offset", |
| 399 | .help = read_help, | 426 | .help = read_help, |
| 400 | }; | 427 | }; |
| @@ -534,6 +561,7 @@ write_help(void) | @@ -534,6 +561,7 @@ write_help(void) | ||
| 534 | "\n" | 561 | "\n" |
| 535 | " Writes into a segment of the currently open file, using a buffer\n" | 562 | " Writes into a segment of the currently open file, using a buffer\n" |
| 536 | " filled with a set pattern (0xcdcdcdcd).\n" | 563 | " filled with a set pattern (0xcdcdcdcd).\n" |
| 564 | +" -b, -- write to the VM state rather than the virtual disk\n" | ||
| 537 | " -p, -- use bdrv_pwrite to write the file\n" | 565 | " -p, -- use bdrv_pwrite to write the file\n" |
| 538 | " -P, -- use different pattern to fill file\n" | 566 | " -P, -- use different pattern to fill file\n" |
| 539 | " -C, -- report statistics in a machine parsable format\n" | 567 | " -C, -- report statistics in a machine parsable format\n" |
| @@ -545,7 +573,7 @@ static int | @@ -545,7 +573,7 @@ static int | ||
| 545 | write_f(int argc, char **argv) | 573 | write_f(int argc, char **argv) |
| 546 | { | 574 | { |
| 547 | struct timeval t1, t2; | 575 | struct timeval t1, t2; |
| 548 | - int Cflag = 0, pflag = 0, qflag = 0; | 576 | + int Cflag = 0, pflag = 0, qflag = 0, bflag = 0; |
| 549 | int c, cnt; | 577 | int c, cnt; |
| 550 | char *buf; | 578 | char *buf; |
| 551 | int64_t offset; | 579 | int64_t offset; |
| @@ -554,8 +582,11 @@ write_f(int argc, char **argv) | @@ -554,8 +582,11 @@ write_f(int argc, char **argv) | ||
| 554 | int total = 0; | 582 | int total = 0; |
| 555 | int pattern = 0xcd; | 583 | int pattern = 0xcd; |
| 556 | 584 | ||
| 557 | - while ((c = getopt(argc, argv, "CpP:q")) != EOF) { | 585 | + while ((c = getopt(argc, argv, "bCpP:q")) != EOF) { |
| 558 | switch (c) { | 586 | switch (c) { |
| 587 | + case 'b': | ||
| 588 | + bflag = 1; | ||
| 589 | + break; | ||
| 559 | case 'C': | 590 | case 'C': |
| 560 | Cflag = 1; | 591 | Cflag = 1; |
| 561 | break; | 592 | break; |
| @@ -576,6 +607,11 @@ write_f(int argc, char **argv) | @@ -576,6 +607,11 @@ write_f(int argc, char **argv) | ||
| 576 | if (optind != argc - 2) | 607 | if (optind != argc - 2) |
| 577 | return command_usage(&write_cmd); | 608 | return command_usage(&write_cmd); |
| 578 | 609 | ||
| 610 | + if (bflag && pflag) { | ||
| 611 | + printf("-b and -p cannot be specified at the same time\n"); | ||
| 612 | + return 0; | ||
| 613 | + } | ||
| 614 | + | ||
| 579 | offset = cvtnum(argv[optind]); | 615 | offset = cvtnum(argv[optind]); |
| 580 | if (offset < 0) { | 616 | if (offset < 0) { |
| 581 | printf("non-numeric length argument -- %s\n", argv[optind]); | 617 | printf("non-numeric length argument -- %s\n", argv[optind]); |
| @@ -608,6 +644,8 @@ write_f(int argc, char **argv) | @@ -608,6 +644,8 @@ write_f(int argc, char **argv) | ||
| 608 | gettimeofday(&t1, NULL); | 644 | gettimeofday(&t1, NULL); |
| 609 | if (pflag) | 645 | if (pflag) |
| 610 | cnt = do_pwrite(buf, offset, count, &total); | 646 | cnt = do_pwrite(buf, offset, count, &total); |
| 647 | + else if (bflag) | ||
| 648 | + cnt = do_save_vmstate(buf, offset, count, &total); | ||
| 611 | else | 649 | else |
| 612 | cnt = do_write(buf, offset, count, &total); | 650 | cnt = do_write(buf, offset, count, &total); |
| 613 | gettimeofday(&t2, NULL); | 651 | gettimeofday(&t2, NULL); |
| @@ -636,7 +674,7 @@ static const cmdinfo_t write_cmd = { | @@ -636,7 +674,7 @@ static const cmdinfo_t write_cmd = { | ||
| 636 | .cfunc = write_f, | 674 | .cfunc = write_f, |
| 637 | .argmin = 2, | 675 | .argmin = 2, |
| 638 | .argmax = -1, | 676 | .argmax = -1, |
| 639 | - .args = "[-aCpq] [-P pattern ] off len", | 677 | + .args = "[-abCpq] [-P pattern ] off len", |
| 640 | .oneline = "writes a number of bytes at a specified offset", | 678 | .oneline = "writes a number of bytes at a specified offset", |
| 641 | .help = write_help, | 679 | .help = write_help, |
| 642 | }; | 680 | }; |