NFS: Add timeout to submounts
[deliverable/linux.git] / fs / nfs / inode.c
index cc753928e4116cc6d54f8543aea288ebb2dcd4d6..3eea556d8f59274abe631527b4aa1c05bcdf60a6 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/unistd.h>
 #include <linux/sunrpc/clnt.h>
 #include <linux/sunrpc/stats.h>
+#include <linux/sunrpc/metrics.h>
 #include <linux/nfs_fs.h>
 #include <linux/nfs_mount.h>
 #include <linux/nfs4_mount.h>
@@ -40,7 +41,9 @@
 #include <asm/uaccess.h>
 
 #include "nfs4_fs.h"
+#include "callback.h"
 #include "delegation.h"
+#include "iostat.h"
 
 #define NFSDBG_FACILITY                NFSDBG_VFS
 #define NFS_PARANOIA 1
@@ -59,11 +62,11 @@ static int nfs_update_inode(struct inode *, struct nfs_fattr *);
 static struct inode *nfs_alloc_inode(struct super_block *sb);
 static void nfs_destroy_inode(struct inode *);
 static int nfs_write_inode(struct inode *,int);
-static void nfs_delete_inode(struct inode *);
 static void nfs_clear_inode(struct inode *);
-static void nfs_umount_begin(struct super_block *);
+static void nfs_umount_begin(struct vfsmount *, int);
 static int  nfs_statfs(struct super_block *, struct kstatfs *);
 static int  nfs_show_options(struct seq_file *, struct vfsmount *);
+static int  nfs_show_stats(struct seq_file *, struct vfsmount *);
 static void nfs_zap_acl_cache(struct inode *);
 
 static struct rpc_program      nfs_program;
@@ -72,11 +75,11 @@ static struct super_operations nfs_sops = {
        .alloc_inode    = nfs_alloc_inode,
        .destroy_inode  = nfs_destroy_inode,
        .write_inode    = nfs_write_inode,
-       .delete_inode   = nfs_delete_inode,
        .statfs         = nfs_statfs,
        .clear_inode    = nfs_clear_inode,
        .umount_begin   = nfs_umount_begin,
        .show_options   = nfs_show_options,
+       .show_stats     = nfs_show_stats,
 };
 
 /*
@@ -102,7 +105,7 @@ static struct rpc_version * nfs_version[] = {
 static struct rpc_program      nfs_program = {
        .name                   = "nfs",
        .number                 = NFS_PROGRAM,
-       .nrvers                 = sizeof(nfs_version) / sizeof(nfs_version[0]),
+       .nrvers                 = ARRAY_SIZE(nfs_version),
        .version                = nfs_version,
        .stats                  = &nfs_rpcstat,
        .pipe_dir_name          = "/nfs",
@@ -117,7 +120,7 @@ static struct rpc_version * nfsacl_version[] = {
 struct rpc_program             nfsacl_program = {
        .name =                 "nfsacl",
        .number =               NFS_ACL_PROGRAM,
-       .nrvers =               sizeof(nfsacl_version) / sizeof(nfsacl_version[0]),
+       .nrvers =               ARRAY_SIZE(nfsacl_version),
        .version =              nfsacl_version,
        .stats =                &nfsacl_rpcstat,
 };
@@ -132,7 +135,7 @@ nfs_fattr_to_ino_t(struct nfs_fattr *fattr)
 static int
 nfs_write_inode(struct inode *inode, int sync)
 {
-       int flags = sync ? FLUSH_WAIT : 0;
+       int flags = sync ? FLUSH_SYNC : 0;
        int ret;
 
        ret = nfs_commit_inode(inode, flags);
@@ -141,31 +144,16 @@ nfs_write_inode(struct inode *inode, int sync)
        return 0;
 }
 
-static void
-nfs_delete_inode(struct inode * inode)
-{
-       dprintk("NFS: delete_inode(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino);
-
-       truncate_inode_pages(&inode->i_data, 0);
-
-       nfs_wb_all(inode);
-       /*
-        * The following should never happen...
-        */
-       if (nfs_have_writebacks(inode)) {
-               printk(KERN_ERR "nfs_delete_inode: inode %ld has pending RPC requests\n", inode->i_ino);
-       }
-
-       clear_inode(inode);
-}
-
 static void
 nfs_clear_inode(struct inode *inode)
 {
        struct nfs_inode *nfsi = NFS_I(inode);
        struct rpc_cred *cred;
 
-       nfs_wb_all(inode);
+       /*
+        * The following should never happen...
+        */
+       BUG_ON(nfs_have_writebacks(inode));
        BUG_ON (!list_empty(&nfsi->open_files));
        nfs_zap_acl_cache(inode);
        cred = nfsi->cache_access.cred;
@@ -174,15 +162,20 @@ nfs_clear_inode(struct inode *inode)
        BUG_ON(atomic_read(&nfsi->data_updates) != 0);
 }
 
-void
-nfs_umount_begin(struct super_block *sb)
+static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
 {
-       struct rpc_clnt *rpc = NFS_SB(sb)->client;
+       struct nfs_server *server;
+       struct rpc_clnt *rpc;
 
+       shrink_submounts(vfsmnt, &nfs_automount_list);
+       if (!(flags & MNT_FORCE))
+               return;
        /* -EIO all pending I/O */
+       server = NFS_SB(vfsmnt->mnt_sb);
+       rpc = server->client;
        if (!IS_ERR(rpc))
                rpc_killall_tasks(rpc);
-       rpc = NFS_SB(sb)->client_acl;
+       rpc = server->client_acl;
        if (!IS_ERR(rpc))
                rpc_killall_tasks(rpc);
 }
@@ -221,14 +214,22 @@ nfs_calc_block_size(u64 tsize)
 static inline unsigned long
 nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
 {
-       if (bsize < 1024)
-               bsize = NFS_DEF_FILE_IO_BUFFER_SIZE;
-       else if (bsize >= NFS_MAX_FILE_IO_BUFFER_SIZE)
-               bsize = NFS_MAX_FILE_IO_BUFFER_SIZE;
+       if (bsize < NFS_MIN_FILE_IO_SIZE)
+               bsize = NFS_DEF_FILE_IO_SIZE;
+       else if (bsize >= NFS_MAX_FILE_IO_SIZE)
+               bsize = NFS_MAX_FILE_IO_SIZE;
 
        return nfs_block_bits(bsize, nrbitsp);
 }
 
