nsproxy.h 2.2 KB

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