From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id DA4FC5A0082 for ; Fri, 6 Jan 2023 01:43:31 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Np4ML62zHz4y0k; Fri, 6 Jan 2023 11:43:26 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1672965806; bh=EpTHFMeIHdKAIVSJ9gqP2k7/C9t+j1d+pvsqyXnZZug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZkrKJjfHzfolObM6ZTH5YdyuP+Bi9X9ZtT/Qei96lzNZ30kqzkF6YuZzooxq3ebQj QQk74GcGWt5AYyfMYglsx64hbnsTjh2YVzraqeO5VJPgTqopvehBvTYmyEqxDDDo8H RsCyBpZUUmLPTVElKt194vmzhnalO9htZXuoJSYI= From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v3 03/18] tcp: Combine two parts of passt tap send path together Date: Fri, 6 Jan 2023 11:43:07 +1100 Message-Id: <20230106004322.985665-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230106004322.985665-1-david@gibson.dropbear.id.au> References: <20230106004322.985665-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 3F7YMOFIBSGWNMLTI5X7RN3MX47Q3D4E X-Message-ID-Hash: 3F7YMOFIBSGWNMLTI5X7RN3MX47Q3D4E 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: David Gibson X-Mailman-Version: 3.3.3 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: tcp_l2_buf_flush() open codes the "primary" send of message to the passt tap interface, but calls tcp_l2_buf_flush_part() to handle the case of a short send. Combine these two passt-specific operations into tcp_l2_buf_flush_passt() which is a little cleaner and will enable furrther cleanups. Signed-off-by: David Gibson --- tcp.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tcp.c b/tcp.c index ed65a9e..6a59c85 100644 --- a/tcp.c +++ b/tcp.c @@ -1415,19 +1415,25 @@ static int tcp_l2_buf_write_one(struct ctx *c, const struct iovec *iov) } /** - * tcp_l2_buf_flush_part() - Ensure a complete last message on partial sendmsg() + * tcp_l2_buf_flush_passt() - Send a message on the passt tap interface * @c: Execution context * @mh: Message header that was partially sent by sendmsg() - * @sent: Bytes already sent + * @buf_bytes: Total number of bytes to send */ -static void tcp_l2_buf_flush_part(const struct ctx *c, - const struct msghdr *mh, size_t sent) +static void tcp_l2_buf_flush_passt(const struct ctx *c, + const struct msghdr *mh, size_t buf_bytes) { - size_t end = 0, missing; + size_t end = 0, missing, sent; struct iovec *iov; unsigned int i; + ssize_t n; char *p; + n = sendmsg(c->fd_tap, mh, MSG_NOSIGNAL | MSG_DONTWAIT); + if (n < 0 || ((sent = (size_t)n) == buf_bytes)) + return; + + /* Ensure a complete last message on partial sendmsg() */ for (i = 0, iov = mh->msg_iov; i < mh->msg_iovlen; i++, iov++) { end += iov->iov_len; if (end >= sent) @@ -1454,9 +1460,7 @@ static void tcp_l2_buf_flush(struct ctx *c, struct msghdr *mh, return; if (c->mode == MODE_PASST) { - size_t n = sendmsg(c->fd_tap, mh, MSG_NOSIGNAL | MSG_DONTWAIT); - if (n > 0 && n < *buf_bytes) - tcp_l2_buf_flush_part(c, mh, n); + tcp_l2_buf_flush_passt(c, mh, *buf_bytes); } else { size_t i; -- 2.39.0