From patchwork Thu Oct 12 11:13:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 151937 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1147942vqb; Thu, 12 Oct 2023 04:14:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEf/FBwNwMcdwVQTyNlgpx5otHf1Rh1qHxmHArh6sM5uYLXKyjMsJ0aejZq9ca3xLQ1yUzJ X-Received: by 2002:a17:90a:4ca4:b0:274:99ed:a80c with SMTP id k33-20020a17090a4ca400b0027499eda80cmr21250835pjh.3.1697109278763; Thu, 12 Oct 2023 04:14:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697109278; cv=none; d=google.com; s=arc-20160816; b=A9tHAuh+TIjJGZeTfEYMonxPs4C1XrzAuePqEE6u4zfNzwZhkx5/8jYm2+9U7KbliJ nNnmPxmpTsnloyPBGsa7yfOmsoCG5unOPQIY/7GqZR3SihxXbkOOIsIAbqMsZ1Rdhi0T xGfXkRTNvpgMlUwFJ3AMT9ZHyEdt76Hkc+rZjBZ1gzmnOZ+6cJctkaAUOoa2q4vxU8V1 PG/eQ9s+R/zGLKX7VQWVHT1ahZPuGjjSxtWEjEVIlnsyLSLqC6Rqkdr6MYf28xDqgDvS aXF6ANlchmqnrLLAaEJLzxy2Io0OiWGtiLKy1FDhDx0m8YZxFQWBrc6zaeJabq6akssj oEEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=M90K/d3r5eUqR7rkir6gs7Lk0yYzS3hpFs7OoQ1iJbU=; fh=t3kfgQuaGyM84gKNjjnNISmg23a5dmENm6EBz3YSRHQ=; b=x75L76nmi/fu8NT1cIP0jrypTesS8eqY6jy/GchOJlsaFlnpBLCJSLR1nFUxj0Eerv vDkwSDj9J4cz3qxPm8IfpIGeDFcpAlwsfy1KoRxd7CA73Pce1BmV8tdV2mLM8bw2Romj rx1YBP9vQnZRqkebJvUeLlqLaVIuql7G6JQ0WnVfN0qVvgGh6jKBLcK3diNz3JpEyw/7 pzinXR92g2rOfhlGKDvp49T43dv6581tGEQBbLPwdnI6AZWxcJyg1nJyELBo9fQJc7PJ yfpjQjsozqzKfHFsMrGtgoAozC4nI1GHvOlZ/IT5yFRX5+NPhEaGEb3jbk9J0OjuIqCD d3pA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id ng7-20020a17090b1a8700b0027ceb84b60bsi2289368pjb.56.2023.10.12.04.14.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 04:14:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id BA817822CAB7; Thu, 12 Oct 2023 04:14:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378207AbjJLLOc (ORCPT + 19 others); Thu, 12 Oct 2023 07:14:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235689AbjJLLO1 (ORCPT ); Thu, 12 Oct 2023 07:14:27 -0400 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1397C0; Thu, 12 Oct 2023 04:14:25 -0700 (PDT) Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-9ae2cc4d17eso136599066b.1; Thu, 12 Oct 2023 04:14:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697109263; x=1697714063; 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=M90K/d3r5eUqR7rkir6gs7Lk0yYzS3hpFs7OoQ1iJbU=; b=GiYRpW0rJPlYW2JjcPo4ldHt/c0J7OGGdkupOWlWVRl1PBX5+n7v5sSWFl3vHRikWP A2sUqc7pqGiKlI37dPG3jaMbfaBzeI49oIm4l4wiRhnb0oZjri/Un2S+bbTBMdyePUhm FAXKTKh+tGuk5upHTBqvcTL/5bov3o5bTa06Mp5SJ3FoVXJE70Bkd/1EiiLdPtvq+e7d gm9QT39ZXej6kH+nYEc43Mov4zvA2Lz3MTgQ6p6ctEtWreNFnnFmfeoGZ9fAsMsigtn8 9X6QQZsoKAS8ezJ4Uv8qfixnpgc0YFxvBbDbAl05jHDyJ5KFCD03OTWECrelBoR20NH1 ElrQ== X-Gm-Message-State: AOJu0YzK3x8NIQFZsS/rldzYCKEvHtziF3Vb7AG43cFHBPBKccpsBIHw 3wuJXGQRTTmMldgRM7K17Nw= X-Received: by 2002:a17:906:714a:b0:9b2:b9ad:ddd1 with SMTP id z10-20020a170906714a00b009b2b9adddd1mr21560154ejj.28.1697109262971; Thu, 12 Oct 2023 04:14:22 -0700 (PDT) Received: from localhost (fwdproxy-cln-000.fbsv.net. [2a03:2880:31ff::face:b00c]) by smtp.gmail.com with ESMTPSA id a6-20020a170906190600b009ad89697c86sm11016697eje.144.2023.10.12.04.14.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 04:14:22 -0700 (PDT) From: Breno Leitao To: jlbec@evilplan.org, kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com, Eric Dumazet Cc: hch@lst.de, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, horms@kernel.org Subject: [PATCH net-next v4 1/4] netconsole: move init/cleanup functions lower Date: Thu, 12 Oct 2023 04:13:58 -0700 Message-Id: <20231012111401.333798-2-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231012111401.333798-1-leitao@debian.org> References: <20231012111401.333798-1-leitao@debian.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 12 Oct 2023 04:14:37 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779548059071981930 X-GMAIL-MSGID: 1779548059071981930 Move alloc_param_target() and its counterpart (free_param_target()) to the bottom of the file. These functions are called mostly at initialization/cleanup of the module, and they should be just above the callers, at the bottom of the file. From a practical perspective, having alloc_param_target() at the bottom of the file will avoid forward declaration later (in the following patch). Nothing changed other than the functions location. Suggested-by: Jakub Kicinski Signed-off-by: Breno Leitao Reviewed-by: Joel Becker --- drivers/net/netconsole.c | 104 +++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 3111e1648592..d609fb59cf99 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -192,58 +192,6 @@ static struct netconsole_target *alloc_and_init(void) return nt; } -/* Allocate new target (from boot/module param) and setup netpoll for it */ -static struct netconsole_target *alloc_param_target(char *target_config) -{ - struct netconsole_target *nt; - int err; - - nt = alloc_and_init(); - if (!nt) { - err = -ENOMEM; - goto fail; - } - - if (*target_config == '+') { - nt->extended = true; - target_config++; - } - - if (*target_config == 'r') { - if (!nt->extended) { - pr_err("Netconsole configuration error. Release feature requires extended log message"); - err = -EINVAL; - goto fail; - } - nt->release = true; - target_config++; - } - - /* Parse parameters and setup netpoll */ - err = netpoll_parse_options(&nt->np, target_config); - if (err) - goto fail; - - err = netpoll_setup(&nt->np); - if (err) - goto fail; - - nt->enabled = true; - - return nt; - -fail: - kfree(nt); - return ERR_PTR(err); -} - -/* Cleanup netpoll for given target (from boot/module param) and free it */ -static void free_param_target(struct netconsole_target *nt) -{ - netpoll_cleanup(&nt->np); - kfree(nt); -} - #ifdef CONFIG_NETCONSOLE_DYNAMIC /* @@ -938,6 +886,58 @@ static void write_msg(struct console *con, const char *msg, unsigned int len) spin_unlock_irqrestore(&target_list_lock, flags); } +/* Allocate new target (from boot/module param) and setup netpoll for it */ +static struct netconsole_target *alloc_param_target(char *target_config) +{ + struct netconsole_target *nt; + int err; + + nt = alloc_and_init(); + if (!nt) { + err = -ENOMEM; + goto fail; + } + + if (*target_config == '+') { + nt->extended = true; + target_config++; + } + + if (*target_config == 'r') { + if (!nt->extended) { + pr_err("Netconsole configuration error. Release feature requires extended log message"); + err = -EINVAL; + goto fail; + } + nt->release = true; + target_config++; + } + + /* Parse parameters and setup netpoll */ + err = netpoll_parse_options(&nt->np, target_config); + if (err) + goto fail; + + err = netpoll_setup(&nt->np); + if (err) + goto fail; + + nt->enabled = true; + + return nt; + +fail: + kfree(nt); + return ERR_PTR(err); +} + +/* Cleanup netpoll for given target (from boot/module param) and free it */ +static void free_param_target(struct netconsole_target *nt) +{ + netpoll_cleanup(&nt->np); + kfree(nt); +} + static struct console netconsole_ext = { .name = "netcon_ext", .flags = CON_ENABLED | CON_EXTENDED, From patchwork Thu Oct 12 11:13:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 151939 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1148159vqb; Thu, 12 Oct 2023 04:15:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGz4fmvkMdfKVml/I3u6Hqn59YRreAonKONHW1Hye2w35i49eklX3YdzAWmjkkne2SuET9P X-Received: by 2002:a05:6a21:197:b0:14e:2c56:7b02 with SMTP id le23-20020a056a21019700b0014e2c567b02mr29815460pzb.0.1697109302324; Thu, 12 Oct 2023 04:15:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697109302; cv=none; d=google.com; s=arc-20160816; b=F513vKzq6tZ2V02ZRWhPwXg5m+BeKPo827qvpHmWjuKpJCVkn2I1rT2uMH7fJfbi9v fMZZ0K+Npw2egWzh1pY1hG21selEOshZ6gN7mu+ZxQtgBBfgFX/xlz3knQ3ZcNoUhC3L +ogviAxYgl8aPJ2gGcgMK4Wkt93ACgN/zt5s9V2TxEkzL6wHgNSsV7pI9jMslbXVMExO 3Z4Bnb5nDLp97dVIf+gfR2H3kqp9EN9no2hcozm9nE2+gTsSIw4oM+sW4p2bu8gOhhLT wex+XnP3IlWHMynEDGlq3icrjK2roqCk9phBgegccaj5x9foM+HbeaQlPFB5ilrbky4N Orug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=azlBm1bMHX5sI/cuS/oB85eLn/m2Im3cX9O78MhWE54=; fh=t3kfgQuaGyM84gKNjjnNISmg23a5dmENm6EBz3YSRHQ=; b=XVYEZQvfsur+0jNTA7ytc0yNzxaWD8s/RGruiRGvEkQ/dnDHgEC0Ub/DKSBjRear57 wP0whJuu65eDNDusUpBpF5SXHIrBDEZV3SAK+PZoPrJ57/K5VFXV0UtavlCwfZ+H/wIE CBoHIf/rms8PktZhSp2yvUeqI66DonAVIxbimLJHFE0CwPJKDVy7kRpKdZcItDs1G15D 8QOwaMRbTVUrk03NsOQuCZHTczbXGA/tSMbnlnCyz7EL6iJdJAs0Yi0Q8DuBDstGQhzo 6vjpyMyl2a/iDRXzXaV9VGTSruOCDEO8zVo6j6BFEw26R7LC36bxlg4DL8bwRKpa6Cwn Hryw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id e18-20020a656892000000b00578e29ae274si2078740pgt.521.2023.10.12.04.15.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 04:15:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 2742681A7D06; Thu, 12 Oct 2023 04:14:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378223AbjJLLOf (ORCPT + 19 others); Thu, 12 Oct 2023 07:14:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232490AbjJLLO2 (ORCPT ); Thu, 12 Oct 2023 07:14:28 -0400 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 061A0C6; Thu, 12 Oct 2023 04:14:26 -0700 (PDT) Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-9a645e54806so129367266b.0; Thu, 12 Oct 2023 04:14:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697109264; x=1697714064; 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=azlBm1bMHX5sI/cuS/oB85eLn/m2Im3cX9O78MhWE54=; b=bro8zqXcehwrO4ezI3RZmUzadTXDhiL1ZDgtyvkNuIEAsez50/uTu3RKK94j9/I94f KUYMZKUZWY4gn3QO7M/hgEAfdz4T6gzY6RfRSP6FLseDY9ljjnOdfvg0+SHYnaPsLNsE lcYWVyfKVKg8clz68w2Xc9UneQS1FNN/aZ8JDI1LfGiaEhdh4LCRSogZKpgEtLkuM8H6 c+dwq8rqGOz8+4TEJ15kl6jgTe3t4qQ5IWJroTn0chFb1wV3opPAGdZzabVihlqF2XxA WdIdlUx4NT/BRobcVam2j4QvV3uV3ompu9lwipw9DF6jvfKlWxU0nV0+MNjsqSWIIZ8V J3uA== X-Gm-Message-State: AOJu0YyIiUblXJE2aex6tIsZfgMnXwBZNtk8z/5CkPGJjNS5MYScYjL3 H/ba+cygxHsd/LrczWa4urI= X-Received: by 2002:a17:907:2711:b0:9b2:6c58:87a2 with SMTP id w17-20020a170907271100b009b26c5887a2mr19986752ejk.29.1697109264354; Thu, 12 Oct 2023 04:14:24 -0700 (PDT) Received: from localhost (fwdproxy-cln-018.fbsv.net. [2a03:2880:31ff:12::face:b00c]) by smtp.gmail.com with ESMTPSA id x26-20020a170906711a00b0099329b3ab67sm10945121ejj.71.2023.10.12.04.14.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 04:14:23 -0700 (PDT) From: Breno Leitao To: jlbec@evilplan.org, kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com, Eric Dumazet Cc: hch@lst.de, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, horms@kernel.org Subject: [PATCH net-next v4 2/4] netconsole: Initialize configfs_item for default targets Date: Thu, 12 Oct 2023 04:13:59 -0700 Message-Id: <20231012111401.333798-3-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231012111401.333798-1-leitao@debian.org> References: <20231012111401.333798-1-leitao@debian.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 12 Oct 2023 04:14:58 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779548084023384823 X-GMAIL-MSGID: 1779548084023384823 For netconsole targets allocated during the boot time (passing netconsole=... argument), netconsole_target->item is not initialized. That is not a problem because it is not used inside configfs. An upcoming patch will be using it, thus, initialize the targets with the name 'cmdline' plus a counter starting from 0. This name will match entries in the configfs later. Suggested-by: Joel Becker Signed-off-by: Breno Leitao Reviewed-by: Joel Becker --- drivers/net/netconsole.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index d609fb59cf99..e153bce4dee4 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -53,6 +53,8 @@ static bool oops_only = false; module_param(oops_only, bool, 0600); MODULE_PARM_DESC(oops_only, "Only log oops messages"); +#define NETCONSOLE_PARAM_TARGET_PREFIX "cmdline" + #ifndef MODULE static int __init option_setup(char *opt) { @@ -165,6 +167,10 @@ static void netconsole_target_put(struct netconsole_target *nt) { } +static void populate_configfs_item(struct netconsole_target *nt, + int cmdline_count) +{ +} #endif /* CONFIG_NETCONSOLE_DYNAMIC */ /* Allocate and initialize with defaults. @@ -688,6 +694,17 @@ static struct configfs_subsystem netconsole_subsys = { }, }; +static void populate_configfs_item(struct netconsole_target *nt, + int cmdline_count) +{ + char target_name[16]; + + snprintf(target_name, sizeof(target_name), "%s%d", + NETCONSOLE_PARAM_TARGET_PREFIX, cmdline_count); + config_item_init_type_name(&nt->item, target_name, + &netconsole_target_type); +} + #endif /* CONFIG_NETCONSOLE_DYNAMIC */ /* Handle network interface device notifications */ @@ -887,7 +904,8 @@ static void write_msg(struct console *con, const char *msg, unsigned int len) } /* Allocate new target (from boot/module param) and setup netpoll for it */ -static struct netconsole_target *alloc_param_target(char *target_config) +static struct netconsole_target *alloc_param_target(char *target_config, + int cmdline_count) { struct netconsole_target *nt; int err; @@ -922,6 +940,7 @@ static struct netconsole_target *alloc_param_target(char *target_config) if (err) goto fail; + populate_configfs_item(nt, cmdline_count); nt->enabled = true; return nt; @@ -954,6 +973,7 @@ static int __init init_netconsole(void) { int err; struct netconsole_target *nt, *tmp; + unsigned int count = 0; bool extended = false; unsigned long flags; char *target_config; @@ -961,7 +981,7 @@ static int __init init_netconsole(void) if (strnlen(input, MAX_PARAM_LENGTH)) { while ((target_config = strsep(&input, ";"))) { - nt = alloc_param_target(target_config); + nt = alloc_param_target(target_config, count); if (IS_ERR(nt)) { err = PTR_ERR(nt); goto fail; @@ -977,6 +997,7 @@ static int __init init_netconsole(void) spin_lock_irqsave(&target_list_lock, flags); list_add(&nt->list, &target_list); spin_unlock_irqrestore(&target_list_lock, flags); + count++; } } From patchwork Thu Oct 12 11:14:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 151938 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1147984vqb; Thu, 12 Oct 2023 04:14:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE1dBUTvnDqCMOkZP6TiinXeXi8siIYOVpcTuxd/vh5wd+HWQGuI9/q07EykIWSJETK0pGr X-Received: by 2002:a17:90b:1bce:b0:27c:ebab:5c60 with SMTP id oa14-20020a17090b1bce00b0027cebab5c60mr7054392pjb.2.1697109284447; Thu, 12 Oct 2023 04:14:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697109284; cv=none; d=google.com; s=arc-20160816; b=vvS/PHdZsIUhxNWBbxXnIokttu23h9N6Yl1UEo5EAsvB1DqArV31uNxSnbZKfPAH57 qGILZOLaR82Mq8hXjl1IgMeMLVcGmP8TXVh6m7TBgA3/CCACStlNxryjS4q9JC4Xj2H7 /GgYUkPexI0laJFpYKQdx35F9tB05FcYI53UqK3+gXORRo95AIKIziIwZ9U+8ZljAZ0p qyhJ38CUN6dXRuGeCP3HaJARtsaiqW1biqH4hp7jDrp+kFBpckvNzOjC0yeCMvojE/bB kHelYd9y+MmiFgdLwIOMhGjuMNrCPLjt1z/O0IT5uE+Yc5k480X4znyKnKzlRSDZQNRv lUZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=PjdP/1UQNz4vXjRgezA+S9KrCfwhCzW1/s+0kKPQHC8=; fh=t3kfgQuaGyM84gKNjjnNISmg23a5dmENm6EBz3YSRHQ=; b=odfnm+/FM5oFqAcoAzV35qmuor7oFkWxl7sGCJNpWD5aYTIKt6zppQVnA0WUQ90crr y05YXlr/Oi8E8Q5V8Dw7L82+12UGM0MkwH9r+jchWyDzWmYcGN9+psYhR/vjW/la5M1b w62gS6xeUTYNdY9aS2KnPav7eL67ckO3k9Rs99QlaPCIJl/X3bo/Wy41yx8ewMOCKIfh 7EPhwQ3nz6KgO/wrMLge5m377k3tWLWbdRE6t3m1xxv2FyyBdZVnrFpbWKnL1uC/Xv10 8GxL3C0+ZRBtuBAOHFrWF7GmIrRxx7XgBX0mrKnbeotdZ84tcOoUspyUC/HKUIC/MP2y lKmQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id k2-20020a170902c40200b001c59b6ed118si2124310plk.157.2023.10.12.04.14.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 04:14:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id ADC87822CACF; Thu, 12 Oct 2023 04:14:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378229AbjJLLOj (ORCPT + 19 others); Thu, 12 Oct 2023 07:14:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377950AbjJLLO3 (ORCPT ); Thu, 12 Oct 2023 07:14:29 -0400 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9913D94; Thu, 12 Oct 2023 04:14:27 -0700 (PDT) Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-53db360294fso1574710a12.3; Thu, 12 Oct 2023 04:14:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697109266; x=1697714066; 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=PjdP/1UQNz4vXjRgezA+S9KrCfwhCzW1/s+0kKPQHC8=; b=EB61wJADKpOXPBLFtkSqnYDu54z/yt51b5q5zuYeq7AI1uWtzOpEun9R0Zs5tAVEG1 dXT2dEV5OE5adtJF+9aY3jzKkAsz+toRqDPxxQo8Tb4u6sfDjjvZNqKzKM5k8ZVliYFU ZJDnC7BtY9GN47Ddn06HxLVaePOYapvr3MO8RsrX8zKGd9Ujiq3sfD7HkFDUIag+4mp3 ChlXIMYHDXUJOAOVZ+QHAxf2tG7xchaA99Rb9sk7jhOEpudpKX1HUue09H+Bmo1f2dgK BuDGJ+/EYs9bYBmtMtfpKsRV3aeKUMTRBlfXHMQlOjkGmtG4AarQf8zip2IM3wf0Vw1L fWNQ== X-Gm-Message-State: AOJu0YzsMrhvRXsqXJfujyizOAZ/QXMDUFT26l+gsyA0YmPPVVtlR3pE 3+hS0mwqz96WHyggLM5ORrJlhOb90wk= X-Received: by 2002:aa7:df0e:0:b0:52c:8a13:2126 with SMTP id c14-20020aa7df0e000000b0052c8a132126mr21198955edy.37.1697109265642; Thu, 12 Oct 2023 04:14:25 -0700 (PDT) Received: from localhost (fwdproxy-cln-012.fbsv.net. [2a03:2880:31ff:c::face:b00c]) by smtp.gmail.com with ESMTPSA id s7-20020aa7c547000000b0052348d74865sm9972352edr.61.2023.10.12.04.14.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 04:14:25 -0700 (PDT) From: Breno Leitao To: jlbec@evilplan.org, kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com, Eric Dumazet Cc: hch@lst.de, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, horms@kernel.org Subject: [PATCH net-next v4 3/4] netconsole: Attach cmdline target to dynamic target Date: Thu, 12 Oct 2023 04:14:00 -0700 Message-Id: <20231012111401.333798-4-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231012111401.333798-1-leitao@debian.org> References: <20231012111401.333798-1-leitao@debian.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 12 Oct 2023 04:14:43 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779548065041614489 X-GMAIL-MSGID: 1779548065041614489 Enable the attachment of a dynamic target to the target created during boot time. The boot-time targets are named as "cmdline\d", where "\d" is a number starting at 0. If the user creates a dynamic target named "cmdline0", it will attach to the first target created at boot time (as defined in the `netconsole=...` command line argument). `cmdline1` will attach to the second target and so forth. If there is no netconsole target created at boot time, then, the target name could be reused. Relevant design discussion: https://lore.kernel.org/all/ZRWRal5bW93px4km@gmail.com/ Suggested-by: Joel Becker Signed-off-by: Breno Leitao Reviewed-by: Joel Becker --- drivers/net/netconsole.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index e153bce4dee4..6e14ba5e06c8 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -629,6 +629,23 @@ static const struct config_item_type netconsole_target_type = { .ct_owner = THIS_MODULE, }; +static struct netconsole_target *find_cmdline_target(const char *name) +{ + struct netconsole_target *nt, *ret = NULL; + unsigned long flags; + + spin_lock_irqsave(&target_list_lock, flags); + list_for_each_entry(nt, &target_list, list) { + if (!strcmp(nt->item.ci_name, name)) { + ret = nt; + break; + } + } + spin_unlock_irqrestore(&target_list_lock, flags); + + return ret; +} + /* * Group operations and type for netconsole_subsys. */ @@ -639,6 +656,17 @@ static struct config_item *make_netconsole_target(struct config_group *group, struct netconsole_target *nt; unsigned long flags; + /* Checking if a target by this name was created at boot time. If so, + * attach a configfs entry to that target. This enables dynamic + * control. + */ + if (!strncmp(name, NETCONSOLE_PARAM_TARGET_PREFIX, + strlen(NETCONSOLE_PARAM_TARGET_PREFIX))) { + nt = find_cmdline_target(name); + if (nt) + return &nt->item; + } + nt = alloc_and_init(); if (!nt) return ERR_PTR(-ENOMEM);