From nobody Sat May 4 16:34:07 2024 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 1505743470811228.37341692387236; Mon, 18 Sep 2017 07:04:30 -0700 (PDT) Received: from localhost ([::1]:36802 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtwez-0005dR-SY for importer@patchew.org; Mon, 18 Sep 2017 10:04:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38437) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtwaR-0001iL-A0 for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtwaN-0001QQ-Ms for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:47 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:37069 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 1dtwaN-0001P3-B3 for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:43 -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 v8IDxZdV022049; Mon, 18 Sep 2017 16:59:37 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 16:59:29 +0300 Message-Id: <20170918135935.255591-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170918135935.255591-1-vsementsov@virtuozzo.com> References: <20170918135935.255591-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 v2 1/7] block/nbd-client: refactor nbd_co_receive_reply 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" "NBDReply *reply" parameter of nbd_co_receive_reply is used only to pass return value for nbd_co_request (reply.error). Remove it and use function return value instead. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/nbd-client.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index ee7f758e68..acd8e5d007 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -178,26 +178,26 @@ err: return rc; } =20 -static void nbd_co_receive_reply(NBDClientSession *s, - NBDRequest *request, - NBDReply *reply, - QEMUIOVector *qiov) +static int nbd_co_receive_reply(NBDClientSession *s, + NBDRequest *request, + QEMUIOVector *qiov) { + int ret; int i =3D HANDLE_TO_INDEX(s, request->handle); =20 /* Wait until we're woken up by nbd_read_reply_entry. */ s->requests[i].receiving =3D true; qemu_coroutine_yield(); s->requests[i].receiving =3D false; - *reply =3D s->reply; - if (reply->handle !=3D request->handle || !s->ioc || s->quit) { - reply->error =3D EIO; + if (s->reply.handle !=3D request->handle || !s->ioc || s->quit) { + ret =3D -EIO; } else { - if (qiov && reply->error =3D=3D 0) { + ret =3D -s->reply.error; + if (qiov && s->reply.error =3D=3D 0) { assert(request->len =3D=3D iov_size(qiov->iov, qiov->niov)); if (qio_channel_readv_all(s->ioc, qiov->iov, qiov->niov, NULL) < 0) { - reply->error =3D EIO; + ret =3D -EIO; s->quit =3D true; } } @@ -217,6 +217,8 @@ static void nbd_co_receive_reply(NBDClientSession *s, s->in_flight--; qemu_co_queue_next(&s->free_sema); qemu_co_mutex_unlock(&s->send_mutex); + + return ret; } =20 static int nbd_co_request(BlockDriverState *bs, @@ -224,7 +226,6 @@ static int nbd_co_request(BlockDriverState *bs, QEMUIOVector *qiov) { NBDClientSession *client =3D nbd_get_client_session(bs); - NBDReply reply; int ret; =20 assert(!qiov || request->type =3D=3D NBD_CMD_WRITE || @@ -232,12 +233,11 @@ static int nbd_co_request(BlockDriverState *bs, ret =3D nbd_co_send_request(bs, request, request->type =3D=3D NBD_CMD_WRITE ? qiov : = NULL); if (ret < 0) { - reply.error =3D -ret; - } else { - nbd_co_receive_reply(client, request, &reply, - request->type =3D=3D NBD_CMD_READ ? qiov : NU= LL); + return ret; } - return -reply.error; + + return nbd_co_receive_reply(client, request, + request->type =3D=3D NBD_CMD_READ ? qiov := NULL); } =20 int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset, --=20 2.11.1 From nobody Sat May 4 16:34:07 2024 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 1505743355791777.8660418284691; Mon, 18 Sep 2017 07:02:35 -0700 (PDT) Received: from localhost ([::1]:36796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtwd8-0003uu-Py for importer@patchew.org; Mon, 18 Sep 2017 10:02:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38441) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtwaR-0001iN-AF for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtwaN-0001QY-Ns for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:47 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:2112 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 1dtwaN-0001Pe-BK for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:43 -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 v8IDxZdW022049; Mon, 18 Sep 2017 16:59:37 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 16:59:30 +0300 Message-Id: <20170918135935.255591-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170918135935.255591-1-vsementsov@virtuozzo.com> References: <20170918135935.255591-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 v2 2/7] 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 Reviewed-by: Eric Blake --- block/nbd-client.h | 1 + block/nbd-client.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/block/nbd-client.h b/block/nbd-client.h index b435754b82..b1900e6a6d 100644 --- a/block/nbd-client.h +++ b/block/nbd-client.h @@ -20,6 +20,7 @@ typedef struct { Coroutine *coroutine; bool receiving; /* waiting for read_reply_co? */ + NBDRequest *request; } NBDClientRequest; =20 typedef struct NBDClientSession { diff --git a/block/nbd-client.c b/block/nbd-client.c index acd8e5d007..5f241ecc22 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -92,7 +92,9 @@ static coroutine_fn void nbd_read_reply_entry(void *opaqu= e) i =3D HANDLE_TO_INDEX(s, s->reply.handle); if (i >=3D MAX_NBD_REQUESTS || !s->requests[i].coroutine || - !s->requests[i].receiving) { + !s->requests[i].receiving || + s->reply.handle !=3D s->requests[i].request->handle) + { break; } =20 @@ -142,6 +144,7 @@ static int nbd_co_send_request(BlockDriverState *bs, s->requests[i].receiving =3D false; =20 request->handle =3D INDEX_TO_HANDLE(s, i); + s->requests[i].request =3D request; =20 if (s->quit) { rc =3D -EIO; @@ -189,9 +192,10 @@ static int nbd_co_receive_reply(NBDClientSession *s, s->requests[i].receiving =3D true; qemu_coroutine_yield(); s->requests[i].receiving =3D false; - if (s->reply.handle !=3D request->handle || !s->ioc || s->quit) { + if (!s->ioc || s->quit) { ret =3D -EIO; } else { + assert(s->reply.handle =3D=3D request->handle); ret =3D -s->reply.error; if (qiov && s->reply.error =3D=3D 0) { assert(request->len =3D=3D iov_size(qiov->iov, qiov->niov)); --=20 2.11.1 From nobody Sat May 4 16:34:07 2024 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 1505743299752127.39474299889082; Mon, 18 Sep 2017 07:01:39 -0700 (PDT) Received: from localhost ([::1]:36793 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtwcE-00035l-PQ for importer@patchew.org; Mon, 18 Sep 2017 10:01:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38438) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtwaR-0001iM-A1 for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtwaN-0001Q9-Eb for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:47 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:32117 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 1dtwaM-0001PB-UM for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:43 -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 v8IDxZdX022049; Mon, 18 Sep 2017 16:59:37 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 16:59:31 +0300 Message-Id: <20170918135935.255591-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170918135935.255591-1-vsementsov@virtuozzo.com> References: <20170918135935.255591-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 v2 3/7] block/nbd-client: refactor reading reply 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" Read the whole reply in one place - in nbd_read_reply_entry. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/nbd-client.h | 1 + block/nbd-client.c | 42 ++++++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/block/nbd-client.h b/block/nbd-client.h index b1900e6a6d..3f97d31013 100644 --- a/block/nbd-client.h +++ b/block/nbd-client.h @@ -21,6 +21,7 @@ typedef struct { Coroutine *coroutine; bool receiving; /* waiting for read_reply_co? */ NBDRequest *request; + QEMUIOVector *qiov; } NBDClientRequest; =20 typedef struct NBDClientSession { diff --git a/block/nbd-client.c b/block/nbd-client.c index 5f241ecc22..f7b642f079 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -98,6 +98,21 @@ static coroutine_fn void nbd_read_reply_entry(void *opaq= ue) break; } =20 + if (s->reply.error =3D=3D 0 && + s->requests[i].request->type =3D=3D NBD_CMD_READ) + { + QEMUIOVector *qiov =3D s->requests[i].qiov; + assert(qiov !=3D NULL); + assert(s->requests[i].request->len =3D=3D + iov_size(qiov->iov, qiov->niov)); + if (qio_channel_readv_all(s->ioc, qiov->iov, qiov->niov, + NULL) < 0) + { + s->reply.error =3D EIO; + break; + } + } + /* We're woken up again by the request itself. Note that there * is no race between yielding and reentering read_reply_co. This * is because: @@ -118,6 +133,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opa= que) s->read_reply_co =3D NULL; } =20 +/* qiov should be provided for READ and WRITE */ static int nbd_co_send_request(BlockDriverState *bs, NBDRequest *request, QEMUIOVector *qiov) @@ -145,6 +161,7 @@ static int nbd_co_send_request(BlockDriverState *bs, =20 request->handle =3D INDEX_TO_HANDLE(s, i); s->requests[i].request =3D request; + s->requests[i].qiov =3D qiov; =20 if (s->quit) { rc =3D -EIO; @@ -155,7 +172,8 @@ static int nbd_co_send_request(BlockDriverState *bs, goto err; } =20 - if (qiov) { + if (s->requests[i].request->type =3D=3D NBD_CMD_WRITE) { + assert(qiov); qio_channel_set_cork(s->ioc, true); rc =3D nbd_send_request(s->ioc, request); if (rc >=3D 0 && !s->quit) { @@ -181,9 +199,7 @@ err: return rc; } =20 -static int nbd_co_receive_reply(NBDClientSession *s, - NBDRequest *request, - QEMUIOVector *qiov) +static int nbd_co_receive_reply(NBDClientSession *s, NBDRequest *request) { int ret; int i =3D HANDLE_TO_INDEX(s, request->handle); @@ -197,14 +213,6 @@ static int nbd_co_receive_reply(NBDClientSession *s, } else { assert(s->reply.handle =3D=3D request->handle); ret =3D -s->reply.error; - if (qiov && s->reply.error =3D=3D 0) { - assert(request->len =3D=3D iov_size(qiov->iov, qiov->niov)); - if (qio_channel_readv_all(s->ioc, qiov->iov, qiov->niov, - NULL) < 0) { - ret =3D -EIO; - s->quit =3D true; - } - } =20 /* Tell the read handler to read another header. */ s->reply.handle =3D 0; @@ -232,16 +240,14 @@ static int nbd_co_request(BlockDriverState *bs, NBDClientSession *client =3D nbd_get_client_session(bs); int ret; =20 - assert(!qiov || request->type =3D=3D NBD_CMD_WRITE || - request->type =3D=3D NBD_CMD_READ); - ret =3D nbd_co_send_request(bs, request, - request->type =3D=3D NBD_CMD_WRITE ? qiov : = NULL); + assert((qiov =3D=3D NULL) !=3D + (request->type =3D=3D NBD_CMD_WRITE || request->type =3D=3D NBD= _CMD_READ)); + ret =3D nbd_co_send_request(bs, request, qiov); if (ret < 0) { return ret; } =20 - return nbd_co_receive_reply(client, request, - request->type =3D=3D NBD_CMD_READ ? qiov := NULL); + return nbd_co_receive_reply(client, request); } =20 int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset, --=20 2.11.1 From nobody Sat May 4 16:34:07 2024 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 1505743528656241.57025383191444; Mon, 18 Sep 2017 07:05:28 -0700 (PDT) Received: from localhost ([::1]:36804 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtwfv-0006Og-0q for importer@patchew.org; Mon, 18 Sep 2017 10:05:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtwaW-0001nk-Dz for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtwaS-0001TY-IF for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:52 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:2677 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 1dtwaS-0001SD-6o for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:48 -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 v8IDxZdY022049; Mon, 18 Sep 2017 16:59:37 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 16:59:32 +0300 Message-Id: <20170918135935.255591-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170918135935.255591-1-vsementsov@virtuozzo.com> References: <20170918135935.255591-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 v2 4/7] block/nbd-client: drop reply field from NBDClientSession 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" Drop 'reply' from NBDClientSession. It's used to only deliver request return code to receiving coroutine. Instead introduce per-request ret variable to simplify the scheme and make further refactoring possible. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/nbd-client.h | 2 +- block/nbd-client.c | 22 +++++++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/block/nbd-client.h b/block/nbd-client.h index 3f97d31013..4bc8fe3993 100644 --- a/block/nbd-client.h +++ b/block/nbd-client.h @@ -22,6 +22,7 @@ typedef struct { bool receiving; /* waiting for read_reply_co? */ NBDRequest *request; QEMUIOVector *qiov; + int ret; } NBDClientRequest; =20 typedef struct NBDClientSession { @@ -35,7 +36,6 @@ typedef struct NBDClientSession { int in_flight; =20 NBDClientRequest requests[MAX_NBD_REQUESTS]; - NBDReply reply; bool quit; } NBDClientSession; =20 diff --git a/block/nbd-client.c b/block/nbd-client.c index f7b642f079..f331f08a9a 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -74,10 +74,10 @@ static coroutine_fn void nbd_read_reply_entry(void *opa= que) uint64_t i; int ret =3D 0; Error *local_err =3D NULL; + NBDReply reply; =20 while (!s->quit) { - assert(s->reply.handle =3D=3D 0); - ret =3D nbd_receive_reply(s->ioc, &s->reply, &local_err); + ret =3D nbd_receive_reply(s->ioc, &reply, &local_err); if (ret < 0) { error_report_err(local_err); } @@ -89,18 +89,18 @@ static coroutine_fn void nbd_read_reply_entry(void *opa= que) * handler acts as a synchronization point and ensures that only * one coroutine is called until the reply finishes. */ - i =3D HANDLE_TO_INDEX(s, s->reply.handle); + i =3D HANDLE_TO_INDEX(s, reply.handle); if (i >=3D MAX_NBD_REQUESTS || !s->requests[i].coroutine || !s->requests[i].receiving || - s->reply.handle !=3D s->requests[i].request->handle) + reply.handle !=3D s->requests[i].request->handle) { break; } =20 - if (s->reply.error =3D=3D 0 && - s->requests[i].request->type =3D=3D NBD_CMD_READ) - { + s->requests[i].ret =3D -reply.error; + + if (reply.error =3D=3D 0 && s->requests[i].request->type =3D=3D NB= D_CMD_READ) { QEMUIOVector *qiov =3D s->requests[i].qiov; assert(qiov !=3D NULL); assert(s->requests[i].request->len =3D=3D @@ -108,7 +108,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opa= que) if (qio_channel_readv_all(s->ioc, qiov->iov, qiov->niov, NULL) < 0) { - s->reply.error =3D EIO; + s->requests[i].ret =3D -EIO; break; } } @@ -211,11 +211,7 @@ static int nbd_co_receive_reply(NBDClientSession *s, N= BDRequest *request) if (!s->ioc || s->quit) { ret =3D -EIO; } else { - assert(s->reply.handle =3D=3D request->handle); - ret =3D -s->reply.error; - - /* Tell the read handler to read another header. */ - s->reply.handle =3D 0; + ret =3D s->requests[i].ret; } =20 s->requests[i].coroutine =3D NULL; --=20 2.11.1 From nobody Sat May 4 16:34:07 2024 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 150574330050490.91533622723705; Mon, 18 Sep 2017 07:01:40 -0700 (PDT) Received: from localhost ([::1]:36794 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtwcF-00037Q-Ie for importer@patchew.org; Mon, 18 Sep 2017 10:01:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38435) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtwaR-0001iJ-9T for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtwaO-0001R1-Pn for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:47 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:14443 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 1dtwaO-0001PG-Ei for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:44 -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 v8IDxZdZ022049; Mon, 18 Sep 2017 16:59:37 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 16:59:33 +0300 Message-Id: <20170918135935.255591-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170918135935.255591-1-vsementsov@virtuozzo.com> References: <20170918135935.255591-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 v2 5/7] block/nbd-client: nbd_co_send_request: return -EIO if s->quit was set in parallel 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" It's incorrect to return success rc >=3D 0 if we skip qio_channel_writev_al= l() call due to s->quit. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/nbd-client.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/nbd-client.c b/block/nbd-client.c index f331f08a9a..280147e6a7 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -189,6 +189,9 @@ static int nbd_co_send_request(BlockDriverState *bs, } =20 err: + if (rc >=3D 0 && s->quit) { + rc =3D -EIO; + } if (rc < 0) { s->quit =3D true; s->requests[i].coroutine =3D NULL; --=20 2.11.1 From nobody Sat May 4 16:34:07 2024 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 1505743468774995.0047540692537; Mon, 18 Sep 2017 07:04:28 -0700 (PDT) Received: from localhost ([::1]:36801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtwew-0005aO-QW for importer@patchew.org; Mon, 18 Sep 2017 10:04:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38501) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtwaT-0001kX-7t for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtwaS-0001TO-Aa for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:49 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:19804 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 1dtwaR-0001S7-Vc for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:48 -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 v8IDxZda022049; Mon, 18 Sep 2017 16:59:37 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 16:59:34 +0300 Message-Id: <20170918135935.255591-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170918135935.255591-1-vsementsov@virtuozzo.com> References: <20170918135935.255591-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 v2 6/7] block/nbd-client: early fail nbd_read_reply_entry if s->quit is set 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" Do not continue any operation if s->quit is set in parallel. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/nbd-client.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 280147e6a7..f80a4c5564 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -81,7 +81,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opaqu= e) if (ret < 0) { error_report_err(local_err); } - if (ret <=3D 0) { + if (ret <=3D 0 || s->quit) { break; } =20 @@ -105,9 +105,8 @@ static coroutine_fn void nbd_read_reply_entry(void *opa= que) assert(qiov !=3D NULL); assert(s->requests[i].request->len =3D=3D iov_size(qiov->iov, qiov->niov)); - if (qio_channel_readv_all(s->ioc, qiov->iov, qiov->niov, - NULL) < 0) - { + ret =3D qio_channel_readv_all(s->ioc, qiov->iov, qiov->niov, N= ULL); + if (ret < 0 || s->quit) { s->requests[i].ret =3D -EIO; break; } --=20 2.11.1 From nobody Sat May 4 16:34:07 2024 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 1505743479653241.28736706647203; Mon, 18 Sep 2017 07:04:39 -0700 (PDT) Received: from localhost ([::1]:36803 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtwf9-0005kH-0s for importer@patchew.org; Mon, 18 Sep 2017 10:04:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtwaR-0001iK-9i for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtwaN-0001QL-Me for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:47 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:10237 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 1dtwaN-0001Pg-B7 for qemu-devel@nongnu.org; Mon, 18 Sep 2017 09:59:43 -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 v8IDxZdb022049; Mon, 18 Sep 2017 16:59:37 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 18 Sep 2017 16:59:35 +0300 Message-Id: <20170918135935.255591-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170918135935.255591-1-vsementsov@virtuozzo.com> References: <20170918135935.255591-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 v2 7/7] block/nbd-client: do not yield from nbd_read_reply_entry 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" Refactor nbd client to not yield from nbd_read_reply_entry. It's possible now as all reading is done in nbd_read_reply_entry and all request-related data is stored in per-request s->requests[i]. We need here some additional work with s->requests[i].ret and s->quit to not fail requests on normal disconnet and to not report reading errors on normal disconnect. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/nbd-client.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index f80a4c5564..bf20d5d5e6 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -79,7 +79,11 @@ static coroutine_fn void nbd_read_reply_entry(void *opaq= ue) while (!s->quit) { ret =3D nbd_receive_reply(s->ioc, &reply, &local_err); if (ret < 0) { - error_report_err(local_err); + if (s->quit) { + error_free(local_err); + } else { + error_report_err(local_err); + } } if (ret <=3D 0 || s->quit) { break; @@ -112,19 +116,8 @@ static coroutine_fn void nbd_read_reply_entry(void *op= aque) } } =20 - /* We're woken up again by the request itself. Note that there - * is no race between yielding and reentering read_reply_co. This - * is because: - * - * - if the request runs on the same AioContext, it is only - * entered after we yield - * - * - if the request runs on a different AioContext, reentering - * read_reply_co happens through a bottom half, which can only - * run after we yield. - */ + s->requests[i].receiving =3D false; aio_co_wake(s->requests[i].coroutine); - qemu_coroutine_yield(); } =20 s->quit =3D true; @@ -157,6 +150,7 @@ static int nbd_co_send_request(BlockDriverState *bs, =20 s->requests[i].coroutine =3D qemu_coroutine_self(); s->requests[i].receiving =3D false; + s->requests[i].ret =3D -EIO; =20 request->handle =3D INDEX_TO_HANDLE(s, i); s->requests[i].request =3D request; @@ -210,7 +204,7 @@ static int nbd_co_receive_reply(NBDClientSession *s, NB= DRequest *request) s->requests[i].receiving =3D true; qemu_coroutine_yield(); s->requests[i].receiving =3D false; - if (!s->ioc || s->quit) { + if (!s->ioc) { ret =3D -EIO; } else { ret =3D s->requests[i].ret; @@ -218,11 +212,6 @@ static int nbd_co_receive_reply(NBDClientSession *s, N= BDRequest *request) =20 s->requests[i].coroutine =3D NULL; =20 - /* Kick the read_reply_co to get the next reply. */ - if (s->read_reply_co) { - aio_co_wake(s->read_reply_co); - } - qemu_co_mutex_lock(&s->send_mutex); s->in_flight--; qemu_co_queue_next(&s->free_sema); @@ -364,6 +353,8 @@ void nbd_client_close(BlockDriverState *bs) =20 nbd_send_request(client->ioc, &request); =20 + client->quit =3D true; + nbd_teardown_connection(bs); } =20 --=20 2.11.1