From: Greg KH <gregkh@suse.de>
To: Phil Carmody <ext-phil.2.carmody@nokia.com>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] sysfs: add more info to the oops dump
Date: Thu, 10 Mar 2011 08:25:01 -0800 [thread overview]
Message-ID: <20110310162501.GB23989@suse.de> (raw)
In-Reply-To: <1299772388-15439-1-git-send-email-ext-phil.2.carmody@nokia.com>
On Thu, Mar 10, 2011 at 05:53:08PM +0200, Phil Carmody wrote:
> If we're going to remember which file we accessed, we might as well
> also remember whether it was a read or a write, and if the latter,
> some indication of what was written.
>
> e.g.
> $ echo 1 > /sys/kernel/slab/:at-0000064/sanity_checks
> $ echo c > /proc/sysrq-trigger
> ...
> [ 112.457580] last sysfs file (w): /sys/kernel/slab/:at-0000064/sanity_checks
> [ 112.464569] written: 1
Has this actually helped you out? I've been thinking of removing this
line in the dmesg entirely as I haven't seen it help in a very long time
to track anything down.
>
> Signed-off-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
> ---
> fs/sysfs/file.c | 21 ++++++++++++++++++++-
> 1 files changed, 20 insertions(+), 1 deletions(-)
>
> diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
> index da3fefe..281e4dd 100644
> --- a/fs/sysfs/file.c
> +++ b/fs/sysfs/file.c
> @@ -26,9 +26,18 @@
>
> /* used in crash dumps to help with debugging */
> static char last_sysfs_file[PATH_MAX];
> +static char last_sysfs_write[16];
> +static int last_sysfs_write_len; /* magic value < 0 => read */
> void sysfs_printk_last_file(void)
> {
> - printk(KERN_EMERG "last sysfs file: %s\n", last_sysfs_file);
> + printk(KERN_EMERG "last sysfs file (%c): %s\n",
> + (last_sysfs_write_len < 0) ? 'r' : 'w',
> + last_sysfs_file);
> + if (last_sysfs_write_len >= sizeof(last_sysfs_write))
> + printk(KERN_EMERG " written: %s...(%d chars)\n",
> + last_sysfs_write, last_sysfs_write_len);
> + else if (last_sysfs_write_len > 0)
> + printk(KERN_EMERG " written: %s\n", last_sysfs_write);
> }
>
> /*
> @@ -200,12 +209,19 @@ flush_write_buffer(struct dentry * dentry, struct sysfs_buffer * buffer, size_t
> struct sysfs_dirent *attr_sd = dentry->d_fsdata;
> struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
> const struct sysfs_ops * ops = buffer->ops;
> + int copylen = min(count, sizeof(last_sysfs_write) - 1);
> int rc;
>
> /* need attr_sd for attr and ops, its parent for kobj */
> if (!sysfs_get_active(attr_sd))
> return -ENODEV;
>
> + while (copylen > 0 && buffer->page[copylen-1] == '\n')
> + --copylen; /* never print trailing \n's */
> + memcpy(last_sysfs_write, buffer->page, copylen);
> + last_sysfs_write[copylen] = '\0';
> + last_sysfs_write_len = count;
> +
> rc = ops->store(kobj, attr_sd->s_attr.attr, buffer->page, count);
>
> sysfs_put_active(attr_sd);
> @@ -363,6 +379,9 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
> if (file->f_mode & FMODE_WRITE) {
> if (!(inode->i_mode & S_IWUGO) || !ops->store)
> goto err_out;
> + last_sysfs_write_len = 0;
> + } else {
> + last_sysfs_write_len = -1; /* magic value */
"magic" values are bad, please use a #define or something else that
makes more sense to those looking at the code in 5 years.
thanks,
greg k-h
next prev parent reply other threads:[~2011-03-10 17:05 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-10 15:53 [PATCH 1/1] sysfs: add more info to the oops dump Phil Carmody
2011-03-10 16:25 ` Greg KH [this message]
2011-03-10 18:32 ` Phil Carmody
2011-03-10 19:02 ` Greg KH
2011-03-10 21:10 ` Phil Carmody
2011-03-10 21:27 ` Greg KH
2011-03-10 22:27 ` [PATCHv3 0/1] " Phil Carmody
2011-03-10 22:27 ` [PATCHv3 1/1] " Phil Carmody
2011-03-10 22:38 ` Andrew Morton
2011-03-10 22:59 ` Thomas Gleixner
2011-03-10 23:03 ` Greg KH
2011-03-10 23:15 ` Andrew Morton
2011-03-10 23:06 ` Phil Carmody
2011-03-10 23:13 ` Thomas Gleixner
2011-03-10 23:22 ` Andrew Morton
2011-03-10 23:27 ` Thomas Gleixner
2011-03-10 23:46 ` Thomas Gleixner
2011-03-10 23:22 ` Phil Carmody
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110310162501.GB23989@suse.de \
--to=gregkh@suse.de \
--cc=akpm@linux-foundation.org \
--cc=ext-phil.2.carmody@nokia.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.