Add simple message printing

Add a message printing function whose output includes the device and
major:minor and which handles the kernel level string prefix.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2016-02-12 19:28:03 -08:00
parent 25a1e8d1b7
commit eb4694e401
2 changed files with 36 additions and 0 deletions

20
kmod/src/msg.c Normal file
View File

@@ -0,0 +1,20 @@
#include <linux/kernel.h>
#include <linux/fs.h>
void scoutfs_msg(struct super_block *sb, const char *prefix, const char *str,
const char *fmt, ...)
{
struct va_format vaf;
va_list args;
va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
printk("%sscoutfs (%s %u:%u)%s: %pV\n", prefix,
sb->s_id, MAJOR(sb->s_bdev->bd_dev), MINOR(sb->s_bdev->bd_dev),
str, &vaf);
va_end(args);
}

16
kmod/src/msg.h Normal file
View File

@@ -0,0 +1,16 @@
#ifndef _SCOUTFS_MSG_H_
#define _SCOUTFS_MSG_H_
void scoutfs_msg(struct super_block *sb, const char *prefix, const char *str,
const char *fmt, ...);
#define scoutfs_err(sb, fmt, args...) \
scoutfs_msg(sb, KERN_ERR, " error", fmt, ##args)
#define scoutfs_warn(sb, fmt, args...) \
scoutfs_msg(sb, KERN_WARNING, " warning", fmt, ##args)
#define scoutfs_info(sb, fmt, args...) \
scoutfs_msg(sb, KERN_INFO, "", fmt, ##args)
#endif