Commit 93233125 authored by Michael Holzheu's avatar Michael Holzheu Committed by Linus Torvalds

taskstats: separate taskstats commands

Move each taskstats command into a single function.  This makes the code
more readable and makes it easier to add new commands.
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 85893120
...@@ -430,39 +430,46 @@ static int cgroupstats_user_cmd(struct sk_buff *skb, struct genl_info *info) ...@@ -430,39 +430,46 @@ static int cgroupstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
return rc; return rc;
} }
static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info) static int cmd_attr_register_cpumask(struct genl_info *info)
{ {
int rc;
struct sk_buff *rep_skb;
struct taskstats *stats;
size_t size;
cpumask_var_t mask; cpumask_var_t mask;
int rc;
if (!alloc_cpumask_var(&mask, GFP_KERNEL)) if (!alloc_cpumask_var(&mask, GFP_KERNEL))
return -ENOMEM; return -ENOMEM;
rc = parse(info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK], mask); rc = parse(info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK], mask);
if (rc < 0) if (rc < 0)
goto free_return_rc; goto out;
if (rc == 0) { rc = add_del_listener(info->snd_pid, mask, REGISTER);
rc = add_del_listener(info->snd_pid, mask, REGISTER); out:
goto free_return_rc; free_cpumask_var(mask);
} return rc;
}
static int cmd_attr_deregister_cpumask(struct genl_info *info)
{
cpumask_var_t mask;
int rc;
if (!alloc_cpumask_var(&mask, GFP_KERNEL))
return -ENOMEM;
rc = parse(info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK], mask); rc = parse(info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK], mask);
if (rc < 0) if (rc < 0)
goto free_return_rc; goto out;
if (rc == 0) { rc = add_del_listener(info->snd_pid, mask, DEREGISTER);
rc = add_del_listener(info->snd_pid, mask, DEREGISTER); out:
free_return_rc:
free_cpumask_var(mask);
return rc;
}
free_cpumask_var(mask); free_cpumask_var(mask);
return rc;
}
static int cmd_attr_pid(struct genl_info *info)
{
struct taskstats *stats;
struct sk_buff *rep_skb;
size_t size;
u32 pid;
int rc;
/*
* Size includes space for nested attributes
*/
size = nla_total_size(sizeof(u32)) + size = nla_total_size(sizeof(u32)) +
nla_total_size(sizeof(struct taskstats)) + nla_total_size(0); nla_total_size(sizeof(struct taskstats)) + nla_total_size(0);
...@@ -471,33 +478,64 @@ static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info) ...@@ -471,33 +478,64 @@ static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
return rc; return rc;
rc = -EINVAL; rc = -EINVAL;
if (info->attrs[TASKSTATS_CMD_ATTR_PID]) { pid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_PID]);
u32 pid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_PID]); stats = mk_reply(rep_skb, TASKSTATS_TYPE_PID, pid);
stats = mk_reply(rep_skb, TASKSTATS_TYPE_PID, pid); if (!stats)
if (!stats) goto err;
goto err;
rc = fill_pid(pid, NULL, stats);
rc = fill_pid(pid, NULL, stats); if (rc < 0)
if (rc < 0) goto err;
goto err; return send_reply(rep_skb, info);
} else if (info->attrs[TASKSTATS_CMD_ATTR_TGID]) { err:
u32 tgid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_TGID]); nlmsg_free(rep_skb);
stats = mk_reply(rep_skb, TASKSTATS_TYPE_TGID, tgid); return rc;
if (!stats) }
goto err;
static int cmd_attr_tgid(struct genl_info *info)
rc = fill_tgid(tgid, NULL, stats); {
if (rc < 0) struct taskstats *stats;
goto err; struct sk_buff *rep_skb;
} else size_t size;
u32 tgid;
int rc;
size = nla_total_size(sizeof(u32)) +
nla_total_size(sizeof(struct taskstats)) + nla_total_size(0);
rc = prepare_reply(info, TASKSTATS_CMD_NEW, &rep_skb, size);
if (rc < 0)
return rc;
rc = -EINVAL;
tgid = nla_get_u32(info->attrs[TASKSTATS_CMD_ATTR_TGID]);
stats = mk_reply(rep_skb, TASKSTATS_TYPE_TGID, tgid);
if (!stats)
goto err; goto err;
rc = fill_tgid(tgid, NULL, stats);
if (rc < 0)
goto err;
return send_reply(rep_skb, info); return send_reply(rep_skb, info);
err: err:
nlmsg_free(rep_skb); nlmsg_free(rep_skb);
return rc; return rc;
} }
static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
{
if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
return cmd_attr_register_cpumask(info);
else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
return cmd_attr_deregister_cpumask(info);
else if (info->attrs[TASKSTATS_CMD_ATTR_PID])
return cmd_attr_pid(info);
else if (info->attrs[TASKSTATS_CMD_ATTR_TGID])
return cmd_attr_tgid(info);
else
return -EINVAL;
}
static struct taskstats *taskstats_tgid_alloc(struct task_struct *tsk) static struct taskstats *taskstats_tgid_alloc(struct task_struct *tsk)
{ {
struct signal_struct *sig = tsk->signal; struct signal_struct *sig = tsk->signal;
......
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