qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, kwolf@nongnu.org, mreitz@redhat.com,
	Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [PATCH v5 6/6] qemu-io: Add 'write -z -u' to test MAY_UNMAP flag
Date: Sat,  7 May 2016 21:16:45 -0600	[thread overview]
Message-ID: <1462677405-4752-7-git-send-email-eblake@redhat.com> (raw)
In-Reply-To: <1462677405-4752-1-git-send-email-eblake@redhat.com>

Make it easier to control whether the BDRV_REQ_MAY_UNMAP flag
can be passed through a write_zeroes command, by adding the '-u'
flag to qemu-io 'write -z' and 'aio_write -z'.  To be useful,
the device has to be opened with BDRV_O_UNMAP (done by default
in qemu-io, but can be made explicit with '-d unmap').

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>

---
v5: tweak commit message for rebase conflict resolution
---
 qemu-io-cmds.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 17f408d..83de5f9 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -943,6 +943,7 @@ static void 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"
+" -u, -- with -z, allow unmapping\n"
 " -z, -- write zeroes using blk_co_write_zeroes\n"
 "\n");
 }
@@ -955,7 +956,7 @@ static const cmdinfo_t write_cmd = {
     .cfunc      = write_f,
     .argmin     = 2,
     .argmax     = -1,
-    .args       = "[-bcCfqz] [-P pattern] off len",
+    .args       = "[-bcCfquz] [-P pattern] off len",
     .oneline    = "writes a number of bytes at a specified offset",
     .help       = write_help,
 };
@@ -974,7 +975,7 @@ static int write_f(BlockBackend *blk, int argc, char **argv)
     int64_t total = 0;
     int pattern = 0xcd;

-    while ((c = getopt(argc, argv, "bcCfpP:qz")) != -1) {
+    while ((c = getopt(argc, argv, "bcCfpP:quz")) != -1) {
         switch (c) {
         case 'b':
             bflag = true;
@@ -1001,6 +1002,9 @@ static int write_f(BlockBackend *blk, int argc, char **argv)
         case 'q':
             qflag = true;
             break;
+        case 'u':
+            flags |= BDRV_REQ_MAY_UNMAP;
+            break;
         case 'z':
             zflag = true;
             break;
@@ -1023,6 +1027,11 @@ static int write_f(BlockBackend *blk, int argc, char **argv)
         return 0;
     }

+    if ((flags & BDRV_REQ_MAY_UNMAP) && !zflag) {
+        printf("-u requires -z to be specified\n");
+        return 0;
+    }
+
     if (zflag && Pflag) {
         printf("-z and -P cannot be specified at the same time\n");
         return 0;
@@ -1561,6 +1570,7 @@ static void aio_write_help(void)
 " -C, -- report statistics in a machine parsable format\n"
 " -f, -- use Force Unit Access semantics\n"
 " -q, -- quiet mode, do not show I/O statistics\n"
+" -u, -- with -z, allow unmapping\n"
 " -z, -- write zeroes using blk_aio_write_zeroes\n"
 "\n");
 }
@@ -1572,7 +1582,7 @@ static const cmdinfo_t aio_write_cmd = {
     .cfunc      = aio_write_f,
     .argmin     = 2,
     .argmax     = -1,
-    .args       = "[-Cfqz] [-P pattern] off len [len..]",
+    .args       = "[-Cfquz] [-P pattern] off len [len..]",
     .oneline    = "asynchronously writes a number of bytes",
     .help       = aio_write_help,
 };
@@ -1596,6 +1606,9 @@ static int aio_write_f(BlockBackend *blk, int argc, char **argv)
         case 'q':
             ctx->qflag = true;
             break;
+        case 'u':
+            flags |= BDRV_REQ_MAY_UNMAP;
+            break;
         case 'P':
             pattern = parse_pattern(optarg);
             if (pattern < 0) {
@@ -1623,6 +1636,11 @@ static int aio_write_f(BlockBackend *blk, int argc, char **argv)
         return 0;
     }

+    if ((flags & BDRV_REQ_MAY_UNMAP) && !ctx->zflag) {
+        printf("-u requires -z to be specified\n");
+        return 0;
+    }
+
     if (ctx->zflag && ctx->Pflag) {
         printf("-z and -P cannot be specified at the same time\n");
         g_free(ctx);
-- 
2.5.5

  parent reply	other threads:[~2016-05-08  3:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-08  3:16 [Qemu-devel] [PATCH v5 0/6] qemu-io: UI enhancements Eric Blake
2016-05-08  3:16 ` [Qemu-devel] [PATCH v5 1/6] qemu-io: Add missing option documentation Eric Blake
2016-05-09 17:43   ` Max Reitz
2016-05-08  3:16 ` [Qemu-devel] [PATCH v5 2/6] qemu-io: Make 'open' subcommand more like command line Eric Blake
2016-05-09 18:10   ` Max Reitz
2016-05-08  3:16 ` [Qemu-devel] [PATCH v5 3/6] qemu-io: Use bool for command line flags Eric Blake
2016-05-08  3:16 ` [Qemu-devel] [PATCH v5 4/6] qemu-io: Allow unaligned access by default Eric Blake
2016-05-09 18:14   ` Max Reitz
2016-05-12 14:38   ` Kevin Wolf
2016-05-12 15:50     ` Eric Blake
2016-05-12 21:52       ` Eric Blake
2016-05-08  3:16 ` [Qemu-devel] [PATCH v5 5/6] qemu-io: Add 'write -f' to test FUA flag Eric Blake
2016-05-09 18:21   ` Max Reitz
2016-05-08  3:16 ` Eric Blake [this message]
2016-05-08  3:35 ` [Qemu-devel] [PATCH v5 0/6] qemu-io: UI enhancements Eric Blake
2016-05-09 18:23   ` Max Reitz
2016-05-10  8:35     ` Kevin Wolf
2016-05-11 13:47 ` Max Reitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1462677405-4752-7-git-send-email-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=kwolf@nongnu.org \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).