From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id C17BC5A0272 for ; Fri, 11 Aug 2023 05:20:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1691724000; bh=NL9Y0uqsQl0fe9DneEgYO9ogK7hnPhxeg0B41pPvLvg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AI+HRoTuQvheK2e57i6wIPKz+iRykD+08f/aqsa/2OsbhQIL4kNZ+9bX/c2C2lEcG R/b0AoWn7D9CkJxYFP1HuHB4n2rnfL9ha6Px+d6J4mXlX3ScJN78RVK9iQjjj7p9NE RgUIBC9JHfOS22f6Cl7huL77nkZkzSRq3wWsgldc= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4RMTYr14y1z4wxm; Fri, 11 Aug 2023 13:20:00 +1000 (AEST) Date: Fri, 11 Aug 2023 13:17:09 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 8/9] epoll: Split listening Unix domain socket into its own type Message-ID: References: <20230807134631.1400119-1-david@gibson.dropbear.id.au> <20230807134631.1400119-9-david@gibson.dropbear.id.au> <20230809215927.006be951@elisabeth> <20230810095055.421e2636@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="HbPr9Lfc0VQE03w6" Content-Disposition: inline In-Reply-To: <20230810095055.421e2636@elisabeth> Message-ID-Hash: 7I7WBIB3UEELB4VQWEPEFZQNWMHUTGPE X-Message-ID-Hash: 7I7WBIB3UEELB4VQWEPEFZQNWMHUTGPE X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --HbPr9Lfc0VQE03w6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 10, 2023 at 09:50:55AM +0200, Stefano Brivio wrote: > On Thu, 10 Aug 2023 11:08:19 +1000 > David Gibson wrote: >=20 > > On Wed, Aug 09, 2023 at 09:59:27PM +0200, Stefano Brivio wrote: > > > On Mon, 7 Aug 2023 23:46:30 +1000 > > > David Gibson wrote: > > > =20 > > > > tap_handler() actually handles events on three different types of o= bject: > > > > the /dev/tap character device (pasta), a connected Unix domain sock= et > > > > (passt) or a listening Unix domain socket (passt). > > > >=20 > > > > The last, in particular, really has no handling in common with the = others, > > > > so split it into its own epoll type and directly dispatch to the re= levant > > > > handler from the top level. > > > >=20 > > > > Signed-off-by: David Gibson > > > > --- > > > > passt.c | 6 +++++- > > > > passt.h | 6 ++++-- > > > > tap.c | 20 ++++++++------------ > > > > tap.h | 4 ++-- > > > > 4 files changed, 19 insertions(+), 17 deletions(-) > > > >=20 > > > > diff --git a/passt.c b/passt.c > > > > index c32981d..c60f346 100644 > > > > --- a/passt.c > > > > +++ b/passt.c > > > > @@ -64,6 +64,7 @@ char *epoll_type_str[EPOLL_TYPE_MAX+1] =3D { > > > > [EPOLL_TYPE_ICMPV6] =3D "ICMPv6 socket", > > > > [EPOLL_TYPE_NSQUIT] =3D "namespace inotify", > > > > [EPOLL_TYPE_TAP] =3D "tap device", > > > > + [EPOLL_TYPE_TAP_LISTEN] =3D "listening qemu socket", > > > > }; > > > > =20 > > > > /** > > > > @@ -317,7 +318,10 @@ loop: > > > > =20 > > > > switch (ref.type) { > > > > case EPOLL_TYPE_TAP: > > > > - tap_handler(&c, ref.fd, events[i].events, &now); > > > > + tap_handler(&c, events[i].events, &now); > > > > + break; > > > > + case EPOLL_TYPE_TAP_LISTEN: > > > > + tap_listen_handler(&c, eventmask); > > > > break; > > > > case EPOLL_TYPE_NSQUIT: > > > > pasta_netns_quit_handler(&c, quit_fd); > > > > diff --git a/passt.h b/passt.h > > > > index 176bc85..7dae08b 100644 > > > > --- a/passt.h > > > > +++ b/passt.h > > > > @@ -61,10 +61,12 @@ enum epoll_type { > > > > EPOLL_TYPE_ICMPV6, > > > > /* inotify fd watching for end of netns (pasta) */ > > > > EPOLL_TYPE_NSQUIT, > > > > - /* tap char device, or qemu socket fd */ > > > > + /* tap char device, or connected qemu socket fd */ > > > > EPOLL_TYPE_TAP, > > > > + /* socket listening for qemu socket connections */ > > > > + EPOLL_TYPE_TAP_LISTEN, > > > > =20 > > > > - EPOLL_TYPE_MAX =3D EPOLL_TYPE_TAP, > > > > + EPOLL_TYPE_MAX =3D EPOLL_TYPE_TAP_LISTEN, > > > > }; > > > > =20 > > > > /** > > > > diff --git a/tap.c b/tap.c > > > > index ad0decf..8468f86 100644 > > > > --- a/tap.c > > > > +++ b/tap.c > > > > @@ -1076,7 +1076,7 @@ restart: > > > > static void tap_sock_unix_init(struct ctx *c) > > > > { > > > > int fd =3D socket(AF_UNIX, SOCK_STREAM, 0); > > > > - union epoll_ref ref =3D { .type =3D EPOLL_TYPE_TAP }; > > > > + union epoll_ref ref =3D { .type =3D EPOLL_TYPE_TAP_LISTEN }; > > > > struct epoll_event ev =3D { 0 }; > > > > struct sockaddr_un addr =3D { > > > > .sun_family =3D AF_UNIX, > > > > @@ -1142,10 +1142,11 @@ static void tap_sock_unix_init(struct ctx *= c) > > > > } > > > > =20 > > > > /** > > > > - * tap_sock_unix_new() - Handle new connection on listening socket > > > > + * tap_listen_handler() - Handle new connection on listening socket > > > > * @c: Execution context > > > > + * @events: epoll events on the socket > > > > */ > > > > -static void tap_sock_unix_new(struct ctx *c) > > > > +void tap_listen_handler(struct ctx *c, uint32_t events) > > > > { > > > > union epoll_ref ref =3D { .type =3D EPOLL_TYPE_TAP }; > > > > struct epoll_event ev =3D { 0 }; > > > > @@ -1153,6 +1154,9 @@ static void tap_sock_unix_new(struct ctx *c) > > > > struct ucred ucred; > > > > socklen_t len; > > > > =20 > > > > + if (events !=3D EPOLLIN) > > > > + return; > > > > + =20 > > >=20 > > > This comment actually belongs to 2/4 of the tap reset clean-up series, > > > but posting it here for clarity: ...wouldn't it be appropriate to > > > handle errors while at it? Otherwise I guess we'll just spin on > > > EPOLLERR or EPOLLRDHUP. =20 > >=20 > > So, I don't think we'll spin, because we set EPOLLET (edge > > triggered). That said, EPOLLRDHUP makes no sense on a listening > > socket, and we're not subscribed to EPOLLERR >=20 > There's no need to subscribe to EPOLLERR (and EPOLLHUP): both types of > events are always reported. >=20 > I guess it's also fine to indicate it explicitly in 2/13 v2 as you did, > to remark that we handle it, but if you look around we never add > EPOLLERR or EPOLLHUP (except for a stray occurrence in > udp_splice_new()) to the set of events. Ah, right, I missed that. Since I have a few other minor reasons to do a respin anyway, I've removed EPOLLERR for consistency with the other places, and will send that in v3. --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --HbPr9Lfc0VQE03w6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmTVqC8ACgkQzQJF27ox 2Gfe9Q//VnjH/+iTJKWxowrBYexdopvTE9EqnydgOM4kbB0Gt5KfJk2lFjjpQEum 3b6cu4xtNhUJorkT9TnnmmeE5uOJ0EUkLCCyYxMnwhTXelTUGKbh2pcJjcA9RmRL CYXnI3iZ6c08sA//KwafGAfTCCmUWXN0TPjO2udiISNj9mx7tw7sMG9X/1Wvdff9 /5rbfI9qaK5vOVRX4VhUDBwfEjNV6R56Q9fNCD6SXhk+hW5UpKNaEvdM12EmCklx vhWemlvsxYwKC2TH9pe7hK/bYp0MT4/sopI4tF1OYLRXJr+fUWlXbdnQY2zPRUW/ 11INm6TGBQBeJrOaeSyfLECISWI4clpD2WlCZHlB7XA/Ng9FQNwVanZCTg2gVq2I 5NR/TPyOMnXYcRyhv/Axj1ASpfD18NRuyOAfqFVkPehaTxZg8LzRk5blg2bF/HJf AhkqhUxd36TstV7jDkpSl1YiqLm8bXtyEYg0UGIXktCdhawqYrY66DtK5oULhFW/ O/hPcOVdKz9Hc9eVOLkECQtBvYortpEpzvGNzEC60IEVlG7U+3fDXSueeM5q6tsJ dPIytt0oi2fDqi0qhx+liwhce35oLrFrgNClhLOLVYIEn8nbzMwgCaRPY8lvjam2 R9nGNCz82zhd2dFyBivlmHlQOEtNIYaZ70KDLFOz4LpnYuQV7BI= =7hM3 -----END PGP SIGNATURE----- --HbPr9Lfc0VQE03w6--