latencytop: change /proc task_struct access method
Change getting task_struct by get_proc_task() at read or write time, and returns -ESRCH if get_proc_task() returns NULL. This is same behavior as other /proc files. Signed-off-by: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
parent
d6643d12cb
commit
13d77c37ca
@ -314,9 +314,12 @@ static int proc_pid_schedstat(struct task_struct *task, char *buffer)
|
|||||||
static int lstats_show_proc(struct seq_file *m, void *v)
|
static int lstats_show_proc(struct seq_file *m, void *v)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct task_struct *task = m->private;
|
struct inode *inode = m->private;
|
||||||
seq_puts(m, "Latency Top version : v0.1\n");
|
struct task_struct *task = get_proc_task(inode);
|
||||||
|
|
||||||
|
if (!task)
|
||||||
|
return -ESRCH;
|
||||||
|
seq_puts(m, "Latency Top version : v0.1\n");
|
||||||
for (i = 0; i < 32; i++) {
|
for (i = 0; i < 32; i++) {
|
||||||
if (task->latency_record[i].backtrace[0]) {
|
if (task->latency_record[i].backtrace[0]) {
|
||||||
int q;
|
int q;
|
||||||
@ -341,43 +344,24 @@ static int lstats_show_proc(struct seq_file *m, void *v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
put_task_struct(task);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lstats_open(struct inode *inode, struct file *file)
|
static int lstats_open(struct inode *inode, struct file *file)
|
||||||
{
|
{
|
||||||
int ret;
|
return single_open(file, lstats_show_proc, inode);
|
||||||
struct seq_file *m;
|
|
||||||
struct task_struct *task = get_proc_task(inode);
|
|
||||||
|
|
||||||
if (!task)
|
|
||||||
return -ENOENT;
|
|
||||||
ret = single_open(file, lstats_show_proc, NULL);
|
|
||||||
if (!ret) {
|
|
||||||
m = file->private_data;
|
|
||||||
m->private = task;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int lstats_release(struct inode *inode, struct file *file)
|
|
||||||
{
|
|
||||||
struct seq_file *m = file->private_data;
|
|
||||||
struct task_struct *task = m->private;
|
|
||||||
|
|
||||||
put_task_struct(task);
|
|
||||||
return single_release(inode, file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t lstats_write(struct file *file, const char __user *buf,
|
static ssize_t lstats_write(struct file *file, const char __user *buf,
|
||||||
size_t count, loff_t *offs)
|
size_t count, loff_t *offs)
|
||||||
{
|
{
|
||||||
struct seq_file *m;
|
struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
|
||||||
struct task_struct *task;
|
|
||||||
|
|
||||||
m = file->private_data;
|
if (!task)
|
||||||
task = m->private;
|
return -ESRCH;
|
||||||
clear_all_latency_tracing(task);
|
clear_all_latency_tracing(task);
|
||||||
|
put_task_struct(task);
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
@ -387,7 +371,7 @@ static const struct file_operations proc_lstats_operations = {
|
|||||||
.read = seq_read,
|
.read = seq_read,
|
||||||
.write = lstats_write,
|
.write = lstats_write,
|
||||||
.llseek = seq_lseek,
|
.llseek = seq_lseek,
|
||||||
.release = lstats_release,
|
.release = single_release,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user