Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1274342rdb; Wed, 24 Jan 2024 09:51:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFLVg5679vKwbMDNOu4v6y4R+trA2/exiiQoKedHgV8Q25lblJDoGDRejESSOvaysd2gHWc X-Received: by 2002:ae9:ee02:0:b0:783:908d:943f with SMTP id i2-20020ae9ee02000000b00783908d943fmr7700653qkg.16.1706118693254; Wed, 24 Jan 2024 09:51:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706118693; cv=pass; d=google.com; s=arc-20160816; b=GzddULA9/VeYiSTsxBVHd8/W7WBFfr4P7PvLs2GxDS2+3pK79mPVJAgP/mtIiUzqw0 NufLiSIBSB4DDzsueMjwqtnUhF9PbAPzedYf7oWbAhr1fppzb+1R+vCFY7Y1rLb2FXjw lqq8WYWmNylEOKcjNU5i++kH4nsxBq4F685Lta5ryh7pwsOpCLV9GTxOyWHqwZSG5w+p NTY9gPWDEIs4ovst1d6Wc8z4+2PstCNHZEbQWEqca9HKLHjCNsU/X0p2MMebsqkBwdWR 5l1FZqGeYVFwLijydkzS8t2aSZDWFqeJXW1VkZkj9MeN9ui+ZvHf1P94wVNby98Y4DTO jXyg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=6yr4N28qTdreJQILPMIL8Vba8ZMs6hXrf/fYG9mRvfk=; fh=+EB6oBnXtBrxaPMIm1rb1kOyvjkddCLSgL4/UeSWQvM=; b=RGufMm2qRvKMXMQa6LutizLd4PGdjPv6jYwpzUTVrnFKMf35WJXUh1OZKIcI1yxIpz Qf4gvQgyUA8cCGb/WpVn70+VK4ah18fjisGbFUTGAGTR569cJQKWCqxGLzjIhfIDcQBN KT9Wqx5YA8iYede43skQcLl73BO+ZfYaebk7L6+5ztgODPCgrVWinXwT0qXVwA3jdkbD xU4k+LZ02MlXldZcnpYuH0kZBxiE5hcMpViJaLLW7p1zjMjF4hUpS4XIYlCI/R6UV+tz v2c9C/Pq+6CuhfIlL7NNrWUTQQhbn0JqrjN4fhSD6ArdcrCYaBWlsLLBSi6lP8KZLdF7 2ZAw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Gh+1Hasm; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-37461-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37461-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id j13-20020ae9c20d000000b007836dbd60d3si10254616qkg.129.2024.01.24.09.51.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 09:51:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37461-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Gh+1Hasm; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-37461-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37461-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 48D271C22D32 for ; Wed, 24 Jan 2024 17:50:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3091712BF10; Wed, 24 Jan 2024 17:47:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Gh+1Hasm" Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (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 7F48E12BE82; Wed, 24 Jan 2024 17:47:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706118448; cv=none; b=VB/Rm0scIPpH/xV1vFVUUYyfiGUHcbzR5R0mv7e+sY7lYHgwXxBkTuIUO3AiqV0T0AWVBWJFT6riLB+xwvStfyX3UfCk8XovKkaD9KZvz1b/zEFgwQch5RnKYRBXOJPz2MziQ4ASAvnjmhwV8quKxZvCAzGzFYl3VZQwljfqwoM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706118448; c=relaxed/simple; bh=Jjv/TuEFrl542Uz2oPY2+FJwkmzA1uzPImxNDC4FnrI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gz9DcnNP9cuXwMqSVvqqPzaoLaV6BvUxiSL5YTRurTuv8FFUVCmHdD8o57jIyWe/snMelhq8jBg8Hu9LFQc7VbP0SsYwYFdVz7KYC8BrTp1lLSbACJrpNBXPF2iw8YsixVDxIW/vMyEiA+MKasS3kwyN/g2lM0sXpiyh534tWuU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Gh+1Hasm; arc=none smtp.client-ip=209.85.215.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso4095691a12.3; Wed, 24 Jan 2024 09:47:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706118446; x=1706723246; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6yr4N28qTdreJQILPMIL8Vba8ZMs6hXrf/fYG9mRvfk=; b=Gh+1HasmqJacU8EJ00LtEwisiIY1EPc/ZxwqM8qR0eGv2aA3q/ku9pcJst0AZzD4vE IuPXK0+3jGTqx3WIiKW4kCT3gkOdAQxloCJmu9wUwnZrWLeok9h4L+FdNAH65j84G65n csHe/5O7K+/95RtY07Phff24ChEkqjT5OYLLArnY2nf+JKPpv4uvE/n7q3ZVx6LzLgm3 S/Sfy2zNhMKu+7FQF2531l2LopBtHXvTfgrHIiMGSqfEdG7idNfbLsCku2+RwuasmBFl WG1VOMg56YoWJZ/CqPAYnQDu9m4S7CfO2ZpxDShS8PJsj5UJjbP8xis+/zg3eJA95QUB Ysqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706118446; x=1706723246; 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=6yr4N28qTdreJQILPMIL8Vba8ZMs6hXrf/fYG9mRvfk=; b=nfBXPCLaqmneyC2b3+VgapczHM46rM6fLsB2bzaFWMy51nGnpngGPNo94GK96EHYhK kZJFQM/u/KT2F6V/WWKefNhi+CBaZcjqD5g0w8iTiXYBHvoNiNUDEew49fBtL4+V4Oc2 KRe2jjHT55pVXQmfcLCtjT9eZywPGlDn/SfyOMn/k7GdxpqGsFlJB70zdfXLGcV6Fb61 FXeRoBJoStrn/om6ShT0+2VA1P359vs8/gYGW+1g9AFWYDZa29RS20BQy5sWgc9PXGqo krxMWfqNA2ptGVAM0OIYY9JvonLx2ae0la6YEYlNus4rhiQ2BoORULcsmGfge+XWNVNi lggA== X-Gm-Message-State: AOJu0Ywe5m/wYoIfjB0TsZkqwSSFbN7iTRtGeVPGjX/6n63cMEcTxsND rU5HNsEaUcAm+q0GCMPzejFzL4Lz4wtKbZv+7bNzLFmhw6C0qlbU X-Received: by 2002:a05:6a20:671c:b0:199:a725:9b59 with SMTP id q28-20020a056a20671c00b00199a7259b59mr1075725pzh.114.1706118445804; Wed, 24 Jan 2024 09:47:25 -0800 (PST) Received: from localhost ([2601:644:9380:8cd0::7fb4]) by smtp.gmail.com with ESMTPSA id ey15-20020a056a0038cf00b006db05eb1301sm14174896pfb.21.2024.01.24.09.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 09:47:25 -0800 (PST) From: Matthew Wood To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: leitao@debian.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v1 6/8] net: netconsole: cache userdata formatted string in netconsole_target Date: Wed, 24 Jan 2024 09:47:04 -0800 Message-ID: <20240124174711.1906102-7-thepacketgeek@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124174711.1906102-1-thepacketgeek@gmail.com> References: <20240124174711.1906102-1-thepacketgeek@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Store a formatted string for userdata that will be appended to netconsole messages. The string has a capacity of 4KB, as calculated by the userdatum entry length of 256 bytes and a max of 16 userdata entries. Update the stored netconsole_target->userdata_complete string with the new formatted userdata values when a userdatum is created, edited, or removed. Each userdata entry contains a trailing newline, which will be formatted as such in netconsole messages:: 6.7.0-rc8-virtme,12,500,1646292204,-;test release=foo something=bar 6.7.0-rc8-virtme,12,500,1646292204,-;another test release=foo something=bar Enforcement of MAX_USERDATA_ITEMS is done in userdatum_make_item; update_userdata will not check for this case but will skip any userdata children over the limit of MAX_USERDATA_ITEMs. If a userdata entry/dir is created but no value is provided, that entry will be skipped. This is in part because update_userdata() can't be called in userdatum_make_item() since the item will not have been added to the userdata config_group children yet. To preserve the experience of adding an empty userdata that doesn't show up in the netconsole messages, purposefully skip emtpy userdata items even when update_userdata() can be called. Co-developed-by: Breno Leitao Signed-off-by: Breno Leitao Signed-off-by: Matthew Wood --- drivers/net/netconsole.c | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 26a3bb070ad0..7de693d0773f 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -108,6 +108,8 @@ struct netconsole_target { #ifdef CONFIG_NETCONSOLE_DYNAMIC struct config_group group; struct config_group userdata_group; + char userdata_complete[MAX_USERDATA_ENTRY_LENGTH * MAX_USERDATA_ITEMS]; + size_t userdata_length; #endif bool enabled; bool extended; @@ -637,10 +639,50 @@ static ssize_t userdatum_value_show(struct config_item *item, char *buf) return sysfs_emit(buf, "%s\n", &(to_userdatum(item)->value[0])); } +static void update_userdata(struct netconsole_target *nt) +{ + int complete_idx = 0, child_count = 0; + struct list_head *entry; + struct userdata *ud; + + /* Clear the current string in case the last userdatum was deleted */ + nt->userdata_length = 0; + nt->userdata_complete[0] = 0; + + ud = to_userdata(&nt->userdata_group.cg_item); + list_for_each(entry, &nt->userdata_group.cg_children) { + struct userdatum *udm_item; + struct config_item *item; + + if (child_count >= MAX_USERDATA_ITEMS) + break; + child_count++; + + item = container_of(entry, struct config_item, ci_entry); + udm_item = to_userdatum(item); + + /* Skip userdata with no value set */ + if (strnlen(udm_item->value, MAX_USERDATA_VALUE_LENGTH) == 0) + continue; + + /* This doesn't overflow userdata_complete since it will write + * one entry length (1/MAX_USERDATA_ITEMS long), entry count is + * checked to not exceed MAX items with child_count above + */ + complete_idx += scnprintf(&nt->userdata_complete[complete_idx], + MAX_USERDATA_ENTRY_LENGTH, "%s=%s\n", + item->ci_name, udm_item->value); + } + nt->userdata_length = strnlen(nt->userdata_complete, + sizeof(nt->userdata_complete)); +} + static ssize_t userdatum_value_store(struct config_item *item, const char *buf, size_t count) { struct userdatum *udm = to_userdatum(item); + struct netconsole_target *nt; + struct userdata *ud; int ret; if (count > MAX_USERDATA_VALUE_LENGTH) @@ -653,6 +695,10 @@ static ssize_t userdatum_value_store(struct config_item *item, const char *buf, goto out_unlock; trim_newline(udm->value, sizeof(udm->value)); + ud = to_userdata(item->ci_parent); + nt = userdata_to_target(ud); + update_userdata(nt); + mutex_unlock(&dynamic_netconsole_mutex); return count; out_unlock: @@ -707,12 +753,27 @@ static struct config_item *userdatum_make_item(struct config_group *group, return &udm->item; } +static void userdatum_drop(struct config_group *group, struct config_item *item) +{ + struct netconsole_target *nt; + struct userdata *ud; + + ud = to_userdata(&group->cg_item); + nt = userdata_to_target(ud); + + mutex_lock(&dynamic_netconsole_mutex); + update_userdata(nt); + config_item_put(item); + mutex_unlock(&dynamic_netconsole_mutex); +} + static struct configfs_attribute *userdata_attrs[] = { NULL, }; static struct configfs_group_operations userdata_ops = { .make_item = userdatum_make_item, + .drop_item = userdatum_drop, }; static struct config_item_type userdata_type = { -- 2.43.0