From: Andrew Morton Display the most-recently-opened sysfs file's name when oopsing. From: Adrian Bunk Build fix From: Greg Kroah-Hartman Modified to make the api call cleaner, and available to all arches if need be. Also added it to x86-64's crash dump message. Signed-off-by: Adrian Bunk Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- arch/i386/kernel/traps.c | 1 + arch/x86_64/kernel/traps.c | 1 + fs/sysfs/file.c | 14 ++++++++++++++ include/linux/sysfs.h | 6 ++++++ 4 files changed, 22 insertions(+) --- gregkh-2.6.orig/arch/i386/kernel/traps.c +++ gregkh-2.6/arch/i386/kernel/traps.c @@ -425,6 +425,7 @@ void die(const char * str, struct pt_reg #endif if (nl) printk("\n"); + sysfs_printk_last_file(); if (notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV) != NOTIFY_STOP) { --- gregkh-2.6.orig/arch/x86_64/kernel/traps.c +++ gregkh-2.6/arch/x86_64/kernel/traps.c @@ -533,6 +533,7 @@ void __kprobes __die(const char * str, s printk("DEBUG_PAGEALLOC"); #endif printk("\n"); + sysfs_printk_last_file(); notify_die(DIE_OOPS, str, regs, err, current->thread.trap_no, SIGSEGV); show_registers(regs); /* Executive summary in case the oops scrolled away */ --- gregkh-2.6.orig/fs/sysfs/file.c +++ gregkh-2.6/fs/sysfs/file.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -16,6 +17,13 @@ #define to_subsys(k) container_of(k,struct subsystem,kset.kobj) #define to_sattr(a) container_of(a,struct subsys_attribute,attr) +/* used in crash dumps to help with debugging */ +static char last_sysfs_file[PATH_MAX]; +void sysfs_printk_last_file(void) +{ + printk(KERN_EMERG "last sysfs file: %s\n", last_sysfs_file); +} + /* * Subsystem file operations. * These operations allow subsystems to have files that can be @@ -283,6 +291,12 @@ static int sysfs_open_file(struct inode struct sysfs_buffer * buffer; struct sysfs_ops * ops = NULL; int error = 0; + char *p; + + p = d_path(file->f_dentry, sysfs_mount, last_sysfs_file, + sizeof(last_sysfs_file)); + if (p) + memmove(last_sysfs_file, p, strlen(p) + 1); if (!kobj || !attr) goto Einval; --- gregkh-2.6.orig/include/linux/sysfs.h +++ gregkh-2.6/include/linux/sysfs.h @@ -121,6 +121,7 @@ void sysfs_remove_file_from_group(struct const struct attribute *attr, const char *group); void sysfs_notify(struct kobject * k, char *dir, char *attr); +void sysfs_printk_last_file(void); extern int sysfs_make_shadowed_dir(struct kobject *kobj, @@ -230,6 +231,11 @@ static inline int __must_check sysfs_ini return 0; } +static inline void sysfs_printk_last_file(void) +{ + ; +} + #endif /* CONFIG_SYSFS */ #endif /* _SYSFS_H_ */