Skip to content

Commit

Permalink
fix iput() to more obviously avoid deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Morris committed Aug 8, 2017
1 parent 1c7aa96 commit a4ee6f7
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,20 +329,22 @@ iunlock(struct inode *ip)
void
iput(struct inode *ip)
{
acquire(&icache.lock);
if(ip->ref == 1){
acquiresleep(&ip->lock);
if(ip->valid && ip->nlink == 0){
acquiresleep(&ip->lock);
if(ip->valid && ip->nlink == 0){
acquire(&icache.lock);
int r = ip->ref;
release(&icache.lock);
if(r == 1){
// inode has no links and no other references: truncate and free.
release(&icache.lock);
itrunc(ip);
ip->type = 0;
iupdate(ip);
ip->valid = 0;
acquire(&icache.lock);
}
releasesleep(&ip->lock);
}
releasesleep(&ip->lock);

acquire(&icache.lock);
ip->ref--;
release(&icache.lock);
}
Expand Down

0 comments on commit a4ee6f7

Please sign in to comment.