Lines Matching full:ns

57  * aa_ns_name - Find the ns name to display for @view from @curr
71 /* at this point if a ns is visible it is in a view ns in aa_ns_name()
72 * thus the curr ns.hname is a prefix of its name. in aa_ns_name()
107 struct aa_ns *ns; in alloc_ns() local
109 ns = kzalloc(sizeof(*ns), GFP_KERNEL); in alloc_ns()
110 AA_DEBUG("%s(%p)\n", __func__, ns); in alloc_ns()
111 if (!ns) in alloc_ns()
113 if (!aa_policy_init(&ns->base, prefix, name, GFP_KERNEL)) in alloc_ns()
116 INIT_LIST_HEAD(&ns->sub_ns); in alloc_ns()
117 INIT_LIST_HEAD(&ns->rawdata_list); in alloc_ns()
118 mutex_init(&ns->lock); in alloc_ns()
119 init_waitqueue_head(&ns->wait); in alloc_ns()
122 ns->unconfined = alloc_unconfined("unconfined"); in alloc_ns()
123 if (!ns->unconfined) in alloc_ns()
125 /* ns and ns->unconfined share ns->unconfined refcount */ in alloc_ns()
126 ns->unconfined->ns = ns; in alloc_ns()
128 atomic_set(&ns->uniq_null, 0); in alloc_ns()
130 aa_labelset_init(&ns->labels); in alloc_ns()
132 return ns; in alloc_ns()
135 aa_policy_destroy(&ns->base); in alloc_ns()
137 kfree_sensitive(ns); in alloc_ns()
143 * @ns: the namespace to free (MAYBE NULL)
148 void aa_free_ns(struct aa_ns *ns) in aa_free_ns() argument
150 if (!ns) in aa_free_ns()
153 aa_policy_destroy(&ns->base); in aa_free_ns()
154 aa_labelset_destroy(&ns->labels); in aa_free_ns()
155 aa_put_ns(ns->parent); in aa_free_ns()
157 ns->unconfined->ns = NULL; in aa_free_ns()
158 aa_free_profile(ns->unconfined); in aa_free_ns()
159 kfree_sensitive(ns); in aa_free_ns()
165 * @hname: hierarchical ns name (NOT NULL)
170 * Returns: unrefcounted ns pointer or NULL if not found
176 struct aa_ns *ns = view; in __aa_lookupn_ns() local
181 ns = __aa_findn_ns(&ns->sub_ns, hname, split - hname); in __aa_lookupn_ns()
182 if (!ns) in __aa_lookupn_ns()
190 return __aa_findn_ns(&ns->sub_ns, hname, n); in __aa_lookupn_ns()
207 struct aa_ns *ns = NULL; in aa_lookupn_ns() local
210 ns = aa_get_ns(__aa_lookupn_ns(view, name, n)); in aa_lookupn_ns()
213 return ns; in aa_lookupn_ns()
219 struct aa_ns *ns; in __aa_create_ns() local
226 ns = alloc_ns(parent->base.hname, name); in __aa_create_ns()
227 if (!ns) in __aa_create_ns()
229 ns->level = parent->level + 1; in __aa_create_ns()
230 mutex_lock_nested(&ns->lock, ns->level); in __aa_create_ns()
231 error = __aafs_ns_mkdir(ns, ns_subns_dir(parent), name, dir); in __aa_create_ns()
233 AA_ERROR("Failed to create interface for ns %s\n", in __aa_create_ns()
234 ns->base.name); in __aa_create_ns()
235 mutex_unlock(&ns->lock); in __aa_create_ns()
236 aa_free_ns(ns); in __aa_create_ns()
239 ns->parent = aa_get_ns(parent); in __aa_create_ns()
240 list_add_rcu(&ns->base.list, &parent->sub_ns); in __aa_create_ns()
242 aa_get_ns(ns); in __aa_create_ns()
243 mutex_unlock(&ns->lock); in __aa_create_ns()
245 return ns; in __aa_create_ns()
249 * __aa_find_or_create_ns - create an ns, fail if it already exists
252 * @dir: if not null the dir to put the ns entries in
254 * Returns: the a refcounted ns that has been add or an ERR_PTR
259 struct aa_ns *ns; in __aa_find_or_create_ns() local
263 /* try and find the specified ns */ in __aa_find_or_create_ns()
265 ns = aa_get_ns(__aa_find_ns(&parent->sub_ns, name)); in __aa_find_or_create_ns()
266 if (!ns) in __aa_find_or_create_ns()
267 ns = __aa_create_ns(parent, name, dir); in __aa_find_or_create_ns()
269 ns = ERR_PTR(-EEXIST); in __aa_find_or_create_ns()
272 return ns; in __aa_find_or_create_ns()
277 * @parent: ns to treat as parent
284 struct aa_ns *ns; in aa_prepare_ns() local
287 /* try and find the specified ns and if it doesn't exist create it */ in aa_prepare_ns()
289 ns = aa_get_ns(__aa_find_ns(&parent->sub_ns, name)); in aa_prepare_ns()
290 if (!ns) in aa_prepare_ns()
291 ns = __aa_create_ns(parent, name, NULL); in aa_prepare_ns()
295 return ns; in aa_prepare_ns()
301 * destroy_ns - remove everything contained by @ns
302 * @ns: namespace to have it contents removed (NOT NULL)
304 static void destroy_ns(struct aa_ns *ns) in destroy_ns() argument
306 if (!ns) in destroy_ns()
309 mutex_lock_nested(&ns->lock, ns->level); in destroy_ns()
311 __aa_profile_list_release(&ns->base.profiles); in destroy_ns()
314 __ns_list_release(&ns->sub_ns); in destroy_ns()
316 if (ns->parent) { in destroy_ns()
319 write_lock_irqsave(&ns->labels.lock, flags); in destroy_ns()
320 __aa_proxy_redirect(ns_unconfined(ns), in destroy_ns()
321 ns_unconfined(ns->parent)); in destroy_ns()
322 write_unlock_irqrestore(&ns->labels.lock, flags); in destroy_ns()
324 __aafs_ns_rmdir(ns); in destroy_ns()
325 mutex_unlock(&ns->lock); in destroy_ns()
330 * @ns: namespace to be removed (NOT NULL)
332 * Requires: ns->parent->lock be held and ns removed from parent.
334 void __aa_remove_ns(struct aa_ns *ns) in __aa_remove_ns() argument
336 /* remove ns from namespace list */ in __aa_remove_ns()
337 list_del_rcu(&ns->base.list); in __aa_remove_ns()
338 destroy_ns(ns); in __aa_remove_ns()
339 aa_put_ns(ns); in __aa_remove_ns()
350 struct aa_ns *ns, *tmp; in __ns_list_release() local
352 list_for_each_entry_safe(ns, tmp, head, base.list) in __ns_list_release()
353 __aa_remove_ns(ns); in __ns_list_release()
379 root_ns->unconfined->ns = aa_get_ns(root_ns); in aa_alloc_root_ns()
389 struct aa_ns *ns = root_ns; in aa_free_root_ns() local
394 destroy_ns(ns); in aa_free_root_ns()
395 aa_put_ns(ns); in aa_free_root_ns()