NFS: Remove attribute update related BKL references
[safe/jmp/linux-2.6] / fs / nfs / inode.c
index ee13cb0..df23f98 100644 (file)
  *
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
-
+#include <linux/sched.h>
 #include <linux/time.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include "callback.h"
 #include "delegation.h"
 #include "iostat.h"
+#include "internal.h"
 
 #define NFSDBG_FACILITY                NFSDBG_VFS
-#define NFS_PARANOIA 1
 
-/* Maximum number of readahead requests
- * FIXME: this should really be a sysctl so that users may tune it to suit
- *        their needs. People that do NFS over a slow network, might for
- *        instance want to reduce it to something closer to 1 for improved
- *        interactive response.
- */
-#define NFS_MAX_READAHEAD      (RPC_DEF_SLOT_TABLE - 1)
+#define NFS_64_BIT_INODE_NUMBERS_ENABLED       1
+
+/* Default is to see 64-bit inode numbers */
+static int enable_ino64 = NFS_64_BIT_INODE_NUMBERS_ENABLED;
 
 static void nfs_invalidate_inode(struct inode *);
 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_clear_inode(struct inode *);
-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;
-
-static struct super_operations nfs_sops = { 
-       .alloc_inode    = nfs_alloc_inode,
-       .destroy_inode  = nfs_destroy_inode,
-       .write_inode    = nfs_write_inode,
-       .statfs         = nfs_statfs,
-       .clear_inode    = nfs_clear_inode,
-       .umount_begin   = nfs_umount_begin,
-       .show_options   = nfs_show_options,
-       .show_stats     = nfs_show_stats,
-};
-
-/*
- * RPC cruft for NFS
- */
-static struct rpc_stat         nfs_rpcstat = {
-       .program                = &nfs_program
-};
-static struct rpc_version *    nfs_version[] = {
-       NULL,
-       NULL,
-       &nfs_version2,
-#if defined(CONFIG_NFS_V3)
-       &nfs_version3,
-#elif defined(CONFIG_NFS_V4)
-       NULL,
-#endif
-#if defined(CONFIG_NFS_V4)
-       &nfs_version4,
-#endif
-};
-
-static struct rpc_program      nfs_program = {
-       .name                   = "nfs",
-       .number                 = NFS_PROGRAM,
-       .nrvers                 = ARRAY_SIZE(nfs_version),
-       .version                = nfs_version,
-       .stats                  = &nfs_rpcstat,
-       .pipe_dir_name          = "/nfs",
-};
-
-#ifdef CONFIG_NFS_V3_ACL
-static struct rpc_stat         nfsacl_rpcstat = { &nfsacl_program };
-static struct rpc_version *    nfsacl_version[] = {
-       [3]                     = &nfsacl_version3,
-};
-
-struct rpc_program             nfsacl_program = {
-       .name =                 "nfsacl",
-       .number =               NFS_ACL_PROGRAM,
-       .nrvers =               ARRAY_SIZE(nfsacl_version),
-       .version =              nfsacl_version,
-       .stats =                &nfsacl_rpcstat,
-};
-#endif  /* CONFIG_NFS_V3_ACL */
+static struct kmem_cache * nfs_inode_cachep;
 
 static inline unsigned long
 nfs_fattr_to_ino_t(struct nfs_fattr *fattr)
@@ -134,594 +65,50 @@ nfs_fattr_to_ino_t(struct nfs_fattr *fattr)
        return nfs_fileid_to_ino_t(fattr->fileid);
 }
 
-static int
-nfs_write_inode(struct inode *inode, int sync)
-{
-       int flags = sync ? FLUSH_SYNC : 0;
-       int ret;
-
-       ret = nfs_commit_inode(inode, flags);
-       if (ret < 0)
-               return ret;
-       return 0;
-}
-
-static void
-nfs_clear_inode(struct inode *inode)
-{
-       struct nfs_inode *nfsi = NFS_I(inode);
-       struct rpc_cred *cred;
-
-       /*
-        * 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;
-       if (cred)
-               put_rpccred(cred);
-       BUG_ON(atomic_read(&nfsi->data_updates) != 0);
-}
-
-static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
-{
-       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 = server->client_acl;
-       if (!IS_ERR(rpc))
-               rpc_killall_tasks(rpc);
-}
-
-
-static inline unsigned long
-nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
-{
-       /* make sure blocksize is a power of two */
-       if ((bsize & (bsize - 1)) || nrbitsp) {
-               unsigned char   nrbits;
-
-               for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
-                       ;
-               bsize = 1 << nrbits;
-               if (nrbitsp)
-                       *nrbitsp = nrbits;
-       }
-
-       return bsize;
-}
-
-/*
- * Calculate the number of 512byte blocks used.
- */
-static inline unsigned long
-nfs_calc_block_size(u64 tsize)
-{
-       loff_t used = (tsize + 511) >> 9;
-       return (used > ULONG_MAX) ? ULONG_MAX : used;
-}
-
-/*
- * Compute and set NFS server blocksize
- */
-static inline unsigned long
-nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
-{
-       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.
- */
-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);
-       int                     error;
-
-       error = server->rpc_ops->getroot(server, rootfh, fsinfo);
-       if (error < 0) {
-               dprintk("nfs_get_root: getattr error = %d\n", -error);
-               return ERR_PTR(error);
-       }
-
-       server->fsid = fsinfo->fattr->fsid;
-       return nfs_fhget(sb, rootfh, fsinfo->fattr);
-}
-
-/*
- * Do NFS version-independent mount processing, and sanity checking
- */
-static int
-nfs_sb_init(struct super_block *sb, rpc_authflavor_t authflavor)
-{
-       struct nfs_server       *server;
-       struct inode            *root_inode;
-       struct nfs_fattr        fattr;
-       struct nfs_fsinfo       fsinfo = {
-                                       .fattr = &fattr,
-                               };
-       struct nfs_pathconf pathinfo = {
-                       .fattr = &fattr,
-       };
-       int no_root_error = 0;
-       unsigned long max_rpc_payload;
-
-       /* We probably want something more informative here */
-       snprintf(sb->s_id, sizeof(sb->s_id), "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev));
-
-       server = NFS_SB(sb);
-
-       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)) {
-               no_root_error = PTR_ERR(root_inode);
-               goto out_no_root;
-       }
-       sb->s_root = d_alloc_root(root_inode);
-       if (!sb->s_root) {
-               no_root_error = -ENOMEM;
-               goto out_no_root;
-       }
-       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)
-               server->namelen = pathinfo.max_namelen;
-       /* Work out a lot of parameters */
-       if (server->rsize == 0)
-               server->rsize = nfs_block_size(fsinfo.rtpref, NULL);
-       if (server->wsize == 0)
-               server->wsize = nfs_block_size(fsinfo.wtpref, NULL);
-
-       if (fsinfo.rtmax >= 512 && server->rsize > fsinfo.rtmax)
-               server->rsize = nfs_block_size(fsinfo.rtmax, NULL);
-       if (fsinfo.wtmax >= 512 && server->wsize > fsinfo.wtmax)
-               server->wsize = nfs_block_size(fsinfo.wtmax, NULL);
-
-       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->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->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 (sb->s_blocksize == 0)
-               sb->s_blocksize = nfs_block_bits(server->wsize,
-                                                        &sb->s_blocksize_bits);
-       server->wtmult = nfs_block_bits(fsinfo.wtmult, NULL);
-
-       server->dtsize = nfs_block_size(fsinfo.dtpref, NULL);
-       if (server->dtsize > PAGE_CACHE_SIZE)
-               server->dtsize = PAGE_CACHE_SIZE;
-       if (server->dtsize > server->rsize)
-               server->dtsize = server->rsize;
-
-       if (server->flags & NFS_MOUNT_NOAC) {
-               server->acregmin = server->acregmax = 0;
-               server->acdirmin = server->acdirmax = 0;
-               sb->s_flags |= MS_SYNCHRONOUS;
-       }
-       server->backing_dev_info.ra_pages = server->rpages * NFS_MAX_READAHEAD;
-
-       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;
-
-       /* We're airborne Set socket buffersize */
-       rpc_setbufsize(server->client, server->wsize + 100, server->rsize + 100);
-       return 0;
-       /* Yargs. It didn't work out. */
-out_no_root:
-       dprintk("nfs_sb_init: get root inode failed: errno %d\n", -no_root_error);
-       if (!IS_ERR(root_inode))
-               iput(root_inode);
-       return no_root_error;
-}
-
-static void nfs_init_timeout_values(struct rpc_timeout *to, int proto, unsigned int timeo, unsigned int retrans)
-{
-       to->to_initval = timeo * HZ / 10;
-       to->to_retries = retrans;
-       if (!to->to_retries)
-               to->to_retries = 2;
-
-       switch (proto) {
-       case IPPROTO_TCP:
-               if (!to->to_initval)
-                       to->to_initval = 60 * HZ;
-               if (to->to_initval > NFS_MAX_TCP_TIMEOUT)
-                       to->to_initval = NFS_MAX_TCP_TIMEOUT;
-               to->to_increment = to->to_initval;
-               to->to_maxval = to->to_initval + (to->to_increment * to->to_retries);
-               to->to_exponential = 0;
-               break;
-       case IPPROTO_UDP:
-       default:
-               if (!to->to_initval)
-                       to->to_initval = 11 * HZ / 10;
-               if (to->to_initval > NFS_MAX_UDP_TIMEOUT)
-                       to->to_initval = NFS_MAX_UDP_TIMEOUT;
-               to->to_maxval = NFS_MAX_UDP_TIMEOUT;
-               to->to_exponential = 1;
-               break;
-       }
-}
-
-/*
- * Create an RPC client handle.
- */
-static struct rpc_clnt *
-nfs_create_client(struct nfs_server *server, const struct nfs_mount_data *data)
-{
-       struct rpc_timeout      timeparms;
-       struct rpc_xprt         *xprt = NULL;
-       struct rpc_clnt         *clnt = NULL;
-       int                     proto = (data->flags & NFS_MOUNT_TCP) ? IPPROTO_TCP : IPPROTO_UDP;
-
-       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)) {
-               dprintk("%s: cannot create RPC transport. Error = %ld\n",
-                               __FUNCTION__, PTR_ERR(xprt));
-               return (struct rpc_clnt *)xprt;
-       }
-       clnt = rpc_create_client(xprt, server->hostname, &nfs_program,
-                                server->rpc_ops->version, data->pseudoflavor);
-       if (IS_ERR(clnt)) {
-               dprintk("%s: cannot create RPC client. Error = %ld\n",
-                               __FUNCTION__, PTR_ERR(xprt));
-               goto out_fail;
-       }
-
-       clnt->cl_intr     = 1;
-       clnt->cl_softrtry = 1;
-
-       return clnt;
-
-out_fail:
-       return clnt;
-}
-
-/*
- * The way this works is that the mount process passes a structure
- * in the data argument which contains the server's IP address
- * and the root file handle obtained from the server's mount
- * daemon. We stash these away in the private superblock fields.
+/**
+ * nfs_compat_user_ino64 - returns the user-visible inode number
+ * @fileid: 64-bit fileid
+ *
+ * This function returns a 32-bit inode number if the boot parameter
+ * nfs.enable_ino64 is zero.
  */
