| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | 
|---|
| 2 | #ifndef _LINUX_NSTREE_H | 
|---|
| 3 | #define _LINUX_NSTREE_H | 
|---|
| 4 |  | 
|---|
| 5 | #include <linux/ns_common.h> | 
|---|
| 6 | #include <linux/nsproxy.h> | 
|---|
| 7 | #include <linux/rbtree.h> | 
|---|
| 8 | #include <linux/seqlock.h> | 
|---|
| 9 | #include <linux/rculist.h> | 
|---|
| 10 | #include <linux/cookie.h> | 
|---|
| 11 |  | 
|---|
| 12 | extern struct ns_tree cgroup_ns_tree; | 
|---|
| 13 | extern struct ns_tree ipc_ns_tree; | 
|---|
| 14 | extern struct ns_tree mnt_ns_tree; | 
|---|
| 15 | extern struct ns_tree net_ns_tree; | 
|---|
| 16 | extern struct ns_tree pid_ns_tree; | 
|---|
| 17 | extern struct ns_tree time_ns_tree; | 
|---|
| 18 | extern struct ns_tree user_ns_tree; | 
|---|
| 19 | extern struct ns_tree uts_ns_tree; | 
|---|
| 20 |  | 
|---|
| 21 | #define to_ns_tree(__ns)					\ | 
|---|
| 22 | _Generic((__ns),					\ | 
|---|
| 23 | struct cgroup_namespace *: &(cgroup_ns_tree),	\ | 
|---|
| 24 | struct ipc_namespace *:    &(ipc_ns_tree),	\ | 
|---|
| 25 | struct net *:              &(net_ns_tree),	\ | 
|---|
| 26 | struct pid_namespace *:    &(pid_ns_tree),	\ | 
|---|
| 27 | struct mnt_namespace *:    &(mnt_ns_tree),	\ | 
|---|
| 28 | struct time_namespace *:   &(time_ns_tree),	\ | 
|---|
| 29 | struct user_namespace *:   &(user_ns_tree),	\ | 
|---|
| 30 | struct uts_namespace *:    &(uts_ns_tree)) | 
|---|
| 31 |  | 
|---|
| 32 | u64 ns_tree_gen_id(struct ns_common *ns); | 
|---|
| 33 | void __ns_tree_add_raw(struct ns_common *ns, struct ns_tree *ns_tree); | 
|---|
| 34 | void __ns_tree_remove(struct ns_common *ns, struct ns_tree *ns_tree); | 
|---|
| 35 | struct ns_common *ns_tree_lookup_rcu(u64 ns_id, int ns_type); | 
|---|
| 36 | struct ns_common *__ns_tree_adjoined_rcu(struct ns_common *ns, | 
|---|
| 37 | struct ns_tree *ns_tree, | 
|---|
| 38 | bool previous); | 
|---|
| 39 |  | 
|---|
| 40 | static inline void __ns_tree_add(struct ns_common *ns, struct ns_tree *ns_tree) | 
|---|
| 41 | { | 
|---|
| 42 | ns_tree_gen_id(ns); | 
|---|
| 43 | __ns_tree_add_raw(ns, ns_tree); | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | /** | 
|---|
| 47 | * ns_tree_add_raw - Add a namespace to a namespace | 
|---|
| 48 | * @ns: Namespace to add | 
|---|
| 49 | * | 
|---|
| 50 | * This function adds a namespace to the appropriate namespace tree | 
|---|
| 51 | * without assigning a id. | 
|---|
| 52 | */ | 
|---|
| 53 | #define ns_tree_add_raw(__ns) __ns_tree_add_raw(to_ns_common(__ns), to_ns_tree(__ns)) | 
|---|
| 54 |  | 
|---|
| 55 | /** | 
|---|
| 56 | * ns_tree_add - Add a namespace to a namespace tree | 
|---|
| 57 | * @ns: Namespace to add | 
|---|
| 58 | * | 
|---|
| 59 | * This function assigns a new id to the namespace and adds it to the | 
|---|
| 60 | * appropriate namespace tree and list. | 
|---|
| 61 | */ | 
|---|
| 62 | #define ns_tree_add(__ns) __ns_tree_add(to_ns_common(__ns), to_ns_tree(__ns)) | 
|---|
| 63 |  | 
|---|
| 64 | /** | 
|---|
| 65 | * ns_tree_remove - Remove a namespace from a namespace tree | 
|---|
| 66 | * @ns: Namespace to remove | 
|---|
| 67 | * | 
|---|
| 68 | * This function removes a namespace from the appropriate namespace | 
|---|
| 69 | * tree and list. | 
|---|
| 70 | */ | 
|---|
| 71 | #define ns_tree_remove(__ns)  __ns_tree_remove(to_ns_common(__ns), to_ns_tree(__ns)) | 
|---|
| 72 |  | 
|---|
| 73 | #define ns_tree_adjoined_rcu(__ns, __previous) \ | 
|---|
| 74 | __ns_tree_adjoined_rcu(to_ns_common(__ns), to_ns_tree(__ns), __previous) | 
|---|
| 75 |  | 
|---|
| 76 | #define ns_tree_active(__ns) (!RB_EMPTY_NODE(&to_ns_common(__ns)->ns_tree_node)) | 
|---|
| 77 |  | 
|---|
| 78 | #endif /* _LINUX_NSTREE_H */ | 
|---|
| 79 |  | 
|---|