From nobody Tue Feb 10 21:19:21 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 1501863648561321.33107446063286; Fri, 4 Aug 2017 09:20:48 -0700 (PDT) Received: from localhost ([::1]:52317 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddfLC-0000ox-MW for importer@patchew.org; Fri, 04 Aug 2017 12:20:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddeJP-0005Wp-Se for qemu-devel@nongnu.org; Fri, 04 Aug 2017 11:14:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddeJM-0007GW-R8 for qemu-devel@nongnu.org; Fri, 04 Aug 2017 11:14:51 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:47517 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 1ddeJM-00078e-Aq for qemu-devel@nongnu.org; Fri, 04 Aug 2017 11:14: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 v74FEeGB003061; Fri, 4 Aug 2017 18:14:40 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Fri, 4 Aug 2017 18:14:30 +0300 Message-Id: <20170804151440.320927-8-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 07/17] block/nbd-client: refactor request send/receive 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" Move nbd_co_receive_reply and nbd_coroutine_end calls into nbd_co_send_request and rename the latter to just nbd_co_request. This removes code duplications in nbd_client_co_{pwrite,pread,...} functions. Also this is needed for further refactoring. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/nbd-client.c | 89 ++++++++++++++++++++------------------------------= ---- 1 file changed, 33 insertions(+), 56 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 0c88d84de6..c9ade9b517 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -112,12 +112,20 @@ static coroutine_fn void nbd_read_reply_entry(void *o= paque) s->read_reply_co =3D NULL; } =20 -static int nbd_co_send_request(BlockDriverState *bs, - NBDRequest *request, - QEMUIOVector *qiov) +static void nbd_co_receive_reply(NBDClientSession *s, + NBDRequest *request, + NBDReply *reply, + QEMUIOVector *qiov); +static void nbd_coroutine_end(BlockDriverState *bs, + NBDRequest *request); + +static int nbd_co_request(BlockDriverState *bs, + NBDRequest *request, + QEMUIOVector *qiov) { NBDClientSession *s =3D nbd_get_client_session(bs); int rc, ret, i; + NBDReply reply; =20 qemu_co_mutex_lock(&s->send_mutex); while (s->in_flight =3D=3D MAX_NBD_REQUESTS) { @@ -141,7 +149,8 @@ static int nbd_co_send_request(BlockDriverState *bs, return -EPIPE; } =20 - if (qiov) { + if (request->type =3D=3D NBD_CMD_WRITE) { + assert(qiov !=3D NULL); qio_channel_set_cork(s->ioc, true); rc =3D nbd_send_request(s->ioc, request); if (rc >=3D 0) { @@ -156,6 +165,21 @@ static int nbd_co_send_request(BlockDriverState *bs, rc =3D nbd_send_request(s->ioc, request); } qemu_co_mutex_unlock(&s->send_mutex); + + if (rc < 0) { + goto out; + } + + if (request->type =3D=3D NBD_CMD_READ) { + assert(qiov !=3D NULL); + } else { + qiov =3D NULL; + } + nbd_co_receive_reply(s, request, &reply, qiov); + rc =3D -reply.error; + +out: + nbd_coroutine_end(bs, request); return rc; } =20 @@ -208,26 +232,16 @@ static void nbd_coroutine_end(BlockDriverState *bs, int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) { - NBDClientSession *client =3D nbd_get_client_session(bs); NBDRequest request =3D { .type =3D NBD_CMD_READ, .from =3D offset, .len =3D bytes, }; - NBDReply reply; - int ret; =20 assert(bytes <=3D NBD_MAX_BUFFER_SIZE); assert(!flags); =20 - ret =3D nbd_co_send_request(bs, &request, NULL); - if (ret < 0) { - reply.error =3D -ret; - } else { - nbd_co_receive_reply(client, &request, &reply, qiov); - } - nbd_coroutine_end(bs, &request); - return -reply.error; + return nbd_co_request(bs, &request, qiov); } =20 int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset, @@ -239,8 +253,6 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_= t offset, .from =3D offset, .len =3D bytes, }; - NBDReply reply; - int ret; =20 if (flags & BDRV_REQ_FUA) { assert(client->info.flags & NBD_FLAG_SEND_FUA); @@ -249,27 +261,18 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint6= 4_t offset, =20 assert(bytes <=3D NBD_MAX_BUFFER_SIZE); =20 - ret =3D nbd_co_send_request(bs, &request, qiov); - if (ret < 0) { - reply.error =3D -ret; - } else { - nbd_co_receive_reply(client, &request, &reply, NULL); - } - nbd_coroutine_end(bs, &request); - return -reply.error; + return nbd_co_request(bs, &request, qiov); } =20 int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags) { - int ret; NBDClientSession *client =3D nbd_get_client_session(bs); NBDRequest request =3D { .type =3D NBD_CMD_WRITE_ZEROES, .from =3D offset, .len =3D bytes, }; - NBDReply reply; =20 if (!(client->info.flags & NBD_FLAG_SEND_WRITE_ZEROES)) { return -ENOTSUP; @@ -283,22 +286,13 @@ int nbd_client_co_pwrite_zeroes(BlockDriverState *bs,= int64_t offset, request.flags |=3D NBD_CMD_FLAG_NO_HOLE; } =20 - ret =3D nbd_co_send_request(bs, &request, NULL); - if (ret < 0) { - reply.error =3D -ret; - } else { - nbd_co_receive_reply(client, &request, &reply, NULL); - } - nbd_coroutine_end(bs, &request); - return -reply.error; + return nbd_co_request(bs, &request, NULL); } =20 int nbd_client_co_flush(BlockDriverState *bs) { NBDClientSession *client =3D nbd_get_client_session(bs); NBDRequest request =3D { .type =3D NBD_CMD_FLUSH }; - NBDReply reply; - int ret; =20 if (!(client->info.flags & NBD_FLAG_SEND_FLUSH)) { return 0; @@ -307,14 +301,7 @@ int nbd_client_co_flush(BlockDriverState *bs) request.from =3D 0; request.len =3D 0; =20 - ret =3D nbd_co_send_request(bs, &request, NULL); - if (ret < 0) { - reply.error =3D -ret; - } else { - nbd_co_receive_reply(client, &request, &reply, NULL); - } - nbd_coroutine_end(bs, &request); - return -reply.error; + return nbd_co_request(bs, &request, NULL); } =20 int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) @@ -325,22 +312,12 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int6= 4_t offset, int bytes) .from =3D offset, .len =3D bytes, }; - NBDReply reply; - int ret; =20 if (!(client->info.flags & NBD_FLAG_SEND_TRIM)) { return 0; } =20 - ret =3D nbd_co_send_request(bs, &request, NULL); - if (ret < 0) { - reply.error =3D -ret; - } else { - nbd_co_receive_reply(client, &request, &reply, NULL); - } - nbd_coroutine_end(bs, &request); - return -reply.error; - + return nbd_co_request(bs, &request, NULL); } =20 void nbd_client_detach_aio_context(BlockDriverState *bs) --=20 2.11.1