This is the code that implements the log level settings.
It adds the thresholds and code to printk to implement the thresholds.
It also adds xen_startup (still needs to be used) and oops_in_progress.
-- Steve
Signed-off-by: Steven Rostedt <srostedt@xxxxxxxxxx>
diff -r 066de2eb02f8 xen/drivers/char/console.c
--- a/xen/drivers/char/console.c Fri Oct 27 11:11:36 2006 -0400
+++ b/xen/drivers/char/console.c Fri Oct 27 11:11:38 2006 -0400
@@ -57,6 +57,13 @@ static int sercon_handle = -1;
static int sercon_handle = -1;
static DEFINE_SPINLOCK(console_lock);
+
+int xenlog_upper_thresh = XENLOG_UPPER_THRESHOLD;
+int xenlog_lower_thresh = XENLOG_LOWER_THRESHOLD;
+int xenlog_guest_upper_thresh = XENLOG_GUEST_UPPER_THRESHOLD;
+int xenlog_guest_lower_thresh = XENLOG_GUEST_LOWER_THRESHOLD;
+
+int xen_startup = 1;
/*
* ********************************************************
@@ -307,6 +314,10 @@ void printk(const char *fmt, ...)
va_list args;
char *p, *q;
unsigned long flags;
+ int level = XENLOG_DEFAULT;
+ int upper_thresh = xenlog_upper_thresh;
+ int lower_thresh = xenlog_lower_thresh;
+ int print_regardless = xen_startup;
spin_lock_irqsave(&console_lock, flags);
@@ -315,6 +326,42 @@ void printk(const char *fmt, ...)
va_end(args);
p = buf;
+
+ /*
+ * Is this print caused by a guest?
+ */
+ if (strncmp("<G>", p, 3) == 0)
+ {
+ upper_thresh = xenlog_guest_upper_thresh;
+ lower_thresh = xenlog_guest_lower_thresh;
+ level = XENLOG_GUEST_DEFAULT;
+ p += 3;
+ }
+
+ if ( (p[0] == '<') && (p[1] >= '0')
+ && (p[1] <= ('0' + XENLOG_MAX))
+ && (p[2] == '>') )
+ {
+ level = p[1] - '0';
+ p += 3;
+ }
+
+ if ( print_regardless )
+ {
+ goto printme;
+ }
+
+ if ( level > upper_thresh )
+ {
+ goto out;
+ }
+
+ if ( (level >= lower_thresh) && (!printk_ratelimit()) )
+ {
+ goto out;
+ }
+
+ printme:
while ( (q = strchr(p, '\n')) != NULL )
{
*q = '\0';
@@ -334,6 +381,7 @@ void printk(const char *fmt, ...)
start_of_line = 0;
}
+ out:
spin_unlock_irqrestore(&console_lock, flags);
}
@@ -419,6 +467,11 @@ void console_endboot(void)
/* Serial input is directed to DOM0 by default. */
switch_serial_input();
+
+ /*
+ * Now we implement the thresholds.
+ */
+ xen_startup = 0;
}
void console_force_unlock(void)
diff -r 066de2eb02f8 xen/include/xen/config.h
--- a/xen/include/xen/config.h Fri Oct 27 11:11:36 2006 -0400
+++ b/xen/include/xen/config.h Fri Oct 27 11:11:38 2006 -0400
@@ -12,26 +12,119 @@
#define EXPORT_SYMBOL(var)
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-/* Linux syslog levels. */
-#define KERN_NOTICE ""
-#define KERN_WARNING ""
-#define KERN_DEBUG ""
-#define KERN_INFO ""
-#define KERN_ERR ""
-#define KERN_CRIT ""
-#define KERN_EMERG ""
-#define KERN_ALERT ""
+/*
+ * The following log levels are as follows:
+ *
+ * XENLOG_ERR: Fatal errors, either Xen, Guest or Dom0
+ * is about to crash.
+ *
+ * XENLOG_WARNING: Something bad happened, but we can recover.
+ *
+ * XENLOG_INFO: Interesting stuff, but not too noisy.
+ *
+ * XENLOG_DEBUG: Use where ever you like. Lots of noise.
+ *
+ *
+ * Since we don't trust the guest operating system, we don't want
+ * it to allow for DoS by causing the HV to print out a lot of
+ * info, so where ever the guest has control of what is printed
+ * we use the XENLOG_GUEST to distinguish that the output is
+ * controled by the Guest.
+ *
+ * To make it easier on the typing, the above log levels all
+ * have a corresponding _G_ equivalent that appends the
+ * XENLOG_GUEST. (see the defines below).
+ *
+ */
+#define XENLOG_ERR "<0>"
+#define XENLOG_WARNING "<1>"
+#define XENLOG_INFO "<2>"
+#define XENLOG_DEBUG "<3>"
+
+#define XENLOG_GUEST "<G>"
+
+#define XENLOG_G_ERR XENLOG_GUEST XENLOG_ERR
+#define XENLOG_G_WARNING XENLOG_GUEST XENLOG_WARNING
+#define XENLOG_G_INFO XENLOG_GUEST XENLOG_INFO
+#define XENLOG_G_DEBUG XENLOG_GUEST XENLOG_DEBUG
+
+#define XENLOG_MAX 3
+
+/*
+ * To control the amount of printing, thresholds are added.
+ * These thresholds correspond to the above log levels.
+ * There's an upper and lower threshold for non-guests
+ * and Guest. This works as follows:
+ *
+ * If printk log level > upper threshold
+ * don't print anything
+ *
+ * If printk log level >= lower threshold
+ * rate limit the print (keep the amount down)
+ *
+ * Otherwise, just print.
+ *
+ * Note, in the above algorithm, to never rate limit
+ * simply make the lower threshold greater than the upper.
+ * This way the output will never be rate limited.
+ *
+ * For example:
+ * lower = 2; upper = 1;
+ * This will always print ERR and WARNING messages
+ * but will not print anything else. Nothing is
+ * rate limited.
+ */
+/*
+ * Defaults:
+ * For the HV, always print ERR and WARNING
+ * but nothing for INFO and DEBUG.
+ *
+ * For Guests, always rate limit ERR and WARNING
+ * but never print for INFO and DEBUG.
+ */
+#ifndef XENLOG_UPPER_THRESHOLD
+#define XENLOG_UPPER_THRESHOLD 1
+#endif
+#ifndef XENLOG_LOWER_THRESHOLD
+#define XENLOG_LOWER_THRESHOLD 2
+#endif
+#ifndef XENLOG_GUEST_UPPER_THRESHOLD
+#define XENLOG_GUEST_UPPER_THRESHOLD 1
+#endif
+#ifndef XENLOG_GUEST_LOWER_THRESHOLD
+#define XENLOG_GUEST_LOWER_THRESHOLD 0
+#endif
+
+/*
+ * The XENLOG_DEFAULT is the default given to printks that
+ * do not have any print level associated to it.
+ */
+#ifndef XENLOG_DEFAULT
+#define XENLOG_DEFAULT 1 /* Warning */
+#endif
+#ifndef XENLOG_GUEST_DEFAULT
+#define XENLOG_GUEST_DEFAULT 1 /* Warning */
+#endif
+
+/*
+ * Some code is copied directly from Linux.
+ * Match some of the Linux log levels to Xen.
+ * (Should these be Guest logs?? - SDR)
+ */
+#define KERN_ERR XENLOG_ERR
+#define KERN_CRIT XENLOG_ERR
+#define KERN_EMERG XENLOG_ERR
+#define KERN_WARNING XENLOG_WARNING
+#define KERN_NOTICE XENLOG_INFO
+#define KERN_INFO XENLOG_INFO
+#define KERN_DEBUG XENLOG_DEBUG
/* Linux 'checker' project. */
#define __iomem
#define __user
-#ifdef VERBOSE
#define DPRINTK(_f, _a...) printk("(file=%s, line=%d) " _f, \
__FILE__ , __LINE__ , ## _a )
-#else
-#define DPRINTK(_f, _a...) ((void)0)
-#endif
#ifndef __ASSEMBLY__
#include <xen/compiler.h>
diff -r 066de2eb02f8 xen/include/xen/lib.h
--- a/xen/include/xen/lib.h Fri Oct 27 11:11:36 2006 -0400
+++ b/xen/include/xen/lib.h Fri Oct 27 11:11:38 2006 -0400
@@ -58,6 +58,12 @@ extern long vm_assist(struct domain *, u
extern long vm_assist(struct domain *, unsigned int, unsigned int);
extern int __printk_ratelimit(int ratelimit_ms, int ratelimit_burst);
extern int printk_ratelimit(void);
+extern int xenlog_upper_thresh;
+extern int xenlog_lower_thresh;
+extern int xenlog_guest_upper_thresh;
+extern int xenlog_guest_lower_thresh;
+
+extern int xen_startup;
/* vsprintf.c */
extern int sprintf(char * buf, const char * fmt, ...)
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|