Skip to contentSkip to conversation

1 of 4 - New problem logging macros, Event Logging

PATCH-RFC Larry Kessler 3 participants 3 messages Sep 24, 2002

lore
Share & tools
lore
#0 lore raw

Please see [PATCH-RFC] README 1ST

Summary of this patch...

include/linux/evl_log.h
Data structures, constants, and fucnction protos, required for event logging. Also included by libevl and user-space utilities.

init/Config.help
Added help text for event logging

init/Config.in
CONFIG_EVLOG - default=disabled (problems
become printks)
CONFIG_EVLOG_BUFSIZE - Configurable static
event buffer size.

kernel/evlog.c
* posix_log_write() - creates event record from introduce(), problem() detail(), and array_detail()
* Static event buffer for kernel events (has nothing whatsoever to do with printk ring-buffer or printk behavior).
* generates console messages from events (portion of event data that will fit on a single line)
* facility code and event_type generation

kernel/printk.c
Added option to do_syslog() for evlogd
deamon to read events from kernel
event buffer.

include/linux/evl_log.h +208 -0
diff -Naur linux.org/include/linux/evl_log.h linux.evlog.patched/include/linux/evl_log.h
@@ -0,0 +1,208 @@
+/*
+ * Linux Event Logging for the Enterprise
+ * Copyright (c) International Business Machines Corp., 2002
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *  Please send e-mail to [email protected] if you have
+ *  questions or comments.
+ *
+ *  Project Website:  http://evlog.sourceforge.net/
+ *
+ */
+
+#ifndef _LINUX_EVL_LOG_H
+#define _LINUX_EVL_LOG_H
+
+#ifndef __KERNEL__
+#include <time.h>
+#ifdef _POSIX_THREADS
+#include <pthread.h>
+#endif
+#else
+#include <linux/time.h>
+#endif
+
+/* Values for log_flags member */
+#define POSIX_LOG_TRUNCATE  0x1
+#define EVL_KERNEL_EVENT	0x2
+#define EVL_INITIAL_BOOT_EVENT 	0x4
+#define EVL_KERNTIME_LOCAL	0x8
+#define EVL_INTERRUPT		0x10	/* Logged from interrupt context */
+#define EVL_PRINTK		0x20	/* Reserved */
+
+/* Formats for optional portion of record. */
+#define POSIX_LOG_NODATA    0
+#define POSIX_LOG_BINARY    1
+#define POSIX_LOG_STRING    2
+#define POSIX_LOG_PRINTF    3	
+
+/* Maximum length of variable portion of record */
+#define POSIX_LOG_ENTRY_MAXLEN      (8 * 1024)
+
+/* Maximum length for a string returned by posix_log_memtostr */
+/* Thus also the max length of a facility name */
+#define POSIX_LOG_MEMSTR_MAXLEN	128
+
+typedef unsigned int posix_log_facility_t;
+typedef int posix_log_severity_t;
+typedef int posix_log_recid_t;
+typedef int posix_log_procid_t;
+
+#define EVL_INVALID_FACILITY ((posix_log_facility_t)-1)
+
+struct posix_log_entry {
+	unsigned int            log_magic;
+        posix_log_recid_t   	log_recid;
+        size_t          	log_size;
+        int             	log_format;
+        int             	log_event_type;
+        posix_log_facility_t 	log_facility;
+        posix_log_severity_t    log_severity;
+        uid_t           	log_uid;
+        gid_t           	log_gid;
+        pid_t           	log_pid;
+        pid_t           	log_pgrp;
+        struct timespec 	log_time;
+        unsigned int    	log_flags;
+#ifdef __KERNEL__
+        unsigned long int	log_thread;
+#else
+#ifdef _POSIX_THREADS
+	pthread_t		log_thread;
+#else
+	unsigned long int	log_thread;
+#endif
+#endif
+        posix_log_procid_t	log_processor;
+}; 
+
+typedef struct posix_log_entry rec_hdr_t;
+typedef struct evl_buf_rec {
+        struct posix_log_entry  rechdr;
+        char                    varbuf[1];
+} evl_buf_rec_t;
+
+
+#define LOGFILE_MAGIC   0xbeefface
+#define LOGREC_MAGIC    0xfeefface
+#define REC_HDR_SIZE    sizeof(struct posix_log_entry)
+
+/*
+ * Reserved Event Types
+ */
+#define EVL_SYSLOG_MESSAGE      0x1	/* Reserved */
+#define EVL_PRINTK_MESSAGE      0x2	/* Reserved */
+#define EVL_BUFFER_OVERRUN      0x6
+#define EVL_DUPS_DISCARDED      0x7
+
+/*
+ * A record of type (LOG_LOGMGMT, EVLOG_REGISTER_FAC) is generated by
+ * evl_register_facility().
+ */
+#define EVLOG_REGISTER_FAC 40
+
+#define LOG_LOGMGMT              (12<<3)	/* EVL Facility */
+
+/*
+ * The optional portion of a record of type (LOG_LOGMGMT, EVLOG_REGISTER_FAC)
+ * is an evl_facreg_rq object followed by a string (the facility name).
+ * evlogd intercepts this record and does the requested registration, if needed.
+ *
+ * fr_kernel_fac_code is the facility code generated by the kernel's call
+ * to evl_register_facility().  This field is filled in by the kernel.
+ *
+ * fr_registry_fac_code is the facility code that appears in the registry.
+ * (This should match fr_kernel_fac_code.)  This field is filled in by
+ * evlogd after it intercepts and executes this request.
+ *
+ * fr_rq_status is the request's status:
+ *	frst_kernel_failed: Set by the kernel to indicate that it could not
+ *		generate a valid facility code for the given name.
+ *	frst_kernel_ok: Set by the kernel to indicate success so far.
+ * evlogd replaces the frst_kernel_ok value with one of the following:
+ *	frst_already_registered: No need to register the facility.  It's
+ *		already registered, and the code matches.
+ *	frst_registered_ok: We registered it, with the expected results.
+ *	frst_registration_failed: We tried to register it, but couldn't.
+ *	frst_faccode_mismatch: A facility by that name is in the registry,
+ *		but its code doesn't match fr_kernel_fac_code.
+ */
+typedef enum {
+	frst_kernel_failed = -1,
+	frst_kernel_ok = 0,
+	frst_already_registered,
+	frst_registered_ok,
+	frst_registration_failed,
+	frst_faccode_mismatch
+} evl_facreg_rq_status_t;
+
+struct evl_facreg_rq {
+	posix_log_facility_t	fr_kernel_fac_code;
+	posix_log_facility_t	fr_registry_fac_code;
+	evl_facreg_rq_status_t	fr_rq_status;
+};
+
+#ifdef __KERNEL__
+/*
+ * Reserved Facilities
+ */
+#define LOG_KERN        (0<<3)  /* Kernel Facility */
+#define LOG_AUTHPRIV    (10<<3) /* security/authorization messages (private) */
+/*
+ * priorities (these are ordered)
+ */
+#define LOG_EMERG   0   /* system is unusable */
+#define LOG_ALERT   1   /* action must be taken immediately */
+#define LOG_CRIT    2   /* critical conditions */
+#define LOG_ERR     3   /* error conditions */
+#define LOG_WARNING 4   /* warning conditions */
+#define LOG_NOTICE  5   /* normal but significant condition */
+#define LOG_INFO    6   /* informational */
+#define LOG_DEBUG   7   /* debug-level messages */
+
+#ifdef CONFIG_EVLOG
+extern int posix_log_write(posix_log_facility_t facility, int event_type,
+         	posix_log_severity_t severity, const void *buf,
+        	size_t len, int format, unsigned int flags);
+
+extern int evl_gen_event_type(const char *s1, const char *s2, const char *s3);
+
+extern int evl_gen_facility_code(const char *fname,
+		posix_log_facility_t *fcode);
+
+extern int evl_register_facility(const char *fname,
+		posix_log_facility_t *fcode);
+#else	/* ! CONFIG_EVLOG */
+inline int posix_log_write(posix_log_facility_t facility, int event_type,
+		posix_log_severity_t severity, const void *buf,
+		size_t len, int format, unsigned int flags)
+		{ return -ENOSYS; }
+
+inline int evl_gen_event_type(const char *s1, const char *s2, const char *s3)
+		{ return -ENOSYS; }
+
+inline int evl_gen_facility_code(const char *fname,
+		posix_log_facility_t *fcode)
+		{ return -ENOSYS; }
+
+inline int evl_register_facility(const char *fname,
+		posix_log_facility_t *fcode)
+		{ return -ENOSYS; }
+#endif	/* CONFIG_EVLOG */
+#endif	/* __KERNEL__ */
+
+#endif
init/Config.help +13 -0
diff -Naur linux.org/init/Config.help linux.evlog.patched/init/Config.help
@@ -115,3 +115,16 @@
   replacement for kerneld.) Say Y here and read about configuring it
   in <file:Documentation/kmod.txt>.
 
