Commit 230d4fa48bd64dbc07b509e0eb0bbc885ddf4cc8

Authored by Christoph Hellwig
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,25 +769,23 @@ aio_write_done(void *opaque, int ret)
769 { 769 {
770 struct aio_ctx *ctx = opaque; 770 struct aio_ctx *ctx = opaque;
771 struct timeval t2; 771 struct timeval t2;
772 - int total;  
773 - int cnt = 1;  
774 772
775 gettimeofday(&t2, NULL); 773 gettimeofday(&t2, NULL);
776 774
777 - total = ctx->qiov.size;  
778 775
779 if (ret < 0) { 776 if (ret < 0) {
780 printf("aio_write failed: %s\n", strerror(-ret)); 777 printf("aio_write failed: %s\n", strerror(-ret));
781 return; 778 return;
782 } 779 }
783 780
784 - if (ctx->qflag) 781 + if (ctx->qflag) {
785 return; 782 return;
  783 + }
786 784
787 /* Finally, report back -- -C gives a parsable format */ 785 /* Finally, report back -- -C gives a parsable format */
788 t2 = tsub(t2, ctx->t1); 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 qemu_io_free(ctx->buf); 790 qemu_io_free(ctx->buf);
793 free(ctx); 791 free(ctx);
@@ -800,44 +798,41 @@ aio_read_done(void *opaque, int ret) @@ -800,44 +798,41 @@ aio_read_done(void *opaque, int ret)
800 { 798 {
801 struct aio_ctx *ctx = opaque; 799 struct aio_ctx *ctx = opaque;
802 struct timeval t2; 800 struct timeval t2;
803 - int total;  
804 - int cnt = 1;  
805 801
806 gettimeofday(&t2, NULL); 802 gettimeofday(&t2, NULL);
807 803
808 - total = ctx->qiov.size;  
809 -  
810 if (ret < 0) { 804 if (ret < 0) {
811 printf("readv failed: %s\n", strerror(-ret)); 805 printf("readv failed: %s\n", strerror(-ret));
812 return; 806 return;
813 } 807 }
814 808
815 if (ctx->Pflag) { 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 printf("Pattern verification failed at offset %lld, " 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 free(cmp_buf); 818 free(cmp_buf);
825 } 819 }
826 820
827 - if (ctx->qflag) 821 + if (ctx->qflag) {
828 return; 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 /* Finally, report back -- -C gives a parsable format */ 829 /* Finally, report back -- -C gives a parsable format */
834 t2 = tsub(t2, ctx->t1); 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 qemu_io_free(ctx->buf); 834 qemu_io_free(ctx->buf);
839 free(ctx); 835 free(ctx);
840 -  
841 } 836 }
842 837
843 static void 838 static void
@@ -870,8 +865,6 @@ aio_read_f(int argc, char **argv) @@ -870,8 +865,6 @@ aio_read_f(int argc, char **argv)
870 struct aio_ctx *ctx = calloc(1, sizeof(struct aio_ctx)); 865 struct aio_ctx *ctx = calloc(1, sizeof(struct aio_ctx));
871 BlockDriverAIOCB *acb; 866 BlockDriverAIOCB *acb;
872 867
873 - ctx->pattern = 0xcd;  
874 -  
875 while ((c = getopt(argc, argv, "CP:qv")) != EOF) { 868 while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
876 switch (c) { 869 switch (c) {
877 case 'C': 870 case 'C':
@@ -1035,7 +1028,6 @@ aio_write_f(int argc, char **argv) @@ -1035,7 +1028,6 @@ aio_write_f(int argc, char **argv)
1035 return 0; 1028 return 0;
1036 } 1029 }
1037 1030
1038 -  
1039 for (i = optind; i < argc; i++) { 1031 for (i = optind; i < argc; i++) {
1040 size_t len; 1032 size_t len;
1041 1033