From nobody Sun Oct 5 19:25:52 2025 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 1504116568927229.8517547110406; Wed, 30 Aug 2017 11:09:28 -0700 (PDT) Received: from localhost ([::1]:52044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7Qc-00038P-Nr for importer@patchew.org; Wed, 30 Aug 2017 14:09:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53134) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7Om-0001wT-0g for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dn7Ol-0001cU-1O for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54540) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dn7Og-0001aQ-KG; Wed, 30 Aug 2017 14:07:26 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A1382C04B938; Wed, 30 Aug 2017 18:07:25 +0000 (UTC) Received: from red.redhat.com (ovpn-122-186.rdu2.redhat.com [10.10.122.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BC0717106; Wed, 30 Aug 2017 18:07:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A1382C04B938 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 30 Aug 2017 13:07:06 -0500 Message-Id: <20170830180711.7974-7-eblake@redhat.com> In-Reply-To: <20170830180711.7974-1-eblake@redhat.com> References: <20170830180711.7974-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 30 Aug 2017 18:07:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 06/11] nbd/client: refactor nbd_read_eof 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: Kevin Wolf , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." , Max Reitz 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" From: Vladimir Sementsov-Ogievskiy Refactor nbd_read_eof to return 1 on success, 0 on eof, when no data was read and <0 for other cases, because returned size of read data is not actually used. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20170804151440.320927-3-vsementsov@virtuozzo.com> [eblake: tweak function comments, rebase to test 083 enhancements] Signed-off-by: Eric Blake --- nbd/nbd-internal.h | 33 ++++++++++++++++++++++++--------- nbd/client.c | 5 ----- tests/qemu-iotests/083.out | 8 ++++---- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h index 396ddb4d3e..03549e3f39 100644 --- a/nbd/nbd-internal.h +++ b/nbd/nbd-internal.h @@ -77,21 +77,36 @@ #define NBD_ESHUTDOWN 108 /* nbd_read_eof - * Tries to read @size bytes from @ioc. Returns number of bytes actually r= ead. - * May return a value >=3D 0 and < size only on EOF, i.e. when iteratively= called - * qio_channel_readv() returns 0. So, there is no need to call nbd_read_eof - * iteratively. + * Tries to read @size bytes from @ioc. + * Returns 1 on success + * 0 on eof, when no data was read (errp is not set) + * negative errno on failure (errp is set) */ -static inline ssize_t nbd_read_eof(QIOChannel *ioc, void *buffer, size_t s= ize, - Error **errp) +static inline int nbd_read_eof(QIOChannel *ioc, void *buffer, size_t size, + Error **errp) { struct iovec iov =3D { .iov_base =3D buffer, .iov_len =3D size }; + ssize_t ret; + /* Sockets are kept in blocking mode in the negotiation phase. After * that, a non-readable socket simply means that another thread stole * our request/reply. Synchronization is done with recv_coroutine, so * that this is coroutine-safe. */ - return nbd_rwv(ioc, &iov, 1, size, true, errp); + + assert(size); + + ret =3D nbd_rwv(ioc, &iov, 1, size, true, errp); + if (ret <=3D 0) { + return ret; + } + + if (ret !=3D size) { + error_setg(errp, "End of file"); + return -EINVAL; + } + + return 1; } /* nbd_read @@ -100,9 +115,9 @@ static inline ssize_t nbd_read_eof(QIOChannel *ioc, voi= d *buffer, size_t size, static inline int nbd_read(QIOChannel *ioc, void *buffer, size_t size, Error **errp) { - ssize_t ret =3D nbd_read_eof(ioc, buffer, size, errp); + int ret =3D nbd_read_eof(ioc, buffer, size, errp); - if (ret >=3D 0 && ret !=3D size) { + if (ret =3D=3D 0) { ret =3D -EINVAL; error_setg(errp, "End of file"); } diff --git a/nbd/client.c b/nbd/client.c index f1c16b588f..4556056daa 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -925,11 +925,6 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *r= eply, Error **errp) return ret; } - if (ret !=3D sizeof(buf)) { - error_setg(errp, "read failed"); - return -EINVAL; - } - /* Reply [ 0 .. 3] magic (NBD_REPLY_MAGIC) [ 4 .. 7] error (0 =3D=3D no error) diff --git a/tests/qemu-iotests/083.out b/tests/qemu-iotests/083.out index a7fb081889..fb71b6f8ad 100644 --- a/tests/qemu-iotests/083.out +++ b/tests/qemu-iotests/083.out @@ -69,12 +69,12 @@ read failed: Input/output error =3D=3D=3D Check disconnect 4 reply =3D=3D=3D -read failed +End of file read failed: Input/output error =3D=3D=3D Check disconnect 8 reply =3D=3D=3D -read failed +End of file read failed: Input/output error =3D=3D=3D Check disconnect before data =3D=3D=3D @@ -180,12 +180,12 @@ read failed: Input/output error =3D=3D=3D Check disconnect 4 reply =3D=3D=3D -read failed +End of file read failed: Input/output error =3D=3D=3D Check disconnect 8 reply =3D=3D=3D -read failed +End of file read failed: Input/output error =3D=3D=3D Check disconnect before data =3D=3D=3D --=20 2.13.5