From e44ed99d1949315755bffb12a5a483ac66d4a976 Mon Sep 17 00:00:00 2001 From: Vladimir Sementsov-Ogievskiy Date: Tue, 16 May 2017 12:45:32 +0300 Subject: nbd: add errp to read_sync, write_sync and drop_sync There a lot of calls of these functions, which already have errp, which they are filling themselves. On the other hand, nbd_wr_syncv has errp parameter too, so it would be great to connect them. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20170516094533.6160-5-vsementsov@virtuozzo.com> Signed-off-by: Paolo Bonzini --- nbd/nbd-internal.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'nbd/nbd-internal.h') diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h index 1d479fe135..d6071640a0 100644 --- a/nbd/nbd-internal.h +++ b/nbd/nbd-internal.h @@ -100,7 +100,8 @@ * qio_channel_readv() returns 0. So, there are no needs to call read_sync_eof * iteratively. */ -static inline ssize_t read_sync_eof(QIOChannel *ioc, void *buffer, size_t size) +static inline ssize_t read_sync_eof(QIOChannel *ioc, void *buffer, size_t size, + Error **errp) { struct iovec iov = { .iov_base = buffer, .iov_len = size }; /* Sockets are kept in blocking mode in the negotiation phase. After @@ -108,18 +109,20 @@ static inline ssize_t read_sync_eof(QIOChannel *ioc, void *buffer, size_t size) * our request/reply. Synchronization is done with recv_coroutine, so * that this is coroutine-safe. */ - return nbd_wr_syncv(ioc, &iov, 1, size, true, NULL); + return nbd_wr_syncv(ioc, &iov, 1, size, true, errp); } /* read_sync * Reads @size bytes from @ioc. Returns 0 on success. */ -static inline int read_sync(QIOChannel *ioc, void *buffer, size_t size) +static inline int read_sync(QIOChannel *ioc, void *buffer, size_t size, + Error **errp) { - ssize_t ret = read_sync_eof(ioc, buffer, size); + ssize_t ret = read_sync_eof(ioc, buffer, size, errp); if (ret >= 0 && ret != size) { ret = -EINVAL; + error_setg(errp, "End of file"); } return ret < 0 ? ret : 0; @@ -128,11 +131,12 @@ static inline int read_sync(QIOChannel *ioc, void *buffer, size_t size) /* write_sync * Writes @size bytes to @ioc. Returns 0 on success. */ -static inline int write_sync(QIOChannel *ioc, const void *buffer, size_t size) +static inline int write_sync(QIOChannel *ioc, const void *buffer, size_t size, + Error **errp) { struct iovec iov = { .iov_base = (void *) buffer, .iov_len = size }; - ssize_t ret = nbd_wr_syncv(ioc, &iov, 1, size, false, NULL); + ssize_t ret = nbd_wr_syncv(ioc, &iov, 1, size, false, errp); assert(ret < 0 || ret == size); -- cgit v1.2.1