⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inode.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	/* 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)		invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;	/* Has the link count changed? */	if (inode->i_nlink != fattr->nlink)		invalid |= NFS_INO_INVALID_ATTR;	if (!timespec_equal(&inode->i_atime, &fattr->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;}/** * 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){	struct nfs_inode *nfsi = NFS_I(inode);	int status;	if ((fattr->valid & NFS_ATTR_FATTR) == 0)		return 0;	spin_lock(&inode->i_lock);	if (time_after(fattr->time_start, nfsi->last_updated))		status = nfs_update_inode(inode, fattr);	else		status = nfs_check_inode_attributes(inode, fattr);	spin_unlock(&inode->i_lock);	return status;}/** * 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){	struct nfs_inode *nfsi = NFS_I(inode);	spin_lock(&inode->i_lock);	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 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 = inode->i_size;		fattr->valid |= NFS_ATTR_WCC;	}	return nfs_post_op_update_inode(inode, fattr);}/* * 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){	struct nfs_server *server;	struct nfs_inode *nfsi = NFS_I(inode);	loff_t cur_isize, new_isize;	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,			atomic_read(&inode->i_count), fattr->valid);	if (nfsi->fileid != fattr->fileid)		goto out_fileid;	/*	 * Make sure the inode's type hasn't changed.	 */	if ((inode->i_mode & S_IFMT) != (fattr->mode & S_IFMT))		goto out_changed;	server = NFS_SERVER(inode);	/* Update the fsid? */	if (S_ISDIR(inode->i_mode)			&& !nfs_fsid_equal(&server->fsid, &fattr->fsid))		server->fsid = fattr->fsid;	/*	 * Update the read time so we don't revalidate too often.	 */	nfsi->read_cache_jiffies = fattr->time_start;	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;			nfsi->cache_change_attribute = now;		}		/* 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;		nfsi->cache_change_attribute = now;	}	/* 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, or has		 * the file grown beyond our last write? */		if (nfsi->npages == 0 || new_isize > cur_isize) {			inode->i_size = new_isize;			invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA;		}		dprintk("NFS: isize change on server for file %s/%ld\n",				inode->i_sb->s_id, inode->i_ino);	}	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 ||	    inode->i_gid != fattr->gid)		invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;	inode->i_mode = fattr->mode;	inode->i_nlink = fattr->nlink;	inode->i_uid = fattr->uid;	inode->i_gid = fattr->gid;	if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {		/*		 * report the blocks in 512byte units		 */		inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used); 	} else { 		inode->i_blocks = fattr->du.nfs2.blocks; 	}	/* 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 = 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 (!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.	 */	printk(KERN_DEBUG "%s: inode %ld mode changed, %07o to %07o\n",			__FUNCTION__, inode->i_ino, inode->i_mode, fattr->mode); out_err:	/*	 * 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;}#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_clear_inode(struct inode *inode){	/* If we are holding a delegation, return it! */	nfs_inode_return_delegation(inode);	/* First call standard NFS clear_inode() code */	nfs_clear_inode(inode);}#endifstruct inode *nfs_alloc_inode(struct super_block *sb){	struct nfs_inode *nfsi;	nfsi = (struct nfs_inode *)kmem_cache_alloc(nfs_inode_cachep, GFP_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 */	return &nfsi->vfs_inode;}void nfs_destroy_inode(struct inode *inode){	kmem_cache_free(nfs_inode_cachep, NFS_I(inode));}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;	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 __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);	if (nfs_inode_cachep == NULL)		return -ENOMEM;	return 0;}static void nfs_destroy_inodecache(void){	kmem_cache_destroy(nfs_inode_cachep);}/* * Initialize NFS */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;	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(&nfs_rpcstat);#endif	if ((err = register_nfs_fs()) != 0)		goto out;	return 0;out:#ifdef CONFIG_PROC_FS	rpc_proc_unregister("nfs");#endif	nfs_destroy_directcache();out0:	nfs_destroy_writepagecache();out1:	nfs_destroy_readpagecache();out2:	nfs_destroy_inodecache();out3:	nfs_destroy_nfspagecache();out4:	nfs_fs_proc_exit();out5:	return err;}static void __exit exit_nfs_fs(void){	nfs_destroy_directcache();	nfs_destroy_writepagecache();	nfs_destroy_readpagecache();	nfs_destroy_inodecache();	nfs_destroy_nfspagecache();#ifdef CONFIG_PROC_FS	rpc_proc_unregister("nfs");#endif	unregister_nfs_fs();	nfs_fs_proc_exit();}/* 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)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -