mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 01:33:56 -06:00
nbd: rename read_sync and friends
Rename
nbd_wr_syncv -> nbd_rwv
read_sync -> nbd_read
read_sync_eof -> nbd_read_eof
write_sync -> nbd_write
drop_sync -> nbd_drop
1. nbd_ prefix
read_sync and write_sync are already shared, so it is good to have a
namespace prefix. drop_sync will be shared, and read_sync_eof is
related to read_sync, so let's rename them all.
2. _sync suffix
_sync is related to the fact that nbd_wr_syncv doesn't return if a
write to socket returns EAGAIN. The first implementation of
nbd_wr_syncv (was wr_sync in 7a5ca8648b
) just loops while getting
EAGAIN, the current implementation yields in this case.
Why we want to get rid of it:
- it is normal for r/w functions to be synchronous, so having an
additional suffix for it looks redundant (contrariwise, we have
_aio suffix for async functions)
- _sync suffix in block layer is used when function does flush (so
using it for other thing is confusing a bit)
- keep function names short after adding nbd_ prefix
3. for nbd_wr_syncv let's use more common notation 'rw'
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20170602150150.258222-2-vsementsov@virtuozzo.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
92229a57bb
commit
d1fdf257d5
6 changed files with 48 additions and 56 deletions
|
@ -94,14 +94,14 @@
|
|||
#define NBD_ENOSPC 28
|
||||
#define NBD_ESHUTDOWN 108
|
||||
|
||||
/* read_sync_eof
|
||||
/* nbd_read_eof
|
||||
* Tries to read @size bytes from @ioc. Returns number of bytes actually read.
|
||||
* May return a value >= 0 and < size only on EOF, i.e. when iteratively called
|
||||
* qio_channel_readv() returns 0. So, there are no needs to call read_sync_eof
|
||||
* qio_channel_readv() returns 0. So, there is no need to call nbd_read_eof
|
||||
* iteratively.
|
||||
*/
|
||||
static inline ssize_t read_sync_eof(QIOChannel *ioc, void *buffer, size_t size,
|
||||
Error **errp)
|
||||
static inline ssize_t nbd_read_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
|
||||
|
@ -109,16 +109,16 @@ 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, errp);
|
||||
return nbd_rwv(ioc, &iov, 1, size, true, errp);
|
||||
}
|
||||
|
||||
/* read_sync
|
||||
/* nbd_read
|
||||
* Reads @size bytes from @ioc. Returns 0 on success.
|
||||
*/
|
||||
static inline int read_sync(QIOChannel *ioc, void *buffer, size_t size,
|
||||
Error **errp)
|
||||
static inline int nbd_read(QIOChannel *ioc, void *buffer, size_t size,
|
||||
Error **errp)
|
||||
{
|
||||
ssize_t ret = read_sync_eof(ioc, buffer, size, errp);
|
||||
ssize_t ret = nbd_read_eof(ioc, buffer, size, errp);
|
||||
|
||||
if (ret >= 0 && ret != size) {
|
||||
ret = -EINVAL;
|
||||
|
@ -128,15 +128,15 @@ static inline int read_sync(QIOChannel *ioc, void *buffer, size_t size,
|
|||
return ret < 0 ? ret : 0;
|
||||
}
|
||||
|
||||
/* write_sync
|
||||
/* nbd_write
|
||||
* Writes @size bytes to @ioc. Returns 0 on success.
|
||||
*/
|
||||
static inline int write_sync(QIOChannel *ioc, const void *buffer, size_t size,
|
||||
Error **errp)
|
||||
static inline int nbd_write(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, errp);
|
||||
ssize_t ret = nbd_rwv(ioc, &iov, 1, size, false, errp);
|
||||
|
||||
assert(ret < 0 || ret == size);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue