Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754425AbbGFIvH (ORCPT ); Mon, 6 Jul 2015 04:51:07 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:14676 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754291AbbGFIvD (ORCPT ); Mon, 6 Jul 2015 04:51:03 -0400 From: Andrey Vagin To: linux-kernel@vger.kernel.org Cc: linux-api@vger.kernel.org, Andrey Vagin , Oleg Nesterov , Andrew Morton , Cyrill Gorcunov , Pavel Emelyanov , Roger Luethi , Arnd Bergmann , Arnaldo Carvalho de Melo , David Ahern , Andy Lutomirski , Pavel Odintsov Subject: [PATCH 11/24] task_diag: add a new group to get task statistics Date: Mon, 6 Jul 2015 11:47:12 +0300 Message-Id: <1436172445-6979-12-git-send-email-avagin@openvz.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1436172445-6979-1-git-send-email-avagin@openvz.org> References: <1436172445-6979-1-git-send-email-avagin@openvz.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3606 Lines: 124 Signed-off-by: Andrey Vagin --- include/linux/taskstats_kern.h | 2 ++ include/uapi/linux/task_diag.h | 2 ++ kernel/taskdiag.c | 30 ++++++++++++++++++++++++++++++ kernel/taskstats.c | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/include/linux/taskstats_kern.h b/include/linux/taskstats_kern.h index 716835f..8faec32 100644 --- a/include/linux/taskstats_kern.h +++ b/include/linux/taskstats_kern.h @@ -32,6 +32,8 @@ int taskdiag_doit(struct sk_buff *skb, struct genl_info *info); struct netlink_callback; int taskdiag_dumpit(struct sk_buff *skb, struct netlink_callback *cb); +extern int fill_stats_for_pid(pid_t pid, struct taskstats *stats); + #else static inline void taskstats_exit(struct task_struct *tsk, int group_dead) {} diff --git a/include/uapi/linux/task_diag.h b/include/uapi/linux/task_diag.h index af192db..c51380a 100644 --- a/include/uapi/linux/task_diag.h +++ b/include/uapi/linux/task_diag.h @@ -8,6 +8,7 @@ enum { /* optional attributes which can be specified in show_flags */ TASK_DIAG_BASE = 0, TASK_DIAG_CRED, + TASK_DIAG_STAT, /* other attributes */ TASK_DIAG_PID = 64, /* u32 */ @@ -18,6 +19,7 @@ enum { #define TASK_DIAG_SHOW_BASE (1ULL << TASK_DIAG_BASE) #define TASK_DIAG_SHOW_CRED (1ULL << TASK_DIAG_CRED) +#define TASK_DIAG_SHOW_STAT (1ULL << TASK_DIAG_STAT) enum { TASK_DIAG_RUNNING, diff --git a/kernel/taskdiag.c b/kernel/taskdiag.c index 6dd3361..a49ccab 100644 --- a/kernel/taskdiag.c +++ b/kernel/taskdiag.c @@ -6,6 +6,7 @@ #include #include #include +#include static size_t taskdiag_packet_size(u64 show_flags) { @@ -19,6 +20,9 @@ static size_t taskdiag_packet_size(u64 show_flags) if (show_flags & TASK_DIAG_SHOW_CRED) size += nla_total_size(sizeof(struct task_diag_creds)); + if (show_flags & TASK_DIAG_SHOW_STAT) + size += nla_total_size(sizeof(struct taskstats)); + return size; } @@ -94,6 +98,24 @@ static inline void caps2diag(struct task_diag_caps *diag, const kernel_cap_t *ca diag->cap[i] = cap->cap[i]; } +static int fill_stats(struct task_struct *tsk, struct sk_buff *skb) +{ + struct taskstats *diag_stats; + struct nlattr *attr; + int ret; + + attr = nla_reserve(skb, TASK_DIAG_STAT, sizeof(struct taskstats)); + if (!attr) + return -EMSGSIZE; + + diag_stats = nla_data(attr); + + ret = fill_stats_for_pid(task_pid_vnr(tsk), diag_stats); + if (ret) + return ret; + return 0; +} + static int fill_creds(struct task_struct *p, struct sk_buff *skb) { struct user_namespace *user_ns = current_user_ns(); @@ -168,6 +190,14 @@ static int task_diag_fill(struct task_struct *tsk, struct sk_buff *skb, i++; } + if (show_flags & TASK_DIAG_SHOW_STAT) { + if (i >= n) + err = fill_stats(tsk, skb); + if (err) + goto err; + i++; + } + genlmsg_end(skb, reply); if (cb) cb->args[2] = 0; diff --git a/kernel/taskstats.c b/kernel/taskstats.c index 40f2cdf2..3b3d660 100644 --- a/kernel/taskstats.c +++ b/kernel/taskstats.c @@ -192,7 +192,7 @@ static void fill_stats(struct user_namespace *user_ns, xacct_add_tsk(stats, tsk); } -static int fill_stats_for_pid(pid_t pid, struct taskstats *stats) +int fill_stats_for_pid(pid_t pid, struct taskstats *stats) { struct task_struct *tsk; -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/