1 Subject: display last accessed sysfs file on kernel panic message
2 From: Andrew Morton <akpm@osdl.org>
5 Display the most-recently-opened sysfs file's name when oopsing.
7 From: Adrian Bunk <bunk@stusta.de>
11 From: Greg Kroah-Hartman <gregkh@suse.de>
13 Modified to make the api call cleaner, and available to all arches if
14 need be. Also added it to x86-64's crash dump message.
17 Signed-off-by: Adrian Bunk <bunk@stusta.de>
18 Signed-off-by: Andrew Morton <akpm@osdl.org>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
21 arch/x86/kernel/traps_32.c | 2 ++
22 arch/x86/kernel/traps_64.c | 2 ++
23 fs/sysfs/file.c | 14 ++++++++++++++
24 fs/sysfs/mount.c | 2 +-
25 include/linux/sysfs.h | 7 +++++++
26 5 files changed, 26 insertions(+), 1 deletion(-)
28 --- a/arch/x86/kernel/traps_32.c
29 +++ b/arch/x86/kernel/traps_32.c
30 @@ -428,6 +428,8 @@ int __kprobes __die(const char *str, str
31 printk("DEBUG_PAGEALLOC");
35 + sysfs_printk_last_file();
36 if (notify_die(DIE_OOPS, str, regs, err,
37 current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
39 --- a/arch/x86/kernel/traps_64.c
40 +++ b/arch/x86/kernel/traps_64.c
41 @@ -537,6 +537,8 @@ int __kprobes __die(const char *str, str
42 printk("DEBUG_PAGEALLOC");
46 + sysfs_printk_last_file();
47 if (notify_die(DIE_OOPS, str, regs, err,
48 current->thread.trap_no, SIGSEGV) == NOTIFY_STOP)
53 #include <linux/slab.h>
54 #include <linux/fsnotify.h>
55 #include <linux/namei.h>
56 +#include <linux/limits.h>
57 #include <linux/poll.h>
58 #include <linux/list.h>
59 #include <linux/mutex.h>
64 +/* used in crash dumps to help with debugging */
65 +static char last_sysfs_file[PATH_MAX];
68 * There's one sysfs_buffer for each open file and one
69 * sysfs_open_dirent for each sysfs_dirent with one or more open
70 @@ -328,6 +332,11 @@ static int sysfs_open_file(struct inode
71 struct sysfs_buffer *buffer;
72 struct sysfs_ops *ops;
76 + p = d_path(&file->f_path, last_sysfs_file, sizeof(last_sysfs_file));
78 + memmove(last_sysfs_file, p, strlen(p) + 1);
80 /* need attr_sd for attr and ops, its parent for kobj */
81 if (!sysfs_get_active_two(attr_sd))
82 @@ -389,6 +398,11 @@ static int sysfs_open_file(struct inode
86 +void sysfs_printk_last_file(void)
88 + printk(KERN_EMERG "last sysfs file: %s\n", last_sysfs_file);
91 static int sysfs_release(struct inode *inode, struct file *filp)
93 struct sysfs_dirent *sd = filp->f_path.dentry->d_fsdata;
94 --- a/fs/sysfs/mount.c
95 +++ b/fs/sysfs/mount.c
97 /* Random magic number */
98 #define SYSFS_MAGIC 0x62656572
100 -static struct vfsmount *sysfs_mount;
101 +struct vfsmount *sysfs_mount;
102 struct super_block * sysfs_sb = NULL;
103 struct kmem_cache *sysfs_dir_cachep;
105 --- a/include/linux/sysfs.h
106 +++ b/include/linux/sysfs.h
107 @@ -121,6 +121,8 @@ void sysfs_notify(struct kobject *kobj,
109 extern int __must_check sysfs_init(void);
111 +void sysfs_printk_last_file(void);
113 #else /* CONFIG_SYSFS */
115 static inline int sysfs_schedule_callback(struct kobject *kobj,
116 @@ -231,6 +233,11 @@ static inline int __must_check sysfs_ini
120 +static inline void sysfs_printk_last_file(void)
125 #endif /* CONFIG_SYSFS */
127 #endif /* _SYSFS_H_ */