+CONFIG_EVLOG
+  This enables support for enterprise level event logging based upon
+  the draft POSIX 1003.25 standard. Enabling this feature does not affect
+  the operation of the sysklogd package in any way. In order to fully
+  utilize this feature user must also install the companion evlog package
+  in user-space.
+
+  For more information see http://evlog.sourceforge.net
+
+  If you don't know what to do here, say N.
+
+CONFIG_EVLOG_BUFSIZE
+  Event log buffer size in kBytes. Default size is 128 kBytes.
init/Config.in +4 -0
diff -Naur linux.org/init/Config.in linux.evlog.patched/init/Config.in
@@ -9,6 +9,10 @@
 bool 'System V IPC' CONFIG_SYSVIPC
 bool 'BSD Process Accounting' CONFIG_BSD_PROCESS_ACCT
 bool 'Sysctl support' CONFIG_SYSCTL
+bool 'Enterprise event logging support' CONFIG_EVLOG
+if [ "$CONFIG_EVLOG" != "n" ]; then
+   int 'Eventlog buffer size (in K bytes)' CONFIG_EVLOG_BUFSIZE 128
+fi
 endmenu
 
 mainmenu_option next_comment
kernel/Makefile +2 -1
diff -Naur linux.org/kernel/Makefile linux.evlog.patched/kernel/Makefile
@@ -3,7 +3,7 @@
 #
 
 export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o \
