Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Aug 2018 17:47:47 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r337545 - in head/sys: conf kern sys
Message-ID:  <201808091747.w79Hlldv071157@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Thu Aug  9 17:47:47 2018
New Revision: 337545
URL: https://svnweb.freebsd.org/changeset/base/337545

Log:
  BOOT_TAG: Make a config(5) option, expose as sysctl and loader tunable
  
  BOOT_TAG lived shortly in sys/msgbuf.h, but this wasn't necessarily great
  for changing it or removing it. Move it into subr_prf.c and add options for
  it to opt_printf.h.
  
  One can specify both the BOOT_TAG and BOOT_TAG_SZ (really, size of the
  buffer that holds the BOOT_TAG). We expose it as kern.boot_tag and also add
  a loader tunable by the same name that we'll fetch upon initialization of
  the msgbuf.
  
  This allows for flexibility and also ensures that there's a consistent way
  to figure out the boot tag of the running kernel, rather than relying on
  headers to be in-sync.
  
  Prodded super-super-lightly by:	imp

Modified:
  head/sys/conf/NOTES
  head/sys/conf/options
  head/sys/kern/subr_prf.c
  head/sys/sys/msgbuf.h

Modified: head/sys/conf/NOTES
==============================================================================
--- head/sys/conf/NOTES	Thu Aug  9 17:42:27 2018	(r337544)
+++ head/sys/conf/NOTES	Thu Aug  9 17:47:47 2018	(r337545)
@@ -145,6 +145,16 @@ options 	INCLUDE_CONFIG_FILE     # Include this file i
 options 	BOOTVERBOSE=1
 options 	BOOTHOWTO=RB_MULTIPLE
 
+#
+# Compile-time defaults for dmesg boot tagging
+#
+# Default boot tag; may use 'kern.boot_tag' loader tunable to override.  The
+# current boot's tag is also exposed via the 'kern.boot_tag' sysctl.
+options 	BOOT_TAG=\"---<<BOOT>>---\"
+# Maximum boot tag size the kernel's static buffer should accomodate.  Maximum
+# size for both BOOT_TAG and the assocated tunable.
+options 	BOOT_TAG_SZ=32
+
 options 	GEOM_BDE		# Disk encryption.
 options 	GEOM_BSD		# BSD disklabels (obsolete, gone in 12)
 options 	GEOM_CACHE		# Disk cache.

Modified: head/sys/conf/options
==============================================================================
--- head/sys/conf/options	Thu Aug  9 17:42:27 2018	(r337544)
+++ head/sys/conf/options	Thu Aug  9 17:47:47 2018	(r337545)
@@ -811,6 +811,8 @@ TERMINAL_NORM_ATTR	opt_teken.h
 
 # options for printf
 PRINTF_BUFR_SIZE	opt_printf.h
+BOOT_TAG		opt_printf.h
+BOOT_TAG_SZ		opt_printf.h
 
 # kbd options
 KBD_DISABLE_KEYMAP_LOAD	opt_kbd.h

Modified: head/sys/kern/subr_prf.c
==============================================================================
--- head/sys/kern/subr_prf.c	Thu Aug  9 17:42:27 2018	(r337544)
+++ head/sys/kern/subr_prf.c	Thu Aug  9 17:47:47 2018	(r337545)
@@ -124,6 +124,18 @@ static bool msgbufmapped;		/* Set when safe to use msg
 int msgbuftrigger;
 struct msgbuf *msgbufp;
 
+#ifndef BOOT_TAG_SZ
+#define	BOOT_TAG_SZ	32
+#endif
+#ifndef BOOT_TAG
+/* Tag used to mark the start of a boot in dmesg */
+#define	BOOT_TAG	"---<<BOOT>>---"
+#endif
+
+static char current_boot_tag[BOOT_TAG_SZ + 1] = BOOT_TAG;
+SYSCTL_STRING(_kern, OID_AUTO, boot_tag, CTLFLAG_RDTUN | CTLFLAG_NOFETCH,
+    current_boot_tag, 0, "Tag added to dmesg at start of boot");
+
 static int log_console_output = 1;
 SYSCTL_INT(_kern, OID_AUTO, log_console_output, CTLFLAG_RWTUN,
     &log_console_output, 0, "Duplicate console output to the syslog");
@@ -1025,9 +1037,13 @@ msgbufinit(void *ptr, int size)
 
 	size -= sizeof(*msgbufp);
 	cp = (char *)ptr;
+	/* Attempt to fetch kern.boot_tag tunable on first mapping */
+	if (!msgbufmapped)
+		TUNABLE_STR_FETCH("kern.boot_tag", current_boot_tag,
+		    BOOT_TAG_SZ + 1);
 	msgbufp = (struct msgbuf *)(cp + size);
 	msgbuf_reinit(msgbufp, cp, size);
-	msgbuf_addstr(msgbufp, -1, BOOT_TAG, 0);
+	msgbuf_addstr(msgbufp, -1, current_boot_tag, 0);
 	if (msgbufmapped && oldp != msgbufp)
 		msgbuf_copy(oldp, msgbufp);
 	msgbufmapped = true;

Modified: head/sys/sys/msgbuf.h
==============================================================================
--- head/sys/sys/msgbuf.h	Thu Aug  9 17:42:27 2018	(r337544)
+++ head/sys/sys/msgbuf.h	Thu Aug  9 17:47:47 2018	(r337545)
@@ -60,9 +60,6 @@ struct msgbuf {
 /* Subtract sequence numbers.  Note that only positive values result. */
 #define	MSGBUF_SEQSUB(mbp, seq1, seq2)	(MSGBUF_SEQNORM((mbp), (seq1) - (seq2)))
 
-/* Tag used to mark the start of a boot in dmesg */
-#define	BOOT_TAG  "---<<BOOT>>---"
-
 #ifdef _KERNEL
 extern int	msgbufsize;
 extern int	msgbuftrigger;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808091747.w79Hlldv071157>