nsproxy.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef _LINUX_NSPROXY_H
  2. #define _LINUX_NSPROXY_H
  3. #include <linux/spinlock.h>
  4. #include <linux/sched.h>
  5. struct mnt_namespace;
  6. struct uts_namespace;
  7. struct ipc_namespace;
  8. struct pid_namespace;
  9. struct cgroup_namespace;
  10. struct fs_struct;
  11. /*
  12. * A structure to contain pointers to all per-process
  13. * namespaces - fs (mount), uts, network, sysvipc, etc.
  14. *
  15. * The pid namespace is an exception -- it's accessed using
  16. * task_active_pid_ns. The pid namespace here is the
  17. * namespace that children will use.
  18. *
  19. * 'count' is the number of tasks holding a reference.
  20. * The count for each namespace, then, will be the number
  21. * of nsproxies pointing to it, not the number of tasks.
  22. *
  23. * The nsproxy is shared by tasks which share all namespaces.
  24. * As soon as a single namespace is cloned or unshared, the
  25. * nsproxy is copied.
  26. */
  27. struct nsproxy {
  28. atomic_t count;
  29. struct uts_namespace *uts_ns;
  30. struct ipc_namespace *ipc_ns;
  31. struct mnt_namespace *mnt_ns;
  32. struct pid_namespace *pid_ns_for_children;
  33. struct net *net_ns;
  34. struct cgroup_namespace *cgroup_ns;
  35. };
  36. extern struct nsproxy init_nsproxy;
  37. /*
  38. * the namespaces access rules are:
  39. *
  40. * 1. only current task is allowed to change tsk->nsproxy pointer or
  41. * any pointer on the nsproxy itself. Current must hold the task_lock
  42. * when changing tsk->nsproxy.
  43. *
  44. * 2. when accessing (i.e. reading) current task's namespaces - no
  45. * precautions should be taken - just dereference the pointers
  46. *
  47. * 3. the access to other task namespaces is performed like this
  48. * task_lock(task);
  49. * nsproxy = task->nsproxy;
  50. * if (nsproxy != NULL) {
  51. * / *
  52. * * work with the namespaces here
  53. * * e.g. get the reference on one of them
  54. * * /
  55. * } / *
  56. * * NULL task->nsproxy means that this task is
  57. * * almost dead (zombie)
  58. * * /
  59. * task_unlock(task);
  60. *
  61. */
  62. int copy_namespaces(unsigned long flags, struct task_struct *tsk);
  63. void exit_task_namespaces(struct task_struct *tsk);
  64. void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
  65. void free_nsproxy(struct nsproxy *ns);
  66. int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
  67. struct cred *, struct fs_struct *);
  68. int __init nsproxy_cache_init(void);
  69. static inline void put_nsproxy(struct nsproxy *ns)
  70. {
  71. if (atomic_dec_and_test(&ns->count)) {
  72. free_nsproxy(ns);
  73. }
  74. }
  75. static inline void get_nsproxy(struct nsproxy *ns)
  76. {
  77. atomic_inc(&ns->count);
  78. }
  79. #endif