blob: cc4f45361dbbc8a956f9a9fad2a865dc7f4add33 [file] [log] [blame]
Cedric Le Goateracce2922007-07-15 23:40:59 -07001#ifndef _LINUX_USER_NAMESPACE_H
2#define _LINUX_USER_NAMESPACE_H
3
4#include <linux/kref.h>
5#include <linux/nsproxy.h>
6#include <linux/sched.h>
Serge E. Hallyn77ec7392007-07-15 23:41:01 -07007#include <linux/err.h>
Cedric Le Goateracce2922007-07-15 23:40:59 -07008
9#define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 8)
10#define UIDHASH_SZ (1 << UIDHASH_BITS)
11
12struct user_namespace {
13 struct kref kref;
Pavel Emelyanov735de222007-09-18 22:46:44 -070014 struct hlist_head uidhash_table[UIDHASH_SZ];
Serge Hallyn18b6e042008-10-15 16:38:45 -050015 struct user_struct *creator;
David Howells51708362009-02-27 14:03:03 -080016 struct work_struct destroyer;
Cedric Le Goateracce2922007-07-15 23:40:59 -070017};
18
19extern struct user_namespace init_user_ns;
20
21#ifdef CONFIG_USER_NS
22
23static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
24{
25 if (ns)
26 kref_get(&ns->kref);
27 return ns;
28}
29
Serge Hallyn18b6e042008-10-15 16:38:45 -050030extern int create_user_ns(struct cred *new);
Cedric Le Goateracce2922007-07-15 23:40:59 -070031extern void free_user_ns(struct kref *kref);
32
33static inline void put_user_ns(struct user_namespace *ns)
34{
35 if (ns)
36 kref_put(&ns->kref, free_user_ns);
37}
38
39#else
40
41static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
42{
43 return &init_user_ns;
44}
45
Serge Hallyn18b6e042008-10-15 16:38:45 -050046static inline int create_user_ns(struct cred *new)
Cedric Le Goateracce2922007-07-15 23:40:59 -070047{
Serge Hallyn18b6e042008-10-15 16:38:45 -050048 return -EINVAL;
Cedric Le Goateracce2922007-07-15 23:40:59 -070049}
50
51static inline void put_user_ns(struct user_namespace *ns)
52{
53}
54
55#endif
56
57#endif /* _LINUX_USER_H */