Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Michael Holzheu and committed by
Linus Torvalds
3d9e0cf1 93233125

+22 -30
+22 -30
kernel/taskstats.c
··· 175 175 up_write(&listeners->sem); 176 176 } 177 177 178 - static int fill_pid(pid_t pid, struct task_struct *tsk, 179 - struct taskstats *stats) 178 + static void fill_stats(struct task_struct *tsk, struct taskstats *stats) 180 179 { 181 - int rc = 0; 182 - 183 - if (!tsk) { 184 - rcu_read_lock(); 185 - tsk = find_task_by_vpid(pid); 186 - if (tsk) 187 - get_task_struct(tsk); 188 - rcu_read_unlock(); 189 - if (!tsk) 190 - return -ESRCH; 191 - } else 192 - get_task_struct(tsk); 193 - 194 180 memset(stats, 0, sizeof(*stats)); 195 181 /* 196 182 * Each accounting subsystem adds calls to its functions to ··· 195 209 196 210 /* fill in extended acct fields */ 197 211 xacct_add_tsk(stats, tsk); 198 - 199 - /* Define err: label here if needed */ 200 - put_task_struct(tsk); 201 - return rc; 202 - 203 212 } 204 213 205 - static int fill_tgid(pid_t tgid, struct task_struct *first, 206 - struct taskstats *stats) 214 + static int fill_stats_for_pid(pid_t pid, struct taskstats *stats) 207 215 { 208 216 struct task_struct *tsk; 217 + 218 + rcu_read_lock(); 219 + tsk = find_task_by_vpid(pid); 220 + if (tsk) 221 + get_task_struct(tsk); 222 + rcu_read_unlock(); 223 + if (!tsk) 224 + return -ESRCH; 225 + fill_stats(tsk, stats); 226 + put_task_struct(tsk); 227 + return 0; 228 + } 229 + 230 + static int fill_stats_for_tgid(pid_t tgid, struct taskstats *stats) 231 + { 232 + struct task_struct *tsk, *first; 209 233 unsigned long flags; 210 234 int rc = -ESRCH; 211 235 ··· 224 228 * leaders who are already counted with the dead tasks 225 229 */ 226 230 rcu_read_lock(); 227 - if (!first) 228 - first = find_task_by_vpid(tgid); 231 + first = find_task_by_vpid(tgid); 229 232 230 233 if (!first || !lock_task_sighand(first, &flags)) 231 234 goto out; ··· 262 267 */ 263 268 return rc; 264 269 } 265 - 266 270 267 271 static void fill_tgid_exit(struct task_struct *tsk) 268 272 { ··· 477 483 if (!stats) 478 484 goto err; 479 485 480 - rc = fill_pid(pid, NULL, stats); 486 + rc = fill_stats_for_pid(pid, stats); 481 487 if (rc < 0) 482 488 goto err; 483 489 return send_reply(rep_skb, info); ··· 507 513 if (!stats) 508 514 goto err; 509 515 510 - rc = fill_tgid(tgid, NULL, stats); 516 + rc = fill_stats_for_tgid(tgid, stats); 511 517 if (rc < 0) 512 518 goto err; 513 519 return send_reply(rep_skb, info); ··· 593 599 if (!stats) 594 600 goto err; 595 601 596 - rc = fill_pid(-1, tsk, stats); 597 - if (rc < 0) 598 - goto err; 602 + fill_stats(tsk, stats); 599 603 600 604 /* 601 605 * Doesn't matter if tsk is the leader or the last group member leaving