-static int
-nfs_fill_super(struct super_block *sb, struct nfs_mount_data *data, int silent)
-{
-       struct nfs_server       *server;
-       rpc_authflavor_t        authflavor;
-
-       server           = NFS_SB(sb);
-       sb->s_blocksize_bits = 0;
-       sb->s_blocksize = 0;
-       if (data->bsize)
-               sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
-       if (data->rsize)
-               server->rsize = nfs_block_size(data->rsize, NULL);
-       if (data->wsize)
-               server->wsize = nfs_block_size(data->wsize, NULL);
-       server->flags    = data->flags & NFS_MOUNT_FLAGMASK;
-
-       server->acregmin = data->acregmin*HZ;
-       server->acregmax = data->acregmax*HZ;
-       server->acdirmin = data->acdirmin*HZ;
-       server->acdirmax = data->acdirmax*HZ;
-
-       /* Start lockd here, before we might error out */
-       if (!(server->flags & NFS_MOUNT_NONLM))
-               lockd_up();
-
-       server->namelen  = data->namlen;
-       server->hostname = kmalloc(strlen(data->hostname) + 1, GFP_KERNEL);
-       if (!server->hostname)
-               return -ENOMEM;
-       strcpy(server->hostname, data->hostname);
-
-       /* Check NFS protocol revision and initialize RPC op vector
-        * and file handle pool. */
-#ifdef CONFIG_NFS_V3
-       if (server->flags & NFS_MOUNT_VER3) {
-               server->rpc_ops = &nfs_v3_clientops;
-               server->caps |= NFS_CAP_READDIRPLUS;
-       } else {
-               server->rpc_ops = &nfs_v2_clientops;
-       }
-#else
-       server->rpc_ops = &nfs_v2_clientops;
-#endif
-
-       /* Fill in pseudoflavor for mount version < 5 */
-       if (!(data->flags & NFS_MOUNT_SECFLAVOUR))
-               data->pseudoflavor = RPC_AUTH_UNIX;
-       authflavor = data->pseudoflavor;        /* save for sb_init() */
-       /* XXX maybe we want to add a server->pseudoflavor field */
-
-       /* Create RPC client handles */
-       server->client = nfs_create_client(server, data);
-       if (IS_ERR(server->client))
-               return PTR_ERR(server->client);
-       /* RFC 2623, sec 2.3.2 */
-       if (authflavor != RPC_AUTH_UNIX) {
-               struct rpc_auth *auth;
-
-               server->client_sys = rpc_clone_client(server->client);
-               if (IS_ERR(server->client_sys))
-                       return PTR_ERR(server->client_sys);
-               auth = rpcauth_create(RPC_AUTH_UNIX, server->client_sys);
-               if (IS_ERR(auth))
-                       return PTR_ERR(auth);
-       } else {
-               atomic_inc(&server->client->cl_count);
-               server->client_sys = server->client;
-       }
-       if (server->flags & NFS_MOUNT_VER3) {
-#ifdef CONFIG_NFS_V3_ACL
-               if (!(server->flags & NFS_MOUNT_NOACL)) {
-                       server->client_acl = rpc_bind_new_program(server->client, &nfsacl_program, 3);
-                       /* No errors! Assume that Sun nfsacls are supported */
-                       if (!IS_ERR(server->client_acl))
-                               server->caps |= NFS_CAP_ACLS;
-               }
-#else
-               server->flags &= ~NFS_MOUNT_NOACL;
-#endif /* CONFIG_NFS_V3_ACL */
-               /*
-                * The VFS shouldn't apply the umask to mode bits. We will
-                * do so ourselves when necessary.
-                */
-               sb->s_flags |= MS_POSIXACL;
-               if (server->namelen == 0 || server->namelen > NFS3_MAXNAMLEN)
-                       server->namelen = NFS3_MAXNAMLEN;
-               sb->s_time_gran = 1;
-       } else {
-               if (server->namelen == 0 || server->namelen > NFS2_MAXNAMLEN)
-                       server->namelen = NFS2_MAXNAMLEN;
-       }
-
-       sb->s_op = &nfs_sops;
-       return nfs_sb_init(sb, authflavor);
-}
-
-static int
-nfs_statfs(struct super_block *sb, struct kstatfs *buf)
+u64 nfs_compat_user_ino64(u64 fileid)
 {
-       struct nfs_server *server = NFS_SB(sb);
-       unsigned char blockbits;
-       unsigned long blockres;
-       struct nfs_fh *rootfh = NFS_FH(sb->s_root->d_inode);
-       struct nfs_fattr fattr;
-       struct nfs_fsstat res = {
-                       .fattr = &fattr,
-       };
-       int error;
-
-       lock_kernel();
-
-       error = server->rpc_ops->statfs(server, rootfh, &res);
-       buf->f_type = NFS_SUPER_MAGIC;
-       if (error < 0)
-               goto out_err;
-
-       /*
-        * Current versions of glibc do not correctly handle the
-        * case where f_frsize != f_bsize.  Eventually we want to
-        * report the value of wtmult in this field.
-        */
-       buf->f_frsize = sb->s_blocksize;
-
-       /*
-        * On most *nix systems, f_blocks, f_bfree, and f_bavail
-        * are reported in units of f_frsize.  Linux hasn't had
-        * an f_frsize field in its statfs struct until recently,
-        * thus historically Linux's sys_statfs reports these
-        * fields in units of f_bsize.
-        */
-       buf->f_bsize = sb->s_blocksize;
-       blockbits = sb->s_blocksize_bits;
-       blockres = (1 << blockbits) - 1;
-       buf->f_blocks = (res.tbytes + blockres) >> blockbits;
-       buf->f_bfree = (res.fbytes + blockres) >> blockbits;
-       buf->f_bavail = (res.abytes + blockres) >> blockbits;
-
-       buf->f_files = res.tfiles;
-       buf->f_ffree = res.afiles;
-
-       buf->f_namelen = server->namelen;
- out:
-       unlock_kernel();
-       return 0;
+       int ino;
 
- out_err:
-       dprintk("%s: statfs error = %d\n", __FUNCTION__, -error);
-       buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1;
-       goto out;
-
-}
-
-static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults)
-{
-       static struct proc_nfs_info {
-               int flag;
-               char *str;
-               char *nostr;
-       } nfs_info[] = {
-               { NFS_MOUNT_SOFT, ",soft", ",hard" },
-               { NFS_MOUNT_INTR, ",intr", "" },
-               { NFS_MOUNT_NOCTO, ",nocto", "" },
-               { NFS_MOUNT_NOAC, ",noac", "" },
-               { NFS_MOUNT_NONLM, ",nolock", "" },
-               { NFS_MOUNT_NOACL, ",noacl", "" },
-               { 0, NULL, NULL }
-       };
-       struct proc_nfs_info *nfs_infop;
-       char buf[12];
-       char *proto;
-
-       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 || showdefaults)
-               seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ);
-       if (nfss->acregmax != 60*HZ || showdefaults)
-               seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ);
-       if (nfss->acdirmin != 30*HZ || showdefaults)
-               seq_printf(m, ",acdirmin=%d", nfss->acdirmin/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)
-                       seq_puts(m, nfs_infop->str);
-               else
-                       seq_puts(m, nfs_infop->nostr);
-       }
-       switch (nfss->client->cl_xprt->prot) {
-               case IPPROTO_TCP:
-                       proto = "tcp";
-                       break;
-               case IPPROTO_UDP:
-                       proto = "udp";
-                       break;
-               default:
-                       snprintf(buf, sizeof(buf), "%u", nfss->client->cl_xprt->prot);
-                       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);
+       if (enable_ino64)
+               return fileid;
+       ino = fileid;
+       if (sizeof(ino) < sizeof(fileid))
+               ino ^= fileid >> (sizeof(fileid)-sizeof(ino)) * 8;
+       return ino;
 }
 
-static int nfs_show_options(struct seq_file *m, struct vfsmount *mnt)
+int nfs_write_inode(struct inode *inode, int sync)
 {
-       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\\");
+       int ret;
 
-       return 0;
+       if (sync) {
+               ret = filemap_fdatawait(inode->i_mapping);
+               if (ret == 0)
+                       ret = nfs_commit_inode(inode, FLUSH_SYNC);
+       } else
+               ret = nfs_commit_inode(inode, 0);
+       if (ret >= 0)
+               return 0;
+       __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
+       return ret;
 }
 
-static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
+void nfs_clear_inode(struct inode *inode)
 {
-       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
+        * The following should never happen...
         */
-       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;
+       BUG_ON(nfs_have_writebacks(inode));
+       BUG_ON(!list_empty(&NFS_I(inode)->open_files));
+       nfs_zap_acl_cache(inode);
+       nfs_access_zap_cache(inode);
 }
 
 /**
@@ -752,8 +139,8 @@ static void nfs_zap_caches_locked(struct inode *inode)
 
        nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
 
-       NFS_ATTRTIMEO(inode) = NFS_MINATTRTIMEO(inode);
-       NFS_ATTRTIMEO_UPDATE(inode) = jiffies;
+       nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
+       nfsi->attrtimeo_timestamp = jiffies;
 
        memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
        if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
@@ -769,7 +156,16 @@ void nfs_zap_caches(struct inode *inode)
        spin_unlock(&inode->i_lock);
 }
 
-static void nfs_zap_acl_cache(struct inode *inode)
+void nfs_zap_mapping(struct inode *inode, struct address_space *mapping)
+{
+       if (mapping->nrpages != 0) {
+               spin_lock(&inode->i_lock);
+               NFS_I(inode)->cache_validity |= NFS_INO_INVALID_DATA;
+               spin_unlock(&inode->i_lock);
+       }
+}
+
+void nfs_zap_acl_cache(struct inode *inode)
 {
        void (*clear_acl_cache)(struct inode *);
 
@@ -781,13 +177,20 @@ static void nfs_zap_acl_cache(struct inode *inode)
        spin_unlock(&inode->i_lock);
 }
 
+void nfs_invalidate_atime(struct inode *inode)
+{
+       spin_lock(&inode->i_lock);
+       NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATIME;
+       spin_unlock(&inode->i_lock);
+}
+
 /*
  * Invalidate, but do not unhash, the inode.
  * NB: must be called with inode->i_lock held!
  */
 static void nfs_invalidate_inode(struct inode *inode)
 {
-       set_bit(NFS_INO_STALE, &NFS_FLAGS(inode));
+       set_bit(NFS_INO_STALE, &NFS_I(inode)->flags);
        nfs_zap_caches_locked(inode);
 }
 
@@ -824,7 +227,7 @@ nfs_init_locked(struct inode *inode, void *opaque)
        struct nfs_find_desc    *desc = (struct nfs_find_desc *)opaque;
        struct nfs_fattr        *fattr = desc->fattr;
 
-       NFS_FILEID(inode) = fattr->fileid;
+       set_nfs_fileid(inode, fattr->fileid);
        nfs_copy_fh(NFS_FH(inode), desc->fh);
        return 0;
 }
@@ -864,6 +267,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
 
        if (inode->i_state & I_NEW) {
                struct nfs_inode *nfsi = NFS_I(inode);
+               unsigned long now = jiffies;
 
                /* We set i_ino for the few things that still rely on it,
                 * such as stat(2) */
@@ -875,17 +279,17 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
                /* Why so? Because we want revalidate for devices/FIFOs, and
                 * that's precisely what we have in nfs_file_inode_operations.
                 */
-               inode->i_op = NFS_SB(sb)->rpc_ops->file_inode_ops;
+               inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->file_inode_ops;
                if (S_ISREG(inode->i_mode)) {
                        inode->i_fop = &nfs_file_operations;
                        inode->i_data.a_ops = &nfs_file_aops;
                        inode->i_data.backing_dev_info = &NFS_SB(sb)->backing_dev_info;
                } else if (S_ISDIR(inode->i_mode)) {
-                       inode->i_op = NFS_SB(sb)->rpc_ops->dir_inode_ops;
+                       inode->i_op = NFS_SB(sb)->nfs_client->rpc_ops->dir_inode_ops;
                        inode->i_fop = &nfs_dir_operations;
                        if (nfs_server_capable(inode, NFS_CAP_READDIRPLUS)
                            && fattr->size <= NFS_LIMIT_READDIRPLUS)
-                               set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_FLAGS(inode));
+                               set_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(inode)->flags);
                        /* Deal with crossing mountpoints */
                        if (!nfs_fsid_equal(&NFS_SB(sb)->fsid, &fattr->fsid)) {
                                if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)
@@ -893,6 +297,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
                                else
                                        inode->i_op = &nfs_mountpoint_inode_operations;
                                inode->i_fop = NULL;
+                               set_bit(NFS_INO_MOUNTPOINT, &nfsi->flags);
                        }
                } else if (S_ISLNK(inode->i_mode))
                        inode->i_op = &nfs_symlink_inode_operations;
@@ -900,7 +305,8 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
                        init_special_inode(inode, inode->i_mode, fattr->rdev);
 
                nfsi->read_cache_jiffies = fattr->time_start;
-               nfsi->last_updated = jiffies;
+               nfsi->last_updated = now;
+               nfsi->cache_change_attribute = now;
                inode->i_atime = fattr->atime;
                inode->i_mtime = fattr->mtime;
                inode->i_ctime = fattr->ctime;
@@ -915,15 +321,13 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
                         * report the blocks in 512byte units
                         */
                        inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
-                       inode->i_blksize = inode->i_sb->s_blocksize;
                } else {
                        inode->i_blocks = fattr->du.nfs2.blocks;
-                       inode->i_blksize = fattr->du.nfs2.blocksize;
                }
                nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
-               nfsi->attrtimeo_timestamp = jiffies;
+               nfsi->attrtimeo_timestamp = now;
                memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
-               nfsi->cache_access.cred = NULL;
+               nfsi->access_cache = RB_ROOT;
 
                unlock_new_inode(inode);
        } else
@@ -941,7 +345,7 @@ out_no_inode:
        goto out;
 }
 
-#define NFS_VALID_ATTRS (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_ATIME|ATTR_ATIME_SET|ATTR_MTIME|ATTR_MTIME_SET)
+#define NFS_VALID_ATTRS (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_ATIME|ATTR_ATIME_SET|ATTR_MTIME|ATTR_MTIME_SET|ATTR_FILE)
 
 int
 nfs_setattr(struct dentry *dentry, struct iattr *attr)
@@ -952,6 +356,10 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
 
        nfs_inc_stats(inode, NFSIOS_VFSSETATTR);
 
+       /* skip mode change if it's just for clearing setuid/setgid */
+       if (attr->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
+               attr->ia_valid &= ~ATTR_MODE;
+
        if (attr->ia_valid & ATTR_SIZE) {
                if (!S_ISREG(inode->i_mode) || attr->ia_size == i_size_read(inode))
                        attr->ia_valid &= ~ATTR_SIZE;
@@ -959,14 +367,14 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
 
        /* Optimization: if the end result is no change, don't RPC */
        attr->ia_valid &= NFS_VALID_ATTRS;
-       if (attr->ia_valid == 0)
+       if ((attr->ia_valid & ~ATTR_FILE) == 0)
                return 0;
 
-       lock_kernel();
-       nfs_begin_data_update(inode);
        /* Write all dirty data */
-       filemap_write_and_wait(inode->i_mapping);
-       nfs_wb_all(inode);
+       if (S_ISREG(inode->i_mode)) {
+               filemap_write_and_wait(inode->i_mapping);
+               nfs_wb_all(inode);
+       }
        /*
         * Return any delegations if we're going to change ACLs
         */
@@ -975,12 +383,66 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
        error = NFS_PROTO(inode)->setattr(dentry, &fattr, attr);
        if (error == 0)
                nfs_refresh_inode(inode, &fattr);
-       nfs_end_data_update(inode);
-       unlock_kernel();
        return error;
 }
 
 /**
+ * nfs_vmtruncate - unmap mappings "freed" by truncate() syscall
+ * @inode: inode of the file used
+ * @offset: file offset to start truncating
+ *
+ * This is a copy of the common vmtruncate, but with the locking
+ * corrected to take into account the fact that NFS requires
+ * inode->i_size to be updated under the inode->i_lock.
+ */
+static int nfs_vmtruncate(struct inode * inode, loff_t offset)
+{
+       if (i_size_read(inode) < offset) {
+               unsigned long limit;
+
+               limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
+               if (limit != RLIM_INFINITY && offset > limit)
+                       goto out_sig;
+               if (offset > inode->i_sb->s_maxbytes)
+                       goto out_big;
+               spin_lock(&inode->i_lock);
+               i_size_write(inode, offset);
+               spin_unlock(&inode->i_lock);
+       } else {
+               struct address_space *mapping = inode->i_mapping;
+
+               /*
+                * truncation of in-use swapfiles is disallowed - it would
+                * cause subsequent swapout to scribble on the now-freed
+                * blocks.
+                */
+               if (IS_SWAPFILE(inode))
+                       return -ETXTBSY;
+               spin_lock(&inode->i_lock);
+               i_size_write(inode, offset);
+               spin_unlock(&inode->i_lock);
+
+               /*
+                * unmap_mapping_range is called twice, first simply for
+                * efficiency so that truncate_inode_pages does fewer
+                * single-page unmaps.  However after this first call, and
+                * before truncate_inode_pages finishes, it is possible for
+                * private pages to be COWed, which remain after
+                * truncate_inode_pages finishes, hence the second
+                * unmap_mapping_range call must be made for correctness.
+                */
+               unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
+               truncate_inode_pages(mapping, offset);
+               unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
+       }
+       return 0;
+out_sig:
+       send_sig(SIGXFSZ, current, 0);
+out_big:
+       return -EFBIG;
+}
+
+/**
  * nfs_setattr_update_inode - Update inode metadata after a setattr call.
  * @inode: pointer to struct inode
  * @attr: pointer to struct iattr
@@ -1006,8 +468,7 @@ void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr)
        }
        if ((attr->ia_valid & ATTR_SIZE) != 0) {
                nfs_inc_stats(inode, NFSIOS_SETATTRTRUNC);
-               inode->i_size = attr->ia_size;
-               vmtruncate(inode, attr->ia_size);
+               nfs_vmtruncate(inode, attr->ia_size);
        }
 }
 
@@ -1024,15 +485,11 @@ static int nfs_wait_schedule(void *word)
  */
 static int nfs_wait_on_inode(struct inode *inode)
 {
-       struct rpc_clnt *clnt = NFS_CLIENT(inode);
        struct nfs_inode *nfsi = NFS_I(inode);
-       sigset_t oldmask;
        int error;
 
-       rpc_clnt_sigmask(clnt, &oldmask);
        error = wait_on_bit_lock(&nfsi->flags, NFS_INO_REVALIDATING,
-                                       nfs_wait_schedule, TASK_INTERRUPTIBLE);
-       rpc_clnt_sigunmask(clnt, &oldmask);
+                                       nfs_wait_schedule, TASK_KILLABLE);
 
        return error;
 }
@@ -1052,8 +509,18 @@ 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;
 
