namespaces.h 2.0 KB

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