Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 58494C433FE for ; Thu, 20 Oct 2022 13:15:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.426759.675414 (Exim 4.92) (envelope-from ) id 1olVO6-0000hp-Te; Thu, 20 Oct 2022 13:15:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 426759.675414; Thu, 20 Oct 2022 13:15:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1olVO6-0000hi-Qm; Thu, 20 Oct 2022 13:15:06 +0000 Received: by outflank-mailman (input) for mailman id 426759; Thu, 20 Oct 2022 13:15:05 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1olVO5-0000hc-Gw for xen-devel@lists.xenproject.org; Thu, 20 Oct 2022 13:15:05 +0000 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 353fd074-5079-11ed-8fd0-01056ac49cbb; Thu, 20 Oct 2022 15:15:04 +0200 (CEST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-395-8XB1Lg7xNuqHFFNztoU2DA-1; Thu, 20 Oct 2022 09:14:50 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6A2BF101E154; Thu, 20 Oct 2022 13:14:14 +0000 (UTC) Received: from redhat.com (unknown [10.33.36.226]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7C8FA47505F; Thu, 20 Oct 2022 13:13:58 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 353fd074-5079-11ed-8fd0-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666271703; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wa6ijFnbOddGZNwKzmOMeXhd0ltWkdQZWS1P83dxN6s=; b=iW5hRJ1MxMEZ3Y0EY4b+HgVVDFPXGWdY23GjHlkFAE8GpxGPFsDN7Jfj1XMHyNxcXbIY6/ RFyRZF2FCQdJqIshaQKMnhoLo+L69r5bSkfAaVkvV4W5GkdXBPmDJUXA96RIvr3o5lyF0o sRFNSSHmgdMFYIxIG0WFu6cJ7d+3oso= X-MC-Unique: 8XB1Lg7xNuqHFFNztoU2DA-1 Date: Thu, 20 Oct 2022 14:13:55 +0100 From: Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= To: Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= Cc: Laurent Vivier , qemu-devel@nongnu.org, xen-devel@lists.xenproject.org, Eric Blake , Stefano Stabellini , Paolo Bonzini , Greg Kurz , Jason Wang , Anthony Perard , Thomas Huth , David Gibson , "Michael S. Tsirkin" , Samuel Thibault , "Dr. David Alan Gilbert" , Paul Durrant , Stefan Weil , Markus Armbruster Subject: Re: [PATCH v12 15/17] net: stream: move to QIO to enable additional parameters Message-ID: Reply-To: Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= References: <20221020091624.48368-1-lvivier@redhat.com> <20221020091624.48368-16-lvivier@redhat.com> <6fa6b9e5-fede-0f68-752f-0c0d8fa3494f@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6fa6b9e5-fede-0f68-752f-0c0d8fa3494f@linaro.org> User-Agent: Mutt/2.2.7 (2022-08-07) X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 On Thu, Oct 20, 2022 at 03:09:10PM +0200, Philippe Mathieu-Daudé wrote: > On 20/10/22 11:16, Laurent Vivier wrote: > > Use QIOChannel, QIOChannelSocket and QIONetListener. > > This allows net/stream to use all the available parameters provided by > > SocketAddress. > > > > Signed-off-by: Laurent Vivier > > Acked-by: Michael S. Tsirkin > > --- > > meson | 2 +- > > net/stream.c | 493 +++++++++++++++++------------------------------- > > qemu-options.hx | 4 +- > > 3 files changed, 180 insertions(+), 319 deletions(-) > > > static int net_stream_server_init(NetClientState *peer, > > @@ -283,105 +287,61 @@ static int net_stream_server_init(NetClientState *peer, > > { > > NetClientState *nc; > > NetStreamState *s; > > - int fd, ret; > > - > > - switch (addr->type) { > > - case SOCKET_ADDRESS_TYPE_INET: { > > - struct sockaddr_in saddr_in; > > - > > - if (convert_host_port(&saddr_in, addr->u.inet.host, addr->u.inet.port, > > - errp) < 0) { > > - return -1; > > - } > > + QIOChannelSocket *listen_sioc = qio_channel_socket_new(); > > - fd = qemu_socket(PF_INET, SOCK_STREAM, 0); > > - if (fd < 0) { > > - error_setg_errno(errp, errno, "can't create stream socket"); > > - return -1; > > - } > > - qemu_socket_set_nonblock(fd); > > + nc = qemu_new_net_client(&net_stream_info, peer, model, name); > > + s = DO_UPCAST(NetStreamState, nc, nc); > > - socket_set_fast_reuse(fd); > > + s->listen_ioc = QIO_CHANNEL(listen_sioc); > > + qio_channel_socket_listen_async(listen_sioc, addr, 0, > > + net_stream_server_listening, s, > > + NULL, NULL); > > - ret = bind(fd, (struct sockaddr *)&saddr_in, sizeof(saddr_in)); > > - if (ret < 0) { > > - error_setg_errno(errp, errno, "can't bind ip=%s to socket", > > - inet_ntoa(saddr_in.sin_addr)); > > - closesocket(fd); > > - return -1; > > - } > > - break; > > - } > > - case SOCKET_ADDRESS_TYPE_UNIX: { > > - struct sockaddr_un saddr_un; > > - > > - ret = unlink(addr->u.q_unix.path); > > - if (ret < 0 && errno != ENOENT) { > > - error_setg_errno(errp, errno, "failed to unlink socket %s", > > - addr->u.q_unix.path); > > - return -1; > > - } > > + return 0; > > +} > > - saddr_un.sun_family = PF_UNIX; > > - ret = snprintf(saddr_un.sun_path, sizeof(saddr_un.sun_path), "%s", > > - addr->u.q_unix.path); > > - if (ret < 0 || ret >= sizeof(saddr_un.sun_path)) { > > - error_setg(errp, "UNIX socket path '%s' is too long", > > - addr->u.q_unix.path); > > - error_append_hint(errp, "Path must be less than %zu bytes\n", > > - sizeof(saddr_un.sun_path)); > > - return -1; > > - } > > +static void net_stream_client_connected(QIOTask *task, gpointer opaque) > > +{ > > + NetStreamState *s = opaque; > > + QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(s->ioc); > > + SocketAddress *addr; > > + gchar *uri; > > + int ret; > > - fd = qemu_socket(PF_UNIX, SOCK_STREAM, 0); > > - if (fd < 0) { > > - error_setg_errno(errp, errno, "can't create stream socket"); > > - return -1; > > - } > > - qemu_socket_set_nonblock(fd); > > - > > - ret = bind(fd, (struct sockaddr *)&saddr_un, sizeof(saddr_un)); > > - if (ret < 0) { > > - error_setg_errno(errp, errno, "can't create socket with path: %s", > > - saddr_un.sun_path); > > - closesocket(fd); > > - return -1; > > - } > > - break; > > - } > > - case SOCKET_ADDRESS_TYPE_FD: > > - fd = monitor_fd_param(monitor_cur(), addr->u.fd.str, errp); > > - if (fd == -1) { > > - return -1; > > - } > > - ret = qemu_socket_try_set_nonblock(fd); > > - if (ret < 0) { > > - error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d", > > - name, fd); > > - return -1; > > - } > > - break; > > - default: > > - error_setg(errp, "only support inet or fd type"); > > - return -1; > > + if (sioc->fd < 0) { > > + qemu_set_info_str(&s->nc, "connection error"); > > + goto error; > > } > > - ret = listen(fd, 0); > > - if (ret < 0) { > > - error_setg_errno(errp, errno, "can't listen on socket"); > > - closesocket(fd); > > - return -1; > > + addr = qio_channel_socket_get_remote_address(sioc, NULL); > > + g_assert(addr != NULL); > > Please use: > > addr = qio_channel_socket_get_remote_address(sioc, &error_fatal); Just 'err' instead of '&error_fatal', and return - to the caller. This is code where we need to propagate back to the caller, not abort the running QEMU when hotplugging a NIC backend. With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|