Skip to content

Commit

Permalink
Merge branch 'mnt_devname' of git://git.kernel.org/pub/scm/linux/kern…
Browse files Browse the repository at this point in the history
…el/git/viro/vfs-2.6

* 'mnt_devname' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6:
  vfs: bury ->get_sb()
  nfs: switch NFS from ->get_sb() to ->mount()
  nfs: stop mangling ->mnt_devname on NFS
  vfs: new superblock methods to override /proc/*/mount{s,info}
  nfs: nfs_do_{ref,sub}mount() superblock argument is redundant
  nfs: make nfs_path() work without vfsmount
  nfs: store devname at disconnected NFS roots
  nfs: propagate devname to nfs{,4}_get_root()
  • Loading branch information
torvalds committed Mar 17, 2011
2 parents dc113c1 + 1a102ff commit 054cfaa
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 272 deletions.
6 changes: 2 additions & 4 deletions Documentation/filesystems/Locking
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,11 @@ prototypes:
void (*kill_sb) (struct super_block *);
locking rules:
may block
get_sb yes
mount yes
kill_sb yes

->get_sb() returns error or 0 with locked superblock attached to the vfsmount
(exclusive on ->s_umount).
->mount() returns ERR_PTR or the root dentry.
->mount() returns ERR_PTR or the root dentry; its superblock should be locked
on return.
->kill_sb() takes a write-locked superblock, does all shutdown work on it,
unlocks and drops the reference.

Expand Down
7 changes: 7 additions & 0 deletions Documentation/filesystems/porting
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,10 @@ file) you must return -EOPNOTSUPP if FALLOC_FL_PUNCH_HOLE is set in mode.
Currently you can only have FALLOC_FL_PUNCH_HOLE with FALLOC_FL_KEEP_SIZE set,
so the i_size should not change when hole punching, even when puching the end of
a file off.

--
[mandatory]
->get_sb() is gone. Switch to use of ->mount(). Typically it's just
a matter of switching from calling get_sb_... to mount_... and changing the
function type. If you were doing it manually, just switch from setting ->mnt_root
to some pointer to returning that pointer. On errors return ERR_PTR(...).
56 changes: 32 additions & 24 deletions Documentation/filesystems/vfs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ functions:
extern int unregister_filesystem(struct file_system_type *);

The passed struct file_system_type describes your filesystem. When a
request is made to mount a device onto a directory in your filespace,
the VFS will call the appropriate get_sb() method for the specific
filesystem. The dentry for the mount point will then be updated to
point to the root inode for the new filesystem.
request is made to mount a filesystem onto a directory in your namespace,
the VFS will call the appropriate mount() method for the specific
filesystem. New vfsmount refering to the tree returned by ->mount()
will be attached to the mountpoint, so that when pathname resolution
reaches the mountpoint it will jump into the root of that vfsmount.

You can see all filesystems that are registered to the kernel in the
file /proc/filesystems.
Expand All @@ -107,14 +108,14 @@ file /proc/filesystems.
struct file_system_type
-----------------------

This describes the filesystem. As of kernel 2.6.22, the following
This describes the filesystem. As of kernel 2.6.39, the following
members are defined:

struct file_system_type {
const char *name;
int fs_flags;
int (*get_sb) (struct file_system_type *, int,
const char *, void *, struct vfsmount *);
struct dentry (*mount) (struct file_system_type *, int,
const char *, void *);
void (*kill_sb) (struct super_block *);
struct module *owner;
struct file_system_type * next;
Expand All @@ -128,11 +129,11 @@ struct file_system_type {

fs_flags: various flags (i.e. FS_REQUIRES_DEV, FS_NO_DCACHE, etc.)

get_sb: the method to call when a new instance of this
mount: the method to call when a new instance of this
filesystem should be mounted

kill_sb: the method to call when an instance of this filesystem
should be unmounted
should be shut down

owner: for internal VFS use: you should initialize this to THIS_MODULE in
most cases.
Expand All @@ -141,7 +142,7 @@ struct file_system_type {

s_lock_key, s_umount_key: lockdep-specific

The get_sb() method has the following arguments:
The mount() method has the following arguments:

struct file_system_type *fs_type: describes the filesystem, partly initialized
by the specific filesystem code
Expand All @@ -153,32 +154,39 @@ The get_sb() method has the following arguments:
void *data: arbitrary mount options, usually comes as an ASCII
string (see "Mount Options" section)

struct vfsmount *mnt: a vfs-internal representation of a mount point
The mount() method must return the root dentry of the tree requested by
caller. An active reference to its superblock must be grabbed and the
superblock must be locked. On failure it should return ERR_PTR(error).

The get_sb() method must determine if the block device specified
in the dev_name and fs_type contains a filesystem of the type the method
supports. If it succeeds in opening the named block device, it initializes a
struct super_block descriptor for the filesystem contained by the block device.
On failure it returns an error.
The arguments match those of mount(2) and their interpretation
depends on filesystem type. E.g. for block filesystems, dev_name is
interpreted as block device name, that device is opened and if it
contains a suitable filesystem image the method creates and initializes
struct super_block accordingly, returning its root dentry to caller.

->mount() may choose to return a subtree of existing filesystem - it
doesn't have to create a new one. The main result from the caller's
point of view is a reference to dentry at the root of (sub)tree to
be attached; creation of new superblock is a common side effect.

The most interesting member of the superblock structure that the
get_sb() method fills in is the "s_op" field. This is a pointer to
mount() method fills in is the "s_op" field. This is a pointer to
a "struct super_operations" which describes the next level of the
filesystem implementation.

Usually, a filesystem uses one of the generic get_sb() implementations
and provides a fill_super() method instead. The generic methods are:
Usually, a filesystem uses one of the generic mount() implementations
and provides a fill_super() callback instead. The generic variants are:

get_sb_bdev: mount a filesystem residing on a block device
mount_bdev: mount a filesystem residing on a block device

get_sb_nodev: mount a filesystem that is not backed by a device
mount_nodev: mount a filesystem that is not backed by a device

get_sb_single: mount a filesystem which shares the instance between
mount_single: mount a filesystem which shares the instance between
all mounts

A fill_super() method implementation has the following arguments:
A fill_super() callback implementation has the following arguments:

struct super_block *sb: the superblock structure. The method fill_super()
struct super_block *sb: the superblock structure. The callback
must initialize this properly.

void *data: arbitrary mount options, usually comes as an ASCII
Expand Down
39 changes: 30 additions & 9 deletions fs/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,13 @@ static int show_vfsmnt(struct seq_file *m, void *v)
int err = 0;
struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };

mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
if (mnt->mnt_sb->s_op->show_devname) {
err = mnt->mnt_sb->s_op->show_devname(m, mnt);
if (err)
goto out;
} else {
mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
}
seq_putc(m, ' ');
seq_path(m, &mnt_path, " \t\n\\");
seq_putc(m, ' ');
Expand Down Expand Up @@ -1025,7 +1031,12 @@ static int show_mountinfo(struct seq_file *m, void *v)

seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
MAJOR(sb->s_dev), MINOR(sb->s_dev));
seq_dentry(m, mnt->mnt_root, " \t\n\\");
if (sb->s_op->show_path)
err = sb->s_op->show_path(m, mnt);
else
seq_dentry(m, mnt->mnt_root, " \t\n\\");
if (err)
goto out;
seq_putc(m, ' ');
seq_path_root(m, &mnt_path, &root, " \t\n\\");
if (root.mnt != p->root.mnt || root.dentry != p->root.dentry) {
Expand Down Expand Up @@ -1060,7 +1071,12 @@ static int show_mountinfo(struct seq_file *m, void *v)
seq_puts(m, " - ");
show_type(m, sb);
seq_putc(m, ' ');
mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
if (sb->s_op->show_devname)
err = sb->s_op->show_devname(m, mnt);
else
mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
if (err)
goto out;
seq_puts(m, sb->s_flags & MS_RDONLY ? " ro" : " rw");
err = show_sb_opts(m, sb);
if (err)
Expand All @@ -1086,11 +1102,15 @@ static int show_vfsstat(struct seq_file *m, void *v)
int err = 0;

/* device */
if (mnt->mnt_devname) {
seq_puts(m, "device ");
mangle(m, mnt->mnt_devname);
} else
seq_puts(m, "no device");
if (mnt->mnt_sb->s_op->show_devname) {
err = mnt->mnt_sb->s_op->show_devname(m, mnt);
} else {
if (mnt->mnt_devname) {
seq_puts(m, "device ");
mangle(m, mnt->mnt_devname);
} else
seq_puts(m, "no device");
}