-       /* Flush out writes to the server in order to update c/mtime */
-       nfs_sync_inode_wait(inode, 0, 0, FLUSH_NOCOMMIT);
+       /*
+        * Flush out writes to the server in order to update c/mtime.
+        *
+        * Hold the i_mutex to suspend application writes temporarily;
+        * this prevents long-running writing applications from blocking
+        * nfs_wb_nocommit.
+        */
+       if (S_ISREG(inode->i_mode)) {
+               mutex_lock(&inode->i_mutex);
+               nfs_wb_nocommit(inode);
+               mutex_unlock(&inode->i_mutex);
+       }
 
        /*
         * We may force a getattr if the user cares about atime.
@@ -1072,8 +539,10 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
                err = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
        else
                err = nfs_revalidate_inode(NFS_SERVER(inode), inode);
-       if (!err)
+       if (!err) {
                generic_fillattr(inode, stat);
+               stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode));
+       }
        return err;
 }
 
@@ -1081,16 +550,17 @@ static struct nfs_open_context *alloc_nfs_open_context(struct vfsmount *mnt, str
 {
        struct nfs_open_context *ctx;
 
-       ctx = (struct nfs_open_context *)kmalloc(sizeof(*ctx), GFP_KERNEL);
+       ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
        if (ctx != NULL) {
-               atomic_set(&ctx->count, 1);
-               ctx->dentry = dget(dentry);
-               ctx->vfsmnt = mntget(mnt);
+               ctx->path.dentry = dget(dentry);
+               ctx->path.mnt = mntget(mnt);
                ctx->cred = get_rpccred(cred);
                ctx->state = NULL;
                ctx->lockowner = current->files;
+               ctx->flags = 0;
                ctx->error = 0;
                ctx->dir_cookie = 0;
+               atomic_set(&ctx->count, 1);
        }
        return ctx;
 }
@@ -1102,23 +572,38 @@ struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx)
        return ctx;
 }
 
-void put_nfs_open_context(struct nfs_open_context *ctx)
+static void __put_nfs_open_context(struct nfs_open_context *ctx, int wait)
 {
-       if (atomic_dec_and_test(&ctx->count)) {
-               if (!list_empty(&ctx->list)) {
-                       struct inode *inode = ctx->dentry->d_inode;
-                       spin_lock(&inode->i_lock);
-                       list_del(&ctx->list);
-                       spin_unlock(&inode->i_lock);
-               }
-               if (ctx->state != NULL)
-                       nfs4_close_state(ctx->state, ctx->mode);
-               if (ctx->cred != NULL)
-                       put_rpccred(ctx->cred);
-               dput(ctx->dentry);
-               mntput(ctx->vfsmnt);
-               kfree(ctx);
+       struct inode *inode;
+
+       if (ctx == NULL)
+               return;
+
+       inode = ctx->path.dentry->d_inode;
+       if (!atomic_dec_and_lock(&ctx->count, &inode->i_lock))
+               return;
+       list_del(&ctx->list);
+       spin_unlock(&inode->i_lock);
+       if (ctx->state != NULL) {
+               if (wait)
+                       nfs4_close_sync(&ctx->path, ctx->state, ctx->mode);
+               else
+                       nfs4_close_state(&ctx->path, ctx->state, ctx->mode);
        }
+       if (ctx->cred != NULL)
+               put_rpccred(ctx->cred);
+       path_put(&ctx->path);
+       kfree(ctx);
+}
+
+void put_nfs_open_context(struct nfs_open_context *ctx)
+{
+       __put_nfs_open_context(ctx, 0);
+}
+
+static void put_nfs_open_context_sync(struct nfs_open_context *ctx)
+{
+       __put_nfs_open_context(ctx, 1);
 }
 
 /*
@@ -1127,7 +612,7 @@ void put_nfs_open_context(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 inode *inode = filp->f_path.dentry->d_inode;
        struct nfs_inode *nfsi = NFS_I(inode);
 
        filp->private_data = get_nfs_open_context(ctx);
@@ -1159,15 +644,15 @@ struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_c
 
 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;
+       struct inode *inode = filp->f_path.dentry->d_inode;
+       struct nfs_open_context *ctx = nfs_file_open_context(filp);
 
        if (ctx) {
                filp->private_data = NULL;
                spin_lock(&inode->i_lock);
                list_move_tail(&ctx->list, &NFS_I(inode)->open_files);
                spin_unlock(&inode->i_lock);
-               put_nfs_open_context(ctx);
+               put_nfs_open_context_sync(ctx);
        }
 }
 
@@ -1179,10 +664,10 @@ int nfs_open(struct inode *inode, struct file *filp)
        struct nfs_open_context *ctx;
        struct rpc_cred *cred;
 
-       cred = rpcauth_lookupcred(NFS_CLIENT(inode)->cl_auth, 0);
+       cred = rpc_lookup_cred();
        if (IS_ERR(cred))
                return PTR_ERR(cred);
-       ctx = alloc_nfs_open_context(filp->f_vfsmnt, filp->f_dentry, cred);
+       ctx = alloc_nfs_open_context(filp->f_path.mnt, filp->f_path.dentry, cred);
        put_rpccred(cred);
        if (ctx == NULL)
                return -ENOMEM;
@@ -1213,8 +698,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
                inode->i_sb->s_id, (long long)NFS_FILEID(inode));
 
        nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE);
-       lock_kernel();
-       if (!inode || is_bad_inode(inode))
+       if (is_bad_inode(inode))
                goto out_nowait;
        if (NFS_STALE(inode))
                goto out_nowait;
@@ -1222,16 +706,10 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
        status = nfs_wait_on_inode(inode);
        if (status < 0)
                goto out;
-       if (NFS_STALE(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_ATIME)) {
-                               /* no */
-                       } else
-                               goto out;
-               }
-       }
+
+       status = -ESTALE;
+       if (NFS_STALE(inode))
+               goto out;
 
        status = NFS_PROTO(inode)->getattr(server, NFS_FH(inode), &fattr);
        if (status != 0) {
@@ -1241,7 +719,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
                if (status == -ESTALE) {
                        nfs_zap_caches(inode);
                        if (!S_ISDIR(inode->i_mode))
-                               set_bit(NFS_INO_STALE, &NFS_FLAGS(inode));
+                               set_bit(NFS_INO_STALE, &NFS_I(inode)->flags);
                }
                goto out;
        }
@@ -1268,7 +746,6 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
        nfs_wake_up_inode(inode);
 
  out_nowait:
-       unlock_kernel();
        return status;
 }
 
@@ -1278,7 +755,14 @@ int nfs_attribute_timeout(struct inode *inode)
 
        if (nfs_have_delegation(inode, FMODE_READ))
                return 0;
-       return time_after(jiffies, nfsi->read_cache_jiffies+nfsi->attrtimeo);
+       /*
+        * Special case: if the attribute timeout is set to 0, then always
+        *               treat the cache as having expired (unless holding
+        *               a delegation).
+        */
+       if (nfsi->attrtimeo == 0)
+               return 1;
+       return !time_in_range(jiffies, nfsi->read_cache_jiffies, nfsi->read_cache_jiffies + nfsi->attrtimeo);
 }
 
 /**
@@ -1296,95 +780,109 @@ int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
        return __nfs_revalidate_inode(server, inode);
 }
 
-/**
- * nfs_revalidate_mapping - Revalidate the pagecache
- * @inode - pointer to host inode
- * @mapping - pointer to mapping
- */
-int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
+static int nfs_invalidate_mapping_nolock(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);
+       
+       if (mapping->nrpages != 0) {
+               int ret = invalidate_inode_pages2(mapping);
+               if (ret < 0)
+                       return ret;
+       }
+       spin_lock(&inode->i_lock);
+       nfsi->cache_validity &= ~NFS_INO_INVALID_DATA;
+       if (S_ISDIR(inode->i_mode))
+               memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
+       spin_unlock(&inode->i_lock);
+       nfs_inc_stats(inode, NFSIOS_DATAINVALIDATE);
+       dfprintk(PAGECACHE, "NFS: (%s/%Ld) data cache invalidated\n",
+                       inode->i_sb->s_id, (long long)NFS_FILEID(inode));
+       return 0;
+}
 
-               spin_lock(&inode->i_lock);
-               nfsi->cache_validity &= ~NFS_INO_INVALID_DATA;
-               if (S_ISDIR(inode->i_mode)) {
-                       memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
-                       /* This ensures we revalidate child dentries */
-                       nfsi->cache_change_attribute = jiffies;
-               }
-               spin_unlock(&inode->i_lock);
+static int nfs_invalidate_mapping(struct inode *inode, struct address_space *mapping)
+{
+       int ret = 0;
 
-               dfprintk(PAGECACHE, "NFS: (%s/%Ld) data cache invalidated\n",
-                               inode->i_sb->s_id,
-                               (long long)NFS_FILEID(inode));
+       mutex_lock(&inode->i_mutex);
+       if (NFS_I(inode)->cache_validity & NFS_INO_INVALID_DATA) {
+               ret = nfs_sync_mapping(mapping);
+               if (ret == 0)
+                       ret = nfs_invalidate_mapping_nolock(inode, mapping);
        }
+       mutex_unlock(&inode->i_mutex);
        return ret;
 }
 
 /**
- * nfs_begin_data_update
- * @inode - pointer to inode
- * Declare that a set of operations will update file data on the server
+ * nfs_revalidate_mapping_nolock - Revalidate the pagecache
+ * @inode - pointer to host inode
+ * @mapping - pointer to mapping
  */
-void nfs_begin_data_update(struct inode *inode)
+int nfs_revalidate_mapping_nolock(struct inode *inode, struct address_space *mapping)
 {
-       atomic_inc(&NFS_I(inode)->data_updates);
+       struct nfs_inode *nfsi = NFS_I(inode);
+       int ret = 0;
+
+       if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
+                       || nfs_attribute_timeout(inode) || NFS_STALE(inode)) {
+               ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
+               if (ret < 0)
+                       goto out;
+       }
+       if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
+               ret = nfs_invalidate_mapping_nolock(inode, mapping);
+out:
+       return ret;
 }
 
 /**
- * nfs_end_data_update
- * @inode - pointer to inode
- * Declare end of the operations that will update file data
- * This will mark the inode as immediately needing revalidation
- * of its attribute cache.
+ * nfs_revalidate_mapping - Revalidate the pagecache
+ * @inode - pointer to host inode
+ * @mapping - pointer to mapping
+ *
+ * This version of the function will take the inode->i_mutex and attempt to
+ * flush out all dirty data if it needs to invalidate the page cache.
  */
-void nfs_end_data_update(struct inode *inode)
+int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
 {
        struct nfs_inode *nfsi = NFS_I(inode);
+       int ret = 0;
 
-       if (!nfs_have_delegation(inode, FMODE_READ)) {
-               /* Directories and symlinks: invalidate page cache */
-               if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) {
-                       spin_lock(&inode->i_lock);
-                       nfsi->cache_validity |= NFS_INO_INVALID_DATA;
-                       spin_unlock(&inode->i_lock);
-               }
+       if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
+                       || nfs_attribute_timeout(inode) || NFS_STALE(inode)) {
+               ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
+               if (ret < 0)
+                       goto out;
        }
-       nfsi->cache_change_attribute = jiffies;
-       atomic_dec(&nfsi->data_updates);
+       if (nfsi->cache_validity & NFS_INO_INVALID_DATA)
+               ret = nfs_invalidate_mapping(inode, mapping);
+out:
+       return ret;
 }
 
 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_WCC_V4) != 0 &&
+                       nfsi->change_attr == fattr->pre_change_attr) {
+               nfsi->change_attr = fattr->change_attr;
+               if (S_ISDIR(inode->i_mode))
+                       nfsi->cache_validity |= NFS_INO_INVALID_DATA;
+       }
        /* 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)) {
+               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;
+                       if (S_ISDIR(inode->i_mode))
+                               nfsi->cache_validity |= NFS_INO_INVALID_DATA;
                }
+               if (i_size_read(inode) == nfs_size_to_loff_t(fattr->pre_size) &&
+                   nfsi->npages == 0)
+                       i_size_write(inode, nfs_size_to_loff_t(fattr->size));
        }
 }
 
@@ -1401,7 +899,7 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
 {
        struct nfs_inode *nfsi = NFS_I(inode);
        loff_t cur_size, new_isize;
-       int data_unstable;
+       unsigned long invalid = 0;
 
 
        /* Has the inode gone and changed behind our back? */
@@ -1410,37 +908,41 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat
                return -EIO;
        }
 
-       /* Are we in the process of updating data on the server? */
-       data_unstable = nfs_caches_unstable(inode);
-
        /* 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;
+               invalid |= 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|NFS_INO_REVAL_PAGECACHE;
+               invalid |= 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;
+               invalid |= 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
                        || inode->i_gid != fattr->gid)
-               nfsi->cache_validity |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
+               invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
 
        /* Has the link count changed? */
        if (inode->i_nlink != fattr->nlink)
-               nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
+               invalid |= NFS_INO_INVALID_ATTR;
 
        if (!timespec_equal(&inode->i_atime, &fattr->atime))
-               nfsi->cache_validity |= NFS_INO_INVALID_ATIME;
+               invalid |= NFS_INO_INVALID_ATIME;
+
+       if (invalid != 0)
+               nfsi->cache_validity |= invalid;
+       else
+               nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR
+                               | NFS_INO_INVALID_ATIME
+                               | NFS_INO_REVAL_PAGECACHE);
 
        nfsi->read_cache_jiffies = fattr->time_start;
        return 0;
@@ -1480,21 +982,51 @@ int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
  *
  * After an operation that has changed the inode metadata, mark the
  * attribute cache as being invalid, then try to update it.
+ *
+ * NB: if the server didn't return any post op attributes, this
+ * function will force the retrieval of attributes before the next
+ * NFS request.  Thus it should be used only for operations that
+ * are expected to change one or more attributes, to avoid
+ * unnecessary NFS requests and trips through nfs_update_inode().
  */
 int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr)
 {
        struct nfs_inode *nfsi = NFS_I(inode);
-       int status = 0;
 
        spin_lock(&inode->i_lock);
-       if (unlikely((fattr->valid & NFS_ATTR_FATTR) == 0)) {
-               nfsi->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
-               goto out;
-       }
-       status = nfs_update_inode(inode, fattr);
-out:
+       nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
+       if (S_ISDIR(inode->i_mode))
+               nfsi->cache_validity |= NFS_INO_INVALID_DATA;
        spin_unlock(&inode->i_lock);
-       return status;
+       return nfs_refresh_inode(inode, fattr);
+}
+
+/**
+ * nfs_post_op_update_inode_force_wcc - try to update the inode attribute cache
+ * @inode - pointer to inode
+ * @fattr - updated attributes
+ *
+ * After an operation that has changed the inode metadata, mark the
+ * attribute cache as being invalid, then try to update it. Fake up
+ * weak cache consistency data, if none exist.
+ *
+ * This function is mainly designed to be used by the ->write_done() functions.
+ */
+int nfs_post_op_update_inode_force_wcc(struct inode *inode, struct nfs_fattr *fattr)
+{
+       if ((fattr->valid & NFS_ATTR_FATTR_V4) != 0 &&
+                       (fattr->valid & NFS_ATTR_WCC_V4) == 0) {
+               fattr->pre_change_attr = NFS_I(inode)->change_attr;
+               fattr->valid |= NFS_ATTR_WCC_V4;
+       }
+       if ((fattr->valid & NFS_ATTR_FATTR) != 0 &&
+                       (fattr->valid & NFS_ATTR_WCC) == 0) {
+               memcpy(&fattr->pre_ctime, &inode->i_ctime, sizeof(fattr->pre_ctime));
+               memcpy(&fattr->pre_mtime, &inode->i_mtime, sizeof(fattr->pre_mtime));
+               fattr->pre_size = i_size_read(inode);
+               fattr->valid |= NFS_ATTR_WCC;
+       }
+       return nfs_post_op_update_inode(inode, fattr);
 }
 
 /*
@@ -1514,11 +1046,11 @@ 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;
-       int data_stable;
+       unsigned long invalid = 0;
+       unsigned long now = jiffies;
 
        dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
-                       __FUNCTION__, inode->i_sb->s_id, inode->i_ino,
+                       __func__, inode->i_sb->s_id, inode->i_ino,
                        atomic_read(&inode->i_count), fattr->valid);
 
        if (nfsi->fileid != fattr->fileid)
@@ -1531,62 +1063,63 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
                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))
+       /* Update the fsid? */
+       if (S_ISDIR(inode->i_mode) &&
+                       !nfs_fsid_equal(&server->fsid, &fattr->fsid) &&
+                       !test_bit(NFS_INO_MOUNTPOINT, &nfsi->flags))
                server->fsid = fattr->fsid;
 
        /*
         * Update the read time so we don't revalidate too often.
         */
        nfsi->read_cache_jiffies = fattr->time_start;
-       nfsi->last_updated = jiffies;
 
-       /* 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_REVAL_PAGECACHE|NFS_INO_INVALID_ATIME);
+       nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ATIME
+                       | NFS_INO_REVAL_PAGECACHE);
 
        /* Do atomic weak cache consistency updates */
        nfs_wcc_update_inode(inode, fattr);
 
+       /* More cache consistency checks */
+       if (!(fattr->valid & NFS_ATTR_FATTR_V4)) {
+               /* NFSv2/v3: Check if the mtime agrees */
+               if (!timespec_equal(&inode->i_mtime, &fattr->mtime)) {
+                       dprintk("NFS: mtime change on server for file %s/%ld\n",
+                                       inode->i_sb->s_id, inode->i_ino);
+                       invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
+                       if (S_ISDIR(inode->i_mode))
+                               nfs_force_lookup_revalidate(inode);
+               }
+               /* 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;
+       } else 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);
+               invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
+               if (S_ISDIR(inode->i_mode))
+                       nfs_force_lookup_revalidate(inode);
+       }
+
        /* Check if our cached file size is stale */
        new_isize = nfs_size_to_loff_t(fattr->size);
        cur_isize = i_size_read(inode);
        if (new_isize != cur_isize) {
-               /* Do we perhaps have any outstanding writes? */
-               if (nfsi->npages == 0) {
-                       /* No, but did we race with nfs_end_data_update()? */
-                       if (data_stable) {
-                               inode->i_size = new_isize;
-                               invalid |= NFS_INO_INVALID_DATA;
-                       }
-                       invalid |= NFS_INO_INVALID_ATTR;
-               } else if (new_isize > cur_isize) {
-                       inode->i_size = new_isize;
+               /* Do we perhaps have any outstanding writes, or has
+                * the file grown beyond our last write? */
+               if (nfsi->npages == 0 || new_isize > cur_isize) {
+                       i_size_write(inode, new_isize);
                        invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
                }
-               nfsi->cache_change_attribute = jiffies;
                dprintk("NFS: isize change on server for file %s/%ld\n",
                                inode->i_sb->s_id, inode->i_ino);
        }
 
-       /* Check if the mtime agrees */
-       if (!timespec_equal(&inode->i_mtime, &fattr->mtime)) {
-               memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
-               dprintk("NFS: mtime change on server for file %s/%ld\n",
-                               inode->i_sb->s_id, inode->i_ino);
-               invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
-               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;
-               memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
-               nfsi->cache_change_attribute = jiffies;
-       }
+       memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
+       memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
        memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
+       nfsi->change_attr = fattr->change_attr;
 
        if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
            inode->i_uid != fattr->uid ||
@@ -1603,49 +1136,45 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
                 * report the blocks in 512byte units
                 */
                inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
-               inode->i_blksize = inode->i_sb->s_blocksize;
        } else {
                inode->i_blocks = fattr->du.nfs2.blocks;
-               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)) {
-               if ((nfsi->attrtimeo <<= 1) > NFS_MAXATTRTIMEO(inode))
-                       nfsi->attrtimeo = NFS_MAXATTRTIMEO(inode);
-               nfsi->attrtimeo_timestamp = jiffies;
+               nfsi->attrtimeo_timestamp = now;
+               nfsi->last_updated = now;
+       } else {
+               if (!time_in_range(now, nfsi->attrtimeo_timestamp, nfsi->attrtimeo_timestamp + nfsi->attrtimeo)) {
+                       if ((nfsi->attrtimeo <<= 1) > NFS_MAXATTRTIMEO(inode))
+                               nfsi->attrtimeo = NFS_MAXATTRTIMEO(inode);
+                       nfsi->attrtimeo_timestamp = now;
+               }
+               /*
+                * Avoid jiffy wraparound issues with nfsi->last_updated
+                */
+               if (!time_in_range(nfsi->last_updated, nfsi->read_cache_jiffies, now))
+                       nfsi->last_updated = nfsi->read_cache_jiffies;
        }
+       invalid &= ~NFS_INO_INVALID_ATTR;
        /* Don't invalidate the data if we were to blame */
        if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)
                                || S_ISLNK(inode->i_mode)))
                invalid &= ~NFS_INO_INVALID_DATA;
-       if (data_stable)
-               invalid &= ~(NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ATIME|NFS_INO_REVAL_PAGECACHE);
-       if (!nfs_have_delegation(inode, FMODE_READ))
+       if (!nfs_have_delegation(inode, FMODE_READ) ||
+                       (nfsi->cache_validity & NFS_INO_REVAL_FORCED))
                nfsi->cache_validity |= invalid;
+       nfsi->cache_validity &= ~NFS_INO_REVAL_FORCED;
 
        return 0;
  out_changed:
        /*
         * Big trouble! The inode has become a different object.
         */
