Re: [PATCH v1 5/6] Allow prepending to the dmesg

From: Andrew Morton
Date: Mon Jan 24 2011 - 20:01:24 EST


On Mon, 24 Jan 2011 16:25:00 -0800
Mike Waychison <mikew@xxxxxxxxxx> wrote:

> The next patch in this series (Memory Console driver) would like to
> prepend firmware messages to the kernel logs.

I went to the changelog for "Memory Console driver" to work out why it
wants to do prepending, but it didn't tell me.

> Instead of exposing all the nitty gritty lock details of the kernel's
> printk system to the entire kernel, expose a "prepend_to_dmesg()" that
> attempts to rewrite the in-memory dmesg to inject pre-kernel messages.
>
> This function only prepends if the start of the kernel's messages are
> still in the ring and there is still room for messages (without losing
> the current tail of the message log). We determine this by checking out
> whether the bufer has yet been cleared (indicated by a new flag:
> buffer_has_cleared), and by checking whether the buffer is less than
> full (which would indicate that it had wrapped).
>
> If there is enough room to prepend data, we simply shift the existing
> log contents down and copy into the buffer the tail of the prepended
> data that fits.
>
> Signed-off-by: Mike Waychison <mikew@xxxxxxxxxx>
> ---
> include/linux/printk.h | 5 ++++
> kernel/printk.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 59 insertions(+), 1 deletions(-)
>
> diff --git a/include/linux/printk.h b/include/linux/printk.h
> index ee048e7..df89965 100644
> --- a/include/linux/printk.h
> +++ b/include/linux/printk.h
> @@ -113,6 +113,7 @@ extern int dmesg_restrict;
> extern int kptr_restrict;
>
> void log_buf_kexec_setup(void);
> +void prepend_to_dmesg(const char *buffer, size_t length);

Should have the __init tag in the declaration (can fix link problems on
weird architectures).

> #else
> static inline __attribute__ ((format (printf, 1, 0)))
> int vprintk(const char *s, va_list args)
> @@ -137,6 +138,10 @@ static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
> static inline void log_buf_kexec_setup(void)
> {
> }
> +
> +void prepend_to_dmesg(const char *buffer, size_t length)
> +{
> +}

Didn't this cause the linker to detect multiple definitions of
prepend_to_dmesg()?

Should be static inline void, or __init and not-inlined in a .c file.

> #endif
>
> ...
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/