Chinaunix

标题: VFS path_walk中cached_lookup()里的Bug? [打印本页]

作者: Benson_linux    时间: 2007-10-13 12:32
标题: VFS path_walk中cached_lookup()里的Bug?
最近在看2.4内核VFS部分的代码,看到path_walk里边通过cached_lookup在内存中查找dentry的时候,感觉cached_lookup里边有一个地方是不是一个Bug?

cached_lookup()的代码:

  1. static struct dentry * cached_lookup(struct dentry * parent, struct qstr * name, int flags)
  2. {
  3.         struct dentry * dentry = d_lookup(parent, name);

  4.         if (dentry && dentry->d_op && dentry->d_op->d_revalidate) {
  5.                 if (!dentry->d_op->d_revalidate(dentry, flags) && !d_invalidate(dentry)) {
  6.                         dput(dentry);
  7.                         dentry = NULL;
  8.                 }
  9.         }
  10.         return dentry;
  11. }
复制代码

在d_revalidate验证dentry不可用的情况下,需要d_invalidate来释放该dentry的时候,如果dentry忙,没有成功释放,那么还是会将这个不可用的dentry返回,这个地方会不会是一个Bug呢?

在看d_invalidate()函数的内容:


  1. …………

  2.         if (atomic_read(&dentry->d_count) > 1) {
  3.                 if (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode)) {
  4.                         spin_unlock(&dcache_lock);
  5.                         return -EBUSY;
  6.                 }
  7.         }

  8. …………

复制代码


虽然在计数器大于1,也就是有其地方在使用这个dentry时,但也要该dentry对应的inode有效,且描述的是一个目录时,才返回BUSY,此时cached_lookup就返回了一个文件系统认为不可用的dentry给path_walk。这究竟是一个Bug,还是在内核的其他地方有补充来避免这种现象?

小弟对内核VFS这部分了解的不够全面,希望大家帮忙。
作者: zx_wing    时间: 2007-10-14 14:10
原帖由 Benson_linux 于 2007-10-13 12:32 发表
最近在看2.4内核VFS部分的代码,看到path_walk里边通过cached_lookup在内存中查找dentry的时候,感觉cached_lookup里边有一个地方是不是一个Bug?

cached_lookup()的代码:

static struct dentry * cache ...

我对VFS不了解。但如果你在老版本的kernel里发现你认为是bug的地方,应该去搜索一下,或查看新的版本,因为它很可能就是个bug。
以前一个朋友也遇到过这种情况,发现是个bug,一搜,在新版本里已经fix掉了
作者: Benson_linux    时间: 2007-10-15 15:17
谢谢,我看一下kernel2.6里边的代码是在怎么写的
作者: Benson_linux    时间: 2007-10-15 15:22
刚看了kernel2.6的代码,这部分的代码虽然修改了,但是逻辑还是没有变,看来可能是某些地方有约束。

希望知道的能说说。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2