Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp2358502rwp; Fri, 14 Jul 2023 05:09:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlGsL8UYTslZ+1xYmuPapsLytIOyxd/L1QSXZFbBNK+8Mn/ilfkyN1nz1tP7yzsvBMYeDHgt X-Received: by 2002:a17:906:4f99:b0:95e:d3f5:3d47 with SMTP id o25-20020a1709064f9900b0095ed3f53d47mr3333257eju.48.1689336575459; Fri, 14 Jul 2023 05:09:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689336575; cv=none; d=google.com; s=arc-20160816; b=BAf6GdFVQal0x5sICacEQ0KRnWflYwgsvqTyVNb4MFJTy61MZthSeualRKQ0OdAa02 T+BrqkExH53RdUNM2TFWN7sJ4DQCnGWwxEs1a1lm5jVZyOUIyBNg32bo/MRjDwUVZWSX ulE52B/n7Jtff6bQGVgliPSjORzyRjuKReCGOWMkLUG+r3z162LWyNKEY8lhPRFegM+a JwtiBMoYwTVbC5/gwu0i2WxtdQC1uqiSYpGizjwp1WuZD9zW+fthGfkn98hPkJ+AsKV2 sLQ/5SfUQTmzQll5xNprG8MQfIEOhJucZ1Vh/3z7J3bKzyE0Kom4YjVOhvs+6mXMCq4e 9Rjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+bI4L209gcDMOttkb6gYEjAaK8FSpSt87+9I+YqlkJ8=; fh=3N/tU/Ecui0Gxl58PrOvCetyQNeucXgldl4BGHZYzoo=; b=dAKd+1Ai2OTC841MtEz+IC311FRscq0BuZYw6VnunsJNtmljXrYWvXg8G0RBOYDfN3 HOiAT9/+0FfhllaSOXgxPnNzDnwaFYVdZ9gRwF1/Gt2OpamNqESv0xC2HcBIjRiu6r43 +nfBKWD02Cclt4qwlMINjAgCh4aQorm/Unh98E8T/iOFyY7NDZzkaj2cP+s+gcIhrO5f lW7xGUM34QaX8Eznqoh0yZ0VSGwkODdXXaOC//VEL7PXl5wR/coTJCNNoqqdyMH4jI5G jE4gYHN4/gSOB7uPU4uBoPY4zgZM7B906RP1seuyb/1u4UrXj9vRif5QcLd+Ec1PLV+M p2MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=m6ec5be5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lf16-20020a170907175000b0099331b3e6f6si8635843ejc.661.2023.07.14.05.09.09; Fri, 14 Jul 2023 05:09:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=m6ec5be5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235555AbjGNLmi (ORCPT + 99 others); Fri, 14 Jul 2023 07:42:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235323AbjGNLmb (ORCPT ); Fri, 14 Jul 2023 07:42:31 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C02523A93; Fri, 14 Jul 2023 04:42:07 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 62AEA1FD8A; Fri, 14 Jul 2023 11:42:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1689334920; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+bI4L209gcDMOttkb6gYEjAaK8FSpSt87+9I+YqlkJ8=; b=m6ec5be5POm77rzxsDYwk+0dmMuE8FvcRsm6t3C1ePr+pO2lCq1fhNBINGy6JQwhIwWQpM HB5Iw2NAfUtInozjO+OcqNt6Xp48+7DnPLu8mDpEuj9Cl5Y5iQT6gYsNrjp79AWSHUoHxq Z9pliSVh0bvXHHEnANjN9vL+VsazVdY= Received: from suse.cz (pmladek.tcp.ovpn2.prg.suse.de [10.100.208.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 92DE92C142; Fri, 14 Jul 2023 11:41:59 +0000 (UTC) Date: Fri, 14 Jul 2023 13:41:55 +0200 From: Petr Mladek To: Breno Leitao Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , sergey.senozhatsky@gmail.com, tj@kernel.org, stephen@networkplumber.org, Dave Jones , "open list:NETWORKING [GENERAL]" , "open list:DOCUMENTATION" , open list Subject: Re: [PATCH v2] netconsole: Append kernel version to message Message-ID: References: <20230707132911.2033870-1-leitao@debian.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230707132911.2033870-1-leitao@debian.org> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 On Fri 2023-07-07 06:29:11, Breno Leitao wrote: > Create a new netconsole runtime option that prepends the kernel version in > the netconsole message. This is useful to map kernel messages to kernel > version in a simple way, i.e., without checking somewhere which kernel > version the host that sent the message is using. > > If this option is selected, then the "," is prepended before the > netconsole message. This is an example of a netconsole output, with > release feature enabled: > > 6.4.0-01762-ga1ba2ffe946e;12,426,112883998,-;this is a test > > Calvin Owens send a RFC about this problem in 2016[1], but his > approach was a bit more intrusive, changing the printk subsystem. This > approach is lighter, and just append the information in the last mile, > just before netconsole push the message to netpoll. Thanks a lot for solving this on the netconsole level. The extended console format is used also for /dev/kmsg. Which is then used by systemd journal, dmesg, and maybe other userspace tools. Any format changes might break these tools. I have glanced over the patch and have two comments. > @@ -254,6 +267,11 @@ static ssize_t extended_show(struct config_item *item, char *buf) > return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->extended); > } > > +static ssize_t release_show(struct config_item *item, char *buf) > +{ > + return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->release); I have learned recently that sysfs_emit() was preferred over snprintf() in the _show() callbacks. > +} > + > static ssize_t dev_name_show(struct config_item *item, char *buf) > { > return snprintf(buf, PAGE_SIZE, "%s\n", to_target(item)->np.dev_name); > @@ -366,6 +389,38 @@ static ssize_t enabled_store(struct config_item *item, > return err; > } > > +static ssize_t release_store(struct config_item *item, const char *buf, > + size_t count) > +{ > + struct netconsole_target *nt = to_target(item); > + int release; > + int err; > + > + mutex_lock(&dynamic_netconsole_mutex); > + if (nt->enabled) { > + pr_err("target (%s) is enabled, disable to update parameters\n", > + config_item_name(&nt->item)); > + err = -EINVAL; > + goto out_unlock; > + } > + > + err = kstrtoint(buf, 10, &release); > + if (err < 0) > + goto out_unlock; > + if (release < 0 || release > 1) { > + err = -EINVAL; > + goto out_unlock; > + } You might consider using: bool enabled; err = kstrtobool(buf, &enabled); if (err) goto unlock; It accepts more input values, for example, 1/0, y/n, Y/N, ... Well, I see that kstrtoint() is used also in enabled_store(). It might be confusing when "/enabled" supports only "1/0" and "/release" supports more variants. > + > + nt->release = release; > + > + mutex_unlock(&dynamic_netconsole_mutex); > + return strnlen(buf, count); > +out_unlock: > + mutex_unlock(&dynamic_netconsole_mutex); > + return err; > +} > + Best Regards, Petr