-		printk.o platform.o suspend.o dma.o
+		printk.o platform.o suspend.o dma.o evlog.o
 
 obj-y     = sched.o fork.o exec_domain.o panic.o printk.o \
 	    module.o exit.o itimer.o time.o softirq.o resource.o \
@@ -17,6 +17,7 @@
 obj-$(CONFIG_PM) += pm.o
 obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
 obj-$(CONFIG_SOFTWARE_SUSPEND) += suspend.o
+obj-$(CONFIG_EVLOG) += evlog.o
 
 ifneq ($(CONFIG_IA64),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/evlog.c +1206 -0

1,206 lines not on this page · raw message

kernel/printk.c +16 -1
diff -Naur linux.org/kernel/printk.c linux.evlog.patched/kernel/printk.c
@@ -68,7 +68,7 @@
  * provides serialisation for access to the entire console
  * driver system.
  */
-static DECLARE_MUTEX(console_sem);
+DECLARE_MUTEX(console_sem);
 struct console *console_drivers;
 
 /*
@@ -92,6 +92,9 @@
 
 struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
 static int preferred_console = -1;
+#ifdef CONFIG_EVLOG
+extern int evl_kbufread(char *, size_t);
+#endif
 
 /* Flag: console code may call schedule() */
 static int console_may_schedule;
@@ -166,6 +169,7 @@
  *	9 -- Return number of unread characters in the log buffer
  *     10 -- Printk from userspace.  Includes loglevel.  Returns number of
  *           chars printed.
+ *     20 -- Read from event logging buffer 
  */
 int do_syslog(int type, char * buf, int len)
 {
@@ -297,6 +301,17 @@
 			break;
 		lbuf[len] = '\0';
 		error = printk("%s", lbuf);
+		break;
+	case 20:
+#ifdef CONFIG_EVLOG
+		error = verify_area(VERIFY_WRITE, buf, len);
+		if (error) {
+			goto out;
+		}
+		error = evl_kbufread(buf, len);
+#else
+		error = -EIO;
+#endif
 		break;
 	default:
 		error = -EINVAL;
#1 lore raw

Please edit your CC list for crap. Linus's email is wrong. The CC list is so huge that my reply to you is being held by the evlog list manager.
And my reply is being "held for moderation" in the cgl-discuss list.

And you came very close to setting off spamassassin's spam trigger ;-)

Good email etiquette goes a long way, around here...

Jeff

#2 lore raw

On Mon, 23 Sep 2002, Jeff Garzik wrote:

| Please edit your CC list for crap.  Linus's email is wrong.  The CC list
| is so huge that my reply to you is being held by the evlog list manager.
|   And my reply is being "held for moderation" in the cgl-discuss list.
|
| And you came very close to setting off spamassassin's spam trigger ;-)
|
| Good email etiquette goes a long way, around here...

cgl_discussion is now unmoderated (supposed to be). Please let us know if you have problems with it.

Signature · 1 line
~Randy