Acquire inode ref before checking if inode is valid

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