Date: Mon, 20 Aug 2018 17:27:30 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r338109 - in stable/11/sys: conf kern sys Message-ID: <201808201727.w7KHRUBS013800@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Mon Aug 20 17:27:30 2018 New Revision: 338109 URL: https://svnweb.freebsd.org/changeset/base/338109 Log: MFC boot tagging support: r337518, r337544-r337546, r337548, r337579-r337580, r337952 This is equivalent to what's in head, except the default is an empty boot tag string so that nothing gets output by default. r337518: kern: Add a BOOT_TAG marker at the beginning of boot dmesg From the "newly licensed to drive" PR department, add a BOOT_TAG marker (by default, --<<BOOT>>--, to the beginning of each boot's dmesg. This makes it easier to do textproc magic to locate the start of each boot and, of particular interest to some, the dmesg of the current boot. The PR has a dmesg(8) component as well that I've opted not to include for the moment- it was the more contentious part of this PR. bde@ also made the statement that this boot tag should be written with an ordinary printf, which I've- for the moment- declined to change about this patch to keep it more transparent to observer of the boot process. PR: 43434 Submitted by: dak <aurelien.nephtali@wanadoo.fr> (basically rewritten) r337544: msgbuf: Light detailing (const'ify and bool'itize) r337545: 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 r337546: subr_prf: Use "sizeof current_boot_tag" instead r337548: subr_prf: style(9) the sizeof Reported by: jkim, ian r337579: boot tagging: minor fixes msgbufinit may be called multiple times as we initialize the msgbuf into a progressively larger buffer. This doesn't happen as of now on head, but it may happen in the future and we generally support this. As such, only print the boot tag if we've just initialized the buffer for the first time. The boot tag also now has a newline appended to it for better visibility, and has been switched to a normal printf, by requesto f bde, after we've denoted that the msgbuf is mapped. r337580: subr_prf: remove think-o that had returned to local patch Reported by: cognet r337952: subr_prf: Don't write kern.boot_tag if it's empty This change allows one to set kern.boot_tag="" and not get a blank line preceding other boot messages. While this isn't super critical- blank lines are easy to filter out both mentally and in processing dmesg later- it allows for a mode of operation that matches previous behavior. I intend to MFC this whole series to stable/11 by the end of the month with boot_tag empty by default to make this effectively a nop in the stable branch. Modified: stable/11/sys/conf/NOTES stable/11/sys/conf/options stable/11/sys/kern/subr_msgbuf.c stable/11/sys/kern/subr_prf.c stable/11/sys/sys/msgbuf.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/conf/NOTES ============================================================================== --- stable/11/sys/conf/NOTES Mon Aug 20 16:44:09 2018 (r338108) +++ stable/11/sys/conf/NOTES Mon Aug 20 17:27:30 2018 (r338109) @@ -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=\"\" +# 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_AES # Don't use, use GEOM_BDE (obsolete, gone in 12) options GEOM_BDE # Disk encryption. options GEOM_BSD # BSD disklabels (obsolete, gone in 12) Modified: stable/11/sys/conf/options ============================================================================== --- stable/11/sys/conf/options Mon Aug 20 16:44:09 2018 (r338108) +++ stable/11/sys/conf/options Mon Aug 20 17:27:30 2018 (r338109) @@ -801,6 +801,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: stable/11/sys/kern/subr_msgbuf.c ============================================================================== --- stable/11/sys/kern/subr_msgbuf.c Mon Aug 20 16:44:09 2018 (r338108) +++ stable/11/sys/kern/subr_msgbuf.c Mon Aug 20 17:27:30 2018 (r338109) @@ -179,7 +179,7 @@ msgbuf_addchar(struct msgbuf *mbp, int c) * carriage returns down this path. So do we still need it? */ void -msgbuf_addstr(struct msgbuf *mbp, int pri, char *str, int filter_cr) +msgbuf_addstr(struct msgbuf *mbp, int pri, const char *str, int filter_cr) { u_int seq; size_t len, prefix_len; Modified: stable/11/sys/kern/subr_prf.c ============================================================================== --- stable/11/sys/kern/subr_prf.c Mon Aug 20 16:44:09 2018 (r338108) +++ stable/11/sys/kern/subr_prf.c Mon Aug 20 17:27:30 2018 (r338109) @@ -118,9 +118,21 @@ static void putchar(int ch, void *arg); static char *ksprintn(char *nbuf, uintmax_t num, int base, int *len, int upper); static void snprintf_func(int ch, void *arg); -static int msgbufmapped; /* Set when safe to use msgbuf */ +static bool msgbufmapped; /* Set when safe to use msgbuf */ int msgbuftrigger; +#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 "" +#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"); @@ -1011,14 +1023,22 @@ msgbufinit(void *ptr, int size) { char *cp; static struct msgbuf *oldp = NULL; + bool print_boot_tag; size -= sizeof(*msgbufp); cp = (char *)ptr; + print_boot_tag = !msgbufmapped; + /* Attempt to fetch kern.boot_tag tunable on first mapping */ + if (!msgbufmapped) + TUNABLE_STR_FETCH("kern.boot_tag", current_boot_tag, + sizeof(current_boot_tag)); msgbufp = (struct msgbuf *)(cp + size); msgbuf_reinit(msgbufp, cp, size); if (msgbufmapped && oldp != msgbufp) msgbuf_copy(oldp, msgbufp); - msgbufmapped = 1; + msgbufmapped = true; + if (print_boot_tag && *current_boot_tag != '\0') + printf("%s\n", current_boot_tag); oldp = msgbufp; } Modified: stable/11/sys/sys/msgbuf.h ============================================================================== --- stable/11/sys/sys/msgbuf.h Mon Aug 20 16:44:09 2018 (r338108) +++ stable/11/sys/sys/msgbuf.h Mon Aug 20 17:27:30 2018 (r338109) @@ -66,7 +66,7 @@ extern struct mtx msgbuf_lock; void msgbufinit(void *ptr, int size); void msgbuf_addchar(struct msgbuf *mbp, int c); -void msgbuf_addstr(struct msgbuf *mbp, int pri, char *str, int filter_cr); +void msgbuf_addstr(struct msgbuf *mbp, int pri, const char *str, int filter_cr); void msgbuf_clear(struct msgbuf *mbp); void msgbuf_copy(struct msgbuf *src, struct msgbuf *dst); int msgbuf_getbytes(struct msgbuf *mbp, char *buf, int buflen);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808201727.w7KHRUBS013800>