NFS系统read调用过程(二)

本文深入探讨了NFS文件系统中read操作的详细流程。当缓存页数据无效时,通过nfs_readpages()函数更新,该函数涉及缓存页结构、nfs_pageio_descriptor以及发起READ请求的过程。在六步操作中,包括初始化数据结构、检查缓存有效性、向服务器发起读请求等关键步骤,揭示了NFS在处理读取操作时的内部机制。
摘要由CSDN通过智能技术生成

        上一篇文章中我们讲解了NFS文件系统中读操作的主要流程。如果缓存页中的数据有效,直接将缓存页中的数据拷贝到用户态缓冲区中。如果缓存页中的数据无效,则需要调用nfs_readpages()更新缓存页中的数据。nfs_readpages()完整定义如下:

// 这是NFS文件系统的readpages()函数
// pages是一个缓存页链表,nr_pages是链表中缓存页的数量
// 需要将链表中的缓存页添加到radix树中,然后从服务器中请求数据填充这些缓存页.
int nfs_readpages(struct file *filp, struct address_space *mapping,
		struct list_head *pages, unsigned nr_pages)
{
	struct nfs_pageio_descriptor pgio;
	struct nfs_readdesc desc = {
		.pgio = &pgio,
	};
	struct inode *inode = mapping->host;
	unsigned long npages;
	int ret = -ESTALE;

	dprintk("NFS: nfs_readpages (%s/%Ld %d)\n",
			inode->i_sb->s_id,
			(long long)NFS_FILEID(inode),
			nr_pages);
	nfs_inc_stats(inode, NFSIOS_VFSREADPAGES);

	if (NFS_STALE(inode))
		goto out;

	// 步骤1  获取用户信息,发起READ请求时需要使用用户信息.
	if (filp == NULL) {
		desc.ctx = nfs_find_open_context(inode, NULL, FMODE_READ);
		if (desc.ctx == NULL)
			return -EBADF;
	} else
		desc.ctx = get_nfs_open_context(nfs_file_open_context(filp));

	/* attempt to read as many of the pages as possible from the cache
	 * - this returns -ENOBUFS immediately if the cookie is negative
	 */
	// 步骤2   检查FS-Cache中的数据是否有效,如果有效就用FS-Cache中的数据填充缓存页,
	// 不用向服务器发起READ请求了。
	ret = nfs_readpages_from_fscache(desc.ctx, inode, mapping,
					 pages, &nr_pages);
	if (ret == 0)	// FS-Cache中的数据有效.
		goto read_complete; /* all pages were read */

	// 现在只能向服务器请求数据了
	
	// 步骤3   初始化pgio
	NFS_PROTO(inode)->read_pageio_init(&pgio, inode, &nfs_async_read_completion_ops);

	// 步骤4   创建读请求
        // 将链表中的缓存页添加到radix树中
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值