namespaces.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/perf_event.h>
  12. #include <linux/refcount.h>
  13. #include <linux/types.h>
  14. struct namespaces_event;
  15. struct namespaces {
  16. struct list_head list;
  17. u64 end_time;
  18. struct perf_ns_link_info link_info[];
  19. };
  20. struct namespaces *namespaces__new(struct namespaces_event *event);
  21. void namespaces__free(struct namespaces *namespaces);
  22. struct nsinfo {
  23. pid_t pid;
  24. pid_t tgid;
  25. pid_t nstgid;
  26. bool need_setns;
  27. char *mntns_path;
  28. refcount_t refcnt;
  29. };
  30. struct nscookie {
  31. int oldns;
  32. int newns;
  33. };
  34. int nsinfo__init(struct nsinfo *nsi);
  35. struct nsinfo *nsinfo__new(pid_t pid);
  36. struct nsinfo *nsinfo__copy(struct nsinfo *nsi);
  37. void nsinfo__delete(struct nsinfo *nsi);
  38. struct nsinfo *nsinfo__get(struct nsinfo *nsi);
  39. void nsinfo__put(struct nsinfo *nsi);
  40. void nsinfo__mountns_enter(struct nsinfo *nsi, struct nscookie *nc);
  41. void nsinfo__mountns_exit(struct nscookie *nc);
  42. char *nsinfo__realpath(const char *path, struct nsinfo *nsi);
  43. static inline void __nsinfo__zput(struct nsinfo **nsip)
  44. {
  45. if (nsip) {
  46. nsinfo__put(*nsip);
  47. *nsip = NULL;
  48. }
  49. }
  50. #define nsinfo__zput(nsi) __nsinfo__zput(&nsi)
  51. #endif /* __PERF_NAMESPACES_H */