[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 20/20] nbd: make nbd_read* return -EIO on error
From: |
Eric Blake |
Subject: |
[PULL 20/20] nbd: make nbd_read* return -EIO on error |
Date: |
Tue, 2 Feb 2021 16:45:29 -0600 |
From: Roman Kagan <rvkagan@yandex-team.ru>
NBD reconnect logic considers the error code from the functions that
read NBD messages to tell if reconnect should be attempted or not: it is
attempted on -EIO, otherwise the client transitions to NBD_CLIENT_QUIT
state (see nbd_channel_error). This error code is propagated from the
primitives like nbd_read.
The problem, however, is that nbd_read itself turns every error into -1
rather than -EIO. As a result, if the NBD server happens to die while
sending the message, the client in QEMU receives less data than it
expects, considers it as a fatal error, and wouldn't attempt
reestablishing the connection.
Fix it by turning every negative return from qio_channel_read_all into
-EIO returned from nbd_read. Apparently that was the original behavior,
but got broken later. Also adjust nbd_readXX to follow.
Fixes: e6798f06a6 ("nbd: generalize usage of nbd_read")
Signed-off-by: Roman Kagan <rvkagan@yandex-team.ru>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210129073859.683063-4-rvkagan@yandex-team.ru>
Signed-off-by: Eric Blake <eblake@redhat.com>
---
include/block/nbd.h | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/include/block/nbd.h b/include/block/nbd.h
index 4a52a43ef598..5f34d23bb037 100644
--- a/include/block/nbd.h
+++ b/include/block/nbd.h
@@ -364,7 +364,7 @@ static inline int nbd_read(QIOChannel *ioc, void *buffer,
size_t size,
if (desc) {
error_prepend(errp, "Failed to read %s: ", desc);
}
- return -1;
+ return ret;
}
return 0;
@@ -375,8 +375,9 @@ static inline int nbd_read##bits(QIOChannel *ioc,
\
uint##bits##_t *val, \
const char *desc, Error **errp) \
{ \
- if (nbd_read(ioc, val, sizeof(*val), desc, errp) < 0) { \
- return -1; \
+ int ret = nbd_read(ioc, val, sizeof(*val), desc, errp); \
+ if (ret < 0) { \
+ return ret; \
} \
*val = be##bits##_to_cpu(*val); \
return 0; \
--
2.30.0
- [PULL 08/20] block/io: improve bdrv_check_request: check qiov too, (continued)
- [PULL 08/20] block/io: improve bdrv_check_request: check qiov too, Eric Blake, 2021/02/02
- [PULL 06/20] block/io: bdrv_pad_request(): support qemu_iovec_init_extended failure, Eric Blake, 2021/02/02
- [PULL 09/20] block: use int64_t as bytes type in tracked requests, Eric Blake, 2021/02/02
- [PULL 10/20] block/io: use int64_t bytes in driver wrappers, Eric Blake, 2021/02/02
- [PULL 11/20] block/io: support int64_t bytes in bdrv_co_do_pwrite_zeroes(), Eric Blake, 2021/02/02
- [PULL 12/20] block/io: support int64_t bytes in bdrv_aligned_pwritev(), Eric Blake, 2021/02/02
- [PULL 16/20] block/io: support int64_t bytes in read/write wrappers, Eric Blake, 2021/02/02
- [PULL 17/20] block/io: use int64_t bytes in copy_range, Eric Blake, 2021/02/02
- [PULL 15/20] block/io: support int64_t bytes in bdrv_co_p{read, write}v_part(), Eric Blake, 2021/02/02
- [PULL 19/20] block/nbd: only enter connection coroutine if it's present, Eric Blake, 2021/02/02
- [PULL 20/20] nbd: make nbd_read* return -EIO on error,
Eric Blake <=
- [PULL 14/20] block/io: support int64_t bytes in bdrv_aligned_preadv(), Eric Blake, 2021/02/02
- [PULL 18/20] block/nbd: only detach existing iochannel from aio_context, Eric Blake, 2021/02/02
- [PULL 13/20] block/io: support int64_t bytes in bdrv_co_do_copy_on_readv(), Eric Blake, 2021/02/02
- Re: [PULL 00/20] NBD patches for 2021-02-02, no-reply, 2021/02/02
- Re: [PULL 00/20] NBD patches for 2021-02-02, Eric Blake, 2021/02/03