blob: 4b33f684eddd00f20cba42f05444cd48210711c8 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Hari Bathinif3b36142017-03-08 02:11:43 +05302/*
Hari Bathinif3b36142017-03-08 02:11:43 +05303 *
4 * Copyright (C) 2017 Hari Bathini, IBM Corporation
5 */
6
7#ifndef __PERF_NAMESPACES_H
8#define __PERF_NAMESPACES_H
9
Arnaldo Carvalho de Melob1f03ca2017-10-19 15:11:17 -030010#include <sys/types.h>
Arnaldo Carvalho de Melo44fe6192018-07-30 13:15:03 -030011#include <linux/stddef.h>
Arnaldo Carvalho de Melob1f03ca2017-10-19 15:11:17 -030012#include <linux/perf_event.h>
Krister Johansen843ff372017-07-05 18:48:08 -070013#include <linux/refcount.h>
Arnaldo Carvalho de Melob1f03ca2017-10-19 15:11:17 -030014#include <linux/types.h>
Hari Bathinif3b36142017-03-08 02:11:43 +053015
Arnaldo Carvalho de Melo245aec72019-07-05 13:59:06 -030016#ifndef HAVE_SETNS_SUPPORT
17int setns(int fd, int nstype);
18#endif
19
Arnaldo Carvalho de Melo69d81f02019-08-26 19:02:31 -030020struct perf_record_namespaces;
Hari Bathinif3b36142017-03-08 02:11:43 +053021
22struct namespaces {
23 struct list_head list;
24 u64 end_time;
25 struct perf_ns_link_info link_info[];
26};
27
Arnaldo Carvalho de Melo69d81f02019-08-26 19:02:31 -030028struct namespaces *namespaces__new(struct perf_record_namespaces *event);
Hari Bathinif3b36142017-03-08 02:11:43 +053029void namespaces__free(struct namespaces *namespaces);
30
Krister Johansen843ff372017-07-05 18:48:08 -070031struct nsinfo {
32 pid_t pid;
Krister Johansenbf2e7102017-07-05 18:48:09 -070033 pid_t tgid;
34 pid_t nstgid;
Krister Johansen843ff372017-07-05 18:48:08 -070035 bool need_setns;
36 char *mntns_path;
37 refcount_t refcnt;
38};
39
40struct nscookie {
41 int oldns;
42 int newns;
Jiri Olsab01c1f692018-11-01 18:00:01 +010043 char *oldcwd;
Krister Johansen843ff372017-07-05 18:48:08 -070044};
45
Krister Johansenbf2e7102017-07-05 18:48:09 -070046int nsinfo__init(struct nsinfo *nsi);
Krister Johansen843ff372017-07-05 18:48:08 -070047struct nsinfo *nsinfo__new(pid_t pid);
Krister Johansenbf2e7102017-07-05 18:48:09 -070048struct nsinfo *nsinfo__copy(struct nsinfo *nsi);
Krister Johansen843ff372017-07-05 18:48:08 -070049void nsinfo__delete(struct nsinfo *nsi);
50
51struct nsinfo *nsinfo__get(struct nsinfo *nsi);
52void nsinfo__put(struct nsinfo *nsi);
53
54void nsinfo__mountns_enter(struct nsinfo *nsi, struct nscookie *nc);
55void nsinfo__mountns_exit(struct nscookie *nc);
56
Krister Johansen544abd42017-07-05 18:48:10 -070057char *nsinfo__realpath(const char *path, struct nsinfo *nsi);
58
Krister Johansen843ff372017-07-05 18:48:08 -070059static inline void __nsinfo__zput(struct nsinfo **nsip)
60{
61 if (nsip) {
62 nsinfo__put(*nsip);
63 *nsip = NULL;
64 }
65}
66
67#define nsinfo__zput(nsi) __nsinfo__zput(&nsi)
68
Arnaldo Carvalho de Melo055c67e2019-09-18 16:08:52 -030069const char *perf_ns__name(unsigned int id);
70
Hari Bathinif3b36142017-03-08 02:11:43 +053071#endif /* __PERF_NAMESPACES_H */