+static inline void
+nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
+{
+       sb->s_maxbytes = (loff_t)maxfilesize;
+       if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
+               sb->s_maxbytes = MAX_LFS_FILESIZE;
+}
+
 /*
  * Obtain the root inode of the file system.
  */
@@ -236,7 +237,6 @@ static struct inode *
 nfs_get_root(struct super_block *sb, struct nfs_fh *rootfh, struct nfs_fsinfo *fsinfo)
 {
        struct nfs_server       *server = NFS_SB(sb);
-       struct inode *rooti;
        int                     error;
 
        error = server->rpc_ops->getroot(server, rootfh, fsinfo);
@@ -245,10 +245,8 @@ nfs_get_root(struct super_block *sb, struct nfs_fh *rootfh, struct nfs_fsinfo *f
                return ERR_PTR(error);
        }
 
-       rooti = nfs_fhget(sb, rootfh, fsinfo->fattr);
-       if (!rooti)
-               return ERR_PTR(-ENOMEM);
-       return rooti;
+       server->fsid = fsinfo->fattr->fsid;
+       return nfs_fhget(sb, rootfh, fsinfo->fattr);
 }
 
 /*
@@ -276,6 +274,10 @@ nfs_sb_init(struct super_block *sb, rpc_authflavor_t authflavor)
 
        sb->s_magic      = NFS_SUPER_MAGIC;
 
+       server->io_stats = nfs_alloc_iostats();
+       if (server->io_stats == NULL)
+               return -ENOMEM;
+
        root_inode = nfs_get_root(sb, &server->fh, &fsinfo);
        /* Did getting the root inode fail? */
        if (IS_ERR(root_inode)) {
@@ -289,6 +291,9 @@ nfs_sb_init(struct super_block *sb, rpc_authflavor_t authflavor)
        }
        sb->s_root->d_op = server->rpc_ops->dentry_ops;
 
+       /* mount time stamp, in seconds */
+       server->mount_time = jiffies;
+
        /* Get some general file system info */
        if (server->namelen == 0 &&
            server->rpc_ops->pathconf(server, &server->fh, &pathinfo) >= 0)
@@ -307,20 +312,15 @@ nfs_sb_init(struct super_block *sb, rpc_authflavor_t authflavor)
        max_rpc_payload = nfs_block_size(rpc_max_payload(server->client), NULL);
        if (server->rsize > max_rpc_payload)
                server->rsize = max_rpc_payload;
-       if (server->wsize > max_rpc_payload)
-               server->wsize = max_rpc_payload;
-
+       if (server->rsize > NFS_MAX_FILE_IO_SIZE)
+               server->rsize = NFS_MAX_FILE_IO_SIZE;
        server->rpages = (server->rsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
-       if (server->rpages > NFS_READ_MAXIOV) {
-               server->rpages = NFS_READ_MAXIOV;
-               server->rsize = server->rpages << PAGE_CACHE_SHIFT;
-       }
 
+       if (server->wsize > max_rpc_payload)
+               server->wsize = max_rpc_payload;
+       if (server->wsize > NFS_MAX_FILE_IO_SIZE)
+               server->wsize = NFS_MAX_FILE_IO_SIZE;
        server->wpages = (server->wsize + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
-        if (server->wpages > NFS_WRITE_MAXIOV) {
-               server->wpages = NFS_WRITE_MAXIOV;
-                server->wsize = server->wpages << PAGE_CACHE_SHIFT;
-       }
 
        if (sb->s_blocksize == 0)
                sb->s_blocksize = nfs_block_bits(server->wsize,
@@ -340,9 +340,7 @@ nfs_sb_init(struct super_block *sb, rpc_authflavor_t authflavor)
        }
        server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD;
 
-       sb->s_maxbytes = fsinfo.maxfilesize;
-       if (sb->s_maxbytes > MAX_LFS_FILESIZE) 
-               sb->s_maxbytes = MAX_LFS_FILESIZE; 
+       nfs_super_set_maxbytes(sb, fsinfo.maxfilesize);
 
        server->client->cl_intr = (server->flags & NFS_MOUNT_INTR) ? 1 : 0;
        server->client->cl_softrtry = (server->flags & NFS_MOUNT_SOFT) ? 1 : 0;
@@ -400,6 +398,9 @@ nfs_create_client(struct nfs_server *server, const struct nfs_mount_data *data)
 
        nfs_init_timeout_values(&timeparms, proto, data->timeo, data->retrans);
 
+       server->retrans_timeo = timeparms.to_initval;
+       server->retrans_count = timeparms.to_retries;
+
        /* create transport and client */
        xprt = xprt_create_proto(proto, &server->addr, &timeparms);
        if (IS_ERR(xprt)) {
@@ -417,7 +418,6 @@ nfs_create_client(struct nfs_server *server, const struct nfs_mount_data *data)
 
        clnt->cl_intr     = 1;
        clnt->cl_softrtry = 1;
-       clnt->cl_chatty   = 1;
 
        return clnt;
 
@@ -584,7 +584,7 @@ nfs_statfs(struct super_block *sb, struct kstatfs *buf)
 
 }
 
-static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
+static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
 {
        static struct proc_nfs_info {
                int flag;
@@ -593,28 +593,26 @@ static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
        } nfs_info[] = {
                { NFS_MOUNT_SOFT, ",soft", ",hard" },
                { NFS_MOUNT_INTR, ",intr", "" },
-               { NFS_MOUNT_POSIX, ",posix", "" },
                { NFS_MOUNT_NOCTO, ",nocto", "" },
                { NFS_MOUNT_NOAC, ",noac", "" },
-               { NFS_MOUNT_NONLM, ",nolock", ",lock" },
+               { NFS_MOUNT_NONLM, ",nolock", "" },
                { NFS_MOUNT_NOACL, ",noacl", "" },
                { 0, NULL, NULL }
        };
        struct proc_nfs_info *nfs_infop;
-       struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
        char buf[12];
        char *proto;
 
-       seq_printf(m, ",v%d", nfss->rpc_ops->version);
+       seq_printf(m, ",vers=%d", nfss->rpc_ops->version);
        seq_printf(m, ",rsize=%d", nfss->rsize);
        seq_printf(m, ",wsize=%d", nfss->wsize);
-       if (nfss->acregmin != 3*HZ)
+       if (nfss->acregmin != 3*HZ || showdefaults)
                seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
-       if (nfss->acregmax != 60*HZ)
+       if (nfss->acregmax != 60*HZ || showdefaults)
                seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
-       if (nfss->acdirmin != 30*HZ)
+       if (nfss->acdirmin != 30*HZ || showdefaults)
                seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ);
-       if (nfss->acdirmax != 60*HZ)
+       if (nfss->acdirmax != 60*HZ || showdefaults)
                seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ);
        for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
                if (nfss->flags & nfs_infop->flag)
@@ -634,8 +632,93 @@ static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
                        proto = buf;
        }
        seq_printf(m, ",proto=%s", proto);
