2013-07-15 21:51:42

by Joe Perches

[permalink] [raw]
Subject: [v3.11-rc1 PATCH 0/5] printk: Initial restructuring

Back last year, I posted a largish restructuring of printk.

V1: https://lkml.org/lkml/2012/10/17/41
V2: https://lkml.org/lkml/2012/10/24/748

The idea was to break up this way too large a file into
something more manageable and readable.

This is another posting of just the first few patches of this
series rebased onto v3.11-rc1

If this is acceptable, I'll post 5 or so patches at a time
after/if each block of patches is applied.

Joe Perches (5):
printk: Move to separate directory for easier modification
printk: Add console_cmdline.h
printk: Move braille console support into separate braille.[ch] files
printk: Use pointer for console_cmdline indexing
printk: rename struct log to struct printk_log

drivers/accessibility/braille/braille_console.c | 9 +-
kernel/Makefile | 3 +-
kernel/printk/Makefile | 2 +
kernel/printk/braille.c | 48 ++++++
kernel/printk/braille.h | 48 ++++++
kernel/printk/console_cmdline.h | 14 ++
kernel/{ => printk}/printk.c | 185 +++++++++++-------------
7 files changed, 202 insertions(+), 107 deletions(-)
create mode 100644 kernel/printk/Makefile
create mode 100644 kernel/printk/braille.c
create mode 100644 kernel/printk/braille.h
create mode 100644 kernel/printk/console_cmdline.h
rename kernel/{ => printk}/printk.c (95%)

--
1.8.1.2.459.gbcd45b4.dirty


2013-07-15 21:51:51

by Joe Perches

[permalink] [raw]
Subject: [v3.11-rc1 PATCH 1/5] printk: Move to separate directory for easier modification

Make it easier to break up printk into bite-sized chunks.

Remove printk path/filename from comment.

Signed-off-by: Joe Perches <[email protected]>
---
kernel/Makefile | 3 ++-
kernel/printk/Makefile | 1 +
kernel/{ => printk}/printk.c | 2 --
3 files changed, 3 insertions(+), 3 deletions(-)
create mode 100644 kernel/printk/Makefile
rename kernel/{ => printk}/printk.c (99%)

diff --git a/kernel/Makefile b/kernel/Makefile
index 470839d..35ef118 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -2,7 +2,7 @@
# Makefile for the linux kernel.
#

-obj-y = fork.o exec_domain.o panic.o printk.o \
+obj-y = fork.o exec_domain.o panic.o \
cpu.o exit.o itimer.o time.o softirq.o resource.o \
sysctl.o sysctl_binary.o capability.o ptrace.o timer.o user.o \
signal.o sys.o kmod.o workqueue.o pid.o task_work.o \
@@ -24,6 +24,7 @@ endif

obj-y += sched/
obj-y += power/
+obj-y += printk/
obj-y += cpu/

obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
diff --git a/kernel/printk/Makefile b/kernel/printk/Makefile
new file mode 100644
index 0000000..36d306d
--- /dev/null
+++ b/kernel/printk/Makefile
@@ -0,0 +1 @@
+obj-y = printk.o
diff --git a/kernel/printk.c b/kernel/printk/printk.c
similarity index 99%
rename from kernel/printk.c
rename to kernel/printk/printk.c
index d37d45c..cd5a6cf 100644
--- a/kernel/printk.c
+++ b/kernel/printk/printk.c
@@ -1,6 +1,4 @@
/*
- * linux/kernel/printk.c
- *
* Copyright (C) 1991, 1992 Linus Torvalds
*
* Modified to make sys_syslog() more flexible: added commands to
--
1.8.1.2.459.gbcd45b4.dirty

2013-07-15 21:52:00

by Joe Perches

[permalink] [raw]
Subject: [v3.11-rc1 PATCH 2/5] printk: Add console_cmdline.h

Add an include file for the console_cmdline struct
so that the braille console driver can be separated.

Signed-off-by: Joe Perches <[email protected]>
---
kernel/printk/console_cmdline.h | 14 ++++++++++++++
kernel/printk/printk.c | 12 +++---------
2 files changed, 17 insertions(+), 9 deletions(-)
create mode 100644 kernel/printk/console_cmdline.h

diff --git a/kernel/printk/console_cmdline.h b/kernel/printk/console_cmdline.h
new file mode 100644
index 0000000..cbd69d8
--- /dev/null
+++ b/kernel/printk/console_cmdline.h
@@ -0,0 +1,14 @@
+#ifndef _CONSOLE_CMDLINE_H
+#define _CONSOLE_CMDLINE_H
+
+struct console_cmdline
+{
+ char name[8]; /* Name of the driver */
+ int index; /* Minor dev. to use */
+ char *options; /* Options for the driver */
+#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
+ char *brl_options; /* Options for braille driver */
+#endif
+};
+
+#endif
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index cd5a6cf..4e9a982 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -49,6 +49,8 @@
#define CREATE_TRACE_POINTS
#include <trace/events/printk.h>

+#include "console_cmdline.h"
+
/* printk's without a loglevel use this.. */
#define DEFAULT_MESSAGE_LOGLEVEL CONFIG_DEFAULT_MESSAGE_LOGLEVEL

@@ -103,19 +105,11 @@ static struct console *exclusive_console;
/*
* Array of consoles built from command line options (console=)
*/
-struct console_cmdline
-{
- char name[8]; /* Name of the driver */
- int index; /* Minor dev. to use */
- char *options; /* Options for the driver */
-#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
- char *brl_options; /* Options for braille driver */
-#endif
-};

#define MAX_CMDLINECONSOLES 8

static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
+
static int selected_console = -1;
static int preferred_console = -1;
int console_set_on_cmdline;
--
1.8.1.2.459.gbcd45b4.dirty

2013-07-15 21:52:12

by Joe Perches

[permalink] [raw]
Subject: [v3.11-rc1 PATCH 3/5] printk: Move braille console support into separate braille.[ch] files

Create files with prototypes and static inlines for braille
support. Make braille_console functions return 1 on success.

Corrected CONFIG_A11Y_BRAILLE_CONSOLE=n _braille_console_setup
return value to NULL.

link: http://lkml.kernel.org/r/[email protected]
cc: Samuel Thibault <[email protected]>
cc: Ming Lei <[email protected]>

Signed-off-by: Joe Perches <[email protected]>
---
drivers/accessibility/braille/braille_console.c | 9 +++--
kernel/printk/Makefile | 1 +
kernel/printk/braille.c | 48 +++++++++++++++++++++++++
kernel/printk/braille.h | 48 +++++++++++++++++++++++++
kernel/printk/printk.c | 44 +++++++----------------
5 files changed, 117 insertions(+), 33 deletions(-)
create mode 100644 kernel/printk/braille.c
create mode 100644 kernel/printk/braille.h

diff --git a/drivers/accessibility/braille/braille_console.c b/drivers/accessibility/braille/braille_console.c
index d21167b..dc34a5b 100644
--- a/drivers/accessibility/braille/braille_console.c
+++ b/drivers/accessibility/braille/braille_console.c
@@ -359,6 +359,9 @@ int braille_register_console(struct console *console, int index,
char *console_options, char *braille_options)
{
int ret;
+
+ if (!(console->flags & CON_BRL))
+ return 0;
if (!console_options)
/* Only support VisioBraille for now */
console_options = "57600o8";
@@ -374,15 +377,17 @@ int braille_register_console(struct console *console, int index,
braille_co = console;
register_keyboard_notifier(&keyboard_notifier_block);
register_vt_notifier(&vt_notifier_block);
- return 0;
+ return 1;
}

int braille_unregister_console(struct console *console)
{
if (braille_co != console)
return -EINVAL;
+ if (!(console->flags & CON_BRL))
+ return 0;
unregister_keyboard_notifier(&keyboard_notifier_block);
unregister_vt_notifier(&vt_notifier_block);
braille_co = NULL;
- return 0;
+ return 1;
}
diff --git a/kernel/printk/Makefile b/kernel/printk/Makefile
index 36d306d..85405bd 100644
--- a/kernel/printk/Makefile
+++ b/kernel/printk/Makefile
@@ -1 +1,2 @@
obj-y = printk.o
+obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) += braille.o
diff --git a/kernel/printk/braille.c b/kernel/printk/braille.c
new file mode 100644
index 0000000..b51087f
--- /dev/null
+++ b/kernel/printk/braille.c
@@ -0,0 +1,48 @@
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/kernel.h>
+#include <linux/console.h>
+#include <linux/string.h>
+
+#include "console_cmdline.h"
+#include "braille.h"
+
+char *_braille_console_setup(char **str, char **brl_options)
+{
+ if (!memcmp(*str, "brl,", 4)) {
+ *brl_options = "";
+ *str += 4;
+ } else if (!memcmp(str, "brl=", 4)) {
+ *brl_options = *str + 4;
+ *str = strchr(*brl_options, ',');
+ if (!*str)
+ pr_err("need port name after brl=\n");
+ else
+ *((*str)++) = 0;
+ }
+
+ return *str;
+}
+
+int
+_braille_register_console(struct console *console, struct console_cmdline *c)
+{
+ int rtn = 0;
+
+ if (c->brl_options) {
+ console->flags |= CON_BRL;
+ rtn = braille_register_console(console, c->index, c->options,
+ c->brl_options);
+ }
+
+ return rtn;
+}
+
+int
+_braille_unregister_console(struct console *console)
+{
+ if (console->flags & CON_BRL)
+ return braille_unregister_console(console);
+
+ return 0;
+}
diff --git a/kernel/printk/braille.h b/kernel/printk/braille.h
new file mode 100644
index 0000000..769d771
--- /dev/null
+++ b/kernel/printk/braille.h
@@ -0,0 +1,48 @@
+#ifndef _PRINTK_BRAILLE_H
+#define _PRINTK_BRAILLE_H
+
+#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
+
+static inline void
+braille_set_options(struct console_cmdline *c, char *brl_options)
+{
+ c->brl_options = brl_options;
+}
+
+char *
+_braille_console_setup(char **str, char **brl_options);
+
+int
+_braille_register_console(struct console *console, struct console_cmdline *c);
+
+int
+_braille_unregister_console(struct console *console);
+
+#else
+
+static inline void
+braille_set_options(struct console_cmdline *c, char *brl_options)
+{
+}
+
+static inline char *
+_braille_console_setup(char **str, char **brl_options)
+{
+ return NULL;
+}
+
+static inline int
+_braille_register_console(struct console *console, struct console_cmdline *c)
+{
+ return 0;
+}
+
+static inline int
+_braille_unregister_console(struct console *console)
+{
+ return 0;
+}
+
+#endif
+
+#endif
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 4e9a982..7c4020c 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -50,6 +50,7 @@
#include <trace/events/printk.h>

