Commit 230d4fa48bd64dbc07b509e0eb0bbc885ddf4cc8
Committed by
Anthony Liguori
1 parent
52249f0f
qemu-io: small cleanups for the aio code
Address a couple of review comments from Kevin. Signed-off-by: Christoph Hellwig <hch@lst.de>
Showing
1 changed file
with
16 additions
and
24 deletions
qemu-io.c
| ... | ... | @@ -769,25 +769,23 @@ aio_write_done(void *opaque, int ret) |
| 769 | 769 | { |
| 770 | 770 | struct aio_ctx *ctx = opaque; |
| 771 | 771 | struct timeval t2; |
| 772 | - int total; | |
| 773 | - int cnt = 1; | |
| 774 | 772 | |
| 775 | 773 | gettimeofday(&t2, NULL); |
| 776 | 774 | |
| 777 | - total = ctx->qiov.size; | |
| 778 | 775 | |
| 779 | 776 | if (ret < 0) { |
| 780 | 777 | printf("aio_write failed: %s\n", strerror(-ret)); |
| 781 | 778 | return; |
| 782 | 779 | } |
| 783 | 780 | |
| 784 | - if (ctx->qflag) | |
| 781 | + if (ctx->qflag) { | |
| 785 | 782 | return; |
| 783 | + } | |
| 786 | 784 | |
| 787 | 785 | /* Finally, report back -- -C gives a parsable format */ |
| 788 | 786 | t2 = tsub(t2, ctx->t1); |
| 789 | - print_report("wrote", &t2, ctx->offset, ctx->qiov.size, total, cnt, | |
| 790 | - ctx->Cflag); | |
| 787 | + print_report("wrote", &t2, ctx->offset, ctx->qiov.size, | |
| 788 | + ctx->qiov.size, 1, ctx->Cflag); | |
| 791 | 789 | |
| 792 | 790 | qemu_io_free(ctx->buf); |
| 793 | 791 | free(ctx); |
| ... | ... | @@ -800,44 +798,41 @@ aio_read_done(void *opaque, int ret) |
| 800 | 798 | { |
| 801 | 799 | struct aio_ctx *ctx = opaque; |
| 802 | 800 | struct timeval t2; |
| 803 | - int total; | |
| 804 | - int cnt = 1; | |
| 805 | 801 | |
| 806 | 802 | gettimeofday(&t2, NULL); |
| 807 | 803 | |
| 808 | - total = ctx->qiov.size; | |
| 809 | - | |
| 810 | 804 | if (ret < 0) { |
| 811 | 805 | printf("readv failed: %s\n", strerror(-ret)); |
| 812 | 806 | return; |
| 813 | 807 | } |
| 814 | 808 | |
| 815 | 809 | if (ctx->Pflag) { |
| 816 | - void *cmp_buf = malloc(total); | |
| 810 | + void *cmp_buf = malloc(ctx->qiov.size); | |
| 817 | 811 | |
| 818 | - memset(cmp_buf, ctx->pattern, total); | |
| 819 | - if (memcmp(ctx->buf, cmp_buf, total)) { | |
| 812 | + memset(cmp_buf, ctx->pattern, ctx->qiov.size); | |
| 813 | + if (memcmp(ctx->buf, cmp_buf, ctx->qiov.size)) { | |
| 820 | 814 | printf("Pattern verification failed at offset %lld, " |
| 821 | - "%d bytes\n", | |
| 822 | - (long long) ctx->offset, total); | |
| 815 | + "%zd bytes\n", | |
| 816 | + (long long) ctx->offset, ctx->qiov.size); | |
| 823 | 817 | } |
| 824 | 818 | free(cmp_buf); |
| 825 | 819 | } |
| 826 | 820 | |
| 827 | - if (ctx->qflag) | |
| 821 | + if (ctx->qflag) { | |
| 828 | 822 | return; |
| 823 | + } | |
| 829 | 824 | |
| 830 | - if (ctx->vflag) | |
| 831 | - dump_buffer(ctx->buf, ctx->offset, total); | |
| 825 | + if (ctx->vflag) { | |
| 826 | + dump_buffer(ctx->buf, ctx->offset, ctx->qiov.size); | |
| 827 | + } | |
| 832 | 828 | |
| 833 | 829 | /* Finally, report back -- -C gives a parsable format */ |
| 834 | 830 | t2 = tsub(t2, ctx->t1); |
| 835 | - print_report("read", &t2, ctx->offset, ctx->qiov.size, total, cnt, | |
| 836 | - ctx->Cflag); | |
| 831 | + print_report("read", &t2, ctx->offset, ctx->qiov.size, | |
| 832 | + ctx->qiov.size, 1, ctx->Cflag); | |
| 837 | 833 | |
| 838 | 834 | qemu_io_free(ctx->buf); |
| 839 | 835 | free(ctx); |
| 840 | - | |
| 841 | 836 | } |
| 842 | 837 | |
| 843 | 838 | static void |
| ... | ... | @@ -870,8 +865,6 @@ aio_read_f(int argc, char **argv) |
| 870 | 865 | struct aio_ctx *ctx = calloc(1, sizeof(struct aio_ctx)); |
| 871 | 866 | BlockDriverAIOCB *acb; |
| 872 | 867 | |
| 873 | - ctx->pattern = 0xcd; | |
| 874 | - | |
| 875 | 868 | while ((c = getopt(argc, argv, "CP:qv")) != EOF) { |
| 876 | 869 | switch (c) { |
| 877 | 870 | case 'C': |
| ... | ... | @@ -1035,7 +1028,6 @@ aio_write_f(int argc, char **argv) |
| 1035 | 1028 | return 0; |
| 1036 | 1029 | } |
| 1037 | 1030 | |
| 1038 | - | |
| 1039 | 1031 | for (i = optind; i < argc; i++) { |
| 1040 | 1032 | size_t len; |
| 1041 | 1033 | ... | ... |