Commit 454e2398 authored by David Howells's avatar David Howells Committed by Linus Torvalds
Browse files

[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: default avatarDavid Howells <dhowells@redhat.com>
Acked-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Cc: Nathan Scott <nathans@sgi.com>
Cc: Roland Dreier <rolandd@cisco.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 1ad55440
......@@ -739,10 +739,10 @@ static int bm_fill_super(struct super_block * sb, void * data, int silent)
return err;
}
static struct super_block *bm_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
static int bm_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{
return get_sb_single(fs_type, flags, data, bm_fill_super);
return get_sb_single(fs_type, flags, data, bm_fill_super, mnt);
}
static struct linux_binfmt misc_format = {
......
......@@ -300,10 +300,10 @@ static struct super_operations bdev_sops = {
.clear_inode = bdev_clear_inode,
};
static struct super_block *bd_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
static int bd_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{
return get_sb_pseudo(fs_type, "bdev:", &bdev_sops, 0x62646576);
return get_sb_pseudo(fs_type, "bdev:", &bdev_sops, 0x62646576, mnt);
}
static struct file_system_type bd_type = {
......
......@@ -460,9 +460,9 @@ struct super_operations cifs_super_ops = {
.remount_fs = cifs_remount,
};
static struct super_block *
static int
cifs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{
int rc;
struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL);
......@@ -470,7 +470,7 @@ cifs_get_sb(struct file_system_type *fs_type,
cFYI(1, ("Devname: %s flags: %d ", dev_name, flags));
if (IS_ERR(sb))
return sb;
return PTR_ERR(sb);
sb->s_flags = flags;
......@@ -478,10 +478,10 @@ cifs_get_sb(struct file_system_type *fs_type,
if (rc) {
up_write(&sb->s_umount);
deactivate_super(sb);
return ERR_PTR(rc);
return rc;
}
sb->s_flags |= MS_ACTIVE;
return sb;
return simple_set_mnt(mnt, sb);
}
static ssize_t cifs_file_writev(struct file *file, const struct iovec *iov,
......
......@@ -307,10 +307,10 @@ static int coda_statfs(struct super_block *sb, struct kstatfs *buf)
/* init_coda: used by filesystems.c to register coda */
static struct super_block *coda_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
static int coda_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{
return get_sb_nodev(fs_type, flags, data, coda_fill_super);
return get_sb_nodev(fs_type, flags, data, coda_fill_super, mnt);
}
struct file_system_type coda_fs_type = {
......
......@@ -103,10 +103,10 @@ static int configfs_fill_super(struct super_block *sb, void *data, int silent)
return 0;
}
static struct super_block *configfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
static int configfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{
return get_sb_single(fs_type, flags, data, configfs_fill_super);
return get_sb_single(fs_type, flags, data, configfs_fill_super, mnt);
}
static struct file_system_type configfs_fs_type = {
......
......@@ -528,10 +528,11 @@ static struct super_operations cramfs_ops = {
.statfs = cramfs_statfs,
};
static struct super_block *cramfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
static int cramfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{
return get_sb_bdev(fs_type, flags, dev_name, data, cramfs_fill_super);
return get_sb_bdev(fs_type, flags, dev_name, data, cramfs_fill_super,
mnt);
}
static struct file_system_type cramfs_fs_type = {
......
......@@ -687,46 +687,6 @@ void shrink_dcache_parent(struct dentry * parent)
prune_dcache(found, parent->d_sb);
}
/**
* shrink_dcache_anon - further prune the cache
* @head: head of d_hash list of dentries to prune
*
* Prune the dentries that are anonymous
*
* parsing d_hash list does not hlist_for_each_entry_rcu() as it
* done under dcache_lock.
*
*/
void shrink_dcache_anon(struct super_block *sb)
{
struct hlist_node *lp;
struct hlist_head *head = &sb->s_anon;
int found;
do {
found = 0;
spin_lock(&dcache_lock);
hlist_for_each(lp, head) {
struct dentry *this = hlist_entry(lp, struct dentry, d_hash);
if (!list_empty(&this->d_lru)) {
dentry_stat.nr_unused--;
list_del_init(&this->d_lru);
}
/*
* move only zero ref count dentries to the end
* of the unused list for prune_dcache
*/
if (!atomic_read(&this->d_count)) {
list_add_tail(&this->d_lru, &dentry_unused);
dentry_stat.nr_unused++;
found++;
}
}
spin_unlock(&dcache_lock);
prune_dcache(found, sb);
} while(found);
}
/*
* Scan `nr' dentries and return the number which remain.
*
......
......@@ -111,11 +111,11 @@ static int debug_fill_super(struct super_block *sb, void *data, int silent)
return simple_fill_super(sb, DEBUGFS_MAGIC, debug_files);
}
static struct super_block *debug_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name,
void *data)
static int debug_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name,
void *data, struct vfsmount *mnt)
{
return get_sb_single(fs_type, flags, data, debug_fill_super);
return get_sb_single(fs_type, flags, data, debug_fill_super, mnt);
}
static struct file_system_type debug_fs_type = {
......
......@@ -2549,11 +2549,11 @@ static int devfs_fill_super(struct super_block *sb, void *data, int silent)
return -EINVAL;
} /* End Function devfs_fill_super */
static struct super_block *devfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name,
void *data)
static int devfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name,
void *data, struct vfsmount *mnt)
{
return get_sb_single(fs_type, flags, data, devfs_fill_super);
return get_sb_single(fs_type, flags, data, devfs_fill_super, mnt);
}
static struct file_system_type devfs_fs_type = {
......
......@@ -130,10 +130,10 @@ fail:
return -ENOMEM;
}
static struct super_block *devpts_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
static int devpts_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{
return get_sb_single(fs_type, flags, data, devpts_fill_super);
return get_sb_single(fs_type, flags, data, devpts_fill_super, mnt);
}
static struct file_system_type devpts_fs_type = {
......
......@@ -18,10 +18,10 @@
static int efs_statfs(struct super_block *s, struct kstatfs *buf);
static int efs_fill_super(struct super_block *s, void *d, int silent);
static struct super_block *efs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
static int efs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{
return get_sb_bdev(fs_type, flags, dev_name, data, efs_fill_super);
return get_sb_bdev(fs_type, flags, dev_name, data, efs_fill_super, mnt);
}
static struct file_system_type efs_fs_type = {
......
......@@ -268,9 +268,9 @@ static int ep_poll(struct eventpoll *ep, struct epoll_event __user *events,
int maxevents, long timeout);
static int eventpollfs_delete_dentry(struct dentry *dentry);
static struct inode *ep_eventpoll_inode(void);
static struct super_block *eventpollfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name,
void *data);
static int eventpollfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name,
void *data, struct vfsmount *mnt);
/*
* This semaphore is used to serialize ep_free() and eventpoll_release_file().
......@@ -1595,11 +1595,12 @@ eexit_1:
}
static struct super_block *
static int
eventpollfs_get_sb(struct file_system_type *fs_type, int flags,
const char *dev_name, void *data)
const char *dev_name, void *data, struct vfsmount *mnt)
{
return get_sb_pseudo(fs_type, "eventpoll:", NULL, EVENTPOLLFS_MAGIC);
return get_sb_pseudo(fs_type, "eventpoll:", NULL, EVENTPOLLFS_MAGIC,
mnt);
}
......
......@@ -1087,10 +1087,10 @@ static int ext2_statfs (struct super_block * sb, struct kstatfs * buf)
return 0;
}
static struct super_block *ext2_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
static int ext2_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{
return get_sb_bdev(fs_type, flags, dev_name, data, ext2_fill_super);
return get_sb_bdev(fs_type, flags, dev_name, data, ext2_fill_super, mnt);
}
#ifdef CONFIG_QUOTA
......
......@@ -2646,10 +2646,10 @@ out:
#endif
static struct super_block *ext3_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
static int ext3_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{
return get_sb_bdev(fs_type, flags, dev_name, data, ext3_fill_super);
return get_sb_bdev(fs_type, flags, dev_name, data, ext3_fill_super, mnt);
}
static struct file_system_type ext3_fs_type = {
......
......@@ -241,10 +241,11 @@ out:
/*
* The usual module blurb.
*/
static struct super_block *vxfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
static int vxfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{
return get_sb_bdev(fs_type, flags, dev_name, data, vxfs_fill_super);
return get_sb_bdev(fs_type, flags, dev_name, data, vxfs_fill_super,
mnt);
}
static struct file_system_type vxfs_fs_type = {
......
......@@ -569,11 +569,11 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
return err;
}
static struct super_block *fuse_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name,
void *raw_data)
static int fuse_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name,
void *raw_data, struct vfsmount *mnt)
{
return get_sb_nodev(fs_type, flags, raw_data, fuse_fill_super);
return get_sb_nodev(fs_type, flags, raw_data, fuse_fill_super, mnt);
}
static struct file_system_type fuse_fs_type = {
......
......@@ -413,10 +413,11 @@ bail:
return res;
}
static struct super_block *hfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
static int hfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data,
struct vfsmount *mnt)
{
return get_sb_bdev(fs_type, flags, dev_name, data, hfs_fill_super);
return get_sb_bdev(fs_type, flags, dev_name, data, hfs_fill_super, mnt);
}
static struct file_system_type hfs_fs_type = {
......
......@@ -450,10 +450,12 @@ static void hfsplus_destroy_inode(struct inode *inode)
#define HFSPLUS_INODE_SIZE sizeof(struct hfsplus_inode_info)
static struct super_block *hfsplus_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
static int hfsplus_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data,
struct vfsmount *mnt)
{
return get_sb_bdev(fs_type, flags, dev_name, data, hfsplus_fill_super);
return get_sb_bdev(fs_type, flags, dev_name, data, hfsplus_fill_super,
mnt);
}
static struct file_system_type hfsplus_fs_type = {
......
......@@ -993,11 +993,11 @@ static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent)
return(err);
}
static struct super_block *hostfs_read_sb(struct file_system_type *type,
int flags, const char *dev_name,
void *data)
static int hostfs_read_sb(struct file_system_type *type,
int flags, const char *dev_name,
void *data, struct vfsmount *mnt)
{
return(get_sb_nodev(type, flags, data, hostfs_fill_sb_common));
return get_sb_nodev(type, flags, data, hostfs_fill_sb_common, mnt);
}
static struct file_system_type hostfs_type = {
......
......@@ -662,10 +662,11 @@ bail0:
return -EINVAL;
}
static struct super_block *hpfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
static int hpfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
{
return get_sb_bdev(fs_type, flags, dev_name, data, hpfs_fill_super);
return get_sb_bdev(fs_type, flags, dev_name, data, hpfs_fill_super,
mnt);
}
static struct file_system_type hpfs_fs_type = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment