kmsg: add additional buffers support to memory class 79/60879/3
authorMarcin Niesluchowski <m.niesluchow@samsung.com>
Mon, 20 Jul 2015 12:52:06 +0000 (14:52 +0200)
committerJoonyoung Shim <jy0922.shim@samsung.com>
Fri, 11 Mar 2016 00:49:48 +0000 (16:49 -0800)
Memory class does not support additional kmsg buffers.

Add additional kmsg buffers support to:
* devnode() callback of "mem" class
* file operations of major "mem" character device

Signed-off-by: Marcin Niesluchowski <m.niesluchow@samsung.com>
Change-Id: Ideadca14d2f2e8abd653ab8677e04132b7d9757e

drivers/char/mem.c
include/linux/printk.h
kernel/printk_kmsg.c

index 38d3069..1dcc6b3 100644 (file)
@@ -880,7 +880,7 @@ static const struct memdev {
         [7] = { "full", 0666, &full_fops, NULL },
         [8] = { "random", 0666, &random_fops, NULL },
         [9] = { "urandom", 0666, &urandom_fops, NULL },
-#ifdef CONFIG_PRINTK
+#if defined(CONFIG_PRINTK) && !defined(CONFIG_MULTIPLE_KMSG)
        [11] = { "kmsg", 0644, &kmsg_fops, NULL },
 #endif
 #ifdef CONFIG_CRASH_DUMP
@@ -895,7 +895,11 @@ static int memory_open(struct inode *inode, struct file *filp)
 
        minor = iminor(inode);
        if (minor >= ARRAY_SIZE(devlist))
+#ifdef CONFIG_MULTIPLE_KMSG
+               return kmsg_memory_open(inode, filp);
+#else
                return -ENXIO;
+#endif
 
        dev = &devlist[minor];
        if (!dev->fops)
@@ -920,19 +924,42 @@ static const struct file_operations memory_fops = {
        .llseek = noop_llseek,
 };
 
+#ifdef CONFIG_MULTIPLE_KMSG
+static char *mem_devnode(struct device *dev, umode_t *mode)
+{
+       int minor = MINOR(dev->devt);
+
+       if (!mode)
+               goto out;
+
+       if (minor >= ARRAY_SIZE(devlist)) {
+               kmsg_mode(minor, mode);
+               goto out;
+       }
+
+       if (devlist[minor].mode)
+               *mode = devlist[minor].mode;
+out:
+       return NULL;
+}
+#else
 static char *mem_devnode(struct device *dev, umode_t *mode)
 {
        if (mode && devlist[MINOR(dev->devt)].mode)
                *mode = devlist[MINOR(dev->devt)].mode;
        return NULL;
 }
+#endif
 
-static struct class *mem_class;
+struct class *mem_class;
 
 static int __init chr_dev_init(void)
 {
        int minor;
        int err;
+#ifdef CONFIG_MULTIPLE_KMSG
+       struct device *kmsg;
+#endif
 
        err = bdi_init(&zero_bdi);
        if (err)
@@ -960,6 +987,12 @@ static int __init chr_dev_init(void)
                              NULL, devlist[minor].name);
        }
 
+#ifdef CONFIG_MULTIPLE_KMSG
+       kmsg = init_kmsg(KMSG_MINOR, 0644);
+       if (IS_ERR(kmsg))
+               return PTR_ERR(kmsg);
+#endif
+
        return tty_init();
 }
 
index db9831e..1d2aa37 100644 (file)
@@ -357,6 +357,40 @@ extern void dump_stack(void) __cold;
 
 extern const struct file_operations kmsg_fops;
 
+#ifdef CONFIG_MULTIPLE_KMSG
+struct file;
+struct inode;
+
+#ifdef CONFIG_PRINTK
+
+extern struct class *mem_class;
+
+#define KMSG_MINOR     11
+
+extern struct device *init_kmsg(int minor, umode_t mode);
+extern int kmsg_memory_open(struct inode *inode, struct file *filp);
+extern int kmsg_mode(int minor, umode_t *mode);
+
+#else
+
+static inline struct device *init_kmsg(int minor, umode_t mode)
+{
+       return NULL;
+}
+
+static inline int kmsg_memory_open(struct inode *inode, struct file *filp)
+{
+       return -ENXIO;
+}
+
+static inline int kmsg_mode(int minor, umode_t *mode)
+{
+       return -ENXIO;
+}
+
+#endif
+#endif
+
 enum {
        DUMP_PREFIX_NONE,
        DUMP_PREFIX_ADDRESS,
index de15ce1..77efb8b 100644 (file)
@@ -45,6 +45,8 @@
 #include <linux/poll.h>
 #include <linux/irq_work.h>
 #include <linux/utsname.h>
+#include <linux/device.h>
+#include <linux/kdev_t.h>
 
 #include <asm/uaccess.h>
 
@@ -245,6 +247,7 @@ struct log_buffer {
        u64 next_seq;
 #ifdef CONFIG_PRINTK
        u32 next_idx;           /* index of the next record to store */
+       int mode;               /* mode of device */
        int minor;              /* minor representing buffer device */
 #endif
 };
@@ -291,6 +294,7 @@ static struct log_buffer log_buf = {
        .first_idx      = 0,
        .next_seq       = 0,
        .next_idx       = 0,
+       .mode           = 0,
        .minor          = 0,
 };
 
@@ -1259,6 +1263,45 @@ const struct file_operations kmsg_fops = {
        .release = devkmsg_release,
 };
 
+/* Should be used for device registration */
+struct device *init_kmsg(int minor, umode_t mode)
+{
+       log_buf.minor = minor;
+       log_buf.mode = mode;
+       return device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
+                       NULL, "kmsg");
+}
+
+int kmsg_memory_open(struct inode *inode, struct file *filp)
+{
+       filp->f_op = &kmsg_fops;
+
+       return kmsg_fops.open(inode, filp);
+}
+
+int kmsg_mode(int minor, umode_t *mode)
+{
+       int ret = -ENXIO;
+       struct log_buffer *log_b;
+
+       if (minor == log_buf.minor) {
+               *mode = log_buf.mode;
+               return 0;
+       }
+
+       rcu_read_lock();
+       list_for_each_entry_rcu(log_b, &log_buf.list, list) {
+               if (log_b->minor == minor) {
+                       *mode = log_b->mode;
+                       ret = 0;
+                       break;
+               }
+       }
+       rcu_read_unlock();
+
+       return ret;
+}
+
 #ifdef CONFIG_KEXEC
 /*
  * This appends the listed symbols to /proc/vmcoreinfo