From nobody Mon Feb 9 00:42:42 2026 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=1564049225; cv=none; d=zoho.com; s=zohoarc; b=h+2QhvABuSeeALYwCEMJodREj/CdlbtSOw3UXxWBKfyKi+p3Cv4dcJCB8LOs+blmB2GdV/UoeGrQoikNOvcV6/cCLwdmVZDJlUEZXyKouD/2xl74J0ll/ZIw8Cp4B03EWKr7Y7zEOaHl0LX7Y+fzNr/avc4NB1gRNmQaLNZNSK8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564049225; 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=7N4cBy560YX4ew4fx2oWhmG31f1kwi/bQIbFWKjOwx4=; b=Gly6zYLnG0jn9bfVqLxnsy7ZA53ybTmyBwtApiqFlxxZcIIzMpJJiU8+HOCwif6guBCo9COrY2xjGbXmqDeSK37G7w25Qs3EG8t2q1hI1b86xdokUPTvx9YqmxzDRQGck6/h+o7FXnhZRi7d32nM01zPGFVCy7HJGsFyTlhrKxk= 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 1564049225148394.1059009915325; Thu, 25 Jul 2019 03:07:05 -0700 (PDT) Received: from localhost ([::1]:58334 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqaeO-0000wn-2i for importer@patchew.org; Thu, 25 Jul 2019 06:07:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49320) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqadO-0005WJ-9D for qemu-devel@nongnu.org; Thu, 25 Jul 2019 06:06:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqadN-0006R5-65 for qemu-devel@nongnu.org; Thu, 25 Jul 2019 06:06:02 -0400 Received: from relay.sw.ru ([185.231.240.75]:45726) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqadJ-0006O5-JR; Thu, 25 Jul 2019 06:05:57 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hqadD-0001mQ-2y; Thu, 25 Jul 2019 13:05:51 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 25 Jul 2019 13:05:50 +0300 Message-Id: <20190725100550.33801-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190725100550.33801-1-vsementsov@virtuozzo.com> References: <20190725100550.33801-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 v3 3/3] nbd: improve CMD_CACHE: use BDRV_REQ_PREFETCH X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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 Reviewed-by: Eric Blake --- nbd/server.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 10faedcfc5..a2cf085f76 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2104,12 +2104,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) @@ -2194,7 +2197,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) { @@ -2206,7 +2209,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); @@ -2214,7 +2217,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); } @@ -2233,6 +2236,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_preadv(exp->blk, request->from + exp->dev_offset, reque= st->len, + NULL, BDRV_REQ_COPY_ON_READ | BDRV_REQ_PREFETCH); + + 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. */ @@ -2246,8 +2271,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