]> bbs.cooldavid.org Git - net-next-2.6.git/blame - kernel/utsname.c
xps: Transmit Packet Steering
[net-next-2.6.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>
467e9f4b 15#include <linux/err.h>
1aeb272c 16#include <linux/slab.h>
4865ecf1 17
4c2a7e72
AD
18static struct uts_namespace *create_uts_ns(void)
19{
20 struct uts_namespace *uts_ns;
21
22 uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
23 if (uts_ns)
24 kref_init(&uts_ns->kref);
25 return uts_ns;
26}
27
071df104
SH
28/*
29 * Clone a new ns copying an original utsname, setting refcount to 1
30 * @old_ns: namespace to clone
31 * Return NULL on error (failure to kmalloc), new ns otherwise
32 */
33static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns)
34{
35 struct uts_namespace *ns;
36
4c2a7e72 37 ns = create_uts_ns();
467e9f4b
CLG
38 if (!ns)
39 return ERR_PTR(-ENOMEM);
40
efc63c4f 41 down_read(&uts_sem);
467e9f4b 42 memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
efc63c4f 43 up_read(&uts_sem);
071df104
SH
44 return ns;
45}
46
4865ecf1
SH
47/*
48 * Copy task tsk's utsname namespace, or clone it if flags
49 * specifies CLONE_NEWUTS. In latter case, changes to the
50 * utsname of this process won't be seen by parent, and vice
51 * versa.
52 */
213dd266 53struct uts_namespace *copy_utsname(unsigned long flags, struct uts_namespace *old_ns)
4865ecf1 54{
071df104 55 struct uts_namespace *new_ns;
4865ecf1 56
e3222c4e 57 BUG_ON(!old_ns);
4865ecf1
SH
58 get_uts_ns(old_ns);
59
071df104 60 if (!(flags & CLONE_NEWUTS))
e3222c4e 61 return old_ns;
071df104
SH
62
63 new_ns = clone_uts_ns(old_ns);
071df104 64
071df104 65 put_uts_ns(old_ns);
e3222c4e 66 return new_ns;
4865ecf1
SH
67}
68
69void free_uts_ns(struct kref *kref)
70{
71 struct uts_namespace *ns;
72
73 ns = container_of(kref, struct uts_namespace, kref);
74 kfree(ns);
75}