]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/nfs/inode.c
Merge branch 'devel' of master.kernel.org:/home/rmk/linux-2.6-serial
[linux-2.6-omap-h63xx.git] / fs / nfs / inode.c
index 432f41cd75e6c9258035d01440720175008d3ebb..d0b991a92327f32941a454865c6aed187523d52e 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
@@ -64,6 +67,7 @@ static void nfs_clear_inode(struct inode *);
 static void nfs_umount_begin(struct super_block *);
 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;
@@ -77,6 +81,7 @@ static struct super_operations nfs_sops = {
        .clear_inode    = nfs_clear_inode,
        .umount_begin   = nfs_umount_begin,
        .show_options   = nfs_show_options,
+       .show_stats     = nfs_show_stats,
 };
 
 /*
@@ -102,7 +107,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 +122,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 +137,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);
@@ -221,10 +226,10 @@ 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);
 }
@@ -236,7 +241,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 +249,7 @@ 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;
+       return nfs_fhget(sb, rootfh, fsinfo->fattr);
 }
 
 /*
@@ -276,6 +277,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 +294,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 +315,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,
@@ -400,6 +403,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 +423,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;
 
@@ -575,17 +580,16 @@ nfs_statfs(struct super_block *sb, struct kstatfs *buf)
        buf->f_namelen = server->namelen;
  out:
        unlock_kernel();
-
        return 0;
 
  out_err:
-       printk(KERN_WARNING "nfs_statfs: statfs error = %d\n", -error);
+       dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
        buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1;
        goto out;
 
 }
 
-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;
@@ -594,28 +598,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)
@@ -635,8 +637,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;
 }
 
@@ -650,10 +737,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);
@@ -669,6 +753,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;
 
@@ -760,7 +846,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)
@@ -773,8 +859,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);
@@ -843,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;
 }
 
@@ -856,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;
@@ -868,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
         */
@@ -912,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);
        }
@@ -958,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
@@ -972,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;
 
@@ -980,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;
@@ -1010,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);
        }
 }
@@ -1018,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);
@@ -1050,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;
@@ -1075,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;
@@ -1184,6 +1286,7 @@ int nfs_attribute_timeout(struct inode *inode)
  */
 int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
 {
+       nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE);
        if (!(NFS_I(inode)->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA))
                        && !nfs_attribute_timeout(inode))
                return NFS_STALE(inode) ? -ESTALE : 0;
@@ -1200,6 +1303,7 @@ void nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
        struct nfs_inode *nfsi = NFS_I(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);
@@ -1252,6 +1356,33 @@ 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 ((fattr->valid & NFS_ATTR_PRE_CHANGE) != 0
+                       && nfsi->change_attr == fattr->pre_change_attr) {
+               nfsi->change_attr = fattr->change_attr;
+               nfsi->cache_change_attribute = jiffies;
+       }
+
+       /* 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
@@ -1268,23 +1399,8 @@ 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) {
+       if ((fattr->valid & NFS_ATTR_FATTR) == 0)
                return 0;
-       }
 
        /* Has the inode gone and changed behind our back? */
        if (nfsi->fileid != fattr->fileid
@@ -1292,29 +1408,32 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
                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);
 
-       /* Verify a few of the more important attributes */
-       if (!timespec_equal(&inode->i_mtime, &fattr->mtime)) {
+       if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0) {
+               if (nfsi->change_attr == fattr->change_attr)
+                       goto out;
                nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
                if (!data_unstable)
                        nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE;
        }
-       if (cur_size != new_isize) {
+
+       /* Verify a few of the more important attributes */
+       if (!timespec_equal(&inode->i_mtime, &fattr->mtime)) {
                nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
-               if (nfsi->npages == 0)
+               if (!data_unstable)
                        nfsi->cache_validity |= 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)
                        || inode->i_uid != fattr->uid
@@ -1325,6 +1444,7 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
        if (inode->i_nlink != fattr->nlink)
                nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
 
+out:
        if (!timespec_equal(&inode->i_atime, &fattr->atime))
                nfsi->cache_validity |= NFS_INO_INVALID_ATIME;
 
@@ -1410,14 +1530,8 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
        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.
@@ -1436,6 +1550,9 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
        if (data_stable)
                nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR|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);
        cur_isize = i_size_read(inode);
@@ -1466,15 +1583,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;
@@ -1504,8 +1612,20 @@ 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)) {
+               if (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;
+               } else
+                       invalid &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA);
+       }
+
        /* 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)) {
@@ -1539,6 +1659,13 @@ 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;
 }
 
 /*
@@ -1615,10 +1742,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);
@@ -1657,7 +1783,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);
@@ -1690,6 +1816,7 @@ static void nfs_kill_super(struct super_block *s)
 
        rpciod_down();          /* release rpciod */
 
+       nfs_free_iostats(server->io_stats);
        kfree(server->hostname);
        kfree(server);
 }
@@ -1716,6 +1843,7 @@ static struct super_operations nfs4_sops = {
        .clear_inode    = nfs4_clear_inode,
        .umount_begin   = nfs_umount_begin,
        .show_options   = nfs_show_options,
+       .show_stats     = nfs_show_stats,
 };
 
 /*
@@ -1778,6 +1906,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__);
@@ -1820,25 +1951,10 @@ 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;
-               clp->cl_cred = rpcauth_lookupcred(clnt->cl_auth, 0);
-               if (IS_ERR(clp->cl_cred)) {
-                       up_write(&clp->cl_sem);
-                       err = PTR_ERR(clp->cl_cred);
-                       clp->cl_cred = NULL;
-                       goto out_fail;
-               }
                memcpy(clp->cl_ipaddr, server->ip_addr, sizeof(clp->cl_ipaddr));
                nfs_idmap_new(clp);
        }
-       if (list_empty(&clp->cl_superblocks)) {
-               err = nfs4_init_client(clp);
-               if (err != 0) {
-                       up_write(&clp->cl_sem);
-                       goto out_fail;
-               }
-       }
        list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks);
        clnt = rpc_clone_client(clp->cl_rpcclient);
        if (!IS_ERR(clnt))
@@ -1934,10 +2050,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);
@@ -1989,7 +2104,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);
@@ -2017,10 +2132,12 @@ 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);
 }
@@ -2033,6 +2150,35 @@ 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);
+
 #define nfs4_init_once(nfsi) \
        do { \
                INIT_LIST_HEAD(&(nfsi)->open_states); \
@@ -2040,8 +2186,25 @@ 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_init_once(nfsi) \
        do { } while (0)
@@ -2110,7 +2273,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;
@@ -2166,11 +2330,11 @@ out:
 #ifdef CONFIG_PROC_FS
        rpc_proc_unregister("nfs");
 #endif
-       nfs_destroy_writepagecache();
 #ifdef CONFIG_NFS_DIRECTIO
-out0:
        nfs_destroy_directcache();
+out0:
 #endif
+       nfs_destroy_writepagecache();
 out1:
        nfs_destroy_readpagecache();
 out2: