Serge E. Hallyn | ab51601 | 2006-10-02 02:18:06 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_NSPROXY_H |
| 2 | #define _LINUX_NSPROXY_H |
| 3 | |
| 4 | #include <linux/spinlock.h> |
| 5 | #include <linux/sched.h> |
| 6 | |
Serge E. Hallyn | 1651e14 | 2006-10-02 02:18:08 -0700 | [diff] [blame] | 7 | struct namespace; |
Serge E. Hallyn | 4865ecf | 2006-10-02 02:18:14 -0700 | [diff] [blame^] | 8 | struct uts_namespace; |
Serge E. Hallyn | 1651e14 | 2006-10-02 02:18:08 -0700 | [diff] [blame] | 9 | |
Serge E. Hallyn | ab51601 | 2006-10-02 02:18:06 -0700 | [diff] [blame] | 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 | spinlock_t nslock; |
Serge E. Hallyn | 4865ecf | 2006-10-02 02:18:14 -0700 | [diff] [blame^] | 25 | struct uts_namespace *uts_ns; |
Serge E. Hallyn | 1651e14 | 2006-10-02 02:18:08 -0700 | [diff] [blame] | 26 | struct namespace *namespace; |
Serge E. Hallyn | ab51601 | 2006-10-02 02:18:06 -0700 | [diff] [blame] | 27 | }; |
| 28 | extern struct nsproxy init_nsproxy; |
| 29 | |
| 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 | |
| 35 | static inline void put_nsproxy(struct nsproxy *ns) |
| 36 | { |
| 37 | if (atomic_dec_and_test(&ns->count)) { |
| 38 | free_nsproxy(ns); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | static inline void exit_task_namespaces(struct task_struct *p) |
| 43 | { |
| 44 | struct nsproxy *ns = p->nsproxy; |
| 45 | if (ns) { |
| 46 | put_nsproxy(ns); |
| 47 | p->nsproxy = NULL; |
| 48 | } |
| 49 | } |
| 50 | #endif |