-#ifdef NFS_PARANOIA
        printk(KERN_DEBUG "%s: inode %ld mode changed, %07o to %07o\n",
-                       __FUNCTION__, inode->i_ino, inode->i_mode, fattr->mode);
-#endif
+                       __func__, inode->i_ino, inode->i_mode, fattr->mode);
  out_err:
        /*
         * No need to worry about unhashing the dentry, as the
@@ -1658,1158 +1187,36 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
  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,
+               NFS_SERVER(inode)->nfs_client->cl_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;
-       char *hostname;
-       char *mnt_path;
-       struct sockaddr_in *addr;
-       rpc_authflavor_t authflavor;
-};
-
-static struct super_block *nfs_clone_generic_sb(struct nfs_clone_mount *data,
-               struct super_block *(*fill_sb)(struct nfs_server *, struct nfs_clone_mount *),
-               struct nfs_server *(*fill_server)(struct super_block *, 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);
-       char *hostname;
-       int len;
-
-       server = kmalloc(sizeof(struct nfs_server), GFP_KERNEL);
-       if (server == NULL)
-               goto out_err;
-       memcpy(server, parent, sizeof(*server));
-       hostname = (data->hostname != NULL) ? data->hostname : parent->hostname;
-       len = strlen(hostname) + 1;
-       server->hostname = kmalloc(len, GFP_KERNEL);
-       if (server->hostname == NULL)
-               goto free_server;
-       memcpy(server->hostname, hostname, len);
-       if (rpciod_up() != 0)
-               goto free_hostname;
-
-       sb = fill_sb(server, data);
-       if (IS_ERR((err = sb)) || sb->s_root)
-               goto kill_rpciod;
-
-       server = fill_server(sb, data);
-       if (IS_ERR((err = server)))
-               goto out_deactivate;
-       return sb;
-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;
-       return set_anon_super(s, data);
-}
-static int nfs_compare_super(struct super_block *sb, void *data)
-{
-       struct nfs_server *server = data;
-       struct nfs_server *old = NFS_SB(sb);
-
-       if (old->addr.sin_addr.s_addr != server->addr.sin_addr.s_addr)
-               return 0;
-       if (old->addr.sin_port != server->addr.sin_port)
-               return 0;
-       return !nfs_compare_fh(&old->fh, &server->fh);
-}
-
-static struct super_block *nfs_get_sb(struct file_system_type *fs_type,
-       int flags, const char *dev_name, void *raw_data)
-{
-       int error;
-       struct nfs_server *server = NULL;
-       struct super_block *s;
-       struct nfs_fh *root;
-       struct nfs_mount_data *data = raw_data;
-
-       s = ERR_PTR(-EINVAL);
-       if (data == NULL) {
-               dprintk("%s: missing data argument\n", __FUNCTION__);
-               goto out_err;
-       }
-       if (data->version <= 0 || data->version > NFS_MOUNT_VERSION) {
-               dprintk("%s: bad mount version\n", __FUNCTION__);
-               goto out_err;
-       }
-       switch (data->version) {
-               case 1:
-                       data->namlen = 0;
-               case 2:
-                       data->bsize  = 0;
-               case 3:
-                       if (data->flags & NFS_MOUNT_VER3) {
-                               dprintk("%s: mount structure version %d does not support NFSv3\n",
-                                               __FUNCTION__,
-                                               data->version);
-                               goto out_err;
-                       }
-                       data->root.size = NFS2_FHSIZE;
-                       memcpy(data->root.data, data->old_root.data, NFS2_FHSIZE);
-               case 4:
-                       if (data->flags & NFS_MOUNT_SECFLAVOUR) {
-                               dprintk("%s: mount structure version %d does not support strong security\n",
-                                               __FUNCTION__,
-                                               data->version);
-                               goto out_err;
-                       }
-               case 5:
-                       memset(data->context, 0, sizeof(data->context));
-       }
-#ifndef CONFIG_NFS_V3
-       /* If NFSv3 is not compiled in, return -EPROTONOSUPPORT */
-       s = ERR_PTR(-EPROTONOSUPPORT);
-       if (data->flags & NFS_MOUNT_VER3) {
-               dprintk("%s: NFSv3 not compiled into kernel\n", __FUNCTION__);
-               goto out_err;
-       }
-#endif /* CONFIG_NFS_V3 */
-
-       s = ERR_PTR(-ENOMEM);
-       server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
-       if (!server)
-               goto out_err;
-       /* Zero out the NFS state stuff */
-       init_nfsv4_state(server);
-       server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
-
-       root = &server->fh;
-       if (data->flags & NFS_MOUNT_VER3)
-               root->size = data->root.size;
-       else
-               root->size = NFS2_FHSIZE;
-       s = ERR_PTR(-EINVAL);
-       if (root->size > sizeof(root->data)) {
-               dprintk("%s: invalid root filehandle\n", __FUNCTION__);
-               goto out_err;
-       }
-       memcpy(root->data, data->root.data, root->size);
-
-       /* We now require that the mount process passes the remote address */
-       memcpy(&server->addr, &data->addr, sizeof(server->addr));
-       if (server->addr.sin_addr.s_addr == INADDR_ANY) {
-               dprintk("%s: mount program didn't pass remote address!\n",
-                               __FUNCTION__);
-               goto out_err;
-       }
-
-       /* Fire up rpciod if not yet running */
-       s = ERR_PTR(rpciod_up());
-       if (IS_ERR(s)) {
-               dprintk("%s: couldn't start rpciod! Error = %ld\n",
-                               __FUNCTION__, PTR_ERR(s));
-               goto out_err;
-       }
-
-       s = sget(fs_type, nfs_compare_super, nfs_set_super, server);
-       if (IS_ERR(s) || s->s_root)
-               goto out_rpciod_down;
-
-       s->s_flags = flags;
-
-       error = nfs_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
-       if (error) {
-               up_write(&s->s_umount);
-               deactivate_super(s);
-               return ERR_PTR(error);
-       }
-       s->s_flags |= MS_ACTIVE;
-       return s;
-out_rpciod_down:
-       rpciod_down();
-out_err:
-       kfree(server);
-       return s;
-}
-
-static void nfs_kill_super(struct super_block *s)
-{
-       struct nfs_server *server = NFS_SB(s);
-
-       kill_anon_super(s);
-
-       if (!IS_ERR(server->client))
-               rpc_shutdown_client(server->client);
-       if (!IS_ERR(server->client_sys))
-               rpc_shutdown_client(server->client_sys);
-       if (!IS_ERR(server->client_acl))
-               rpc_shutdown_client(server->client_acl);
-
-       if (!(server->flags & NFS_MOUNT_NONLM))
-               lockd_down();   /* release rpc.lockd */
-
-       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 = {
-       .owner          = THIS_MODULE,
-       .name           = "nfs",
-       .get_sb         = nfs_get_sb,
-       .kill_sb        = nfs_kill_super,
-       .fs_flags       = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
-};
-
-static struct super_block *nfs_clone_sb(struct nfs_server *server, struct nfs_clone_mount *data)
-{
-       struct super_block *sb;
-
-       server->fsid = data->fattr->fsid;
-       nfs_copy_fh(&server->fh, data->fh);
-       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 nfs_server *nfs_clone_server(struct super_block *sb, struct nfs_clone_mount *data)
-{
-       struct nfs_server *server = NFS_SB(sb);
-       struct nfs_server *parent = NFS_SB(data->sb);
-       struct inode *root_inode;
-       struct nfs_fsinfo fsinfo;
-       void *err = ERR_PTR(-ENOMEM);
-
-       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);
-       server->io_stats = nfs_alloc_iostats();
-       if (server->io_stats == NULL)
-               goto out;
-
-       server->client = rpc_clone_client(parent->client);
-       if (IS_ERR((err = server->client)))
-               goto out;
-
-       if (!IS_ERR(parent->client_sys)) {
-               server->client_sys = rpc_clone_client(parent->client_sys);
-               if (IS_ERR((err = server->client_sys)))
-                       goto out;
-       }
-       if (!IS_ERR(parent->client_acl)) {
-               server->client_acl = rpc_clone_client(parent->client_acl);
-               if (IS_ERR((err = server->client_acl)))
-                       goto out;
-       }
-       root_inode = nfs_fhget(sb, data->fh, data->fattr);
-       if (!root_inode)
-               goto out;
-       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 server;
-out_put_root:
-       iput(root_inode);
-out:
-       return err;
-}
-
-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_sb, nfs_clone_server);
-}
-
-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 *);
-
-
-static struct super_operations nfs4_sops = { 
-       .alloc_inode    = nfs_alloc_inode,
-       .destroy_inode  = nfs_destroy_inode,
-       .write_inode    = nfs_write_inode,
-       .statfs         = nfs_statfs,
-       .clear_inode    = nfs4_clear_inode,
-       .umount_begin   = nfs_umount_begin,
-       .show_options   = nfs_show_options,
-       .show_stats     = nfs_show_stats,
-};
-
 /*
  * Clean out any remaining NFSv4 state that might be left over due
  * to open() calls that passed nfs_atomic_lookup, but failed to call
  * nfs_open().
  */
