2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2007-09-20 16:31:38 +08:00
|
|
|
* fs/sysfs/symlink.c - operations for initializing and mounting sysfs
|
|
|
|
*
|
|
|
|
* Copyright (c) 2001-3 Patrick Mochel
|
|
|
|
* Copyright (c) 2007 SUSE Linux Products GmbH
|
|
|
|
* Copyright (c) 2007 Tejun Heo <teheo@suse.de>
|
|
|
|
*
|
|
|
|
* This file is released under the GPLv2.
|
|
|
|
*
|
|
|
|
* Please see Documentation/filesystems/sysfs.txt for more information.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEBUG
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/mount.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/init.h>
|
2008-07-16 06:58:04 +08:00
|
|
|
#include <linux/module.h>
|
2009-01-14 15:45:13 +08:00
|
|
|
#include <linux/magic.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include "sysfs.h"
|
|
|
|
|
|
|
|
|
2007-08-20 20:36:30 +08:00
|
|
|
static struct vfsmount *sysfs_mount;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct super_block * sysfs_sb = NULL;
|
2006-12-07 12:33:20 +08:00
|
|
|
struct kmem_cache *sysfs_dir_cachep;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-12 16:55:41 +08:00
|
|
|
static const struct super_operations sysfs_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.statfs = simple_statfs,
|
2007-07-31 18:15:08 +08:00
|
|
|
.drop_inode = generic_delete_inode,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2007-06-14 03:27:25 +08:00
|
|
|
struct sysfs_dirent sysfs_root = {
|
2007-09-20 15:05:12 +08:00
|
|
|
.s_name = "",
|
2007-06-14 02:45:14 +08:00
|
|
|
.s_count = ATOMIC_INIT(1),
|
2007-09-20 15:05:12 +08:00
|
|
|
.s_flags = SYSFS_DIR,
|
2007-06-14 02:45:17 +08:00
|
|
|
.s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
|
2007-06-11 13:02:45 +08:00
|
|
|
.s_ino = 1,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int sysfs_fill_super(struct super_block *sb, void *data, int silent)
|
|
|
|
{
|
|
|
|
struct inode *inode;
|
|
|
|
struct dentry *root;
|
|
|
|
|
|
|
|
sb->s_blocksize = PAGE_CACHE_SIZE;
|
|
|
|
sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
|
|
|
|
sb->s_magic = SYSFS_MAGIC;
|
|
|
|
sb->s_op = &sysfs_ops;
|
|
|
|
sb->s_time_gran = 1;
|
|
|
|
sysfs_sb = sb;
|
|
|
|
|
2007-07-18 13:29:06 +08:00
|
|
|
/* get root inode, initialize and unlock it */
|
|
|
|
inode = sysfs_get_inode(&sysfs_root);
|
2007-06-14 02:45:17 +08:00
|
|
|
if (!inode) {
|
2005-04-17 06:20:36 +08:00
|
|
|
pr_debug("sysfs: could not get root inode\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2007-07-18 13:29:06 +08:00
|
|
|
/* instantiate and link root dentry */
|
2005-04-17 06:20:36 +08:00
|
|
|
root = d_alloc_root(inode);
|
|
|
|
if (!root) {
|
2008-04-30 15:55:09 +08:00
|
|
|
pr_debug("%s: could not get root dentry!\n",__func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
iput(inode);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
root->d_fsdata = &sysfs_root;
|
|
|
|
sb->s_root = root;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
[PATCH] VFS: Permit filesystem to override root dentry on mount
Extend the get_sb() filesystem operation to take an extra argument that
permits the VFS to pass in the target vfsmount that defines the mountpoint.
The filesystem is then required to manually set the superblock and root dentry
pointers. For most filesystems, this should be done with simple_set_mnt()
which will set the superblock pointer and then set the root dentry to the
superblock's s_root (as per the old default behaviour).
The get_sb() op now returns an integer as there's now no need to return the
superblock pointer.
This patch permits a superblock to be implicitly shared amongst several mount
points, such as can be done with NFS to avoid potential inode aliasing. In
such a case, simple_set_mnt() would not be called, and instead the mnt_root
and mnt_sb would be set directly.
The patch also makes the following changes:
(*) the get_sb_*() convenience functions in the core kernel now take a vfsmount
pointer argument and return an integer, so most filesystems have to change
very little.
(*) If one of the convenience function is not used, then get_sb() should
normally call simple_set_mnt() to instantiate the vfsmount. This will
always return 0, and so can be tail-called from get_sb().
(*) generic_shutdown_super() now calls shrink_dcache_sb() to clean up the
dcache upon superblock destruction rather than shrink_dcache_anon().
This is required because the superblock may now have multiple trees that
aren't actually bound to s_root, but that still need to be cleaned up. The
currently called functions assume that the whole tree is rooted at s_root,
and that anonymous dentries are not the roots of trees which results in
dentries being left unculled.
However, with the way NFS superblock sharing are currently set to be
implemented, these assumptions are violated: the root of the filesystem is
simply a dummy dentry and inode (the real inode for '/' may well be
inaccessible), and all the vfsmounts are rooted on anonymous[*] dentries
with child trees.
[*] Anonymous until discovered from another tree.
(*) The documentation has been adjusted, including the additional bit of
changing ext2_* into foo_* in the documentation.
[akpm@osdl.org: convert ipath_fs, do other stuff]
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: Nathan Scott <nathans@sgi.com>
Cc: Roland Dreier <rolandd@cisco.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-23 17:02:57 +08:00
|
|
|
static int sysfs_get_sb(struct file_system_type *fs_type,
|
|
|
|
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
[PATCH] VFS: Permit filesystem to override root dentry on mount
Extend the get_sb() filesystem operation to take an extra argument that
permits the VFS to pass in the target vfsmount that defines the mountpoint.
The filesystem is then required to manually set the superblock and root dentry
pointers. For most filesystems, this should be done with simple_set_mnt()
which will set the superblock pointer and then set the root dentry to the
superblock's s_root (as per the old default behaviour).
The get_sb() op now returns an integer as there's now no need to return the
superblock pointer.
This patch permits a superblock to be implicitly shared amongst several mount
points, such as can be done with NFS to avoid potential inode aliasing. In
such a case, simple_set_mnt() would not be called, and instead the mnt_root
and mnt_sb would be set directly.
The patch also makes the following changes:
(*) the get_sb_*() convenience functions in the core kernel now take a vfsmount
pointer argument and return an integer, so most filesystems have to change
very little.
(*) If one of the convenience function is not used, then get_sb() should
normally call simple_set_mnt() to instantiate the vfsmount. This will
always return 0, and so can be tail-called from get_sb().
(*) generic_shutdown_super() now calls shrink_dcache_sb() to clean up the
dcache upon superblock destruction rather than shrink_dcache_anon().
This is required because the superblock may now have multiple trees that
aren't actually bound to s_root, but that still need to be cleaned up. The
currently called functions assume that the whole tree is rooted at s_root,
and that anonymous dentries are not the roots of trees which results in
dentries being left unculled.
However, with the way NFS superblock sharing are currently set to be
implemented, these assumptions are violated: the root of the filesystem is
simply a dummy dentry and inode (the real inode for '/' may well be
inaccessible), and all the vfsmounts are rooted on anonymous[*] dentries
with child trees.
[*] Anonymous until discovered from another tree.
(*) The documentation has been adjusted, including the additional bit of
changing ext2_* into foo_* in the documentation.
[akpm@osdl.org: convert ipath_fs, do other stuff]
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Cc: Nathan Scott <nathans@sgi.com>
Cc: Roland Dreier <rolandd@cisco.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-23 17:02:57 +08:00
|
|
|
return get_sb_single(fs_type, flags, data, sysfs_fill_super, mnt);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_system_type sysfs_fs_type = {
|
|
|
|
.name = "sysfs",
|
|
|
|
.get_sb = sysfs_get_sb,
|
2007-08-20 20:36:29 +08:00
|
|
|
.kill_sb = kill_anon_super,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int __init sysfs_init(void)
|
|
|
|
{
|
|
|
|
int err = -ENOMEM;
|
|
|
|
|
|
|
|
sysfs_dir_cachep = kmem_cache_create("sysfs_dir_cache",
|
|
|
|
sizeof(struct sysfs_dirent),
|
2007-07-20 09:11:58 +08:00
|
|
|
0, 0, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!sysfs_dir_cachep)
|
|
|
|
goto out;
|
|
|
|
|
2007-10-17 14:25:46 +08:00
|
|
|
err = sysfs_inode_init();
|
|
|
|
if (err)
|
|
|
|
goto out_err;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
err = register_filesystem(&sysfs_fs_type);
|
|
|
|
if (!err) {
|
|
|
|
sysfs_mount = kern_mount(&sysfs_fs_type);
|
|
|
|
if (IS_ERR(sysfs_mount)) {
|
|
|
|
printk(KERN_ERR "sysfs: could not mount!\n");
|
|
|
|
err = PTR_ERR(sysfs_mount);
|
|
|
|
sysfs_mount = NULL;
|
|
|
|
unregister_filesystem(&sysfs_fs_type);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
goto out_err;
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
out_err:
|
|
|
|
kmem_cache_destroy(sysfs_dir_cachep);
|
|
|
|
sysfs_dir_cachep = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
2008-07-16 06:58:04 +08:00
|
|
|
|
|
|
|
#undef sysfs_get
|
|
|
|
struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd)
|
|
|
|
{
|
|
|
|
return __sysfs_get(sd);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(sysfs_get);
|
|
|
|
|
|
|
|
#undef sysfs_put
|
|
|
|
void sysfs_put(struct sysfs_dirent *sd)
|
|
|
|
{
|
|
|
|
__sysfs_put(sd);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(sysfs_put);
|