^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2017 Hari Bathini, IBM Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef __PERF_NAMESPACES_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define __PERF_NAMESPACES_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/perf_event.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/refcount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #ifndef HAVE_SETNS_SUPPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) int setns(int fd, int nstype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct perf_record_namespaces;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct namespaces {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) u64 end_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct perf_ns_link_info link_info[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct namespaces *namespaces__new(struct perf_record_namespaces *event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) void namespaces__free(struct namespaces *namespaces);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct nsinfo {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) pid_t pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) pid_t tgid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) pid_t nstgid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) bool need_setns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) char *mntns_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) refcount_t refcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct nscookie {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) int oldns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int newns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) char *oldcwd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int nsinfo__init(struct nsinfo *nsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct nsinfo *nsinfo__new(pid_t pid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct nsinfo *nsinfo__copy(struct nsinfo *nsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) void nsinfo__delete(struct nsinfo *nsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct nsinfo *nsinfo__get(struct nsinfo *nsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) void nsinfo__put(struct nsinfo *nsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) void nsinfo__mountns_enter(struct nsinfo *nsi, struct nscookie *nc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) void nsinfo__mountns_exit(struct nscookie *nc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) char *nsinfo__realpath(const char *path, struct nsinfo *nsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static inline void __nsinfo__zput(struct nsinfo **nsip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (nsip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) nsinfo__put(*nsip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) *nsip = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define nsinfo__zput(nsi) __nsinfo__zput(&nsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) const char *perf_ns__name(unsigned int id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #endif /* __PERF_NAMESPACES_H */