-static void nfs4_clear_inode(struct inode *inode)
+void nfs4_clear_inode(struct inode *inode)
 {
-       struct nfs_inode *nfsi = NFS_I(inode);
-
        /* If we are holding a delegation, return it! */
-       nfs_inode_return_delegation(inode);
+       nfs_inode_return_delegation_noreclaim(inode);
        /* First call standard NFS clear_inode() code */
        nfs_clear_inode(inode);
-       /* Now clear out any remaining state */
-       while (!list_empty(&nfsi->open_states)) {
-               struct nfs4_state *state;
-               
-               state = list_entry(nfsi->open_states.next,
-                               struct nfs4_state,
-                               inode_states);
-               dprintk("%s(%s/%Ld): found unclaimed NFSv4 state %p\n",
-                               __FUNCTION__,
-                               inode->i_sb->s_id,
-                               (long long)NFS_FILEID(inode),
-                               state);
-               BUG_ON(atomic_read(&state->count) != 1);
-               nfs4_close_state(state, state->state);
-       }
-}
-
-
-static struct rpc_clnt *nfs4_create_client(struct nfs_server *server,
-       struct rpc_timeout *timeparms, int proto, rpc_authflavor_t flavor)
-{
-       struct nfs4_client *clp;
-       struct rpc_xprt *xprt = NULL;
-       struct rpc_clnt *clnt = NULL;
-       int err = -EIO;
-
-       clp = nfs4_get_client(&server->addr.sin_addr);
-       if (!clp) {
-               dprintk("%s: failed to create NFS4 client.\n", __FUNCTION__);
-               return ERR_PTR(err);
-       }
-
-       /* Now create transport and client */
-       down_write(&clp->cl_sem);
-       if (IS_ERR(clp->cl_rpcclient)) {
-               xprt = xprt_create_proto(proto, &server->addr, timeparms);
-               if (IS_ERR(xprt)) {
-                       up_write(&clp->cl_sem);
-                       err = PTR_ERR(xprt);
-                       dprintk("%s: cannot create RPC transport. Error = %d\n",
-                                       __FUNCTION__, err);
-                       goto out_fail;
-               }
-               clnt = rpc_create_client(xprt, server->hostname, &nfs_program,
-                               server->rpc_ops->version, flavor);
-               if (IS_ERR(clnt)) {
-                       up_write(&clp->cl_sem);
-                       err = PTR_ERR(clnt);
-                       dprintk("%s: cannot create RPC client. Error = %d\n",
-                                       __FUNCTION__, err);
-                       goto out_fail;
-               }
-               clnt->cl_intr     = 1;
-               clnt->cl_softrtry = 1;
-               clp->cl_rpcclient = clnt;
-               memcpy(clp->cl_ipaddr, server->ip_addr, sizeof(clp->cl_ipaddr));
-               nfs_idmap_new(clp);
-       }
-       list_add_tail(&server->nfs4_siblings, &clp->cl_superblocks);
-       clnt = rpc_clone_client(clp->cl_rpcclient);
-       if (!IS_ERR(clnt))
-               server->nfs4_state = clp;
-       up_write(&clp->cl_sem);
-       clp = NULL;
-
-       if (IS_ERR(clnt)) {
-               dprintk("%s: cannot create RPC client. Error = %d\n",
-                               __FUNCTION__, err);
-               return clnt;
-       }
-
-       if (server->nfs4_state->cl_idmap == NULL) {
-               dprintk("%s: failed to create idmapper.\n", __FUNCTION__);
-               return ERR_PTR(-ENOMEM);
-       }
-
-       if (clnt->cl_auth->au_flavor != flavor) {
-               struct rpc_auth *auth;
-
-               auth = rpcauth_create(flavor, clnt);
-               if (IS_ERR(auth)) {
-                       dprintk("%s: couldn't create credcache!\n", __FUNCTION__);
-                       return (struct rpc_clnt *)auth;
-               }
-       }
-       return clnt;
-
- out_fail:
-       if (clp)
-               nfs4_put_client(clp);
-       return ERR_PTR(err);
-}
-
-static int nfs4_fill_super(struct super_block *sb, struct nfs4_mount_data *data, int silent)
-{
-       struct nfs_server *server;
-       struct rpc_timeout timeparms;
-       rpc_authflavor_t authflavour;
-       int err = -EIO;
-
-       sb->s_blocksize_bits = 0;
-       sb->s_blocksize = 0;
-       server = NFS_SB(sb);
-       if (data->rsize != 0)
-               server->rsize = nfs_block_size(data->rsize, NULL);
-       if (data->wsize != 0)
-               server->wsize = nfs_block_size(data->wsize, NULL);
-       server->flags = data->flags & NFS_MOUNT_FLAGMASK;
-       server->caps = NFS_CAP_ATOMIC_OPEN;
-
-       server->acregmin = data->acregmin*HZ;
-       server->acregmax = data->acregmax*HZ;
-       server->acdirmin = data->acdirmin*HZ;
-       server->acdirmax = data->acdirmax*HZ;
-
-       server->rpc_ops = &nfs_v4_clientops;
-
-       nfs_init_timeout_values(&timeparms, data->proto, data->timeo, data->retrans);
-
-       server->retrans_timeo = timeparms.to_initval;
-       server->retrans_count = timeparms.to_retries;
-
-       /* Now create transport and client */
-       authflavour = RPC_AUTH_UNIX;
-       if (data->auth_flavourlen != 0) {
-               if (data->auth_flavourlen != 1) {
-                       dprintk("%s: Invalid number of RPC auth flavours %d.\n",
-                                       __FUNCTION__, data->auth_flavourlen);
-                       err = -EINVAL;
-                       goto out_fail;
-               }
-               if (copy_from_user(&authflavour, data->auth_flavours, sizeof(authflavour))) {
-                       err = -EFAULT;
-                       goto out_fail;
-               }
-       }
-
-       server->client = nfs4_create_client(server, &timeparms, data->proto, authflavour);
-       if (IS_ERR(server->client)) {
-               err = PTR_ERR(server->client);
-                       dprintk("%s: cannot create RPC client. Error = %d\n",
-                                       __FUNCTION__, err);
-                       goto out_fail;
-       }
-
-       sb->s_time_gran = 1;
-
-       sb->s_op = &nfs4_sops;
-       err = nfs_sb_init(sb, authflavour);
-
- out_fail:
-       return err;
-}
-
-static int nfs4_compare_super(struct super_block *sb, void *data)
-{
-       struct nfs_server *server = data;
-       struct nfs_server *old = NFS_SB(sb);
-
-       if (strcmp(server->hostname, old->hostname) != 0)
-               return 0;
-       if (strcmp(server->mnt_path, old->mnt_path) != 0)
-               return 0;
-       return 1;
-}
-
-static void *
-nfs_copy_user_string(char *dst, struct nfs_string *src, int maxlen)
-{
-       void *p = NULL;
-
-       if (!src->len)
-               return ERR_PTR(-EINVAL);
-       if (src->len < maxlen)
-               maxlen = src->len;
-       if (dst == NULL) {
-               p = dst = kmalloc(maxlen + 1, GFP_KERNEL);
-               if (p == NULL)
-                       return ERR_PTR(-ENOMEM);
-       }
-       if (copy_from_user(dst, src->data, maxlen)) {
-               kfree(p);
-               return ERR_PTR(-EFAULT);
-       }
-       dst[maxlen] = '\0';
-       return dst;
-}
-
-static struct super_block *nfs4_get_sb(struct file_system_type *fs_type,
-       int flags, const char *dev_name, void *raw_data)
-{
-       int error;
-       struct nfs_server *server;
-       struct super_block *s;
-       struct nfs4_mount_data *data = raw_data;
-       void *p;
-
-       if (data == NULL) {
-               dprintk("%s: missing data argument\n", __FUNCTION__);
-               return ERR_PTR(-EINVAL);
-       }
-       if (data->version <= 0 || data->version > NFS4_MOUNT_VERSION) {
-               dprintk("%s: bad mount version\n", __FUNCTION__);
-               return ERR_PTR(-EINVAL);
-       }
-
-       server = kzalloc(sizeof(struct nfs_server), GFP_KERNEL);
-       if (!server)
-               return ERR_PTR(-ENOMEM);
-       /* Zero out the NFS state stuff */
-       init_nfsv4_state(server);
-       server->client = server->client_sys = server->client_acl = ERR_PTR(-EINVAL);
-
-       p = nfs_copy_user_string(NULL, &data->hostname, 256);
-       if (IS_ERR(p))
-               goto out_err;
-       server->hostname = p;
-
-       p = nfs_copy_user_string(NULL, &data->mnt_path, 1024);
-       if (IS_ERR(p))
-               goto out_err;
-       server->mnt_path = p;
-
-       p = nfs_copy_user_string(server->ip_addr, &data->client_addr,
-                       sizeof(server->ip_addr) - 1);
-       if (IS_ERR(p))
-               goto out_err;
-
-       /* We now require that the mount process passes the remote address */
-       if (data->host_addrlen != sizeof(server->addr)) {
-               s = ERR_PTR(-EINVAL);
-               goto out_free;
-       }
-       if (copy_from_user(&server->addr, data->host_addr, sizeof(server->addr))) {
-               s = ERR_PTR(-EFAULT);
-               goto out_free;
-       }
-       if (server->addr.sin_family != AF_INET ||
-           server->addr.sin_addr.s_addr == INADDR_ANY) {
-               dprintk("%s: mount program didn't pass remote IP address!\n",
-                               __FUNCTION__);
-               s = ERR_PTR(-EINVAL);
-               goto out_free;
-       }
-
-       /* Fire up rpciod if not yet running */
-       s = ERR_PTR(rpciod_up());
-       if (IS_ERR(s)) {
-               dprintk("%s: couldn't start rpciod! Error = %ld\n",
-                               __FUNCTION__, PTR_ERR(s));
-               goto out_free;
-       }
-
-       s = sget(fs_type, nfs4_compare_super, nfs_set_super, server);
-
-       if (IS_ERR(s) || s->s_root)
-               goto out_free;
-
-       s->s_flags = flags;
-
-       error = nfs4_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
-       if (error) {
-               up_write(&s->s_umount);
-               deactivate_super(s);
-               return ERR_PTR(error);
-       }
-       s->s_flags |= MS_ACTIVE;
-       return s;
-out_err:
-       s = (struct super_block *)p;
-out_free:
-       kfree(server->mnt_path);
-       kfree(server->hostname);
-       kfree(server);
-       return s;
-}
-
-static void nfs4_kill_super(struct super_block *sb)
-{
-       struct nfs_server *server = NFS_SB(sb);
-
-       nfs_return_all_delegations(sb);
-       kill_anon_super(sb);
-
-       nfs4_renewd_prepare_shutdown(server);
-
-       if (server->client != NULL && !IS_ERR(server->client))
-               rpc_shutdown_client(server->client);
-
-       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 = {
-       .owner          = THIS_MODULE,
-       .name           = "nfs4",
-       .get_sb         = nfs4_get_sb,
-       .kill_sb        = nfs4_kill_super,
-       .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_sb(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->fsid = data->fattr->fsid;
-       nfs_copy_fh(&server->fh, data->fh);
-       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_sb, nfs_clone_server);
-}
-
-static struct file_system_type clone_nfs4_fs_type = {
-       .owner          = THIS_MODULE,
-       .name           = "nfs4",
-       .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); \
-               nfsi->delegation = NULL; \
-               nfsi->delegation_state = 0; \
-               init_rwsem(&nfsi->rwsem); \
-       } while(0)
-
-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_fill_sb(a,b)      ERR_PTR(-EINVAL)
-#define nfs4_fill_super(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;
 }
-
-/* Check if fs_root is valid */
-static inline char *nfs4_pathname_string(struct nfs4_pathname *pathname, char *buffer, ssize_t buflen)
-{
-       char *end = buffer + buflen;
-       int n;
-
-       *--end = '\0';
-       buflen--;
-
-       n = pathname->ncomponents;
-       while (--n >= 0) {
-               struct nfs4_string *component = &pathname->components[n];
-               buflen -= component->len + 1;
-               if (buflen < 0)
-                       goto Elong;
-               end -= component->len;
-               memcpy(end, component->data, component->len);
-               *--end = '/';
-       }
-       return end;
-Elong:
-       return ERR_PTR(-ENAMETOOLONG);
-}
-
-/* Check if the string represents a "valid" IPv4 address */
-static inline int valid_ipaddr4(const char *buf)
-{
-       int rc, count, in[4];
-
-       rc = sscanf(buf, "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]);
-       if (rc != 4)
-               return -EINVAL;
-       for (count = 0; count < 4; count++) {
-               if (in[count] > 255)
-                       return -EINVAL;
-       }
-       return 0;
-}
-
-static struct super_block *nfs4_referral_sb(struct nfs_server *server, struct nfs_clone_mount *data)
-{
-       struct super_block *sb = ERR_PTR(-ENOMEM);
-       int len;
-
-       len = strlen(data->mnt_path) + 1;
-       server->mnt_path = kmalloc(len, GFP_KERNEL);
-       if (server->mnt_path == NULL)
-               goto err;
-       memcpy(server->mnt_path, data->mnt_path, len);
-       memcpy(&server->addr, data->addr, sizeof(struct sockaddr_in));
-
-       sb = sget(&nfs4_fs_type, nfs4_compare_super, nfs_set_super, server);
-       if (IS_ERR(sb) || sb->s_root)
-               goto free_path;
-       return sb;
-free_path:
-       kfree(server->mnt_path);
-err:
-       server->mnt_path = NULL;
-       return sb;
-}
-
-static struct nfs_server *nfs4_referral_server(struct super_block *sb, struct nfs_clone_mount *data)
-{
-       struct nfs_server *server = NFS_SB(sb);
-       struct rpc_timeout timeparms;
-       int proto, timeo, retrans;
-       void *err;
-
-       proto = IPPROTO_TCP;
-       /* Since we are following a referral and there may be alternatives,
-          set the timeouts and retries to low values */
-       timeo = 2;
-       retrans = 1;
-       nfs_init_timeout_values(&timeparms, proto, timeo, retrans);
-
-       server->client = nfs4_create_client(server, &timeparms, proto, data->authflavor);
-       if (IS_ERR((err = server->client)))
-               goto out_err;
-
-       sb->s_time_gran = 1;
-       sb->s_op = &nfs4_sops;
-       err = ERR_PTR(nfs_sb_init(sb, data->authflavor));
-       if (!IS_ERR(err))
-               return server;
-out_err:
-       return (struct nfs_server *)err;
-}
-
-static struct super_block *nfs_referral_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_referral_sb, nfs4_referral_server);
-}
-
-static struct file_system_type nfs_referral_nfs4_fs_type = {
-       .owner          = THIS_MODULE,
-       .name           = "nfs4",
-       .get_sb         = nfs_referral_nfs4_sb,
-       .kill_sb        = nfs4_kill_super,
-       .fs_flags       = FS_ODD_RENAME|FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
-};
-
-/**
- * nfs_follow_referral - set up mountpoint when hitting a referral on moved error
- * @mnt_parent - mountpoint of parent directory
- * @dentry - parent directory
- * @fspath - fs path returned in fs_locations
- * @mntpath - mount path to new server
- * @hostname - hostname of new server
- * @addr - host addr of new server
- *
- */
-struct vfsmount *nfs_follow_referral(const struct vfsmount *mnt_parent,
-            const struct dentry *dentry, struct nfs4_fs_locations *locations)
-{
-       struct vfsmount *mnt = ERR_PTR(-ENOENT);
-       struct nfs_clone_mount mountdata = {
-               .sb = mnt_parent->mnt_sb,
-               .dentry = dentry,
-               .authflavor = NFS_SB(mnt_parent->mnt_sb)->client->cl_auth->au_flavor,
-       };
-       char *page, *page2;
-       char *path, *fs_path;
-       char *devname;
-       int loc, s;
-
-       if (locations == NULL || locations->nlocations <= 0)
-               goto out;
-
-       dprintk("%s: referral at %s/%s\n", __FUNCTION__,
-               dentry->d_parent->d_name.name, dentry->d_name.name);
-
-       /* Ensure fs path is a prefix of current dentry path */
-       page = (char *) __get_free_page(GFP_USER);
-       if (page == NULL)
-               goto out;
-       page2 = (char *) __get_free_page(GFP_USER);
-       if (page2 == NULL)
-               goto out;
-
-       path = nfs4_path(dentry, page, PAGE_SIZE);
-       if (IS_ERR(path))
-               goto out_free;
-
-       fs_path = nfs4_pathname_string(&locations->fs_path, page2, PAGE_SIZE);
-       if (IS_ERR(fs_path))
-               goto out_free;
-
-       if (strncmp(path, fs_path, strlen(fs_path)) != 0) {
-               dprintk("%s: path %s does not begin with fsroot %s\n", __FUNCTION__, path, fs_path);
-               goto out_free;
-       }
-
-       devname = nfs_devname(mnt_parent, dentry, page, PAGE_SIZE);
-       if (IS_ERR(devname)) {
-               mnt = (struct vfsmount *)devname;
-               goto out_free;
-       }
-
-       loc = 0;
-       while (loc < locations->nlocations && IS_ERR(mnt)) {
-               struct nfs4_fs_location *location = &locations->locations[loc];
-               char *mnt_path;
-
-               if (location == NULL || location->nservers <= 0 ||
-                   location->rootpath.ncomponents == 0) {
-                       loc++;
-                       continue;
-               }
-
-               mnt_path = nfs4_pathname_string(&location->rootpath, page2, PAGE_SIZE);
-               if (IS_ERR(mnt_path)) {
-                       loc++;
-                       continue;
-               }
-               mountdata.mnt_path = mnt_path;
-
-               s = 0;
-               while (s < location->nservers) {
-                       struct sockaddr_in addr = {};
-
-                       if (location->servers[s].len <= 0 ||
-                           valid_ipaddr4(location->servers[s].data) < 0) {
-                               s++;
-                               continue;
-                       }
-
-                       mountdata.hostname = location->servers[s].data;
-                       addr.sin_addr.s_addr = in_aton(mountdata.hostname);
-                       addr.sin_family = AF_INET;
-                       addr.sin_port = htons(NFS_PORT);
-                       mountdata.addr = &addr;
-
-                       mnt = vfs_kern_mount(&nfs_referral_nfs4_fs_type, 0, devname, &mountdata);
-                       if (!IS_ERR(mnt)) {
-                               break;
-                       }
-                       s++;
-               }
-               loc++;
-       }
-
-out_free:
-       free_page((unsigned long)page);
-       free_page((unsigned long)page2);
-out:
-       dprintk("%s: done\n", __FUNCTION__);
-       return mnt;
-}
-
-/*
- * nfs_do_refmount - handle crossing a referral on server
- * @dentry - dentry of referral
- * @nd - nameidata info
- *
- */
-struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
-{
-       struct vfsmount *mnt = ERR_PTR(-ENOENT);
-       struct dentry *parent;
-       struct nfs4_fs_locations *fs_locations = NULL;
-       struct page *page;
-       int err;
-
-       /* BUG_ON(IS_ROOT(dentry)); */
-       dprintk("%s: enter\n", __FUNCTION__);
-
-       page = alloc_page(GFP_KERNEL);
-       if (page == NULL)
-               goto out;
-
-       fs_locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
-       if (fs_locations == NULL)
-               goto out_free;
-
-       /* Get locations */
-       parent = dget_parent(dentry);
-       dprintk("%s: getting locations for %s/%s\n", __FUNCTION__, parent->d_name.name, dentry->d_name.name);
-       err = nfs4_proc_fs_locations(parent->d_inode, dentry, fs_locations, page);
-       dput(parent);
-       if (err != 0 || fs_locations->nlocations <= 0 ||
-           fs_locations->fs_path.ncomponents <= 0)
-               goto out_free;
-
-       mnt = nfs_follow_referral(mnt_parent, dentry, fs_locations);
-out_free:
-       __free_page(page);
-       kfree(fs_locations);
-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);
-extern void nfs_destroy_readpagecache(void);
-extern int nfs_init_writepagecache(void);
-extern void nfs_destroy_writepagecache(void);
-#ifdef CONFIG_NFS_DIRECTIO
-extern int nfs_init_directcache(void);
-extern void nfs_destroy_directcache(void);
 #endif
 