+       seq_printf(m, ",timeo=%lu", 10U * nfss->retrans_timeo / HZ);
+       seq_printf(m, ",retrans=%u", nfss->retrans_count);
+}
+
+static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
+{
+       struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
+
+       nfs_show_mount_options(m, nfss, 0);
+
        seq_puts(m, ",addr=");
        seq_escape(m, nfss->hostname, " \t\n\\");
+
+       return 0;
+}
+
+static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
+{
+       int i, cpu;
+       struct nfs_server *nfss = NFS_SB(mnt->mnt_sb);
+       struct rpc_auth *auth = nfss->client->cl_auth;
+       struct nfs_iostats totals = { };
+
+       seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
+
+       /*
+        * Display all mount option settings
+        */
+       seq_printf(m, "\n\topts:\t");
+       seq_puts(m, mnt->mnt_sb->s_flags & MS_RDONLY ? "ro" : "rw");
+       seq_puts(m, mnt->mnt_sb->s_flags & MS_SYNCHRONOUS ? ",sync" : "");
+       seq_puts(m, mnt->mnt_sb->s_flags & MS_NOATIME ? ",noatime" : "");
+       seq_puts(m, mnt->mnt_sb->s_flags & MS_NODIRATIME ? ",nodiratime" : "");
+       nfs_show_mount_options(m, nfss, 1);
+
+       seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
+
+       seq_printf(m, "\n\tcaps:\t");
+       seq_printf(m, "caps=0x%x", nfss->caps);
+       seq_printf(m, ",wtmult=%d", nfss->wtmult);
+       seq_printf(m, ",dtsize=%d", nfss->dtsize);
+       seq_printf(m, ",bsize=%d", nfss->bsize);
+       seq_printf(m, ",namelen=%d", nfss->namelen);
+
+#ifdef CONFIG_NFS_V4
+       if (nfss->rpc_ops->version == 4) {
+               seq_printf(m, "\n\tnfsv4:\t");
+               seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
+               seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
+               seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
+       }
+#endif
+
+       /*
+        * Display security flavor in effect for this mount
+        */
+       seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor);
+       if (auth->au_flavor)
+               seq_printf(m, ",pseudoflavor=%d", auth->au_flavor);
+
+       /*
+        * Display superblock I/O counters
+        */
+       for_each_possible_cpu(cpu) {
+               struct nfs_iostats *stats;
+
+               preempt_disable();
+               stats = per_cpu_ptr(nfss->io_stats, cpu);
+
+               for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
+                       totals.events[i] += stats->events[i];
+               for (i = 0; i < __NFSIOS_BYTESMAX; i++)
+                       totals.bytes[i] += stats->bytes[i];
+
+               preempt_enable();
+       }
+
+       seq_printf(m, "\n\tevents:\t");
+       for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
+               seq_printf(m, "%lu ", totals.events[i]);
+       seq_printf(m, "\n\tbytes:\t");
+       for (i = 0; i < __NFSIOS_BYTESMAX; i++)
+               seq_printf(m, "%Lu ", totals.bytes[i]);
+       seq_printf(m, "\n");
+
+       rpc_print_iostats(m, nfss->client);
+
        return 0;
 }
 
@@ -649,10 +732,7 @@ int nfs_sync_mapping(struct address_space *mapping)
        if (mapping->nrpages == 0)
                return 0;
        unmap_mapping_range(mapping, 0, 0, 0);
-       ret = filemap_fdatawrite(mapping);
-       if (ret != 0)
-               goto out;
-       ret = filemap_fdatawait(mapping);
+       ret = filemap_write_and_wait(mapping);
        if (ret != 0)
                goto out;
        ret = nfs_wb_all(mapping->host);
@@ -668,6 +748,8 @@ static void nfs_zap_caches_locked(struct inode *inode)
        struct nfs_inode *nfsi = NFS_I(inode);
        int mode = inode->i_mode;
 
+       nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
+
        NFS_ATTRTIMEO(inode) = NFS_MINATTRTIMEO(inode);
        NFS_ATTRTIMEO_UPDATE(inode) = jiffies;
 
@@ -759,7 +841,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
                .fh     = fh,
                .fattr  = fattr
        };
-       struct inode *inode = NULL;
+       struct inode *inode = ERR_PTR(-ENOENT);
        unsigned long hash;
 
        if ((fattr->valid & NFS_ATTR_FATTR) == 0)
@@ -772,8 +854,11 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
 
        hash = nfs_fattr_to_ino_t(fattr);
 
-       if (!(inode = iget5_locked(sb, hash, nfs_find_actor, nfs_init_locked, &desc)))
+       inode = iget5_locked(sb, hash, nfs_find_actor, nfs_init_locked, &desc);
+       if (inode == NULL) {
+               inode = ERR_PTR(-ENOMEM);
                goto out_no_inode;
+       }
 
        if (inode->i_state & I_NEW) {
                struct nfs_inode *nfsi = NFS_I(inode);
@@ -799,6 +884,11 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
                        if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS)
                            && fattr->size <= NFS_LIMIT_READDIRPLUS)
                                set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_FLAGS(inode));
+                       /* Deal with crossing mountpoints */
+                       if (!nfs_fsid_equal(&NFS_SB(sb)->fsid, &fattr->fsid)) {
+                               inode->i_op = &nfs_mountpoint_inode_operations;
+                               inode->i_fop = NULL;
+                       }
                } else if (S_ISLNK(inode->i_mode))
                        inode->i_op = &nfs_symlink_inode_operations;
                else
@@ -842,7 +932,7 @@ out:
        return inode;
 
 out_no_inode:
-       printk("nfs_fhget: iget failed\n");
+       dprintk("nfs_fhget: iget failed with error %ld\n", PTR_ERR(inode));
        goto out;
 }
 
@@ -855,6 +945,8 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
        struct nfs_fattr fattr;
        int error;
 
