From patchwork Fri Feb 22 21:23:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 222664 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2912F2C02A6 for ; Sat, 23 Feb 2013 08:58:03 +1100 (EST) Received: from localhost ([::1]:44023 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U908J-0005K4-Cv for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2013 16:26:19 -0500 Received: from eggs.gnu.org ([208.118.235.92]:35975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U906f-0002zq-Sl for qemu-devel@nongnu.org; Fri, 22 Feb 2013 16:24:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U906Z-0003rC-HM for qemu-devel@nongnu.org; Fri, 22 Feb 2013 16:24:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:62847) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U906Z-0003r0-7s for qemu-devel@nongnu.org; Fri, 22 Feb 2013 16:24:31 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1MLOTZN022827 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 22 Feb 2013 16:24:30 -0500 Received: from dhcp-200-207.str.redhat.com (ovpn-116-66.ams2.redhat.com [10.36.116.66]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1MLNuFj010868; Fri, 22 Feb 2013 16:24:28 -0500 From: Kevin Wolf To: anthony@codemonkey.ws Date: Fri, 22 Feb 2013 22:23:49 +0100 Message-Id: <1361568231-18198-21-git-send-email-kwolf@redhat.com> In-Reply-To: <1361568231-18198-1-git-send-email-kwolf@redhat.com> References: <1361568231-18198-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 20/22] qemu-nbd: add --discard option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Paolo Bonzini Similar to --cache and --aio, this option mimics the discard suboption of "-drive". Signed-off-by: Paolo Bonzini Signed-off-by: Kevin Wolf --- qemu-nbd.c | 18 +++++++++++++++--- qemu-nbd.texi | 4 ++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 0a6091b..e7268d0 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -33,9 +33,10 @@ #include #include -#define SOCKET_PATH "/var/lock/qemu-nbd-%s" -#define QEMU_NBD_OPT_CACHE 1 -#define QEMU_NBD_OPT_AIO 2 +#define SOCKET_PATH "/var/lock/qemu-nbd-%s" +#define QEMU_NBD_OPT_CACHE 1 +#define QEMU_NBD_OPT_AIO 2 +#define QEMU_NBD_OPT_DISCARD 3 static NBDExport *exp; static int verbose; @@ -330,6 +331,7 @@ int main(int argc, char **argv) #ifdef CONFIG_LINUX_AIO { "aio", 1, NULL, QEMU_NBD_OPT_AIO }, #endif + { "discard", 1, NULL, QEMU_NBD_OPT_DISCARD }, { "shared", 1, NULL, 'e' }, { "persistent", 0, NULL, 't' }, { "verbose", 0, NULL, 'v' }, @@ -344,6 +346,7 @@ int main(int argc, char **argv) int ret; int fd; bool seen_cache = false; + bool seen_discard = false; #ifdef CONFIG_LINUX_AIO bool seen_aio = false; #endif @@ -389,6 +392,15 @@ int main(int argc, char **argv) } break; #endif + case QEMU_NBD_OPT_DISCARD: + if (seen_discard) { + errx(EXIT_FAILURE, "--discard can only be specified once"); + } + seen_discard = true; + if (bdrv_parse_discard_flags(optarg, &flags) == -1) { + errx(EXIT_FAILURE, "Invalid discard mode `%s'", optarg); + } + break; case 'b': bindto = optarg; break; diff --git a/qemu-nbd.texi b/qemu-nbd.texi index 3e57200..5f3f3e3 100644 --- a/qemu-nbd.texi +++ b/qemu-nbd.texi @@ -35,6 +35,10 @@ Export QEMU disk image using NBD protocol. @item --aio=@var{aio} choose asynchronous I/O mode between @samp{threads} (the default) and @samp{native} (Linux only). +@item --discard=@var{discard} + toggles whether @dfn{discard} (also known as @dfn{trim} or @dfn{unmap}) + requests are ignored or passed to the filesystem. The default is no + (@samp{--discard=ignore}). @item -c, --connect=@var{dev} connect @var{filename} to NBD device @var{dev} @item -d, --disconnect