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=202410 header.b=ZluBH4Dh; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id DFEA85A004E for ; Fri, 25 Oct 2024 02:34:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202410; t=1729816446; bh=rTxisPSaZwN97/7nwWh1ooYjRuhnq1SM5A4eaEmHDW4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZluBH4DhtUIP0LeuWxKlHUdQ/ogkIJ65KI+R5UQieVUzrFOKMhWAsER4YAbhEWeNh 07HjekZZR3dmI+vR6DgqC6KtqqaQNod/dykav6ZHHcaIQoLuKJwSj3no2RzmEBzXHZ B+bswLKsx7LeJDLbZIvGHk/HXHjvwfQSC98fFqxpSQcEOxJgTPttKBxRnUpHUQGs+r wAIkxBn2esH03WIFlQvPs4mWRU4i92XAwTCxDRmefOVrvzw7/azbs/x3F8BIQhBnrv 4NUxP23OjnOU/IDYnxO8a3byUrNglq9zOWf4js4qm3KZZ0V52hc52+R2WBjVyaR7Oe 0/7SdozgCGM2w== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4XZP0t3M6Sz4wbR; Fri, 25 Oct 2024 11:34:06 +1100 (AEDT) Date: Fri, 25 Oct 2024 11:33:34 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH] tcp: cleanup tcp_buf_data_from_sock() Message-ID: References: <20241024085058.348853-1-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="X9rlbt+ZUYNZDr2U" Content-Disposition: inline In-Reply-To: <20241024085058.348853-1-lvivier@redhat.com> Message-ID-Hash: X5JI4KBIJP2QFQU4EFLG6DIJIAZSLAK4 X-Message-ID-Hash: X5JI4KBIJP2QFQU4EFLG6DIJIAZSLAK4 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: --X9rlbt+ZUYNZDr2U Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Oct 24, 2024 at 10:50:58AM +0200, Laurent Vivier wrote: > Remove the err label as there is only one caller, and move code > to the caller position. ret is not needed here anymore as it is > always 0. > Remove sendlen as we can user directly len. English usage nit: s/user directly/directly use/ But otherwise, Reviewed-by: David Gibson >=20 > Signed-off-by: Laurent Vivier > --- > tcp_buf.c | 34 ++++++++++++++++------------------ > 1 file changed, 16 insertions(+), 18 deletions(-) >=20 > diff --git a/tcp_buf.c b/tcp_buf.c > index 44df0e492c7b..cb6742ca1a39 100644 > --- a/tcp_buf.c > +++ b/tcp_buf.c > @@ -382,8 +382,8 @@ int tcp_buf_data_from_sock(const struct ctx *c, struc= t tcp_tap_conn *conn) > { > uint32_t wnd_scaled =3D conn->wnd_from_tap << conn->ws_from_tap; > int fill_bufs, send_bufs =3D 0, last_len, iov_rem =3D 0; > - int sendlen, len, dlen, v4 =3D CONN_V4(conn); > - int s =3D conn->sock, i, ret =3D 0; > + int len, dlen, v4 =3D CONN_V4(conn); > + int s =3D conn->sock, i; > struct msghdr mh_sock =3D { 0 }; > uint16_t mss =3D MSS_GET(conn); > uint32_t already_sent, seq; > @@ -453,12 +453,19 @@ int tcp_buf_data_from_sock(const struct ctx *c, str= uct tcp_tap_conn *conn) > len =3D recvmsg(s, &mh_sock, MSG_PEEK); > while (len < 0 && errno =3D=3D EINTR); > =20 > - if (len < 0) > - goto err; > + if (len < 0) { > + if (errno !=3D EAGAIN && errno !=3D EWOULDBLOCK) { > + tcp_rst(c, conn); > + return -errno; > + } > + > + return 0; > + } > =20 > if (!len) { > if ((conn->events & (SOCK_FIN_RCVD | TAP_FIN_SENT)) =3D=3D SOCK_FIN_RC= VD) { > - if ((ret =3D tcp_buf_send_flag(c, conn, FIN | ACK))) { > + int ret =3D tcp_buf_send_flag(c, conn, FIN | ACK); > + if (ret) { > tcp_rst(c, conn); > return ret; > } > @@ -469,19 +476,18 @@ int tcp_buf_data_from_sock(const struct ctx *c, str= uct tcp_tap_conn *conn) > return 0; > } > =20 > - sendlen =3D len; > if (!peek_offset_cap) > - sendlen -=3D already_sent; > + len -=3D already_sent; > =20 > - if (sendlen <=3D 0) { > + if (len <=3D 0) { > conn_flag(c, conn, STALLED); > return 0; > } > =20 > conn_flag(c, conn, ~STALLED); > =20 > - send_bufs =3D DIV_ROUND_UP(sendlen, mss); > - last_len =3D sendlen - (send_bufs - 1) * mss; > + send_bufs =3D DIV_ROUND_UP(len, mss); > + last_len =3D len - (send_bufs - 1) * mss; > =20 > /* Likely, some new data was acked too. */ > tcp_update_seqack_wnd(c, conn, false, NULL); > @@ -502,12 +508,4 @@ int tcp_buf_data_from_sock(const struct ctx *c, stru= ct tcp_tap_conn *conn) > conn_flag(c, conn, ACK_FROM_TAP_DUE); > =20 > return 0; > - > -err: > - if (errno !=3D EAGAIN && errno !=3D EWOULDBLOCK) { > - ret =3D -errno; > - tcp_rst(c, conn); > - } > - > - return ret; > } --=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 --X9rlbt+ZUYNZDr2U Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmca510ACgkQzQJF27ox 2Gf3gA//Zc/PiDJWaKz/AiYu/o5otqhA912FgaAVyu36OkaDmzjzhAcebd0ZIWCf dVmycNLaZmNaRvLogz7W2kFCU+hURt+1KceQQBdCbfWTFGhz08yQJOJAJQI6NAmU OY6tTqVKmrEm6SLhx9MTmU+A/hi37BemmFe+/503pnNb/t2ASzpW+x3796gX71tE wAd5dehNNVnhzSBhQ15BCoqOIvcdjlR8W1YC0UMZtkwf9j+2FqAxGuRIeyTQBw4/ lu8l4n33v2Bgrqz0war6SFLKeqEp9VtC83KGpL+nlAC5JjVtb6ZBAeIPbFdq02ne 6j116AiU+Fsfm7/RlvFaDWh6e81Lz79XUrOyA9AeHsO3KJ+Gb78wQOq1Ktu82H1m +48WJic5wdVJ3CLK0OtVidHdjl5HsOWtWrtQxzQDaqOhMtbguSEWTmEDAMQtbdOX i8Ddj+2daAtU2uttbUOpjI+4FtB/QCb5hdVrabkWtQRFr1NCuN/ZrfL9uU0fuBtX aXzcZKWKzSdxHXVDeYwLjQrDdvusyOwp48ctei8ZnkN2vAqR6IeTxX86eXipmJGS twaxLO0O5Q5MxYJeI2QxZ6Ge5YQYk4bwgjPwiQW3+XWQ5VUGTGzDAH6geuoncjlI sd9eVPfzf4zbDElUbDloq+zrfDDolkVWaIiaQEb3J0Yn8Lw/P7k= =DXz/ -----END PGP SIGNATURE----- --X9rlbt+ZUYNZDr2U--