diff options
author | Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com> | 2008-02-20 19:53:29 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-02-25 10:34:18 -0500 |
commit | 13d77c37cab2bb906022309e1e7182c327e49916 (patch) | |
tree | e63f3a56dc443f3a2807b85102464d04934d06db /fs | |
parent | d6643d12cb0885d06a1491b16c1476abcbd53d40 (diff) |
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>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/proc/base.c | 40 |
1 files changed, 12 insertions, 28 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c index 85e06e498078..91a1bd67ac1d 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -314,9 +314,12 @@ static int proc_pid_schedstat(struct task_struct *task, char *buffer) | |||
314 | static int lstats_show_proc(struct seq_file *m, void *v) | 314 | static int lstats_show_proc(struct seq_file *m, void *v) |
315 | { | 315 | { |
316 | int i; | 316 | int i; |
317 | struct task_struct *task = m->private; | 317 | struct inode *inode = m->private; |
318 | seq_puts(m, "Latency Top version : v0.1\n"); | 318 | struct task_struct *task = get_proc_task(inode); |
319 | 319 | ||
320 | if (!task) | ||
321 | return -ESRCH; | ||
322 | seq_puts(m, "Latency Top version : v0.1\n"); | ||
320 | for (i = 0; i < 32; i++) { | 323 | for (i = 0; i < 32; i++) { |
321 | if (task->latency_record[i].backtrace[0]) { | 324 | if (task->latency_record[i].backtrace[0]) { |
322 | int q; | 325 | int q; |
@@ -341,43 +344,24 @@ static int lstats_show_proc(struct seq_file *m, void *v) | |||
341 | } | 344 | } |
342 | 345 | ||
343 | } | 346 | } |
347 | put_task_struct(task); | ||
344 | return 0; | 348 | return 0; |
345 | } | 349 | } |
346 | 350 | ||
347 | static int lstats_open(struct inode *inode, struct file *file) | 351 | static int lstats_open(struct inode *inode, struct file *file) |
348 | { | 352 | { |
349 | int ret; | 353 | return single_open(file, lstats_show_proc, inode); |
350 | struct seq_file *m; | ||
351 | struct task_struct *task = get_proc_task(inode); | ||
352 | |||
353 | if (!task) | ||
354 | return -ENOENT; | ||
355 | ret = single_open(file, lstats_show_proc, NULL); | ||
356 | if (!ret) { | ||
357 | m = file->private_data; | ||
358 | m->private = task; | ||
359 | } | ||
360 | return ret; | ||
361 | } | ||
362 | |||
363 | static int lstats_release(struct inode *inode, struct file *file) | ||
364 | { | ||
365 | struct seq_file *m = file->private_data; | ||
366 | struct task_struct *task = m->private; | ||
367 | |||
368 | put_task_struct(task); | ||
369 | return single_release(inode, file); | ||
370 | } | 354 | } |
371 | 355 | ||
372 | static ssize_t lstats_write(struct file *file, const char __user *buf, | 356 | static ssize_t lstats_write(struct file *file, const char __user *buf, |
373 | size_t count, loff_t *offs) | 357 | size_t count, loff_t *offs) |
374 | { | 358 | { |
375 | struct seq_file *m; | 359 | struct task_struct *task = get_proc_task(file->f_dentry->d_inode); |
376 | struct task_struct *task; | ||
377 | 360 | ||
378 | m = file->private_data; | 361 | if (!task) |
379 | task = m->private; | 362 | return -ESRCH; |
380 | clear_all_latency_tracing(task); | 363 | clear_all_latency_tracing(task); |
364 | put_task_struct(task); | ||
381 | 365 | ||
382 | return count; | 366 | return count; |
383 | } | 367 | } |
@@ -387,7 +371,7 @@ static const struct file_operations proc_lstats_operations = { | |||
387 | .read = seq_read, | 371 | .read = seq_read, |
388 | .write = lstats_write, | 372 | .write = lstats_write, |
389 | .llseek = seq_lseek, | 373 | .llseek = seq_lseek, |
390 | .release = lstats_release, | 374 | .release = single_release, |
391 | }; | 375 | }; |
392 | 376 | ||
393 | #endif | 377 | #endif |