Replace I_BUSY with sleep locks
This commit is contained in:
parent
2adb7c21dc
commit
dec637bc59
|
@ -7,6 +7,7 @@
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "traps.h"
|
#include "traps.h"
|
||||||
#include "spinlock.h"
|
#include "spinlock.h"
|
||||||
|
#include "sleeplock.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "memlayout.h"
|
#include "memlayout.h"
|
||||||
|
|
3
file.c
3
file.c
|
@ -6,8 +6,9 @@
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
#include "param.h"
|
#include "param.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "file.h"
|
|
||||||
#include "spinlock.h"
|
#include "spinlock.h"
|
||||||
|
#include "sleeplock.h"
|
||||||
|
#include "file.h"
|
||||||
|
|
||||||
struct devsw devsw[NDEV];
|
struct devsw devsw[NDEV];
|
||||||
struct {
|
struct {
|
||||||
|
|
4
file.h
4
file.h
|
@ -14,7 +14,8 @@ struct inode {
|
||||||
uint dev; // Device number
|
uint dev; // Device number
|
||||||
uint inum; // Inode number
|
uint inum; // Inode number
|
||||||
int ref; // Reference count
|
int ref; // Reference count
|
||||||
int flags; // I_BUSY, I_VALID
|
struct sleeplock lock;
|
||||||
|
int flags; // I_VALID
|
||||||
|
|
||||||
short type; // copy of disk inode
|
short type; // copy of disk inode
|
||||||
short major;
|
short major;
|
||||||
|
@ -23,7 +24,6 @@ struct inode {
|
||||||
uint size;
|
uint size;
|
||||||
uint addrs[NDIRECT+1];
|
uint addrs[NDIRECT+1];
|
||||||
};
|
};
|
||||||
#define I_BUSY 0x1
|
|
||||||
#define I_VALID 0x2
|
#define I_VALID 0x2
|
||||||
|
|
||||||
// table mapping major device number to
|
// table mapping major device number to
|
||||||
|
|
27
fs.c
27
fs.c
|
@ -135,9 +135,7 @@ bfree(int dev, uint b)
|
||||||
//
|
//
|
||||||
// * Locked: file system code may only examine and modify
|
// * Locked: file system code may only examine and modify
|
||||||
// the information in an inode and its content if it
|
// the information in an inode and its content if it
|
||||||
// has first locked the inode. The I_BUSY flag indicates
|
// has first locked the inode.
|
||||||
// that the inode is locked. ilock() sets I_BUSY,
|
|
||||||
// while iunlock clears it.
|
|
||||||
//
|
//
|
||||||
// Thus a typical sequence is:
|
// Thus a typical sequence is:
|
||||||
// ip = iget(dev, inum)
|
// ip = iget(dev, inum)
|
||||||
|
@ -165,7 +163,13 @@ struct {
|
||||||
void
|
void
|
||||||
iinit(int dev)
|
iinit(int dev)
|
||||||
{
|
{
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
initlock(&icache.lock, "icache");
|
initlock(&icache.lock, "icache");
|
||||||
|
for(i = 0; i < NINODE; i++) {
|
||||||
|
initsleeplock(&icache.inode[i].lock, "inode");
|
||||||
|
}
|
||||||
|
|
||||||
readsb(dev, &sb);
|
readsb(dev, &sb);
|
||||||
cprintf("sb: size %d nblocks %d ninodes %d nlog %d logstart %d\
|
cprintf("sb: size %d nblocks %d ninodes %d nlog %d logstart %d\
|
||||||
inodestart %d bmap start %d\n", sb.size, sb.nblocks,
|
inodestart %d bmap start %d\n", sb.size, sb.nblocks,
|
||||||
|
@ -277,11 +281,7 @@ ilock(struct inode *ip)
|
||||||
if(ip == 0 || ip->ref < 1)
|
if(ip == 0 || ip->ref < 1)
|
||||||
panic("ilock");
|
panic("ilock");
|
||||||
|
|
||||||
acquire(&icache.lock);
|
acquiresleep(&ip->lock);
|
||||||
while(ip->flags & I_BUSY)
|
|
||||||
sleep(ip, &icache.lock);
|
|
||||||
ip->flags |= I_BUSY;
|
|
||||||
release(&icache.lock);
|
|
||||||
|
|
||||||
if(!(ip->flags & I_VALID)){
|
if(!(ip->flags & I_VALID)){
|
||||||
bp = bread(ip->dev, IBLOCK(ip->inum, sb));
|
bp = bread(ip->dev, IBLOCK(ip->inum, sb));
|
||||||
|
@ -303,13 +303,10 @@ ilock(struct inode *ip)
|
||||||
void
|
void
|
||||||
iunlock(struct inode *ip)
|
iunlock(struct inode *ip)
|
||||||
{
|
{
|
||||||
if(ip == 0 || !(ip->flags & I_BUSY) || ip->ref < 1)
|
if(ip == 0 || !holdingsleep(&ip->lock) || ip->ref < 1)
|
||||||
panic("iunlock");
|
panic("iunlock");
|
||||||
|
|
||||||
acquire(&icache.lock);
|
releasesleep(&ip->lock);
|
||||||
ip->flags &= ~I_BUSY;
|
|
||||||
wakeup(ip);
|
|
||||||
release(&icache.lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drop a reference to an in-memory inode.
|
// Drop a reference to an in-memory inode.
|
||||||
|
@ -325,16 +322,12 @@ iput(struct inode *ip)
|
||||||
acquire(&icache.lock);
|
acquire(&icache.lock);
|
||||||
if(ip->ref == 1 && (ip->flags & I_VALID) && ip->nlink == 0){
|
if(ip->ref == 1 && (ip->flags & I_VALID) && ip->nlink == 0){
|
||||||
// inode has no links and no other references: truncate and free.
|
// inode has no links and no other references: truncate and free.
|
||||||
if(ip->flags & I_BUSY)
|
|
||||||
panic("iput busy");
|
|
||||||
ip->flags |= I_BUSY;
|
|
||||||
release(&icache.lock);
|
release(&icache.lock);
|
||||||
itrunc(ip);
|
itrunc(ip);
|
||||||
ip->type = 0;
|
ip->type = 0;
|
||||||
iupdate(ip);
|
iupdate(ip);
|
||||||
acquire(&icache.lock);
|
acquire(&icache.lock);
|
||||||
ip->flags = 0;
|
ip->flags = 0;
|
||||||
wakeup(ip);
|
|
||||||
}
|
}
|
||||||
ip->ref--;
|
ip->ref--;
|
||||||
release(&icache.lock);
|
release(&icache.lock);
|
||||||
|
|
3
pipe.c
3
pipe.c
|
@ -4,8 +4,9 @@
|
||||||
#include "mmu.h"
|
#include "mmu.h"
|
||||||
#include "proc.h"
|
#include "proc.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
#include "file.h"
|
|
||||||
#include "spinlock.h"
|
#include "spinlock.h"
|
||||||
|
#include "sleeplock.h"
|
||||||
|
#include "file.h"
|
||||||
|
|
||||||
#define PIPESIZE 512
|
#define PIPESIZE 512
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include "mmu.h"
|
#include "mmu.h"
|
||||||
#include "proc.h"
|
#include "proc.h"
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
|
#include "spinlock.h"
|
||||||
|
#include "sleeplock.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "fcntl.h"
|
#include "fcntl.h"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue