From patchwork Thu Oct 17 09:50:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13839747 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21CD71D958B; Thu, 17 Oct 2024 09:50:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158654; cv=none; b=L2NAZ4Oz0aA4NqYqB0jHo5/k1XG1jzZEl8pt1DuglYzrrMrhQD1UkVkfOINHFnBo3/WAKJGQl6vMXybT4qNDlKXFfGgGsI1W2w8zw3kaS3sCqUlOKg6TVG9EVhA9+T9KSsPMZ6cqWFY+/r+/dWDGRnXaqgOqlLu7ovpXqIx5L3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158654; c=relaxed/simple; bh=13oDv9K/TtdANIFyDZPCtxSwGQD8SejAzD84rs210cs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hT4hsCSk4vGwXaAsvBCXCsPWWtGpX29141bdcGd1Tgqf+roJ58VZrGz90dxpJnmOlSvTvg+mvCvvZducLGXvAHWdaC5l4x6CYFdhI4dhtOhiJeHAw+x6pfMf7UifqCZTBT1wIR8Tzmt0M10SJv3vulMDDFm5UePUUTTWufqQpFg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5c94c4ad9d8so1141251a12.2; Thu, 17 Oct 2024 02:50:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729158651; x=1729763451; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lUKUh9/c0jcVOB7NUuvJ159i2bkxlfNZskS7vvZp3VY=; b=IZSxLZVEhnwNoiX35QnbONPr8jm6AIZ6bGpOK+PDChGij8h+iaJmqmxO7ylQrTS/Z+ zc4ScUZ1iH58yJE9LCMH0BtLi2OB4mowHzojBhmpFNBbPg3nIVG4QCVwoMFIPKVH8FwK prIlTYi8+zKUWiRUr0qVlzIhoyaQCq/FDuGhkKjcFai7r66vhGo97GmmjLFsaibI8RwF OBuzCGGMcFEcBNUrjbdz2SlnRuUMUrb+GIqY1ekur/hXy1XCjiYqnXpEq1zl8kKoX+sA GneH1URlXyDd9PTMrsZ1/yJQWCP+tKEPOhT0W3o4Jc23ecRAKEbqYJE6qEmjdTzLXyJp 2rog== X-Forwarded-Encrypted: i=1; AJvYcCUeUcJEJ+PEHRUHgnngHaqPkOu+sQLMP+/NFgisCSQ//GS+IezDsQFUfpn6FZg1we4r8s/U28BnxsstGwM=@vger.kernel.org, AJvYcCVqdzq5HuTjxpsLI6jOK6bEi+7wiVEMNYEQ1lMIAIJjWbRvI+1K+qQcg6JZwNvuSaTg3OBj3qoZ@vger.kernel.org X-Gm-Message-State: AOJu0Yx+VA8erZ+2GGcLuY6KQ4CB0El0+KLV/mgbQBVMCIzJGH16lkFw 1mmnDkzPgk46PGjZB5oLN5nwMKfPLTs1sO24/28inGNHWQKZRoIg X-Google-Smtp-Source: AGHT+IGVu/dn/BdzmKxCnSpXlj5OYTnfNLE1a7yozVN6WAea37Uafy7xqpmHbejXysCYEp+ETifmwQ== X-Received: by 2002:a05:6402:254f:b0:5c9:7f8b:4e49 with SMTP id 4fb4d7f45d1cf-5c97f8b4f3bmr10148558a12.25.1729158651099; Thu, 17 Oct 2024 02:50:51 -0700 (PDT) Received: from localhost (fwdproxy-lla-115.fbsv.net. [2a03:2880:30ff:73::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c98d7b7da0sm2548486a12.95.2024.10.17.02.50.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 02:50:50 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com, kernel-team@meta.com Subject: [PATCH net-next v5 1/9] net: netconsole: remove msg_ready variable Date: Thu, 17 Oct 2024 02:50:16 -0700 Message-ID: <20241017095028.3131508-2-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241017095028.3131508-1-leitao@debian.org> References: <20241017095028.3131508-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Variable msg_ready is useless, since it does not represent anything. Get rid of it, using buf directly instead. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index de20928f7402..a006507c92c6 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1075,7 +1075,6 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, const char *header, *body; int offset = 0; int header_len, body_len; - const char *msg_ready = msg; const char *release; int release_len = 0; int userdata_len = 0; @@ -1105,8 +1104,7 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, MAX_PRINT_CHUNK - msg_len, "%s", userdata); - msg_ready = buf; - netpoll_send_udp(&nt->np, msg_ready, msg_len); + netpoll_send_udp(&nt->np, buf, msg_len); return; } From patchwork Thu Oct 17 09:50:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13839748 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ABF261DA614; Thu, 17 Oct 2024 09:50:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158656; cv=none; b=EJ3Ziwoi32IxWcvWpQluO0b/w5JXTRBSVEyMQscy1kUHieDXlPJLUPIDEOuzgkmLLwJtRbdQReKm9AQIjcHeEmJc1fU7Dsb090oTDaVQEZGY2whNx77x6W2bYcDBaU1m1WOHdVv20hv7xJ7fQopmfA2Uq2pOx37NCjWPuftEgBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158656; c=relaxed/simple; bh=Ln7Wzjg1uZeOz10ZJbtx8j92rBQDislaLmxEWlAnTww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=L33EulgY7LuKzVkUv3ppU2Zjne3UQyi6DQiWI9ddpJgBxBFH5uLT31v174Qe6tloQZLNAi2p6JwbQOpeQM06dR05ZlPUj2DFxWAxR1upi5m4UyOIAsEEEhe18lG9tINHr2GvdQ5jUVYHdds0GjTw9YLOAJoHqGYtKEWHZGnxXzA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a99cc265e0aso90624966b.3; Thu, 17 Oct 2024 02:50:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729158653; x=1729763453; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CgYUhnRG0TgPDVVw4Pl1Mc0WqgFJv0JtFsCOdF+IG2w=; b=RwxgV3TGxz5Vk8iCslx4G0lbM3THxFLw2NrKW2R2QATcEc3411mCF3Ql0ajfhK7u1s St9sEQUKFov8tAP7EWlkyzVG7pb3iImsFRpsbuuDo/K+clSQozdf25UCqoBByPrgdPY/ 9CbFjumB9ssW5ZxF8Z9lbnXtU5azhagJxsSaa8QwI0LPYLo6a2sHIuhpFe8ej46kuTJW vcz/f8Ao3SLKi6+/L4708e2qv2FoljcGHP/2gLrHT8veBSRIf1pi2YTcFfTWXFI4gpJq Gp2bqcxheixYdhZKr4wsSoQvFKto6J0tKQwgfxXzH/+uLN6MabwC3a7NPM4fuusJEGYW BVoA== X-Forwarded-Encrypted: i=1; AJvYcCVWNALpEtCekBMQfpOFFzWiVzFP+cXgsnJVNR+oTAKyHSAvo+Lygb+onLB73jBlc1pLDTpLPOjzj5TLy98=@vger.kernel.org, AJvYcCX/5RWWF6OCm4ktZifWeN34ZKnjCvWEsH6EsDo4JgQ1WH0EHMXVwlZgguGJT6bdeZ9KDCsCY0OA@vger.kernel.org X-Gm-Message-State: AOJu0Yxcs0iIL9h2sX/meBsytBuKgsNFB7e2FB1oh5vHvSFEyv16PvVc 1WHwZB4Q/7Z6b5t4DhW0xeL8SMTu42v6zGFKlgVpG7wykdNPpE1y X-Google-Smtp-Source: AGHT+IGKH13023E6QgXZHE+TX7zssFbvqD7qM/AU7CagTRDkoQjMeK/p9OvSYx8zcOjCL/OjDcWdXg== X-Received: by 2002:a17:907:d591:b0:a9a:296:b501 with SMTP id a640c23a62f3a-a9a34cfeb7bmr535226766b.26.1729158652858; Thu, 17 Oct 2024 02:50:52 -0700 (PDT) Received: from localhost (fwdproxy-lla-004.fbsv.net. [2a03:2880:30ff:4::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a2981828bsm275419966b.127.2024.10.17.02.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 02:50:52 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com, kernel-team@meta.com Subject: [PATCH net-next v5 2/9] net: netconsole: split send_ext_msg_udp() function Date: Thu, 17 Oct 2024 02:50:17 -0700 Message-ID: <20241017095028.3131508-3-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241017095028.3131508-1-leitao@debian.org> References: <20241017095028.3131508-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The send_ext_msg_udp() function has become quite large, currently spanning 102 lines. Its complexity, along with extensive pointer and offset manipulation, makes it difficult to read and error-prone. The function has evolved over time, and it’s now due for a refactor. To improve readability and maintainability, isolate the case where no message fragmentation occurs into a separate function, into a new send_msg_no_fragmentation() function. This scenario covers about 95% of the messages. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 46 +++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index a006507c92c6..23fe9edff26e 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1058,6 +1058,32 @@ static struct notifier_block netconsole_netdev_notifier = { .notifier_call = netconsole_netdev_event, }; +static void send_msg_no_fragmentation(struct netconsole_target *nt, + const char *msg, + const char *userdata, + int msg_len, + int release_len) +{ + static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ + const char *release; + + if (release_len) { + release = init_utsname()->release; + + scnprintf(buf, MAX_PRINT_CHUNK, "%s,%s", release, msg); + msg_len += release_len; + } else { + memcpy(buf, msg, msg_len); + } + + if (userdata) + msg_len += scnprintf(&buf[msg_len], + MAX_PRINT_CHUNK - msg_len, + "%s", userdata); + + netpoll_send_udp(&nt->np, buf, msg_len); +} + /** * send_ext_msg_udp - send extended log message to target * @nt: target to send message to @@ -1090,23 +1116,9 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, release_len = strlen(release) + 1; } - if (msg_len + release_len + userdata_len <= MAX_PRINT_CHUNK) { - /* No fragmentation needed */ - if (nt->release) { - scnprintf(buf, MAX_PRINT_CHUNK, "%s,%s", release, msg); - msg_len += release_len; - } else { - memcpy(buf, msg, msg_len); - } - - if (userdata) - msg_len += scnprintf(&buf[msg_len], - MAX_PRINT_CHUNK - msg_len, - "%s", userdata); - - netpoll_send_udp(&nt->np, buf, msg_len); - return; - } + if (msg_len + release_len + userdata_len <= MAX_PRINT_CHUNK) + return send_msg_no_fragmentation(nt, msg, userdata, msg_len, + release_len); /* need to insert extra header fields, detect header and body */ header = msg; From patchwork Thu Oct 17 09:50:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13839749 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 775561DA631; Thu, 17 Oct 2024 09:50:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158658; cv=none; b=roF4G6BoOmI6NRMHn6hkylDS57a7kd9I0Ts+Q+AlAIIPvyLYuYY1feFNPYYLTH1/OHw5MsYxqBFzlPnG3BI97ESi69Z3CehM2E2Tz4c6qhXb+hMNJF2V85u9VV/SouJG1h+nBZnvDNxbevVfGD5MIhqwq4aGSo/eoLc/tnN+GUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158658; c=relaxed/simple; bh=BnHwYa0SbUbnfkSuy88Y3YclLvpfhExheFHDqAN8daE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KuBPhhciSVbXlL8xQ1nbvn5RU25xszCrFhL60NwukbPMIKjF4IKIfVR9Ja1GtKbIVQAWZ2jaMRg+IhtOYbiert4BuuPvpVKPgjRz5h5vT4yKGWcmf2nPIg4eE5zIhFfQEvJvlw63Cejr4b9DqXM1i1/2Nz/BqDy+Tw8UIKGfyDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a99650da839so107726966b.2; Thu, 17 Oct 2024 02:50:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729158655; x=1729763455; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+Xvntjz3o+9G+2hN8EN93OP8C9G3Azh/Hv61LlOVr0Q=; b=HMTzf8dDIUeAgPX15xzABIt/2RfB6S87YwLjEORhxWOX91lNndlSmjdo/69ksQpYE4 fD9L7W2vddTT09e8OrOGZPZ3dH/ccrZh72h57pwBvaGg8mMz3JK8Ib55Gh2LnbvjAkj7 u47QXeDIVXtf3FbO2vIDjwwKXD61Sc4Q/0HXLm6D5KwZ+liwJnjAfrLLHd57kwqpHIHk atPTmLTXVSeYlOXdxR/KdsKd+gfftaOp/frn+grZS65PR+iGzTV/YTXI1rUjjDvm3RXk IsMamnbzRsA+xFBikCL2wyZAxfmP6/qMIisTynRQkqlCaJ5G18YHOhn8zwMyxlb98WJZ hdow== X-Forwarded-Encrypted: i=1; AJvYcCUJL3lKmH++pikbweF9A3pk+1+UlOtR+pKzzVKhv0Doh37a/zpVqE9ZkV5uEjOZi9EIPwM2o5XsBfXRsi8=@vger.kernel.org, AJvYcCX7hcJjiusixD1ztcylGpcUMTA99u+ncJ3BRHS78T5lvi5CfIR6aCrlsvN2xwecW6y9qYcApJuV@vger.kernel.org X-Gm-Message-State: AOJu0YxR7vTeO4FL/Ba3SrqkfYCLzQIFhCQODNKPHmsLyAeqVQCKdADP vnyy2EjXfIcxiDXaQJ8hDEy9EjVJ0Yv0ukuif5IFdsH3hivsrKN7 X-Google-Smtp-Source: AGHT+IErJtJxtn3qtUhd/tpPdbIH6rcN3bPvAL2fNX3mVTpza7W+Z7FpJWRaI+hYMNBKJyJFiWD76w== X-Received: by 2002:a17:907:9287:b0:a8a:8cdb:83a7 with SMTP id a640c23a62f3a-a99e3e96f26mr1726024266b.54.1729158654676; Thu, 17 Oct 2024 02:50:54 -0700 (PDT) Received: from localhost (fwdproxy-lla-008.fbsv.net. [2a03:2880:30ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a29850aa5sm274011966b.152.2024.10.17.02.50.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 02:50:54 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com, kernel-team@meta.com Subject: [PATCH net-next v5 3/9] net: netconsole: separate fragmented message handling in send_ext_msg Date: Thu, 17 Oct 2024 02:50:18 -0700 Message-ID: <20241017095028.3131508-4-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241017095028.3131508-1-leitao@debian.org> References: <20241017095028.3131508-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Following the previous change, where the non-fragmented case was moved to its own function, this update introduces a new function called send_msg_fragmented to specifically manage scenarios where message fragmentation is required. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 76 +++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 23fe9edff26e..6e916131c061 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1084,42 +1084,23 @@ static void send_msg_no_fragmentation(struct netconsole_target *nt, netpoll_send_udp(&nt->np, buf, msg_len); } -/** - * send_ext_msg_udp - send extended log message to target - * @nt: target to send message to - * @msg: extended log message to send - * @msg_len: length of message - * - * Transfer extended log @msg to @nt. If @msg is longer than - * MAX_PRINT_CHUNK, it'll be split and transmitted in multiple chunks with - * ncfrag header field added to identify them. - */ -static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, - int msg_len) +static void send_msg_fragmented(struct netconsole_target *nt, + const char *msg, + const char *userdata, + int msg_len, + int release_len) { static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ + int offset = 0, userdata_len = 0; const char *header, *body; - int offset = 0; int header_len, body_len; const char *release; - int release_len = 0; - int userdata_len = 0; - char *userdata = NULL; #ifdef CONFIG_NETCONSOLE_DYNAMIC - userdata = nt->userdata_complete; - userdata_len = nt->userdata_length; + if (userdata) + userdata_len = nt->userdata_length; #endif - if (nt->release) { - release = init_utsname()->release; - release_len = strlen(release) + 1; - } - - if (msg_len + release_len + userdata_len <= MAX_PRINT_CHUNK) - return send_msg_no_fragmentation(nt, msg, userdata, msg_len, - release_len); - /* need to insert extra header fields, detect header and body */ header = msg; body = memchr(msg, ';', msg_len); @@ -1134,11 +1115,18 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, * Transfer multiple chunks with the following extra header. * "ncfrag=/" */ - if (nt->release) + if (release_len) { + release = init_utsname()->release; scnprintf(buf, MAX_PRINT_CHUNK, "%s,", release); + } + + /* Copy the header into the buffer */ memcpy(buf + release_len, header, header_len); header_len += release_len; + /* for now on, the header will be persisted, and the body + * will be replaced + */ while (offset < body_len + userdata_len) { int this_header = header_len; int this_offset = 0; @@ -1190,6 +1178,38 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, } } +/** + * send_ext_msg_udp - send extended log message to target + * @nt: target to send message to + * @msg: extended log message to send + * @msg_len: length of message + * + * Transfer extended log @msg to @nt. If @msg is longer than + * MAX_PRINT_CHUNK, it'll be split and transmitted in multiple chunks with + * ncfrag header field added to identify them. + */ +static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, + int msg_len) +{ + char *userdata = NULL; + int userdata_len = 0; + int release_len = 0; + +#ifdef CONFIG_NETCONSOLE_DYNAMIC + userdata = nt->userdata_complete; + userdata_len = nt->userdata_length; +#endif + + if (nt->release) + release_len = strlen(init_utsname()->release) + 1; + + if (msg_len + release_len + userdata_len <= MAX_PRINT_CHUNK) + return send_msg_no_fragmentation(nt, msg, userdata, msg_len, + release_len); + + return send_msg_fragmented(nt, msg, userdata, msg_len, release_len); +} + static void write_ext_msg(struct console *con, const char *msg, unsigned int len) { From patchwork Thu Oct 17 09:50:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13839750 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72D981DCB06; Thu, 17 Oct 2024 09:50:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158660; cv=none; b=h+MsRFxcXjU6irpBsVNGymyCkQG49zdnwELNYpVv3oFM1EJNlYqC0Iwq7ofUg5ffg24GsAwDl1vX7qI6BDpj/rAOZJ911SQjBoVN4Iw1cZ9h+z4smcdCj5PrMbZsId60/bJLVCzwITjzpIMTdVBzf14oVm1fKthPuWGH++bhdvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158660; c=relaxed/simple; bh=zugCEIgehcbeB64o9FtqUvF0JsigTEtwDT0nye+0BQo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hAEPkWO7bQAq5zzqvaDK02LZdNSyyqp5RifrgNR2M7Jir8MBeMho5enCKDifcMy42u4mZSyRko8ym3zhPWmzKxyyUMggUAmXG/pwk2W8AsSkM9XTBW137tueCkzOArBufK0yAs/1FwouXFXNaO2Ysd8FT+W7ujU2J4wzWpME3uA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a99f646ff1bso94879966b.2; Thu, 17 Oct 2024 02:50:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729158657; x=1729763457; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cOJFb1agHKAShwLyoNXeyBzPMaJpkLOy9IhEQOkdcyA=; b=Tm+Tykl4C+vFChtPqcOkOhnkabUwG9jQlZJnso7sOgellDxPZ9Vq0agdGke6OyTnet 8JypsgERbPoLyvK3kj4y9mF9vt8zJPgnxSBTIyAHdXQ+JA0zXgH54WBHXAsByS6l8MX2 hBbKV7fP5FbU88I5eaERKR6yb+irVP+Q+K97VgOvXy3SkJUXelt9Z84NNZ8Jygv/EoPh q1XxnnCy4+vwLv8syu9mVcbLJcy4qe9lhNg3H4boI3KtGEhKc7K0pjMebDYyhAQUU0B7 Ha173Wmt2aIm5k+GsQlgXGvSoIEZ187R7X9aQr3vbBDR1afhD1r1B7Q3QLBlz5/CXVmY UZeA== X-Forwarded-Encrypted: i=1; AJvYcCUYa77rR/+P2oYiaA1NEoUmCP8OsakU9aFuO7FQyHjlLp95++YQy+t6KCtw6fi7lIkMD7bVtDjm@vger.kernel.org, AJvYcCWQFs53/g1cJWmga6QGlzUbXiP/2sHITeE8au6htzWZIiN2QNlQ6KjNKUQqoIwoaUeTSCOcLopxpV3Lh4s=@vger.kernel.org X-Gm-Message-State: AOJu0YwjijcDXRmXHCdT8yfxoAAf/FwgvL5FAHCJkT6AqgEMzQlWzzrA 6OX9gOp2PC0+OG1jp9xQtUY8kZ+mo9Xw2d8EwZxwMRAcWolXKKhw X-Google-Smtp-Source: AGHT+IFqikUWY8yuC4CPdaIlvvlImf1oB8c/wFj2eJXCHofLSN1rqZFTLGz1eVCxNngG63zrNO5DRQ== X-Received: by 2002:a17:907:3f8a:b0:a99:f605:7f1b with SMTP id a640c23a62f3a-a99f6058003mr1656132266b.60.1729158656495; Thu, 17 Oct 2024 02:50:56 -0700 (PDT) Received: from localhost (fwdproxy-lla-116.fbsv.net. [2a03:2880:30ff:74::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a29717ca8sm276916866b.44.2024.10.17.02.50.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 02:50:56 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com, kernel-team@meta.com Subject: [PATCH net-next v5 4/9] net: netconsole: rename body to msg_body Date: Thu, 17 Oct 2024 02:50:19 -0700 Message-ID: <20241017095028.3131508-5-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241017095028.3131508-1-leitao@debian.org> References: <20241017095028.3131508-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org With the introduction of the userdata concept, the term body has become ambiguous and less intuitive. To improve clarity, body is renamed to msg_body, making it clear that the body is not the only content following the header. In an upcoming patch, the term body_len will also be revised for further clarity. The current packet structure is as follows: release, header, body, [msg_body + userdata] Here, [msg_body + userdata] collectively forms what is currently referred to as "body." This renaming helps to distinguish and better understand each component of the packet. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 41 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 6e916131c061..3f59b841d659 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1092,8 +1092,8 @@ static void send_msg_fragmented(struct netconsole_target *nt, { static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ int offset = 0, userdata_len = 0; - const char *header, *body; - int header_len, body_len; + const char *header, *msgbody; + int header_len, msgbody_len; const char *release; #ifdef CONFIG_NETCONSOLE_DYNAMIC @@ -1101,15 +1101,15 @@ static void send_msg_fragmented(struct netconsole_target *nt, userdata_len = nt->userdata_length; #endif - /* need to insert extra header fields, detect header and body */ + /* need to insert extra header fields, detect header and msgbody */ header = msg; - body = memchr(msg, ';', msg_len); - if (WARN_ON_ONCE(!body)) + msgbody = memchr(msg, ';', msg_len); + if (WARN_ON_ONCE(!msgbody)) return; - header_len = body - header; - body_len = msg_len - header_len - 1; - body++; + header_len = msgbody - header; + msgbody_len = msg_len - header_len - 1; + msgbody++; /* * Transfer multiple chunks with the following extra header. @@ -1124,10 +1124,10 @@ static void send_msg_fragmented(struct netconsole_target *nt, memcpy(buf + release_len, header, header_len); header_len += release_len; - /* for now on, the header will be persisted, and the body + /* for now on, the header will be persisted, and the msgbody * will be replaced */ - while (offset < body_len + userdata_len) { + while (offset < msgbody_len + userdata_len) { int this_header = header_len; int this_offset = 0; int this_chunk = 0; @@ -1135,23 +1135,24 @@ static void send_msg_fragmented(struct netconsole_target *nt, this_header += scnprintf(buf + this_header, sizeof(buf) - this_header, ",ncfrag=%d/%d;", offset, - body_len + userdata_len); + msgbody_len + userdata_len); - /* Not all body data has been written yet */ - if (offset < body_len) { - this_chunk = min(body_len - offset, + /* 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(buf + this_header, body + offset, this_chunk); + memcpy(buf + this_header, msgbody + offset, this_chunk); this_offset += this_chunk; } - /* Body is fully written and there is pending userdata to write, - * append userdata in this chunk + + /* Msg body is fully written and there is pending userdata to + * write, append userdata in this chunk */ - if (offset + this_offset >= body_len && - offset + this_offset < userdata_len + body_len) { - int sent_userdata = (offset + this_offset) - body_len; + if (offset + this_offset >= msgbody_len && + offset + this_offset < userdata_len + msgbody_len) { + int sent_userdata = (offset + this_offset) - msgbody_len; int preceding_bytes = this_chunk + this_header; if (WARN_ON_ONCE(sent_userdata < 0)) From patchwork Thu Oct 17 09:50:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13839751 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2897C1DD520; Thu, 17 Oct 2024 09:51:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158662; cv=none; b=b6n+sG4F1YWMSNNIPh1lrT3tKsKkUZiUQwTC1Q5Qdnk3YDT4SBEl1Ufc+UoK93lCSmFJLndhdpV6BKLU5KXSEEz9bL5yh+VH90xmefaCMF/4Ob8+KVZfasyP2byWHEs7PipwqTwfFKvrNy6kcHtslZ12G728mSBosTm4p4rkqvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158662; c=relaxed/simple; bh=DlibL+TKZQO6tpM9TN61ilfGkoHxF5bxE7lVgrwGP/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IMUrWh3zRDQeqIBQJM86628TwHhObB/ZyfBLWns/tarW97G63XtFm7DISiaSx7waczDJIYN1bmnr1keM0Be0AvlBRt3TmA0xbiIb+3wBBpp1TOXm8Ypmy7+hWg+GPNKfcDUPGDMzTgtzVFbPRklBllVP3v8dTtfVzuXxBukG6KQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-5c9428152c0so950512a12.1; Thu, 17 Oct 2024 02:51:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729158659; x=1729763459; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A70dRnWs3e7CjR+g318TfrfK6CTl+FDvGZYubUStoxw=; b=Gckk+WWb/gII6c2YpV+iS4gu30LdM+YhF6L8mkbcsCf/O4R/YctFMcvDN1cZ8VAtQF p1Hejmd/dxIbplJfBbUy5G2X9cBZh1MPthO1mVQWCEKxBByHRoED1Mz4uOnOhtEsicSR ukYMtUYW2IjYyIO5p9kirzUgZx63N4cjVZ3FIFYGir59VvVa8wY61lGtbudkWovQFY7M Ewco688+1j4joC0pFGIE4nzbAXQtMtQR+0cMGuQaqknBBaV6wzRMgOZzJm696C+sRl4N d+hPyw3BmhM9D55K7EvrsIZBPQdYsAlBU3qyxdBW/m+fxBLrVSoiaPaPNAK921+0seOF 7mOw== X-Forwarded-Encrypted: i=1; AJvYcCVBz/kVQt1dzI1M9F0UJb17AYxtQG7YsnlO4en1CanQwuEerYZtmMtCJlXidAVioWc3HP/DZ3hn4FlU1Ps=@vger.kernel.org, AJvYcCX4+MTw5O7GAkx0xyVO+Vw5EMhi72Shug5yRsOhJks+2dM0AMznXtTAoS//y3tuRvx4ACV1tKGe@vger.kernel.org X-Gm-Message-State: AOJu0YyReeqdLCSstqRfU/rkMvAXdJHSpVBS/AL2AyMUWUEjG2/6jnaz AkkiOKlV9WNyJZimqfgD+lU/5hx5mbrDQXLiCNPuCv1B9l07bAna X-Google-Smtp-Source: AGHT+IHgBrNUNt9pWuE6OKsaGLrZFWsECCvUdzBJlFBMremSPxwLuNI9TXOvYhumBva5l/qA4AIfjw== X-Received: by 2002:a05:6402:2714:b0:5c8:8d5e:19b0 with SMTP id 4fb4d7f45d1cf-5c995121654mr5881806a12.30.1729158659158; Thu, 17 Oct 2024 02:50:59 -0700 (PDT) Received: from localhost (fwdproxy-lla-004.fbsv.net. [2a03:2880:30ff:4::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c98d7b7be8sm2548554a12.97.2024.10.17.02.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 02:50:58 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com, kernel-team@meta.com Subject: [PATCH net-next v5 5/9] net: netconsole: introduce variable to track body length Date: Thu, 17 Oct 2024 02:50:20 -0700 Message-ID: <20241017095028.3131508-6-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241017095028.3131508-1-leitao@debian.org> References: <20241017095028.3131508-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org This new variable tracks the total length of the data to be sent, encompassing both the message body (msgbody) and userdata, which is collectively called body. By explicitly defining body_len, the code becomes clearer and easier to reason about, simplifying offset calculations and improving overall readability of the function. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 3f59b841d659..6a6806eeb0c6 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1090,10 +1090,10 @@ static void send_msg_fragmented(struct netconsole_target *nt, int msg_len, int release_len) { + int header_len, msgbody_len, body_len; static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ int offset = 0, userdata_len = 0; const char *header, *msgbody; - int header_len, msgbody_len; const char *release; #ifdef CONFIG_NETCONSOLE_DYNAMIC @@ -1124,10 +1124,11 @@ static void send_msg_fragmented(struct netconsole_target *nt, memcpy(buf + release_len, header, header_len); header_len += release_len; + body_len = msgbody_len + userdata_len; /* for now on, the header will be persisted, and the msgbody * will be replaced */ - while (offset < msgbody_len + userdata_len) { + while (offset < body_len) { int this_header = header_len; int this_offset = 0; int this_chunk = 0; @@ -1135,7 +1136,7 @@ static void send_msg_fragmented(struct netconsole_target *nt, this_header += scnprintf(buf + this_header, sizeof(buf) - this_header, ",ncfrag=%d/%d;", offset, - msgbody_len + userdata_len); + body_len); /* Not all msgbody data has been written yet */ if (offset < msgbody_len) { @@ -1151,7 +1152,7 @@ static void send_msg_fragmented(struct netconsole_target *nt, * write, append userdata in this chunk */ if (offset + this_offset >= msgbody_len && - offset + this_offset < userdata_len + msgbody_len) { + offset + this_offset < body_len) { int sent_userdata = (offset + this_offset) - msgbody_len; int preceding_bytes = this_chunk + this_header; From patchwork Thu Oct 17 09:50:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13839752 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B14561DD556; Thu, 17 Oct 2024 09:51:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158665; cv=none; b=uw5XMZZBppvpPFm8btv58tL9QYb2Qirov2R+Xt+7VKsiRhfdV1pYm2ol5J4YHw4bHzrjAZlA4ArMQZkVXg8tyqJDLgInjfHP24Mu19rsfSAI9sz/yN7NLK/yGx7mh4DdfrU86fwVoYx+LBW/Ix506u9uUX9VDs6MlXxcdDaGRrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158665; c=relaxed/simple; bh=n/vjjkCbkFWQWl9HAYwVUViUNHDXTzrYAj4MUYQhlp0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BtdoKAplDKYoDAr42KS6pwi4kF8aEo4o0NXJsqLR7Y2RwhgVlzWrAWWqj7cpenMPffWHhRPSQSUKEu2876Co0M1cR2pc997iYulRBCijFtgaEN9LY9tvDuVV9fvcOLTPYpXjd7aEyDB/lXT5Nz4xGZIJS14Dygz2ZZvHis/JDGE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a99ea294480so46075466b.2; Thu, 17 Oct 2024 02:51:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729158662; x=1729763462; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mjpe0l3bZlOokvZFmHO4Q8i0x69QhLwteNPZIJVaTNA=; b=SG3HdkvA8OlWeDVcD55DqhkHXpzqPmqGK6KOwoibUXe+cLrCQuS9YIryzIHh1HXzx1 cZVE9syOnPbhQLew6eBm+Wb8hdZZW1WYI0CTgtoLM4IZ4EaQtX1s9b6Av/WXZeRICb4T MjUw9H67/PrWf87T20zs/BWAca4vtrDtf00zELL3bMdZTNxhkyLo7GR7vIf9craFVXRl Z9aTdLi46zDjCoIZfM4D1uecc18uISAi5XTBdTSaPPCm/msxbhf76FzEC2k3Hzp0YnFY Ozfz49orJXuWX5PgILK5F0Xcj6v6xip6zYWrj01g7Fpk/a1RMcdFjnvxKqEx4XLfbe4G oJhA== X-Forwarded-Encrypted: i=1; AJvYcCWXKoVaIQp3fnPYDJEOssTZ2hNQQzc6eCrqV2YdCXfklrHf10IDBCvf8/Lrnr5FYxfiO1VusGIk@vger.kernel.org, AJvYcCXYv0urBPxfiJVjVahO/8JSb1lyBBWY/t6kHrRxsGt6F/mD5/XF3nPSGHKU7YlrN+EmMOoVBC8drNNrxjc=@vger.kernel.org X-Gm-Message-State: AOJu0YzDoqeDYQoyo6pbgtrXc5EWFXUYfm6UvV+0m9gulHTyxOKhx1MH R9TB8AZ3yaoz5PFxS9r0A3BP3vRayNJtSCNXTHlAh1kJIfP68f+O X-Google-Smtp-Source: AGHT+IHPNT63pIiuPQp/GQpvdv5R++QjmXNxV01vuUJwVMGSC7UFId+a9gsOcviSMqQ4q4OXskdMCA== X-Received: by 2002:a05:6402:370a:b0:5c9:44bc:f9b3 with SMTP id 4fb4d7f45d1cf-5c95ac15792mr20538206a12.11.1729158661786; Thu, 17 Oct 2024 02:51:01 -0700 (PDT) Received: from localhost (fwdproxy-lla-004.fbsv.net. [2a03:2880:30ff:4::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c98d4f8b92sm2563706a12.27.2024.10.17.02.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 02:51:00 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com, kernel-team@meta.com Subject: [PATCH net-next v5 6/9] net: netconsole: track explicitly if msgbody was written to buffer Date: Thu, 17 Oct 2024 02:50:21 -0700 Message-ID: <20241017095028.3131508-7-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241017095028.3131508-1-leitao@debian.org> References: <20241017095028.3131508-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The current check to determine if the message body was fully sent is difficult to follow. To improve clarity, introduce a variable that explicitly tracks whether the message body (msgbody) has been completely sent, indicating when it's time to begin sending userdata. Additionally, add comments to make the code more understandable for others who may work with it. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 6a6806eeb0c6..9a5cca4ee8b8 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1130,6 +1130,7 @@ static void send_msg_fragmented(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; @@ -1148,12 +1149,21 @@ static void send_msg_fragmented(struct netconsole_target *nt, this_offset += this_chunk; } + /* msgbody was finally written, either in the previous + * messages and/or in the current buf. Time to write + * the userdata. + */ + msgbody_written |= offset + this_offset >= msgbody_len; + /* Msg body is fully written and there is pending userdata to * write, append userdata in this chunk */ - if (offset + this_offset >= msgbody_len && - offset + this_offset < body_len) { + if (msgbody_written && offset + this_offset < body_len) { + /* Track how much user data was already sent. First + * time here, sent_userdata is zero + */ int sent_userdata = (offset + this_offset) - msgbody_len; + /* offset of bytes used in current buf */ int preceding_bytes = this_chunk + this_header; if (WARN_ON_ONCE(sent_userdata < 0)) From patchwork Thu Oct 17 09:50:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13839753 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 942A71DD86C; Thu, 17 Oct 2024 09:51:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158667; cv=none; b=RAldMvEqWyjobQvCY6JASqURDwfQKXvIUcVIw7CmIzvcMysqBCcz+C1pXdgXNEpwCKMc6fOtjIBZuxiUEodI4qX6E9w4aFb3zts1ntQlELWizNHfMEEQW+AQAYtZQb2NvjHXyWoSoP9hSGejkZkL78nSqHOdOI2yelhPiaNtyPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158667; c=relaxed/simple; bh=mQpC7YgB+kq1ZruSzdGLaLBqEEwfjlPwVeWJnpWWNoE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oa9IQEA93bw9JBdCPTcwpFGnLhYqGReCvC4lXxXz21HXr5zStNTuvZsc0rDEBia9aEvYq9DDAwQ2YCpu06IocvZzBe05SaBcF81UnruZ1kA0lzl1UuwRkio2Ir+OFG7ZPYD/RVQHnIFYLsnK2zZLZLbDQYnfYEgqrYM/1jx/ep8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2fb561f273eso7160071fa.2; Thu, 17 Oct 2024 02:51:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729158664; x=1729763464; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Hn3d5DrrbfnZw+8+PLA51MpHzKJn4lcgJlRW9cmouQs=; b=ugT7DMAkLUcbCbEYht7jJagYR+3s4b66IUwRjw5y9LogOH8RoUElgKUjrt4ApqH6q8 KbnI8br7kyQAgwiYWPgBnSHYaLpyqCxrCwAu3b5qrjOojHU5kgaHyj+fDQcPcFj/m6Qr Bh69u9M0LEirAPb8LMgXr1eW8XslgwH11QYzhkYn5EJHi389D2xgxn7w42kLwF5e8Y9t Y58qPYQzbMmPKWPh+8vmzaXCzNRhjooxdtSiRszrJ3z6WNynqBMDM5Xgr94PlRcjRgXa 7L9BRyd6NdwiRYGkfSZhb2AnUpkULWoWxVjx2yTgzgGIIm/0us4RBSWPav6+fEoxKs3T q1dA== X-Forwarded-Encrypted: i=1; AJvYcCWEgFxt5lp/yjEwmulWXIazEGm8pTMrpSDPmFQaKFNGDKwdYhFiKTDSWvN1lzZhJ2zPEvoxzwz6DS2t1tw=@vger.kernel.org, AJvYcCWlRMnr/JikpXlvaGOW8Xi4+dZP7zQUIa88R+ZKOgVO9YFbaSHvETXsOO77SV4CyLSPMVph3Kxb@vger.kernel.org X-Gm-Message-State: AOJu0YyKiXB6gdoi1gRFVW6Zd6iq3ra4uInC7m7imFlNhLLqveY+wFGp Xv3mo4z9lBfXikDTGLQzLhXFRt7IJ63lddIobIl+McsgphoPrlhR X-Google-Smtp-Source: AGHT+IFa3YWVHSYU+4G/aPkDrpr5t2bDTp/QkCYC8GdBQSYAJJmQiHsb+dlsWyXpknKVHapSBkUzMQ== X-Received: by 2002:a2e:a986:0:b0:2fb:4c5c:3f7d with SMTP id 38308e7fff4ca-2fb4c5c40e0mr84002081fa.5.1729158663573; Thu, 17 Oct 2024 02:51:03 -0700 (PDT) Received: from localhost (fwdproxy-lla-005.fbsv.net. [2a03:2880:30ff:5::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c98d4f9416sm2557858a12.35.2024.10.17.02.51.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 02:51:03 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com, kernel-team@meta.com Subject: [PATCH net-next v5 7/9] net: netconsole: extract release appending into separate function Date: Thu, 17 Oct 2024 02:50:22 -0700 Message-ID: <20241017095028.3131508-8-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241017095028.3131508-1-leitao@debian.org> References: <20241017095028.3131508-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Refactor the code by extracting the logic for appending the release into the buffer into a separate function. The goal is to reduce the size of send_msg_fragmented() and improve code readability. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 9a5cca4ee8b8..e86a857bc166 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1084,6 +1084,14 @@ static void send_msg_no_fragmentation(struct netconsole_target *nt, netpoll_send_udp(&nt->np, buf, msg_len); } +static void append_release(char *buf) +{ + const char *release; + + release = init_utsname()->release; + scnprintf(buf, MAX_PRINT_CHUNK, "%s,", release); +} + static void send_msg_fragmented(struct netconsole_target *nt, const char *msg, const char *userdata, @@ -1094,7 +1102,6 @@ static void send_msg_fragmented(struct netconsole_target *nt, static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ int offset = 0, userdata_len = 0; const char *header, *msgbody; - const char *release; #ifdef CONFIG_NETCONSOLE_DYNAMIC if (userdata) @@ -1115,10 +1122,8 @@ static void send_msg_fragmented(struct netconsole_target *nt, * Transfer multiple chunks with the following extra header. * "ncfrag=/" */ - if (release_len) { - release = init_utsname()->release; - scnprintf(buf, MAX_PRINT_CHUNK, "%s,", release); - } + if (release_len) + append_release(buf); /* Copy the header into the buffer */ memcpy(buf + release_len, header, header_len); From patchwork Thu Oct 17 09:50:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13839754 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BD8D1DDA1E; Thu, 17 Oct 2024 09:51:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158668; cv=none; b=JKPruj7+AwbaQDPapEtI8uvpKBb5OaoQq5ve9gc0we8w+s/1aZX8Eel88KU2eCBff2gxTsx17rIbYYOUgl/tU5a1my5aYKFt69FqQLcnd55sKi/TXiCmafcCQRvEFvS98EDDwZZZQbpCtU0WF2LvU1pzDwyADzFv34WVXIg+bYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158668; c=relaxed/simple; bh=CK6YVX7DrhvqsRMXrMk7N8jXqOjvz5bNUqayjvuoHek=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PqAWxMF4FOnIKt4y/1gzb8+zktnZ7IBN1IM+WLYkhtvQU2jpHaxTyJqx04nAJr1Ev6QeX2m0xPSWxQcjCZv1cBRtJhjCBSeZ/5RnJYglT2yumh7MsYzaxMEDzUGvjSjydP3hTk5IBvFYK4AOeU2etl1Gw9FfXDeQn9BpCINfkM4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a99cc265e0aso90655866b.3; Thu, 17 Oct 2024 02:51:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729158665; x=1729763465; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DMa9T4GRybMuiSZbSNjPfnUtfOBoz1IdxikzoXqbnME=; b=UY05XAXtbWz5ie5RJqovrwP7LotZphMB8U3FpTxQchBtRoBs+SAd6vHiYXCOWEjS7q 6PxBMg5BGkA84QvFqoeVlo7sHHsVvixcFl3NkG80u3CDHvK2X2FfVdfrNPLqLRkseiqI V208cvZGhGXh6Z4vRU7XzpFwsPy45zqQx2mJGOsL0uoYXnGj2Lcb629lWs7qsdGP4T2n aRvUyG9C8SKbWJK85vXT/4p0yu6aqB1KqIYebyz0V85E4ccwKEjwWZHpqFiVGPeFIozh /JJMdpO+UieROfjhlu0lUFoXw1GFQyuo4UMld/CftjaoU6fjOBHOue5osVY9KHDHCeUg 8T4A== X-Forwarded-Encrypted: i=1; AJvYcCUi3nYrWkTqeF8jo4Mkeorxe3f592uDX3Mcl3t2yTK71zYPmTufBQqKfxZReLRvw4zr17PGTYIm@vger.kernel.org, AJvYcCVdybOj2cOI0WuT5vEbrjOSWZp0thsHP1ciZw/0LlP7ErikR92VxjSG1FrH+6iWqNkBBwbcwnOJn2FUkZ0=@vger.kernel.org X-Gm-Message-State: AOJu0YzQyH/i+OlDmhrzcMdOjDMeBw/quhVJzugU9mPFpsdy6pTthyKT IZL3qa1oqh6s8AoOd7bubt1J8wgWR+eWXvXK9dXl8izquIfdarYp X-Google-Smtp-Source: AGHT+IEBJWX1Qsqdjfs5888W8eeR8qgYZe5327bEqWvzvSaplKe63qpSpB17OPBrqaeBMG9Z4E8tAA== X-Received: by 2002:a17:907:3f9e:b0:a86:8e3d:86e2 with SMTP id a640c23a62f3a-a9a34c8357fmr582735066b.11.1729158665339; Thu, 17 Oct 2024 02:51:05 -0700 (PDT) Received: from localhost (fwdproxy-lla-001.fbsv.net. [2a03:2880:30ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a2971b0bfsm279935166b.10.2024.10.17.02.51.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 02:51:04 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com, kernel-team@meta.com Subject: [PATCH net-next v5 8/9] net: netconsole: do not pass userdata up to the tail Date: Thu, 17 Oct 2024 02:50:23 -0700 Message-ID: <20241017095028.3131508-9-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241017095028.3131508-1-leitao@debian.org> References: <20241017095028.3131508-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Do not pass userdata to send_msg_fragmented, since we can get it later. This will be more useful in the next patch, where send_msg_fragmented() will be split even more, and userdata is only necessary in the last function. Suggested-by: Simon Horman Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index e86a857bc166..b04d86fcea8f 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1060,13 +1060,17 @@ static struct notifier_block netconsole_netdev_notifier = { static void send_msg_no_fragmentation(struct netconsole_target *nt, const char *msg, - const char *userdata, int msg_len, int release_len) { static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ + const char *userdata = NULL; const char *release; +#ifdef CONFIG_NETCONSOLE_DYNAMIC + userdata = nt->userdata_complete; +#endif + if (release_len) { release = init_utsname()->release; @@ -1094,7 +1098,6 @@ static void append_release(char *buf) static void send_msg_fragmented(struct netconsole_target *nt, const char *msg, - const char *userdata, int msg_len, int release_len) { @@ -1102,10 +1105,11 @@ static void send_msg_fragmented(struct netconsole_target *nt, static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ int offset = 0, userdata_len = 0; const char *header, *msgbody; + const char *userdata = NULL; #ifdef CONFIG_NETCONSOLE_DYNAMIC - if (userdata) - userdata_len = nt->userdata_length; + userdata = nt->userdata_complete; + userdata_len = nt->userdata_length; #endif /* need to insert extra header fields, detect header and msgbody */ @@ -1208,12 +1212,10 @@ static void send_msg_fragmented(struct netconsole_target *nt, static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, int msg_len) { - char *userdata = NULL; int userdata_len = 0; int release_len = 0; #ifdef CONFIG_NETCONSOLE_DYNAMIC - userdata = nt->userdata_complete; userdata_len = nt->userdata_length; #endif @@ -1221,10 +1223,9 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, release_len = strlen(init_utsname()->release) + 1; if (msg_len + release_len + userdata_len <= MAX_PRINT_CHUNK) - return send_msg_no_fragmentation(nt, msg, userdata, msg_len, - release_len); + return send_msg_no_fragmentation(nt, msg, msg_len, release_len); - return send_msg_fragmented(nt, msg, userdata, msg_len, release_len); + return send_msg_fragmented(nt, msg, msg_len, release_len); } static void write_ext_msg(struct console *con, const char *msg, From patchwork Thu Oct 17 09:50:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13839755 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F20091DDC17; Thu, 17 Oct 2024 09:51:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158670; cv=none; b=ahYiU2/e5+aCqZMWO7RU1Y3S9m2L8J2p3b8oaCHUyTaBm8AicKsT7MGCfZdfh493FbTtFIgSoNQ7HrQKspXwsz1YW7mUOq7E4E3ttTW1lcGTVmAEBmNK2MO4d3B8z9Y2n5xtDwE9/vlxu7GN7LVII1dZ9LpbYQhp2F/ctcHnpKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729158670; c=relaxed/simple; bh=699IaAmYxIBG1woipqR1z8uM7YOd2b7Yuffv+L/zraM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bJCOdGI9K+L4apyBgI+4L5FuuKIeN+S1+9kAECMRxvhU4D9RMmqAs3gXoBQP3TwxZVmmmvGVFlOvNbWAaXOVVv3/zENnjVR3IDDw9uP9oGZXshjjvcpQ0dgwYUsZCzzFuxVNnjfi5S1fcC5YbaYl7uGVY+ewBf6a62NwxaO3P9I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5c97c7852e8so1084217a12.1; Thu, 17 Oct 2024 02:51:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729158667; x=1729763467; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O/6ZZ3fgX1aNbuNd43s/ViNH42DOc1z9jRYfEzzfadM=; b=Xf3zZqqUKinGVB7n3d0ZPBxPrm80k84RyU17h+lMnnzpDsxIJqlgtPqiGI5LaX32bP QIS3rydZgiHKmBA1DKGA6HF6/whje/NI1lsFHeCrMkGZOhqpr55/S/VzroOK2LK5yxYH sl4v49q1UiFTuuFIikXOBnsC8Z5MPOqcgHbG+jweWOyc9IOjkU1NtVgEZ/amDk+6bW0q gp3mrUXn73YEmegpGnfnjGImrkGB0k1RBk7lIgCPHnAEEbmytWla5nBBabWOQ4VHqXlR MD800NOaCtEzRaUwz+kyjstMuOctbMsMCjc+rLhUWHo4udlbbfxOubbGVRgWSYkbYlKV MqWQ== X-Forwarded-Encrypted: i=1; AJvYcCW9xGPgWcHDeBR1sxQlHGQRjRDw0YUcQPNUePIeVZdw0oK23vFK/K/E4b7GCifcABSf6s9Tn6nE@vger.kernel.org, AJvYcCX6+sHbNWBvvkWAbj86+jxgd/wlYFdp1GUUR9+WePv5fjbT4otTZGjaFLYbpoG5LLAogTmRNWoGDxPgr/I=@vger.kernel.org X-Gm-Message-State: AOJu0YxWY8F95lDSU/qtoZVav2yvDS7ev36x3axCAwEh3Tudk64N7pBJ T92JsuHcJZ0u3mPAJWi3ploQYnuDDfx4WDX+i0+f7MRgGQwwT05d X-Google-Smtp-Source: AGHT+IGVmZJFxUCl5y/vCznK/RrczOuJRB6CfDSZ3aazuktdwRwJeLo9ncUAyLmFtaMQ+miUOTxvAQ== X-Received: by 2002:a17:907:3f1a:b0:a9a:19c8:740c with SMTP id a640c23a62f3a-a9a19c876a7mr1102779066b.47.1729158667133; Thu, 17 Oct 2024 02:51:07 -0700 (PDT) Received: from localhost (fwdproxy-lla-112.fbsv.net. [2a03:2880:30ff:70::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a29844899sm277175566b.178.2024.10.17.02.51.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2024 02:51:06 -0700 (PDT) From: Breno Leitao To: kuba@kernel.org, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com Cc: thepacketgeek@gmail.com, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, davej@codemonkey.org.uk, vlad.wing@gmail.com, max@kutsevol.com, kernel-team@meta.com Subject: [PATCH net-next v5 9/9] net: netconsole: split send_msg_fragmented Date: Thu, 17 Oct 2024 02:50:24 -0700 Message-ID: <20241017095028.3131508-10-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241017095028.3131508-1-leitao@debian.org> References: <20241017095028.3131508-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Refactor the send_msg_fragmented() function by extracting the logic for sending the message body into a new function called send_fragmented_body(). Now, send_msg_fragmented() handles appending the release and header, and then delegates the task of breaking up the body and sending the fragments to send_fragmented_body(). This is the final flow now: When send_ext_msg_udp() is called to send a message, it will: - call send_msg_no_fragmentation() if no fragmentation is needed or - call send_msg_fragmented() if fragmentation is needed * send_msg_fragmented() appends the header to the buffer, which is be persisted until the function returns * call send_fragmented_body() to iterate and populate the body of the message. It will not touch the header, and it will only replace the body, writing the msgbody and/or userdata. Also add some comment to make the code easier to review. Signed-off-by: Breno Leitao Reviewed-by: Simon Horman --- drivers/net/netconsole.c | 81 +++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index b04d86fcea8f..4ea44a2f48f7 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1096,46 +1096,30 @@ static void append_release(char *buf) scnprintf(buf, MAX_PRINT_CHUNK, "%s,", release); } -static void send_msg_fragmented(struct netconsole_target *nt, - const char *msg, - int msg_len, - int release_len) +static void send_fragmented_body(struct netconsole_target *nt, char *buf, + const char *msgbody, int header_len, + int msgbody_len) { - int header_len, msgbody_len, body_len; - static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ - int offset = 0, userdata_len = 0; - const char *header, *msgbody; const char *userdata = NULL; + int body_len, offset = 0; + int userdata_len = 0; #ifdef CONFIG_NETCONSOLE_DYNAMIC userdata = nt->userdata_complete; userdata_len = nt->userdata_length; #endif - /* need to insert extra header fields, detect header and msgbody */ - header = msg; - msgbody = memchr(msg, ';', msg_len); - if (WARN_ON_ONCE(!msgbody)) - return; - - header_len = msgbody - header; - msgbody_len = msg_len - header_len - 1; - msgbody++; - - /* - * Transfer multiple chunks with the following extra header. - * "ncfrag=/" + /* 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 + * packets */ - if (release_len) - append_release(buf); - - /* Copy the header into the buffer */ - memcpy(buf + release_len, header, header_len); - header_len += release_len; - body_len = msgbody_len + userdata_len; - /* for now on, the header will be persisted, and the msgbody - * will be replaced + + /* In each iteration of the while loop below, we send a packet + * containing the header and a portion of the body. The body is + * composed of two parts: msgbody and userdata. We keep track of how + * many bytes have been sent so far using the offset variable, which + * ranges from 0 to the total length of the body. */ while (offset < body_len) { int this_header = header_len; @@ -1144,7 +1128,7 @@ static void send_msg_fragmented(struct netconsole_target *nt, int this_chunk = 0; this_header += scnprintf(buf + this_header, - sizeof(buf) - this_header, + MAX_PRINT_CHUNK - this_header, ",ncfrag=%d/%d;", offset, body_len); @@ -1199,6 +1183,41 @@ static void send_msg_fragmented(struct netconsole_target *nt, } } +static void send_msg_fragmented(struct netconsole_target *nt, + const char *msg, + int msg_len, + int release_len) +{ + static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */ + int header_len, msgbody_len; + const char *msgbody; + + /* need to insert extra header fields, detect header and msgbody */ + msgbody = memchr(msg, ';', msg_len); + if (WARN_ON_ONCE(!msgbody)) + return; + + header_len = msgbody - msg; + msgbody_len = msg_len - header_len - 1; + msgbody++; + + /* + * Transfer multiple chunks with the following extra header. + * "ncfrag=/" + */ + if (release_len) + append_release(buf); + + /* Copy the header into the buffer */ + memcpy(buf + release_len, msg, header_len); + header_len += release_len; + + /* for now on, the header will be persisted, and the msgbody + * will be replaced + */ + send_fragmented_body(nt, buf, msgbody, header_len, msgbody_len); +} + /** * send_ext_msg_udp - send extended log message to target * @nt: target to send message to