lockdep: map_acquire
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / kernel / utsname.c
CommitLineData
4865ecf1
SH
1/*
2 * Copyright (C) 2004 IBM Corporation
3 *
4 * Author: Serge Hallyn <serue@us.ibm.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2 of the
9 * License.
10 */
11
12#include <linux/module.h>
13#include <linux/uts.h>
14#include <linux/utsname.h>
15#include <linux/version.h>
467e9f4b 16#include <linux/err.h>
1aeb272c 17#include <linux/slab.h>
4865ecf1 18
071df104
SH
19/*
20 * Clone a new ns copying an original utsname, setting refcount to 1
21 * @old_ns: namespace to clone
22 * Return NULL on error (failure to kmalloc), new ns otherwise
23 */
24static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns)
25{
26 struct uts_namespace *ns;
27
28 ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
467e9f4b
CLG
29 if (!ns)
30 return ERR_PTR(-ENOMEM);
31
efc63c4f 32 down_read(&uts_sem);
467e9f4b 33 memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
efc63c4f 34 up_read(&uts_sem);
467e9f4b 35 kref_init(&ns->kref);
071df104
SH
36 return ns;
37}
38
4865ecf1
SH
39/*
40 * Copy task tsk's utsname namespace, or clone it if flags
41 * specifies CLONE_NEWUTS. In latter case, changes to the
42 * utsname of this process won't be seen by parent, and vice
43 * versa.
44 */
213dd266 45struct uts_namespace *copy_utsname(unsigned long flags, struct uts_namespace *old_ns)
4865ecf1 46{
071df104 47 struct uts_namespace *new_ns;
4865ecf1 48
e3222c4e 49 BUG_ON(!old_ns);
4865ecf1
SH
50 get_uts_ns(old_ns);
51
071df104 52 if (!(flags & CLONE_NEWUTS))
e3222c4e 53 return old_ns;
071df104
SH
54
55 new_ns = clone_uts_ns(old_ns);
071df104 56
071df104 57 put_uts_ns(old_ns);
e3222c4e 58 return new_ns;
4865ecf1
SH
59}
60
61void free_uts_ns(struct kref *kref)
62{
63 struct uts_namespace *ns;
64
65 ns = container_of(kref, struct uts_namespace, kref);
66 kfree(ns);
67}