[Devel,RH7,1/3] ve/printk: add ve_log_printk() for log in !current->task_ve

Submitted by Dmitry Safonov on Dec. 21, 2016, 8:48 a.m.

Details

Message ID 20161221084835.32072-2-dsafonov@virtuozzo.com
State New
Series "iptables LOG in CT"
Headers show

Commit Message

Dmitry Safonov Dec. 21, 2016, 8:48 a.m.
In some places we want to log into non-current VE.
So here is ve_log_printk(), which prints message from any printk-valid
context to other VE's buffer.
This changes current behavior a little as erstwhile we've logged only
into current VE's buffer, but looking at __vprintk_emit()'s locks it
should be safe (but still little dangerous as it introduces new, untested
previously call-path).

Cc: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
---
 include/linux/printk.h |  7 +++++++
 kernel/printk.c        | 16 ++++++++++++++++
 2 files changed, 23 insertions(+)

Patch hide | download patch | download mbox

diff --git a/include/linux/printk.h b/include/linux/printk.h
index b97003c49634..4b6530ac7fff 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -135,6 +135,8 @@  int ve_printk(int dst, const char *fmt, ...);
 
 int ve_log_init(struct ve_struct *ve);
 void ve_log_destroy(struct ve_struct *ve);
+asmlinkage __printf(2, 3) __cold
+int ve_log_printk(struct ve_struct *ve, const char *s, ...);
 
 /*
  * Special printk facility for scheduler use only, _DO_NOT_USE_ !
@@ -194,6 +196,11 @@  static inline
 void ve_log_destroy(struct ve_struct *ve)
 {
 }
+static inline __printf(2, 3) __cold
+int ve_log_printk(struct ve_struct *ve, const char *s, ...)
+{
+	return 0;
+}
 static inline __printf(1, 2) __cold
 int printk_sched(const char *s, ...)
 {
diff --git a/kernel/printk.c b/kernel/printk.c
index 01cc325cda13..4f56c2e833e7 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -1884,6 +1884,22 @@  asmlinkage int ve_printk(int dst, const char *fmt, ...)
 }
 EXPORT_SYMBOL(ve_printk);
 
+asmlinkage int ve_log_printk(struct ve_struct *ve, const char *fmt, ...)
+{
+	struct log_state *log = &init_log_state;
+	va_list args;
+	int r;
+
+	if (likely(ve && ve->log_state))
+		log = ve->log_state;
+
+	va_start(args, fmt);
+	r = __vprintk_emit(log, 0, -1, NULL, 0, fmt, args);
+	va_end(args);
+
+	return r;
+}
+EXPORT_SYMBOL(ve_log_printk);
 /**
  * printk - print a kernel message
  * @fmt: format string