-static kmem_cache_t * nfs_inode_cachep;
-
-static struct inode *nfs_alloc_inode(struct super_block *sb)
+struct inode *nfs_alloc_inode(struct super_block *sb)
 {
        struct nfs_inode *nfsi;
-       nfsi = (struct nfs_inode *)kmem_cache_alloc(nfs_inode_cachep, SLAB_KERNEL);
+       nfsi = (struct nfs_inode *)kmem_cache_alloc(nfs_inode_cachep, GFP_KERNEL);
        if (!nfsi)
                return NULL;
        nfsi->flags = 0UL;
        nfsi->cache_validity = 0UL;
-       nfsi->cache_change_attribute = jiffies;
 #ifdef CONFIG_NFS_V3_ACL
        nfsi->acl_access = ERR_PTR(-EAGAIN);
        nfsi->acl_default = ERR_PTR(-EAGAIN);
@@ -2820,38 +1227,45 @@ static struct inode *nfs_alloc_inode(struct super_block *sb)
        return &nfsi->vfs_inode;
 }
 
-static void nfs_destroy_inode(struct inode *inode)
+void nfs_destroy_inode(struct inode *inode)
 {
        kmem_cache_free(nfs_inode_cachep, NFS_I(inode));
 }
 
-static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
+static inline void nfs4_init_once(struct nfs_inode *nfsi)
+{
+#ifdef CONFIG_NFS_V4
+       INIT_LIST_HEAD(&nfsi->open_states);
+       nfsi->delegation = NULL;
+       nfsi->delegation_state = 0;
+       init_rwsem(&nfsi->rwsem);
+#endif
+}
+
+static void init_once(struct kmem_cache * cachep, void *foo)
 {
        struct nfs_inode *nfsi = (struct nfs_inode *) foo;
 
-       if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
-           SLAB_CTOR_CONSTRUCTOR) {
-               inode_init_once(&nfsi->vfs_inode);
-               spin_lock_init(&nfsi->req_lock);
-               INIT_LIST_HEAD(&nfsi->dirty);
-               INIT_LIST_HEAD(&nfsi->commit);
-               INIT_LIST_HEAD(&nfsi->open_files);
-               INIT_RADIX_TREE(&nfsi->nfs_page_tree, GFP_ATOMIC);
-               atomic_set(&nfsi->data_updates, 0);
-               nfsi->ndirty = 0;
-               nfsi->ncommit = 0;
-               nfsi->npages = 0;
-               nfs4_init_once(nfsi);
-       }
+       inode_init_once(&nfsi->vfs_inode);
+       INIT_LIST_HEAD(&nfsi->open_files);
+       INIT_LIST_HEAD(&nfsi->access_cache_entry_lru);
+       INIT_LIST_HEAD(&nfsi->access_cache_inode_lru);
+       INIT_RADIX_TREE(&nfsi->nfs_page_tree, GFP_ATOMIC);
+       nfsi->ncommit = 0;
+       nfsi->npages = 0;
+       atomic_set(&nfsi->silly_count, 1);
+       INIT_HLIST_HEAD(&nfsi->silly_list);
+       init_waitqueue_head(&nfsi->waitqueue);
+       nfs4_init_once(nfsi);
 }
-static int nfs_init_inodecache(void)
+
+static int __init nfs_init_inodecache(void)
 {
        nfs_inode_cachep = kmem_cache_create("nfs_inode_cache",
                                             sizeof(struct nfs_inode),
                                             0, (SLAB_RECLAIM_ACCOUNT|
                                                SLAB_MEM_SPREAD),
-                                            init_once, NULL);
+                                            init_once);
        if (nfs_inode_cachep == NULL)
                return -ENOMEM;
 
@@ -2860,8 +1274,37 @@ static int nfs_init_inodecache(void)
 
 static void nfs_destroy_inodecache(void)
 {
-       if (kmem_cache_destroy(nfs_inode_cachep))
-               printk(KERN_INFO "nfs_inode_cache: not all structures were freed\n");
+       kmem_cache_destroy(nfs_inode_cachep);
+}
+
+struct workqueue_struct *nfsiod_workqueue;
+
+/*
+ * start up the nfsiod workqueue
+ */
+static int nfsiod_start(void)
+{
+       struct workqueue_struct *wq;
+       dprintk("RPC:       creating workqueue nfsiod\n");
+       wq = create_singlethread_workqueue("nfsiod");
+       if (wq == NULL)
+               return -ENOMEM;
+       nfsiod_workqueue = wq;
+       return 0;
+}
+
+/*
+ * Destroy the nfsiod workqueue
+ */
+static void nfsiod_stop(void)
+{
+       struct workqueue_struct *wq;
+
+       wq = nfsiod_workqueue;
+       if (wq == NULL)
+               return;
+       nfsiod_workqueue = NULL;
+       destroy_workqueue(wq);
 }
 
 /*
@@ -2871,6 +1314,14 @@ static int __init init_nfs_fs(void)
 {
        int err;
 
+       err = nfsiod_start();
+       if (err)
+               goto out6;
+
+       err = nfs_fs_proc_init();
+       if (err)
+               goto out5;
+
        err = nfs_init_nfspagecache();
        if (err)
                goto out4;
@@ -2887,29 +1338,22 @@ static int __init init_nfs_fs(void)
        if (err)
                goto out1;
 
-#ifdef CONFIG_NFS_DIRECTIO
        err = nfs_init_directcache();
        if (err)
                goto out0;
-#endif
 
 #ifdef CONFIG_PROC_FS
        rpc_proc_register(&nfs_rpcstat);
 #endif
-        err = register_filesystem(&nfs_fs_type);
-       if (err)
-               goto out;
-       if ((err = register_nfs4fs()) != 0)
+       if ((err = register_nfs_fs()) != 0)
                goto out;
        return 0;
 out:
 #ifdef CONFIG_PROC_FS
        rpc_proc_unregister("nfs");
 #endif
-#ifdef CONFIG_NFS_DIRECTIO
        nfs_destroy_directcache();
 out0:
-#endif
        nfs_destroy_writepagecache();
 out1:
        nfs_destroy_readpagecache();
@@ -2918,14 +1362,16 @@ out2:
 out3:
        nfs_destroy_nfspagecache();
 out4:
+       nfs_fs_proc_exit();
+out5:
+       nfsiod_stop();
+out6:
        return err;
 }
 
 static void __exit exit_nfs_fs(void)
 {
-#ifdef CONFIG_NFS_DIRECTIO
        nfs_destroy_directcache();
-#endif
        nfs_destroy_writepagecache();
        nfs_destroy_readpagecache();
        nfs_destroy_inodecache();
@@ -2933,13 +1379,15 @@ static void __exit exit_nfs_fs(void)
 #ifdef CONFIG_PROC_FS
        rpc_proc_unregister("nfs");
 #endif
-       unregister_filesystem(&nfs_fs_type);
-       unregister_nfs4fs();
+       unregister_nfs_fs();
+       nfs_fs_proc_exit();
+       nfsiod_stop();
 }
 
 /* Not quite true; I just maintain it */
 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
 MODULE_LICENSE("GPL");
+module_param(enable_ino64, bool, 0644);
 
 module_init(init_nfs_fs)
 module_exit(exit_nfs_fs)