0001
0002
0003
0004
0005
0006
0007 #ifndef __PERF_NAMESPACES_H
0008 #define __PERF_NAMESPACES_H
0009
0010 #include <sys/types.h>
0011 #include <sys/stat.h>
0012 #include <linux/stddef.h>
0013 #include <linux/perf_event.h>
0014 #include <linux/refcount.h>
0015 #include <linux/types.h>
0016
0017 #ifndef HAVE_SETNS_SUPPORT
0018 int setns(int fd, int nstype);
0019 #endif
0020
0021 struct perf_record_namespaces;
0022
0023 struct namespaces {
0024 struct list_head list;
0025 u64 end_time;
0026 struct perf_ns_link_info link_info[];
0027 };
0028
0029 struct namespaces *namespaces__new(struct perf_record_namespaces *event);
0030 void namespaces__free(struct namespaces *namespaces);
0031
0032 struct nsinfo {
0033 pid_t pid;
0034 pid_t tgid;
0035 pid_t nstgid;
0036 bool need_setns;
0037 bool in_pidns;
0038 char *mntns_path;
0039 refcount_t refcnt;
0040 };
0041
0042 struct nscookie {
0043 int oldns;
0044 int newns;
0045 char *oldcwd;
0046 };
0047
0048 int nsinfo__init(struct nsinfo *nsi);
0049 struct nsinfo *nsinfo__new(pid_t pid);
0050 struct nsinfo *nsinfo__copy(const struct nsinfo *nsi);
0051
0052 struct nsinfo *nsinfo__get(struct nsinfo *nsi);
0053 void nsinfo__put(struct nsinfo *nsi);
0054
0055 bool nsinfo__need_setns(const struct nsinfo *nsi);
0056 void nsinfo__clear_need_setns(struct nsinfo *nsi);
0057 pid_t nsinfo__tgid(const struct nsinfo *nsi);
0058 pid_t nsinfo__nstgid(const struct nsinfo *nsi);
0059 pid_t nsinfo__pid(const struct nsinfo *nsi);
0060 pid_t nsinfo__in_pidns(const struct nsinfo *nsi);
0061
0062 void nsinfo__mountns_enter(struct nsinfo *nsi, struct nscookie *nc);
0063 void nsinfo__mountns_exit(struct nscookie *nc);
0064
0065 char *nsinfo__realpath(const char *path, struct nsinfo *nsi);
0066 int nsinfo__stat(const char *filename, struct stat *st, struct nsinfo *nsi);
0067
0068 bool nsinfo__is_in_root_namespace(void);
0069
0070 static inline void __nsinfo__zput(struct nsinfo **nsip)
0071 {
0072 if (nsip) {
0073 nsinfo__put(*nsip);
0074 *nsip = NULL;
0075 }
0076 }
0077
0078 #define nsinfo__zput(nsi) __nsinfo__zput(&nsi)
0079
0080 const char *perf_ns__name(unsigned int id);
0081
0082 #endif