aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2009-04-30 09:23:42 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-09-15 12:50:49 -0400
commit2b2af54a5bb6f7e80ccf78f20084b93c398c3a8b (patch)
treebb27e3b16a2a8fadeea869033a406f0a19b63e29
parentea5ffff57dce2f4c85ab056f4b0a202f71db2bdf (diff)
Driver Core: devtmpfs - kernel-maintained tmpfs-based /dev
Devtmpfs lets the kernel create a tmpfs instance called devtmpfs very early at kernel initialization, before any driver-core device is registered. Every device with a major/minor will provide a device node in devtmpfs. Devtmpfs can be changed and altered by userspace at any time, and in any way needed - just like today's udev-mounted tmpfs. Unmodified udev versions will run just fine on top of it, and will recognize an already existing kernel-created device node and use it. The default node permissions are root:root 0600. Proper permissions and user/group ownership, meaningful symlinks, all other policy still needs to be applied by userspace. If a node is created by devtmps, devtmpfs will remove the device node when the device goes away. If the device node was created by userspace, or the devtmpfs created node was replaced by userspace, it will no longer be removed by devtmpfs. If it is requested to auto-mount it, it makes init=/bin/sh work without any further userspace support. /dev will be fully populated and dynamic, and always reflect the current device state of the kernel. With the commonly used dynamic device numbers, it solves the problem where static devices nodes may point to the wrong devices. It is intended to make the initial bootup logic simpler and more robust, by de-coupling the creation of the inital environment, to reliably run userspace processes, from a complex userspace bootstrap logic to provide a working /dev. Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Jan Blunck <jblunck@suse.de> Tested-By: Harald Hoyer <harald@redhat.com> Tested-By: Scott James Remnant <scott@ubuntu.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/base/Kconfig25
-rw-r--r--drivers/base/Makefile1
-rw-r--r--drivers/base/base.h6
-rw-r--r--drivers/base/core.c3
-rw-r--r--drivers/base/devtmpfs.c367
-rw-r--r--drivers/base/init.c1
-rw-r--r--include/linux/device.h10
-rw-r--r--include/linux/shmem_fs.h3
-rw-r--r--init/do_mounts.c2
-rw-r--r--init/main.c2
-rw-r--r--mm/shmem.c9
11 files changed, 422 insertions, 7 deletions
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index 8f006f96ff53..ee377270beb9 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -8,6 +8,31 @@ config UEVENT_HELPER_PATH
8 Path to uevent helper program forked by the kernel for 8 Path to uevent helper program forked by the kernel for
9 every uevent. 9 every uevent.
10 10
11config DEVTMPFS
12 bool "Create a kernel maintained /dev tmpfs (EXPERIMENTAL)"
13 depends on HOTPLUG && SHMEM && TMPFS
14 help
15 This creates a tmpfs filesystem, and mounts it at bootup
16 and mounts it at /dev. The kernel driver core creates device
17 nodes for all registered devices in that filesystem. All device
18 nodes are owned by root and have the default mode of 0600.
19 Userspace can add and delete the nodes as needed. This is
20 intended to simplify bootup, and make it possible to delay
21 the initial coldplug at bootup done by udev in userspace.
22 It should also provide a simpler way for rescue systems
23 to bring up a kernel with dynamic major/minor numbers.
24 Meaningful symlinks, permissions and device ownership must
25 still be handled by userspace.
26 If unsure, say N here.
27
28config DEVTMPFS_MOUNT
29 bool "Automount devtmpfs at /dev"
30 depends on DEVTMPFS
31 help
32 This will mount devtmpfs at /dev if the kernel mounts the root
33 filesystem. It will not affect initramfs based mounting.
34 If unsure, say N here.
35
11config STANDALONE 36config STANDALONE
12 bool "Select only drivers that don't need compile-time external firmware" if EXPERIMENTAL 37 bool "Select only drivers that don't need compile-time external firmware" if EXPERIMENTAL
13 default y 38 default y
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 1b2640ce74f0..c12c7f2f2a6f 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -4,6 +4,7 @@ obj-y := core.o sys.o bus.o dd.o \
4 driver.o class.o platform.o \ 4 driver.o class.o platform.o \
5 cpu.o firmware.o init.o map.o devres.o \ 5 cpu.o firmware.o init.o map.o devres.o \
6 attribute_container.o transport_class.o 6 attribute_container.o transport_class.o
7obj-$(CONFIG_DEVTMPFS) += devtmpfs.o
7obj-y += power/ 8obj-y += power/
8obj-$(CONFIG_HAS_DMA) += dma-mapping.o 9obj-$(CONFIG_HAS_DMA) += dma-mapping.o
9obj-$(CONFIG_HAVE_GENERIC_DMA_COHERENT) += dma-coherent.o 10obj-$(CONFIG_HAVE_GENERIC_DMA_COHERENT) += dma-coherent.o
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 503d59c57501..2ca7f5b7b824 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -139,3 +139,9 @@ static inline void module_add_driver(struct module *mod,
139 struct device_driver *drv) { } 139 struct device_driver *drv) { }
140static inline void module_remove_driver(struct device_driver *drv) { } 140static inline void module_remove_driver(struct device_driver *drv) { }
141#endif 141#endif
142
143#ifdef CONFIG_DEVTMPFS
144extern int devtmpfs_init(void);
145#else
146static inline int devtmpfs_init(void) { return 0; }
147#endif
diff --git a/drivers/base/core.c b/drivers/base/core.c
index a992985d1fab..390e664ec1c7 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -929,6 +929,8 @@ int device_add(struct device *dev)
929 error = device_create_sys_dev_entry(dev); 929 error = device_create_sys_dev_entry(dev);
930 if (error) 930 if (error)
931 goto devtattrError; 931 goto devtattrError;
932
933 devtmpfs_create_node(dev);
932 } 934 }
933 935
934 error = device_add_class_symlinks(dev); 936 error = device_add_class_symlinks(dev);
@@ -1075,6 +1077,7 @@ void device_del(struct device *dev)
1075 if (parent) 1077 if (parent)
1076 klist_del(&dev->p->knode_parent); 1078 klist_del(&dev->p->knode_parent);
1077 if (MAJOR(dev->devt)) { 1079 if (MAJOR(dev->devt)) {
1080 devtmpfs_delete_node(dev);
1078 device_remove_sys_dev_entry(dev); 1081 device_remove_sys_dev_entry(dev);
1079 device_remove_file(dev, &devt_attr); 1082 device_remove_file(dev, &devt_attr);
1080 } 1083 }
diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
new file mode 100644
index 000000000000..fd488ad4263a
--- /dev/null
+++ b/drivers/base/devtmpfs.c
@@ -0,0 +1,367 @@
1/*
2 * devtmpfs - kernel-maintained tmpfs-based /dev
3 *
4 * Copyright (C) 2009, Kay Sievers <kay.sievers@vrfy.org>
5 *
6 * During bootup, before any driver core device is registered,
7 * devtmpfs, a tmpfs-based filesystem is created. Every driver-core
8 * device which requests a device node, will add a node in this
9 * filesystem. The node is named after the the name of the device,
10 * or the susbsytem can provide a custom name. All devices are
11 * owned by root and have a mode of 0600.
12 */
13
14#include <linux/kernel.h>
15#include <linux/syscalls.h>
16#include <linux/mount.h>
17#include <linux/device.h>
18#include <linux/genhd.h>
19#include <linux/namei.h>
20#include <linux/fs.h>
21#include <linux/shmem_fs.h>
22#include <linux/cred.h>
23#include <linux/init_task.h>
24
25static struct vfsmount *dev_mnt;
26
27#if defined CONFIG_DEVTMPFS_MOUNT
28static int dev_mount = 1;
29#else
30static int dev_mount;
31#endif
32
33static int __init mount_param(char *str)
34{
35 dev_mount = simple_strtoul(str, NULL, 0);
36 return 1;
37}
38__setup("devtmpfs.mount=", mount_param);
39
40static int dev_get_sb(struct file_system_type *fs_type, int flags,
41 const char *dev_name, void *data, struct vfsmount *mnt)
42{
43 return get_sb_single(fs_type, flags, data, shmem_fill_super, mnt);
44}
45
46static struct file_system_type dev_fs_type = {
47 .name = "devtmpfs",
48 .get_sb = dev_get_sb,
49 .kill_sb = kill_litter_super,
50};
51
52#ifdef CONFIG_BLOCK
53static inline int is_blockdev(struct device *dev)
54{
55 return dev->class == &block_class;
56}
57#else
58static inline int is_blockdev(struct device *dev) { return 0; }
59#endif
60
61static int dev_mkdir(const char *name, mode_t mode)
62{
63 struct nameidata nd;
64 struct dentry *dentry;
65 int err;
66
67 err = vfs_path_lookup(dev_mnt->mnt_root, dev_mnt,
68 name, LOOKUP_PARENT, &nd);
69 if (err)
70 return err;
71
72 dentry = lookup_create(&nd, 1);
73 if (!IS_ERR(dentry)) {
74 err = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
75 dput(dentry);
76 } else {
77 err = PTR_ERR(dentry);
78 }
79 mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
80
81 path_put(&nd.path);
82 return err;
83}
84
85static int create_path(const char *nodepath)
86{
87 char *path;
88 struct nameidata nd;
89 int err = 0;
90
91 path = kstrdup(nodepath, GFP_KERNEL);
92 if (!path)
93