From nobody Mon May 6 12:58:16 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 1504711599339339.83803057890236; Wed, 6 Sep 2017 08:26:39 -0700 (PDT) Received: from localhost ([::1]:36713 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpcDs-0008PX-BM for importer@patchew.org; Wed, 06 Sep 2017 11:26:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53926) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpc92-0004GF-UE for qemu-devel@nongnu.org; Wed, 06 Sep 2017 11:21:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpc8y-0007D1-TW for qemu-devel@nongnu.org; Wed, 06 Sep 2017 11:21:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44590) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dpc8n-0006tL-OY; Wed, 06 Sep 2017 11:21:21 -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 CAF887F351; Wed, 6 Sep 2017 15:21: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 6773D61F36; Wed, 6 Sep 2017 15:21:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CAF887F351 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 6 Sep 2017 10:21:07 -0500 Message-Id: <20170906152111.16958-2-eblake@redhat.com> In-Reply-To: <20170906152111.16958-1-eblake@redhat.com> References: <20170906152111.16958-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.26]); Wed, 06 Sep 2017 15:21: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] [PULL 1/5] iotests: rewrite 192 to use _launch_qemu to fix LUKS support 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 , "open list:Block layer core" , 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: "Daniel P. Berrange" The LUKS driver requires extra args to QEMU to setup passwords. The _launch_qemu function takes care of this, so convert the test to use this function and use correct -drive syntax Signed-off-by: Daniel P. Berrange Message-Id: <20170901105434.3288-2-berrange@redhat.com> Reviewed-by: Eric Blake Tested-by: Fam Zheng Signed-off-by: Eric Blake --- tests/qemu-iotests/192 | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tests/qemu-iotests/192 b/tests/qemu-iotests/192 index b50a2c0c8e..595f0d786a 100755 --- a/tests/qemu-iotests/192 +++ b/tests/qemu-iotests/192 @@ -37,6 +37,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 # get standard environment, filters and checks . ./common.rc . ./common.filter +. ./common.qemu _supported_fmt generic _supported_proto file @@ -49,13 +50,21 @@ fi size=3D64M _make_test_img $size -{ -echo "nbd_server_start unix:$TEST_DIR/nbd" -echo "nbd_server_add -w drive0" -echo "q" -} | $QEMU -nodefaults -display none -monitor stdio \ - -drive format=3D$IMGFMT,file=3D$TEST_IMG,if=3Dide,id=3Ddrive0 \ - -incoming defer 2>&1 | _filter_testdir | _filter_qemu | _filter_hmp +if test "$IMGOPTSSYNTAX" =3D "true" +then + DRIVE_ARG=3Dif=3Dide,id=3Ddrive0,$TEST_IMG +else + DRIVE_ARG=3Dif=3Dide,id=3Ddrive0,format=3D$IMGFMT,file=3D$TEST_IMG +fi + +qemu_comm_method=3D"monitor" +_launch_qemu -drive $DRIVE_ARG -incoming defer +h=3D$QEMU_HANDLE +QEMU_COMM_TIMEOUT=3D1 + +_send_qemu_cmd $h "nbd_server_start unix:$TEST_DIR/nbd" "(qemu)" +_send_qemu_cmd $h "nbd_server_add -w drive0" "(qemu)" +_send_qemu_cmd $h "q" "(qemu)" # success, all done echo "*** done" --=20 2.13.5 From nobody Mon May 6 12:58:16 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 1504711668387287.7322378539826; Wed, 6 Sep 2017 08:27:48 -0700 (PDT) Received: from localhost ([::1]:36716 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpcF1-0000vI-5U for importer@patchew.org; Wed, 06 Sep 2017 11:27:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53914) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpc91-0004FJ-NN for qemu-devel@nongnu.org; Wed, 06 Sep 2017 11:21:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpc8w-0007Bw-2y for qemu-devel@nongnu.org; Wed, 06 Sep 2017 11:21:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17314) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dpc8p-0006wk-Jj; Wed, 06 Sep 2017 11:21:23 -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 A508319CFE6; Wed, 6 Sep 2017 15:21:22 +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 115F787801; Wed, 6 Sep 2017 15:21:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A508319CFE6 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 6 Sep 2017 10:21:08 -0500 Message-Id: <20170906152111.16958-3-eblake@redhat.com> In-Reply-To: <20170906152111.16958-1-eblake@redhat.com> References: <20170906152111.16958-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.29]); Wed, 06 Sep 2017 15:21:22 +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 2/5] iotests: blacklist 194 with the luks driver 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 , "open list:Block layer core" , 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: "Daniel P. Berrange" The 194 test has a lot of code that assumes a simple image file. Rewriting this to work with luks is possible, but non-trivial, so blacklist the luks format for now. Signed-off-by: Daniel P. Berrange Message-Id: <20170901105434.3288-3-berrange@redhat.com> Reviewed-by: Eric Blake Tested-by: Fam Zheng [eblake: commit message typo fixed] Reviewed-by: Kashyap Chamarthy Reviewed-by: Stefan Hajnoczi Signed-off-by: Eric Blake --- tests/qemu-iotests/194 | 1 + tests/qemu-iotests/iotests.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/qemu-iotests/194 b/tests/qemu-iotests/194 index 6449b9b64a..8d973b440f 100755 --- a/tests/qemu-iotests/194 +++ b/tests/qemu-iotests/194 @@ -21,6 +21,7 @@ import iotests +iotests.verify_image_format(unsupported_fmts=3D['luks']) iotests.verify_platform(['linux']) with iotests.FilePath('source.img') as source_img_path, \ diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 07fa1626a0..1af117e37d 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -421,9 +421,11 @@ def notrun(reason): print '%s not run: %s' % (seq, reason) sys.exit(0) -def verify_image_format(supported_fmts=3D[]): +def verify_image_format(supported_fmts=3D[], unsupported_fmts=3D[]): if supported_fmts and (imgfmt not in supported_fmts): notrun('not suitable for this image format: %s' % imgfmt) + if unsupported_fmts and (imgfmt in unsupported_fmts): + notrun('not suitable for this image format: %s' % imgfmt) def verify_platform(supported_oses=3D['linux']): if True not in [sys.platform.startswith(x) for x in supported_oses]: --=20 2.13.5 From nobody Mon May 6 12:58:16 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 1504711394387291.33264159026464; Wed, 6 Sep 2017 08:23:14 -0700 (PDT) Received: from localhost ([::1]:36697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpcAb-0005dw-Dd for importer@patchew.org; Wed, 06 Sep 2017 11:23:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53872) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpc8w-0004Ax-Sg for qemu-devel@nongnu.org; Wed, 06 Sep 2017 11:21:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpc8q-0006xr-TS for qemu-devel@nongnu.org; Wed, 06 Sep 2017 11:21:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29162) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dpc8q-0006xL-N2 for qemu-devel@nongnu.org; Wed, 06 Sep 2017 11:21:24 -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 C5176883D6 for ; Wed, 6 Sep 2017 15:21:23 +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 DBD8587801; Wed, 6 Sep 2017 15:21:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C5176883D6 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 6 Sep 2017 10:21:09 -0500 Message-Id: <20170906152111.16958-4-eblake@redhat.com> In-Reply-To: <20170906152111.16958-1-eblake@redhat.com> References: <20170906152111.16958-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.26]); Wed, 06 Sep 2017 15:21:23 +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 3/5] 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: , 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 nested event loop under the hood (so it is that secondary loop which 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 nested event loop. Signed-off-by: Eric Blake Message-Id: <20170905191114.5959-2-eblake@redhat.com> Acked-by: Daniel P. Berrange [commit message updated] Signed-off-by: Eric Blake --- 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 Mon May 6 12:58:16 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 1504711513795118.68442572068443; Wed, 6 Sep 2017 08:25:13 -0700 (PDT) Received: from localhost ([::1]:36703 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpcCW-0007F7-OM for importer@patchew.org; Wed, 06 Sep 2017 11:25:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53868) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpc8w-0004AM-85 for qemu-devel@nongnu.org; Wed, 06 Sep 2017 11:21:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpc8r-0006yT-Qs for qemu-devel@nongnu.org; Wed, 06 Sep 2017 11:21:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37771) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dpc8r-0006xv-Ht for qemu-devel@nongnu.org; Wed, 06 Sep 2017 11:21:25 -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 9AF75806B6 for ; Wed, 6 Sep 2017 15:21:24 +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 0913D8781A; Wed, 6 Sep 2017 15:21:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9AF75806B6 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 6 Sep 2017 10:21:10 -0500 Message-Id: <20170906152111.16958-5-eblake@redhat.com> In-Reply-To: <20170906152111.16958-1-eblake@redhat.com> References: <20170906152111.16958-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.26]); Wed, 06 Sep 2017 15:21:24 +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 4/5] 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: , 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 Message-Id: <20170905191114.5959-3-eblake@redhat.com> 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 Mon May 6 12:58:16 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 150471152333029.46718052103381; Wed, 6 Sep 2017 08:25:23 -0700 (PDT) Received: from localhost ([::1]:36704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpcCf-0007M7-3S for importer@patchew.org; Wed, 06 Sep 2017 11:25:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpc99-0004MK-DE for qemu-devel@nongnu.org; Wed, 06 Sep 2017 11:21:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpc93-0007Jx-Ai for qemu-devel@nongnu.org; Wed, 06 Sep 2017 11:21:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43076) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dpc8s-0006yb-IY; Wed, 06 Sep 2017 11:21: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 A463B1E2F9; Wed, 6 Sep 2017 15:21: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 D110B87804; Wed, 6 Sep 2017 15:21:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A463B1E2F9 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Wed, 6 Sep 2017 10:21:11 -0500 Message-Id: <20170906152111.16958-6-eblake@redhat.com> In-Reply-To: <20170906152111.16958-1-eblake@redhat.com> References: <20170906152111.16958-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.30]); Wed, 06 Sep 2017 15:21: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 5/5] 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 , Paolo Bonzini , "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" 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 Message-Id: <20170905191114.5959-4-eblake@redhat.com> 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