blob: 7ebe66670c592d64cba6b829ce42307b141e44cb [file] [log] [blame]
Serge E. Hallynab516012006-10-02 02:18:06 -07001#ifndef _LINUX_NSPROXY_H
2#define _LINUX_NSPROXY_H
3
4#include <linux/spinlock.h>
5#include <linux/sched.h>
6
Serge E. Hallyn1651e142006-10-02 02:18:08 -07007struct namespace;
8
Serge E. Hallynab516012006-10-02 02:18:06 -07009/*
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 */
21struct nsproxy {
22 atomic_t count;
23 spinlock_t nslock;
Serge E. Hallyn1651e142006-10-02 02:18:08 -070024 struct namespace *namespace;
Serge E. Hallynab516012006-10-02 02:18:06 -070025};
26extern struct nsproxy init_nsproxy;
27
28struct nsproxy *dup_namespaces(struct nsproxy *orig);
29int copy_namespaces(int flags, struct task_struct *tsk);
30void get_task_namespaces(struct task_struct *tsk);
31void free_nsproxy(struct nsproxy *ns);
32
33static inline void put_nsproxy(struct nsproxy *ns)
34{
35 if (atomic_dec_and_test(&ns->count)) {
36 free_nsproxy(ns);
37 }
38}
39
40static inline void exit_task_namespaces(struct task_struct *p)
41{
42 struct nsproxy *ns = p->nsproxy;
43 if (ns) {
44 put_nsproxy(ns);
45 p->nsproxy = NULL;
46 }
47}
48#endif