提交 a4ee6f7d 创建 作者: Robert Morris's avatar Robert Morris

fix iput() to more obviously avoid deadlock

上级 1c7aa960
...@@ -329,20 +329,22 @@ iunlock(struct inode *ip) ...@@ -329,20 +329,22 @@ iunlock(struct inode *ip)
void void
iput(struct inode *ip) iput(struct inode *ip)
{ {
acquire(&icache.lock); acquiresleep(&ip->lock);
if(ip->ref == 1){ if(ip->valid && ip->nlink == 0){
acquiresleep(&ip->lock); acquire(&icache.lock);
if(ip->valid && ip->nlink == 0){ int r = ip->ref;
release(&icache.lock);
if(r == 1){
// inode has no links and no other references: truncate and free. // inode has no links and no other references: truncate and free.
release(&icache.lock);
itrunc(ip); itrunc(ip);
ip->type = 0; ip->type = 0;
iupdate(ip); iupdate(ip);
ip->valid = 0; ip->valid = 0;
acquire(&icache.lock);
} }
releasesleep(&ip->lock);
} }
releasesleep(&ip->lock);
acquire(&icache.lock);
ip->ref--; ip->ref--;
release(&icache.lock); release(&icache.lock);
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论