Acquire inode ref before checking if inode is valid

上级 b2e88e79
...@@ -189,6 +189,7 @@ ialloc(u32 dev, short type) ...@@ -189,6 +189,7 @@ ialloc(u32 dev, short type)
// maybe this inode is free. look at it via the // maybe this inode is free. look at it via the
// inode cache to make sure. // inode cache to make sure.
struct inode *ip = iget(dev, inum); struct inode *ip = iget(dev, inum);
assert(ip->valid());
ilock(ip, 1); ilock(ip, 1);
if(ip->type == 0){ if(ip->type == 0){
ip->type = type; ip->type = type;
...@@ -263,15 +264,15 @@ iget(u32 dev, u32 inum) ...@@ -263,15 +264,15 @@ iget(u32 dev, u32 inum)
scoped_gc_epoch e; scoped_gc_epoch e;
struct inode *ip = ins->lookup(make_pair(dev, inum)); struct inode *ip = ins->lookup(make_pair(dev, inum));
if (ip) { if (ip) {
if (!(ip->flags & I_VALID)) { if (ip->tryinc()) {
acquire(&ip->lock); if (!(ip->flags & I_VALID)) {
while((ip->flags & I_VALID) == 0) acquire(&ip->lock);
cv_sleep(&ip->cv, &ip->lock); while((ip->flags & I_VALID) == 0)
release(&ip->lock); cv_sleep(&ip->cv, &ip->lock);
} release(&ip->lock);
}
if (ip->tryinc())
return ip; return ip;
}
} }
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论