From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202412 header.b=HZfvBwSA; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id B29645A026F for ; Tue, 10 Dec 2024 02:17:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202412; t=1733793438; bh=rQ2eTPNNgTWC5Qhs6946ok9EyILsBAknvOyzw+pjK1I=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HZfvBwSAqsVVTEQYwxk1y/MICEpVfDGe93e98L5Nil91+FmrPujLMSzNcKrPvd86w W4cn1VKKw1almb7pP6SHJ/VP/wrw+CGVTTqI3z0nZSAIM6TI2Pa+ghjIRja2BXS7Id Hp+0uFXiQgCDefGZLqsWqrYSK4LK6IxhwJEhFGErbGOlN2tVJdLFx2jsJsQVry7W6y twLaH0bpb/WR0gVLSoGMnK1MSkw0HZmQR6Ly2/CexFyi81XHqt0r8GTYYHjeKpi/Pi i6uBYORgFbEijGR4x1UMJIUyN5A4Ogt/TbEh0Z7nxNjl7Ig1JSGwg92bX0UnCPT249 AM3bC1dCE9LHw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Y6gnV4b17z4wcy; Tue, 10 Dec 2024 12:17:18 +1100 (AEDT) Date: Tue, 10 Dec 2024 12:13:41 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH 1/2] tap: Use a common function to start a new connection Message-ID: References: <20241209165450.2314060-1-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="LSKfiC70Bk7EtBo2" Content-Disposition: inline In-Reply-To: <20241209165450.2314060-1-lvivier@redhat.com> Message-ID-Hash: YB2KTULRGK7CMB4PXXJMNZ372FDAVFXX X-Message-ID-Hash: YB2KTULRGK7CMB4PXXJMNZ372FDAVFXX 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: --LSKfiC70Bk7EtBo2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Dec 09, 2024 at 05:54:49PM +0100, Laurent Vivier wrote: > Merge code from tap_backend_init(), tap_sock_tun_init() and > tap_listen_handler() to set epoll_ref entry and to add it > to epollfd. >=20 > No functionality change >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson > --- > tap.c | 66 +++++++++++++++++++++++++++-------------------------------- > 1 file changed, 30 insertions(+), 36 deletions(-) >=20 > diff --git a/tap.c b/tap.c > index c4180643bd0a..b2d30456e8dc 100644 > --- a/tap.c > +++ b/tap.c > @@ -1255,6 +1255,33 @@ static void tap_sock_unix_init(const struct ctx *c) > epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap_listen, &ev); > } > =20 > +/** > + * tap_start_connection() - start a new connection > + * @c: Execution context > + */ > +static void tap_start_connection(const struct ctx *c) > +{ > + struct epoll_event ev =3D { 0 }; > + union epoll_ref ref =3D { 0 }; > + > + ref.fd =3D c->fd_tap; > + switch (c->mode) { > + case MODE_PASST: > + ref.type =3D EPOLL_TYPE_TAP_PASST; > + break; > + case MODE_PASTA: > + ref.type =3D EPOLL_TYPE_TAP_PASTA; > + break; > + case MODE_VU: > + ref.type =3D EPOLL_TYPE_VHOST_CMD; > + break; > + } > + > + ev.events =3D EPOLLIN | EPOLLRDHUP; > + ev.data.u64 =3D ref.u64; > + epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev); > +} > + > /** > * tap_listen_handler() - Handle new connection on listening socket > * @c: Execution context > @@ -1262,8 +1289,6 @@ static void tap_sock_unix_init(const struct ctx *c) > */ > void tap_listen_handler(struct ctx *c, uint32_t events) > { > - struct epoll_event ev =3D { 0 }; > - union epoll_ref ref =3D { 0 }; > int v =3D INT_MAX / 2; > struct ucred ucred; > socklen_t len; > @@ -1302,14 +1327,7 @@ void tap_listen_handler(struct ctx *c, uint32_t ev= ents) > setsockopt(c->fd_tap, SOL_SOCKET, SO_SNDBUF, &v, sizeof(v))) > trace("tap: failed to set SO_SNDBUF to %i", v); > =20 > - ref.fd =3D c->fd_tap; > - if (c->mode =3D=3D MODE_VU) > - ref.type =3D EPOLL_TYPE_VHOST_CMD; > - else > - ref.type =3D EPOLL_TYPE_TAP_PASST; > - ev.events =3D EPOLLIN | EPOLLRDHUP; > - ev.data.u64 =3D ref.u64; > - epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev); > + tap_start_connection(c); > } > =20 > /** > @@ -1353,19 +1371,13 @@ static int tap_ns_tun(void *arg) > */ > static void tap_sock_tun_init(struct ctx *c) > { > - union epoll_ref ref =3D { .type =3D EPOLL_TYPE_TAP_PASTA }; > - struct epoll_event ev =3D { 0 }; > - > NS_CALL(tap_ns_tun, c); > if (c->fd_tap =3D=3D -1) > die("Failed to set up tap device in namespace"); > =20 > pasta_ns_conf(c); > =20 > - ref.fd =3D c->fd_tap; > - ev.events =3D EPOLLIN | EPOLLRDHUP; > - ev.data.u64 =3D ref.u64; > - epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev); > + tap_start_connection(c); > } > =20 > /** > @@ -1399,26 +1411,8 @@ void tap_backend_init(struct ctx *c) > tap_sock_update_pool(pkt_buf, sizeof(pkt_buf)); > =20 > if (c->fd_tap !=3D -1) { /* Passed as --fd */ > - struct epoll_event ev =3D { 0 }; > - union epoll_ref ref; > - > ASSERT(c->one_off); > - ref.fd =3D c->fd_tap; > - switch (c->mode) { > - case MODE_PASST: > - ref.type =3D EPOLL_TYPE_TAP_PASST; > - break; > - case MODE_PASTA: > - ref.type =3D EPOLL_TYPE_TAP_PASTA; > - break; > - case MODE_VU: > - ref.type =3D EPOLL_TYPE_VHOST_CMD; > - break; > - } > - > - ev.events =3D EPOLLIN | EPOLLRDHUP; > - ev.data.u64 =3D ref.u64; > - epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev); > + tap_start_connection(c); > return; > } > =20 --=20 David Gibson (he or they) | 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 --LSKfiC70Bk7EtBo2 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmdXlbMACgkQzQJF27ox 2GcztQ//RIty223Wkk76x8GORTmIokaHdeeBhV80niRqykzTYlftMJ6NEkd0iPeH lvCXlUESeAsFLEa2h2VvxRRa5a3FSL8UKFcQ5uqYMQuBblg82nJ1mfhZVmNqlvDB 2e00oe+A1U3KgvSvj/mlb06gs+UMvIRlfDrVvvxGHVhcZVZwVYZdl70gbhxtJUby m7sSWAR9BBo3LpBjvaocofj7q1GVdEkwqR/NAQfhzSj8MzhHOsYy8Jct+GSzpqyd dCMVAH834lPtXN4G4c5LPJ62DGCMCzGSgGD7ytIujHvH1WdDlPnXsN1dMV2Q59bP t//W3O6YUv8p2ycTa+ypUVOHdGDhrJLa3t7OzFXc2O558fozcNGFQlLyU7QHFbDi ophNkwsBBB4qLoeeqXkjJn2y3jk1HD2vx50h7XQ6r01+J4zRR2k1A9EGwR+9a4S1 sel4stnEba4MjR1+6ajLHLWTGL0AVL+SzmYybUtSAe33QEare23OydK9THZiUs1c vpsD7rW4gAnmh18xnXl8tizZn83mA05W6ka3OKObsYxt+YrSlaeDh34O2NFqTbrQ ZSSpM4et1okmVv8h46pYWsVeengRSFM5T6l302Kpe9jZfACng5jmwHwo2xGS4s9H WLILJpr1E8vN9GxtHuihGdDs+sdh3oQWbvuqaGFDQhm5QNsc/4A= =vE/v -----END PGP SIGNATURE----- --LSKfiC70Bk7EtBo2--