From nobody Sun Oct 5 17:38:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152046360779118.81947331824597; Wed, 7 Mar 2018 15:00:07 -0800 (PST) Received: from localhost ([::1]:35948 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eti2Z-0002A2-0Z for importer@patchew.org; Wed, 07 Mar 2018 18:00:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eti1K-0001Ry-JR for qemu-devel@nongnu.org; Wed, 07 Mar 2018 17:58:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eti1J-0000oO-NA for qemu-devel@nongnu.org; Wed, 07 Mar 2018 17:58:50 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39842 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eti1E-0000la-PH; Wed, 07 Mar 2018 17:58:44 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0836E87ABA; Wed, 7 Mar 2018 22:58:34 +0000 (UTC) Received: from red.redhat.com (ovpn-125-187.rdu2.redhat.com [10.10.125.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id 801DF7C41; Wed, 7 Mar 2018 22:58:27 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 7 Mar 2018 16:57:32 -0600 Message-Id: <20180307225732.155835-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 07 Mar 2018 22:58:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 07 Mar 2018 22:58:34 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH] nbd/server: Honor FUA request on NBD_CMD_TRIM 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, pbonzini@redhat.com, vsementsov@virtuozzo.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The NBD spec states that since trim requests can affect disk contents, then they should allow for FUA semantics just like writes for ensuring the disk has settled before returning. As bdrv_[co_]pdiscard() does not (yet?) support a flags argument, we can't pass FUA down the block layer stack, and must therefore emulate it with a flush at the NBD layer. Signed-off-by: Eric Blake --- Question for Paolo: does ISCSI support the notion of FUA on a TRIM request (where we could better emulate a guest TRIM request with FUA all the way through our stack to the NBD server), or is FUA just for normal writes? Likewise, are you familiar enough with the kernel's NBD module to know if the kernel as an NBD client would ever request FUA on a discard request? Question for Kevin: should we update the block layer to have a flag arguments to bdrv_co_pdiscard (right now, the only valid flag would be BDRV_REQ_FUA, and we'd probably need a supported_discard_flags in parallel to supported_write_flags), and implement qemu-io -c 'discard -f' for easily testing the use of that flag? Depending on answers to those questions, I may want to spin a v2 patch that adds flag support throughout the block layer discard implementation, rather than this patch which just does it in NBD; but if nothing else, this is the shortest patch possible to fix the (corner-case?) NBD spec non-compliance. nbd/server.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nbd/server.c b/nbd/server.c index 4990a5826e6..e098da819df 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1623,6 +1623,9 @@ static coroutine_fn void nbd_trip(void *opaque) case NBD_CMD_TRIM: ret =3D blk_co_pdiscard(exp->blk, request.from + exp->dev_offset, request.len); + if (ret =3D=3D 0 && request.flags & NBD_CMD_FLAG_FUA) { + ret =3D blk_co_flush(exp->blk); + } if (ret < 0) { error_setg_errno(&local_err, -ret, "discard failed"); } --=20 2.14.3