Lines Matching refs: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
72 * thus the curr ns.hname is a prefix of its name.
107 struct aa_ns *ns;
109 ns = kzalloc(sizeof(*ns), GFP_KERNEL);
110 AA_DEBUG("%s(%p)\n", __func__, ns);
111 if (!ns)
113 if (!aa_policy_init(&ns->base, prefix, name, GFP_KERNEL))
116 INIT_LIST_HEAD(&ns->sub_ns);
117 INIT_LIST_HEAD(&ns->rawdata_list);
118 mutex_init(&ns->lock);
119 init_waitqueue_head(&ns->wait);
122 ns->unconfined = alloc_unconfined("unconfined");
123 if (!ns->unconfined)
125 /* ns and ns->unconfined share ns->unconfined refcount */
126 ns->unconfined->ns = ns;
128 atomic_set(&ns->uniq_null, 0);
130 aa_labelset_init(&ns->labels);
132 return ns;
135 aa_policy_destroy(&ns->base);
137 kfree_sensitive(ns);
143 * @ns: the namespace to free (MAYBE NULL)
148 void aa_free_ns(struct aa_ns *ns)
150 if (!ns)
153 aa_policy_destroy(&ns->base);
154 aa_labelset_destroy(&ns->labels);
155 aa_put_ns(ns->parent);
157 ns->unconfined->ns = NULL;
158 aa_free_profile(ns->unconfined);
159 kfree_sensitive(ns);
175 struct aa_ns *ns = NULL;
178 ns = aa_get_ns(__aa_findn_ns(&root->sub_ns, name, n));
181 return ns;
202 * @hname: hierarchical ns name (NOT NULL)
207 * Returns: unrefcounted ns pointer or NULL if not found
213 struct aa_ns *ns = view;
218 ns = __aa_findn_ns(&ns->sub_ns, hname, split - hname);
219 if (!ns)
227 return __aa_findn_ns(&ns->sub_ns, hname, n);
244 struct aa_ns *ns = NULL;
247 ns = aa_get_ns(__aa_lookupn_ns(view, name, n));
250 return ns;
256 struct aa_ns *ns;
263 ns = alloc_ns(parent->base.hname, name);
264 if (!ns)
266 ns->level = parent->level + 1;
267 mutex_lock_nested(&ns->lock, ns->level);
268 error = __aafs_ns_mkdir(ns, ns_subns_dir(parent), name, dir);
270 AA_ERROR("Failed to create interface for ns %s\n",
271 ns->base.name);
272 mutex_unlock(&ns->lock);
273 aa_free_ns(ns);
276 ns->parent = aa_get_ns(parent);
277 list_add_rcu(&ns->base.list, &parent->sub_ns);
279 aa_get_ns(ns);
280 mutex_unlock(&ns->lock);
282 return 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;
300 /* try and find the specified ns */
302 ns = aa_get_ns(__aa_find_ns(&parent->sub_ns, name));
303 if (!ns)
304 ns = __aa_create_ns(parent, name, dir);
306 ns = ERR_PTR(-EEXIST);
309 return ns;
314 * @parent: ns to treat as parent
321 struct aa_ns *ns;
324 /* try and find the specified ns and if it doesn't exist create it */
326 ns = aa_get_ns(__aa_find_ns(&parent->sub_ns, name));
327 if (!ns)
328 ns = __aa_create_ns(parent, name, NULL);
332 return 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)
343 if (!ns)
346 mutex_lock_nested(&ns->lock, ns->level);
348 __aa_profile_list_release(&ns->base.profiles);
351 __ns_list_release(&ns->sub_ns);
353 if (ns->parent) {
356 write_lock_irqsave(&ns->labels.lock, flags);
357 __aa_proxy_redirect(ns_unconfined(ns),
358 ns_unconfined(ns->parent));
359 write_unlock_irqrestore(&ns->labels.lock, flags);
361 __aafs_ns_rmdir(ns);
362 mutex_unlock(&ns->lock);
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)
373 /* remove ns from namespace list */
374 list_del_rcu(&ns->base.list);
375 destroy_ns(ns);
376 aa_put_ns(ns);
387 struct aa_ns *ns, *tmp;
389 list_for_each_entry_safe(ns, tmp, head, base.list)
390 __aa_remove_ns(ns);
416 root_ns->unconfined->ns = aa_get_ns(root_ns);
426 struct aa_ns *ns = root_ns;
431 destroy_ns(ns);
432 aa_put_ns(ns);