nsproxy.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. struct nsproxy *put_nsproxy(struct nsproxy *ns);
  35. static inline void finalize_put_nsproxy(struct nsproxy *ns)
  36. {
  37. if (ns)
  38. free_nsproxy(ns);
  39. }
  40. static inline void put_and_finalize_nsproxy(struct nsproxy *ns)
  41. {
  42. finalize_put_nsproxy(put_nsproxy(ns));
  43. }
  44. static inline struct nsproxy *preexit_task_namespaces(struct task_struct *p)
  45. {
  46. return put_nsproxy(p->nsproxy);
  47. }
  48. static inline void exit_task_namespaces(struct task_struct *p,
  49. struct nsproxy *ns)
  50. {
  51. task_lock(p);
  52. p->nsproxy = NULL;
  53. task_unlock(p);
  54. finalize_put_nsproxy(ns);
  55. }
  56. #endif