From: Gustavo Luiz Duarte <gustavold@gmail.com>
To: Breno Leitao <leitao@debian.org>,
Andre Carvalho <asantostc@gmail.com>,
Simon Horman <horms@kernel.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Shuah Khan <shuah@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Gustavo Luiz Duarte <gustavold@gmail.com>
Subject: [PATCH net-next 1/4] netconsole: Simplify send_fragmented_body()
Date: Wed, 05 Nov 2025 09:06:43 -0800 [thread overview]
Message-ID: <20251105-netconsole_dynamic_extradata-v1-1-142890bf4936@meta.com> (raw)
In-Reply-To: <20251105-netconsole_dynamic_extradata-v1-0-142890bf4936@meta.com>
Refactor send_fragmented_body() to use separate offset tracking for
msgbody, and extradata instead of complex conditional logic.
The previous implementation used boolean flags and calculated offsets
which made the code harder to follow.
The new implementation maintains independent offset counters
(msgbody_offset, extradata_offset) and processes each section
sequentially, making the data flow more straightforward and the code
easier to maintain.
This is a preparatory refactoring with no functional changes, which will
allow easily splitting extradata_complete into separate userdata and
sysdata buffers in the next patch.
Signed-off-by: Gustavo Luiz Duarte <gustavold@gmail.com>
---
drivers/net/netconsole.c | 73 ++++++++++++++++--------------------------------
1 file changed, 24 insertions(+), 49 deletions(-)
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 5d8d0214786c..0a8ba7c4bc9d 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -1553,13 +1553,16 @@ static void send_fragmented_body(struct netconsole_target *nt,
const char *msgbody, int header_len,
int msgbody_len, int extradata_len)
{
- int sent_extradata, preceding_bytes;
const char *extradata = NULL;
int body_len, offset = 0;
+ int extradata_offset = 0;
+ int msgbody_offset = 0;
#ifdef CONFIG_NETCONSOLE_DYNAMIC
extradata = nt->extradata_complete;
#endif
+ if (WARN_ON_ONCE(!extradata && extradata_len != 0))
+ return;
/* body_len represents the number of bytes that will be sent. This is
* bigger than MAX_PRINT_CHUNK, thus, it will be split in multiple
@@ -1575,7 +1578,6 @@ static void send_fragmented_body(struct netconsole_target *nt,
*/
while (offset < body_len) {
int this_header = header_len;
- bool msgbody_written = false;
int this_offset = 0;
int this_chunk = 0;
@@ -1584,55 +1586,28 @@ static void send_fragmented_body(struct netconsole_target *nt,
",ncfrag=%d/%d;", offset,
body_len);
- /* Not all msgbody data has been written yet */
- if (offset < msgbody_len) {
- this_chunk = min(msgbody_len - offset,
- MAX_PRINT_CHUNK - this_header);
- if (WARN_ON_ONCE(this_chunk <= 0))
- return;
- memcpy(nt->buf + this_header, msgbody + offset,
- this_chunk);
- this_offset += this_chunk;
- }
-
- /* msgbody was finally written, either in the previous
- * messages and/or in the current buf. Time to write
- * the extradata.
- */
- msgbody_written |= offset + this_offset >= msgbody_len;
-
- /* Msg body is fully written and there is pending extradata to
- * write, append extradata in this chunk
- */
- if (msgbody_written && offset + this_offset < body_len) {
- /* Track how much user data was already sent. First
- * time here, sent_userdata is zero
- */
- sent_extradata = (offset + this_offset) - msgbody_len;
- /* offset of bytes used in current buf */
- preceding_bytes = this_chunk + this_header;
-
- if (WARN_ON_ONCE(sent_extradata < 0))
- return;
-
- this_chunk = min(extradata_len - sent_extradata,
- MAX_PRINT_CHUNK - preceding_bytes);
- if (WARN_ON_ONCE(this_chunk < 0))
- /* this_chunk could be zero if all the previous
- * message used all the buffer. This is not a
- * problem, extradata will be sent in the next
- * iteration
- */
- return;
-
- memcpy(nt->buf + this_header + this_offset,
- extradata + sent_extradata,
- this_chunk);
- this_offset += this_chunk;
- }
+ /* write msgbody first */
+ this_chunk = min(msgbody_len - msgbody_offset,
+ MAX_PRINT_CHUNK - this_header);
+ memcpy(nt->buf + this_header, msgbody + msgbody_offset,
+ this_chunk);
+ msgbody_offset += this_chunk;
+ this_offset += this_chunk;
+
+ /* after msgbody, append extradata */
+ this_chunk = min(extradata_len - extradata_offset,
+ MAX_PRINT_CHUNK - this_header - this_offset);
+ memcpy(nt->buf + this_header + this_offset,
+ extradata + extradata_offset, this_chunk);
+ extradata_offset += this_chunk;
+ this_offset += this_chunk;
+
+ /* if all is good, send the packet out */
+ offset += this_offset;
+ if (WARN_ON_ONCE(offset > body_len))
+ return;
send_udp(nt, nt->buf, this_header + this_offset);
- offset += this_offset;
}
}
--
2.47.3
next prev parent reply other threads:[~2025-11-05 17:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-05 17:06 [PATCH net-next 0/4] netconsole: Allow userdata buffer to grow dynamically Gustavo Luiz Duarte
2025-11-05 17:06 ` Gustavo Luiz Duarte [this message]
2025-11-07 12:15 ` [PATCH net-next 1/4] netconsole: Simplify send_fragmented_body() Breno Leitao
2025-11-07 19:48 ` Gustavo Luiz Duarte
2025-11-05 17:06 ` [PATCH net-next 2/4] netconsole: Split userdata and sysdata Gustavo Luiz Duarte
2025-11-07 13:23 ` Breno Leitao
2025-11-07 20:53 ` Gustavo Luiz Duarte
2025-11-05 17:06 ` [PATCH net-next 3/4] netconsole: Dynamic allocation of userdata buffer Gustavo Luiz Duarte
2025-11-05 17:06 ` [PATCH net-next 4/4] netconsole: Increase MAX_USERDATA_ITEMS Gustavo Luiz Duarte
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251105-netconsole_dynamic_extradata-v1-1-142890bf4936@meta.com \
--to=gustavold@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=asantostc@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).