Commit 3d9e0cf1 authored by Michael Holzheu's avatar Michael Holzheu Committed by Linus Torvalds

taskstats: split fill_pid function

Separate the finding of a task_struct by pid or tgid from filling the
taskstats data. This makes the code more readable.
Signed-off-by: default avatarMichael Holzheu <holzheu@linux.vnet.ibm.com>
Acked-by: default avatarBalbir Singh <balbir@linux.vnet.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 93233125
...@@ -175,22 +175,8 @@ static void send_cpu_listeners(struct sk_buff *skb, ...@@ -175,22 +175,8 @@ static void send_cpu_listeners(struct sk_buff *skb,
up_write(&listeners->sem); up_write(&listeners->sem);
} }
static int fill_pid(pid_t pid, struct task_struct *tsk, static void fill_stats(struct task_struct *tsk, struct taskstats *stats)
struct taskstats *stats)
{ {
int rc = 0;
if (!tsk) {
rcu_read_lock();
tsk = find_task_by_vpid(pid);
if (tsk)
get_task_struct(tsk);
rcu_read_unlock();
if (!tsk)
return -ESRCH;
} else
get_task_struct(tsk);
memset(stats, 0, sizeof(*stats)); memset(stats, 0, sizeof(*stats));
/* /*
* Each accounting subsystem adds calls to its functions to * Each accounting subsystem adds calls to its functions to
...@@ -209,17 +195,27 @@ static int fill_pid(pid_t pid, struct task_struct *tsk, ...@@ -209,17 +195,27 @@ static int fill_pid(pid_t pid, struct task_struct *tsk,
/* fill in extended acct fields */ /* fill in extended acct fields */
xacct_add_tsk(stats, tsk); xacct_add_tsk(stats, tsk);
}
/* Define err: label here if needed */ static int fill_stats_for_pid(pid_t pid, struct taskstats *stats)
put_task_struct(tsk); {
return rc; struct task_struct *tsk;
rcu_read_lock();
tsk = find_task_by_vpid(pid);
if (tsk)
get_task_struct(tsk);
rcu_read_unlock();
if (!tsk)
return -ESRCH;
fill_stats(tsk, stats);
put_task_struct(tsk);
return 0;
} }
static int fill_tgid(pid_t tgid, struct task_struct *first, static int fill_stats_for_tgid(pid_t tgid, struct taskstats *stats)
struct taskstats *stats)
{ {
struct task_struct *tsk; struct task_struct *tsk, *first;
unsigned long flags; unsigned long flags;
int rc = -ESRCH; int rc = -ESRCH;
...@@ -228,8 +224,7 @@ static int fill_tgid(pid_t tgid, struct task_struct *first, ...@@ -228,8 +224,7 @@ static int fill_tgid(pid_t tgid, struct task_struct *first,
* leaders who are already counted with the dead tasks * leaders who are already counted with the dead tasks
*/ */
rcu_read_lock(); rcu_read_lock();
if (!first) first = find_task_by_vpid(tgid);
first = find_task_by_vpid(tgid);
if (!first || !lock_task_sighand(first, &flags)) if (!first || !lock_task_sighand(first, &flags))
goto out; goto out;
...@@ -268,7 +263,6 @@ static int fill_tgid(pid_t tgid, struct task_struct *first, ...@@ -268,7 +263,6 @@ static int fill_tgid(pid_t tgid, struct task_struct *first,
return rc; return rc;
} }
static void fill_tgid_exit(struct task_struct *tsk) static void fill_tgid_exit(struct task_struct *tsk)
{ {
unsigned long flags; unsigned long flags;
...@@ -483,7 +477,7 @@ static int cmd_attr_pid(struct genl_info *info) ...@@ -483,7 +477,7 @@ static int cmd_attr_pid(struct genl_info *info)
if (!stats) if (!stats)
goto err; goto err;
rc = fill_pid(pid, NULL, stats); rc = fill_stats_for_pid(pid, stats);
if (rc < 0) if (rc < 0)
goto err; goto err;
return send_reply(rep_skb, info); return send_reply(rep_skb, info);
...@@ -513,7 +507,7 @@ static int cmd_attr_tgid(struct genl_info *info) ...@@ -513,7 +507,7 @@ static int cmd_attr_tgid(struct genl_info *info)
if (!stats) if (!stats)
goto err; goto err;
rc = fill_tgid(tgid, NULL, stats); rc = fill_stats_for_tgid(tgid, stats);
if (rc < 0) if (rc < 0)
goto err; goto err;
return send_reply(rep_skb, info); return send_reply(rep_skb, info);
...@@ -599,9 +593,7 @@ void taskstats_exit(struct task_struct *tsk, int group_dead) ...@@ -599,9 +593,7 @@ void taskstats_exit(struct task_struct *tsk, int group_dead)
if (!stats) if (!stats)
goto err; goto err;
rc = fill_pid(-1, tsk, stats); fill_stats(tsk, stats);
if (rc < 0)
goto err;
/* /*
* Doesn't matter if tsk is the leader or the last group member leaving * Doesn't matter if tsk is the leader or the last group member leaving
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment