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

perf namespaces: Add 'in_pidns' to nsinfo struct

Provides an accurate mean to determine if the owner thread is in a
different PID namespace.

Signed-off-by: Yonatan Goldschmidt <yonatan.goldschmidt@granulate.io>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20201105015418.1725218-1-yonatan.goldschmidt@granulate.io
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Yonatan Goldschmidt and committed by
Arnaldo Carvalho de Melo
2b51c71b 473f742e

+10 -2
+9 -2
tools/perf/util/namespaces.c
··· 66 66 char spath[PATH_MAX]; 67 67 char *newns = NULL; 68 68 char *statln = NULL; 69 + char *nspid; 69 70 struct stat old_stat; 70 71 struct stat new_stat; 71 72 FILE *f = NULL; ··· 113 112 } 114 113 115 114 if (strstr(statln, "NStgid:") != NULL) { 116 - nsi->nstgid = (pid_t)strtol(strrchr(statln, '\t'), 117 - NULL, 10); 115 + nspid = strrchr(statln, '\t'); 116 + nsi->nstgid = (pid_t)strtol(nspid, NULL, 10); 117 + /* If innermost tgid is not the first, process is in a different 118 + * PID namespace. 119 + */ 120 + nsi->in_pidns = (statln + sizeof("NStgid:") - 1) != nspid; 118 121 break; 119 122 } 120 123 } ··· 145 140 nsi->tgid = pid; 146 141 nsi->nstgid = pid; 147 142 nsi->need_setns = false; 143 + nsi->in_pidns = false; 148 144 /* Init may fail if the process exits while we're trying to look 149 145 * at its proc information. In that case, save the pid but 150 146 * don't try to enter the namespace. ··· 172 166 nnsi->tgid = nsi->tgid; 173 167 nnsi->nstgid = nsi->nstgid; 174 168 nnsi->need_setns = nsi->need_setns; 169 + nnsi->in_pidns = nsi->in_pidns; 175 170 if (nsi->mntns_path) { 176 171 nnsi->mntns_path = strdup(nsi->mntns_path); 177 172 if (!nnsi->mntns_path) {
+1
tools/perf/util/namespaces.h
··· 33 33 pid_t tgid; 34 34 pid_t nstgid; 35 35 bool need_setns; 36 + bool in_pidns; 36 37 char *mntns_path; 37 38 refcount_t refcnt; 38 39 };