nbd: convert to using I/O channels for actual socket I/O

Now that all callers are converted to use I/O channels for
initial connection setup, it is possible to switch the core
NBD protocol handling core over to use QIOChannel APIs for
actual sockets I/O.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Message-Id: <1455129674-17255-7-git-send-email-berrange@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Daniel P. Berrange 2016-02-10 18:41:04 +00:00 committed by Paolo Bonzini
parent ae39827802
commit 1c778ef729
8 changed files with 180 additions and 151 deletions

View file

@ -13,6 +13,7 @@
#include "sysemu/block-backend.h"
#include "qemu/coroutine.h"
#include "qemu/iov.h"
#include <errno.h>
#include <string.h>
@ -29,7 +30,6 @@
#include <linux/fs.h>
#endif
#include "qemu/sockets.h"
#include "qemu/queue.h"
#include "qemu/main-loop.h"
@ -90,24 +90,22 @@
#define NBD_EINVAL 22
#define NBD_ENOSPC 28
static inline ssize_t read_sync(int fd, void *buffer, size_t size)
static inline ssize_t read_sync(QIOChannel *ioc, void *buffer, size_t size)
{
struct iovec iov = { .iov_base = buffer, .iov_len = size };
/* 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_wr_sync(fd, buffer, size, true);
return nbd_wr_syncv(ioc, &iov, 1, 0, size, true);
}
static inline ssize_t write_sync(int fd, void *buffer, size_t size)
static inline ssize_t write_sync(QIOChannel *ioc, void *buffer, size_t size)
{
int ret;
do {
/* For writes, we do expect the socket to be writable. */
ret = nbd_wr_sync(fd, buffer, size, false);
} while (ret == -EAGAIN);
return ret;
struct iovec iov = { .iov_base = buffer, .iov_len = size };
return nbd_wr_syncv(ioc, &iov, 1, 0, size, false);
}
#endif