+       nfs_inc_stats(inode, NFSIOS_VFSSETATTR);
+
        if (attr->ia_valid & ATTR_SIZE) {
                if (!S_ISREG(inode->i_mode) || attr->ia_size == i_size_read(inode))
                        attr->ia_valid &= ~ATTR_SIZE;
@@ -867,12 +959,9 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
 
        lock_kernel();
        nfs_begin_data_update(inode);
-       /* Write all dirty data if we're changing file permissions or size */
-       if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE)) != 0) {
-               if (filemap_fdatawrite(inode->i_mapping) == 0)
-                       filemap_fdatawait(inode->i_mapping);
-               nfs_wb_all(inode);
-       }
+       /* Write all dirty data */
+       filemap_write_and_wait(inode->i_mapping);
+       nfs_wb_all(inode);
        /*
         * Return any delegations if we're going to change ACLs
         */
@@ -911,6 +1000,7 @@ void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr)
                spin_unlock(&inode->i_lock);
        }
        if ((attr->ia_valid & ATTR_SIZE) != 0) {
+               nfs_inc_stats(inode, NFSIOS_SETATTRTRUNC);
                inode->i_size = attr->ia_size;
                vmtruncate(inode, attr->ia_size);
        }
@@ -957,11 +1047,22 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
        int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME;
        int err;
 
-       if (__IS_FLG(inode, MS_NOATIME))
-               need_atime = 0;
-       else if (__IS_FLG(inode, MS_NODIRATIME) && S_ISDIR(inode->i_mode))
+       /* Flush out writes to the server in order to update c/mtime */
+       nfs_sync_inode_wait(inode, 0, 0, FLUSH_NOCOMMIT);
+
+       /*
+        * We may force a getattr if the user cares about atime.
+        *
+        * Note that we only have to check the vfsmount flags here:
+        *  - NFS always sets S_NOATIME by so checking it would give a
+        *    bogus result
+        *  - NFS never sets MS_NOATIME or MS_NODIRATIME so there is
+        *    no point in checking those.
+        */
+       if ((mnt->mnt_flags & MNT_NOATIME) ||
+           ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
                need_atime = 0;
-       /* We may force a getattr if the user cares about atime */
+
        if (need_atime)
                err = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
        else
@@ -971,7 +1072,7 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
        return err;
 }
 
-struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, struct rpc_cred *cred)
+static struct nfs_open_context *alloc_nfs_open_context(struct vfsmount *mnt, struct dentry *dentry, struct rpc_cred *cred)
 {
        struct nfs_open_context *ctx;
 
@@ -979,6 +1080,7 @@ struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, struct rp
        if (ctx != NULL) {
                atomic_set(&ctx->count, 1);
                ctx->dentry = dget(dentry);
+               ctx->vfsmnt = mntget(mnt);
                ctx->cred = get_rpccred(cred);
                ctx->state = NULL;
                ctx->lockowner = current->files;
@@ -1009,6 +1111,7 @@ void put_nfs_open_context(struct nfs_open_context *ctx)
                if (ctx->cred != NULL)
                        put_rpccred(ctx->cred);
                dput(ctx->dentry);
+               mntput(ctx->vfsmnt);
                kfree(ctx);
        }
 }
@@ -1017,7 +1120,7 @@ void put_nfs_open_context(struct nfs_open_context *ctx)
  * Ensure that mmap has a recent RPC credential for use when writing out
  * shared pages
  */
-void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx)
+static void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx)
 {
        struct inode *inode = filp->f_dentry->d_inode;
        struct nfs_inode *nfsi = NFS_I(inode);
@@ -1049,7 +1152,7 @@ struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_c
        return ctx;
 }
 
-void nfs_file_clear_open_context(struct file *filp)
+static void nfs_file_clear_open_context(struct file *filp)
 {
        struct inode *inode = filp->f_dentry->d_inode;
        struct nfs_open_context *ctx = (struct nfs_open_context *)filp->private_data;
@@ -1074,7 +1177,7 @@ int nfs_open(struct inode *inode, struct file *filp)
        cred = rpcauth_lookupcred(NFS_CLIENT(inode)->cl_auth, 0);
        if (IS_ERR(cred))
                return PTR_ERR(cred);
-       ctx = alloc_nfs_open_context(filp->f_dentry, cred);
+       ctx = alloc_nfs_open_context(filp->f_vfsmnt, filp->f_dentry, cred);
        put_rpccred(cred);
        if (ctx == NULL)
                return -ENOMEM;
@@ -1104,6 +1207,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
        dfprintk(PAGECACHE, "NFS: revalidating (%s/%Ld)\n",
                inode->i_sb->s_id, (long long)NFS_FILEID(inode));
 
+       nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE);
        lock_kernel();
        if (!inode || is_bad_inode(inode))
                goto out_nowait;
@@ -1117,7 +1221,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
                status = -ESTALE;
                /* Do we trust the cached ESTALE? */
                if (NFS_ATTRTIMEO(inode) != 0) {
-                       if (nfsi->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ATIME)) {
+                       if (nfsi->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME)) {
                                /* no */
                        } else
                                goto out;
@@ -1148,8 +1252,6 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
        }
        spin_unlock(&inode->i_lock);
 
-       nfs_revalidate_mapping(inode, inode->i_mapping);
-
        if (nfsi->cache_validity & NFS_INO_INVALID_ACL)
                nfs_zap_acl_cache(inode);
 
@@ -1183,7 +1285,7 @@ int nfs_attribute_timeout(struct inode *inode)
  */
 int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
 {
-       if (!(NFS_I(inode)->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA))
+       if (!(NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATTR)
                        && !nfs_attribute_timeout(inode))
                return NFS_STALE(inode) ? -ESTALE : 0;
        return __nfs_revalidate_inode(server, inode);
@@ -1194,11 +1296,19 @@ int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
  * @inode - pointer to host inode
  * @mapping - pointer to mapping
  */
-void nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
+int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
 {
        struct nfs_inode *nfsi = NFS_I(inode);
+       int ret = 0;
+
+       if (NFS_STALE(inode))
+               ret = -ESTALE;
+       if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
+                       || nfs_attribute_timeout(inode))
+               ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
 
        if (nfsi->cache_validity & NFS_INO_INVALID_DATA) {
+               nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE);
                if (S_ISREG(inode->i_mode))
                        nfs_sync_mapping(mapping);
                invalidate_inode_pages2(mapping);
@@ -1216,6 +1326,7 @@ void nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
                                inode->i_sb->s_id,
                                (long long)NFS_FILEID(inode));
        }
