nsproxy.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. struct uts_namespace *uts_ns;
  24. struct ipc_namespace *ipc_ns;
  25. struct mnt_namespace *mnt_ns;
  26. struct pid_namespace *pid_ns;
  27. struct user_namespace *user_ns;
  28. struct net *net_ns;
  29. };
  30. extern struct nsproxy init_nsproxy;
  31. int copy_namespaces(unsigned long flags, struct task_struct *tsk);
  32. void get_task_namespaces(struct task_struct *tsk);
  33. void free_nsproxy(struct nsproxy *ns);
  34. int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
  35. struct fs_struct *);
  36. static inline void put_nsproxy(struct nsproxy *ns)
  37. {
  38. if (atomic_dec_and_test(&ns->count)) {
  39. free_nsproxy(ns);
  40. }
  41. }
  42. static inline void exit_task_namespaces(struct task_struct *p)
  43. {
  44. struct nsproxy *ns = p->nsproxy;
  45. if (ns) {
  46. task_lock(p);
  47. p->nsproxy = NULL;
  48. task_unlock(p);
  49. put_nsproxy(ns);
  50. }
  51. }
  52. #endif