Skip to content

Commit 454e239

Browse files
dhowellsLinus Torvalds
authored andcommitted
[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>
1 parent 1ad5544 commit 454e239

83 files changed

Lines changed: 482 additions & 431 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/filesystems/Locking‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,16 @@ see also dquot_operations section.
142142

143143
--------------------------- file_system_type ---------------------------
144144
prototypes:
145-
struct super_block *(*get_sb) (struct file_system_type *, int,
146-
const char *, void *);
145+
struct int (*get_sb) (struct file_system_type *, int,
146+
const char *, void *, struct vfsmount *);
147147
void (*kill_sb) (struct super_block *);
148148
locking rules:
149149
may block BKL
150150
get_sb yes yes
151151
kill_sb yes yes
152152

153-
->get_sb() returns error or a locked superblock (exclusive on ->s_umount).
153+
->get_sb() returns error or 0 with locked superblock attached to the vfsmount
154+
(exclusive on ->s_umount).
154155
->kill_sb() takes a write-locked superblock, does all shutdown work on it,
155156
unlocks and drops the reference.
156157

‎Documentation/filesystems/porting‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ Turn your foo_read_super() into a function that would return 0 in case of
5050
success and negative number in case of error (-EINVAL unless you have more
5151
informative error value to report). Call it foo_fill_super(). Now declare
5252

53-
struct super_block foo_get_sb(struct file_system_type *fs_type,
54-
int flags, const char *dev_name, void *data)
53+
int foo_get_sb(struct file_system_type *fs_type,
54+
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
5555
{
56-
return get_sb_bdev(fs_type, flags, dev_name, data, ext2_fill_super);
56+
return get_sb_bdev(fs_type, flags, dev_name, data, foo_fill_super,
57+
mnt);
5758
}
5859

5960
(or similar with s/bdev/nodev/ or s/bdev/single/, depending on the kind of

‎Documentation/filesystems/vfs.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ members are defined:
113113
struct file_system_type {
114114
const char *name;
115115
int fs_flags;
116-
struct super_block *(*get_sb) (struct file_system_type *, int,
117-
const char *, void *);
116+
struct int (*get_sb) (struct file_system_type *, int,
117+
const char *, void *, struct vfsmount *);
118118
void (*kill_sb) (struct super_block *);
119119
struct module *owner;
120120
struct file_system_type * next;

‎arch/ia64/kernel/perfmon.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,11 @@ pfm_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len,
595595
}
596596

597597

598-
static struct super_block *
599-
pfmfs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data)
598+
static int
599+
pfmfs_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data,
600+
struct vfsmount *mnt)
600601
{
601-
return get_sb_pseudo(fs_type, "pfm:", NULL, PFMFS_MAGIC);
602+
return get_sb_pseudo(fs_type, "pfm:", NULL, PFMFS_MAGIC, mnt);
602603
}
603604

604605
static struct file_system_type pfm_fs_type = {

‎arch/powerpc/platforms/cell/spufs/inode.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,11 @@ spufs_fill_super(struct super_block *sb, void *data, int silent)
436436
return spufs_create_root(sb, data);
437437
}
438438

439-
static struct super_block *
439+
static int
440440
spufs_get_sb(struct file_system_type *fstype, int flags,
441-
const char *name, void *data)
441+
const char *name, void *data, struct vfsmount *mnt)
442442
{
443-
return get_sb_single(fstype, flags, data, spufs_fill_super);
443+
return get_sb_single(fstype, flags, data, spufs_fill_super, mnt);
444444
}
445445

446446
static struct file_system_type spufs_type = {

‎drivers/infiniband/core/uverbs_main.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,11 +821,12 @@ static void ib_uverbs_remove_one(struct ib_device *device)
821821
kref_put(&uverbs_dev->ref, ib_uverbs_release_dev);
822822
}
823823

824-
static struct super_block *uverbs_event_get_sb(struct file_system_type *fs_type, int flags,
825-
const char *dev_name, void *data)
824+
static int uverbs_event_get_sb(struct file_system_type *fs_type, int flags,
825+
const char *dev_name, void *data,
826+
struct vfsmount *mnt)
826827
{
827828
return get_sb_pseudo(fs_type, "infinibandevent:", NULL,
828-
INFINIBANDEVENTFS_MAGIC);
829+
INFINIBANDEVENTFS_MAGIC, mnt);
829830
}
830831

831832
static struct file_system_type uverbs_event_fs = {

‎drivers/infiniband/hw/ipath/ipath_fs.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -542,13 +542,14 @@ static int ipathfs_fill_super(struct super_block *sb, void *data,
542542
return ret;
543543
}
544544

545-
static struct super_block *ipathfs_get_sb(struct file_system_type *fs_type,
546-
int flags, const char *dev_name,
547-
void *data)
545+
static int ipathfs_get_sb(struct file_system_type *fs_type, int flags,
546+
const char *dev_name, void *data, struct vfsmount *mnt)
548547
{
549-
ipath_super = get_sb_single(fs_type, flags, data,
550-
ipathfs_fill_super);
551-
return ipath_super;
548+
int ret = get_sb_single(fs_type, flags, data,
549+
ipathfs_fill_super, mnt);
550+
if (ret >= 0)
551+
ipath_super = mnt->mnt_sb;
552+
return ret;
552553
}
553554

554555
static void ipathfs_kill_super(struct super_block *s)

‎drivers/isdn/capi/capifs.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ capifs_fill_super(struct super_block *s, void *data, int silent)
121121
return -ENOMEM;
122122
}
123123

124-
static struct super_block *capifs_get_sb(struct file_system_type *fs_type,
125-
int flags, const char *dev_name, void *data)
124+
static int capifs_get_sb(struct file_system_type *fs_type,
125+
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
126126
{
127-
return get_sb_single(fs_type, flags, data, capifs_fill_super);
127+
return get_sb_single(fs_type, flags, data, capifs_fill_super, mnt);
128128
}
129129

130130
static struct file_system_type capifs_fs_type = {

‎drivers/misc/ibmasm/ibmasmfs.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ static void ibmasmfs_create_files (struct super_block *sb, struct dentry *root);
9090
static int ibmasmfs_fill_super (struct super_block *sb, void *data, int silent);
9191

9292

93-
static struct super_block *ibmasmfs_get_super(struct file_system_type *fst,
94-
int flags, const char *name, void *data)
93+
static int ibmasmfs_get_super(struct file_system_type *fst,
94+
int flags, const char *name, void *data,
95+
struct vfsmount *mnt)
9596
{
96-
return get_sb_single(fst, flags, data, ibmasmfs_fill_super);
97+
return get_sb_single(fst, flags, data, ibmasmfs_fill_super, mnt);
9798
}
9899

99100
static struct super_operations ibmasmfs_s_ops = {

‎drivers/oprofile/oprofilefs.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ static int oprofilefs_fill_super(struct super_block * sb, void * data, int silen
272272
}
273273

274274

275-
static struct super_block *oprofilefs_get_sb(struct file_system_type *fs_type,
276-
int flags, const char *dev_name, void *data)
275+
static int oprofilefs_get_sb(struct file_system_type *fs_type,
276+
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
277277
{
278-
return get_sb_single(fs_type, flags, data, oprofilefs_fill_super);
278+
return get_sb_single(fs_type, flags, data, oprofilefs_fill_super, mnt);
279279
}
280280

281281

0 commit comments

Comments
 (0)