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()
175 struct aa_ns *ns = NULL; in aa_findn_ns() local
178 ns = aa_get_ns(__aa_findn_ns(&root->sub_ns, name, n)); in aa_findn_ns()
181 return ns; in aa_findn_ns()
202 * @hname: hierarchical ns name (NOT NULL)
207 * Returns: unrefcounted ns pointer or NULL if not found
213 struct aa_ns *ns = view; in __aa_lookupn_ns() local
218 ns = __aa_findn_ns(&ns->sub_ns, hname, split - hname); in __aa_lookupn_ns()
219 if (!ns) in __aa_lookupn_ns()
227 return __aa_findn_ns(&ns->sub_ns, hname, n); in __aa_lookupn_ns()
244 struct aa_ns *ns = NULL; in aa_lookupn_ns() local
247 ns = aa_get_ns(__aa_lookupn_ns(view, name, n)); in aa_lookupn_ns()
250 return ns; in aa_lookupn_ns()
256 struct aa_ns *ns; in __aa_create_ns() local
263 ns = alloc_ns(parent->base.hname, name); in __aa_create_ns()
264 if (!ns) in __aa_create_ns()
266 ns->level = parent->level + 1; in __aa_create_ns()
267 mutex_lock_nested(&ns->lock, ns->level); in __aa_create_ns()
268 error = __aafs_ns_mkdir(ns, ns_subns_dir(parent), name, dir); in __aa_create_ns()
270 AA_ERROR("Failed to create interface for ns %s\n", in __aa_create_ns()
271 ns->base.name); in __aa_create_ns()
272 mutex_unlock(&ns->lock); in __aa_create_ns()
273 aa_free_ns(ns); in __aa_create_ns()
276 ns->parent = aa_get_ns(parent); in __aa_create_ns()
277 list_add_rcu(&ns->base.list, &parent->sub_ns); in __aa_create_ns()
279 aa_get_ns(ns); in __aa_create_ns()
280 mutex_unlock(&ns->lock); in __aa_create_ns()
282 return ns; in __aa_create_ns()
286 * __aa_find_or_create_ns - create an ns, fail if it already exists
289 * @dir: if not null the dir to put the ns entries in
291 * Returns: the a refcounted ns that has been add or an ERR_PTR
296 struct aa_ns *ns; in __aa_find_or_create_ns() local
300 /* try and find the specified ns */ in __aa_find_or_create_ns()
302 ns = aa_get_ns(__aa_find_ns(&parent->sub_ns, name)); in __aa_find_or_create_ns()
303 if (!ns) in __aa_find_or_create_ns()
304 ns = __aa_create_ns(parent, name, dir); in __aa_find_or_create_ns()
306 ns = ERR_PTR(-EEXIST); in __aa_find_or_create_ns()
309 return ns; in __aa_find_or_create_ns()
314 * @parent: ns to treat as parent
321 struct aa_ns *ns; in aa_prepare_ns() local
324 /* try and find the specified ns and if it doesn't exist create it */ in aa_prepare_ns()
326 ns = aa_get_ns(__aa_find_ns(&parent->sub_ns, name)); in aa_prepare_ns()
327 if (!ns) in aa_prepare_ns()
328 ns = __aa_create_ns(parent, name, NULL); in aa_prepare_ns()
332 return ns; in aa_prepare_ns()
338 * destroy_ns - remove everything contained by @ns
339 * @ns: namespace to have it contents removed (NOT NULL)
341 static void destroy_ns(struct aa_ns *ns) in destroy_ns() argument
343 if (!ns) in destroy_ns()
346 mutex_lock_nested(&ns->lock, ns->level); in destroy_ns()
348 __aa_profile_list_release(&ns->base.profiles); in destroy_ns()
351 __ns_list_release(&ns->sub_ns); in destroy_ns()
353 if (ns->parent) { in destroy_ns()
356 write_lock_irqsave(&ns->labels.lock, flags); in destroy_ns()
357 __aa_proxy_redirect(ns_unconfined(ns), in destroy_ns()
358 ns_unconfined(ns->parent)); in destroy_ns()
359 write_unlock_irqrestore(&ns->labels.lock, flags); in destroy_ns()
361 __aafs_ns_rmdir(ns); in destroy_ns()
362 mutex_unlock(&ns->lock); in destroy_ns()
367 * @ns: namespace to be removed (NOT NULL)
369 * Requires: ns->parent->lock be held and ns removed from parent.
371 void __aa_remove_ns(struct aa_ns *ns) in __aa_remove_ns() argument
373 /* remove ns from namespace list */ in __aa_remove_ns()
374 list_del_rcu(&ns->base.list); in __aa_remove_ns()
375 destroy_ns(ns); in __aa_remove_ns()
376 aa_put_ns(ns); in __aa_remove_ns()
387 struct aa_ns *ns, *tmp; in __ns_list_release() local
389 list_for_each_entry_safe(ns, tmp, head, base.list) in __ns_list_release()
390 __aa_remove_ns(ns); in __ns_list_release()
416 root_ns->unconfined->ns = aa_get_ns(root_ns); in aa_alloc_root_ns()
426 struct aa_ns *ns = root_ns; in aa_free_root_ns() local
431 destroy_ns(ns); in aa_free_root_ns()
432 aa_put_ns(ns); in aa_free_root_ns()