/* mount point */
seq_puts(m, " mounted on ");
Expand All @@ -1104,7 +1124,8 @@ static int show_vfsstat(struct seq_file *m, void *v)
/* optional statistics */
if (mnt->mnt_sb->s_op->show_stats) {
seq_putc(m, ' ');
err = mnt->mnt_sb->s_op->show_stats(m, mnt);
if (!err)
err = mnt->mnt_sb->s_op->show_stats(m, mnt);
}

seq_putc(m, '\n');
Expand Down
13 changes: 13 additions & 0 deletions fs/nfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -1169,11 +1169,23 @@ static void nfs_dentry_iput(struct dentry *dentry, struct inode *inode)
iput(inode);
}

static void nfs_d_release(struct dentry *dentry)
{
/* free cached devname value, if it survived that far */
if (unlikely(dentry->d_fsdata)) {
if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
WARN_ON(1);
else
kfree(dentry->d_fsdata);
}
}

const struct dentry_operations nfs_dentry_operations = {
.d_revalidate = nfs_lookup_revalidate,
.d_delete = nfs_dentry_delete,
.d_iput = nfs_dentry_iput,
.d_automount = nfs_d_automount,
.d_release = nfs_d_release,
};

static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd)
Expand Down Expand Up @@ -1248,6 +1260,7 @@ const struct dentry_operations nfs4_dentry_operations = {
.d_delete = nfs_dentry_delete,
.d_iput = nfs_dentry_iput,
.d_automount = nfs_d_automount,
.d_release = nfs_d_release,
};

