From patchwork Sat Apr 9 09:39:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Borzenkov X-Patchwork-Id: 8787851 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 0999E9F3D1 for ; Sat, 9 Apr 2016 09:39:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2D1682021B for ; Sat, 9 Apr 2016 09:39:44 +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 091C22014A for ; Sat, 9 Apr 2016 09:39:43 +0000 (UTC) Received: from localhost ([::1]:59757 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aopMk-0008Tp-Fm for patchwork-qemu-devel@patchwork.kernel.org; Sat, 09 Apr 2016 05:39:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aopMb-0008QK-L0 for qemu-devel@nongnu.org; Sat, 09 Apr 2016 05:39:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aopMY-0005wC-Ao for qemu-devel@nongnu.org; Sat, 09 Apr 2016 05:39:33 -0400 Received: from mail-db5eur01on0105.outbound.protection.outlook.com ([104.47.2.105]:33824 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aopMX-0005w3-Lx for qemu-devel@nongnu.org; Sat, 09 Apr 2016 05:39:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=kTTAzljsT0zVF0FMimJC8FdyYqNydAFeo+d3gG62A2c=; b=JP0oFevLp9JVy3faMkcH9nqsS4LKwf82lAZ17TYI0S5L6OrjInI6i0eyQg9kTKTLciVA6YeitBlmZzIWYCYktFFCBuVGTWZKGalyMHbq+lBFrO2LYg3w1gyZoRdnC85AxG1gvpVKZMFsxLwKZc3ovq6lYq0hQiC7YFsOkiaJ6H0= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=virtuozzo.com; Received: from localhost (195.214.232.10) by HE1PR08MB0921.eurprd08.prod.outlook.com (10.166.125.9) with Microsoft SMTP Server (TLS) id 15.1.453.26; Sat, 9 Apr 2016 09:39:26 +0000 Date: Sat, 9 Apr 2016 12:39:21 +0300 From: Pavel Borzenkov To: Eric Blake Message-ID: <20160409093921.GB21526@phobos> References: <1460153158-21612-1-git-send-email-eblake@redhat.com> <1460153158-21612-18-git-send-email-eblake@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1460153158-21612-18-git-send-email-eblake@redhat.com> User-Agent: Mutt/1.6.0 (2016-04-01) X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AMSPR04CA0041.eurprd04.prod.outlook.com (10.242.87.159) To HE1PR08MB0921.eurprd08.prod.outlook.com (10.166.125.9) X-MS-Office365-Filtering-Correlation-Id: 5fe56d7a-c7b6-4c72-6458-08d3605ad7b2 X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB0921; 2:DdHdRWIWIZw7TDYBlZ33fL12qq/gV5FjuUKWwLGlH0Hdoj02DL11Kk+QwlpAUySUdIXpJNgtyYOQQJ4dJabYN4M7FIpyOrgunl5DB6o6GUmAu8dBIFRrdCx8ZqYIwtdVXgbqwPxgMlggBii+jXSv/oCMsPJw8P7pRylTDLG5JIkTtyF+wV+wNJSP1nPCxVXB; 3:lumBhXt1bLQuTz6o8N3O3nYWiYDgwC7fPuquHEngFerJ0UYnovXxM21ZLmwyh/u3MbPBFeBVtL6CWZz9gzPfH/g6DoB8F6cTODBLmWZX8Md6eQlS4++huvz6dSFkuZ6k X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HE1PR08MB0921; X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB0921; 25:HODWmFydQPP+VuHQmNGSXQiY8AOV9uusQKz0RQX4opmYrUwQ6Vgr+xe5Wpn8IPFTnDJoVy5Ss0fYmg7fufWZByVrGW7bgmDlzIZBiJFxU9aChBn3v5P7uXPC/WKNl6cZ/jRlAMcbQgotsugHndyF4wf0vkzxLCrrbpXzLIi3furnkiiaPYNPOD32/kJvQ3E1iQhsQq8yYgB+Dt1JP3zuE43q/fA9Wh0v4VRZ5LCpASP28lhlnxgEFiJIc7IeIxEp4orSt+yTFsMbtoRpkORV0waReWma+e1cIkjOQEoqE0BC++H1XNVPczTBnf1CY7PAy9bHKuKQU+OsOPnZj7OydPUCXC48KNEvDLrb7iQNWI3TFkbR08/0YkElNArHh6fAXq2YnTLOcxkGOtse5bDfBR298T9cd4B8AF6m+fqPTQ5io3kSwFGWzaR2wK2zfmkou/B0XwAKoCqTVEsNJttUZERXq8yPBtNztNGTxJ1HVW/kP0dxwyCBAtoWGBHhkfzP+ym9rVmxJ3jMeK96WghhQuc4XRHRoFNVr2gClQsJ+wRIXktJk4XSz08BHIyrFtNOBo38O4TieaCbmCtKJ/1pA3HrgRUkke2epcE5Skd2j0O/hxbQuP6+Avoi21QjxjrqSjGpaQuBNkHK6O81Bksh90e0xr5QffQ6LGSCvCbao18= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040074)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041046)(6043046); SRVR:HE1PR08MB0921; BCL:0; PCL:0; RULEID:; SRVR:HE1PR08MB0921; X-Microsoft-Exchange-Diagnostics: 1; HE1PR08MB0921; 4:OR75iEP41+hZIBDx7AZawTFmUbvd89d9UC0Vh1JJy4F1drTm7crhJrgcuBK3KdP7dCFScKvosk5QDZX/ulVH8tmPFzbM/g5gW+W8bg493rL1pDUleO+1zL1gd+jR3sK6+o/W7EubGrJXedGbtQwkxMei53A6vlXsSNXu0lUyuukykESehEo/2P5yuKwhuKwTx7M6vzldnyaFg0Kfpj4S4JtX2fVvkSuKc4L2QhYYo+OW19PHSDTli61akjnrp6pFU9Z0CXlva0IA1dgP9TY1p2Fo/lSntsH0sxqtlN21LObHLEtF7tfQXtbQ9vvT+NVbXI1V+qSI3im/YV+Cl06ZRoEzCA5dMLB7txFbcAQzn26AosMVlQ10Rftfh4y95JijAYl1nLl8dq3rGvIMNmx4vSvHsyStptc9eDlj7hU1q/k= X-Forefront-PRVS: 0907F58A24 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6069001)(6009001)(24454002)(81166005)(47776003)(92566002)(2950100001)(77096005)(2906002)(83506001)(586003)(110136002)(46406003)(19580405001)(5008740100001)(9686002)(23726003)(19580395003)(189998001)(4001350100001)(33716001)(1096002)(42186005)(6116002)(1076002)(76506005)(97756001)(50466002)(3846002)(50986999)(54356999)(33656002)(66066001)(4326007)(5004730100002)(86362001)(76176999)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR08MB0921; H:localhost; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR08MB0921; 23:lxUrUFSM3KOBYMqyC/dRTaLFjaSglcN+2JRUr5QhU?= =?us-ascii?Q?K74FM7hEPxoPVVBu72Pzd1mzrPhs1zx6pFk7KZA6+yfTSGLoTvxrLZPTTCC8?= =?us-ascii?Q?xGdSRaNq+0NyISLabtbUGTvZgXDejEpkfOhZv2cwiXnE60wZGtdUGz4gTmHI?= =?us-ascii?Q?P2/0mBRvsDF+nJCFrV3qbbactQksX8L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Diagnostics: 1; HE1PR08MB0921; 5:o5XRImZBTPHYEAewoexo8TnI9vC12oguYN6Y/8k859YPER9qhBepr//+BikBPhtYf0iiGGt40VyUe9ylQ71ocmYDyqzXVeMdmTgiyrqYBDduQnF0+KLKqC3SLJH3vO90ehEVQMPSTV+jQrVttyRBXg==; 24:RQDsUp+CMxnOqZUJjQjgcf895B4e+bhpsUrpnJQ+fPslNFsi1Hpf1VW5TZsPC6MHvWs6FJ7HeGKvFaYNnr4OjCQYH+qW5Nv5iy+dxFl9S9Y=; 20:L047zbhfc5mbKm4v85t695LtP3WzcLmIbq8SXaqUtJ3VY8zP0lnPPq/q1BL1bS5ZeS6eJ9jkH/AMp13XFWYdc6psyHAT6Znt86PshVWcFUIi5vPHIG7Azqbmmo/Un7m2u2nRt9FOtxn3a8THlBVepDNtvElhRgwswLT278qZ/6k= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Apr 2016 09:39:26.9925 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR08MB0921 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.105 Subject: Re: [Qemu-devel] [RFC PATCH 17/18] nbd: Implement NBD_CMD_WRITE_ZEROES on server 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: Kevin Wolf , Paolo Bonzini , alex@alex.org.uk, qemu-devel@nongnu.org, "open list:Block layer core" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-7.0 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 On Fri, Apr 08, 2016 at 04:05:57PM -0600, Eric Blake wrote: > RFC because there is still discussion on the NBD list about > adding an NBD_OPT_ to let the client suggest server defaults > related to scanning for zeroes during NBD_CMD_WRITE, which may > tweak this patch. > > Upstream NBD protocol recently added the ability to efficiently > write zeroes without having to send the zeroes over the wire, > along with a flag to control whether the client wants a hole. > > Signed-off-by: Eric Blake > --- > include/block/nbd.h | 5 ++++- > nbd/server.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++--- > 2 files changed, 64 insertions(+), 4 deletions(-) > > diff --git a/include/block/nbd.h b/include/block/nbd.h > index 4c57754..a1d955c 100644 > --- a/include/block/nbd.h > +++ b/include/block/nbd.h > @@ -70,6 +70,7 @@ typedef struct nbd_reply nbd_reply; > #define NBD_FLAG_SEND_FUA (1 << 3) /* Send FUA (Force Unit Access) */ > #define NBD_FLAG_ROTATIONAL (1 << 4) /* Use elevator algorithm - rotational media */ > #define NBD_FLAG_SEND_TRIM (1 << 5) /* Send TRIM (discard) */ > +#define NBD_FLAG_SEND_WRITE_ZEROES (1 << 6) /* Send WRITE_ZEROES */ > #define NBD_FLAG_SEND_CLOSE (1 << 8) /* Send CLOSE */ > > /* New-style handshake (global) flags, sent from server to client, and > @@ -92,7 +93,8 @@ typedef struct nbd_reply nbd_reply; > #define NBD_REP_ERR_UNKNOWN ((UINT32_C(1) << 31) | 6) /* Export unknown */ > > /* Request flags, sent from client to server during transmission phase */ > -#define NBD_CMD_FLAG_FUA (1 << 0) > +#define NBD_CMD_FLAG_FUA (1 << 0) /* 'force unit access' during write */ > +#define NBD_CMD_FLAG_NO_HOLE (1 << 1) /* don't punch hole on zero run */ > > /* Supported request types */ > enum { > @@ -101,6 +103,7 @@ enum { > NBD_CMD_DISC = 2, > NBD_CMD_FLUSH = 3, > NBD_CMD_TRIM = 4, > + NBD_CMD_WRITE_ZEROES = 5, > NBD_CMD_CLOSE = 7, > }; > > diff --git a/nbd/server.c b/nbd/server.c > index 2a6eaf2..09af915 100644 > --- a/nbd/server.c > +++ b/nbd/server.c > @@ -625,7 +625,8 @@ static coroutine_fn int nbd_negotiate(NBDClientNewData *data) > int rc; > const uint16_t myflags = (NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_TRIM | > NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA | > - NBD_FLAG_SEND_CLOSE); > + NBD_FLAG_SEND_CLOSE | > + NBD_FLAG_SEND_WRITE_ZEROES); > bool oldStyle; > size_t len; > > @@ -1088,7 +1089,7 @@ static ssize_t nbd_co_receive_request(NBDRequest *req, struct nbd_request *reque > goto out; > } > > - if (request->flags & ~NBD_CMD_FLAG_FUA) { > + if (request->flags & ~(NBD_CMD_FLAG_FUA | NBD_CMD_FLAG_NO_HOLE)) { > LOG("unsupported flags (got 0x%x)", request->flags); > return -EINVAL; > } > @@ -1102,7 +1103,13 @@ static ssize_t nbd_co_receive_request(NBDRequest *req, struct nbd_request *reque > TRACE("Decoding type"); > > command = request->type; > - if (command == NBD_CMD_READ || command == NBD_CMD_WRITE) { > + if (request->flags & NBD_CMD_FLAG_NO_HOLE && > + !(command == NBD_CMD_WRITE || command == NBD_CMD_WRITE_ZEROES)) { > + LOG("NO_HOLE flag valid only with write operation"); > + return -EINVAL; > + } > + if (command == NBD_CMD_READ || command == NBD_CMD_WRITE || > + command == NBD_CMD_WRITE_ZEROES) { > if (request->len > NBD_MAX_BUFFER_SIZE) { > LOG("len (%" PRIu32" ) is larger than max len (%u)", > request->len, NBD_MAX_BUFFER_SIZE); > @@ -1143,6 +1150,7 @@ static void nbd_trip(void *opaque) > struct nbd_reply reply; > ssize_t ret; > uint32_t command; > + int flags; > > TRACE("Reading request."); > if (client->closing) { > @@ -1221,6 +1229,9 @@ static void nbd_trip(void *opaque) > > TRACE("Writing to device"); > > + /* FIXME: if the client passes NBD_CMD_FLAG_NO_HOLE, can we > + * make that override a server that is set to look for > + * holes? */ > ret = blk_write(exp->blk, > (request.from + exp->dev_offset) / BDRV_SECTOR_SIZE, > req->data, request.len / BDRV_SECTOR_SIZE); > @@ -1243,6 +1254,52 @@ static void nbd_trip(void *opaque) > goto out; > } > break; > + case NBD_CMD_WRITE_ZEROES: > + TRACE("Request type is WRITE_ZEROES"); > + > + if (exp->nbdflags & NBD_FLAG_READ_ONLY) { > + TRACE("Server is read-only, return error"); > + reply.error = EROFS; > + goto error_reply; > + } > + > + TRACE("Writing to device"); > + > + flags = 0; > + if (request.flags & NBD_CMD_FLAG_FUA) { > + flags |= BDRV_REQ_FUA; > + } > + if (!(request.flags & NBD_CMD_FLAG_NO_HOLE)) { > + /* FIXME: should this depend on whether the server is set to > + look for holes? */ > + flags |= BDRV_REQ_MAY_UNMAP; > + } > + ret = blk_write_zeroes(exp->blk, > + ((request.from + exp->dev_offset) / > + BDRV_SECTOR_SIZE), > + request.len / BDRV_SECTOR_SIZE, > + flags); blk_write_zeroes() ignores flags right now. Something like this is required for this code to work: > + if (ret < 0) { > + LOG("writing to file failed"); > + reply.error = -ret; > + goto error_reply; > + } > + > + /* FIXME: do we need FUA flush here, if we also passed it to > + * blk_write_zeroes? */ > + if (request.flags & NBD_CMD_FLAG_FUA) { > + ret = blk_co_flush(exp->blk); > + if (ret < 0) { > + LOG("flush failed"); > + reply.error = -ret; > + goto error_reply; > + } > + } > + > + if (nbd_co_send_reply(req, &reply, 0) < 0) { > + goto out; > + } > + break; > case NBD_CMD_DISC: > TRACE("Request type is DISCONNECT"); > goto out; > -- > 2.5.5 > > diff --git a/block/block-backend.c b/block/block-backend.c index f0470bc..3ae4157 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -827,7 +827,7 @@ int blk_write_zeroes(BlockBackend *blk, int64_t sector_num, int nb_sectors, BdrvRequestFlags flags) { return blk_rw(blk, sector_num, NULL, nb_sectors, blk_write_entry, - BDRV_REQ_ZERO_WRITE); + BDRV_REQ_ZERO_WRITE | flags); } static void error_callback_bh(void *opaque)