namespaces.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License, version 2, as
  4. * published by the Free Software Foundation.
  5. *
  6. * Copyright (C) 2017 Hari Bathini, IBM Corporation
  7. */
  8. #ifndef __PERF_NAMESPACES_H
  9. #define __PERF_NAMESPACES_H
  10. #include <sys/types.h>
  11. #include <linux/stddef.h>
  12. #include <linux/perf_event.h>
  13. #include <linux/refcount.h>
  14. #include <linux/types.h>
  15. struct namespaces_event;
  16. struct namespaces {
  17. struct list_head list;
  18. u64 end_time;
  19. struct perf_ns_link_info link_info[];
  20. };
  21. struct namespaces *namespaces__new(struct namespaces_event *event);
  22. void namespaces__free(struct namespaces *namespaces);
  23. struct nsinfo {
  24. pid_t pid;
  25. pid_t tgid;
  26. pid_t nstgid;
  27. bool need_setns;
  28. char *mntns_path;
  29. refcount_t refcnt;
  30. };
  31. struct nscookie {
  32. int oldns;
  33. int newns;
  34. char *oldcwd;
  35. };
  36. int nsinfo__init(struct nsinfo *nsi);
  37. struct nsinfo *nsinfo__new(pid_t pid);
  38. struct nsinfo *nsinfo__copy(struct nsinfo *nsi);
  39. void nsinfo__delete(struct nsinfo *nsi);
  40. struct nsinfo *nsinfo__get(struct nsinfo *nsi);
  41. void nsinfo__put(struct nsinfo *nsi);
  42. void nsinfo__mountns_enter(struct nsinfo *nsi, struct nscookie *nc);
  43. void nsinfo__mountns_exit(struct nscookie *nc);
  44. char *nsinfo__realpath(const char *path, struct nsinfo *nsi);
  45. static inline void __nsinfo__zput(struct nsinfo **nsip)
  46. {
  47. if (nsip) {
  48. nsinfo__put(*nsip);
  49. *nsip = NULL;
  50. }
  51. }
  52. #define nsinfo__zput(nsi) __nsinfo__zput(&nsi)
  53. #endif /* __PERF_NAMESPACES_H */