From nobody Sun Oct 5 17:23:30 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 1504116580054229.65354313524472; Wed, 30 Aug 2017 11:09:40 -0700 (PDT) Received: from localhost ([::1]:52045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7Qn-0003Hq-OD for importer@patchew.org; Wed, 30 Aug 2017 14:09:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52995) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7Od-0001ny-2O for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dn7Ob-0001Yv-LL for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60492) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dn7OY-0001YN-IT; Wed, 30 Aug 2017 14:07:18 -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 851FD285A0; Wed, 30 Aug 2017 18:07:17 +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 3C451173A6; Wed, 30 Aug 2017 18:07:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 851FD285A0 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, 30 Aug 2017 13:07:01 -0500 Message-Id: <20170830180711.7974-2-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.30]); Wed, 30 Aug 2017 18:07:17 +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 01/11] qemu-iotests: Extend non-shared storage migration test (194) 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 , Max Reitz , "open list:Block layer core" , Kashyap Chamarthy 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: Kashyap Chamarthy This is the follow-up patch that was discussed[*] as part of feedback to qemu-iotest 194. Changes in this patch: - Supply 'job-id' parameter to `drive-mirror` invocation. - Once migration completes, issue QMP `block-job-cancel` command on the source QEMU to gracefully complete `drive-mirror` operation. - Once the BLOCK_JOB_COMPLETED event is emitted, stop the NBD server on the destination QEMU. - Check for both the events: MIGRATION and BLOCK_JOB_COMPLETED. With the above, the test will also be (almost) in sync with the procedure outlined in the document 'live-block-operations.rst'[+] (section: "QMP invocation for live storage migration with ``drive-mirror`` + NBD"). [*] https://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg04820.html -- qemu-iotests: add 194 non-shared storage migration test [+] https://git.qemu.org/gitweb.cgi?p=3Dqemu.git;a=3Dblob;f=3Ddocs/interop/= live-block-operations.rst Signed-off-by: Kashyap Chamarthy Message-Id: <20170829165058.8229-1-kchamart@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Eric Blake --- tests/qemu-iotests/194 | 23 +++++++++++++++++------ tests/qemu-iotests/194.out | 11 ++++++++--- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/tests/qemu-iotests/194 b/tests/qemu-iotests/194 index 8028111e21..a3e3bad664 100755 --- a/tests/qemu-iotests/194 +++ b/tests/qemu-iotests/194 @@ -46,16 +46,17 @@ iotests.log('Launching NBD server on destination...') iotests.log(dest_vm.qmp('nbd-server-start', addr=3D{'type': 'unix', 'data'= : {'path': nbd_sock_path}})) iotests.log(dest_vm.qmp('nbd-server-add', device=3D'drive0', writable=3DTr= ue)) -iotests.log('Starting drive-mirror on source...') +iotests.log('Starting `drive-mirror` on source...') iotests.log(source_vm.qmp( 'drive-mirror', device=3D'drive0', target=3D'nbd+unix:///drive0?socket=3D{0}'.format(nbd_sock_p= ath), sync=3D'full', format=3D'raw', # always raw, the server handles the format - mode=3D'existing')) + mode=3D'existing', + job_id=3D'mirror-job0')) -iotests.log('Waiting for drive-mirror to complete...') +iotests.log('Waiting for `drive-mirror` to complete...') iotests.log(source_vm.event_wait('BLOCK_JOB_READY'), filters=3D[iotests.filter_qmp_event]) @@ -67,7 +68,17 @@ dest_vm.qmp('migrate-set-capabilities', iotests.log(source_vm.qmp('migrate', uri=3D'unix:{0}'.format(migration_soc= k_path))) while True: - event =3D source_vm.event_wait('MIGRATION') - iotests.log(event, filters=3D[iotests.filter_qmp_event]) - if event['data']['status'] in ('completed', 'failed'): + event1 =3D source_vm.event_wait('MIGRATION') + iotests.log(event1, filters=3D[iotests.filter_qmp_event]) + if event1['data']['status'] in ('completed', 'failed'): + iotests.log('Gracefully ending the `drive-mirror` job on source...= ') + iotests.log(source_vm.qmp('block-job-cancel', device=3D'mirror-job= 0')) + break + +while True: + event2 =3D source_vm.event_wait('BLOCK_JOB_COMPLETED') + iotests.log(event2, filters=3D[iotests.filter_qmp_event]) + if event2['event'] =3D=3D 'BLOCK_JOB_COMPLETED': + iotests.log('Stopping the NBD server on destination...') + iotests.log(dest_vm.qmp('nbd-server-stop')) break diff --git a/tests/qemu-iotests/194.out b/tests/qemu-iotests/194.out index ae501fecac..50ac50da5e 100644 --- a/tests/qemu-iotests/194.out +++ b/tests/qemu-iotests/194.out @@ -2,12 +2,17 @@ Launching VMs... Launching NBD server on destination... {u'return': {}} {u'return': {}} -Starting drive-mirror on source... +Starting `drive-mirror` on source... {u'return': {}} -Waiting for drive-mirror to complete... -{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'device': u'drive0', u'type': u'mirror', u'speed': 0, u'len': 1073741824, u= 'offset': 1073741824}, u'event': u'BLOCK_JOB_READY'} +Waiting for `drive-mirror` to complete... +{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'device': u'mirror-job0', u'type': u'mirror', u'speed': 0, u'len': 10737418= 24, u'offset': 1073741824}, u'event': u'BLOCK_JOB_READY'} Starting migration... {u'return': {}} {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'status': u'setup'}, u'event': u'MIGRATION'} {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'status': u'active'}, u'event': u'MIGRATION'} {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'status': u'completed'}, u'event': u'MIGRATION'} +Gracefully ending the `drive-mirror` job on source... +{u'return': {}} +{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'device': u'mirror-job0', u'type': u'mirror', u'speed': 0, u'len': 10737418= 24, u'offset': 1073741824}, u'event': u'BLOCK_JOB_COMPLETED'} +Stopping the NBD server on destination... +{u'return': {}} --=20 2.13.5 From nobody Sun Oct 5 17:23:30 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 1504116721665285.42783739947924; Wed, 30 Aug 2017 11:12:01 -0700 (PDT) Received: from localhost ([::1]:52061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7T5-00060y-KZ for importer@patchew.org; Wed, 30 Aug 2017 14:11:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7Og-0001qQ-AB for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dn7Oe-0001a7-Uc for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46462) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dn7Ob-0001Yr-Tz; Wed, 30 Aug 2017 14:07:22 -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 EB16B80C06; Wed, 30 Aug 2017 18:07:20 +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 BEBC1173A6; Wed, 30 Aug 2017 18:07:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EB16B80C06 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, 30 Aug 2017 13:07:02 -0500 Message-Id: <20170830180711.7974-3-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.26]); Wed, 30 Aug 2017 18:07:21 +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 02/11] nbd-client: avoid read_reply_co entry if send failed 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..." , Stefan Hajnoczi , 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: Stefan Hajnoczi The following segfault is encountered if the NBD server closes the UNIX domain socket immediately after negotiation: Program terminated with signal SIGSEGV, Segmentation fault. #0 aio_co_schedule (ctx=3D0x0, co=3D0xd3c0ff2ef0) at util/async.c:441 441 QSLIST_INSERT_HEAD_ATOMIC(&ctx->scheduled_coroutines, (gdb) bt #0 0x000000d3c01a50f8 in aio_co_schedule (ctx=3D0x0, co=3D0xd3c0ff2ef0) = at util/async.c:441 #1 0x000000d3c012fa90 in nbd_coroutine_end (bs=3Dbs@entry=3D0xd3c0fec650= , request=3D) at block/nbd-client.c:207 #2 0x000000d3c012fb58 in nbd_client_co_preadv (bs=3D0xd3c0fec650, offset= =3D0, bytes=3D, qiov=3D0x7ffc10a91b20, flags=3D0) at block/n= bd-client.c:237 #3 0x000000d3c0128e63 in bdrv_driver_preadv (bs=3Dbs@entry=3D0xd3c0fec65= 0, offset=3Doffset@entry=3D0, bytes=3Dbytes@entry=3D512, qiov=3Dqiov@entry= =3D0x7ffc10a91b20, flags=3D0) at block/io.c:836 #4 0x000000d3c012c3e0 in bdrv_aligned_preadv (child=3Dchild@entry=3D0xd3= c0ff51d0, req=3Dreq@entry=3D0x7f31885d6e90, offset=3Doffset@entry=3D0, byte= s=3Dbytes@entry=3D512, align=3Dalign@entry=3D1, qiov=3Dqiov@entry=3D0x7ffc1= 0a91b20, f +lags=3D0) at block/io.c:1086 #5 0x000000d3c012c6b8 in bdrv_co_preadv (child=3D0xd3c0ff51d0, offset=3D= offset@entry=3D0, bytes=3Dbytes@entry=3D512, qiov=3Dqiov@entry=3D0x7ffc10a9= 1b20, flags=3Dflags@entry=3D0) at block/io.c:1182 #6 0x000000d3c011cc17 in blk_co_preadv (blk=3D0xd3c0ff4f80, offset=3D0, = bytes=3D512, qiov=3D0x7ffc10a91b20, flags=3D0) at block/block-backend.c:1032 #7 0x000000d3c011ccec in blk_read_entry (opaque=3D0x7ffc10a91b40) at blo= ck/block-backend.c:1079 #8 0x000000d3c01bbb96 in coroutine_trampoline (i0=3D, i1= =3D) at util/coroutine-ucontext.c:79 #9 0x00007f3196cb8600 in __start_context () at /lib64/libc.so.6 The problem is that nbd_client_init() uses nbd_client_attach_aio_context() -> aio_co_schedule(new_context, client->read_reply_co). Execution of read_reply_co is deferred to a BH which doesn't run until later. In the mean time blk_co_preadv() can be called and nbd_coroutine_end() calls aio_wake() on read_reply_co. At this point in time read_reply_co's ctx isn't set because it has never been entered yet. This patch simplifies the nbd_co_send_request() -> nbd_co_receive_reply() -> nbd_coroutine_end() lifecycle to just nbd_co_send_request() -> nbd_co_receive_reply(). The request is "ended" if an error occurs at any point. Callers no longer have to invoke nbd_coroutine_end(). This cleanup also eliminates the segfault because we don't call aio_co_schedule() to wake up s->read_reply_co if sending the request failed. It is only necessary to wake up s->read_reply_co if a reply was received. Note this only happens with UNIX domain sockets on Linux. It doesn't seem possible to reproduce this with TCP sockets. Suggested-by: Paolo Bonzini Signed-off-by: Stefan Hajnoczi Message-Id: <20170829122745.14309-2-stefanha@redhat.com> Signed-off-by: Eric Blake --- block/nbd-client.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 25bcaa2346..ea728fffc8 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -144,12 +144,12 @@ static int nbd_co_send_request(BlockDriverState *bs, request->handle =3D INDEX_TO_HANDLE(s, i); if (s->quit) { - qemu_co_mutex_unlock(&s->send_mutex); - return -EIO; + rc =3D -EIO; + goto err; } if (!s->ioc) { - qemu_co_mutex_unlock(&s->send_mutex); - return -EPIPE; + rc =3D -EPIPE; + goto err; } if (qiov) { @@ -166,8 +166,13 @@ static int nbd_co_send_request(BlockDriverState *bs, } else { rc =3D nbd_send_request(s->ioc, request); } + +err: if (rc < 0) { s->quit =3D true; + s->requests[i].coroutine =3D NULL; + s->in_flight--; + qemu_co_queue_next(&s->free_sema); } qemu_co_mutex_unlock(&s->send_mutex); return rc; @@ -201,13 +206,6 @@ static void nbd_co_receive_reply(NBDClientSession *s, /* Tell the read handler to read another header. */ s->reply.handle =3D 0; } -} - -static void nbd_coroutine_end(BlockDriverState *bs, - NBDRequest *request) -{ - NBDClientSession *s =3D nbd_get_client_session(bs); - int i =3D HANDLE_TO_INDEX(s, request->handle); s->requests[i].coroutine =3D NULL; @@ -243,7 +241,6 @@ int nbd_client_co_preadv(BlockDriverState *bs, uint64_t= offset, } else { nbd_co_receive_reply(client, &request, &reply, qiov); } - nbd_coroutine_end(bs, &request); return -reply.error; } @@ -272,7 +269,6 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_= t offset, } else { nbd_co_receive_reply(client, &request, &reply, NULL); } - nbd_coroutine_end(bs, &request); return -reply.error; } @@ -306,7 +302,6 @@ int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, i= nt64_t offset, } else { nbd_co_receive_reply(client, &request, &reply, NULL); } - nbd_coroutine_end(bs, &request); return -reply.error; } @@ -330,7 +325,6 @@ int nbd_client_co_flush(BlockDriverState *bs) } else { nbd_co_receive_reply(client, &request, &reply, NULL); } - nbd_coroutine_end(bs, &request); return -reply.error; } @@ -355,7 +349,6 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int64_= t offset, int bytes) } else { nbd_co_receive_reply(client, &request, &reply, NULL); } - nbd_coroutine_end(bs, &request); return -reply.error; } --=20 2.13.5 From nobody Sun Oct 5 17:23:31 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 1504116742047173.96126603911932; Wed, 30 Aug 2017 11:12:22 -0700 (PDT) Received: from localhost ([::1]:52064 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7TP-0006Ip-RX for importer@patchew.org; Wed, 30 Aug 2017 14:12:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7Og-0001qX-Bv for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dn7Of-0001aM-IT for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44935) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dn7Od-0001ZF-7Q; Wed, 30 Aug 2017 14:07: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 4EB99C0587E5; Wed, 30 Aug 2017 18:07:22 +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 2FD91173A6; Wed, 30 Aug 2017 18:07:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4EB99C0587E5 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.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:03 -0500 Message-Id: <20170830180711.7974-4-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.32]); Wed, 30 Aug 2017 18:07: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 03/11] qemu-iotests: improve nbd-fault-injector.py startup protocol 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" , Stefan Hajnoczi , 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: Stefan Hajnoczi Currently 083 waits for the nbd-fault-injector.py server to start up by looping until netstat shows the TCP listen socket. The startup protocol can be simplified by passing a 0 port number to nbd-fault-injector.py. The kernel will allocate a port in bind(2) and the final port number can be printed by nbd-fault-injector.py. This should make it slightly nicer and less TCP-specific to wait for server startup. This patch changes nbd-fault-injector.py, the next one will rewrite server startup in 083. Reviewed-by: Eric Blake Signed-off-by: Stefan Hajnoczi Message-Id: <20170829122745.14309-3-stefanha@redhat.com> Signed-off-by: Eric Blake --- tests/qemu-iotests/nbd-fault-injector.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/qemu-iotests/nbd-fault-injector.py b/tests/qemu-iotests/= nbd-fault-injector.py index 6c07191a5a..1c10dcb51c 100755 --- a/tests/qemu-iotests/nbd-fault-injector.py +++ b/tests/qemu-iotests/nbd-fault-injector.py @@ -235,11 +235,15 @@ def open_socket(path): sock =3D socket.socket() sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind((host, int(port))) + + # If given port was 0 the final port number is now available + path =3D '%s:%d' % sock.getsockname() else: sock =3D socket.socket(socket.AF_UNIX) sock.bind(path) sock.listen(0) print 'Listening on %s' % path + sys.stdout.flush() # another process may be waiting, show message now return sock def usage(args): --=20 2.13.5 From nobody Sun Oct 5 17:23:31 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 150411688594760.2185370189585; Wed, 30 Aug 2017 11:14:45 -0700 (PDT) Received: from localhost ([::1]:52075 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7Vj-0008N8-Gn for importer@patchew.org; Wed, 30 Aug 2017 14:14:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53130) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7Ol-0001wF-Op 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 1dn7Oj-0001bw-O2 for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44108) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dn7Oe-0001Zj-AG; Wed, 30 Aug 2017 14:07: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 63A22C0587E8; Wed, 30 Aug 2017 18:07:23 +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 8803E17106; Wed, 30 Aug 2017 18:07:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 63A22C0587E8 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.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:04 -0500 Message-Id: <20170830180711.7974-5-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.32]); Wed, 30 Aug 2017 18:07: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 04/11] qemu-iotests: test NBD over UNIX domain sockets in 083 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" , Stefan Hajnoczi , 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: Stefan Hajnoczi 083 only tests TCP. Some failures might be specific to UNIX domain sockets. A few adjustments are necessary: 1. Generating a port number and waiting for server startup is TCP-specific. Use the new nbd-fault-injector.py startup protocol to fetch the address. This is a little more elegant because we don't need netstat anymore. 2. The NBD filter does not work for the UNIX domain sockets URIs we generate and must be extended. 3. Run all tests twice: once for TCP and once for UNIX domain sockets. Reviewed-by: Eric Blake Signed-off-by: Stefan Hajnoczi Message-Id: <20170829122745.14309-4-stefanha@redhat.com> Signed-off-by: Eric Blake --- tests/qemu-iotests/common.filter | 4 +- tests/qemu-iotests/083 | 138 +++++++++++++++++++++++------------= -- tests/qemu-iotests/083.out | 145 ++++++++++++++++++++++++++++++++++-= ---- 3 files changed, 215 insertions(+), 72 deletions(-) diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.f= ilter index 7a58e57317..9d5442ecd9 100644 --- a/tests/qemu-iotests/common.filter +++ b/tests/qemu-iotests/common.filter @@ -170,9 +170,9 @@ _filter_nbd() # # Filter out the TCP port number since this changes between runs. sed -e '/nbd\/.*\.c:/d' \ - -e 's#nbd:\(//\)\?127\.0\.0\.1:[0-9]*#nbd:\1127.0.0.1:PORT#g' \ + -e 's#127\.0\.0\.1:[0-9]*#127.0.0.1:PORT#g' \ -e "s#?socket=3D$TEST_DIR#?socket=3DTEST_DIR#g" \ - -e 's#\(exportname=3Dfoo\|PORT\): Failed to .*$#\1#' + -e 's#\(foo\|PORT/\?\|.sock\): Failed to .*$#\1#' } # make sure this script returns success diff --git a/tests/qemu-iotests/083 b/tests/qemu-iotests/083 index bff9360048..0306f112da 100755 --- a/tests/qemu-iotests/083 +++ b/tests/qemu-iotests/083 @@ -27,6 +27,14 @@ echo "QA output created by $seq" here=3D`pwd` status=3D1 # failure is the default! +_cleanup() +{ + rm -f nbd.sock + rm -f nbd-fault-injector.out + rm -f nbd-fault-injector.conf +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + # get standard environment, filters and checks . ./common.rc . ./common.filter @@ -35,81 +43,105 @@ _supported_fmt generic _supported_proto nbd _supported_os Linux -# Pick a TCP port based on our pid. This way multiple instances of this t= est -# can run in parallel without conflicting. -choose_tcp_port() { - echo $((($$ % 31744) + 1024)) # 1024 <=3D port < 32768 -} - -wait_for_tcp_port() { - while ! (netstat --tcp --listening --numeric | \ - grep "$1.*0\\.0\\.0\\.0:\\*.*LISTEN") >/dev/null 2>&1; do - sleep 0.1 - done -} - check_disconnect() { + local event export_name=3Dfoo extra_args nbd_addr nbd_url proto when + + while true; do + case $1 in + --classic-negotiation) + shift + extra_args=3D--classic-negotiation + export_name=3D + ;; + --tcp) + shift + proto=3Dtcp + ;; + --unix) + shift + proto=3Dunix + ;; + *) + break + ;; + esac + done + event=3D$1 when=3D$2 - negotiation=3D$3 echo "=3D=3D=3D Check disconnect $when $event =3D=3D=3D" echo - port=3D$(choose_tcp_port) - cat > "$TEST_DIR/nbd-fault-injector.conf" <"$TEST_DIR/nbd-fault-injector.out" 2>&1 & + + # Wait for server to be ready + while ! grep -q 'Listening on ' "$TEST_DIR/nbd-fault-injector.out"; do + sleep 0.1 + done + + # Extract the final address (port number has now been assigned in tcp cas= e) + nbd_addr=3D$(sed 's/Listening on \(.*\)$/\1/' "$TEST_DIR/nbd-fault-inject= or.out") + + if [ "$proto" =3D "tcp" ]; then + nbd_url=3D"nbd+tcp://$nbd_addr/$export_name" + else + nbd_url=3D"nbd+unix:///$export_name?socket=3D$nbd_addr" fi - $PYTHON nbd-fault-injector.py $extra_args "127.0.0.1:$port" "$TEST_DIR/nb= d-fault-injector.conf" >/dev/null 2>&1 & - wait_for_tcp_port "127\\.0\\.0\\.1:$port" $QEMU_IO -c "read 0 512" "$nbd_url" 2>&1 | _filter_qemu_io | _filter_nbd echo } -for event in neg1 "export" neg2 request reply data; do - for when in before after; do - check_disconnect "$event" "$when" - done - - # Also inject short replies from the NBD server - case "$event" in - neg1) - for when in 8 16; do - check_disconnect "$event" "$when" - done - ;; - "export") - for when in 4 12 16; do - check_disconnect "$event" "$when" - done - ;; - neg2) - for when in 8 10; do - check_disconnect "$event" "$when" +for proto in tcp unix; do + for event in neg1 "export" neg2 request reply data; do + for when in before after; do + check_disconnect "--$proto" "$event" "$when" done - ;; - reply) - for when in 4 8; do - check_disconnect "$event" "$when" - done - ;; - esac -done -# Also check classic negotiation without export information -for when in before 8 16 24 28 after; do - check_disconnect "neg-classic" "$when" --classic-negotiation + # Also inject short replies from the NBD server + case "$event" in + neg1) + for when in 8 16; do + check_disconnect "--$proto" "$event" "$when" + done + ;; + "export") + for when in 4 12 16; do + check_disconnect "--$proto" "$event" "$when" + done + ;; + neg2) + for when in 8 10; do + check_disconnect "--$proto" "$event" "$when" + done + ;; + reply) + for when in 4 8; do + check_disconnect "--$proto" "$event" "$when" + done + ;; + esac + done + + # Also check classic negotiation without export information + for when in before 8 16 24 28 after; do + check_disconnect "--$proto" --classic-negotiation "neg-classic" "$when" + done done # success, all done diff --git a/tests/qemu-iotests/083.out b/tests/qemu-iotests/083.out index a24c6bfece..a7fb081889 100644 --- a/tests/qemu-iotests/083.out +++ b/tests/qemu-iotests/083.out @@ -1,43 +1,43 @@ QA output created by 083 =3D=3D=3D Check disconnect before neg1 =3D=3D=3D -can't open device nbd:127.0.0.1:PORT:exportname=3Dfoo +can't open device nbd+tcp://127.0.0.1:PORT/foo =3D=3D=3D Check disconnect after neg1 =3D=3D=3D -can't open device nbd:127.0.0.1:PORT:exportname=3Dfoo +can't open device nbd+tcp://127.0.0.1:PORT/foo =3D=3D=3D Check disconnect 8 neg1 =3D=3D=3D -can't open device nbd:127.0.0.1:PORT:exportname=3Dfoo +can't open device nbd+tcp://127.0.0.1:PORT/foo =3D=3D=3D Check disconnect 16 neg1 =3D=3D=3D -can't open device nbd:127.0.0.1:PORT:exportname=3Dfoo +can't open device nbd+tcp://127.0.0.1:PORT/foo =3D=3D=3D Check disconnect before export =3D=3D=3D -can't open device nbd:127.0.0.1:PORT:exportname=3Dfoo +can't open device nbd+tcp://127.0.0.1:PORT/foo =3D=3D=3D Check disconnect after export =3D=3D=3D -can't open device nbd:127.0.0.1:PORT:exportname=3Dfoo +can't open device nbd+tcp://127.0.0.1:PORT/foo =3D=3D=3D Check disconnect 4 export =3D=3D=3D -can't open device nbd:127.0.0.1:PORT:exportname=3Dfoo +can't open device nbd+tcp://127.0.0.1:PORT/foo =3D=3D=3D Check disconnect 12 export =3D=3D=3D -can't open device nbd:127.0.0.1:PORT:exportname=3Dfoo +can't open device nbd+tcp://127.0.0.1:PORT/foo =3D=3D=3D Check disconnect 16 export =3D=3D=3D -can't open device nbd:127.0.0.1:PORT:exportname=3Dfoo +can't open device nbd+tcp://127.0.0.1:PORT/foo =3D=3D=3D Check disconnect before neg2 =3D=3D=3D -can't open device nbd:127.0.0.1:PORT:exportname=3Dfoo +can't open device nbd+tcp://127.0.0.1:PORT/foo =3D=3D=3D Check disconnect after neg2 =3D=3D=3D @@ -45,11 +45,11 @@ read failed: Input/output error =3D=3D=3D Check disconnect 8 neg2 =3D=3D=3D -can't open device nbd:127.0.0.1:PORT:exportname=3Dfoo +can't open device nbd+tcp://127.0.0.1:PORT/foo =3D=3D=3D Check disconnect 10 neg2 =3D=3D=3D -can't open device nbd:127.0.0.1:PORT:exportname=3Dfoo +can't open device nbd+tcp://127.0.0.1:PORT/foo =3D=3D=3D Check disconnect before request =3D=3D=3D @@ -88,23 +88,134 @@ read 512/512 bytes at offset 0 =3D=3D=3D Check disconnect before neg-classic =3D=3D=3D -can't open device nbd:127.0.0.1:PORT +can't open device nbd+tcp://127.0.0.1:PORT/ =3D=3D=3D Check disconnect 8 neg-classic =3D=3D=3D -can't open device nbd:127.0.0.1:PORT +can't open device nbd+tcp://127.0.0.1:PORT/ =3D=3D=3D Check disconnect 16 neg-classic =3D=3D=3D -can't open device nbd:127.0.0.1:PORT +can't open device nbd+tcp://127.0.0.1:PORT/ =3D=3D=3D Check disconnect 24 neg-classic =3D=3D=3D -can't open device nbd:127.0.0.1:PORT +can't open device nbd+tcp://127.0.0.1:PORT/ =3D=3D=3D Check disconnect 28 neg-classic =3D=3D=3D -can't open device nbd:127.0.0.1:PORT +can't open device nbd+tcp://127.0.0.1:PORT/ + +=3D=3D=3D Check disconnect after neg-classic =3D=3D=3D + +read failed: Input/output error + +=3D=3D=3D Check disconnect before neg1 =3D=3D=3D + +can't open device nbd+unix:///foo?socket=3DTEST_DIR/nbd.sock + +=3D=3D=3D Check disconnect after neg1 =3D=3D=3D + +can't open device nbd+unix:///foo?socket=3DTEST_DIR/nbd.sock + +=3D=3D=3D Check disconnect 8 neg1 =3D=3D=3D + +can't open device nbd+unix:///foo?socket=3DTEST_DIR/nbd.sock + +=3D=3D=3D Check disconnect 16 neg1 =3D=3D=3D + +can't open device nbd+unix:///foo?socket=3DTEST_DIR/nbd.sock + +=3D=3D=3D Check disconnect before export =3D=3D=3D + +can't open device nbd+unix:///foo?socket=3DTEST_DIR/nbd.sock + +=3D=3D=3D Check disconnect after export =3D=3D=3D + +can't open device nbd+unix:///foo?socket=3DTEST_DIR/nbd.sock + +=3D=3D=3D Check disconnect 4 export =3D=3D=3D + +can't open device nbd+unix:///foo?socket=3DTEST_DIR/nbd.sock + +=3D=3D=3D Check disconnect 12 export =3D=3D=3D + +can't open device nbd+unix:///foo?socket=3DTEST_DIR/nbd.sock + +=3D=3D=3D Check disconnect 16 export =3D=3D=3D + +can't open device nbd+unix:///foo?socket=3DTEST_DIR/nbd.sock + +=3D=3D=3D Check disconnect before neg2 =3D=3D=3D + +can't open device nbd+unix:///foo?socket=3DTEST_DIR/nbd.sock + +=3D=3D=3D Check disconnect after neg2 =3D=3D=3D + +read failed: Input/output error + +=3D=3D=3D Check disconnect 8 neg2 =3D=3D=3D + +can't open device nbd+unix:///foo?socket=3DTEST_DIR/nbd.sock + +=3D=3D=3D Check disconnect 10 neg2 =3D=3D=3D + +can't open device nbd+unix:///foo?socket=3DTEST_DIR/nbd.sock + +=3D=3D=3D Check disconnect before request =3D=3D=3D + +read failed: Input/output error + +=3D=3D=3D Check disconnect after request =3D=3D=3D + +read failed: Input/output error + +=3D=3D=3D Check disconnect before reply =3D=3D=3D + +read failed: Input/output error + +=3D=3D=3D Check disconnect after reply =3D=3D=3D + +read failed: Input/output error + +=3D=3D=3D Check disconnect 4 reply =3D=3D=3D + +read failed +read failed: Input/output error + +=3D=3D=3D Check disconnect 8 reply =3D=3D=3D + +read failed +read failed: Input/output error + +=3D=3D=3D Check disconnect before data =3D=3D=3D + +read failed: Input/output error + +=3D=3D=3D Check disconnect after data =3D=3D=3D + +read 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=3D=3D=3D Check disconnect before neg-classic =3D=3D=3D + +can't open device nbd+unix:///?socket=3DTEST_DIR/nbd.sock + +=3D=3D=3D Check disconnect 8 neg-classic =3D=3D=3D + +can't open device nbd+unix:///?socket=3DTEST_DIR/nbd.sock + +=3D=3D=3D Check disconnect 16 neg-classic =3D=3D=3D + +can't open device nbd+unix:///?socket=3DTEST_DIR/nbd.sock + +=3D=3D=3D Check disconnect 24 neg-classic =3D=3D=3D + +can't open device nbd+unix:///?socket=3DTEST_DIR/nbd.sock + +=3D=3D=3D Check disconnect 28 neg-classic =3D=3D=3D + +can't open device nbd+unix:///?socket=3DTEST_DIR/nbd.sock =3D=3D=3D Check disconnect after neg-classic =3D=3D=3D --=20 2.13.5 From nobody Sun Oct 5 17:23:31 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 1504116579829251.5183476725132; Wed, 30 Aug 2017 11:09:39 -0700 (PDT) Received: from localhost ([::1]:52046 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7Qn-0003IN-Mi for importer@patchew.org; Wed, 30 Aug 2017 14:09:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53129) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7Ol-0001wE-Ol for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dn7Ok-0001cO-R0 for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56400) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dn7Of-0001a4-9Z; Wed, 30 Aug 2017 14:07: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 51B6B5F7B4; Wed, 30 Aug 2017 18:07:24 +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 9865017106; Wed, 30 Aug 2017 18:07:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 51B6B5F7B4 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: Wed, 30 Aug 2017 13:07:05 -0500 Message-Id: <20170830180711.7974-6-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.39]); Wed, 30 Aug 2017 18:07: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 05/11] nbd/client: fix nbd_opt_go 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: Paolo Bonzini , Vladimir Sementsov-Ogievskiy , "open list:Network Block Dev..." 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 Do not send NBD_OPT_ABORT to the broken server. After sending NBD_REP_ACK on NBD_OPT_GO server is most probably in transmission phase, when option sending is finished. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20170804151440.320927-2-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- nbd/client.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index 0a17de80b5..f1c16b588f 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -399,12 +399,10 @@ static int nbd_opt_go(QIOChannel *ioc, const char *wa= ntname, phase, but make sure it sent flags */ if (len) { error_setg(errp, "server sent invalid NBD_REP_ACK"); - nbd_send_opt_abort(ioc); return -1; } if (!info->flags) { error_setg(errp, "broken server omitted NBD_INFO_EXPORT"); - nbd_send_opt_abort(ioc); return -1; } trace_nbd_opt_go_success(); --=20 2.13.5 From nobody Sun Oct 5 17:23:31 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 From nobody Sun Oct 5 17:23:31 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 1504116997568989.7321157092688; Wed, 30 Aug 2017 11:16:37 -0700 (PDT) Received: from localhost ([::1]:52088 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7XX-000246-Ia for importer@patchew.org; Wed, 30 Aug 2017 14:16:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53235) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7Ou-00025r-Ie for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dn7Op-0001ea-LT for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58320) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dn7Oi-0001bO-5Z; Wed, 30 Aug 2017 14:07:28 -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 390764A6F1; Wed, 30 Aug 2017 18:07:27 +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 DAB7E17106; Wed, 30 Aug 2017 18:07:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 390764A6F1 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: Wed, 30 Aug 2017 13:07:07 -0500 Message-Id: <20170830180711.7974-8-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.38]); Wed, 30 Aug 2017 18:07:27 +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 07/11] nbd/client: refactor nbd_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: 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_receive_reply 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-4-vsementsov@virtuozzo.com> [eblake: tweak function comments] Signed-off-by: Eric Blake --- include/block/nbd.h | 2 +- nbd/client.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 9c3d0a5868..f7450608b4 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -164,7 +164,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, int nbd_init(int fd, QIOChannelSocket *sioc, NBDExportInfo *info, Error **errp); ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *request); -ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp); +int nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp); int nbd_client(int fd); int nbd_disconnect(int fd); diff --git a/nbd/client.c b/nbd/client.c index 4556056daa..f8c213bc96 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -914,11 +914,16 @@ ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest = *request) return nbd_write(ioc, buf, sizeof(buf), NULL); } -ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp) +/* nbd_receive_reply + * Returns 1 on success + * 0 on eof, when no data was read (errp is not set) + * negative errno on failure (errp is set) + */ +int nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp) { uint8_t buf[NBD_REPLY_SIZE]; uint32_t magic; - ssize_t ret; + int ret; ret =3D nbd_read_eof(ioc, buf, sizeof(buf), errp); if (ret <=3D 0) { @@ -948,6 +953,7 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *re= ply, Error **errp) error_setg(errp, "invalid magic (got 0x%" PRIx32 ")", magic); return -EINVAL; } - return sizeof(buf); + + return 1; } --=20 2.13.5 From nobody Sun Oct 5 17:23:31 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 1504116855942669.3951673817412; Wed, 30 Aug 2017 11:14:15 -0700 (PDT) Received: from localhost ([::1]:52072 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7VG-0007y4-4C for importer@patchew.org; Wed, 30 Aug 2017 14:14:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7Om-0001xL-Mp 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-0001ch-Nh for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56552) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dn7Oj-0001be-Kl; Wed, 30 Aug 2017 14:07:29 -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 B4FCC5F7AD; Wed, 30 Aug 2017 18:07:28 +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 72E0C17106; Wed, 30 Aug 2017 18:07:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B4FCC5F7AD 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: Wed, 30 Aug 2017 13:07:08 -0500 Message-Id: <20170830180711.7974-9-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.39]); Wed, 30 Aug 2017 18:07:28 +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 08/11] nbd/client: fix nbd_send_request to return int 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 Fix nbd_send_request to return int, as it returns a return value of nbd_write (which is int), and the only user of nbd_send_request's return value (nbd_co_send_request) consider it as int too. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20170804151440.320927-5-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- include/block/nbd.h | 2 +- nbd/client.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index f7450608b4..040cdd2e60 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -163,7 +163,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *= name, Error **errp); int nbd_init(int fd, QIOChannelSocket *sioc, NBDExportInfo *info, Error **errp); -ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *request); +int nbd_send_request(QIOChannel *ioc, NBDRequest *request); int nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp); int nbd_client(int fd); int nbd_disconnect(int fd); diff --git a/nbd/client.c b/nbd/client.c index f8c213bc96..68a0bc1ffc 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -896,7 +896,7 @@ int nbd_disconnect(int fd) } #endif -ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *request) +int nbd_send_request(QIOChannel *ioc, NBDRequest *request) { uint8_t buf[NBD_REQUEST_SIZE]; --=20 2.13.5 From nobody Sun Oct 5 17:23:31 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 15041167401011023.7302455489145; Wed, 30 Aug 2017 11:12:20 -0700 (PDT) Received: from localhost ([::1]:52063 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7TN-0006G5-Qp for importer@patchew.org; Wed, 30 Aug 2017 14:12:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53195) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7Op-0001ze-4p for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dn7Oo-0001e2-A5 for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52730) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dn7Ol-0001cZ-V5; Wed, 30 Aug 2017 14:07:32 -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 1028081DFE; Wed, 30 Aug 2017 18:07:31 +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 EE39717106; Wed, 30 Aug 2017 18:07:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1028081DFE Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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:09 -0500 Message-Id: <20170830180711.7974-10-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.25]); Wed, 30 Aug 2017 18:07:31 +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 09/11] block/nbd-client: get rid of ssize_t 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 Use int variable for nbd_co_send_request return value (as nbd_co_send_request returns int). Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20170804151440.320927-6-vsementsov@virtuozzo.com> Signed-off-by: Eric Blake --- block/nbd-client.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index ea728fffc8..1e393cf26f 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -230,7 +230,7 @@ int nbd_client_co_preadv(BlockDriverState *bs, uint64_t= offset, .len =3D bytes, }; NBDReply reply; - ssize_t ret; + int ret; assert(bytes <=3D NBD_MAX_BUFFER_SIZE); assert(!flags); @@ -254,7 +254,7 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_= t offset, .len =3D bytes, }; NBDReply reply; - ssize_t ret; + int ret; if (flags & BDRV_REQ_FUA) { assert(client->info.flags & NBD_FLAG_SEND_FUA); @@ -275,7 +275,7 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_= t offset, int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags) { - ssize_t ret; + int ret; NBDClientSession *client =3D nbd_get_client_session(bs); NBDRequest request =3D { .type =3D NBD_CMD_WRITE_ZEROES, @@ -310,7 +310,7 @@ 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; - ssize_t ret; + int ret; if (!(client->info.flags & NBD_FLAG_SEND_FLUSH)) { return 0; @@ -337,7 +337,7 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int64_= t offset, int bytes) .len =3D bytes, }; NBDReply reply; - ssize_t ret; + int ret; if (!(client->info.flags & NBD_FLAG_SEND_TRIM)) { return 0; --=20 2.13.5 From nobody Sun Oct 5 17:23:31 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 15041168699711012.5239593302801; Wed, 30 Aug 2017 11:14:29 -0700 (PDT) Received: from localhost ([::1]:52073 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7VT-00089U-QZ for importer@patchew.org; Wed, 30 Aug 2017 14:14:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7Ou-00025h-CR for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dn7Op-0001eU-Fy for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52766) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dn7On-0001dS-Ag; Wed, 30 Aug 2017 14:07:33 -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 5C05B81DFD; Wed, 30 Aug 2017 18:07:32 +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 47B7B17106; Wed, 30 Aug 2017 18:07:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5C05B81DFD Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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:10 -0500 Message-Id: <20170830180711.7974-11-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.25]); Wed, 30 Aug 2017 18:07:32 +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 10/11] block/nbd-client: rename nbd_recv_coroutines_enter_all 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 Rename nbd_recv_coroutines_enter_all to nbd_recv_coroutines_wake_all, as it most probably just adds all recv coroutines into co_queue_wakeup, rather than directly enter them. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20170804151440.320927-9-vsementsov@virtuozzo.com> [eblake: tweak commit message] Signed-off-by: Eric Blake --- block/nbd-client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 1e393cf26f..322b725ff9 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -34,7 +34,7 @@ #define HANDLE_TO_INDEX(bs, handle) ((handle) ^ ((uint64_t)(intptr_t)bs)) #define INDEX_TO_HANDLE(bs, index) ((index) ^ ((uint64_t)(intptr_t)bs)) -static void nbd_recv_coroutines_enter_all(NBDClientSession *s) +static void nbd_recv_coroutines_wake_all(NBDClientSession *s) { int i; @@ -112,7 +112,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opa= que) } s->quit =3D true; - nbd_recv_coroutines_enter_all(s); + nbd_recv_coroutines_wake_all(s); s->read_reply_co =3D NULL; } --=20 2.13.5 From nobody Sun Oct 5 17:23:31 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 1504116736727619.2067379375762; Wed, 30 Aug 2017 11:12:16 -0700 (PDT) Received: from localhost ([::1]:52062 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7TJ-0006BG-B4 for importer@patchew.org; Wed, 30 Aug 2017 14:12:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53277) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dn7Oy-00029P-73 for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dn7Ou-0001fm-VK for qemu-devel@nongnu.org; Wed, 30 Aug 2017 14:07:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58848) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dn7Oo-0001dw-GV; Wed, 30 Aug 2017 14:07:34 -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 902E47EA93; Wed, 30 Aug 2017 18:07:33 +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 956A217106; Wed, 30 Aug 2017 18:07:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 902E47EA93 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.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:11 -0500 Message-Id: <20170830180711.7974-12-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.28]); Wed, 30 Aug 2017 18:07:33 +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 11/11] 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: 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 Add nbd_co_request, to remove code duplications in nbd_client_co_{pwrite,pread,...} functions. Also this is needed for further refactoring. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20170804151440.320927-8-vsementsov@virtuozzo.com> [eblake: make nbd_co_request a wrapper, rather than merging two existing functions] Signed-off-by: Eric Blake --- block/nbd-client.c | 73 +++++++++++++++++++-------------------------------= ---- 1 file changed, 26 insertions(+), 47 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 322b725ff9..f0dbea24d3 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -220,28 +220,40 @@ static void nbd_co_receive_reply(NBDClientSession *s, qemu_co_mutex_unlock(&s->send_mutex); } +static int nbd_co_request(BlockDriverState *bs, + NBDRequest *request, + QEMUIOVector *qiov) +{ + NBDClientSession *client =3D nbd_get_client_session(bs); + NBDReply reply; + int ret; + + 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); + 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 -reply.error; +} + 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; assert(bytes <=3D NBD_MAX_BUFFER_SIZE); assert(!flags); - 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); - } - return -reply.error; + return nbd_co_request(bs, &request, qiov); } int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset, @@ -253,8 +265,6 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_= t offset, .from =3D offset, .len =3D bytes, }; - NBDReply reply; - int ret; if (flags & BDRV_REQ_FUA) { assert(client->info.flags & NBD_FLAG_SEND_FUA); @@ -263,26 +273,18 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint6= 4_t offset, assert(bytes <=3D NBD_MAX_BUFFER_SIZE); - 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); - } - return -reply.error; + return nbd_co_request(bs, &request, qiov); } 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; if (!(client->info.flags & NBD_FLAG_SEND_WRITE_ZEROES)) { return -ENOTSUP; @@ -296,21 +298,13 @@ int nbd_client_co_pwrite_zeroes(BlockDriverState *bs,= int64_t offset, request.flags |=3D NBD_CMD_FLAG_NO_HOLE; } - 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); - } - return -reply.error; + return nbd_co_request(bs, &request, NULL); } 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; if (!(client->info.flags & NBD_FLAG_SEND_FLUSH)) { return 0; @@ -319,13 +313,7 @@ int nbd_client_co_flush(BlockDriverState *bs) request.from =3D 0; request.len =3D 0; - 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); - } - return -reply.error; + return nbd_co_request(bs, &request, NULL); } int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) @@ -336,21 +324,12 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int6= 4_t offset, int bytes) .from =3D offset, .len =3D bytes, }; - NBDReply reply; - int ret; if (!(client->info.flags & NBD_FLAG_SEND_TRIM)) { return 0; } - 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); - } - return -reply.error; - + return nbd_co_request(bs, &request, NULL); } void nbd_client_detach_aio_context(BlockDriverState *bs) --=20 2.13.5