From nobody Tue Feb 10 21:41:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502382036518482.2018927332932; Thu, 10 Aug 2017 09:20:36 -0700 (PDT) Received: from localhost ([::1]:53991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfqCI-0002UQ-Vg for importer@patchew.org; Thu, 10 Aug 2017 12:20:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dfpz4-0006Fb-TR for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:06:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dfpz3-0003iV-Ks for qemu-devel@nongnu.org; Thu, 10 Aug 2017 12:06:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33594) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dfpyy-0003h3-OC; Thu, 10 Aug 2017 12:06:48 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B36107BE37; Thu, 10 Aug 2017 16:06:47 +0000 (UTC) Received: from t460.lcy.redhat.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 588A28AD95; Thu, 10 Aug 2017 16:06:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B36107BE37 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=berrange@redhat.com From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 10 Aug 2017 17:04:47 +0100 Message-Id: <20170810160451.32723-5-berrange@redhat.com> In-Reply-To: <20170810160451.32723-1-berrange@redhat.com> References: <20170810160451.32723-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 10 Aug 2017 16:06:47 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/8] blockdev: convert qemu-nbd server to QIONetListener X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block@nongnu.org, Juan Quintela , "Dr. David Alan Gilbert" , Max Reitz , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Daniel P. Berrange Reviewed-by: Eric Blake --- qemu-nbd.c | 50 +++++++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index b8666bb575..dcde7ac75c 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -38,6 +38,7 @@ #include "qapi/qmp/qstring.h" #include "qom/object_interfaces.h" #include "io/channel-socket.h" +#include "io/net-listener.h" #include "crypto/init.h" #include "trace/control.h" #include "qemu-version.h" @@ -63,8 +64,7 @@ static int persistent =3D 0; static enum { RUNNING, TERMINATE, TERMINATING, TERMINATED } state; static int shared =3D 1; static int nb_fds; -static QIOChannelSocket *server_ioc; -static int server_watch =3D -1; +static QIONetListener *server; static QCryptoTLSCreds *tlscreds; =20 static void usage(const char *name) @@ -345,44 +345,24 @@ static void nbd_client_closed(NBDClient *client, bool= negotiated) nbd_client_put(client); } =20 -static gboolean nbd_accept(QIOChannel *ioc, GIOCondition cond, gpointer op= aque) +static void nbd_accept(QIONetListener *listener, QIOChannelSocket *cioc, g= pointer opaque) { - QIOChannelSocket *cioc; - - cioc =3D qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc), - NULL); - if (!cioc) { - return TRUE; - } - if (state >=3D TERMINATE) { - object_unref(OBJECT(cioc)); - return TRUE; + return; } =20 nb_fds++; nbd_update_server_watch(); nbd_client_new(newproto ? NULL : exp, cioc, tlscreds, NULL, nbd_client_closed); - object_unref(OBJECT(cioc)); - - return TRUE; } =20 static void nbd_update_server_watch(void) { if (nbd_can_accept()) { - if (server_watch =3D=3D -1) { - server_watch =3D qio_channel_add_watch(QIO_CHANNEL(server_ioc), - G_IO_IN, - nbd_accept, - NULL, NULL); - } + qio_net_listener_set_client_func(server, nbd_accept, NULL, NULL); } else { - if (server_watch !=3D -1) { - g_source_remove(server_watch); - server_watch =3D -1; - } + qio_net_listener_set_client_func(server, NULL, NULL, NULL); } } =20 @@ -917,24 +897,28 @@ int main(int argc, char **argv) snprintf(sockpath, 128, SOCKET_PATH, basename(device)); } =20 + server =3D qio_net_listener_new(); if (socket_activation =3D=3D 0) { - server_ioc =3D qio_channel_socket_new(); saddr =3D nbd_build_socket_address(sockpath, bindto, port); - if (qio_channel_socket_listen_sync(server_ioc, saddr, &local_err) = < 0) { - object_unref(OBJECT(server_ioc)); + if (qio_net_listener_open_sync(server, saddr, &local_err) < 0) { + object_unref(OBJECT(server)); error_report_err(local_err); - return 1; + exit(EXIT_FAILURE); } } else { + QIOChannelSocket *sioc; /* See comment in check_socket_activation above. */ assert(socket_activation =3D=3D 1); - server_ioc =3D qio_channel_socket_new_fd(FIRST_SOCKET_ACTIVATION_F= D, - &local_err); - if (server_ioc =3D=3D NULL) { + sioc =3D qio_channel_socket_new_fd(FIRST_SOCKET_ACTIVATION_FD, + &local_err); + if (sioc =3D=3D NULL) { + object_unref(OBJECT(server)); error_report("Failed to use socket activation: %s", error_get_pretty(local_err)); exit(EXIT_FAILURE); } + qio_net_listener_add(server, sioc); + object_unref(OBJECT(sioc)); } =20 if (qemu_init_main_loop(&local_err)) { --=20 2.13.3