Commit a1ad4b8a authored by Chris Down's avatar Chris Down Committed by Petr Mladek

printk: Straighten out log_flags into printk_info_flags

In the past, `enum log_flags` was part of `struct log`, hence the name.
`struct log` has since been reworked and now this struct is stored
inside `struct printk_info`. However, the name was never updated, which
is somewhat confusing -- especially since these flags operate at the
record level rather than at the level of an abstract log.

printk_info_flags also joins its other metadata struct friends in
printk_ringbuffer.h.
Signed-off-by: default avatarChris Down <chris@chrisdown.name>
Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
Acked-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/3dd801982f02603e6e3aa4f8bc4f5ebb830a4949.1623775748.git.chris@chrisdown.name
parent 91027d0a
...@@ -12,6 +12,12 @@ ...@@ -12,6 +12,12 @@
#define PRINTK_NMI_CONTEXT_OFFSET 0x010000000 #define PRINTK_NMI_CONTEXT_OFFSET 0x010000000
/* Flags for a single printk record. */
enum printk_info_flags {
LOG_NEWLINE = 2, /* text ended with a newline */
LOG_CONT = 8, /* text is a fragment of a continuation line */
};
__printf(4, 0) __printf(4, 0)
int vprintk_store(int facility, int level, int vprintk_store(int facility, int level,
const struct dev_printk_info *dev_info, const struct dev_printk_info *dev_info,
......
...@@ -350,11 +350,6 @@ static int console_msg_format = MSG_FORMAT_DEFAULT; ...@@ -350,11 +350,6 @@ static int console_msg_format = MSG_FORMAT_DEFAULT;
* non-prinatable characters are escaped in the "\xff" notation. * non-prinatable characters are escaped in the "\xff" notation.
*/ */
enum log_flags {
LOG_NEWLINE = 2, /* text ended with a newline */
LOG_CONT = 8, /* text is a fragment of a continuation line */
};
/* syslog_lock protects syslog_* variables and write access to clear_seq. */ /* syslog_lock protects syslog_* variables and write access to clear_seq. */
static DEFINE_RAW_SPINLOCK(syslog_lock); static DEFINE_RAW_SPINLOCK(syslog_lock);
...@@ -1965,19 +1960,20 @@ static inline u32 printk_caller_id(void) ...@@ -1965,19 +1960,20 @@ static inline u32 printk_caller_id(void)
* *
* @text: The terminated text message. * @text: The terminated text message.
* @level: A pointer to the current level value, will be updated. * @level: A pointer to the current level value, will be updated.
* @lflags: A pointer to the current log flags, will be updated. * @flags: A pointer to the current printk_info flags, will be updated.
* *
* @level may be NULL if the caller is not interested in the parsed value. * @level may be NULL if the caller is not interested in the parsed value.
* Otherwise the variable pointed to by @level must be set to * Otherwise the variable pointed to by @level must be set to
* LOGLEVEL_DEFAULT in order to be updated with the parsed value. * LOGLEVEL_DEFAULT in order to be updated with the parsed value.
* *
* @lflags may be NULL if the caller is not interested in the parsed value. * @flags may be NULL if the caller is not interested in the parsed value.
* Otherwise the variable pointed to by @lflags will be OR'd with the parsed * Otherwise the variable pointed to by @flags will be OR'd with the parsed
* value. * value.
* *
* Return: The length of the parsed level and control flags. * Return: The length of the parsed level and control flags.
*/ */
static u16 parse_prefix(char *text, int *level, enum log_flags *lflags) static u16 parse_prefix(char *text, int *level,
enum printk_info_flags *flags)
{ {
u16 prefix_len = 0; u16 prefix_len = 0;
int kern_level; int kern_level;
...@@ -1993,8 +1989,8 @@ static u16 parse_prefix(char *text, int *level, enum log_flags *lflags) ...@@ -1993,8 +1989,8 @@ static u16 parse_prefix(char *text, int *level, enum log_flags *lflags)
*level = kern_level - '0'; *level = kern_level - '0';
break; break;
case 'c': /* KERN_CONT */ case 'c': /* KERN_CONT */
if (lflags) if (flags)
*lflags |= LOG_CONT; *flags |= LOG_CONT;
} }
prefix_len += 2; prefix_len += 2;
...@@ -2004,8 +2000,9 @@ static u16 parse_prefix(char *text, int *level, enum log_flags *lflags) ...@@ -2004,8 +2000,9 @@ static u16 parse_prefix(char *text, int *level, enum log_flags *lflags)
return prefix_len; return prefix_len;
} }
static u16 printk_sprint(char *text, u16 size, int facility, enum log_flags *lflags, static u16 printk_sprint(char *text, u16 size, int facility,
const char *fmt, va_list args) enum printk_info_flags *flags, const char *fmt,
va_list args)
{ {
u16 text_len; u16 text_len;
...@@ -2014,7 +2011,7 @@ static u16 printk_sprint(char *text, u16 size, int facility, enum log_flags *lfl ...@@ -2014,7 +2011,7 @@ static u16 printk_sprint(char *text, u16 size, int facility, enum log_flags *lfl
/* Mark and strip a trailing newline. */ /* Mark and strip a trailing newline. */
if (text_len && text[text_len - 1] == '\n') { if (text_len && text[text_len - 1] == '\n') {
text_len--; text_len--;
*lflags |= LOG_NEWLINE; *flags |= LOG_NEWLINE;
} }
/* Strip log level and control flags. */ /* Strip log level and control flags. */
...@@ -2038,7 +2035,7 @@ int vprintk_store(int facility, int level, ...@@ -2038,7 +2035,7 @@ int vprintk_store(int facility, int level,
{ {
const u32 caller_id = printk_caller_id(); const u32 caller_id = printk_caller_id();
struct prb_reserved_entry e; struct prb_reserved_entry e;
enum log_flags lflags = 0; enum printk_info_flags flags = 0;
struct printk_record r; struct printk_record r;
u16 trunc_msg_len = 0; u16 trunc_msg_len = 0;
char prefix_buf[8]; char prefix_buf[8];
...@@ -2070,22 +2067,22 @@ int vprintk_store(int facility, int level, ...@@ -2070,22 +2067,22 @@ int vprintk_store(int facility, int level,
/* Extract log level or control flags. */ /* Extract log level or control flags. */
if (facility == 0) if (facility == 0)
parse_prefix(&prefix_buf[0], &level, &lflags); parse_prefix(&prefix_buf[0], &level, &flags);
if (level == LOGLEVEL_DEFAULT) if (level == LOGLEVEL_DEFAULT)
level = default_message_loglevel; level = default_message_loglevel;
if (dev_info) if (dev_info)
lflags |= LOG_NEWLINE; flags |= LOG_NEWLINE;
if (lflags & LOG_CONT) { if (flags & LOG_CONT) {
prb_rec_init_wr(&r, reserve_size); prb_rec_init_wr(&r, reserve_size);
if (prb_reserve_in_last(&e, prb, &r, caller_id, LOG_LINE_MAX)) { if (prb_reserve_in_last(&e, prb, &r, caller_id, LOG_LINE_MAX)) {
text_len = printk_sprint(&r.text_buf[r.info->text_len], reserve_size, text_len = printk_sprint(&r.text_buf[r.info->text_len], reserve_size,
facility, &lflags, fmt, args); facility, &flags, fmt, args);
r.info->text_len += text_len; r.info->text_len += text_len;
if (lflags & LOG_NEWLINE) { if (flags & LOG_NEWLINE) {
r.info->flags |= LOG_NEWLINE; r.info->flags |= LOG_NEWLINE;
prb_final_commit(&e); prb_final_commit(&e);
} else { } else {
...@@ -2112,20 +2109,20 @@ int vprintk_store(int facility, int level, ...@@ -2112,20 +2109,20 @@ int vprintk_store(int facility, int level,
} }
/* fill message */ /* fill message */
text_len = printk_sprint(&r.text_buf[0], reserve_size, facility, &lflags, fmt, args); text_len = printk_sprint(&r.text_buf[0], reserve_size, facility, &flags, fmt, args);
if (trunc_msg_len) if (trunc_msg_len)
memcpy(&r.text_buf[text_len], trunc_msg, trunc_msg_len); memcpy(&r.text_buf[text_len], trunc_msg, trunc_msg_len);
r.info->text_len = text_len + trunc_msg_len; r.info->text_len = text_len + trunc_msg_len;
r.info->facility = facility; r.info->facility = facility;
r.info->level = level & 7; r.info->level = level & 7;
r.info->flags = lflags & 0x1f; r.info->flags = flags & 0x1f;
r.info->ts_nsec = ts_nsec; r.info->ts_nsec = ts_nsec;
r.info->caller_id = caller_id; r.info->caller_id = caller_id;
if (dev_info) if (dev_info)
memcpy(&r.info->dev_info, dev_info, sizeof(r.info->dev_info)); memcpy(&r.info->dev_info, dev_info, sizeof(r.info->dev_info));
/* A message without a trailing newline can be continued. */ /* A message without a trailing newline can be continued. */
if (!(lflags & LOG_NEWLINE)) if (!(flags & LOG_NEWLINE))
prb_commit(&e); prb_commit(&e);
else else
prb_final_commit(&e); prb_final_commit(&e);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment