Skip to content
Snippets Groups Projects
inode.c 48.3 KiB
Newer Older
  • Learn to ignore specific revisions
  • 	if (!(fattr->valid & NFS_ATTR_FATTR_SIZE))
    		return 0;
    
    	return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
    }
    
    static atomic_long_t nfs_attr_generation_counter;
    
    
    static unsigned long nfs_read_attr_generation_counter(void)
    {
    
    	return atomic_long_read(&nfs_attr_generation_counter);
    
    }
    
    unsigned long nfs_inc_attr_generation_counter(void)
    {
    
    	return atomic_long_inc_return(&nfs_attr_generation_counter);
    
    }
    
    void nfs_fattr_init(struct nfs_fattr *fattr)
    {
    	fattr->valid = 0;
    	fattr->time_start = jiffies;
    	fattr->gencount = nfs_inc_attr_generation_counter();
    
    	fattr->owner_name = NULL;
    	fattr->group_name = NULL;
    
    struct nfs_fattr *nfs_alloc_fattr(void)
    {
    	struct nfs_fattr *fattr;
    
    	fattr = kmalloc(sizeof(*fattr), GFP_NOFS);
    	if (fattr != NULL)
    		nfs_fattr_init(fattr);
    	return fattr;
    }
    
    struct nfs_fh *nfs_alloc_fhandle(void)
    {
    	struct nfs_fh *fh;
    
    	fh = kmalloc(sizeof(struct nfs_fh), GFP_NOFS);
    	if (fh != NULL)
    		fh->size = 0;
    	return fh;
    }
    
    
    /*
     * _nfs_display_fhandle_hash - calculate the crc32 hash for the filehandle
     *                             in the same way that wireshark does
     *
     * @fh: file handle
     *
     * For debugging only.
     */
    u32 _nfs_display_fhandle_hash(const struct nfs_fh *fh)
    {
    	/* wireshark uses 32-bit AUTODIN crc and does a bitwise
    	 * not on the result */
    	return ~crc32(0xFFFFFFFF, &fh->data[0], fh->size);
    }
    
    /*
    
     * _nfs_display_fhandle - display an NFS file handle on the console
     *
     * @fh: file handle to display
     * @caption: display caption
     *
     * For debugging only.
     */
    void _nfs_display_fhandle(const struct nfs_fh *fh, const char *caption)
    {
    	unsigned short i;
    
    
    	if (fh == NULL || fh->size == 0) {
    
    		printk(KERN_DEFAULT "%s at %p is empty\n", caption, fh);
    		return;
    	}
    
    
    	printk(KERN_DEFAULT "%s at %p is %u bytes, crc: 0x%08x:\n",
    	       caption, fh, fh->size, _nfs_display_fhandle_hash(fh));
    
    	for (i = 0; i < fh->size; i += 16) {
    		__be32 *pos = (__be32 *)&fh->data[i];
    
    		switch ((fh->size - i - 1) >> 2) {
    		case 0:
    			printk(KERN_DEFAULT " %08x\n",
    				be32_to_cpup(pos));
    			break;
    		case 1:
    			printk(KERN_DEFAULT " %08x %08x\n",
    				be32_to_cpup(pos), be32_to_cpup(pos + 1));
    			break;
    		case 2:
    			printk(KERN_DEFAULT " %08x %08x %08x\n",
    				be32_to_cpup(pos), be32_to_cpup(pos + 1),
    				be32_to_cpup(pos + 2));
    			break;
    		default:
    			printk(KERN_DEFAULT " %08x %08x %08x %08x\n",
    				be32_to_cpup(pos), be32_to_cpup(pos + 1),
    				be32_to_cpup(pos + 2), be32_to_cpup(pos + 3));
    		}
    	}
    }
    #endif
    
    
    /**
     * nfs_inode_attrs_need_update - check if the inode attributes need updating
     * @inode - pointer to inode
     * @fattr - attributes
     *
     * Attempt to divine whether or not an RPC call reply carrying stale
     * attributes got scheduled after another call carrying updated ones.
     *
     * To do so, the function first assumes that a more recent ctime means
     * that the attributes in fattr are newer, however it also attempt to
     * catch the case where ctime either didn't change, or went backwards
     * (if someone reset the clock on the server) by looking at whether
     * or not this RPC call was started after the inode was last updated.
    
     * Note also the check for wraparound of 'attr_gencount'
    
     *
     * The function returns 'true' if it thinks the attributes in 'fattr' are
     * more recent than the ones cached in the inode.
     *
     */
    static int nfs_inode_attrs_need_update(const struct inode *inode, const struct nfs_fattr *fattr)
    {
    	const struct nfs_inode *nfsi = NFS_I(inode);
    
    
    	return ((long)fattr->gencount - (long)nfsi->attr_gencount) > 0 ||
    
    		nfs_ctime_need_update(inode, fattr) ||
    		nfs_size_need_update(inode, fattr) ||
    
    		((long)nfsi->attr_gencount - (long)nfs_read_attr_generation_counter() > 0);
    
    }
    
    static int nfs_refresh_inode_locked(struct inode *inode, struct nfs_fattr *fattr)
    {
    	if (nfs_inode_attrs_need_update(inode, fattr))
    
    		return nfs_update_inode(inode, fattr);
    	return nfs_check_inode_attributes(inode, fattr);
    }
    
    
    /**
     * nfs_refresh_inode - try to update the inode attribute cache
     * @inode - pointer to inode
     * @fattr - updated attributes
     *
     * Check that an RPC call that returned attributes has not overlapped with
     * other recent updates of the inode metadata, then decide whether it is
     * safe to do a full update of the inode attributes, or whether just to
     * call nfs_check_inode_attributes.
     */
    int nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
    {
    	int status;
    
    	if ((fattr->valid & NFS_ATTR_FATTR) == 0)
    		return 0;
    	spin_lock(&inode->i_lock);
    
    	status = nfs_refresh_inode_locked(inode, fattr);
    
    	spin_unlock(&inode->i_lock);
    
    static int nfs_post_op_update_inode_locked(struct inode *inode, struct nfs_fattr *fattr)
    {
    	struct nfs_inode *nfsi = NFS_I(inode);
    
    	nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
    	if (S_ISDIR(inode->i_mode))
    		nfsi->cache_validity |= NFS_INO_INVALID_DATA;
    	if ((fattr->valid & NFS_ATTR_FATTR) == 0)
    		return 0;
    	return nfs_refresh_inode_locked(inode, fattr);
    }
    
    
    /**
     * nfs_post_op_update_inode - 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.
    
     *
     * 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)
    {
    
    	status = nfs_post_op_update_inode_locked(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)
    {
    
    	int status;
    
    	spin_lock(&inode->i_lock);
    	/* Don't do a WCC update if these attributes are already stale */
    	if ((fattr->valid & NFS_ATTR_FATTR) == 0 ||
    			!nfs_inode_attrs_need_update(inode, fattr)) {
    
    		fattr->valid &= ~(NFS_ATTR_FATTR_PRECHANGE
    				| NFS_ATTR_FATTR_PRESIZE
    				| NFS_ATTR_FATTR_PREMTIME
    				| NFS_ATTR_FATTR_PRECTIME);
    
    	if ((fattr->valid & NFS_ATTR_FATTR_CHANGE) != 0 &&
    			(fattr->valid & NFS_ATTR_FATTR_PRECHANGE) == 0) {
    
    		fattr->pre_change_attr = inode->i_version;
    
    		fattr->valid |= NFS_ATTR_FATTR_PRECHANGE;
    
    	if ((fattr->valid & NFS_ATTR_FATTR_CTIME) != 0 &&
    			(fattr->valid & NFS_ATTR_FATTR_PRECTIME) == 0) {
    
    		memcpy(&fattr->pre_ctime, &inode->i_ctime, sizeof(fattr->pre_ctime));
    
    		fattr->valid |= NFS_ATTR_FATTR_PRECTIME;
    	}
    	if ((fattr->valid & NFS_ATTR_FATTR_MTIME) != 0 &&
    			(fattr->valid & NFS_ATTR_FATTR_PREMTIME) == 0) {
    
    		memcpy(&fattr->pre_mtime, &inode->i_mtime, sizeof(fattr->pre_mtime));
    
    		fattr->valid |= NFS_ATTR_FATTR_PREMTIME;
    	}
    	if ((fattr->valid & NFS_ATTR_FATTR_SIZE) != 0 &&
    			(fattr->valid & NFS_ATTR_FATTR_PRESIZE) == 0) {
    
    		fattr->pre_size = i_size_read(inode);
    
    		fattr->valid |= NFS_ATTR_FATTR_PRESIZE;
    
    out_noforce:
    	status = nfs_post_op_update_inode_locked(inode, fattr);
    	spin_unlock(&inode->i_lock);
    	return status;
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    /*
     * Many nfs protocol calls return the new file attributes after
     * an operation.  Here we update the inode to reflect the state
     * of the server's inode.
     *
     * This is a bit tricky because we have to make sure all dirty pages
     * have been sent off to the server before calling invalidate_inode_pages.
     * To make sure no other process adds more write requests while we try
     * our best to flush them, we make them sleep during the attribute refresh.
     *
     * A very similar scenario holds for the dir cache.
     */
    
    static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    {
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	struct nfs_inode *nfsi = NFS_I(inode);
    
    	loff_t cur_isize, new_isize;
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    
    
    	dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
    
    			__func__, inode->i_sb->s_id, inode->i_ino,
    
    			nfs_display_fhandle_hash(NFS_FH(inode)),
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    			atomic_read(&inode->i_count), fattr->valid);
    
    
    	if ((fattr->valid & NFS_ATTR_FATTR_FILEID) && nfsi->fileid != fattr->fileid)
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    
    	/*
    	 * Make sure the inode's type hasn't changed.
    	 */
    
    	if ((fattr->valid & NFS_ATTR_FATTR_TYPE) && (inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT))
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    		goto out_changed;
    
    
    	/* Update the fsid? */
    
    	if (S_ISDIR(inode->i_mode) && (fattr->valid & NFS_ATTR_FATTR_FSID) &&
    
    			!nfs_fsid_equal(&server->fsid, &fattr->fsid) &&
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	/*
    	 * Update the read time so we don't revalidate too often.
    	 */
    
    	nfsi->read_cache_jiffies = fattr->time_start;
    
    	save_cache_validity = nfsi->cache_validity;
    	nfsi->cache_validity &= ~(NFS_INO_INVALID_ATTR
    			| NFS_INO_INVALID_ATIME
    			| NFS_INO_REVAL_FORCED
    			| NFS_INO_REVAL_PAGECACHE);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    
    
    	/* Do atomic weak cache consistency updates */
    
    	invalid |= nfs_wcc_update_inode(inode, fattr);
    
    	if (fattr->valid & NFS_ATTR_FATTR_CHANGE) {
    
    		if (inode->i_version != 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
    				| NFS_INO_REVAL_PAGECACHE;
    
    			if (S_ISDIR(inode->i_mode))
    				nfs_force_lookup_revalidate(inode);
    
    			inode->i_version = fattr->change_attr;
    
    	} else if (server->caps & NFS_CAP_CHANGE_ATTR)
    		invalid |= save_cache_validity;
    
    
    	if (fattr->valid & NFS_ATTR_FATTR_MTIME) {
    
    		/* 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);
    
    			memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime));
    
    	} else if (server->caps & NFS_CAP_MTIME)
    		invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
    				| NFS_INO_INVALID_DATA
    				| NFS_INO_REVAL_PAGECACHE
    				| NFS_INO_REVAL_FORCED);
    
    
    	if (fattr->valid & NFS_ATTR_FATTR_CTIME) {
    
    		/* If ctime has changed we should definitely clear access+acl caches */
    
    		if (!timespec_equal(&inode->i_ctime, &fattr->ctime)) {
    
    			invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
    
    			/* and probably clear data for a directory too as utimes can cause
    			 * havoc with our cache.
    			 */
    			if (S_ISDIR(inode->i_mode)) {
    				invalid |= NFS_INO_INVALID_DATA;
    				nfs_force_lookup_revalidate(inode);
    			}
    
    			memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime));
    
    	} else if (server->caps & NFS_CAP_CTIME)
    		invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
    				| NFS_INO_INVALID_ACCESS
    				| NFS_INO_INVALID_ACL
    				| NFS_INO_REVAL_FORCED);
    
    	/* Check if our cached file size is stale */
    
    	if (fattr->valid & NFS_ATTR_FATTR_SIZE) {
    		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, or has
    			 * the file grown beyond our last write? */
    
    			if ((nfsi->npages == 0 && !test_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) ||
    			     new_isize > cur_isize) {
    
    				i_size_write(inode, new_isize);
    				invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;
    			}
    
    			dprintk("NFS: isize change on server for file %s/%ld "
    					"(%Ld to %Ld)\n",
    					inode->i_sb->s_id,
    					inode->i_ino,
    					(long long)cur_isize,
    					(long long)new_isize);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    		}
    
    	} else
    		invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
    				| NFS_INO_REVAL_PAGECACHE
    				| NFS_INO_REVAL_FORCED);
    
    	if (fattr->valid & NFS_ATTR_FATTR_ATIME)
    		memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
    
    	else if (server->caps & NFS_CAP_ATIME)
    		invalid |= save_cache_validity & (NFS_INO_INVALID_ATIME
    				| NFS_INO_REVAL_FORCED);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    
    
    	if (fattr->valid & NFS_ATTR_FATTR_MODE) {
    		if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)) {
    
    			umode_t newmode = inode->i_mode & S_IFMT;
    			newmode |= fattr->mode & S_IALLUGO;
    			inode->i_mode = newmode;
    
    			invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
    		}
    
    	} else if (server->caps & NFS_CAP_MODE)
    		invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
    				| NFS_INO_INVALID_ACCESS
    				| NFS_INO_INVALID_ACL
    				| NFS_INO_REVAL_FORCED);
    
    
    	if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
    		if (inode->i_uid != fattr->uid) {
    			invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
    			inode->i_uid = fattr->uid;
    		}
    
    	} else if (server->caps & NFS_CAP_OWNER)
    		invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
    				| NFS_INO_INVALID_ACCESS
    				| NFS_INO_INVALID_ACL
    				| NFS_INO_REVAL_FORCED);
    
    
    	if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
    		if (inode->i_gid != fattr->gid) {
    			invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
    			inode->i_gid = fattr->gid;
    		}
    
    	} else if (server->caps & NFS_CAP_OWNER_GROUP)
    		invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
    				| NFS_INO_INVALID_ACCESS
    				| NFS_INO_INVALID_ACL
    				| NFS_INO_REVAL_FORCED);
    
    	if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
    		if (inode->i_nlink != fattr->nlink) {
    			invalid |= NFS_INO_INVALID_ATTR;
    			if (S_ISDIR(inode->i_mode))
    				invalid |= NFS_INO_INVALID_DATA;
    
    			set_nlink(inode, fattr->nlink);
    
    	} else if (server->caps & NFS_CAP_NLINK)
    		invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
    				| NFS_INO_REVAL_FORCED);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    
    
    	if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) {
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    		/*
    		 * report the blocks in 512byte units
    		 */
    		inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
     	}
    
    	if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
    		inode->i_blocks = fattr->du.nfs2.blocks;
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    
    	/* Update attrtimeo value if we're out of the unstable period */
    	if (invalid & NFS_INO_INVALID_ATTR) {
    
    		nfs_inc_stats(inode, NFSIOS_ATTRINVALIDATE);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    		nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
    
    		nfsi->attrtimeo_timestamp = now;
    
    		nfsi->attr_gencount = nfs_inc_attr_generation_counter();
    
    		if (!time_in_range_open(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;
    		}
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	}
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	/* 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 (!nfs_have_delegation(inode, FMODE_READ) ||
    
    			(save_cache_validity & NFS_INO_REVAL_FORCED))
    
    		nfsi->cache_validity |= invalid;
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    
    	return 0;
     out_changed:
    	/*
    	 * Big trouble! The inode has become a different object.
    	 */
    
    	printk(KERN_DEBUG "NFS: %s: inode %ld mode changed, %07o to %07o\n",
    
    			__func__, inode->i_ino, inode->i_mode, fattr->mode);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	/*
    	 * No need to worry about unhashing the dentry, as the
    	 * lookup validation will know that the inode is bad.
    	 * (But we fall through to invalidate the caches.)
    	 */
    	nfs_invalidate_inode(inode);
    	return -ESTALE;
    
    
     out_fileid:
    	printk(KERN_ERR "NFS: server %s error: fileid changed\n"
    		"fsid %s: expected fileid 0x%Lx, got 0x%Lx\n",
    
    		NFS_SERVER(inode)->nfs_client->cl_hostname, inode->i_sb->s_id,
    
    		(long long)nfsi->fileid, (long long)fattr->fileid);
    	goto out_err;
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    #ifdef CONFIG_NFS_V4
    
    /*
     * 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().
     */
    
    void nfs4_evict_inode(struct inode *inode)
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    {
    
    	truncate_inode_pages(&inode->i_data, 0);
    	end_writeback(inode);
    
    Benny Halevy's avatar
    Benny Halevy committed
    	pnfs_return_layout(inode);
    	pnfs_destroy_layout(NFS_I(inode));
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	/* If we are holding a delegation, return it! */
    
    	nfs_inode_return_delegation_noreclaim(inode);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	/* First call standard NFS clear_inode() code */
    	nfs_clear_inode(inode);
    }
    #endif
    
    
    David Howells's avatar
    David Howells committed
    struct inode *nfs_alloc_inode(struct super_block *sb)
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    {
    	struct nfs_inode *nfsi;
    
    	nfsi = (struct nfs_inode *)kmem_cache_alloc(nfs_inode_cachep, GFP_KERNEL);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	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_i_callback(struct rcu_head *head)
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    {
    
    	struct inode *inode = container_of(head, struct inode, i_rcu);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	kmem_cache_free(nfs_inode_cachep, NFS_I(inode));
    }
    
    
    void nfs_destroy_inode(struct inode *inode)
    {
    	call_rcu(&inode->i_rcu, nfs_i_callback);
    }
    
    
    Andrew Morton's avatar
    Andrew Morton committed
    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);
    
    	nfsi->layout = NULL;
    
    	atomic_set(&nfsi->commit_info.rpcs_out, 0);
    
    Andrew Morton's avatar
    Andrew Morton committed
    #endif
    }
    
    static void init_once(void *foo)
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    {
    	struct nfs_inode *nfsi = (struct nfs_inode *) foo;
    
    
    	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_LIST_HEAD(&nfsi->commit_info.list);
    
    	nfsi->npages = 0;
    
    	nfsi->commit_info.ncommit = 0;
    
    	atomic_set(&nfsi->silly_count, 1);
    	INIT_HLIST_HEAD(&nfsi->silly_list);
    	init_waitqueue_head(&nfsi->waitqueue);
    
    	nfs4_init_once(nfsi);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    }
    
    David Howells's avatar
    David Howells committed
    static int __init 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|
    						SLAB_MEM_SPREAD),
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	if (nfs_inode_cachep == NULL)
    		return -ENOMEM;
    
    	return 0;
    }
    
    
    static void nfs_destroy_inodecache(void)
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    {
    
    	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 = alloc_workqueue("nfsiod", WQ_MEM_RECLAIM, 0);
    
    	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);
    }
    
    
    	nfs_clients_init(net);
    
    	return nfs_dns_resolver_cache_init(net);
    }
    
    static void nfs_net_exit(struct net *net)
    {
    	nfs_dns_resolver_cache_destroy(net);
    
    	nfs_cleanup_cb_ident_idr(net);
    
    }
    
    static struct pernet_operations nfs_net_ops = {
    	.init = nfs_net_init,
    	.exit = nfs_net_exit,
    	.id   = &nfs_net_id,
    	.size = sizeof(struct nfs_net),
    };
    
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    /*
     * Initialize NFS
     */
    static int __init init_nfs_fs(void)
    {
    	int err;
    
    
    Bryan Schumaker's avatar
    Bryan Schumaker committed
    	err = nfs_idmap_init();
    	if (err < 0)
    
    	if (err < 0)
    		goto out9;
    
    	err = register_pernet_subsys(&nfs_net_ops);
    
    	err = nfs_fscache_register();
    	if (err < 0)
    		goto out7;
    
    
    	err = nfsiod_start();
    	if (err)
    		goto out6;
    
    
    	err = nfs_fs_proc_init();
    	if (err)
    		goto out5;
    
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	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;
    
    	err = nfs_init_directcache();
    	if (err)
    		goto out0;
    
    #ifdef CONFIG_PROC_FS
    
    	rpc_proc_register(&init_net, &nfs_rpcstat);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    #endif
    
    David Howells's avatar
    David Howells committed
    	if ((err = register_nfs_fs()) != 0)
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    		goto out;
    	return 0;
    out:
    #ifdef CONFIG_PROC_FS
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    #endif
    	nfs_destroy_directcache();
    
    out0:
    	nfs_destroy_writepagecache();
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    out1:
    	nfs_destroy_readpagecache();
    out2:
    	nfs_destroy_inodecache();
    out3:
    	nfs_destroy_nfspagecache();
    out4:
    
    	nfs_fs_proc_exit();
    out5:
    
    	nfsiod_stop();
    out6:
    
    	unregister_pernet_subsys(&nfs_net_ops);
    
    Bryan Schumaker's avatar
    Bryan Schumaker committed
    out9:
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    	return err;
    }
    
    static void __exit exit_nfs_fs(void)
    {
    	nfs_destroy_directcache();
    	nfs_destroy_writepagecache();
    	nfs_destroy_readpagecache();
    	nfs_destroy_inodecache();
    	nfs_destroy_nfspagecache();
    
    	unregister_pernet_subsys(&nfs_net_ops);
    
    Bryan Schumaker's avatar
    Bryan Schumaker committed
    	nfs_idmap_quit();
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    #ifdef CONFIG_PROC_FS
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    #endif
    
    David Howells's avatar
    David Howells committed
    	unregister_nfs_fs();
    
    	nfs_fs_proc_exit();
    
    	nfsiod_stop();
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    }
    
    /* Not quite true; I just maintain it */
    MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
    MODULE_LICENSE("GPL");
    
    module_param(enable_ino64, bool, 0644);
    
    Linus Torvalds's avatar
    Linus Torvalds committed
    
    module_init(init_nfs_fs)
    module_exit(exit_nfs_fs)