[PATCH] slab: remove kmem_cache_t
[pandora-kernel.git] / fs / nfs / inode.c
index c5b9166..15afa46 100644 (file)
@@ -13,7 +13,6 @@
  *
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
 
@@ -56,7 +55,7 @@ static int nfs_update_inode(struct inode *, struct nfs_fattr *);
 
 static void nfs_zap_acl_cache(struct inode *);
 
-static kmem_cache_t * nfs_inode_cachep;
+static struct kmem_cache * nfs_inode_cachep;
 
 static inline unsigned long
 nfs_fattr_to_ino_t(struct nfs_fattr *fattr)
@@ -77,19 +76,14 @@ int nfs_write_inode(struct inode *inode, int sync)
 
 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));
+       BUG_ON(!list_empty(&NFS_I(inode)->open_files));
+       BUG_ON(atomic_read(&NFS_I(inode)->data_updates) != 0);
        nfs_zap_acl_cache(inode);
-       cred = nfsi->cache_access.cred;
-       if (cred)
-               put_rpccred(cred);
-       BUG_ON(atomic_read(&nfsi->data_updates) != 0);
+       nfs_access_zap_cache(inode);
 }
 
 /**
@@ -137,6 +131,15 @@ void nfs_zap_caches(struct inode *inode)
        spin_unlock(&inode->i_lock);
 }
 
+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);
+       }
+}
+
 static void nfs_zap_acl_cache(struct inode *inode)
 {
        void (*clear_acl_cache)(struct inode *);
@@ -243,13 +246,13 @@ 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)
@@ -283,15 +286,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;
                memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
-               nfsi->cache_access.cred = NULL;
+               nfsi->access_cache = RB_ROOT;
 
                unlock_new_inode(inode);
        } else
@@ -449,7 +450,7 @@ 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);
@@ -582,7 +583,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *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;
@@ -679,13 +680,20 @@ int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
        if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
                        || nfs_attribute_timeout(inode))
                ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
+       if (ret < 0)
+               goto out;
 
        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) {
+                       if (S_ISREG(inode->i_mode)) {
+                               ret = nfs_sync_mapping(mapping);
+                               if (ret < 0)
+                                       goto out;
+                       }
+                       ret = invalidate_inode_pages2(mapping);
+                       if (ret < 0)
+                               goto out;
+               }
                spin_lock(&inode->i_lock);
                nfsi->cache_validity &= ~NFS_INO_INVALID_DATA;
                if (S_ISDIR(inode->i_mode)) {
@@ -695,10 +703,12 @@ int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
                }
                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));
        }
+out:
        return ret;
 }
 
@@ -723,13 +733,11 @@ void nfs_end_data_update(struct inode *inode)
 {
        struct nfs_inode *nfsi = NFS_I(inode);
 
-       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);
-               }
+       /* Directories: invalidate page cache */
+       if (S_ISDIR(inode->i_mode)) {
+               spin_lock(&inode->i_lock);
+               nfsi->cache_validity |= NFS_INO_INVALID_DATA;
+               spin_unlock(&inode->i_lock);
        }
        nfsi->cache_change_attribute = jiffies;
        atomic_dec(&nfsi->data_updates);
@@ -848,6 +856,12 @@ 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)
 {
@@ -971,10 +985,8 @@ 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 &&
@@ -1026,7 +1038,7 @@ 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;
 }
@@ -1068,7 +1080,7 @@ void nfs4_clear_inode(struct inode *inode)
 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;
@@ -1099,7 +1111,7 @@ static inline void nfs4_init_once(struct nfs_inode *nfsi)
 #endif
 }
 
-static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
+static void init_once(void * foo, struct kmem_cache * cachep, unsigned long flags)
 {
        struct nfs_inode *nfsi = (struct nfs_inode *) foo;
 
@@ -1110,6 +1122,8 @@ static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
                INIT_LIST_HEAD(&nfsi->dirty);
                INIT_LIST_HEAD(&nfsi->commit);
                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);
                atomic_set(&nfsi->data_updates, 0);
                nfsi->ndirty = 0;
@@ -1134,8 +1148,7 @@ static int __init 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);
 }
 
 /*
@@ -1145,6 +1158,10 @@ static int __init init_nfs_fs(void)
 {
        int err;
 
+       err = nfs_fs_proc_init();
+       if (err)
+               goto out5;
+
        err = nfs_init_nfspagecache();
        if (err)
                goto out4;
@@ -1185,6 +1202,8 @@ out2:
 out3:
        nfs_destroy_nfspagecache();
 out4:
+       nfs_fs_proc_exit();
+out5:
        return err;
 }
 
@@ -1199,6 +1218,7 @@ static void __exit exit_nfs_fs(void)
        rpc_proc_unregister("nfs");
 #endif
        unregister_nfs_fs();
+       nfs_fs_proc_exit();
 }
 
 /* Not quite true; I just maintain it */