summaryrefslogtreecommitdiff
path: root/fs.c
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2017-08-08 13:48:48 -0400
committerRobert Morris <[email protected]>2017-08-08 13:48:48 -0400
commit70d912b332328cb30cd86fdf63074cf10ba5ed35 (patch)
tree938191851b452357e63e3eff80d6946cd75a8cf2 /fs.c
parent3375df5061cefd188fefbc55cf57b066d7ed5da5 (diff)
downloadxv6-labs-70d912b332328cb30cd86fdf63074cf10ba5ed35.tar.gz
xv6-labs-70d912b332328cb30cd86fdf63074cf10ba5ed35.tar.bz2
xv6-labs-70d912b332328cb30cd86fdf63074cf10ba5ed35.zip
protect ip->valid and ip->nlink with sleep lock in iput()
Diffstat (limited to 'fs.c')
-rw-r--r--fs.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/fs.c b/fs.c
index b67db5d..c73c530 100644
--- a/fs.c
+++ b/fs.c
@@ -320,15 +320,17 @@ void
iput(struct inode *ip)
{
acquire(&icache.lock);
- if(ip->ref == 1 && ip->valid && ip->nlink == 0){
- // inode has no links and no other references: truncate and free.
+ if(ip->ref == 1){
acquiresleep(&ip->lock);
- release(&icache.lock);
- itrunc(ip);
- ip->type = 0;
- iupdate(ip);
- acquire(&icache.lock);
- ip->valid = 0;
+ if(ip->valid && ip->nlink == 0){
+ // 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);
}
ip->ref--;