* [PATCH RFC 4/5] printk: add ns_printk for specific syslog_ns
@ 2012-11-19 8:17 Rui Xiang
0 siblings, 0 replies; 2+ messages in thread
From: Rui Xiang @ 2012-11-19 8:17 UTC (permalink / raw)
To: serge.hallyn, containers; +Cc: Eric W. Biederman, netdev
From: Libo Chen <clbchenlibo.chen@huawei.com>
In some context such as iptable, we can not get correct syslog_ns by
current_syslog_ns, because we get init_syslog_ns instead of syslog_ns
belonged to container.
We add a new interface ns_printk,and give it an parameter syslog_ns.
Signed-off-by: Libo Chen <clbchenlibo.chen@huawei.com>
Signed-off-by: Xiang Rui <rui.xiang@huawei.com>
---
include/linux/printk.h | 1 +
kernel/printk.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/include/linux/printk.h b/include/linux/printk.h
index e0c60d9..444d229 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -119,6 +119,7 @@ asmlinkage int printk_emit(int facility, int level,
asmlinkage __printf(1, 2) __cold
int printk(const char *fmt, ...);
+int ns_printk(struct syslog_namespace *syslog_ns, const char *fmt, ...);
/*
* Special printk facility for scheduler use only, _DO_NOT_USE_ !
diff --git a/kernel/printk.c b/kernel/printk.c
index 2ef9c46..85a9965 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -1681,6 +1681,43 @@ asmlinkage int printk(const char *fmt, ...)
}
EXPORT_SYMBOL(printk);
+/**
+ * ns_printk - print a kernel message in syslog_ns
+ * @syslog_ns: syslog namespace
+ * @fmt: format string
+ *
+ * This is ns_printk().
+ * It can be called from container context. We add a param
+ * syslog_ns to record current syslog namespace,because
+ * we can't get the correct syslog_ns from current_syslog_ns
+ * in some context,e.g. iptable.
+ *
+ * See the vsnprintf() documentation for format string extensions over C99.
+ **/
+asmlinkage int ns_printk(struct syslog_namespace *syslog_ns,
+ const char *fmt, ...)
+{
+ va_list args;
+ int r;
+
+ if (!syslog_ns)
+ syslog_ns = current_syslog_ns();
+
+#ifdef CONFIG_KGDB_KDB
+ if (unlikely(kdb_trap_printk)) {
+ va_start(args, fmt);
+ r = vkdb_printf(fmt, args);
+ va_end(args);
+ return r;
+ }
+#endif
+ va_start(args, fmt);
+ r = vprintk_emit(0, -1, NULL, 0, fmt, args, syslog_ns);
+ va_end(args);
+
+ return r;
+}
+EXPORT_SYMBOL(ns_printk);
#else /* CONFIG_PRINTK */
#define LOG_LINE_MAX 0
--
1.7.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH RFC 4/5] printk: add ns_printk for specific syslog_ns
@ 2012-11-19 8:17 Rui Xiang
0 siblings, 0 replies; 2+ messages in thread
From: Rui Xiang @ 2012-11-19 8:17 UTC (permalink / raw)
To: serge.hallyn-Z7WLFzj8eWMS+FvcfC7Uqw,
containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
Cc: netdev-u79uwXL29TY76Z2rM5mHXA, Eric W. Biederman
From: Libo Chen <clbchenlibo.chen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
In some context such as iptable, we can not get correct syslog_ns by
current_syslog_ns, because we get init_syslog_ns instead of syslog_ns
belonged to container.
We add a new interface ns_printk,and give it an parameter syslog_ns.
Signed-off-by: Libo Chen <clbchenlibo.chen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
Signed-off-by: Xiang Rui <rui.xiang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
---
include/linux/printk.h | 1 +
kernel/printk.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/include/linux/printk.h b/include/linux/printk.h
index e0c60d9..444d229 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -119,6 +119,7 @@ asmlinkage int printk_emit(int facility, int level,
asmlinkage __printf(1, 2) __cold
int printk(const char *fmt, ...);
+int ns_printk(struct syslog_namespace *syslog_ns, const char *fmt, ...);
/*
* Special printk facility for scheduler use only, _DO_NOT_USE_ !
diff --git a/kernel/printk.c b/kernel/printk.c
index 2ef9c46..85a9965 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -1681,6 +1681,43 @@ asmlinkage int printk(const char *fmt, ...)
}
EXPORT_SYMBOL(printk);
+/**
+ * ns_printk - print a kernel message in syslog_ns
+ * @syslog_ns: syslog namespace
+ * @fmt: format string
+ *
+ * This is ns_printk().
+ * It can be called from container context. We add a param
+ * syslog_ns to record current syslog namespace,because
+ * we can't get the correct syslog_ns from current_syslog_ns
+ * in some context,e.g. iptable.
+ *
+ * See the vsnprintf() documentation for format string extensions over C99.
+ **/
+asmlinkage int ns_printk(struct syslog_namespace *syslog_ns,
+ const char *fmt, ...)
+{
+ va_list args;
+ int r;
+
+ if (!syslog_ns)
+ syslog_ns = current_syslog_ns();
+
+#ifdef CONFIG_KGDB_KDB
+ if (unlikely(kdb_trap_printk)) {
+ va_start(args, fmt);
+ r = vkdb_printf(fmt, args);
+ va_end(args);
+ return r;
+ }
+#endif
+ va_start(args, fmt);
+ r = vprintk_emit(0, -1, NULL, 0, fmt, args, syslog_ns);
+ va_end(args);
+
+ return r;
+}
+EXPORT_SYMBOL(ns_printk);
#else /* CONFIG_PRINTK */
#define LOG_LINE_MAX 0
--
1.7.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-11-19 8:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-19 8:17 [PATCH RFC 4/5] printk: add ns_printk for specific syslog_ns Rui Xiang
-- strict thread matches above, loose matches on Subject: below --
2012-11-19 8:17 Rui Xiang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.