From nobody Tue Feb 10 19:47:45 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501863176307246.47090577603478; Fri, 4 Aug 2017 09:12:56 -0700 (PDT) Received: from localhost ([::1]:51855 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddfDa-00021N-Hv for importer@patchew.org; Fri, 04 Aug 2017 12:12:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddeJN-0005UM-4U for qemu-devel@nongnu.org; Fri, 04 Aug 2017 11:14:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddeJL-0007DV-4W for qemu-devel@nongnu.org; Fri, 04 Aug 2017 11:14:48 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:15385 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddeJK-0007Ac-JY for qemu-devel@nongnu.org; Fri, 04 Aug 2017 11:14:46 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v74FEeGI003061; Fri, 4 Aug 2017 18:14:41 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Fri, 4 Aug 2017 18:14:37 +0300 Message-Id: <20170804151440.320927-15-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170804151440.320927-1-vsementsov@virtuozzo.com> References: <20170804151440.320927-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 14/17] block/nbd-client: exit reply-reading coroutine on incorrect handle 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, vsementsov@virtuozzo.com, mreitz@redhat.com, den@openvz.org, pbonzini@redhat.com 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" Check reply-handle =3D=3D request-handle in the same place, where recv coroutine number is calculated from reply->handle and it's correctness checked - in nbd_read_reply_entry. Also finish nbd_read_reply_entry in case of reply-handle !=3D request-handle in the same way as in case of incorrect reply-handle. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/nbd-client.h | 1 + block/nbd-client.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/block/nbd-client.h b/block/nbd-client.h index 48e2559df6..aa36be8950 100644 --- a/block/nbd-client.h +++ b/block/nbd-client.h @@ -29,6 +29,7 @@ typedef struct NBDClientSession { =20 struct { Coroutine *co; + NBDRequest *request; } requests[MAX_NBD_REQUESTS]; NBDReply reply; } NBDClientSession; diff --git a/block/nbd-client.c b/block/nbd-client.c index 5eb126c399..0e12db4be3 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -88,7 +88,9 @@ static coroutine_fn void nbd_read_reply_entry(void *opaqu= e) * one coroutine is called until the reply finishes. */ i =3D HANDLE_TO_INDEX(s, s->reply.handle); - if (i >=3D MAX_NBD_REQUESTS || !s->requests[i].co) { + if (i >=3D MAX_NBD_REQUESTS || !s->requests[i].co || + s->reply.handle !=3D s->requests[i].request->handle) + { break; } =20 @@ -135,6 +137,7 @@ static int nbd_co_request(BlockDriverState *bs, g_assert(qemu_in_coroutine()); assert(i < MAX_NBD_REQUESTS); request->handle =3D INDEX_TO_HANDLE(s, i); + s->requests[i].request =3D request; =20 if (!s->ioc) { qemu_co_mutex_unlock(&s->send_mutex); @@ -170,11 +173,13 @@ static int nbd_co_request(BlockDriverState *bs, =20 /* Wait until we're woken up by nbd_read_reply_entry. */ qemu_coroutine_yield(); - if (s->reply.handle !=3D request->handle || !s->ioc) { + if (!s->ioc || s->reply.handle =3D=3D 0) { rc =3D -EIO; goto out; } =20 + assert(s->reply.handle =3D=3D request->handle); + if (qiov && s->reply.error =3D=3D 0) { ret =3D nbd_rwv(s->ioc, qiov->iov, qiov->niov, request->len, true,= NULL); if (ret !=3D request->len) { --=20 2.11.1