NBD changes for 2.10-rc3
The following changes since commit 47025a0193f1f910300adfa443305ccf8482ef87:
qxl: call qemu_spice_display_init_common for secondary devices (2017-08-15 15:04:51 +0100)
are available in the git repository at:
git://repo.or.cz/qemu/ericb.git tags/pull-nbd-2017-08-15
for you to fetch changes up to 72b6ffc76653214b69a94a7b1643ff80df134486:
nbd-client: Fix regression when server sends garbage (2017-08-15 10:03:28 -0500)
----------------------------------------------------------------
nbd patches for 2017-08-15
- Eric Blake: nbd: Fix trace message for disconnect
- Stefan Hajnoczi: qemu-iotests: step clock after each test iteration
- Fam Zheng: 0/4 block: Fix non-shared storage migration
- Eric Blake: nbd-client: Fix regression when server sends garbage
----------------------------------------------------------------
Eric Blake (2):
nbd: Fix trace message for disconnect
nbd-client: Fix regression when server sends garbage
Fam Zheng (3):
stubs: Add vm state change handler stubs
block-backend: Defer shared_perm tightening migration completion
iotests: Add non-shared storage migration case 192
Kevin Wolf (1):
nbd: Fix order of bdrv_set_perm and bdrv_invalidate_cache
Stefan Hajnoczi (1):
qemu-iotests: step clock after each test iteration
block/nbd-client.h | 1 + block/block-backend.c | 41 ++++++++++++++++++++++++++++ block/nbd-client.c | 17 +++++++++--- nbd/common.c | 2 +- nbd/server.c | 20 +++++++------- stubs/change-state-handler.c | 14 ++++++++++ stubs/Makefile.objs | 1 + tests/qemu-iotests/093 | 4 +++ tests/qemu-iotests/192 | 63 ++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/192.out | 7 +++++ tests/qemu-iotests/group | 1 + 11 files changed, 157 insertions(+), 14 deletions(-) create mode 100644 stubs/change-state-handler.c create mode 100755 tests/qemu-iotests/192 create mode 100644 tests/qemu-iotests/192.out
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 1/7] nbd: Fix trace message for disconnect
NBD_CMD_DISC is a disconnect request, not a data discard request.
Message-Id: <[email protected]>
--- nbd/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
nbd/common.c +1 -1
@@ -182,7 +182,7 @@ const char *nbd_cmd_lookup(uint16_t cmd)case NBD_CMD_WRITE :return "write" ;case NBD_CMD_DISC : -return "discard" ; +return "disconnect" ;case NBD_CMD_FLUSH :return "flush" ;case NBD_CMD_TRIM :
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 2/7] qemu-iotests: step clock after each test iteration
In reply to Eric BlakeFrom: Stefan Hajnoczi <[email protected]>
The 093 throttling test submits twice as many requests as the throttle limit in order to ensure that we reach the limit. The remaining requests are left in-flight at the end of each test iteration.
Commit 452589b6b47e8dc6353df257fc803dfc1383bed8 ("vl.c/exit: pause cpus before closing block devices") exposed a hang in 093. This happens because requests are still in flight when QEMU terminates but QEMU_CLOCK_VIRTUAL time is frozen. bdrv_drain_all() hangs forever since throttled requests cannot complete.
Step the clock at the end of each test iteration so in-flight requests actually finish. This solves the hang and is cleaner than leaving tests in-flight.
Note that this could also be "fixed" by disabling throttling when drives are closed in QEMU. That approach has two issues:
1. We must drain requests before disabling throttling, so the hang cannot be easily avoided!
2. Any time QEMU disables throttling internally there is a chance that malicious users can abuse the code path to bypass throttling limits.
Therefore it makes more sense to fix the test case than to modify QEMU.
Message-Id: <[email protected]>
--- tests/qemu-iotests/093 | 4 ++++ 1 file changed, 4 insertions(+)
tests/qemu-iotests/093 +4 -0
@@ -133,6 +133,10 @@ class ThrottleTestCase(iotests.QMPTestCase): self.assertTrue(check_limit(params['iops_rd'], rd_iops)) self.assertTrue(check_limit(params['iops_wr'], wr_iops)) + # Allow remaining requests to finish. We submitted twice as many to + # ensure the throttle limit is reached. + self.vm.qtest("clock_step %d" % ns) + # Connect N drives to a VM and test I/O in all of them def test_all(self): params = {"bps": 4096,
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 3/7] stubs: Add vm state change handler stubs
In reply to Eric BlakeFrom: Fam Zheng <[email protected]>
They will be used by BlockBackend code in block-obj-y, which doesn't always get linked with common-obj-y. Add stubs to keep ld happy.
Message-Id: <[email protected]>
--- stubs/change-state-handler.c | 14 ++++++++++++++ stubs/Makefile.objs | 1 + 2 files changed, 15 insertions(+) create mode 100644 stubs/change-state-handler.c
stubs/change-state-handler.c new file +14 -0
@@ -0,0 +1,14 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "sysemu/sysemu.h" + +VMChangeStateEntry *qemu_add_vm_change_state_handler (VMChangeStateHandler *cb, +void *opaque) +{ +return NULL ; +} + +void qemu_del_vm_change_state_handler (VMChangeStateEntry *e) +{ +/* Nothing to do. */ +}
stubs/Makefile.objs +1 -0
@@ -19,6 +19,7 @@ stub-obj-y += is-daemonized.o stub-obj-$(CONFIG_LINUX_AIO) += linux-aio.o stub-obj-y += machine-init-done.o stub-obj-y += migr-blocker.o +stub-obj-y += change-state-handler.o stub-obj-y += monitor.o stub-obj-y += notify-event.o stub-obj-y += qtest.o
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 5/7] block-backend: Defer shared_perm tightening migration completion
In reply to Eric BlakeFrom: Fam Zheng <[email protected]>
As in the case of nbd_export_new(), bdrv_invalidate_cache() can be called when migration is still in progress. In this case we are not ready to tighten the shared permissions fenced by blk->disable_perm.
Defer to a VM state change handler.
Message-Id: <[email protected]>
--- block/block-backend.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
block/block-backend.c +41 -0
@@ -20,6 +20,7 @@#include "qapi-event.h" #include "qemu/id.h" #include "trace.h" +#include "migration/misc.h" /* Number of coroutines to reserve per attached device model */ #define COROUTINE_POOL_RESERVATION 64
@@ -68,6 +69,7 @@ struct BlockBackend {NotifierList remove_bs_notifiers, insert_bs_notifiers;int quiesce_counter; +VMChangeStateEntry *vmsh; }; typedef struct BlockBackendAIOCB {
@@ -129,6 +131,23 @@ static const char *blk_root_get_name(BdrvChild *child)return blk_name (child->opaque); } +static void blk_vm_state_changed (void *opaque,int running,RunState state) +{ +Error *local_err =NULL ; +BlockBackend *blk = opaque; + +if (state ==RUN_STATE_INMIGRATE ) { +return ; + } + +qemu_del_vm_change_state_handler (blk->vmsh); + blk->vmsh =NULL ; +blk_set_perm (blk, blk->perm, blk->shared_perm, &local_err); +if (local_err) { +error_report_err (local_err); + } +} +/* * Notifies the user of the BlockBackend that migration has completed. qdev * devices can tighten their permissions in response (specifically revoke
@@ -147,6 +166,24 @@ static void blk_root_activate(BdrvChild *child, Error **errp) blk->disable_perm = false; +blk_set_perm (blk, blk->perm,BLK_PERM_ALL , &local_err); +if (local_err) { +error_propagate (errp, local_err); + blk->disable_perm = true; +return ; + } + +if (runstate_check (RUN_STATE_INMIGRATE )) { +/* Activation can happen when migration process is still active, for +* example when nbd_server_add is called during non-shared storage +* migration. Defer the shared_perm update to migration completion. */ +if (!blk->vmsh) { + blk->vmsh =qemu_add_vm_change_state_handler (blk_vm_state_changed, + blk); + } +return ; + } +blk_set_perm (blk, blk->perm, blk->shared_perm, &local_err);if (local_err) {error_propagate (errp, local_err);
@@ -291,6 +328,10 @@ static void blk_delete(BlockBackend *blk)if (blk->root) {blk_remove_bs (blk); } +if (blk->vmsh) { +qemu_del_vm_change_state_handler (blk->vmsh); + blk->vmsh =NULL ; + }assert (QLIST_EMPTY (&blk->remove_bs_notifiers.notifiers));assert (QLIST_EMPTY (&blk->insert_bs_notifiers.notifiers));QTAILQ_REMOVE (&block_backends, blk, link);
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 4/7] nbd: Fix order of bdrv_set_perm and bdrv_invalidate_cache
In reply to Eric BlakeFrom: Kevin Wolf <[email protected]>
The "inactive" state of BDS affects whether the permissions can be granted, we must call bdrv_invalidate_cache before bdrv_set_perm to support "-incoming defer" case.
Message-Id: <[email protected]>
--- nbd/server.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
nbd/server.c +11 -9
@@ -1045,11 +1045,22 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, off_t size, bool writethrough, BlockBackend *on_eject_blk, Error **errp) { + AioContext *ctx;BlockBackend *blk;NBDExport *exp =g_malloc0 (sizeof (NBDExport));uint64_t perm;int ret; +/* +* NBD exports are used for non-shared storage migration. Make sure +* that BDRV_O_INACTIVE is cleared and the image is ready for write +* access since the export could be available before migration handover. +*/ + ctx =bdrv_get_aio_context (bs); +aio_context_acquire (ctx); +bdrv_invalidate_cache (bs,NULL ); +aio_context_release (ctx); +/* Don't allow resize while the NBD server is running, otherwise we don't * care what happens with the node. */ perm =BLK_PERM_CONSISTENT_READ ;
@@ -1087,15 +1098,6 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, off_t size, exp->eject_notifier.notify = nbd_eject_notifier;blk_add_remove_bs_notifier (on_eject_blk, &exp->eject_notifier); } - -/* -* NBD exports are used for non-shared storage migration. Make sure -* that BDRV_O_INACTIVE is cleared and the image is ready for write -* access since the export could be available before migration handover. -*/ -aio_context_acquire (exp->ctx); -blk_invalidate_cache (blk,NULL ); -aio_context_release (exp->ctx);return exp; fail:
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 7/7] nbd-client: Fix regression when server sends garbage
In reply to Eric BlakeWhen we switched NBD to use coroutines for qemu 2.9 (in particular, commit a12a712a), we introduced a regression: if a server sends us garbage (such as a corrupted magic number), we quit the read loop but do not stop sending further queued commands, resulting in the client hanging when it never reads the response to those additional commands. In qemu 2.8, we properly detected that the server is no longer reliable, and cancelled all existing pending commands with EIO, then tore down the socket so that all further command attempts get EPIPE.
Restore the proper behavior of quitting (almost) all communication with a broken server: Once we know we are out of sync or otherwise can't trust the server, we must assume that any further incoming data is unreliable and therefore end all pending commands with EIO, and quit trying to send any further commands. As an exception, we still (try to) send NBD_CMD_DISC to let the server know we are going away (in part, because it is easier to do that than to further refactor nbd_teardown_connection, and in part because it is the only command where we do not have to wait for a reply).
Based on a patch by Vladimir Sementsov-Ogievskiy.
A malicious server can be created with the following hack, followed by setting NBD_SERVER_DEBUG to a non-zero value in the environment when running qemu-nbd:
| --- a/nbd/server.c
| +++ b/nbd/server.c
| @@ -919,6 +919,17 @@ static int nbd_send_reply(QIOChannel *ioc, NBDReply *reply, Error **errp)
| stl_be_p(buf + 4, reply->error);
| stq_be_p(buf + 8, reply->handle);
|
| + static int debug;
| + static int count;
| + if (!count++) {
| + const char *str = getenv("NBD_SERVER_DEBUG");
| + if (str) {
| + debug = atoi(str);
| + }
| + }
| + if (debug && !(count % debug)) {
| + buf[0] = 0;
| + }
| return nbd_write(ioc, buf, sizeof(buf), errp);
| }Message-Id: <[email protected]>
--- block/nbd-client.h | 1 + block/nbd-client.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-)
block/nbd-client.h +1 -0
@@ -29,6 +29,7 @@ typedef struct NBDClientSession {Coroutine *recv_coroutine[MAX_NBD_REQUESTS ];NBDReply reply; +bool quit; } NBDClientSession;NBDClientSession *nbd_get_client_session (BlockDriverState *bs);
block/nbd-client.c +13 -4
@@ -73,7 +73,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)int ret;Error *local_err =NULL ; -for (;;) { +while (!s->quit) {assert (s->reply.handle ==0 ); ret =nbd_receive_reply (s->ioc, &s->reply, &local_err);if (ret <0 ) {
@@ -107,6 +107,9 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)qemu_coroutine_yield (); } +if (ret <0 ) { + s->quit = true; + }nbd_recv_coroutines_enter_all (s); s->read_reply_co =NULL ; }
@@ -135,6 +138,10 @@ static int nbd_co_send_request(BlockDriverState *bs,assert (i <MAX_NBD_REQUESTS ); request->handle =INDEX_TO_HANDLE (s, i); +if (s->quit) { +qemu_co_mutex_unlock (&s->send_mutex); +return -EIO ; + }if (!s->ioc) {qemu_co_mutex_unlock (&s->send_mutex);return -EPIPE ;
@@ -143,7 +150,7 @@ static int nbd_co_send_request(BlockDriverState *bs,if (qiov) {qio_channel_set_cork (s->ioc, true); rc =nbd_send_request (s->ioc, request); -if (rc >=0 ) { +if (rc >=0 && !s->quit) { ret =nbd_rwv (s->ioc, qiov->iov, qiov->niov, request->len, false,NULL );if (ret != request->len) {
@@ -154,6 +161,9 @@ static int nbd_co_send_request(BlockDriverState *bs, }else { rc =nbd_send_request (s->ioc, request); } +if (rc <0 ) { + s->quit = true; + }qemu_co_mutex_unlock (&s->send_mutex);return rc; }
@@ -168,8 +178,7 @@ static void nbd_co_receive_reply(NBDClientSession *s,/* Wait until we're woken up by nbd_read_reply_entry. */ qemu_coroutine_yield (); *reply = s->reply; -if (reply->handle != request->handle || - !s->ioc) { +if (reply->handle != request->handle || !s->ioc || s->quit) { reply->error =EIO ; }else {if (qiov && reply->error ==0 ) {
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 6/7] iotests: Add non-shared storage migration case 192
In reply to Eric BlakeFrom: Fam Zheng <[email protected]>
Message-Id: <[email protected]>
--- tests/qemu-iotests/192 | 63 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/192.out | 7 ++++++ tests/qemu-iotests/group | 1 + 3 files changed, 71 insertions(+) create mode 100755 tests/qemu-iotests/192 create mode 100644 tests/qemu-iotests/192.out
tests/qemu-iotests/192 new file +63 -0
@@ -0,0 +1,63 @@ +#!/bin/bash +# +# Test NBD export with -incoming (non-shared storage migration use case from +# libvirt) +# +# Copyright (C) 2017 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq=`basename $0` +echo "QA output created by $seq" + +here=`pwd` +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt generic +_supported_proto file +_supported_os Linux + +if [ "$QEMU_DEFAULT_MACHINE" != "pc" ]; then + _notrun "Requires a PC machine" +fi + +size=64M +_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=$IMGFMT,file=$TEST_IMG,if=ide,id=drive0 \ + -incoming defer 2>&1 | _filter_testdir | _filter_qemu | _filter_hmp + +# success, all done +echo "*** done" +rm -f $seq.full +status=0
tests/qemu-iotests/192.out new file +7 -0
@@ -0,0 +1,7 @@ +QA output created by 192 +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) nbd_server_start unix:TEST_DIR/nbd +(qemu) nbd_server_add -w drive0 +(qemu) q +*** done
tests/qemu-iotests/group +1 -0
@@ -186,3 +186,4 @@ 188 rw auto quick 189 rw auto 190 rw auto quick +192 rw auto quick
Signature · 1 line
2.13.5
Re: [Qemu-devel] [PULL 7/7] nbd-client: Fix regression when server sends garbage
In reply to Eric BlakeQuoted 72 lines · Eric Blake
When we switched NBD to use coroutines for qemu 2.9 (in particular, commit
a12a712a), we introduced a regression: if a server sends us garbage (such as a corrupted magic number), we quit the read loop but do not stop sending further queued commands, resulting in the client hanging when it never reads the response to those additional commands. In qemu 2.8, we properly detected that the server is no longer reliable, and cancelled all existing pending commands with EIO, then tore down the socket so that all further command attempts get EPIPE.Restore the proper behavior of quitting (almost) all communication with a broken server: Once we know we are out of sync or otherwise can't trust the server, we must assume that any further incoming data is unreliable and therefore end all pending commands with EIO, and quit trying to send any further commands. As an exception, we still (try to) send
NBD_CMD_DISCto let the server know we are going away (in part, because it is easier to do that than to further refactornbd_teardown_connection, and in part because it is the only command where we do not have to wait for a reply).Based on a patch by Vladimir Sementsov-Ogievskiy.
A malicious server can be created with the following hack, followed by setting
NBD_SERVER_DEBUGto a non-zero value in the environment when running qemu-nbd:| --- a/nbd/server.c | +++ b/nbd/server.c | @@ -919,6 +919,17 @@ static int nbd_send_reply(QIOChannel *ioc, NBDReply *reply, Error **errp) | stl_be_p(buf + 4, reply->error); | stq_be_p(buf + 8, reply->handle); | | + static int debug; | + static int count; | + if (!count++) { | + const char *str = getenv("NBD_SERVER_DEBUG"); | + if (str) { | + debug = atoi(str); | + } | + } | + if (debug && !(count % debug)) { | + buf[0] = 0; | + } | return nbd_write(ioc, buf, sizeof(buf), errp); | }Reported-by Vladimir Sementsov-Ogievskiy <[email protected]>Signed-off-by Eric Blake <[email protected]>Message-Id: <[email protected]>
Reviewed-by Stefan Hajnoczi <[email protected]>--- block/nbd-client.h | 1 + block/nbd-client.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-)block/nbd-client.h +1
-0@@ -29,6 +29,7 @@ typedef struct NBDClientSession {Coroutine *recv_coroutine[MAX_NBD_REQUESTS ];NBDReply reply; +bool quit; } NBDClientSession;NBDClientSession *nbd_get_client_session (BlockDriverState *bs);block/nbd-client.c +0
-0
block/nbd-client.c static coroutine_fn void nbd_read_reply_entry(void *opaque) · line 79
Quoted 8 lines
block/nbd-client.c +1
-1@@ -73,7 +73,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)int ret;Error *local_err =NULL ; -for (;;) { +while (!s->quit) {assert (s->reply.handle ==0 ); ret =nbd_receive_reply (s->ioc, &s->reply, &local_err);if (ret <0 ) {
I think we should check quit here, if it is true, we should not continue normal path of handling reply
block/nbd-client.c static int nbd_co_send_request(BlockDriverState *bs, · line 139
Quoted 13 lines
block/nbd-client.c +3
-0@@ -107,6 +107,9 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)qemu_coroutine_yield (); } +if (ret <0 ) { + s->quit = true; + }nbd_recv_coroutines_enter_all (s); s->read_reply_co =NULL ; }@@ -135,6 +138,10 @@ static int nbd_co_send_request(BlockDriverState *bs,assert (i <MAX_NBD_REQUESTS ); request->handle =INDEX_TO_HANDLE (s, i);
not bad to check s->quit at start of the function, but it will complicate things like in my patch.
Quoted 17 lines
block/nbd-client.c +5
-1+if (s->quit) { +qemu_co_mutex_unlock (&s->send_mutex); +return -EIO ; + }if (!s->ioc) {qemu_co_mutex_unlock (&s->send_mutex);return -EPIPE ;@@ -143,7 +150,7 @@ static int nbd_co_send_request(BlockDriverState *bs,if (qiov) {qio_channel_set_cork (s->ioc, true); rc =nbd_send_request (s->ioc, request); -if (rc >=0 ) { +if (rc >=0 && !s->quit) { ret =nbd_rwv (s->ioc, qiov->iov, qiov->niov, request->len, false,NULL );if (ret != request->len) {
block/nbd-client.c static int nbd_co_send_request(BlockDriverState *bs, · line 167
Quoted 7 lines
block/nbd-client.c +3
-0@@ -154,6 +161,9 @@ static int nbd_co_send_request(BlockDriverState *bs, }else { rc =nbd_send_request (s->ioc, request); } +if (rc <0 ) { + s->quit = true; + }qemu_co_mutex_unlock (&s->send_mutex);
and here, if rc == 0 and quite is true, we should not return 0
block/nbd-client.c static void nbd_co_receive_reply(NBDClientSession *s, · line 182
Quoted 10 lines
block/nbd-client.c +1
-2return rc; }@@ -168,8 +178,7 @@ static void nbd_co_receive_reply(NBDClientSession *s,/* Wait until we're woken up by nbd_read_reply_entry. */ qemu_coroutine_yield (); *reply = s->reply; -if (reply->handle != request->handle || - !s->ioc) { +if (reply->handle != request->handle || !s->ioc || s->quit) { reply->error =EIO ;
here, if s->quit is false, we should set it to inform other coroutines
block/nbd-client.c static void nbd_co_receive_reply(NBDClientSession *s, · line 184
Quoted 2 lines
block/nbd-client.c +0
-0}else {if (qiov && reply->error ==0 ) {
and here follows a call to nbd_rwv(), where s->quit should be appropriately handled..
Signature · 2 lines
Best regards, Vladimir
Re: [Qemu-devel] [PULL 7/7] nbd-client: Fix regression when server sends garbage
Quoted 18 lines · Vladimir Sementsov-Ogievskiy
Quoted 17 lines · Eric Blake
When we switched NBD to use coroutines for qemu 2.9 (in particular, commit
a12a712a), we introduced a regression: if a server sends us garbage (such as a corrupted magic number), we quit the read loop but do not stop sending further queued commands, resulting in the client hanging when it never reads the response to those additional commands. In qemu 2.8, we properly detected that the server is no longer reliable, and cancelled all existing pending commands with EIO, then tore down the socket so that all further command attempts get EPIPE.+++
b/block/nbd-client.cblock/nbd-client.c +0
-0@@ -73,7 +73,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)int ret;Error *local_err =NULL ;
Quoted 8 lines
Quoted 5 lines
block/nbd-client.c +1
-1-for (;;) { +while (!s->quit) {assert (s->reply.handle ==0 ); ret =nbd_receive_reply (s->ioc, &s->reply, &local_err);if (ret < 0) {I think we should check quit here, if it is true, we should not continue normal path of handling reply
I don't think it matters. If nbd_receive_reply() correctly got data off the wire for this particular coroutine's request, we might as well act on that data, regardless of what other coroutines have learned in the meantime.
This is already in the pull request for -rc3, but if you can come up with a scenario that still behaves incorrectly, we can do a followup patch for -rc4 (although I'm hoping we don't have to change it any further for 2.10). Otherwise, I'm fine if your refactoring work for 2.11 addresses the issue as part of making the code easier to read.
Quoted 12 lines
block/nbd-client.c static int nbd_co_send_request(BlockDriverState *bs, · line 167
Quoted 8 lines
block/nbd-client.c +3
-0@@ -154,6 +161,9 @@ static int nbd_co_send_request(BlockDriverState *bs, }else { rc =nbd_send_request (s->ioc, request); } +if (rc <0 ) { + s->quit = true; + }qemu_co_mutex_unlock (&s->send_mutex);and here, if rc == 0 and quite is true, we should not return 0
Quoted 1 line
block/nbd-client.c +0
-0return rc;
We don't - we return rc, which is negative.
Quoted 11 lines
block/nbd-client.c static void nbd_co_receive_reply(NBDClientSession *s, · line 182
Quoted 9 lines
block/nbd-client.c +1
-2}@@ -168,8 +178,7 @@ static void nbd_co_receive_reply(NBDClientSession *s,/* Wait until we're woken up by nbd_read_reply_entry. */ qemu_coroutine_yield (); *reply = s->reply; -if (reply->handle != request->handle || - !s->ioc) { +if (reply->handle != request->handle || !s->ioc || s->quit) { reply->error =EIO ;here, if
s->quitis false, we should set it to inform other coroutines
We can't get into nbd_co_receive_reply() unless the two handles were once equal, and the only code that changes them to be not equal is when we are shutting down. Checking s->quit is a safety valve if some other coroutine detects corruption first, but this coroutine does not need to set s->quit because it is either already set, or we are already shutting down.
Quoted 6 lines
block/nbd-client.c static void nbd_co_receive_reply(NBDClientSession *s, · line 184
Quoted 3 lines
block/nbd-client.c +0
-0}else {if (qiov && reply->error ==0 ) {and here follows a call to
nbd_rwv(), wheres->quitshould be appropriately handled..
Reading from a corrupt server is not as bad as writing to the corrupt server; the patch for 2.10 is solely focused on preventing writes where we need a followup read (because once we know the server is corrupt, we can't guarantee the followup reads will come).
Again, if you can prove we have a scenario that is still buggy (client can crash or hang), then it is -rc4 material; if not, then this is all the more that 2.10 needs, and your refactoring work for 2.11 should clean up a lot of this mess in the first place as you make the coroutines easier to follow.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Peter Maydell
AppliedQuoted 30 lines · Eric Blake
The following changes since commit
47025a0193f1f910300adfa443305ccf8482ef87:qxl: call
qemu_spice_display_init_commonfor secondary devices (2017-08-15 15:04:51 +0100)are available in the git repository at:
git://repo.or.cz/qemu/ericb.gittags/pull-nbd-2017-08-15for you to fetch changes up to
72b6ffc76653214b69a94a7b1643ff80df134486:nbd-client: Fix regression when server sends garbage (2017-08-15 10:03:28 -0500)
----------------------------------------------------------------
nbd patches for 2017-08-15- Eric Blake: nbd: Fix trace message for disconnect
- Stefan Hajnoczi: qemu-iotests: step clock after each test iteration
- Fam Zheng: 0/4 block: Fix non-shared storage migration
- Eric Blake: nbd-client: Fix regression when server sends garbage----------------------------------------------------------------
Eric Blake (2):
nbd: Fix trace message for disconnect
nbd-client: Fix regression when server sends garbageFam Zheng (3):
stubs: Add vm state change handler stubs
block-backend: Defershared_permtightening migration completion
iotests: Add non-shared storage migration case 192
Quoted 5 lines
Kevin Wolf (1):
nbd: Fix order ofbdrv_set_permandbdrv_invalidate_cacheStefan Hajnoczi (1):
qemu-iotests: step clock after each test iteration
Applied, thanks.
-- PMM
Re: [Qemu-devel] [PULL 7/7] nbd-client: Fix regression when server sends garbage
In reply to Eric BlakeQuoted 25 lines · Eric Blake
Quoted 17 lines · Vladimir Sementsov-Ogievskiy
Quoted 16 lines · Eric Blake
When we switched NBD to use coroutines for qemu 2.9 (in particular, commit
a12a712a), we introduced a regression: if a server sends us garbage (such as a corrupted magic number), we quit the read loop but do not stop sending further queued commands, resulting in the client hanging when it never reads the response to those additional commands. In qemu 2.8, we properly detected that the server is no longer reliable, and cancelled all existing pending commands with EIO, then tore down the socket so that all further command attempts get EPIPE.+++
b/block/nbd-client.cblock/nbd-client.c +0
-0@@ -73,7 +73,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)int ret;Error *local_err =NULL ;Quoted 7 lines
Quoted 5 lines
block/nbd-client.c +1
-1-for (;;) { +while (!s->quit) {assert (s->reply.handle ==0 ); ret =nbd_receive_reply (s->ioc, &s->reply, &local_err);if (ret < 0) {I think we should check quit here, if it is true, we should not continue normal path of handling reply
Quoted 7 lines
I don't think it matters. If
nbd_receive_reply()correctly got data off the wire for this particular coroutine's request, we might as well act on that data, regardless of what other coroutines have learned in the meantime.This is already in the pull request for -rc3, but if you can come up with a scenario that still behaves incorrectly, we can do a followup
it just don't correspond to your commit message:
"... therefore end all pending commands with EIO, and quit trying to send any further commands"
so, we should end this command (we read reply for it) with EIO, instead of continuing success path.
However, I think this don't leads to a scenario, leading to a hang or a crash of the client, it's OK for me to handle it in my refactoring for 2.11.
Quoted 14 lines
patch for -rc4 (although I'm hoping we don't have to change it any further for 2.10). Otherwise, I'm fine if your refactoring work for 2.11 addresses the issue as part of making the code easier to read.
Quoted 10 lines
block/nbd-client.c static int nbd_co_send_request(BlockDriverState *bs, · line 167
Quoted 8 lines
block/nbd-client.c +3
-0@@ -154,6 +161,9 @@ static int nbd_co_send_request(BlockDriverState *bs, }else { rc =nbd_send_request (s->ioc, request); } +if (rc <0 ) { + s->quit = true; + }qemu_co_mutex_unlock (&s->send_mutex);and here, if rc == 0 and quite is true, we should not return 0
Quoted 2 lines
Quoted 1 line
block/nbd-client.c static int nbd_co_send_request(BlockDriverState *bs, · line 168
Quoted 1 line
block/nbd-client.c +0
-0return rc;We don't - we return rc, which is negative.
I think it can be zero, while quit is set to true in other coroutine.
Quoted 11 lines
Quoted 11 lines
block/nbd-client.c static void nbd_co_receive_reply(NBDClientSession *s, · line 182
Quoted 10 lines
block/nbd-client.c +1
-2}@@ -168,8 +178,7 @@ static void nbd_co_receive_reply(NBDClientSession *s,/* Wait until we're woken up by nbd_read_reply_entry. */ qemu_coroutine_yield (); *reply = s->reply; -if (reply->handle != request->handle || - !s->ioc) { +if (reply->handle != request->handle || !s->ioc || s->quit) { reply->error =EIO ;here, if
s->quitis false, we should set it to inform other coroutines
Quoted 6 lines
We can't get into
nbd_co_receive_reply()unless the two handles were once equal, and the only code that changes them to be not equal is when we are shutting down. Checkings->quitis a safety valve if some other coroutine detects corruption first, but this coroutine does not need to sets->quitbecause it is either already set, or we are already shutting down.
ok, and, as s->quit is set when we are shutting down, we can drop comparing handles here.
Quoted 10 lines
Quoted 5 lines
block/nbd-client.c static void nbd_co_receive_reply(NBDClientSession *s, · line 184
Quoted 3 lines
block/nbd-client.c +0
-0}else {if (qiov && reply->error ==0 ) {and here follows a call to
nbd_rwv(), wheres->quitshould be appropriately handled..Reading from a corrupt server is not as bad as writing to the corrupt server; the patch for 2.10 is solely focused on preventing writes where we need a followup read (because once we know the server is corrupt, we can't guarantee the followup reads will come).
Quoted 5 lines
Again, if you can prove we have a scenario that is still buggy (client can crash or hang), then it is -rc4 material; if not, then this is all the more that 2.10 needs, and your refactoring work for 2.11 should clean up a lot of this mess in the first place as you make the coroutines easier to follow.
ok.
Quoted 1 line
Signature · 2 lines
Best regards, Vladimir
Re: [Qemu-devel] [PULL 7/7] nbd-client: Fix regression when server sends garbage
In reply to Eric BlakeQuoted 81 lines · Eric Blake
When we switched NBD to use coroutines for qemu 2.9 (in particular, commit
a12a712a), we introduced a regression: if a server sends us garbage (such as a corrupted magic number), we quit the read loop but do not stop sending further queued commands, resulting in the client hanging when it never reads the response to those additional commands. In qemu 2.8, we properly detected that the server is no longer reliable, and cancelled all existing pending commands with EIO, then tore down the socket so that all further command attempts get EPIPE.Restore the proper behavior of quitting (almost) all communication with a broken server: Once we know we are out of sync or otherwise can't trust the server, we must assume that any further incoming data is unreliable and therefore end all pending commands with EIO, and quit trying to send any further commands. As an exception, we still (try to) send
NBD_CMD_DISCto let the server know we are going away (in part, because it is easier to do that than to further refactornbd_teardown_connection, and in part because it is the only command where we do not have to wait for a reply).Based on a patch by Vladimir Sementsov-Ogievskiy.
A malicious server can be created with the following hack, followed by setting
NBD_SERVER_DEBUGto a non-zero value in the environment when running qemu-nbd:| --- a/nbd/server.c | +++ b/nbd/server.c | @@ -919,6 +919,17 @@ static int nbd_send_reply(QIOChannel *ioc, NBDReply *reply, Error **errp) | stl_be_p(buf + 4, reply->error); | stq_be_p(buf + 8, reply->handle); | | + static int debug; | + static int count; | + if (!count++) { | + const char *str = getenv("NBD_SERVER_DEBUG"); | + if (str) { | + debug = atoi(str); | + } | + } | + if (debug && !(count % debug)) { | + buf[0] = 0; | + } | return nbd_write(ioc, buf, sizeof(buf), errp); | }Reported-by Vladimir Sementsov-Ogievskiy <[email protected]>Signed-off-by Eric Blake <[email protected]>Message-Id: <[email protected]>
Reviewed-by Stefan Hajnoczi <[email protected]>--- block/nbd-client.h | 1 + block/nbd-client.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-)block/nbd-client.h +1
-0@@ -29,6 +29,7 @@ typedef struct NBDClientSession {Coroutine *recv_coroutine[MAX_NBD_REQUESTS ];NBDReply reply; +bool quit; } NBDClientSession;NBDClientSession *nbd_get_client_session (BlockDriverState *bs);block/nbd-client.c +1
-1@@ -73,7 +73,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)int ret;Error *local_err =NULL ; -for (;;) { +while (!s->quit) {assert (s->reply.handle ==0 ); ret =nbd_receive_reply (s->ioc, &s->reply, &local_err);if (ret <0 ) {
block/nbd-client.c static coroutine_fn void nbd_read_reply_entry(void *opaque) · line 111
Quoted 5 lines
block/nbd-client.c +2
-0@@ -107,6 +107,9 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)qemu_coroutine_yield (); } +if (ret <0 ) { + s->quit = true;
but on wrong handle ret is 0:
if (ret <= 0) {
break;
}
/* There's no need for a mutex on the receive side, because the
* handler acts as a synchronization point and ensures that only
* one coroutine is called until the reply finishes. */
i = HANDLE_TO_INDEX(s, s->reply.handle);
if (i >= MAX_NBD_REQUESTS || !s->recv_coroutine[i]) { break;
}
looks like we should set ret in this if-block
Quoted 44 lines
block/nbd-client.c +10
-3+ }nbd_recv_coroutines_enter_all (s); s->read_reply_co =NULL ; }@@ -135,6 +138,10 @@ static int nbd_co_send_request(BlockDriverState *bs,assert (i <MAX_NBD_REQUESTS ); request->handle =INDEX_TO_HANDLE (s, i); +if (s->quit) { +qemu_co_mutex_unlock (&s->send_mutex); +return -EIO ; + }if (!s->ioc) {qemu_co_mutex_unlock (&s->send_mutex);return -EPIPE ;@@ -143,7 +150,7 @@ static int nbd_co_send_request(BlockDriverState *bs,if (qiov) {qio_channel_set_cork (s->ioc, true); rc =nbd_send_request (s->ioc, request); -if (rc >=0 ) { +if (rc >=0 && !s->quit) { ret =nbd_rwv (s->ioc, qiov->iov, qiov->niov, request->len, false,NULL );if (ret != request->len) {@@ -154,6 +161,9 @@ static int nbd_co_send_request(BlockDriverState *bs, }else { rc =nbd_send_request (s->ioc, request); } +if (rc <0 ) { + s->quit = true; + }qemu_co_mutex_unlock (&s->send_mutex);return rc; }@@ -168,8 +178,7 @@ static void nbd_co_receive_reply(NBDClientSession *s,/* Wait until we're woken up by nbd_read_reply_entry. */ qemu_coroutine_yield (); *reply = s->reply; -if (reply->handle != request->handle || - !s->ioc) { +if (reply->handle != request->handle || !s->ioc || s->quit) { reply->error =EIO ; }else {if (qiov && reply->error ==0 ) {
Signature · 2 lines
Best regards, Vladimir
Re: [Qemu-devel] [PULL 7/7] nbd-client: Fix regression when server sends garbage
Quoted 87 lines · Vladimir Sementsov-Ogievskiy
Quoted 86 lines · Eric Blake
When we switched NBD to use coroutines for qemu 2.9 (in particular, commit
a12a712a), we introduced a regression: if a server sends us garbage (such as a corrupted magic number), we quit the read loop but do not stop sending further queued commands, resulting in the client hanging when it never reads the response to those additional commands. In qemu 2.8, we properly detected that the server is no longer reliable, and cancelled all existing pending commands with EIO, then tore down the socket so that all further command attempts get EPIPE.Restore the proper behavior of quitting (almost) all communication with a broken server: Once we know we are out of sync or otherwise can't trust the server, we must assume that any further incoming data is unreliable and therefore end all pending commands with EIO, and quit trying to send any further commands. As an exception, we still (try to) send
NBD_CMD_DISCto let the server know we are going away (in part, because it is easier to do that than to further refactornbd_teardown_connection, and in part because it is the only command where we do not have to wait for a reply).Based on a patch by Vladimir Sementsov-Ogievskiy.
A malicious server can be created with the following hack, followed by setting
NBD_SERVER_DEBUGto a non-zero value in the environment when running qemu-nbd:| --- a/nbd/server.c | +++ b/nbd/server.c | @@ -919,6 +919,17 @@ static int nbd_send_reply(QIOChannel *ioc, NBDReply *reply, Error **errp) | stl_be_p(buf + 4, reply->error); | stq_be_p(buf + 8, reply->handle); | | + static int debug; | + static int count; | + if (!count++) { | + const char *str = getenv("NBD_SERVER_DEBUG"); | + if (str) { | + debug = atoi(str); | + } | + } | + if (debug && !(count % debug)) { | + buf[0] = 0; | + } | return nbd_write(ioc, buf, sizeof(buf), errp); | }Reported-by Vladimir Sementsov-Ogievskiy <[email protected]>Signed-off-by Eric Blake <[email protected]>Message-Id: <[email protected]>
Reviewed-by Stefan Hajnoczi <[email protected]>---
block/nbd-client.h| 1 +
block/nbd-client.c| 17 +++++++++++++----2 files changed, 14 insertions(+), 4 deletions(-)block/nbd-client.h +1
-0@@ -29,6 +29,7 @@ typedef struct NBDClientSession { Coroutine *recv_coroutine[MAX_NBD_REQUESTS]; NBDReply reply; + bool quit; } NBDClientSession; NBDClientSession *nbd_get_client_session(BlockDriverState *bs);block/nbd-client.c +1
-1@@ -73,7 +73,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque) int ret; Error *local_err = NULL; - for (;;) { + while (!s->quit) { assert(s->reply.handle == 0); ret = nbd_receive_reply(s->ioc, &s->reply, &local_err);if (ret < 0) {
block/nbd-client.c +0
-0@@ -107,6 +107,9 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque) qemu_coroutine_yield(); }
Quoted 4 lines
block/nbd-client.c static coroutine_fn void nbd_read_reply_entry(void *opaque) · line 111
Quoted 2 lines
block/nbd-client.c +2
-0+ if (ret < 0) { + s->quit = true;but on wrong handle ret is 0:
s/0/positive/
Quoted 65 lines
if (ret <= 0) {
break;
}/* There's no need for a mutex on the receive side, because the
* handler acts as a synchronization point and ensures that only
* one coroutine is called until the reply finishes. */
i =HANDLE_TO_INDEX(s, s->reply.handle);
if (i >=MAX_NBD_REQUESTS|| !s->recv_coroutine[i]) { break;
}looks like we should set ret in this if-block
Quoted 46 lines
block/nbd-client.c +1
-0+ } nbd_recv_coroutines_enter_all(s); s->read_reply_co = NULL;}
block/nbd-client.c +4
-0@@ -135,6 +138,10 @@ static int nbd_co_send_request(BlockDriverState *bs, assert(i < MAX_NBD_REQUESTS); request->handle = INDEX_TO_HANDLE(s, i); + if (s->quit) { + qemu_co_mutex_unlock(&s->send_mutex); + return -EIO; + } if (!s->ioc) { qemu_co_mutex_unlock(&s->send_mutex);return
-EPIPE;block/nbd-client.c +5
-3@@ -143,7 +150,7 @@ static int nbd_co_send_request(BlockDriverState *bs, if (qiov) { qio_channel_set_cork(s->ioc, true); rc = nbd_send_request(s->ioc, request); - if (rc >= 0) { + if (rc >= 0 && !s->quit) { ret = nbd_rwv(s->ioc, qiov->iov, qiov->niov, request->len, false, NULL); if (ret != request->len) {@@ -154,6 +161,9 @@ static int nbd_co_send_request(BlockDriverState *bs, } else { rc = nbd_send_request(s->ioc, request); } + if (rc < 0) { + s->quit = true; + } qemu_co_mutex_unlock(&s->send_mutex); return rc; }@@ -168,8 +178,7 @@ static void nbd_co_receive_reply(NBDClientSession *s, /* Wait until we're woken up by nbd_read_reply_entry. */ qemu_coroutine_yield(); *reply = s->reply; - if (reply->handle != request->handle || - !s->ioc) { + if (reply->handle != request->handle || !s->ioc || s->quit) { reply->error = EIO; } else {if (qiov &&
reply->error== 0) {
Signature · 2 lines
Best regards, Vladimir
Re: [Qemu-devel] nbd-client: Fix regression when server sends garbage
ping
Quoted 163 lines · Vladimir Sementsov-Ogievskiy
Quoted 87 lines · Vladimir Sementsov-Ogievskiy
Quoted 86 lines · Eric Blake
When we switched NBD to use coroutines for qemu 2.9 (in particular, commit
a12a712a), we introduced a regression: if a server sends us garbage (such as a corrupted magic number), we quit the read loop but do not stop sending further queued commands, resulting in the client hanging when it never reads the response to those additional commands. In qemu 2.8, we properly detected that the server is no longer reliable, and cancelled all existing pending commands with EIO, then tore down the socket so that all further command attempts get EPIPE.Restore the proper behavior of quitting (almost) all communication with a broken server: Once we know we are out of sync or otherwise can't trust the server, we must assume that any further incoming data is unreliable and therefore end all pending commands with EIO, and quit trying to send any further commands. As an exception, we still (try to) send
NBD_CMD_DISCto let the server know we are going away (in part, because it is easier to do that than to further refactornbd_teardown_connection, and in part because it is the only command where we do not have to wait for a reply).Based on a patch by Vladimir Sementsov-Ogievskiy.
A malicious server can be created with the following hack, followed by setting
NBD_SERVER_DEBUGto a non-zero value in the environment when running qemu-nbd:| --- a/nbd/server.c | +++ b/nbd/server.c | @@ -919,6 +919,17 @@ static int nbd_send_reply(QIOChannel *ioc, NBDReply *reply, Error **errp) | stl_be_p(buf + 4, reply->error); | stq_be_p(buf + 8, reply->handle); | | + static int debug; | + static int count; | + if (!count++) { | + const char *str = getenv("NBD_SERVER_DEBUG"); | + if (str) { | + debug = atoi(str); | + } | + } | + if (debug && !(count % debug)) { | + buf[0] = 0; | + } | return nbd_write(ioc, buf, sizeof(buf), errp); | }Reported-by Vladimir Sementsov-Ogievskiy <[email protected]>Signed-off-by Eric Blake <[email protected]>Message-Id: <[email protected]>
Reviewed-by Stefan Hajnoczi <[email protected]>---
block/nbd-client.h| 1 +
block/nbd-client.c| 17 +++++++++++++----2 files changed, 14 insertions(+), 4 deletions(-)block/nbd-client.h +1
-0@@ -29,6 +29,7 @@ typedef struct NBDClientSession { Coroutine *recv_coroutine[MAX_NBD_REQUESTS]; NBDReply reply; + bool quit; } NBDClientSession; NBDClientSession *nbd_get_client_session(BlockDriverState *bs);block/nbd-client.c +1
-1@@ -73,7 +73,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque) int ret; Error *local_err = NULL; - for (;;) { + while (!s->quit) { assert(s->reply.handle == 0); ret = nbd_receive_reply(s->ioc, &s->reply, &local_err);if (ret < 0) {
block/nbd-client.c +0
-0@@ -107,6 +107,9 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque) qemu_coroutine_yield(); }Quoted 4 lines
block/nbd-client.c static coroutine_fn void nbd_read_reply_entry(void *opaque) · line 111
Quoted 2 lines
block/nbd-client.c +2
-0+ if (ret < 0) { + s->quit = true;but on wrong handle ret is 0:
s/0/positive/
Quoted 67 lines
if (ret <= 0) {
break;
}/* There's no need for a mutex on the receive side, because the
* handler acts as a synchronization point and ensures that only
* one coroutine is called until the reply finishes. */
i =HANDLE_TO_INDEX(s, s->reply.handle);
if (i >=MAX_NBD_REQUESTS|| !s->recv_coroutine[i]) { break;
}looks like we should set ret in this if-block
Quoted 48 lines
block/nbd-client.c +1
-0+ } nbd_recv_coroutines_enter_all(s); s->read_reply_co = NULL;}
block/nbd-client.c +4
-0@@ -135,6 +138,10 @@ static int nbd_co_send_request(BlockDriverState *bs, assert(i < MAX_NBD_REQUESTS); request->handle = INDEX_TO_HANDLE(s, i); + if (s->quit) { + qemu_co_mutex_unlock(&s->send_mutex); + return -EIO; + } if (!s->ioc) { qemu_co_mutex_unlock(&s->send_mutex);return
-EPIPE;block/nbd-client.c +1
-1@@ -143,7 +150,7 @@ static int nbd_co_send_request(BlockDriverState *bs, if (qiov) { qio_channel_set_cork(s->ioc, true); rc = nbd_send_request(s->ioc, request); - if (rc >= 0) { + if (rc >= 0 && !s->quit) { ret = nbd_rwv(s->ioc, qiov->iov, qiov->niov, request->len, false, NULL);if (ret !=
request->len) {block/nbd-client.c +3
-0@@ -154,6 +161,9 @@ static int nbd_co_send_request(BlockDriverState *bs, } else { rc = nbd_send_request(s->ioc, request); } + if (rc < 0) { + s->quit = true; + } qemu_co_mutex_unlock(&s->send_mutex); return rc;}
block/nbd-client.c +1
-2@@ -168,8 +178,7 @@ static void nbd_co_receive_reply(NBDClientSession *s, /* Wait until we're woken up by nbd_read_reply_entry. */ qemu_coroutine_yield(); *reply = s->reply; - if (reply->handle != request->handle || - !s->ioc) { + if (reply->handle != request->handle || !s->ioc || s->quit) { reply->error = EIO; } else {if (qiov &&
reply->error== 0) {
Signature · 2 lines
Best regards, Vladimir
Re: [Qemu-devel] nbd-client: Fix regression when server sends garbage
Quoted 2 lines · Vladimir Sementsov-Ogievskiy
ping
We're still trying to round up last-minute patches for a 2.10-rc4 pull request.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
block/nbd-client.c +0
-0@@ -107,6 +107,9 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)qemu_coroutine_yield (); }
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
block/nbd-client.c static coroutine_fn void nbd_read_reply_entry(void *opaque) · line 111
Quoted 2 lines
block/nbd-client.c +2
-0+if (ret <0 ) { + s->quit = true;but on wrong handle ret is 0:
s/0/positive/
Quoted 1 line
Is your issue fixed by Stefan's patch?
https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg04027.html
In fact, he listed a reproduction formula in his earlier attempt at it, that demonstrates that we still had a hang possible with just what made it into -rc3
https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg03853.html
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] nbd-client: Fix regression when server sends garbage
Quoted 14 lines · Eric Blake
Quoted 2 lines · Vladimir Sementsov-Ogievskiy
ping
We're still trying to round up last-minute patches for a 2.10-rc4 pull request.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
block/nbd-client.c +0
-0@@ -107,6 +107,9 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)qemu_coroutine_yield (); }
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
block/nbd-client.c static coroutine_fn void nbd_read_reply_entry(void *opaque) · line 111
Quoted 2 lines
block/nbd-client.c +2
-0+if (ret <0 ) { + s->quit = true;but on wrong handle ret is 0:
s/0/positive/
Is your issue fixed by Stefan's patch?
https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg04027.html
Yes it fixed, I'm now composing reply on it.
Quoted 6 lines
In fact, he listed a reproduction formula in his earlier attempt at it, that demonstrates that we still had a hang possible with just what made it into -rc3
https://lists.gnu.org/archive/html/qemu-devel/2017-08/msg03853.html
Signature · 2 lines
Best regards, Vladimir