aboutsummaryrefslogtreecommitdiff
path: root/util/vhost-user-server.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/vhost-user-server.c')
-rw-r--r--util/vhost-user-server.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c
index b192290..1dbe409 100644
--- a/util/vhost-user-server.c
+++ b/util/vhost-user-server.c
@@ -62,7 +62,7 @@ static void vmsg_close_fds(VhostUserMsg *vmsg)
}
}
-static void vmsg_unblock_fds(VhostUserMsg *vmsg)
+static bool vmsg_unblock_fds(VhostUserMsg *vmsg, Error **errp)
{
int i;
@@ -74,12 +74,16 @@ static void vmsg_unblock_fds(VhostUserMsg *vmsg)
*/
if (vmsg->request == VHOST_USER_ADD_MEM_REG ||
vmsg->request == VHOST_USER_SET_MEM_TABLE) {
- return;
+ return true;
}
for (i = 0; i < vmsg->fd_num; i++) {
- qemu_socket_set_nonblock(vmsg->fds[i]);
+ if (!qemu_set_blocking(vmsg->fds[i], false, errp)) {
+ return false;
+ }
}
+
+ return true;
}
static void panic_cb(VuDev *vu_dev, const char *buf)
@@ -122,7 +126,6 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserMsg *vmsg)
vmsg->fd_num = 0;
if (!ioc) {
- error_report_err(local_err);
goto fail;
}
@@ -176,7 +179,10 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserMsg *vmsg)
} while (read_bytes != VHOST_USER_HDR_SIZE);
/* qio_channel_readv_full will make socket fds blocking, unblock them */
- vmsg_unblock_fds(vmsg);
+ if (!vmsg_unblock_fds(vmsg, &local_err)) {
+ error_report_err(local_err);
+ goto fail;
+ }
if (vmsg->size > sizeof(vmsg->payload)) {
error_report("Error: too big message request: %d, "
"size: vmsg->size: %u, "
@@ -303,7 +309,8 @@ set_watch(VuDev *vu_dev, int fd, int vu_evt,
vu_fd_watch->fd = fd;
vu_fd_watch->cb = cb;
- qemu_socket_set_nonblock(fd);
+ /* TODO: handle error more gracefully than aborting */
+ qemu_set_blocking(fd, false, &error_abort);
aio_set_fd_handler(server->ctx, fd, kick_handler,
NULL, NULL, NULL, vu_fd_watch);
vu_fd_watch->vu_dev = vu_dev;
@@ -336,6 +343,7 @@ static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc,
gpointer opaque)
{
VuServer *server = opaque;
+ Error *local_err = NULL;
if (server->sioc) {
warn_report("Only one vhost-user client is allowed to "
@@ -368,7 +376,11 @@ static void vu_accept(QIONetListener *listener, QIOChannelSocket *sioc,
object_ref(OBJECT(server->ioc));
/* TODO vu_message_write() spins if non-blocking! */
- qio_channel_set_blocking(server->ioc, false, NULL);
+ if (!qio_channel_set_blocking(server->ioc, false, &local_err)) {
+ error_report_err(local_err);
+ vu_deinit(&server->vu_dev);
+ return;
+ }
qio_channel_set_follow_coroutine_ctx(server->ioc, true);