pid_namespace.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #ifndef _LINUX_PID_NS_H
  2. #define _LINUX_PID_NS_H
  3. #include <linux/sched.h>
  4. #include <linux/bug.h>
  5. #include <linux/mm.h>
  6. #include <linux/threads.h>
  7. #include <linux/nsproxy.h>
  8. #include <linux/kref.h>
  9. struct pidmap {
  10. atomic_t nr_free;
  11. void *page;
  12. };
  13. #define PIDMAP_ENTRIES ((PID_MAX_LIMIT + 8*PAGE_SIZE - 1)/PAGE_SIZE/8)
  14. struct bsd_acct_struct;
  15. struct pid_namespace {
  16. struct kref kref;
  17. struct pidmap pidmap[PIDMAP_ENTRIES];
  18. int last_pid;
  19. struct task_struct *child_reaper;
  20. struct kmem_cache *pid_cachep;
  21. unsigned int level;
  22. struct pid_namespace *parent;
  23. #ifdef CONFIG_PROC_FS
  24. struct vfsmount *proc_mnt;
  25. #endif
  26. #ifdef CONFIG_BSD_PROCESS_ACCT
  27. struct bsd_acct_struct *bacct;
  28. #endif
  29. gid_t pid_gid;
  30. int hide_pid;
  31. int reboot; /* group exit code if this pidns was rebooted */
  32. };
  33. extern struct pid_namespace init_pid_ns;
  34. #ifdef CONFIG_PID_NS
  35. static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
  36. {
  37. if (ns != &init_pid_ns)
  38. kref_get(&ns->kref);
  39. return ns;
  40. }
  41. extern struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *ns);
  42. extern void free_pid_ns(struct kref *kref);
  43. extern void zap_pid_ns_processes(struct pid_namespace *pid_ns);
  44. extern int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd);
  45. static inline void put_pid_ns(struct pid_namespace *ns)
  46. {
  47. if (ns != &init_pid_ns)
  48. kref_put(&ns->kref, free_pid_ns);
  49. }
  50. #else /* !CONFIG_PID_NS */
  51. #include <linux/err.h>
  52. static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
  53. {
  54. return ns;
  55. }
  56. static inline struct pid_namespace *
  57. copy_pid_ns(unsigned long flags, struct pid_namespace *ns)
  58. {
  59. if (flags & CLONE_NEWPID)
  60. ns = ERR_PTR(-EINVAL);
  61. return ns;
  62. }
  63. static inline void put_pid_ns(struct pid_namespace *ns)
  64. {
  65. }
  66. static inline void zap_pid_ns_processes(struct pid_namespace *ns)
  67. {
  68. BUG();
  69. }
  70. static inline int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
  71. {
  72. return 0;
  73. }
  74. #endif /* CONFIG_PID_NS */
  75. extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk);
  76. void pidhash_init(void);
  77. void pidmap_init(void);
  78. #endif /* _LINUX_PID_NS_H */