+       return ret;
 }
 
 /**
@@ -1251,6 +1362,27 @@ void nfs_end_data_update(struct inode *inode)
        atomic_dec(&nfsi->data_updates);
 }
 
+static void nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr *fattr)
+{
+       struct nfs_inode *nfsi = NFS_I(inode);
+
+       /* If we have atomic WCC data, we may update some attributes */
+       if ((fattr->valid & NFS_ATTR_WCC) != 0) {
+               if (timespec_equal(&inode->i_ctime, &fattr->pre_ctime)) {
+                       memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
+                       nfsi->cache_change_attribute = jiffies;
+               }
+               if (timespec_equal(&inode->i_mtime, &fattr->pre_mtime)) {
+                       memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
+                       nfsi->cache_change_attribute = jiffies;
+               }
+               if (inode->i_size == fattr->pre_size && nfsi->npages == 0) {
+                       inode->i_size = fattr->size;
+                       nfsi->cache_change_attribute = jiffies;
+               }
+       }
+}
+
 /**
  * nfs_check_inode_attributes - verify consistency of the inode attribute cache
  * @inode - pointer to inode
@@ -1267,52 +1399,30 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
        int data_unstable;
 
 
-       /* Are we in the process of updating data on the server? */
-       data_unstable = nfs_caches_unstable(inode);
-
-       if (fattr->valid & NFS_ATTR_FATTR_V4) {
-               if ((fattr->valid & NFS_ATTR_PRE_CHANGE) != 0
-                               && nfsi->change_attr == fattr->pre_change_attr)
-                       nfsi->change_attr = fattr->change_attr;
-               if (nfsi->change_attr != fattr->change_attr) {
-                       nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
-                       if (!data_unstable)
-                               nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE;
-               }
-       }
-
-       if ((fattr->valid & NFS_ATTR_FATTR) == 0) {
-               return 0;
-       }
-
        /* Has the inode gone and changed behind our back? */
        if (nfsi->fileid != fattr->fileid
                        || (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT)) {
                return -EIO;
        }
 
-       cur_size = i_size_read(inode);
-       new_isize = nfs_size_to_loff_t(fattr->size);
+       /* Are we in the process of updating data on the server? */
+       data_unstable = nfs_caches_unstable(inode);
 
-       /* If we have atomic WCC data, we may update some attributes */
-       if ((fattr->valid & NFS_ATTR_WCC) != 0) {
-               if (timespec_equal(&inode->i_ctime, &fattr->pre_ctime))
-                       memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
-               if (timespec_equal(&inode->i_mtime, &fattr->pre_mtime))
-                       memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
-       }
+       /* Do atomic weak cache consistency updates */
+       nfs_wcc_update_inode(inode, fattr);
+
+       if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0 &&
+                       nfsi->change_attr != fattr->change_attr)
+               nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
 
        /* Verify a few of the more important attributes */
-       if (!timespec_equal(&inode->i_mtime, &fattr->mtime)) {
-               nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
-               if (!data_unstable)
-                       nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE;
-       }
-       if (cur_size != new_isize) {
-               nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
-               if (nfsi->npages == 0)
-                       nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE;
-       }
+       if (!timespec_equal(&inode->i_mtime, &fattr->mtime))
+               nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
+
+       cur_size = i_size_read(inode);
+       new_isize = nfs_size_to_loff_t(fattr->size);
+       if (cur_size != new_isize && nfsi->npages == 0)
+               nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
 
        /* Have any file permissions changed? */
        if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
@@ -1349,7 +1459,6 @@ int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
        if ((fattr->valid & NFS_ATTR_FATTR) == 0)
                return 0;
        spin_lock(&inode->i_lock);
-       nfsi->cache_validity &= ~NFS_INO_REVAL_PAGECACHE;
        if (time_after(fattr->time_start, nfsi->last_updated))
                status = nfs_update_inode(inode, fattr);
        else
@@ -1374,7 +1483,7 @@ int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr)
 
        spin_lock(&inode->i_lock);
        if (unlikely((fattr->valid & NFS_ATTR_FATTR) == 0)) {
-               nfsi->cache_validity |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS;
+               nfsi->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
                goto out;
        }
        status = nfs_update_inode(inode, fattr);
@@ -1397,6 +1506,7 @@ out:
  */
 static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
 {
+       struct nfs_server *server;
        struct nfs_inode *nfsi = NFS_I(inode);
        loff_t cur_isize, new_isize;
        unsigned int    invalid = 0;
@@ -1406,17 +1516,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
                        __FUNCTION__, inode->i_sb->s_id, inode->i_ino,
                        atomic_read(&inode->i_count), fattr->valid);
 
-       if ((fattr->valid & NFS_ATTR_FATTR) == 0)
-               return 0;
-
-       if (nfsi->fileid != fattr->fileid) {
-               printk(KERN_ERR "%s: inode number mismatch\n"
-                      "expected (%s/0x%Lx), got (%s/0x%Lx)\n",
-                      __FUNCTION__,
-                      inode->i_sb->s_id, (long long)nfsi->fileid,
-                      inode->i_sb->s_id, (long long)fattr->fileid);
-               goto out_err;
-       }
+       if (nfsi->fileid != fattr->fileid)
+               goto out_fileid;
 
        /*
         * Make sure the inode's type hasn't changed.
@@ -1424,6 +1525,12 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
        if ((inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT))
                goto out_changed;
 
+       server = NFS_SERVER(inode);
+       /* Update the fsid if and only if this is the root directory */
+       if (inode == inode->i_sb->s_root->d_inode
+                       && !nfs_fsid_equal(&server->fsid, &fattr->fsid))
+               server->fsid = fattr->fsid;
+
        /*
         * Update the read time so we don't revalidate too often.
         */
@@ -1433,7 +1540,10 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
        /* Are we racing with known updates of the metadata on the server? */
        data_stable = nfs_verify_change_attribute(inode, fattr->time_start);
        if (data_stable)
-               nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME);
+               nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_ATIME);
+
+       /* Do atomic weak cache consistency updates */
+       nfs_wcc_update_inode(inode, fattr);
 
        /* Check if our cached file size is stale */
        new_isize = nfs_size_to_loff_t(fattr->size);
@@ -1465,15 +1575,6 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
                nfsi->cache_change_attribute = jiffies;
        }
 
-       if ((fattr->valid & NFS_ATTR_FATTR_V4)
-           && nfsi->change_attr != fattr->change_attr) {
-               dprintk("NFS: change_attr change on server for file %s/%ld\n",
-                      inode->i_sb->s_id, inode->i_ino);
-               nfsi->change_attr = fattr->change_attr;
-               invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
-               nfsi->cache_change_attribute = jiffies;
-       }
-
        /* If ctime has changed we should definitely clear access+acl caches */
        if (!timespec_equal(&inode->i_ctime, &fattr->ctime)) {
                invalid |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
@@ -1503,8 +1604,18 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
                inode->i_blksize = fattr->du.nfs2.blocksize;
        }
 
