From nobody Mon Nov 10 22:32:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1559829083; cv=none; d=zoho.com; s=zohoarc; b=FrVNQsdRizA85aH0M+ZOfJm0mwgYlsIlitR4iyj7ut+nyRY1l0N57sZ5Sai8jFYxqWaVCeDSXYGcTWxhw5U4Pkv1dqCOpSZBzn4ANVawHGMNgFelM1G6rTsXvApSqS/Qv+g+fAtDFyBFUu3KOlg1X0VPhyMIqM3xPQIl0n0UFvQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559829083; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=dMvfxHVgnWjiZurddu16SdEdKnDq8Ce2V5/tmwGVwJ0=; b=EfMwNLboTUTzThxiqLY+kuV2n3AegIXvEgZuTYfIskNCCBcNlVxde64m4HU1gzuTWiFsLzjdTyaF0WyW+WI7iMRd/YJg6DzcdVqjFQL7CAZWInW0FK/kt2WuYe1rItjKShM2LHhTlRaG0g4o9WQgA4n/mqQ9hwjoJiGfV3/LbSg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559829083952701.1444547215538; Thu, 6 Jun 2019 06:51:23 -0700 (PDT) Received: from localhost ([127.0.0.1]:60916 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYsnY-0007us-Ps for importer@patchew.org; Thu, 06 Jun 2019 09:51:20 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44139) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYsku-0006L9-B4 for qemu-devel@nongnu.org; Thu, 06 Jun 2019 09:48:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYskg-0001j2-Qf for qemu-devel@nongnu.org; Thu, 06 Jun 2019 09:48:24 -0400 Received: from relay.sw.ru ([185.231.240.75]:45554) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hYskf-0001Hb-3j; Thu, 06 Jun 2019 09:48:22 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hYska-00004z-0r; Thu, 06 Jun 2019 16:48:16 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 6 Jun 2019 16:48:12 +0300 Message-Id: <20190606134814.123689-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190606134814.123689-1-vsementsov@virtuozzo.com> References: <20190606134814.123689-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 1/3] block: implement blk_co_pcache 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, fam@euphon.net, vsementsov@virtuozzo.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Do effective copy-on-read request when we don't need data actually. It will be used for block-stream and NBD_CMD_CACHE. Signed-off-by: Vladimir Sementsov-Ogievskiy --- include/block/block.h | 8 +++++++- include/sysemu/block-backend.h | 7 +++++++ block/io.c | 18 ++++++++++++------ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index f9415ed740..4662f25513 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -88,8 +88,14 @@ typedef enum { * fallback. */ BDRV_REQ_NO_FALLBACK =3D 0x100, =20 + /* + * BDRV_REQ_CACHE may be used only together with BDRV_REQ_COPY_ON_READ + * on read request and means that caller don't really need data to be + * written to qiov parameter which may be NULL. + */ + BDRV_REQ_CACHE =3D 0x200, /* Mask of valid flags */ - BDRV_REQ_MASK =3D 0x1ff, + BDRV_REQ_MASK =3D 0x3ff, } BdrvRequestFlags; =20 typedef struct BlockSizes { diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 733c4957eb..2bcecd1190 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -135,6 +135,13 @@ static inline int coroutine_fn blk_co_pread(BlockBacke= nd *blk, int64_t offset, return blk_co_preadv(blk, offset, bytes, &qiov, flags); } =20 +static inline int coroutine_fn blk_co_pcache(BlockBackend *blk, int64_t of= fset, + unsigned int bytes) +{ + return blk_co_preadv(blk, offset, bytes, NULL, + BDRV_REQ_COPY_ON_READ | BDRV_REQ_CACHE); +} + static inline int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t of= fset, unsigned int bytes, void *buf, BdrvRequestFlags flags) diff --git a/block/io.c b/block/io.c index 9ba1bada36..9daf7332bd 100644 --- a/block/io.c +++ b/block/io.c @@ -1104,7 +1104,8 @@ bdrv_driver_pwritev_compressed(BlockDriverState *bs, = uint64_t offset, } =20 static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child, - int64_t offset, unsigned int bytes, QEMUIOVector *qiov) + int64_t offset, unsigned int bytes, QEMUIOVector *qiov, + int flags) { BlockDriverState *bs =3D child->bs; =20 @@ -1215,9 +1216,11 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(Bdr= vChild *child, goto err; } =20 - qemu_iovec_from_buf(qiov, progress, bounce_buffer + skip_bytes, - pnum - skip_bytes); - } else { + if (!(flags & BDRV_REQ_CACHE)) { + qemu_iovec_from_buf(qiov, progress, bounce_buffer + skip_b= ytes, + pnum - skip_bytes); + } + } else if (!(flags & BDRV_REQ_CACHE)) { /* Read directly into the destination */ qemu_iovec_init(&local_qiov, qiov->niov); qemu_iovec_concat(&local_qiov, qiov, progress, pnum - skip_byt= es); @@ -1268,7 +1271,8 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild= *child, * potential fallback support, if we ever implement any read flags * to pass through to drivers. For now, there aren't any * passthrough flags. */ - assert(!(flags & ~(BDRV_REQ_NO_SERIALISING | BDRV_REQ_COPY_ON_READ))); + assert(!(flags & ~(BDRV_REQ_NO_SERIALISING | BDRV_REQ_COPY_ON_READ | + BDRV_REQ_CACHE))); =20 /* Handle Copy on Read and associated serialisation */ if (flags & BDRV_REQ_COPY_ON_READ) { @@ -1296,7 +1300,9 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild= *child, } =20 if (!ret || pnum !=3D bytes) { - ret =3D bdrv_co_do_copy_on_readv(child, offset, bytes, qiov); + ret =3D bdrv_co_do_copy_on_readv(child, offset, bytes, qiov, f= lags); + goto out; + } else if (flags & BDRV_REQ_CACHE) { goto out; } } --=20 2.18.0 From nobody Mon Nov 10 22:32:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1559829233; cv=none; d=zoho.com; s=zohoarc; b=kCwSlrijprMR8doV26nZ4yTKf88vYbKHWQtRUmC7H589HED7lunQrBnLj5pUVpv8kh385oQKQwQOSStvCq3Yxq4LpkWi1vcRGgP1Zy5eZFXOAd4FCPi3x1vqkUUsGcwoi1K4qz6Slvg4xZCabzTcuuIkYqOzLwwJpzxiJMaJQQ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559829233; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=DZc/9pAs9KZORO4pEC7h8PHgWTRVukg4XbgTsHnEJB8=; b=fofbga6NBFk36pKz0eIUfckoagZyGY2E1r8wAmKzBupE/91pmTGoR7sHCvz6xmjIOe98MKhfyLT5qftradLp7u7wM/NyQUNaWa5bxNUGrq49VmuocK8hVARA7IpKNcJEvsaB1+pbjffM8XvP5X9kHnyP8A+9ToVNZIY1l0oaZsY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559829233346574.1299342070168; Thu, 6 Jun 2019 06:53:53 -0700 (PDT) Received: from localhost ([127.0.0.1]:60949 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYspu-0001ig-Ic for importer@patchew.org; Thu, 06 Jun 2019 09:53:46 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44093) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYskv-0006Is-3L for qemu-devel@nongnu.org; Thu, 06 Jun 2019 09:48:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYskg-0001im-Qe for qemu-devel@nongnu.org; Thu, 06 Jun 2019 09:48:23 -0400 Received: from relay.sw.ru ([185.231.240.75]:45562) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hYskf-0001HZ-6G; Thu, 06 Jun 2019 09:48:22 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hYska-00004z-6B; Thu, 06 Jun 2019 16:48:16 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 6 Jun 2019 16:48:13 +0300 Message-Id: <20190606134814.123689-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190606134814.123689-1-vsementsov@virtuozzo.com> References: <20190606134814.123689-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 2/3] block/stream: use blk_co_pcache 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, fam@euphon.net, vsementsov@virtuozzo.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This helps to avoid extra io, allocations and memory copying. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/stream.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/block/stream.c b/block/stream.c index 1a906fd860..8478aa4a50 100644 --- a/block/stream.c +++ b/block/stream.c @@ -22,11 +22,11 @@ =20 enum { /* - * Size of data buffer for populating the image file. This should be = large + * Maximum chunk size to feed it to copy-on-read. This should be large * enough to process multiple clusters in a single call, so that popul= ating * contiguous regions of the image is efficient. */ - STREAM_BUFFER_SIZE =3D 512 * 1024, /* in bytes */ + STREAM_CHUNK =3D 512 * 1024, /* in bytes */ }; =20 typedef struct StreamBlockJob { @@ -39,13 +39,11 @@ typedef struct StreamBlockJob { } StreamBlockJob; =20 static int coroutine_fn stream_populate(BlockBackend *blk, - int64_t offset, uint64_t bytes, - void *buf) + int64_t offset, uint64_t bytes) { assert(bytes < SIZE_MAX); =20 - /* Copy-on-read the unallocated clusters */ - return blk_co_pread(blk, offset, bytes, buf, BDRV_REQ_COPY_ON_READ); + return blk_co_pcache(blk, offset, bytes); } =20 static void stream_abort(Job *job) @@ -117,7 +115,6 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) int error =3D 0; int ret =3D 0; int64_t n =3D 0; /* bytes */ - void *buf; =20 if (!bs->backing) { goto out; @@ -130,8 +127,6 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) } job_progress_set_remaining(&s->common.job, len); =20 - buf =3D qemu_blockalign(bs, STREAM_BUFFER_SIZE); - /* Turn on copy-on-read for the whole block device so that guest read * requests help us make progress. Only do this when copying the enti= re * backing chain since the copy-on-read operation does not take base i= nto @@ -154,7 +149,7 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) =20 copy =3D false; =20 - ret =3D bdrv_is_allocated(bs, offset, STREAM_BUFFER_SIZE, &n); + ret =3D bdrv_is_allocated(bs, offset, STREAM_CHUNK, &n); if (ret =3D=3D 1) { /* Allocated in the top, no need to copy. */ } else if (ret >=3D 0) { @@ -172,7 +167,7 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) } trace_stream_one_iteration(s, offset, n, ret); if (copy) { - ret =3D stream_populate(blk, offset, n, buf); + ret =3D stream_populate(blk, offset, n); } if (ret < 0) { BlockErrorAction action =3D @@ -206,8 +201,6 @@ static int coroutine_fn stream_run(Job *job, Error **er= rp) /* Do not remove the backing file if an error was there but ignored. = */ ret =3D error; =20 - qemu_vfree(buf); - out: /* Modify backing chain and close BDSes in main loop */ return ret; --=20 2.18.0 From nobody Mon Nov 10 22:32:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1559829073; cv=none; d=zoho.com; s=zohoarc; b=nu/qVB9aYnk+JPiWIQzoKqSKk7AC3VqHDe3o1edI1dge1EulM/NNcbNwfaFcdFZ5tVJpusCnG67+LgYr0aOYcT9HbIPB/K4fw/8keM5FzRMTvGOngo7ft8tNQEt82ASPn2Yr4xvNiRa0V4rEoOIXxj1U7Nsr/l0mkWHiHjcYrO0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559829073; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=KRtHw0GYlgqOb1edhY9x74c9DA8za5uz/W8ibjc+H0g=; b=TWis1V4RzdkG8tK/17B2onaQphtelOemuvnutxNYdwLl7ldjrut4YBrxatz7a69K0062jQVkNALJ3VD9uJ7uA9BXZkbquayyeYZiRRCeb7N/6WxX6h6//6ty17ydBTQmYq8spwMLEltyCjqHIxGN9XOMBzK4drQgzrNnf/5Fngg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559829073966129.52565591158577; Thu, 6 Jun 2019 06:51:13 -0700 (PDT) Received: from localhost ([127.0.0.1]:60914 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYsnL-0007iU-AM for importer@patchew.org; Thu, 06 Jun 2019 09:51:07 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44116) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYsku-0006L1-Ep for qemu-devel@nongnu.org; Thu, 06 Jun 2019 09:48:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYskg-0001j4-Rk for qemu-devel@nongnu.org; Thu, 06 Jun 2019 09:48:23 -0400 Received: from relay.sw.ru ([185.231.240.75]:45560) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hYskf-0001Ha-3l; Thu, 06 Jun 2019 09:48:22 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1hYska-00004z-Ah; Thu, 06 Jun 2019 16:48:16 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 6 Jun 2019 16:48:14 +0300 Message-Id: <20190606134814.123689-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190606134814.123689-1-vsementsov@virtuozzo.com> References: <20190606134814.123689-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 3/3] nbd: improve CMD_CACHE: use blk_co_pcache 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, fam@euphon.net, vsementsov@virtuozzo.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This helps to avoid extra io, allocations and memory copying. We assume here that CMD_CACHE is always used with copy-on-read, as otherwise it's a noop. Signed-off-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index aeca3893fe..a7e8dbaccd 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2101,12 +2101,15 @@ static int nbd_co_receive_request(NBDRequestData *r= eq, NBDRequest *request, return -EINVAL; } =20 - req->data =3D blk_try_blockalign(client->exp->blk, request->len); - if (req->data =3D=3D NULL) { - error_setg(errp, "No memory"); - return -ENOMEM; + if (request->type !=3D NBD_CMD_CACHE) { + req->data =3D blk_try_blockalign(client->exp->blk, request->le= n); + if (req->data =3D=3D NULL) { + error_setg(errp, "No memory"); + return -ENOMEM; + } } } + if (request->type =3D=3D NBD_CMD_WRITE) { if (nbd_read(client->ioc, req->data, request->len, "CMD_WRITE data= ", errp) < 0) @@ -2191,7 +2194,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *cl= ient, NBDRequest *request, int ret; NBDExport *exp =3D client->exp; =20 - assert(request->type =3D=3D NBD_CMD_READ || request->type =3D=3D NBD_C= MD_CACHE); + assert(request->type =3D=3D NBD_CMD_READ); =20 /* XXX: NBD Protocol only documents use of FUA with WRITE */ if (request->flags & NBD_CMD_FLAG_FUA) { @@ -2203,7 +2206,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *cl= ient, NBDRequest *request, } =20 if (client->structured_reply && !(request->flags & NBD_CMD_FLAG_DF) && - request->len && request->type !=3D NBD_CMD_CACHE) + request->len) { return nbd_co_send_sparse_read(client, request->handle, request->f= rom, data, request->len, errp); @@ -2211,7 +2214,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *cl= ient, NBDRequest *request, =20 ret =3D blk_pread(exp->blk, request->from + exp->dev_offset, data, request->len); - if (ret < 0 || request->type =3D=3D NBD_CMD_CACHE) { + if (ret < 0) { return nbd_send_generic_reply(client, request->handle, ret, "reading from file failed", errp); } @@ -2230,6 +2233,28 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *c= lient, NBDRequest *request, } } =20 +/* + * nbd_do_cmd_cache + * + * Handle NBD_CMD_CACHE request. + * Return -errno if sending fails. Other errors are reported directly to t= he + * client as an error reply. + */ +static coroutine_fn int nbd_do_cmd_cache(NBDClient *client, NBDRequest *re= quest, + Error **errp) +{ + int ret; + NBDExport *exp =3D client->exp; + + assert(request->type =3D=3D NBD_CMD_CACHE); + + ret =3D blk_co_pcache(exp->blk, request->from + exp->dev_offset, + request->len); + + return nbd_send_generic_reply(client, request->handle, ret, + "caching data failed", errp); +} + /* Handle NBD request. * Return -errno if sending fails. Other errors are reported directly to t= he * client as an error reply. */ @@ -2243,8 +2268,10 @@ static coroutine_fn int nbd_handle_request(NBDClient= *client, char *msg; =20 switch (request->type) { - case NBD_CMD_READ: case NBD_CMD_CACHE: + return nbd_do_cmd_cache(client, request, errp); + + case NBD_CMD_READ: return nbd_do_cmd_read(client, request, data, errp); =20 case NBD_CMD_WRITE: --=20 2.18.0