mirror of https://gitee.com/openkylin/qemu.git
qemu-io: small cleanups for the aio code
Address a couple of review comments from Kevin. Signed-off-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
parent
52249f0f3c
commit
230d4fa48b
40
qemu-io.c
40
qemu-io.c
|
@ -769,25 +769,23 @@ aio_write_done(void *opaque, int ret)
|
||||||
{
|
{
|
||||||
struct aio_ctx *ctx = opaque;
|
struct aio_ctx *ctx = opaque;
|
||||||
struct timeval t2;
|
struct timeval t2;
|
||||||
int total;
|
|
||||||
int cnt = 1;
|
|
||||||
|
|
||||||
gettimeofday(&t2, NULL);
|
gettimeofday(&t2, NULL);
|
||||||
|
|
||||||
total = ctx->qiov.size;
|
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
printf("aio_write failed: %s\n", strerror(-ret));
|
printf("aio_write failed: %s\n", strerror(-ret));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->qflag)
|
if (ctx->qflag) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Finally, report back -- -C gives a parsable format */
|
/* Finally, report back -- -C gives a parsable format */
|
||||||
t2 = tsub(t2, ctx->t1);
|
t2 = tsub(t2, ctx->t1);
|
||||||
print_report("wrote", &t2, ctx->offset, ctx->qiov.size, total, cnt,
|
print_report("wrote", &t2, ctx->offset, ctx->qiov.size,
|
||||||
ctx->Cflag);
|
ctx->qiov.size, 1, ctx->Cflag);
|
||||||
|
|
||||||
qemu_io_free(ctx->buf);
|
qemu_io_free(ctx->buf);
|
||||||
free(ctx);
|
free(ctx);
|
||||||
|
@ -800,44 +798,41 @@ aio_read_done(void *opaque, int ret)
|
||||||
{
|
{
|
||||||
struct aio_ctx *ctx = opaque;
|
struct aio_ctx *ctx = opaque;
|
||||||
struct timeval t2;
|
struct timeval t2;
|
||||||
int total;
|
|
||||||
int cnt = 1;
|
|
||||||
|
|
||||||
gettimeofday(&t2, NULL);
|
gettimeofday(&t2, NULL);
|
||||||
|
|
||||||
total = ctx->qiov.size;
|
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
printf("readv failed: %s\n", strerror(-ret));
|
printf("readv failed: %s\n", strerror(-ret));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->Pflag) {
|
if (ctx->Pflag) {
|
||||||
void *cmp_buf = malloc(total);
|
void *cmp_buf = malloc(ctx->qiov.size);
|
||||||
|
|
||||||
memset(cmp_buf, ctx->pattern, total);
|
memset(cmp_buf, ctx->pattern, ctx->qiov.size);
|
||||||
if (memcmp(ctx->buf, cmp_buf, total)) {
|
if (memcmp(ctx->buf, cmp_buf, ctx->qiov.size)) {
|
||||||
printf("Pattern verification failed at offset %lld, "
|
printf("Pattern verification failed at offset %lld, "
|
||||||
"%d bytes\n",
|
"%zd bytes\n",
|
||||||
(long long) ctx->offset, total);
|
(long long) ctx->offset, ctx->qiov.size);
|
||||||
}
|
}
|
||||||
free(cmp_buf);
|
free(cmp_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->qflag)
|
if (ctx->qflag) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (ctx->vflag)
|
if (ctx->vflag) {
|
||||||
dump_buffer(ctx->buf, ctx->offset, total);
|
dump_buffer(ctx->buf, ctx->offset, ctx->qiov.size);
|
||||||
|
}
|
||||||
|
|
||||||
/* Finally, report back -- -C gives a parsable format */
|
/* Finally, report back -- -C gives a parsable format */
|
||||||
t2 = tsub(t2, ctx->t1);
|
t2 = tsub(t2, ctx->t1);
|
||||||
print_report("read", &t2, ctx->offset, ctx->qiov.size, total, cnt,
|
print_report("read", &t2, ctx->offset, ctx->qiov.size,
|
||||||
ctx->Cflag);
|
ctx->qiov.size, 1, ctx->Cflag);
|
||||||
|
|
||||||
qemu_io_free(ctx->buf);
|
qemu_io_free(ctx->buf);
|
||||||
free(ctx);
|
free(ctx);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -870,8 +865,6 @@ aio_read_f(int argc, char **argv)
|
||||||
struct aio_ctx *ctx = calloc(1, sizeof(struct aio_ctx));
|
struct aio_ctx *ctx = calloc(1, sizeof(struct aio_ctx));
|
||||||
BlockDriverAIOCB *acb;
|
BlockDriverAIOCB *acb;
|
||||||
|
|
||||||
ctx->pattern = 0xcd;
|
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
|
while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'C':
|
case 'C':
|
||||||
|
@ -1035,7 +1028,6 @@ aio_write_f(int argc, char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (i = optind; i < argc; i++) {
|
for (i = optind; i < argc; i++) {
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue