nsproxy.h 1.3 KB

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