From nobody Wed Feb 11 05:35:52 2026 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 1529593205110755.9526611332595; Thu, 21 Jun 2018 08:00:05 -0700 (PDT) Received: from localhost ([::1]:55941 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fW148-0002dS-DP for importer@patchew.org; Thu, 21 Jun 2018 11:00:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fW12R-0001LS-9n for qemu-devel@nongnu.org; Thu, 21 Jun 2018 10:58:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fW12Q-0006qH-9n for qemu-devel@nongnu.org; Thu, 21 Jun 2018 10:58:19 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41546 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 1fW12N-0006p7-D8; Thu, 21 Jun 2018 10:58:15 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE4094002248; Thu, 21 Jun 2018 14:58:14 +0000 (UTC) Received: from red.redhat.com (ovpn-120-169.rdu2.redhat.com [10.10.120.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98AD21117643; Thu, 21 Jun 2018 14:58:13 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Thu, 21 Jun 2018 09:57:49 -0500 Message-Id: <20180621145749.191944-10-eblake@redhat.com> In-Reply-To: <20180621145749.191944-1-eblake@redhat.com> References: <20180621145749.191944-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 21 Jun 2018 14:58:14 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Thu, 21 Jun 2018 14:58:14 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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] [PULL v2 9/9] nbd/server: introduce NBD_CMD_CACHE 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 , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz 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" From: Vladimir Sementsov-Ogievskiy Handle nbd CACHE command. Just do read, without sending read data back. Cache mechanism should be done by exported node driver chain. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20180413143156.11409-1-vsementsov@virtuozzo.com> Reviewed-by: Eric Blake [eblake: fix two missing case labels in switch statements] Signed-off-by: Eric Blake --- include/block/nbd.h | 3 ++- nbd/common.c | 2 ++ nbd/server.c | 11 +++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 8bb9606c39b..daaeae61bf9 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -135,6 +135,7 @@ typedef struct NBDExtent { #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_DF (1 << 7) /* Send DF (Do not Fragment) */ +#define NBD_FLAG_SEND_CACHE (1 << 8) /* Send CACHE (prefetch) */ /* New-style handshake (global) flags, sent from server to client, and control what will happen during handshake phase. */ @@ -195,7 +196,7 @@ enum { NBD_CMD_DISC =3D 2, NBD_CMD_FLUSH =3D 3, NBD_CMD_TRIM =3D 4, - /* 5 reserved for failed experiment NBD_CMD_CACHE */ + NBD_CMD_CACHE =3D 5, NBD_CMD_WRITE_ZEROES =3D 6, NBD_CMD_BLOCK_STATUS =3D 7, }; diff --git a/nbd/common.c b/nbd/common.c index 8c95c1d606e..41f5ed8d9fa 100644 --- a/nbd/common.c +++ b/nbd/common.c @@ -148,6 +148,8 @@ const char *nbd_cmd_lookup(uint16_t cmd) return "flush"; case NBD_CMD_TRIM: return "trim"; + case NBD_CMD_CACHE: + return "cache"; case NBD_CMD_WRITE_ZEROES: return "write zeroes"; case NBD_CMD_BLOCK_STATUS: diff --git a/nbd/server.c b/nbd/server.c index 2c2d62c6361..274604609f4 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1252,7 +1252,7 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt, Error **errp) int ret; const uint16_t myflags =3D (NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_TRIM | NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA | - NBD_FLAG_SEND_WRITE_ZEROES); + NBD_FLAG_SEND_WRITE_ZEROES | NBD_FLAG_SEND_C= ACHE); bool oldStyle; /* Old style negotiation header, no room for options @@ -2034,7 +2034,9 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request, return -EIO; } - if (request->type =3D=3D NBD_CMD_READ || request->type =3D=3D NBD_CMD_= WRITE) { + if (request->type =3D=3D NBD_CMD_READ || request->type =3D=3D NBD_CMD_= WRITE || + request->type =3D=3D NBD_CMD_CACHE) + { if (request->len > NBD_MAX_BUFFER_SIZE) { error_setg(errp, "len (%" PRIu32" ) is larger than max len (%u= )", request->len, NBD_MAX_BUFFER_SIZE); @@ -2119,7 +2121,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *cl= ient, NBDRequest *request, int ret; NBDExport *exp =3D client->exp; - assert(request->type =3D=3D NBD_CMD_READ); + assert(request->type =3D=3D NBD_CMD_READ || request->type =3D=3D NBD_C= MD_CACHE); /* XXX: NBD Protocol only documents use of FUA with WRITE */ if (request->flags & NBD_CMD_FLAG_FUA) { @@ -2138,7 +2140,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *cl= ient, NBDRequest *request, ret =3D blk_pread(exp->blk, request->from + exp->dev_offset, data, request->len); - if (ret < 0) { + if (ret < 0 || request->type =3D=3D NBD_CMD_CACHE) { return nbd_send_generic_reply(client, request->handle, ret, "reading from file failed", errp); } @@ -2171,6 +2173,7 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, switch (request->type) { case NBD_CMD_READ: + case NBD_CMD_CACHE: return nbd_do_cmd_read(client, request, data, errp); case NBD_CMD_WRITE: --=20 2.14.4