Skip to content
Snippets Groups Projects
inode.c 58.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • Linus Torvalds's avatar
    Linus Torvalds committed
    	s = (struct super_block *)p;
    out_free:
    	if (server->mnt_path)
    		kfree(server->mnt_path);
    	if (server->hostname)
    		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);
    	rpciod_down();		/* release rpciod */
    
    	destroy_nfsv4_state(server);
    
    	if (server->hostname != NULL)
    		kfree(server->hostname);
    	kfree(server);
    }
    
    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,
    };
    
    #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)
    #define register_nfs4fs() register_filesystem(&nfs4_fs_type)
    #define unregister_nfs4fs() unregister_filesystem(&nfs4_fs_type)
    #else
    #define nfs4_init_once(nfsi) \
    	do { } while (0)
    #define register_nfs4fs() (0)
    #define unregister_nfs4fs()
    #endif
    
    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 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)