+       if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0 &&
+                       nfsi->change_attr != fattr->change_attr) {
+               dprintk("NFS: change_attr change on server for file %s/%ld\n",
+                               inode->i_sb->s_id, inode->i_ino);
+               nfsi->change_attr = fattr->change_attr;
+               invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
+               nfsi->cache_change_attribute = jiffies;
+       }
+
        /* Update attrtimeo value if we're out of the unstable period */
        if (invalid & NFS_INO_INVALID_ATTR) {
+               nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
                nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
                nfsi->attrtimeo_timestamp = jiffies;
        } else if (time_after(jiffies, nfsi->attrtimeo_timestamp+nfsi->attrtimeo)) {
@@ -1538,12 +1649,154 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
         */
        nfs_invalidate_inode(inode);
        return -ESTALE;
+
+ out_fileid:
+       printk(KERN_ERR "NFS: server %s error: fileid changed\n"
+               "fsid %s: expected fileid 0x%Lx, got 0x%Lx\n",
+               NFS_SERVER(inode)->hostname, inode->i_sb->s_id,
+               (long long)nfsi->fileid, (long long)fattr->fileid);
+       goto out_err;
 }
 
 /*
  * File system information
  */
 
+/*
+ * nfs_path - reconstruct the path given an arbitrary dentry
+ * @base - arbitrary string to prepend to the path
+ * @dentry - pointer to dentry
+ * @buffer - result buffer
+ * @buflen - length of buffer
+ *
+ * Helper function for constructing the path from the
+ * root dentry to an arbitrary hashed dentry.
+ *
+ * This is mainly for use in figuring out the path on the
+ * server side when automounting on top of an existing partition.
+ */
+static char *nfs_path(const char *base, const struct dentry *dentry,
+                     char *buffer, ssize_t buflen)
+{
+       char *end = buffer+buflen;
+       int namelen;
+
+       *--end = '\0';
+       buflen--;
+       spin_lock(&dcache_lock);
+       while (!IS_ROOT(dentry)) {
+               namelen = dentry->d_name.len;
+               buflen -= namelen + 1;
+               if (buflen < 0)
+                       goto Elong;
+               end -= namelen;
+               memcpy(end, dentry->d_name.name, namelen);
+               *--end = '/';
+               dentry = dentry->d_parent;
+       }
+       spin_unlock(&dcache_lock);
+       namelen = strlen(base);
+       /* Strip off excess slashes in base string */
+       while (namelen > 0 && base[namelen - 1] == '/')
+               namelen--;
+       buflen -= namelen;
+       if (buflen < 0)
+               goto Elong;
+       end -= namelen;
+       memcpy(end, base, namelen);
+       return end;
+Elong:
+       return ERR_PTR(-ENAMETOOLONG);
+}
+
+struct nfs_clone_mount {
+       const struct super_block *sb;
+       const struct dentry *dentry;
+       struct nfs_fh *fh;
+       struct nfs_fattr *fattr;
+};
+
+static struct super_block *nfs_clone_generic_sb(struct nfs_clone_mount *data,
+               struct super_block *(*clone_client)(struct nfs_server *, struct nfs_clone_mount *))
+{
+       struct nfs_server *server;
+       struct nfs_server *parent = NFS_SB(data->sb);
+       struct super_block *sb = ERR_PTR(-EINVAL);
+       void *err = ERR_PTR(-ENOMEM);
+       struct inode *root_inode;
+       struct nfs_fsinfo fsinfo;
+       int len;
+
+       server = kmalloc(sizeof(struct nfs_server), GFP_KERNEL);
+       if (server == NULL)
+               goto out_err;
+       memcpy(server, parent, sizeof(*server));
+       len = strlen(parent->hostname) + 1;
+       server->hostname = kmalloc(len, GFP_KERNEL);
+       if (server->hostname == NULL)
+               goto free_server;
+       memcpy(server->hostname, parent->hostname, len);
+       server->fsid = data->fattr->fsid;
+       nfs_copy_fh(&server->fh, data->fh);
+       if (rpciod_up() != 0)
+               goto free_hostname;
+
+       sb = clone_client(server, data);
+       if (IS_ERR((err = sb)) || sb->s_root)
+               goto kill_rpciod;
+
+       sb->s_op = data->sb->s_op;
+       sb->s_blocksize = data->sb->s_blocksize;
+       sb->s_blocksize_bits = data->sb->s_blocksize_bits;
+       sb->s_maxbytes = data->sb->s_maxbytes;
+
+       server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
+       err = ERR_PTR(-ENOMEM);
+       server->io_stats = nfs_alloc_iostats();
+       if (server->io_stats == NULL)
+               goto out_deactivate;
+
+       server->client = rpc_clone_client(parent->client);
+       if (IS_ERR((err = server->client)))
+               goto out_deactivate;
+       if (!IS_ERR(parent->client_sys)) {
+               server->client_sys = rpc_clone_client(parent->client_sys);
+               if (IS_ERR((err = server->client_sys)))
+                       goto out_deactivate;
+       }
+       if (!IS_ERR(parent->client_acl)) {
+               server->client_acl = rpc_clone_client(parent->client_acl);
+               if (IS_ERR((err = server->client_acl)))
+                       goto out_deactivate;
+       }
+       root_inode = nfs_fhget(sb, data->fh, data->fattr);
+       if (!root_inode)
+               goto out_deactivate;
+       sb->s_root = d_alloc_root(root_inode);
+       if (!sb->s_root)
+               goto out_put_root;
+       fsinfo.fattr = data->fattr;
+       if (NFS_PROTO(root_inode)->fsinfo(server, data->fh, &fsinfo) == 0)
+               nfs_super_set_maxbytes(sb, fsinfo.maxfilesize);
+       sb->s_root->d_op = server->rpc_ops->dentry_ops;
+       sb->s_flags |= MS_ACTIVE;
+       return sb;
+out_put_root:
+       iput(root_inode);
+out_deactivate:
+       up_write(&sb->s_umount);
+       deactivate_super(sb);
+       return (struct super_block *)err;
+kill_rpciod:
+       rpciod_down();
+free_hostname:
+       kfree(server->hostname);
+free_server:
+       kfree(server);
+out_err:
+       return (struct super_block *)err;
+}
+
 static int nfs_set_super(struct super_block *s, void *data)
 {
        s->s_fs_info = data;
@@ -1614,10 +1867,9 @@ static struct super_block *nfs_get_sb(struct file_system_type *fs_type,
 #endif /* CONFIG_NFS_V3 */
 
        s = ERR_PTR(-ENOMEM);
-       server = kmalloc(sizeof(struct nfs_server), GFP_KERNEL);
+       server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
        if (!server)
                goto out_err;
-       memset(server, 0, sizeof(struct nfs_server));
        /* Zero out the NFS state stuff */
        init_nfsv4_state(server);
        server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
@@ -1656,7 +1908,7 @@ static struct super_block *nfs_get_sb(struct file_system_type *fs_type,
 
        s->s_flags = flags;
 
-       error = nfs_fill_super(s, data, flags & MS_VERBOSE ? 1 : 0);
+       error = nfs_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
        if (error) {
                up_write(&s->s_umount);
                deactivate_super(s);
@@ -1689,8 +1941,10 @@ static void nfs_kill_super(struct super_block *s)
 
        rpciod_down();          /* release rpciod */
 
+       nfs_free_iostats(server->io_stats);
        kfree(server->hostname);
        kfree(server);
+       nfs_release_automount_timer();
 }
 
 static struct file_system_type nfs_fs_type = {
@@ -1701,6 +1955,31 @@ static struct file_system_type nfs_fs_type = {
        .fs_flags       = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
 };
 
+static struct super_block *nfs_clone_client(struct nfs_server *server, struct nfs_clone_mount *data)
+{
+       struct super_block *sb;
+
+       sb = sget(&nfs_fs_type, nfs_compare_super, nfs_set_super, server);
+       if (!IS_ERR(sb) && sb->s_root == NULL && !(server->flags & NFS_MOUNT_NONLM))
+               lockd_up();
+       return sb;
+}
+
+static struct super_block *nfs_clone_nfs_sb(struct file_system_type *fs_type,
+               int flags, const char *dev_name, void *raw_data)
+{
+       struct nfs_clone_mount *data = raw_data;
+       return nfs_clone_generic_sb(data, nfs_clone_client);
+}
+
+static struct file_system_type clone_nfs_fs_type = {
+       .owner          = THIS_MODULE,
+       .name           = "nfs",
+       .get_sb         = nfs_clone_nfs_sb,
+       .kill_sb        = nfs_kill_super,
+       .fs_flags       = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
+};
+
 #ifdef CONFIG_NFS_V4
 
 static void nfs4_clear_inode(struct inode *);
@@ -1710,11 +1989,11 @@ static struct super_operations nfs4_sops = {
        .alloc_inode    = nfs_alloc_inode,
        .destroy_inode  = nfs_destroy_inode,
        .write_inode    = nfs_write_inode,
-       .delete_inode   = nfs_delete_inode,
        .statfs         = nfs_statfs,
        .clear_inode    = nfs4_clear_inode,
        .umount_begin   = nfs_umount_begin,
        .show_options   = nfs_show_options,
+       .show_stats     = nfs_show_stats,
 };
 
 /*
@@ -1777,6 +2056,9 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data,
 
        nfs_init_timeout_values(&timeparms, data->proto, data->timeo, data->retrans);
 
+       server->retrans_timeo = timeparms.to_initval;
+       server->retrans_count = timeparms.to_retries;
+
        clp = nfs4_get_client(&server->addr.sin_addr);
        if (!clp) {
                dprintk("%s: failed to create NFS4 client.\n", __FUNCTION__);
@@ -1819,7 +2101,6 @@ static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data,
                }
                clnt->cl_intr     = 1;
                clnt->cl_softrtry = 1;
-               clnt->cl_chatty   = 1;
                clp->cl_rpcclient = clnt;
                memcpy(clp->cl_ipaddr, server->ip_addr, sizeof(clp->cl_ipaddr));
                nfs_idmap_new(clp);
@@ -1919,10 +2200,9 @@ static struct super_block *nfs4_get_sb(struct file_system_type *fs_type,
                return ERR_PTR(-EINVAL);
        }
 
-       server = kmalloc(sizeof(struct nfs_server), GFP_KERNEL);
+       server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
        if (!server)
                return ERR_PTR(-ENOMEM);
-       memset(server, 0, sizeof(struct nfs_server));
        /* Zero out the NFS state stuff */
        init_nfsv4_state(server);
        server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
@@ -1974,7 +2254,7 @@ static struct super_block *nfs4_get_sb(struct file_system_type *fs_type,
 
        s->s_flags = flags;
 
-       error = nfs4_fill_super(s, data, flags & MS_VERBOSE ? 1 : 0);
+       error = nfs4_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
        if (error) {
                up_write(&s->s_umount);
                deactivate_super(s);
@@ -2002,12 +2282,15 @@ static void nfs4_kill_super(struct super_block *sb)
 
        if (server->client != NULL && !IS_ERR(server->client))
                rpc_shutdown_client(server->client);
-       rpciod_down();          /* release rpciod */
 
        destroy_nfsv4_state(server);
 
+       rpciod_down();
+
+       nfs_free_iostats(server->io_stats);
        kfree(server->hostname);
        kfree(server);
+       nfs_release_automount_timer();
 }
 
 static struct file_system_type nfs4_fs_type = {
@@ -2018,6 +2301,104 @@ static struct file_system_type nfs4_fs_type = {
        .fs_flags       = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
 };
 
+static const int nfs_set_port_min = 0;
+static const int nfs_set_port_max = 65535;
+static int param_set_port(const char *val, struct kernel_param *kp)
+{
+       char *endp;
+       int num = simple_strtol(val, &endp, 0);
+       if (endp == val || *endp || num < nfs_set_port_min || num > nfs_set_port_max)
+               return -EINVAL;
+       *((int *)kp->arg) = num;
+       return 0;
+}
+
+module_param_call(callback_tcpport, param_set_port, param_get_int,
+                &nfs_callback_set_tcpport, 0644);
+
+static int param_set_idmap_timeout(const char *val, struct kernel_param *kp)
+{
+       char *endp;
+       int num = simple_strtol(val, &endp, 0);
+       int jif = num * HZ;
+       if (endp == val || *endp || num < 0 || jif < num)
+               return -EINVAL;
+       *((int *)kp->arg) = jif;
+       return 0;
+}
+
+module_param_call(idmap_cache_timeout, param_set_idmap_timeout, param_get_int,
+                &nfs_idmap_cache_timeout, 0644);
+
+/* Constructs the SERVER-side path */
+static inline char *nfs4_path(const struct dentry *dentry, char *buffer, ssize_t buflen)
+{
+       return nfs_path(NFS_SB(dentry->d_sb)->mnt_path, dentry, buffer, buflen);
+}
+
+static inline char *nfs4_dup_path(const struct dentry *dentry)
+{
+       char *page = (char *) __get_free_page(GFP_USER);
+       char *path;
+
+       path = nfs4_path(dentry, page, PAGE_SIZE);
+       if (!IS_ERR(path)) {
+               int len = PAGE_SIZE + page - path;
+               char *tmp = path;
+
+               path = kmalloc(len, GFP_KERNEL);
+               if (path)
+                       memcpy(path, tmp, len);
+               else
+                       path = ERR_PTR(-ENOMEM);
+       }
+       free_page((unsigned long)page);
+       return path;
+}
+
+static struct super_block *nfs4_clone_client(struct nfs_server *server, struct nfs_clone_mount *data)
+{
+       const struct dentry *dentry = data->dentry;
+       struct nfs4_client *clp = server->nfs4_state;
+       struct super_block *sb;
+
+       server->mnt_path = nfs4_dup_path(dentry);
+       if (IS_ERR(server->mnt_path)) {
+               sb = (struct super_block *)server->mnt_path;
+               goto err;
+       }
+       sb = sget(&nfs4_fs_type, nfs4_compare_super, nfs_set_super, server);
+       if (IS_ERR(sb) || sb->s_root)
+               goto free_path;
+       nfs4_server_capabilities(server, &server->fh);
+
+       down_write(&clp->cl_sem);
+       atomic_inc(&clp->cl_count);
+       list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks);
+       up_write(&clp->cl_sem);
+       return sb;
+free_path:
+       kfree(server->mnt_path);
+err:
+       server->mnt_path = NULL;
+       return sb;
+}
+
+static struct super_block *nfs_clone_nfs4_sb(struct file_system_type *fs_type,
+               int flags, const char *dev_name, void *raw_data)
+{
+       struct nfs_clone_mount *data = raw_data;
+       return nfs_clone_generic_sb(data, nfs4_clone_client);
+}
+
+static struct file_system_type clone_nfs4_fs_type = {
+       .owner          = THIS_MODULE,
+       .name           = "nfs",
+       .get_sb         = nfs_clone_nfs4_sb,
+       .kill_sb        = nfs4_kill_super,
+       .fs_flags       = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
+};
+
 #define nfs4_init_once(nfsi) \
        do { \
                INIT_LIST_HEAD(&(nfsi)->open_states); \
@@ -2025,15 +2406,89 @@ static struct file_system_type nfs4_fs_type = {
                nfsi->delegation_state = 0; \
                init_rwsem(&nfsi->rwsem); \
        } while(0)
-#define register_nfs4fs() register_filesystem(&nfs4_fs_type)
-#define unregister_nfs4fs() unregister_filesystem(&nfs4_fs_type)
+
+static inline int register_nfs4fs(void)
+{
+       int ret;
+
+       ret = nfs_register_sysctl();
+       if (ret != 0)
+               return ret;
+       ret = register_filesystem(&nfs4_fs_type);
+       if (ret != 0)
+               nfs_unregister_sysctl();
+       return ret;
+}
+
+static inline void unregister_nfs4fs(void)
+{
+       unregister_filesystem(&nfs4_fs_type);
+       nfs_unregister_sysctl();
+}
 #else
+#define nfs4_clone_client(a,b) ERR_PTR(-EINVAL)
 #define nfs4_init_once(nfsi) \
        do { } while (0)
 #define register_nfs4fs() (0)
 #define unregister_nfs4fs()
 #endif
 
+static inline char *nfs_devname(const struct vfsmount *mnt_parent,
+                        const struct dentry *dentry,
+                        char *buffer, ssize_t buflen)
+{
+       return nfs_path(mnt_parent->mnt_devname, dentry, buffer, buflen);
+}
+
+/**
+ * nfs_do_submount - set up mountpoint when crossing a filesystem boundary
+ * @mnt_parent - mountpoint of parent directory
+ * @dentry - parent directory
+ * @fh - filehandle for new root dentry
+ * @fattr - attributes for new root inode
+ *
+ */
+struct vfsmount *nfs_do_submount(const struct vfsmount *mnt_parent,
+               const struct dentry *dentry, struct nfs_fh *fh,
+               struct nfs_fattr *fattr)
+{
+       struct nfs_clone_mount mountdata = {
+               .sb = mnt_parent->mnt_sb,
+               .dentry = dentry,
+               .fh = fh,
+               .fattr = fattr,
+       };
+       struct vfsmount *mnt = ERR_PTR(-ENOMEM);
+       char *page = (char *) __get_free_page(GFP_USER);
+       char *devname;
+
+       dprintk("%s: submounting on %s/%s\n", __FUNCTION__,
+                       dentry->d_parent->d_name.name,
+                       dentry->d_name.name);
+       if (page == NULL)
+               goto out;
+       devname = nfs_devname(mnt_parent, dentry, page, PAGE_SIZE);
+       mnt = (struct vfsmount *)devname;
+       if (IS_ERR(devname))
+               goto free_page;
+       switch (NFS_SB(mnt_parent->mnt_sb)->rpc_ops->version) {
+               case 2:
+               case 3:
+                       mnt = vfs_kern_mount(&clone_nfs_fs_type, 0, devname, &mountdata);
+                       break;
+               case 4:
+                       mnt = vfs_kern_mount(&clone_nfs4_fs_type, 0, devname, &mountdata);
+                       break;
+               default:
+                       BUG();
+       }
+free_page:
+       free_page((unsigned long)page);
+out:
+       dprintk("%s: done\n", __FUNCTION__);
+       return mnt;
+}
+
 extern int nfs_init_nfspagecache(void);
 extern void nfs_destroy_nfspagecache(void);
 extern int nfs_init_readpagecache(void);
@@ -2095,7 +2550,8 @@ static int nfs_init_inodecache(void)
 {
        nfs_inode_cachep = kmem_cache_create("nfs_inode_cache",
                                             sizeof(struct nfs_inode),
-                                            0, SLAB_RECLAIM_ACCOUNT,
+                                            0, (SLAB_RECLAIM_ACCOUNT|
+                                               SLAB_MEM_SPREAD),
                                             init_once, NULL);
        if (nfs_inode_cachep == NULL)
                return -ENOMEM;
This page took 0.039567 seconds and 5 git commands to generate.