Re: [PATCH printk v2 2/3] printk: move dictionary keys to dev_printk_info

From: Petr Mladek
Date: Mon Sep 21 2020 - 05:56:01 EST


On Sat 2020-09-19 00:40:20, John Ogness wrote:
> Dictionaries are only used for SUBSYSTEM and DEVICE properties. The
> current implementation stores the property names each time they are
> used. This requires more space than otherwise necessary. Also,
> because the dictionary entries are currently considered optional,
> it cannot be relied upon that they are always available, even if the
> writer wanted to store them. These issues will increase should new
> dictionary properties be introduced.
>
> Rather than storing the subsystem and device properties in the
> dict ring, introduce a struct dev_printk_info with separate fields
> to store only the property values. Embed this struct within the
> struct printk_info to provide guaranteed availability.


> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -629,36 +624,43 @@ static ssize_t msg_print_ext_body(char *buf, size_t size,
> else
> append_char(&p, e, c);
> }
> - append_char(&p, e, '\n');
> + append_char(&p, e, endc);
>
> - if (dict_len) {
> - bool line = true;
> + return p - buf;
> +}
>
> - for (i = 0; i < dict_len; i++) {
> - unsigned char c = dict[i];
> +static ssize_t msg_add_dict_text(char *buf, size_t size,
> + const char *key, const char *val)
> +{
> + size_t val_len = strlen(val);
> + ssize_t len;
>
> - if (line) {
> - append_char(&p, e, ' ');
> - line = false;

I double checked this and found that the above code prefixed dict
values by ' ' in /dev/kmsg.

It slightly improves readability and it is handy for eventual filtering.
It would make sense to keep it.

> - }
> + if (!val_len)
> + return 0;
>
> - if (c == '\0') {
> - append_char(&p, e, '\n');
> - line = true;
> - continue;
> - }
> + len = msg_add_ext_text(buf, size, key, strlen(key), '=');
> + len += msg_add_ext_text(buf + len, size - len, val, val_len, '\n');

Slightly ugly but simple solution is:

len = msg_add_ext_text(buf, size, "", 0, ' '); /* dict prefix */
len += msg_add_ext_text(buf + len, size - len, key, strlen(key), '=');
len += msg_add_ext_text(buf + len, size - len, val, val_len, '\n');

With this fix:

Reviewed-by: Petr Mladek <pmladek@xxxxxxxx>


Now, this is the only problem that I have found. It is not necessary
to resend the entire patchset just because of this.

It might be enough to either respin just this patch. Or I could
commit the below one on top of the patchset. Either solution works
for me.