blob: 9c2e0ad508dbf455483cfa9c2fb8512e2c0f7e5b [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;
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -07008struct uts_namespace;
Serge E. Hallyn1651e142006-10-02 02:18:08 -07009
Serge E. Hallynab516012006-10-02 02:18:06 -070010/*
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 */
22struct nsproxy {
23 atomic_t count;
24 spinlock_t nslock;
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070025 struct uts_namespace *uts_ns;
Serge E. Hallyn1651e142006-10-02 02:18:08 -070026 struct namespace *namespace;
Serge E. Hallynab516012006-10-02 02:18:06 -070027};
28extern struct nsproxy init_nsproxy;
29
30struct nsproxy *dup_namespaces(struct nsproxy *orig);
31int copy_namespaces(int flags, struct task_struct *tsk);
32void get_task_namespaces(struct task_struct *tsk);
33void free_nsproxy(struct nsproxy *ns);
34
35static inline void put_nsproxy(struct nsproxy *ns)
36{
37 if (atomic_dec_and_test(&ns->count)) {
38 free_nsproxy(ns);
39 }
40}
41
42static 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