Skip to content
Snippets Groups Projects
inode.c 56.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • Linus Torvalds's avatar
    Linus Torvalds committed
    #endif
    
    static kmem_cache_t * nfs_inode_cachep;
    
    static 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);
    	if (!nfsi)
    		return NULL;
    
    	nfsi->flags = 0UL;
    	nfsi->cache_validity = 0UL;
    
    #ifdef CONFIG_NFS_V3_ACL
    	nfsi->acl_access = ERR_PTR(-EAGAIN);
    	nfsi->acl_default = ERR_PTR(-EAGAIN);
    #endif
    
    #ifdef CONFIG_NFS_V4
    	nfsi->nfs4_acl = NULL;
    #endif /* CONFIG_NFS_V4 */
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	return &nfsi->vfs_inode;
    }
    
    static 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)
    {
    	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);
    	}
    }
     
    
    static int nfs_init_inodecache(void)
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    {
    	nfs_inode_cachep = kmem_cache_create("nfs_inode_cache",
    					     sizeof(struct nfs_inode),
    					     0, SLAB_RECLAIM_ACCOUNT,
    					     init_once, NULL);
    	if (nfs_inode_cachep == NULL)
    		return -ENOMEM;
    
    	return 0;
    }
    
    
    static void nfs_destroy_inodecache(void)
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    {
    	if (kmem_cache_destroy(nfs_inode_cachep))
    		printk(KERN_INFO "nfs_inode_cache: not all structures were freed\n");
    }
    
    /*
     * Initialize NFS
     */
    static int __init init_nfs_fs(void)
    {
    	int err;
    
    	err = nfs_init_nfspagecache();
    	if (err)
    		goto out4;
    
    	err = nfs_init_inodecache();
    	if (err)
    		goto out3;
    
    	err = nfs_init_readpagecache();
    	if (err)
    		goto out2;
    
    	err = nfs_init_writepagecache();
    	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)
    		goto out;
    	return 0;
    out:
    #ifdef CONFIG_PROC_FS
    	rpc_proc_unregister("nfs");
    #endif
    	nfs_destroy_writepagecache();
    #ifdef CONFIG_NFS_DIRECTIO
    out0:
    	nfs_destroy_directcache();
    #endif
    out1:
    	nfs_destroy_readpagecache();
    out2:
    	nfs_destroy_inodecache();
    out3:
    	nfs_destroy_nfspagecache();
    out4:
    	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();
    	nfs_destroy_nfspagecache();
    #ifdef CONFIG_PROC_FS
    	rpc_proc_unregister("nfs");
    #endif
    	unregister_filesystem(&nfs_fs_type);
    	unregister_nfs4fs();
    }
    
    /* Not quite true; I just maintain it */
    MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
    MODULE_LICENSE("GPL");
    
    module_init(init_nfs_fs)
    module_exit(exit_nfs_fs)