git://ftp.safe.ca
/
safe
/
jmp
/
linux-2.6
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[PATCH] docbook: merge journal-api into filesystems.tmpl
[safe/jmp/linux-2.6]
/
kernel
/
taskstats.c
diff --git
a/kernel/taskstats.c
b/kernel/taskstats.c
index
5d6a8c5
..
f45c5e7
100644
(file)
--- a/
kernel/taskstats.c
+++ b/
kernel/taskstats.c
@@
-77,7
+77,8
@@
static int prepare_reply(struct genl_info *info, u8 cmd, struct sk_buff **skbp,
/*
* If new attributes are added, please revisit this allocation
*/
/*
* If new attributes are added, please revisit this allocation
*/
- skb = nlmsg_new(genlmsg_total_size(size), GFP_KERNEL);
+ size = nlmsg_total_size(genlmsg_total_size(size));
+ skb = nlmsg_new(size, GFP_KERNEL);
if (!skb)
return -ENOMEM;
if (!skb)
return -ENOMEM;
@@
-174,21
+175,19
@@
static void send_cpu_listeners(struct sk_buff *skb, unsigned int cpu)
up_write(&listeners->sem);
}
up_write(&listeners->sem);
}
-static int fill_pid(pid_t pid, struct task_struct *
pid
tsk,
+static int fill_pid(pid_t pid, struct task_struct *tsk,
struct taskstats *stats)
{
int rc = 0;
struct taskstats *stats)
{
int rc = 0;
- struct task_struct *tsk = pidtsk;
- if (!
pid
tsk) {
- r
ead_lock(&tasklist_lock
);
+ if (!tsk) {
+ r
cu_read_lock(
);
tsk = find_task_by_pid(pid);
tsk = find_task_by_pid(pid);
- if (!tsk) {
- read_unlock(&tasklist_lock);
+ if (tsk)
+ get_task_struct(tsk);
+ rcu_read_unlock();
+ if (!tsk)
return -ESRCH;
return -ESRCH;
- }
- get_task_struct(tsk);
- read_unlock(&tasklist_lock);
} else
get_task_struct(tsk);
} else
get_task_struct(tsk);
@@
-214,39
+213,30
@@
static int fill_pid(pid_t pid, struct task_struct *pidtsk,
}
}
-static int fill_tgid(pid_t tgid, struct task_struct *
tgidtsk
,
+static int fill_tgid(pid_t tgid, struct task_struct *
first
,
struct taskstats *stats)
{
struct taskstats *stats)
{
- struct task_struct *tsk
, *first
;
+ struct task_struct *tsk;
unsigned long flags;
unsigned long flags;
+ int rc = -ESRCH;
/*
* Add additional stats from live tasks except zombie thread group
* leaders who are already counted with the dead tasks
*/
/*
* Add additional stats from live tasks except zombie thread group
* leaders who are already counted with the dead tasks
*/
- first = tgidtsk;
- if (!first) {
- read_lock(&tasklist_lock);
+ rcu_read_lock();
+ if (!first)
first = find_task_by_pid(tgid);
first = find_task_by_pid(tgid);
- if (!first) {
- read_unlock(&tasklist_lock);
- return -ESRCH;
- }
- get_task_struct(first);
- read_unlock(&tasklist_lock);
- } else
- get_task_struct(first);
- /* Start with stats from dead tasks */
- spin_lock_irqsave(&first->signal->stats_lock, flags);
+ if (!first || !lock_task_sighand(first, &flags))
+ goto out;
+
if (first->signal->stats)
memcpy(stats, first->signal->stats, sizeof(*stats));
if (first->signal->stats)
memcpy(stats, first->signal->stats, sizeof(*stats));
- spin_unlock_irqrestore(&first->signal->stats_lock, flags);
tsk = first;
tsk = first;
- read_lock(&tasklist_lock);
do {
do {
- if (tsk->exit_state
== EXIT_ZOMBIE && thread_group_leader(tsk)
)
+ if (tsk->exit_state)
continue;
/*
* Accounting subsystem can call its functions here to
continue;
/*
* Accounting subsystem can call its functions here to
@@
-257,15
+247,18
@@
static int fill_tgid(pid_t tgid, struct task_struct *tgidtsk,
delayacct_add_tsk(stats, tsk);
} while_each_thread(first, tsk);
delayacct_add_tsk(stats, tsk);
} while_each_thread(first, tsk);
- read_unlock(&tasklist_lock);
- stats->version = TASKSTATS_VERSION;
+ unlock_task_sighand(first, &flags);
+ rc = 0;
+out:
+ rcu_read_unlock();
+
+ stats->version = TASKSTATS_VERSION;
/*
* Accounting subsytems can also add calls here to modify
* fields of taskstats.
*/
/*
* Accounting subsytems can also add calls here to modify
* fields of taskstats.
*/
-
- return 0;
+ return rc;
}
}
@@
-273,7
+266,7
@@
static void fill_tgid_exit(struct task_struct *tsk)
{
unsigned long flags;
{
unsigned long flags;
- spin_lock_irqsave(&tsk->sig
nal->stats_
lock, flags);
+ spin_lock_irqsave(&tsk->sig
hand->sig
lock, flags);
if (!tsk->signal->stats)
goto ret;
if (!tsk->signal->stats)
goto ret;
@@
-285,7
+278,7
@@
static void fill_tgid_exit(struct task_struct *tsk)
*/
delayacct_add_tsk(tsk->signal->stats, tsk);
ret:
*/
delayacct_add_tsk(tsk->signal->stats, tsk);
ret:
- spin_unlock_irqrestore(&tsk->sig
nal->stats_
lock, flags);
+ spin_unlock_irqrestore(&tsk->sig
hand->sig
lock, flags);
return;
}
return;
}
@@
-419,7
+412,7
@@
static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
return send_reply(rep_skb, info->snd_pid);
nla_put_failure:
return send_reply(rep_skb, info->snd_pid);
nla_put_failure:
- r
eturn
genlmsg_cancel(rep_skb, reply);
+ r
c =
genlmsg_cancel(rep_skb, reply);
err:
nlmsg_free(rep_skb);
return rc;
err:
nlmsg_free(rep_skb);
return rc;
@@
-461,24
+454,26
@@
void taskstats_exit_send(struct task_struct *tsk, struct taskstats *tidstats,
size_t size;
int is_thread_group;
struct nlattr *na;
size_t size;
int is_thread_group;
struct nlattr *na;
- unsigned long flags;
- if (!family_registered
|| !tidstats
)
+ if (!family_registered)
return;
return;
- spin_lock_irqsave(&tsk->signal->stats_lock, flags);
- is_thread_group = tsk->signal->stats ? 1 : 0;
- spin_unlock_irqrestore(&tsk->signal->stats_lock, flags);
-
- rc = 0;
/*
* Size includes space for nested attributes
*/
size = nla_total_size(sizeof(u32)) +
nla_total_size(sizeof(struct taskstats)) + nla_total_size(0);
/*
* Size includes space for nested attributes
*/
size = nla_total_size(sizeof(u32)) +
nla_total_size(sizeof(struct taskstats)) + nla_total_size(0);
- if (is_thread_group)
- size = 2 * size; /* PID + STATS + TGID + STATS */
+ is_thread_group = (tsk->signal->stats != NULL);
+ if (is_thread_group) {
+ /* PID + STATS + TGID + STATS */
+ size = 2 * size;
+ /* fill the tsk->signal->stats structure */
+ fill_tgid_exit(tsk);
+ }
+
+ if (!tidstats)
+ return;
rc = prepare_reply(NULL, TASKSTATS_CMD_NEW, &rep_skb, &reply, size);
if (rc < 0)
rc = prepare_reply(NULL, TASKSTATS_CMD_NEW, &rep_skb, &reply, size);
if (rc < 0)
@@
-498,11
+493,8
@@
void taskstats_exit_send(struct task_struct *tsk, struct taskstats *tidstats,
goto send;
/*
goto send;
/*
- * tsk has/had a thread group so fill the tsk->signal->stats structure
* 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
*/
-
- fill_tgid_exit(tsk);
if (!group_dead)
goto send;
if (!group_dead)
goto send;
@@
-519,7
+511,6
@@
send:
nla_put_failure:
genlmsg_cancel(rep_skb, reply);
nla_put_failure:
genlmsg_cancel(rep_skb, reply);
- goto ret;
err_skb:
nlmsg_free(rep_skb);
ret:
err_skb:
nlmsg_free(rep_skb);
ret: