From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48453C433E2 for ; Tue, 15 Sep 2020 17:59:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CCD9421974 for ; Tue, 15 Sep 2020 17:59:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Sacv/hOt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CCD9421974 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:36704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIFER-00033j-Q2 for qemu-devel@archiver.kernel.org; Tue, 15 Sep 2020 13:59:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIFA6-000684-NU for qemu-devel@nongnu.org; Tue, 15 Sep 2020 13:54:38 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:54453 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIFA3-0008L7-BV for qemu-devel@nongnu.org; Tue, 15 Sep 2020 13:54:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600192472; 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:in-reply-to:in-reply-to: references:references; bh=Rp1gXm/X6qihaf2u+bNhKyeZBEYYmEcPj2iLPkJ6CIg=; b=Sacv/hOtzgmmO/9goF0iaTcHnZ7l3BwZymJZ+V62ZiL2n/uV0phauz6StDeRjrlI3VGp+s lJBWnj1DO4FLMb2DfM7RHcTLA41NsVPTxNiFoieO34vrT7CMdBIIXRV7i3dPr01vR0UKco tSPbIdFd8a/PY0c/KT6HAx/mtZfIxmo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-350-qO79X6XIOwuRVTY6jk6jMA-1; Tue, 15 Sep 2020 13:54:20 -0400 X-MC-Unique: qO79X6XIOwuRVTY6jk6jMA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 856031007464; Tue, 15 Sep 2020 17:54:19 +0000 (UTC) Received: from redhat.com (ovpn-113-234.ams2.redhat.com [10.36.113.234]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EAC3D19D6C; Tue, 15 Sep 2020 17:54:01 +0000 (UTC) Date: Tue, 15 Sep 2020 18:53:59 +0100 From: Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= To: "Dr. David Alan Gilbert" Subject: Re: [PATCH V1 22/32] char: qio_channel_socket_accept reuse fd Message-ID: <20200915175359.GM1502912@redhat.com> References: <1596122076-341293-1-git-send-email-steven.sistare@oracle.com> <1596122076-341293-23-git-send-email-steven.sistare@oracle.com> <20200915173334.GD2922@work-vm> MIME-Version: 1.0 In-Reply-To: <20200915173334.GD2922@work-vm> User-Agent: Mutt/1.14.6 (2020-07-11) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Received-SPF: pass client-ip=205.139.110.120; envelope-from=berrange@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 02:11:06 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= Cc: "Michael S. Tsirkin" , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , Juan Quintela , qemu-devel@nongnu.org, Markus Armbruster , Alex Williamson , Steve Sistare , Stefan Hajnoczi , =?utf-8?Q?Marc-Andr=C3=A9?= Lureau , Paolo Bonzini , Alex =?utf-8?Q?Benn=C3=A9e?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Tue, Sep 15, 2020 at 06:33:34PM +0100, Dr. David Alan Gilbert wrote: > * Steve Sistare (steven.sistare@oracle.com) wrote: > > From: Mark Kanda > > > > Add an fd argument to qio_channel_socket_accept. If not -1, the channel > > uses that fd instead of accepting a new socket connection. All callers > > pass -1 in this patch, so no functional change. > > Doesn't some of this just come from the fact you're insisting on reusing > the command line? We should be able to open a chardev on an fd > shouldn't we? Even ignoring that question, this patch looks pointless to me. The callers have to be modified to pass in the FD to use instead of accepting a new connection. Given that, you migt as well just modify the callers to use the FD immediately if valid and never call qio_channel_socket_accept at all. ie if (reuse_fd) fd = reuse_fd; else fd = qio_channel_socket_accept(ioc...) > > Dave > > > Signed-off-by: Mark Kanda > > Signed-off-by: Steve Sistare > > --- > > include/io/channel-socket.h | 3 ++- > > io/channel-socket.c | 12 +++++++++--- > > io/net-listener.c | 4 ++-- > > scsi/qemu-pr-helper.c | 2 +- > > tests/qtest/tpm-emu.c | 2 +- > > tests/test-char.c | 2 +- > > tests/test-io-channel-socket.c | 4 ++-- > > 7 files changed, 18 insertions(+), 11 deletions(-) > > > > diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h > > index 777ff59..0ffc560 100644 > > --- a/include/io/channel-socket.h > > +++ b/include/io/channel-socket.h > > @@ -248,6 +248,7 @@ qio_channel_socket_get_remote_address(QIOChannelSocket *ioc, > > /** > > * qio_channel_socket_accept: > > * @ioc: the socket channel object > > + * @reuse_fd: fd to reuse; -1 otherwise > > * @errp: pointer to a NULL-initialized error object > > * > > * If the socket represents a server, then this accepts > > @@ -258,7 +259,7 @@ qio_channel_socket_get_remote_address(QIOChannelSocket *ioc, > > */ > > QIOChannelSocket * > > qio_channel_socket_accept(QIOChannelSocket *ioc, > > - Error **errp); > > + int reuse_fd, Error **errp); > > > > > > #endif /* QIO_CHANNEL_SOCKET_H */ > > diff --git a/io/channel-socket.c b/io/channel-socket.c > > index e1b4667..dde12bf 100644 > > --- a/io/channel-socket.c > > +++ b/io/channel-socket.c > > @@ -352,7 +352,7 @@ void qio_channel_socket_dgram_async(QIOChannelSocket *ioc, > > > > QIOChannelSocket * > > qio_channel_socket_accept(QIOChannelSocket *ioc, > > - Error **errp) > > + int reuse_fd, Error **errp) > > { > > QIOChannelSocket *cioc; > > > > @@ -362,8 +362,14 @@ qio_channel_socket_accept(QIOChannelSocket *ioc, > > > > retry: > > trace_qio_channel_socket_accept(ioc); > > - cioc->fd = qemu_accept(ioc->fd, (struct sockaddr *)&cioc->remoteAddr, > > - &cioc->remoteAddrLen); > > + > > + if (reuse_fd != -1) { > > + cioc->fd = reuse_fd; > > + } else { > > + cioc->fd = qemu_accept(ioc->fd, (struct sockaddr *)&cioc->remoteAddr, > > + &cioc->remoteAddrLen); > > + } > > + > > if (cioc->fd < 0) { > > if (errno == EINTR) { > > goto retry; > > diff --git a/io/net-listener.c b/io/net-listener.c > > index 5d8a226..bbdea1e 100644 > > --- a/io/net-listener.c > > +++ b/io/net-listener.c > > @@ -45,7 +45,7 @@ static gboolean qio_net_listener_channel_func(QIOChannel *ioc, > > QIOChannelSocket *sioc; > > > > sioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc), > > - NULL); > > + -1, NULL); > > if (!sioc) { > > return TRUE; > > } > > @@ -194,7 +194,7 @@ static gboolean qio_net_listener_wait_client_func(QIOChannel *ioc, > > QIOChannelSocket *sioc; > > > > sioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc), > > - NULL); > > + -1, NULL); > > if (!sioc) { > > return TRUE; > > } > > diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c > > index 57ad830..0e6d683 100644 > > --- a/scsi/qemu-pr-helper.c > > +++ b/scsi/qemu-pr-helper.c > > @@ -800,7 +800,7 @@ static gboolean accept_client(QIOChannel *ioc, GIOCondition cond, gpointer opaqu > > PRHelperClient *prh; > > > > cioc = qio_channel_socket_accept(QIO_CHANNEL_SOCKET(ioc), > > - NULL); > > + -1, NULL); > > if (!cioc) { > > return TRUE; > > } > > diff --git a/tests/qtest/tpm-emu.c b/tests/qtest/tpm-emu.c > > index 2e8eb7b..19e5dab 100644 > > --- a/tests/qtest/tpm-emu.c > > +++ b/tests/qtest/tpm-emu.c > > @@ -83,7 +83,7 @@ void *tpm_emu_ctrl_thread(void *data) > > g_cond_signal(&s->data_cond); > > > > qio_channel_wait(QIO_CHANNEL(lioc), G_IO_IN); > > - ioc = QIO_CHANNEL(qio_channel_socket_accept(lioc, &error_abort)); > > + ioc = QIO_CHANNEL(qio_channel_socket_accept(lioc, -1, &error_abort)); > > g_assert(ioc); > > > > { > > diff --git a/tests/test-char.c b/tests/test-char.c > > index 614bdac..1bb6ae0 100644 > > --- a/tests/test-char.c > > +++ b/tests/test-char.c > > @@ -884,7 +884,7 @@ char_socket_client_server_thread(gpointer data) > > QIOChannelSocket *cioc; > > > > retry: > > - cioc = qio_channel_socket_accept(ioc, &error_abort); > > + cioc = qio_channel_socket_accept(ioc, -1, &error_abort); > > g_assert_nonnull(cioc); > > > > if (char_socket_ping_pong(QIO_CHANNEL(cioc), NULL) != 0) { > > diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c > > index d43083a..0d410cf 100644 > > --- a/tests/test-io-channel-socket.c > > +++ b/tests/test-io-channel-socket.c > > @@ -75,7 +75,7 @@ static void test_io_channel_setup_sync(SocketAddress *listen_addr, > > qio_channel_set_delay(*src, false); > > > > qio_channel_wait(QIO_CHANNEL(lioc), G_IO_IN); > > - *dst = QIO_CHANNEL(qio_channel_socket_accept(lioc, &error_abort)); > > + *dst = QIO_CHANNEL(qio_channel_socket_accept(lioc, -1, &error_abort)); > > g_assert(*dst); > > > > test_io_channel_set_socket_bufs(*src, *dst); > > @@ -143,7 +143,7 @@ static void test_io_channel_setup_async(SocketAddress *listen_addr, > > g_assert(!data.err); > > > > qio_channel_wait(QIO_CHANNEL(lioc), G_IO_IN); > > - *dst = QIO_CHANNEL(qio_channel_socket_accept(lioc, &error_abort)); > > + *dst = QIO_CHANNEL(qio_channel_socket_accept(lioc, -1, &error_abort)); > > g_assert(*dst); > > > > qio_channel_set_delay(*src, false); > > -- > > 1.8.3.1 > > > -- > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK 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 :|