/*
Expand Down
42 changes: 36 additions & 6 deletions fs/nfs/getroot.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,25 @@ static int nfs_superblock_set_dummy_root(struct super_block *sb, struct inode *i
/*
* get an NFS2/NFS3 root dentry from the root filehandle
*/
struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh)
struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh,
const char *devname)
{
struct nfs_server *server = NFS_SB(sb);
struct nfs_fsinfo fsinfo;
struct dentry *ret;
struct inode *inode;
void *name = kstrdup(devname, GFP_KERNEL);
int error;

if (!name)
return ERR_PTR(-ENOMEM);

/* get the actual root for this mount */
fsinfo.fattr = nfs_alloc_fattr();
if (fsinfo.fattr == NULL)
if (fsinfo.fattr == NULL) {
kfree(name);
return ERR_PTR(-ENOMEM);
}

error = server->nfs_client->rpc_ops->getroot(server, mntfh, &fsinfo);
if (error < 0) {
Expand Down Expand Up @@ -119,7 +126,15 @@ struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh)
}

security_d_instantiate(ret, inode);
spin_lock(&ret->d_lock);
if (IS_ROOT(ret) && !(ret->d_flags & DCACHE_NFSFS_RENAMED)) {
ret->d_fsdata = name;
name = NULL;
}
spin_unlock(&ret->d_lock);
out:
if (name)
kfree(name);
nfs_free_fattr(fsinfo.fattr);
return ret;
}
Expand Down Expand Up @@ -169,27 +184,35 @@ int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh)
/*
* get an NFS4 root dentry from the root filehandle
*/
struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh)
struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh,
const char *devname)
{
struct nfs_server *server = NFS_SB(sb);
struct nfs_fattr *fattr = NULL;
struct dentry *ret;
struct inode *inode;
void *name = kstrdup(devname, GFP_KERNEL);
int error;

dprintk("--> nfs4_get_root()\n");

if (!name)
return ERR_PTR(-ENOMEM);

/* get the info about the server and filesystem */
error = nfs4_server_capabilities(server, mntfh);
if (error < 0) {
dprintk("nfs_get_root: getcaps error = %d\n",
-error);
kfree(name);
return ERR_PTR(error);
}

fattr = nfs_alloc_fattr();
if (fattr == NULL)
return ERR_PTR(-ENOMEM);;
if (fattr == NULL) {
kfree(name);
return ERR_PTR(-ENOMEM);
}

/* get the actual root for this mount */
error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr);
Expand Down Expand Up @@ -223,8 +246,15 @@ struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh)
}

security_d_instantiate(ret, inode);

spin_lock(&ret->d_lock);
if (IS_ROOT(ret) && !(ret->d_flags & DCACHE_NFSFS_RENAMED)) {
ret->d_fsdata = name;
name = NULL;
}
spin_unlock(&ret->d_lock);
out:
if (name)
kfree(name);
nfs_free_fattr(fattr);
dprintk("<-- nfs4_get_root()\n");
return ret;
Expand Down
21 changes: 10 additions & 11 deletions fs/nfs/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ static inline void nfs_fs_proc_exit(void)

/* nfs4namespace.c */
#ifdef CONFIG_NFS_V4
extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
extern struct vfsmount *nfs_do_refmount(struct dentry *dentry);
#else
static inline
struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
struct vfsmount *nfs_do_refmount(struct dentry *dentry)
{
return ERR_PTR(-ENOENT);
}
Expand Down Expand Up @@ -247,16 +247,16 @@ extern void nfs_sb_active(struct super_block *sb);
extern void nfs_sb_deactive(struct super_block *sb);

/* namespace.c */
extern char *nfs_path(const char *base,
const struct dentry *droot,
const struct dentry *dentry,
extern char *nfs_path(char **p, struct dentry *dentry,
char *buffer, ssize_t buflen);
extern struct vfsmount *nfs_d_automount(struct path *path);

/* getroot.c */
extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *,
const char *);
#ifdef CONFIG_NFS_V4
extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *,
const char *);

extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh);
#endif
Expand Down Expand Up @@ -288,12 +288,11 @@ extern int _nfs4_call_sync_session(struct nfs_server *server,
/*
* Determine the device name as a string
*/
static inline char *nfs_devname(const struct vfsmount *mnt_parent,
const struct dentry *dentry,
static inline char *nfs_devname(struct dentry *dentry,
char *buffer, ssize_t buflen)
{
return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root,
dentry, buffer, buflen);
char *dummy;
return nfs_path(&dummy, dentry, buffer, buflen);
}

/*
Expand Down
Loading

0 comments on commit 054cfaa

Please sign in to comment.