diff mbox

[for-2.6,1/2] qemu-io: Support 'aio_write -z'

Message ID 1460545601-29196-2-git-send-email-kwolf@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Kevin Wolf April 13, 2016, 11:06 a.m. UTC
This allows testing blk_aio_write_zeroes().

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 qemu-io-cmds.c | 64 +++++++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 48 insertions(+), 16 deletions(-)

Comments

Max Reitz April 14, 2016, 11:14 p.m. UTC | #1
On 13.04.2016 13:06, Kevin Wolf wrote:
> This allows testing blk_aio_write_zeroes().
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  qemu-io-cmds.c | 64 +++++++++++++++++++++++++++++++++++++++++++---------------
>  1 file changed, 48 insertions(+), 16 deletions(-)

Despite the continuing use of int instead of bool where the latter would
be appropriate and of "9" instead of "BDRV_SECTOR_BITS":

Reviewed-by: Max Reitz <mreitz@redhat.com>
Max Reitz April 14, 2016, 11:24 p.m. UTC | #2
On 13.04.2016 13:06, Kevin Wolf wrote:
> This allows testing blk_aio_write_zeroes().
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  qemu-io-cmds.c | 64 +++++++++++++++++++++++++++++++++++++++++++---------------
>  1 file changed, 48 insertions(+), 16 deletions(-)
> 
> diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
> index 382faa8..51ae5a5 100644
> --- a/qemu-io-cmds.c
> +++ b/qemu-io-cmds.c

[...]

> +        ctx->buf = create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov, pattern);

I just noticed this line has over 80 characters. R-b stands provided
this is fixed.

Max
Kevin Wolf April 15, 2016, 8:18 a.m. UTC | #3
Am 15.04.2016 um 01:14 hat Max Reitz geschrieben:
> On 13.04.2016 13:06, Kevin Wolf wrote:
> > This allows testing blk_aio_write_zeroes().
> > 
> > Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> > ---
> >  qemu-io-cmds.c | 64 +++++++++++++++++++++++++++++++++++++++++++---------------
> >  1 file changed, 48 insertions(+), 16 deletions(-)
> 
> Despite the continuing use of int instead of bool where the latter would
> be appropriate and of "9" instead of "BDRV_SECTOR_BITS":

I considered whether to use bool, but having a few ints and then a bool
for flags in the same struct would be inconsistent. We can have a
cleanup patch on top that changes all instances.

Same thing really with the explicit 9. I didn't even notice it, but this
is just copied code and changing it in one instance only would be
inconsistent.

Kevin
diff mbox

Patch

diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 382faa8..51ae5a5 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -1416,6 +1416,7 @@  struct aio_ctx {
     int vflag;
     int Cflag;
     int Pflag;
+    int zflag;
     BlockAcctCookie acct;
     int pattern;
     struct timeval t1;
@@ -1446,8 +1447,10 @@  static void aio_write_done(void *opaque, int ret)
     print_report("wrote", &t2, ctx->offset, ctx->qiov.size,
                  ctx->qiov.size, 1, ctx->Cflag);
 out:
-    qemu_io_free(ctx->buf);
-    qemu_iovec_destroy(&ctx->qiov);
+    if (!ctx->zflag) {
+        qemu_io_free(ctx->buf);
+        qemu_iovec_destroy(&ctx->qiov);
+    }
     g_free(ctx);
 }
 
@@ -1612,6 +1615,7 @@  static void aio_write_help(void)
 " -P, -- use different pattern to fill file\n"
 " -C, -- report statistics in a machine parsable format\n"
 " -q, -- quiet mode, do not show I/O statistics\n"
+" -z, -- write zeroes using blk_aio_write_zeroes\n"
 "\n");
 }
 
@@ -1622,7 +1626,7 @@  static const cmdinfo_t aio_write_cmd = {
     .cfunc      = aio_write_f,
     .argmin     = 2,
     .argmax     = -1,
-    .args       = "[-Cq] [-P pattern ] off len [len..]",
+    .args       = "[-Cqz] [-P pattern ] off len [len..]",
     .oneline    = "asynchronously writes a number of bytes",
     .help       = aio_write_help,
 };
@@ -1634,7 +1638,7 @@  static int aio_write_f(BlockBackend *blk, int argc, char **argv)
     struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
 
     ctx->blk = blk;
-    while ((c = getopt(argc, argv, "CqP:")) != -1) {
+    while ((c = getopt(argc, argv, "CqP:z")) != -1) {
         switch (c) {
         case 'C':
             ctx->Cflag = 1;
@@ -1649,6 +1653,9 @@  static int aio_write_f(BlockBackend *blk, int argc, char **argv)
                 return 0;
             }
             break;
+        case 'z':
+            ctx->zflag = 1;
+            break;
         default:
             g_free(ctx);
             return qemuio_command_usage(&aio_write_cmd);
@@ -1660,6 +1667,18 @@  static int aio_write_f(BlockBackend *blk, int argc, char **argv)
         return qemuio_command_usage(&aio_write_cmd);
     }
 
+    if (ctx->zflag && optind != argc - 2) {
+        printf("-z supports only a single length parameter\n");
+        g_free(ctx);
+        return 0;
+    }
+
+    if (ctx->zflag && ctx->Pflag) {
+        printf("-z and -P cannot be specified at the same time\n");
+        g_free(ctx);
+        return 0;
+    }
+
     ctx->offset = cvtnum(argv[optind]);
     if (ctx->offset < 0) {
         print_cvtnum_err(ctx->offset, argv[optind]);
@@ -1676,19 +1695,32 @@  static int aio_write_f(BlockBackend *blk, int argc, char **argv)
         return 0;
     }
 
-    nr_iov = argc - optind;
-    ctx->buf = create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov, pattern);
-    if (ctx->buf == NULL) {
-        block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE);
-        g_free(ctx);
-        return 0;
-    }
+    if (ctx->zflag) {
+        int64_t count = cvtnum(argv[optind]);
+        if (count < 0) {
+            print_cvtnum_err(count, argv[optind]);
+            return 0;
+        }
 
-    gettimeofday(&ctx->t1, NULL);
-    block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size,
-                     BLOCK_ACCT_WRITE);
-    blk_aio_writev(blk, ctx->offset >> 9, &ctx->qiov,
-                   ctx->qiov.size >> 9, aio_write_done, ctx);
+        ctx->qiov.size = count;
+        blk_aio_write_zeroes(blk, ctx->offset >> 9, count >> 9, 0,
+                             aio_write_done, ctx);
+    } else {
+        nr_iov = argc - optind;
+        ctx->buf = create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov, pattern);
+        if (ctx->buf == NULL) {
+            block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE);
+            g_free(ctx);
+            return 0;
+        }
+
+        gettimeofday(&ctx->t1, NULL);
+        block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size,
+                         BLOCK_ACCT_WRITE);
+
+        blk_aio_writev(blk, ctx->offset >> 9, &ctx->qiov,
+                       ctx->qiov.size >> 9, aio_write_done, ctx);
+    }
     return 0;
 }