aboutsummaryrefslogtreecommitdiff
path: root/blockdev-nbd.c
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2017-12-18 10:16:42 +0000
committerPaolo Bonzini <pbonzini@redhat.com>2017-12-21 09:30:32 +0100
commit862172f45c38fb6c446cc8db8c9a3f5a9be1dee7 (patch)
tree7b00a168121608af780e70f8dc3ea77e6a9e72aa /blockdev-nbd.c
parentd45f80ba82f281a35168011125cf6664cd217c22 (diff)
blockdev: convert internal NBD server to QIONetListener
Instead of creating a QIOChannelSocket directly for the NBD server socket, use a QIONetListener. This provides the ability to listen on multiple sockets at the same time, so enables full support for IPv4/IPv6 dual stack. Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com> Message-Id: <20171218101643.20360-2-berrange@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'blockdev-nbd.c')
-rw-r--r--blockdev-nbd.c50
1 files changed, 16 insertions, 34 deletions
diff --git a/blockdev-nbd.c b/blockdev-nbd.c
index 28f551a7b0..9e3c22109c 100644
--- a/blockdev-nbd.c
+++ b/blockdev-nbd.c
@@ -18,10 +18,10 @@
#include "qmp-commands.h"
#include "block/nbd.h"
#include "io/channel-socket.h"
+#include "io/net-listener.h"
typedef struct NBDServerData {
- QIOChannelSocket *listen_ioc;
- int watch;
+ QIONetListener *listener;
QCryptoTLSCreds *tlscreds;
} NBDServerData;
@@ -32,27 +32,13 @@ static void nbd_blockdev_client_closed(NBDClient *client, bool ignored)
nbd_client_put(client);
}
-static gboolean nbd_accept(QIOChannel *ioc, GIOCondition condition,
- gpointer opaque)
+static void nbd_accept(QIONetListener *listener, QIOChannelSocket *cioc,
+ gpointer opaque)
{
- QIOChannelSocket *cioc;
-
- if (!nbd_server) {
- return FALSE;
- }
-
- cioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc),
- NULL);
- if (!cioc) {
- return TRUE;
- }
-
qio_channel_set_name(QIO_CHANNEL(cioc), "nbd-server");
nbd_client_new(NULL, cioc,
nbd_server->tlscreds, NULL,
nbd_blockdev_client_closed);
- object_unref(OBJECT(cioc));
- return TRUE;
}
@@ -62,10 +48,8 @@ static void nbd_server_free(NBDServerData *server)
return;
}
- if (server->watch != -1) {
- g_source_remove(server->watch);
- }
- object_unref(OBJECT(server->listen_ioc));
+ qio_net_listener_disconnect(server->listener);
+ object_unref(OBJECT(server->listener));
if (server->tlscreds) {
object_unref(OBJECT(server->tlscreds));
}
@@ -112,12 +96,12 @@ void nbd_server_start(SocketAddress *addr, const char *tls_creds,
}
nbd_server = g_new0(NBDServerData, 1);
- nbd_server->watch = -1;
- nbd_server->listen_ioc = qio_channel_socket_new();
- qio_channel_set_name(QIO_CHANNEL(nbd_server->listen_ioc),
- "nbd-listener");
- if (qio_channel_socket_listen_sync(
- nbd_server->listen_ioc, addr, errp) < 0) {
+ nbd_server->listener = qio_net_listener_new();
+
+ qio_net_listener_set_name(nbd_server->listener,
+ "nbd-listener");
+
+ if (qio_net_listener_open_sync(nbd_server->listener, addr, errp) < 0) {
goto error;
}
@@ -134,12 +118,10 @@ void nbd_server_start(SocketAddress *addr, const char *tls_creds,
}
}
- nbd_server->watch = qio_channel_add_watch(
- QIO_CHANNEL(nbd_server->listen_ioc),
- G_IO_IN,
- nbd_accept,
- NULL,
- NULL);
+ qio_net_listener_set_client_func(nbd_server->listener,
+ nbd_accept,
+ NULL,
+ NULL);
return;