1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (c) 2025 Christian Brauner <brauner@kernel.org> */ 3 #ifndef _LINUX_NSTREE_TYPES_H 4 #define _LINUX_NSTREE_TYPES_H 5 6 #include <linux/rbtree.h> 7 #include <linux/list.h> 8 9 /** 10 * struct ns_tree_root - Root of a namespace tree 11 * @ns_rb: Red-black tree root for efficient lookups 12 * @ns_list_head: List head for sequential iteration 13 * 14 * Each namespace tree maintains both an rbtree (for O(log n) lookups) 15 * and a list (for efficient sequential iteration). The list is kept in 16 * the same sorted order as the rbtree. 17 */ 18 struct ns_tree_root { 19 struct rb_root ns_rb; 20 struct list_head ns_list_head; 21 }; 22 23 /** 24 * struct ns_tree_node - Node in a namespace tree 25 * @ns_node: Red-black tree node 26 * @ns_list_entry: List entry for sequential iteration 27 * 28 * Represents a namespace's position in a tree. Each namespace has 29 * multiple tree nodes for different trees (unified, per-type, owner). 30 */ 31 struct ns_tree_node { 32 struct rb_node ns_node; 33 struct list_head ns_list_entry; 34 }; 35 36 /** 37 * struct ns_tree - Namespace tree nodes and active reference count 38 * @ns_id: Unique namespace identifier 39 * @__ns_ref_active: Active reference count (do not use directly) 40 * @ns_unified_node: Node in the global namespace tree 41 * @ns_tree_node: Node in the per-type namespace tree 42 * @ns_owner_node: Node in the owner namespace's tree of owned namespaces 43 * @ns_owner_root: Root of the tree of namespaces owned by this namespace 44 * (only used when this namespace is an owner) 45 */ 46 struct ns_tree { 47 u64 ns_id; 48 atomic_t __ns_ref_active; 49 struct ns_tree_node ns_unified_node; 50 struct ns_tree_node ns_tree_node; 51 struct ns_tree_node ns_owner_node; 52 struct ns_tree_root ns_owner_root; 53 }; 54 55 #endif /* _LINUX_NSTREE_TYPES_H */ 56