From nobody Tue May 7 15:50:56 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 1504638838686621.9335983353392; Tue, 5 Sep 2017 12:13:58 -0700 (PDT) Received: from localhost ([::1]:60936 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpJIL-0001zd-Ae for importer@patchew.org; Tue, 05 Sep 2017 15:13:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpJG5-0000UI-BO for qemu-devel@nongnu.org; Tue, 05 Sep 2017 15:11:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpJG0-0005aD-IU for qemu-devel@nongnu.org; Tue, 05 Sep 2017 15:11:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36808) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dpJFn-0005Q7-Th; Tue, 05 Sep 2017 15:11:20 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0FF88753A2; Tue, 5 Sep 2017 19:11:19 +0000 (UTC) Received: from red.redhat.com (ovpn-120-228.rdu2.redhat.com [10.10.120.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA9F57EF97; Tue, 5 Sep 2017 19:11:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0FF88753A2 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 5 Sep 2017 14:11:12 -0500 Message-Id: <20170905191114.5959-2-eblake@redhat.com> In-Reply-To: <20170905191114.5959-1-eblake@redhat.com> References: <20170905191114.5959-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 05 Sep 2017 19:11:19 +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] [PATCH 1/3] io: Yield rather than wait when already in coroutine 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: pbonzini@redhat.com, qemu-block@nongnu.org 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" The new qio_channel_{read,write}{,v}_all functions are documented as yielding until data is available. When used on a blocking channel, this yield is done via qio_channel_wait() which spawns a new coroutine under the hood (so it is the new entry point that yields as needed); but if we are already in a coroutine (at which point QIO_CHANNEL_ERR_BLOCK is only possible if we are a non-blocking channel), we want to yield the current coroutine instead of spawning a new one. Signed-off-by: Eric Blake Acked-by: Daniel P. Berrange --- io/channel.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/io/channel.c b/io/channel.c index 5e8c2f0a91..9e62794cab 100644 --- a/io/channel.c +++ b/io/channel.c @@ -105,7 +105,11 @@ int qio_channel_readv_all(QIOChannel *ioc, ssize_t len; len =3D qio_channel_readv(ioc, local_iov, nlocal_iov, errp); if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { - qio_channel_wait(ioc, G_IO_IN); + if (qemu_in_coroutine()) { + qio_channel_yield(ioc, G_IO_IN); + } else { + qio_channel_wait(ioc, G_IO_IN); + } continue; } else if (len < 0) { goto cleanup; @@ -143,7 +147,11 @@ int qio_channel_writev_all(QIOChannel *ioc, ssize_t len; len =3D qio_channel_writev(ioc, local_iov, nlocal_iov, errp); if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { - qio_channel_wait(ioc, G_IO_OUT); + if (qemu_in_coroutine()) { + qio_channel_yield(ioc, G_IO_OUT); + } else { + qio_channel_wait(ioc, G_IO_OUT); + } continue; } if (len < 0) { --=20 2.13.5 From nobody Tue May 7 15:50:56 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 150463899572833.209628207573246; Tue, 5 Sep 2017 12:16:35 -0700 (PDT) Received: from localhost ([::1]:60958 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpJKs-00044x-Ih for importer@patchew.org; Tue, 05 Sep 2017 15:16:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33211) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpJG4-0000TV-IV for qemu-devel@nongnu.org; Tue, 05 Sep 2017 15:11:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpJFz-0005Ze-JG for qemu-devel@nongnu.org; Tue, 05 Sep 2017 15:11:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56486) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dpJFp-0005Qp-2u; Tue, 05 Sep 2017 15:11:21 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2EBEB3A271; Tue, 5 Sep 2017 19:11:20 +0000 (UTC) Received: from red.redhat.com (ovpn-120-228.rdu2.redhat.com [10.10.120.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51EBB7EF97; Tue, 5 Sep 2017 19:11:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2EBEB3A271 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 5 Sep 2017 14:11:13 -0500 Message-Id: <20170905191114.5959-3-eblake@redhat.com> In-Reply-To: <20170905191114.5959-1-eblake@redhat.com> References: <20170905191114.5959-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 05 Sep 2017 19:11:20 +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] [PATCH 2/3] io: Add new qio_channel_read{, v}_all_eof functions 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: pbonzini@redhat.com, qemu-block@nongnu.org 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" Some callers want to distinguish between clean EOF (no bytes read) vs. a short read (at least one byte read, but EOF encountered before reaching the desired length), as it allows clients the ability to do a graceful shutdown when a server shuts down at defined safe points in the protocol, rather than treating all shutdown scenarios as an error due to EOF. However, we don't want to require all callers to have to check for early EOF. So add another wrapper function that can be used by the callers that care about the distinction. Signed-off-by: Eric Blake Acked-by: Daniel P. Berrange --- include/io/channel.h | 53 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ io/channel.c | 48 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 93 insertions(+), 8 deletions(-) diff --git a/include/io/channel.h b/include/io/channel.h index 8f25893c45..3995e243a3 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -269,6 +269,36 @@ ssize_t qio_channel_writev_full(QIOChannel *ioc, Error **errp); /** + * qio_channel_readv_all_eof: + * @ioc: the channel object + * @iov: the array of memory regions to read data into + * @niov: the length of the @iov array + * @errp: pointer to a NULL-initialized error object + * + * Read data from the IO channel, storing it in the + * memory regions referenced by @iov. Each element + * in the @iov will be fully populated with data + * before the next one is used. The @niov parameter + * specifies the total number of elements in @iov. + * + * The function will wait for all requested data + * to be read, yielding from the current coroutine + * if required. + * + * If end-of-file occurs before any data is read, + * no error is reported; otherwise, if it occurs + * before all requested data has been read, an error + * will be reported. + * + * Returns: 1 if all bytes were read, 0 if end-of-file + * occurs without data, or -1 on error + */ +int qio_channel_readv_all_eof(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + Error **errp); + +/** * qio_channel_readv_all: * @ioc: the channel object * @iov: the array of memory regions to read data into @@ -383,6 +413,28 @@ ssize_t qio_channel_write(QIOChannel *ioc, Error **errp); /** + * qio_channel_read_all_eof: + * @ioc: the channel object + * @buf: the memory region to read data into + * @buflen: the number of bytes to @buf + * @errp: pointer to a NULL-initialized error object + * + * Reads @buflen bytes into @buf, possibly blocking or (if the + * channel is non-blocking) yielding from the current coroutine + * multiple times until the entire content is read. If end-of-file + * occurs immediately it is not an error, but if it occurs after + * data has been read it will return an error rather than a + * short-read. Otherwise behaves as qio_channel_read(). + * + * Returns: 1 if all bytes were read, 0 if end-of-file occurs + * without data, or -1 on error + */ +int qio_channel_read_all_eof(QIOChannel *ioc, + char *buf, + size_t buflen, + Error **errp); + +/** * qio_channel_read_all: * @ioc: the channel object * @buf: the memory region to read data into @@ -401,6 +453,7 @@ int qio_channel_read_all(QIOChannel *ioc, char *buf, size_t buflen, Error **errp); + /** * qio_channel_write_all: * @ioc: the channel object diff --git a/io/channel.c b/io/channel.c index 9e62794cab..ec4b86de7c 100644 --- a/io/channel.c +++ b/io/channel.c @@ -86,16 +86,16 @@ ssize_t qio_channel_writev_full(QIOChannel *ioc, } - -int qio_channel_readv_all(QIOChannel *ioc, - const struct iovec *iov, - size_t niov, - Error **errp) +int qio_channel_readv_all_eof(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + Error **errp) { int ret =3D -1; struct iovec *local_iov =3D g_new(struct iovec, niov); struct iovec *local_iov_head =3D local_iov; unsigned int nlocal_iov =3D niov; + bool partial =3D false; nlocal_iov =3D iov_copy(local_iov, nlocal_iov, iov, niov, @@ -114,21 +114,43 @@ int qio_channel_readv_all(QIOChannel *ioc, } else if (len < 0) { goto cleanup; } else if (len =3D=3D 0) { - error_setg(errp, - "Unexpected end-of-file before all bytes were read"= ); + if (partial) { + error_setg(errp, + "Unexpected end-of-file before all bytes were r= ead"); + } else { + ret =3D 0; + } goto cleanup; } + partial =3D true; iov_discard_front(&local_iov, &nlocal_iov, len); } - ret =3D 0; + ret =3D 1; cleanup: g_free(local_iov_head); return ret; } +int qio_channel_readv_all(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + Error **errp) +{ + int ret =3D qio_channel_readv_all_eof(ioc, iov, niov, errp); + + if (ret =3D=3D 0) { + ret =3D -1; + error_setg(errp, + "Unexpected end-of-file before all bytes were read"); + } else if (ret =3D=3D 1) { + ret =3D 0; + } + return ret; +} + int qio_channel_writev_all(QIOChannel *ioc, const struct iovec *iov, size_t niov, @@ -205,6 +227,16 @@ ssize_t qio_channel_write(QIOChannel *ioc, } +int qio_channel_read_all_eof(QIOChannel *ioc, + char *buf, + size_t buflen, + Error **errp) +{ + struct iovec iov =3D { .iov_base =3D buf, .iov_len =3D buflen }; + return qio_channel_readv_all_eof(ioc, &iov, 1, errp); +} + + int qio_channel_read_all(QIOChannel *ioc, char *buf, size_t buflen, --=20 2.13.5 From nobody Tue May 7 15:50:56 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 1504638978056861.4166643351075; Tue, 5 Sep 2017 12:16:18 -0700 (PDT) Received: from localhost ([::1]:60957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpJKa-0003tl-Si for importer@patchew.org; Tue, 05 Sep 2017 15:16:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpJGA-0000Yd-Gk for qemu-devel@nongnu.org; Tue, 05 Sep 2017 15:11:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpJG4-0005cF-Qd for qemu-devel@nongnu.org; Tue, 05 Sep 2017 15:11:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21393) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dpJFt-0005Us-VP; Tue, 05 Sep 2017 15:11:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13B18C08A42E; Tue, 5 Sep 2017 19:11:25 +0000 (UTC) Received: from red.redhat.com (ovpn-120-228.rdu2.redhat.com [10.10.120.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70FB27EF81; Tue, 5 Sep 2017 19:11:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 13B18C08A42E 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: Tue, 5 Sep 2017 14:11:14 -0500 Message-Id: <20170905191114.5959-4-eblake@redhat.com> In-Reply-To: <20170905191114.5959-1-eblake@redhat.com> References: <20170905191114.5959-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 05 Sep 2017 19:11: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] [PATCH 3/3] nbd: Use new qio_channel_*_all() functions 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 , pbonzini@redhat.com, qemu-block@nongnu.org, 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" Rather than open-coding our own read/write-all functions, we can make use of the recently-added qio code. It slightly changes the error message in one of the iotests. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrange --- include/block/nbd.h | 2 -- nbd/nbd-internal.h | 41 +++++++---------------------------------- block/nbd-client.c | 15 +++++++-------- nbd/common.c | 45 ------------------------------------------= --- tests/qemu-iotests/083.out | 8 ++++---- 5 files changed, 18 insertions(+), 93 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 040cdd2e60..707fd37575 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -155,8 +155,6 @@ struct NBDExportInfo { }; typedef struct NBDExportInfo NBDExportInfo; -ssize_t nbd_rwv(QIOChannel *ioc, struct iovec *iov, size_t niov, size_t le= ngth, - bool do_read, Error **errp); int nbd_receive_negotiate(QIOChannel *ioc, const char *name, QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, NBDExportInfo *info, diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h index 03549e3f39..8a609a227f 100644 --- a/nbd/nbd-internal.h +++ b/nbd/nbd-internal.h @@ -85,28 +85,14 @@ 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. - */ + int ret; assert(size); - - ret =3D nbd_rwv(ioc, &iov, 1, size, true, errp); - if (ret <=3D 0) { - return ret; + ret =3D qio_channel_read_all_eof(ioc, buffer, size, errp); + if (ret < 0) { + ret =3D -EIO; } - - if (ret !=3D size) { - error_setg(errp, "End of file"); - return -EINVAL; - } - - return 1; + return ret; } /* nbd_read @@ -115,14 +101,7 @@ static inline int nbd_read_eof(QIOChannel *ioc, void *= buffer, size_t size, static inline int nbd_read(QIOChannel *ioc, void *buffer, size_t size, Error **errp) { - int ret =3D nbd_read_eof(ioc, buffer, size, errp); - - if (ret =3D=3D 0) { - ret =3D -EINVAL; - error_setg(errp, "End of file"); - } - - return ret < 0 ? ret : 0; + return qio_channel_read_all(ioc, buffer, size, errp) < 0 ? -EIO : 0; } /* nbd_write @@ -131,13 +110,7 @@ static inline int nbd_read(QIOChannel *ioc, void *buff= er, size_t size, static inline int nbd_write(QIOChannel *ioc, const void *buffer, size_t si= ze, Error **errp) { - struct iovec iov =3D { .iov_base =3D (void *) buffer, .iov_len =3D siz= e }; - - ssize_t ret =3D nbd_rwv(ioc, &iov, 1, size, false, errp); - - assert(ret < 0 || ret =3D=3D size); - - return ret < 0 ? ret : 0; + return qio_channel_write_all(ioc, buffer, size, errp) < 0 ? -EIO : 0; } struct NBDTLSHandshakeData { diff --git a/block/nbd-client.c b/block/nbd-client.c index f0dbea24d3..ee7f758e68 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -121,7 +121,7 @@ static int nbd_co_send_request(BlockDriverState *bs, QEMUIOVector *qiov) { NBDClientSession *s =3D nbd_get_client_session(bs); - int rc, ret, i; + int rc, i; qemu_co_mutex_lock(&s->send_mutex); while (s->in_flight =3D=3D MAX_NBD_REQUESTS) { @@ -156,9 +156,9 @@ static int nbd_co_send_request(BlockDriverState *bs, qio_channel_set_cork(s->ioc, true); rc =3D nbd_send_request(s->ioc, request); if (rc >=3D 0 && !s->quit) { - ret =3D nbd_rwv(s->ioc, qiov->iov, qiov->niov, request->len, f= alse, - NULL); - if (ret !=3D request->len) { + assert(request->len =3D=3D iov_size(qiov->iov, qiov->niov)); + if (qio_channel_writev_all(s->ioc, qiov->iov, qiov->niov, + NULL) < 0) { rc =3D -EIO; } } @@ -184,7 +184,6 @@ static void nbd_co_receive_reply(NBDClientSession *s, QEMUIOVector *qiov) { int i =3D HANDLE_TO_INDEX(s, request->handle); - int ret; /* Wait until we're woken up by nbd_read_reply_entry. */ s->requests[i].receiving =3D true; @@ -195,9 +194,9 @@ static void nbd_co_receive_reply(NBDClientSession *s, reply->error =3D EIO; } else { if (qiov && reply->error =3D=3D 0) { - ret =3D nbd_rwv(s->ioc, qiov->iov, qiov->niov, request->len, t= rue, - NULL); - if (ret !=3D request->len) { + 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; s->quit =3D true; } diff --git a/nbd/common.c b/nbd/common.c index e288d1b972..59a5316be9 100644 --- a/nbd/common.c +++ b/nbd/common.c @@ -20,51 +20,6 @@ #include "qapi/error.h" #include "nbd-internal.h" -/* nbd_wr_syncv - * The function may be called from coroutine or from non-coroutine context. - * When called from non-coroutine context @ioc must be in blocking mode. - */ -ssize_t nbd_rwv(QIOChannel *ioc, struct iovec *iov, size_t niov, size_t le= ngth, - bool do_read, Error **errp) -{ - ssize_t done =3D 0; - struct iovec *local_iov =3D g_new(struct iovec, niov); - struct iovec *local_iov_head =3D local_iov; - unsigned int nlocal_iov =3D niov; - - nlocal_iov =3D iov_copy(local_iov, nlocal_iov, iov, niov, 0, length); - - while (nlocal_iov > 0) { - ssize_t len; - if (do_read) { - len =3D qio_channel_readv(ioc, local_iov, nlocal_iov, errp); - } else { - len =3D qio_channel_writev(ioc, local_iov, nlocal_iov, errp); - } - if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { - /* errp should not be set */ - assert(qemu_in_coroutine()); - qio_channel_yield(ioc, do_read ? G_IO_IN : G_IO_OUT); - continue; - } - if (len < 0) { - done =3D -EIO; - goto cleanup; - } - - if (do_read && len =3D=3D 0) { - break; - } - - iov_discard_front(&local_iov, &nlocal_iov, len); - done +=3D len; - } - - cleanup: - g_free(local_iov_head); - return done; -} - /* Discard length bytes from channel. Return -errno on failure and 0 on * success */ int nbd_drop(QIOChannel *ioc, size_t size, Error **errp) diff --git a/tests/qemu-iotests/083.out b/tests/qemu-iotests/083.out index fb71b6f8ad..25dde519e3 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 -End of file +Unexpected end-of-file before all bytes were read read failed: Input/output error =3D=3D=3D Check disconnect 8 reply =3D=3D=3D -End of file +Unexpected end-of-file before all bytes were read 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 -End of file +Unexpected end-of-file before all bytes were read read failed: Input/output error =3D=3D=3D Check disconnect 8 reply =3D=3D=3D -End of file +Unexpected end-of-file before all bytes were read read failed: Input/output error =3D=3D=3D Check disconnect before data =3D=3D=3D --=20 2.13.5