免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3401 | 回复: 1

向看懂do_generic_file_read()的高手求解 [复制链接]

论坛徽章:
0
发表于 2012-03-08 19:04 |显示全部楼层
linux-2.6.27.7函数do_generic_file_read()有一段代码:
  1. find_page:
  2.                 page = find_get_page(mapping, index);
  3.                 if (!page) {
  4.                         page_cache_sync_readahead(mapping,
  5.                                         ra, filp,
  6.                                         index, last_index - index);
  7.                         page = find_get_page(mapping, index);
  8.                         if (unlikely(page == NULL))
  9.                                 goto no_cached_page;
  10.                 }
  11.                 if (PageReadahead(page)) {
  12.                         page_cache_async_readahead(mapping,
  13.                                         ra, filp, page,
  14.                                         index, last_index - index);
  15.                 }
  16. [color=Red]               
  17.                 if (!PageUptodate(page)) {
  18.                         if (inode->i_blkbits == PAGE_CACHE_SHIFT ||
  19.                                         !mapping->a_ops->is_partially_uptodate)
  20.                                 goto page_not_up_to_date;
  21.                         if (!trylock_page(page))
  22.                                 goto page_not_up_to_date;
  23.                         if (!mapping->a_ops->is_partially_uptodate(page,
  24.                                                                 desc, offset))
  25.                                 goto page_not_up_to_date_locked;
  26.                         unlock_page(page);
  27.                 }[/color]
  28. page_ok:
  29.                 /*
  30.                  * i_size must be checked after we know the page is Uptodate.
  31.                  *
  32.                  * Checking i_size after the check allows us to calculate
  33.                  * the correct value for "nr", which means the zero-filled
  34.                  * part of the page is not copied back to userspace (unless
  35.                  * another truncate extends the file - this is desired though).
  36.                  */

  37.                 isize = i_size_read(inode);
  38.                 end_index = (isize - 1) >> PAGE_CACHE_SHIFT;
  39.                 if (unlikely(!isize || index > end_index)) {
  40.                         page_cache_release(page);
  41.                         goto out;
  42.                 }
复制代码
page_ok标签处表示page的状态是PG_uptodate的,假如mapping->a_ops->is_partially_uptodate!=NULL(ext文件系统),page_ok上面的一段代码并不能保证page的状态是PG_uptodate的,难道到了page_ok标签处page的状态可以不是PG_uptodate?

论坛徽章:
0
发表于 2012-03-09 07:59 |显示全部楼层
不好意思,看掉
  1. if (!mapping->a_ops->is_partially_uptodate(page,
  2.                                                                 desc, offset))
复制代码
是个函数调用了,如果进入
  1. if (!PageUptodate(page)) {
  2.                         if (inode->i_blkbits == PAGE_CACHE_SHIFT ||
  3.                                         !mapping->a_ops->is_partially_uptodate)
  4.                                 goto page_not_up_to_date;
  5.                         if (!trylock_page(page))
  6.                                 goto page_not_up_to_date;
  7.                         if (!mapping->a_ops->is_partially_uptodate(page,
  8.                                                                 desc, offset))
  9.                                 goto page_not_up_to_date_locked;
  10.                         unlock_page(page);
  11.                 }
复制代码
没有跳转,正常出来以后page的状态肯定是PG_uptodate的.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP