nsproxy.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. /*
  10. * A structure to contain pointers to all per-process
  11. * namespaces - fs (mount), uts, network, sysvipc, etc.
  12. *
  13. * 'count' is the number of tasks holding a reference.
  14. * The count for each namespace, then, will be the number
  15. * of nsproxies pointing to it, not the number of tasks.
  16. *
  17. * The nsproxy is shared by tasks which share all namespaces.
  18. * As soon as a single namespace is cloned or unshared, the
  19. * nsproxy is copied.
  20. */
  21. struct nsproxy {
  22. atomic_t count;
  23. spinlock_t nslock;
  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. };
  29. extern struct nsproxy init_nsproxy;
  30. struct nsproxy *dup_namespaces(struct nsproxy *orig);
  31. int copy_namespaces(int flags, struct task_struct *tsk);
  32. void get_task_namespaces(struct task_struct *tsk);
  33. void free_nsproxy(struct nsproxy *ns);
  34. static inline void put_nsproxy(struct nsproxy *ns)
  35. {
  36. if (atomic_dec_and_test(&ns->count)) {
  37. free_nsproxy(ns);
  38. }
  39. }
  40. static inline void exit_task_namespaces(struct task_struct *p)
  41. {
  42. struct nsproxy *ns = p->nsproxy;
  43. if (ns) {
  44. task_lock(p);
  45. p->nsproxy = NULL;
  46. task_unlock(p);
  47. put_nsproxy(ns);
  48. }
  49. }
  50. #endif