#include "console_cmdline.h"
+#include "braille.h"

/* printk's without a loglevel use this.. */
#define DEFAULT_MESSAGE_LOGLEVEL CONFIG_DEFAULT_MESSAGE_LOGLEVEL
@@ -1767,9 +1768,8 @@ static int __add_preferred_console(char *name, int idx, char *options,
c = &console_cmdline[i];
strlcpy(c->name, name, sizeof(c->name));
c->options = options;
-#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
- c->brl_options = brl_options;
-#endif
+ braille_set_options(c, brl_options);
+
c->index = idx;
return 0;
}
@@ -1782,20 +1782,8 @@ static int __init console_setup(char *str)
char *s, *options, *brl_options = NULL;
int idx;

-#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
- if (!memcmp(str, "brl,", 4)) {
- brl_options = "";
- str += 4;
- } else if (!memcmp(str, "brl=", 4)) {
- brl_options = str + 4;
- str = strchr(brl_options, ',');
- if (!str) {
- printk(KERN_ERR "need port name after brl=\n");
- return 1;
- }
- *(str++) = 0;
- }
-#endif
+ if (_braille_console_setup(&str, &brl_options))
+ return 1;

/*
* Decode str into name, index, options.
@@ -2289,16 +2277,10 @@ void register_console(struct console *newcon)
continue;
if (newcon->index < 0)
newcon->index = console_cmdline[i].index;
-#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
- if (console_cmdline[i].brl_options) {
- newcon->flags |= CON_BRL;
- braille_register_console(newcon,
- console_cmdline[i].index,
- console_cmdline[i].options,
- console_cmdline[i].brl_options);
+
+ if (_braille_register_console(newcon, &console_cmdline[i]))
return;
- }
-#endif
+
if (newcon->setup &&
newcon->setup(newcon, console_cmdline[i].options) != 0)
break;
@@ -2386,13 +2368,13 @@ EXPORT_SYMBOL(register_console);
int unregister_console(struct console *console)
{
struct console *a, *b;
- int res = 1;
+ int res;

-#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
- if (console->flags & CON_BRL)
- return braille_unregister_console(console);
-#endif
+ res = _braille_unregister_console(console);
+ if (res)
+ return res;

+ res = 1;
console_lock();
if (console_drivers == console) {
console_drivers=console->next;
--
1.8.1.2.459.gbcd45b4.dirty

2013-07-15 21:52:21

by Joe Perches

[permalink] [raw]
Subject: [v3.11-rc1 PATCH 4/5] printk: Use pointer for console_cmdline indexing

Make the code a bit more compact by always using a pointer
for the active console_cmdline.

Move overly indented code to correct indent level.

Signed-off-by: Joe Perches <[email protected]>
---
kernel/printk/printk.c | 49 ++++++++++++++++++++++++++-----------------------
1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 7c4020c..008eef4 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1754,18 +1754,19 @@ static int __add_preferred_console(char *name, int idx, char *options,
* See if this tty is not yet registered, and
* if we have a slot free.
*/
- for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++)
- if (strcmp(console_cmdline[i].name, name) == 0 &&
- console_cmdline[i].index == idx) {
- if (!brl_options)
- selected_console = i;
- return 0;
+ for (i = 0, c = console_cmdline;
+ i < MAX_CMDLINECONSOLES && c->name[0];
+ i++, c++) {
+ if (strcmp(c->name, name) == 0 && c->index == idx) {
+ if (!brl_options)
+ selected_console = i;
+ return 0;
}
+ }
if (i == MAX_CMDLINECONSOLES)
return -E2BIG;
if (!brl_options)
selected_console = i;
- c = &console_cmdline[i];
strlcpy(c->name, name, sizeof(c->name));
c->options = options;
braille_set_options(c, brl_options);
@@ -1838,15 +1839,15 @@ int update_console_cmdline(char *name, int idx, char *name_new, int idx_new, cha
struct console_cmdline *c;
int i;

- for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++)
- if (strcmp(console_cmdline[i].name, name) == 0 &&
- console_cmdline[i].index == idx) {
- c = &console_cmdline[i];
- strlcpy(c->name, name_new, sizeof(c->name));
- c->name[sizeof(c->name) - 1] = 0;
- c->options = options;
- c->index = idx_new;
- return i;
+ for (i = 0, c = console_cmdline;
+ i < MAX_CMDLINECONSOLES && c->name[0];
+ i++, c++)
+ if (strcmp(c->name, name) == 0 && c->index == idx) {
+ strlcpy(c->name, name_new, sizeof(c->name));
+ c->name[sizeof(c->name) - 1] = 0;
+ c->options = options;
+ c->index = idx_new;
+ return i;
}
/* not found */
return -1;
@@ -2221,6 +2222,7 @@ void register_console(struct console *newcon)
int i;
unsigned long flags;
struct console *bcon = NULL;
+ struct console_cmdline *c;

/*
* before we register a new CON_BOOT console, make sure we don't
@@ -2268,24 +2270,25 @@ void register_console(struct console *newcon)
* See if this console matches one we selected on
* the command line.
*/
- for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0];
- i++) {
- if (strcmp(console_cmdline[i].name, newcon->name) != 0)
+ for (i = 0, c = console_cmdline;
+ i < MAX_CMDLINECONSOLES && c->name[0];
+ i++, c++) {
+ if (strcmp(c->name, newcon->name) != 0)
continue;
if (newcon->index >= 0 &&
- newcon->index != console_cmdline[i].index)
+ newcon->index != c->index)
continue;
if (newcon->index < 0)
- newcon->index = console_cmdline[i].index;
+ newcon->index = c->index;

- if (_braille_register_console(newcon, &console_cmdline[i]))
+ if (_braille_register_console(newcon, c))
return;

if (newcon->setup &&
newcon->setup(newcon, console_cmdline[i].options) != 0)
break;
newcon->flags |= CON_ENABLED;
- newcon->index = console_cmdline[i].index;
+ newcon->index = c->index;
if (i == selected_console) {
newcon->flags |= CON_CONSDEV;
preferred_console = selected_console;
--
1.8.1.2.459.gbcd45b4.dirty

2013-07-15 21:52:31

by Joe Perches

[permalink] [raw]
Subject: [v3.11-rc1 PATCH 5/5] printk: rename struct log to struct printk_log

Rename the struct to enable moving portions of
printk.c to separate files.

The rename changes output of /proc/vmcoreinfo.

Signed-off-by: Joe Perches <[email protected]>
---
kernel/printk/printk.c | 80 +++++++++++++++++++++++++-------------------------
1 file changed, 40 insertions(+), 40 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 008eef4..860ba8b 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -171,7 +171,7 @@ static int console_may_schedule;
* 67 "g"
* 0032 00 00 00 padding to next message header
*
- * The 'struct log' buffer header must never be directly exported to
+ * The 'struct printk_log' buffer header must never be directly exported to
* userspace, it is a kernel-private implementation detail that might
* need to be changed in the future, when the requirements change.
*
@@ -193,7 +193,7 @@ enum log_flags {
LOG_CONT = 8, /* text is a fragment of a continuation line */
};

-struct log {
+struct printk_log {
u64 ts_nsec; /* timestamp in nanoseconds */
u16 len; /* length of entire record */
u16 text_len; /* length of text buffer */
@@ -241,7 +241,7 @@ static u32 clear_idx;
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
#define LOG_ALIGN 4
#else
-#define LOG_ALIGN __alignof__(struct log)
+#define LOG_ALIGN __alignof__(struct printk_log)
#endif
#define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)
static char __log_buf[__LOG_BUF_LEN] __aligned(LOG_ALIGN);
@@ -252,35 +252,35 @@ static u32 log_buf_len = __LOG_BUF_LEN;
static volatile unsigned int logbuf_cpu = UINT_MAX;

/* human readable text of the record */
-static char *log_text(const struct log *msg)
+static char *log_text(const struct printk_log *msg)
{
- return (char *)msg + sizeof(struct log);
+ return (char *)msg + sizeof(struct printk_log);
}

/* optional key/value pair dictionary attached to the record */
-static char *log_dict(const struct log *msg)
+static char *log_dict(const struct printk_log *msg)
{
- return (char *)msg + sizeof(struct log) + msg->text_len;
+ return (char *)msg + sizeof(struct printk_log) + msg->text_len;
}

/* get record by index; idx must point to valid msg */
-static struct log *log_from_idx(u32 idx)
+static struct printk_log *log_from_idx(u32 idx)
{
- struct log *msg = (struct log *)(log_buf + idx);
+ struct printk_log *msg = (struct printk_log *)(log_buf + idx);

/*
* A length == 0 record is the end of buffer marker. Wrap around and
* read the message at the start of the buffer.
*/
if (!msg->len)
- return (struct log *)log_buf;
+ return (struct printk_log *)log_buf;
return msg;
}

/* get next record; idx must point to valid msg */
static u32 log_next(u32 idx)
{
- struct log *msg = (struct log *)(log_buf + idx);
+ struct printk_log *msg = (struct printk_log *)(log_buf + idx);

/* length == 0 indicates the end of the buffer; wrap */
/*
@@ -289,7 +289,7 @@ static u32 log_next(u32 idx)
* return the one after that.
*/
if (!msg->len) {
- msg = (struct log *)log_buf;
+ msg = (struct printk_log *)log_buf;
return msg->len;
}
return idx + msg->len;
@@ -301,11 +301,11 @@ static void log_store(int facility, int level,
const char *dict, u16 dict_len,
const char *text, u16 text_len)
{
- struct log *msg;
+ struct printk_log *msg;
u32 size, pad_len;

/* number of '\0' padding bytes to next message */
- size = sizeof(struct log) + text_len + dict_len;
+ size = sizeof(struct printk_log) + text_len + dict_len;
pad_len = (-size) & (LOG_ALIGN - 1);
size += pad_len;

@@ -317,7 +317,7 @@ static void log_store(int facility, int level,
else
free = log_first_idx - log_next_idx;

- if (free > size + sizeof(struct log))
+ if (free > size + sizeof(struct printk_log))
break;

/* drop old messages until we have enough contiuous space */
@@ -325,18 +325,18 @@ static void log_store(int facility, int level,
log_first_seq++;
}

- if (log_next_idx + size + sizeof(struct log) >= log_buf_len) {
+ if (log_next_idx + size + sizeof(struct printk_log) >= log_buf_len) {
/*
* This message + an additional empty header does not fit
* at the end of the buffer. Add an empty header with len == 0
* to signify a wrap around.
*/
- memset(log_buf + log_next_idx, 0, sizeof(struct log));
+ memset(log_buf + log_next_idx, 0, sizeof(struct printk_log));
log_next_idx = 0;
}

/* fill message */
- msg = (struct log *)(log_buf + log_next_idx);
+ msg = (struct printk_log *)(log_buf + log_next_idx);
memcpy(log_text(msg), text, text_len);
msg->text_len = text_len;
memcpy(log_dict(msg), dict, dict_len);
@@ -349,7 +349,7 @@ static void log_store(int facility, int level,
else
msg->ts_nsec = local_clock();
memset(log_dict(msg) + dict_len, 0, pad_len);
- msg->len = sizeof(struct log) + text_len + dict_len + pad_len;
+ msg->len = sizeof(struct printk_log) + text_len + dict_len + pad_len;

/* insert message */
log_next_idx += msg->len;
@@ -472,7 +472,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
struct devkmsg_user *user = file->private_data;
- struct log *msg;
+ struct printk_log *msg;
u64 ts_usec;
size_t i;
char cont = '-';
@@ -717,14 +717,14 @@ void log_buf_kexec_setup(void)
VMCOREINFO_SYMBOL(log_first_idx);
VMCOREINFO_SYMBOL(log_next_idx);
/*
- * Export struct log size and field offsets. User space tools can
+ * Export struct printk_log size and field offsets. User space tools can
* parse it and detect any changes to structure down the line.
*/
- VMCOREINFO_STRUCT_SIZE(log);
- VMCOREINFO_OFFSET(log, ts_nsec);
- VMCOREINFO_OFFSET(log, len);
- VMCOREINFO_OFFSET(log, text_len);
- VMCOREINFO_OFFSET(log, dict_len);
+ VMCOREINFO_STRUCT_SIZE(printk_log);
+ VMCOREINFO_OFFSET(printk_log, ts_nsec);
+ VMCOREINFO_OFFSET(printk_log, len);
+ VMCOREINFO_OFFSET(printk_log, text_len);
+ VMCOREINFO_OFFSET(printk_log, dict_len);
}
#endif

@@ -877,7 +877,7 @@ static size_t print_time(u64 ts, char *buf)
(unsigned long)ts, rem_nsec / 1000);
}

-static size_t print_prefix(const struct log *msg, bool syslog, char *buf)
+static size_t print_prefix(const struct printk_log *msg, bool syslog, char *buf)
{
size_t len = 0;
unsigned int prefix = (msg->facility << 3) | msg->level;
@@ -900,7 +900,7 @@ static size_t print_prefix(const struct log *msg, bool syslog, char *buf)
return len;
}

-static size_t msg_print_text(const struct log *msg, enum log_flags prev,
+static size_t msg_print_text(const struct printk_log *msg, enum log_flags prev,
bool syslog, char *buf, size_t size)
{
const char *text = log_text(msg);
@@ -962,7 +962,7 @@ static size_t msg_print_text(const struct log *msg, enum log_flags prev,
static int syslog_print(char __user *buf, int size)
{
char *text;
- struct log *msg;
+ struct printk_log *msg;
int len = 0;

text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
@@ -1053,7 +1053,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
idx = clear_idx;
prev = 0;
while (seq < log_next_seq) {
- struct log *msg = log_from_idx(idx);
+ struct printk_log *msg = log_from_idx(idx);

len += msg_print_text(msg, prev, true, NULL, 0);
prev = msg->flags;
@@ -1066,7 +1066,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
idx = clear_idx;
prev = 0;
while (len > size && seq < log_next_seq) {
- struct log *msg = log_from_idx(idx);
+ struct printk_log *msg = log_from_idx(idx);

len -= msg_print_text(msg, prev, true, NULL, 0);
prev = msg->flags;
@@ -1080,7 +1080,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
len = 0;
prev = 0;
while (len >= 0 && seq < next_seq) {
- struct log *msg = log_from_idx(idx);
+ struct printk_log *msg = log_from_idx(idx);
int textlen;

textlen = msg_print_text(msg, prev, true, text,
@@ -1226,7 +1226,7 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)

error = 0;
while (seq < log_next_seq) {
- struct log *msg = log_from_idx(idx);
+ struct printk_log *msg = log_from_idx(idx);

error += msg_print_text(msg, prev, true, NULL, 0);
idx = log_next(idx);
@@ -1712,10 +1712,10 @@ static struct cont {
u8 level;
bool flushed:1;
} cont;
-static struct log *log_from_idx(u32 idx) { return NULL; }
+static struct printk_log *log_from_idx(u32 idx) { return NULL; }
static u32 log_next(u32 idx) { return 0; }
static void call_console_drivers(int level, const char *text, size_t len) {}
-static size_t msg_print_text(const struct log *msg, enum log_flags prev,
+static size_t msg_print_text(const struct printk_log *msg, enum log_flags prev,
bool syslog, char *buf, size_t size) { return 0; }
static size_t cont_print_text(char *text, size_t size) { return 0; }

@@ -2027,7 +2027,7 @@ void console_unlock(void)
console_cont_flush(text, sizeof(text));
again:
for (;;) {
- struct log *msg;
+ struct printk_log *msg;
size_t len;
int level;

@@ -2643,7 +2643,7 @@ void kmsg_dump(enum kmsg_dump_reason reason)
bool kmsg_dump_get_line_nolock(struct kmsg_dumper *dumper, bool syslog,
char *line, size_t size, size_t *len)
{
- struct log *msg;
+ struct printk_log *msg;
size_t l = 0;
bool ret = false;

@@ -2755,7 +2755,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
idx = dumper->cur_idx;
prev = 0;
while (seq < dumper->next_seq) {
- struct log *msg = log_from_idx(idx);
+ struct printk_log *msg = log_from_idx(idx);

l += msg_print_text(msg, prev, true, NULL, 0);
idx = log_next(idx);
@@ -2768,7 +2768,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
idx = dumper->cur_idx;
prev = 0;
while (l > size && seq < dumper->next_seq) {
- struct log *msg = log_from_idx(idx);
+ struct printk_log *msg = log_from_idx(idx);

l -= msg_print_text(msg, prev, true, NULL, 0);
idx = log_next(idx);
@@ -2783,7 +2783,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
l = 0;
prev = 0;
while (seq < dumper->next_seq) {
- struct log *msg = log_from_idx(idx);
+ struct printk_log *msg = log_from_idx(idx);

l += msg_print_text(msg, prev, syslog, buf + l, size - l);
idx = log_next(idx);
--
1.8.1.2.459.gbcd45b4.dirty

2013-07-17 01:48:15

by Linus Torvalds

[permalink] [raw]
Subject: Re: [v3.11-rc1 PATCH 0/5] printk: Initial restructuring

On Mon, Jul 15, 2013 at 2:51 PM, Joe Perches <[email protected]> wrote:
>
> If this is acceptable, I'll post 5 or so patches at a time
> after/if each block of patches is applied.

I didn't see anything objectionable, but I'm assuming this comes in
through Andrew? And hopefully gets comments from others too..

Linus

2013-07-17 01:56:42

by Joe Perches

[permalink] [raw]
Subject: Re: [v3.11-rc1 PATCH 0/5] printk: Initial restructuring

On Tue, 2013-07-16 at 18:48 -0700, Linus Torvalds wrote:
> On Mon, Jul 15, 2013 at 2:51 PM, Joe Perches <[email protected]> wrote:
> >
> > If this is acceptable, I'll post 5 or so patches at a time
> > after/if each block of patches is applied.
>
> I didn't see anything objectionable, but I'm assuming this comes in
> through Andrew?

I'd rather you take it directly now.

> And hopefully gets comments from others too..

There were a few 9 months ago.

Mostly it was a timing issue as to who
takes it and when.

printk still moves around quite a bit
and Andrew suggested shortly after
an -rc1 was likely the best timing.

http://lkml.indiana.edu/hypermail/linux/kernel/1212.0/02931.html

As far as I'm concerned, the biggest
deal is starting this refactoring.

It doesn't have to be an big blast
like what was submitted last year,
but it should be started sooner
rather never.

2013-07-17 22:31:27

by Andrew Morton

[permalink] [raw]
Subject: Re: [v3.11-rc1 PATCH 0/5] printk: Initial restructuring

On Tue, 16 Jul 2013 18:56:39 -0700 Joe Perches <[email protected]> wrote:

> On Tue, 2013-07-16 at 18:48 -0700, Linus Torvalds wrote:
> > On Mon, Jul 15, 2013 at 2:51 PM, Joe Perches <[email protected]> wrote:
> > >
> > > If this is acceptable, I'll post 5 or so patches at a time
> > > after/if each block of patches is applied.
> >
> > I didn't see anything objectionable, but I'm assuming this comes in
> > through Andrew?
>
> I'd rather you take it directly now.
>
> > And hopefully gets comments from others too..
>
> There were a few 9 months ago.
>
> Mostly it was a timing issue as to who
> takes it and when.

Well it also broke the build a bit, iirc.

I grabbed them and will give them a run in -next for a week or so. If
that's OK then I'll try to offload everything onto Linus rather than
having to spend two months battling with linux-next monkeyscratchings.

2013-07-18 00:01:53

by Joe Perches

[permalink] [raw]
Subject: Re: [v3.11-rc1 PATCH 0/5] printk: Initial restructuring

On Wed, 2013-07-17 at 15:31 -0700, Andrew Morton wrote:
> On Tue, 16 Jul 2013 18:56:39 -0700 Joe Perches <[email protected]> wrote:
> > There were a few 9 months ago.
> >
> > Mostly it was a timing issue as to who
> > takes it and when.
>
> Well it also broke the build a bit, iirc.

V1 did with a !CONFIG_PRINTK, v2 fixed that.

> I grabbed them and will give them a run in -next for a week or so. If
> that's OK then I'll try to offload everything onto Linus rather than
> having to spend two months battling with linux-next monkeyscratchings.

Yup, that's the problem...

2013-07-20 14:48:41

by Samuel Thibault

[permalink] [raw]
Subject: Re: [v3.11-rc1 PATCH 3/5] printk: Move braille console support into separate braille.[ch] files

Joe Perches, le Mon 15 Jul 2013 14:51:33 -0700, a ?crit :
> Create files with prototypes and static inlines for braille
> support. Make braille_console functions return 1 on success.
>
> Corrected CONFIG_A11Y_BRAILLE_CONSOLE=n _braille_console_setup
> return value to NULL.
>
> link: http://lkml.kernel.org/r/[email protected]
> cc: Samuel Thibault <[email protected]>

Reviewed-By: Samuel Thibault <[email protected]>

Thanks,
Samuel

> cc: Ming Lei <[email protected]>
> Signed-off-by: Joe Perches <[email protected]>
> ---
> drivers/accessibility/braille/braille_console.c | 9 +++--
> kernel/printk/Makefile | 1 +
> kernel/printk/braille.c | 48 +++++++++++++++++++++++++
> kernel/printk/braille.h | 48 +++++++++++++++++++++++++
> kernel/printk/printk.c | 44 +++++++----------------
> 5 files changed, 117 insertions(+), 33 deletions(-)
> create mode 100644 kernel/printk/braille.c
> create mode 100644 kernel/printk/braille.h
>
> diff --git a/drivers/accessibility/braille/braille_console.c b/drivers/accessibility/braille/braille_console.c
> index d21167b..dc34a5b 100644
> --- a/drivers/accessibility/braille/braille_console.c
> +++ b/drivers/accessibility/braille/braille_console.c
> @@ -359,6 +359,9 @@ int braille_register_console(struct console *console, int index,
> char *console_options, char *braille_options)
> {
> int ret;
> +
> + if (!(console->flags & CON_BRL))
> + return 0;
> if (!console_options)
> /* Only support VisioBraille for now */
> console_options = "57600o8";
> @@ -374,15 +377,17 @@ int braille_register_console(struct console *console, int index,
> braille_co = console;
> register_keyboard_notifier(&keyboard_notifier_block);
> register_vt_notifier(&vt_notifier_block);
> - return 0;
> + return 1;
> }
>
> int braille_unregister_console(struct console *console)
> {
> if (braille_co != console)
> return -EINVAL;
> + if (!(console->flags & CON_BRL))
> + return 0;
> unregister_keyboard_notifier(&keyboard_notifier_block);
> unregister_vt_notifier(&vt_notifier_block);
> braille_co = NULL;
> - return 0;
> + return 1;
> }
> diff --git a/kernel/printk/Makefile b/kernel/printk/Makefile
> index 36d306d..85405bd 100644
> --- a/kernel/printk/Makefile
> +++ b/kernel/printk/Makefile
> @@ -1 +1,2 @@
> obj-y = printk.o
> +obj-$(CONFIG_A11Y_BRAILLE_CONSOLE) += braille.o
> diff --git a/kernel/printk/braille.c b/kernel/printk/braille.c
> new file mode 100644
> index 0000000..b51087f
> --- /dev/null
> +++ b/kernel/printk/braille.c
> @@ -0,0 +1,48 @@
> +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> +
> +#include <linux/kernel.h>
> +#include <linux/console.h>
> +#include <linux/string.h>
> +
> +#include "console_cmdline.h"
> +#include "braille.h"
> +
> +char *_braille_console_setup(char **str, char **brl_options)
> +{
> + if (!memcmp(*str, "brl,", 4)) {
> + *brl_options = "";
> + *str += 4;
> + } else if (!memcmp(str, "brl=", 4)) {
> + *brl_options = *str + 4;
> + *str = strchr(*brl_options, ',');
> + if (!*str)
> + pr_err("need port name after brl=\n");
> + else
> + *((*str)++) = 0;
> + }
> +
> + return *str;
> +}
> +
> +int
> +_braille_register_console(struct console *console, struct console_cmdline *c)
> +{
> + int rtn = 0;
> +
> + if (c->brl_options) {
> + console->flags |= CON_BRL;
> + rtn = braille_register_console(console, c->index, c->options,
> + c->brl_options);
> + }
> +
> + return rtn;
> +}
> +
> +int
> +_braille_unregister_console(struct console *console)
> +{
> + if (console->flags & CON_BRL)
> + return braille_unregister_console(console);
> +
> + return 0;
> +}
> diff --git a/kernel/printk/braille.h b/kernel/printk/braille.h
> new file mode 100644
> index 0000000..769d771
> --- /dev/null
> +++ b/kernel/printk/braille.h
> @@ -0,0 +1,48 @@
> +#ifndef _PRINTK_BRAILLE_H
> +#define _PRINTK_BRAILLE_H
> +
> +#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
> +
> +static inline void
> +braille_set_options(struct console_cmdline *c, char *brl_options)
> +{
> + c->brl_options = brl_options;
> +}
> +
> +char *
> +_braille_console_setup(char **str, char **brl_options);
> +
> +int
> +_braille_register_console(struct console *console, struct console_cmdline *c);
> +
> +int
> +_braille_unregister_console(struct console *console);
> +
> +#else
> +
> +static inline void
> +braille_set_options(struct console_cmdline *c, char *brl_options)
> +{
> +}
> +
> +static inline char *
> +_braille_console_setup(char **str, char **brl_options)
> +{
> + return NULL;
> +}
> +
> +static inline int
> +_braille_register_console(struct console *console, struct console_cmdline *c)
> +{
> + return 0;
> +}
> +
> +static inline int
> +_braille_unregister_console(struct console *console)
> +{
> + return 0;
> +}
> +
> +#endif
> +
> +#endif
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 4e9a982..7c4020c 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -50,6 +50,7 @@
> #include <trace/events/printk.h>
>
> #include "console_cmdline.h"
> +#include "braille.h"
>
> /* printk's without a loglevel use this.. */
> #define DEFAULT_MESSAGE_LOGLEVEL CONFIG_DEFAULT_MESSAGE_LOGLEVEL
> @@ -1767,9 +1768,8 @@ static int __add_preferred_console(char *name, int idx, char *options,
> c = &console_cmdline[i];
> strlcpy(c->name, name, sizeof(c->name));
> c->options = options;
> -#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
> - c->brl_options = brl_options;
> -#endif
> + braille_set_options(c, brl_options);
> +
> c->index = idx;
> return 0;
> }
> @@ -1782,20 +1782,8 @@ static int __init console_setup(char *str)
> char *s, *options, *brl_options = NULL;
> int idx;
>
> -#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
> - if (!memcmp(str, "brl,", 4)) {
> - brl_options = "";
> - str += 4;
> - } else if (!memcmp(str, "brl=", 4)) {
> - brl_options = str + 4;
> - str = strchr(brl_options, ',');
> - if (!str) {
> - printk(KERN_ERR "need port name after brl=\n");
> - return 1;
> - }
> - *(str++) = 0;
> - }
> -#endif
> + if (_braille_console_setup(&str, &brl_options))
> + return 1;
>
> /*
> * Decode str into name, index, options.
> @@ -2289,16 +2277,10 @@ void register_console(struct console *newcon)
> continue;
> if (newcon->index < 0)
> newcon->index = console_cmdline[i].index;
> -#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
> - if (console_cmdline[i].brl_options) {
> - newcon->flags |= CON_BRL;
> - braille_register_console(newcon,
> - console_cmdline[i].index,
> - console_cmdline[i].options,
> - console_cmdline[i].brl_options);
> +
> + if (_braille_register_console(newcon, &console_cmdline[i]))
> return;
> - }
> -#endif
> +
> if (newcon->setup &&
> newcon->setup(newcon, console_cmdline[i].options) != 0)
> break;
> @@ -2386,13 +2368,13 @@ EXPORT_SYMBOL(register_console);
> int unregister_console(struct console *console)
> {
> struct console *a, *b;
> - int res = 1;
> + int res;
>
> -#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
> - if (console->flags & CON_BRL)
> - return braille_unregister_console(console);
> -#endif
> + res = _braille_unregister_console(console);
> + if (res)
> + return res;
>
> + res = 1;
> console_lock();
> if (console_drivers == console) {
> console_drivers=console->next;
> --
> 1.8.1.2.459.gbcd45b4.dirty
>

--
Samuel
After watching my newly-retired dad spend two weeks learning how to make a new
folder, it became obvious that "intuitive" mostly means "what the writer or
speaker of intuitive likes".
(Bruce Ediger, [email protected], in comp.os.linux.misc, on X the
intuitiveness of a Mac interface.)