From patchwork Thu May 12 14:35:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9082861 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CCD169F1C3 for ; Thu, 12 May 2016 15:15:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1EE9E201C7 for ; Thu, 12 May 2016 15:15:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 44FEB2010B for ; Thu, 12 May 2016 15:15:13 +0000 (UTC) Received: from localhost ([::1]:58232 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0sKW-00043d-8T for patchwork-qemu-devel@patchwork.kernel.org; Thu, 12 May 2016 11:15:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0rk8-00070k-Fe for qemu-devel@nongnu.org; Thu, 12 May 2016 10:37:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b0rk2-0004Um-DV for qemu-devel@nongnu.org; Thu, 12 May 2016 10:37:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55130) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0rjt-0004Qe-Ix; Thu, 12 May 2016 10:37:21 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E820804E7; Thu, 12 May 2016 14:37:21 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-37.ams2.redhat.com [10.36.116.37]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4CEZp9h028730; Thu, 12 May 2016 10:37:20 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 12 May 2016 16:35:45 +0200 Message-Id: <1463063749-2201-66-git-send-email-kwolf@redhat.com> In-Reply-To: <1463063749-2201-1-git-send-email-kwolf@redhat.com> References: <1463063749-2201-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 12 May 2016 14:37:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 65/69] qemu-io: Add 'write -z -u' to test MAY_UNMAP flag X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Blake 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 Reviewed-by: Max Reitz Message-id: 1462677405-4752-7-git-send-email-eblake@redhat.com Signed-off-by: Max Reitz --- 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 71ae8d0..4a00bc6 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);