Skip to content

Commit 1c7aa96

Browse files
author
Robert Morris
committed
a little more lock documentation
1 parent 70d912b commit 1c7aa96

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

fs.c

+13
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ bfree(int dev, uint b)
154154
// Many internal file system functions expect the caller to
155155
// have locked the inodes involved; this lets callers create
156156
// multi-step atomic operations.
157+
//
158+
// The icache.lock spin-lock defends ip->ref, ip->dev, and ip->inum.
159+
// Since ip->ref indicates whether an icache entry is free, the
160+
// icache.lock defends icache allocation. icache.lock also defends
161+
// all fields of an unallocated icache entry, during allocation.
162+
//
163+
// An ip->lock sleep-lock defends all ip-> fields other than ref,
164+
// dev, and inum. One must hold ip->lock in order to
165+
// read or write that inode's ip->valid, ip->size, ip->type, &c.
157166

158167
struct {
159168
struct spinlock lock;
@@ -205,6 +214,7 @@ ialloc(uint dev, short type)
205214
}
206215

207216
// Copy a modified in-memory inode to disk.
217+
// Caller must hold ip->lock.
208218
void
209219
iupdate(struct inode *ip)
210220
{
@@ -421,6 +431,7 @@ itrunc(struct inode *ip)
421431
}
422432

423433
// Copy stat information from inode.
434+
// Caller must hold ip->lock.
424435
void
425436
stati(struct inode *ip, struct stat *st)
426437
{
@@ -433,6 +444,7 @@ stati(struct inode *ip, struct stat *st)
433444

434445
//PAGEBREAK!
435446
// Read data from inode.
447+
// Caller must hold ip->lock.
436448
int
437449
readi(struct inode *ip, char *dst, uint off, uint n)
438450
{
@@ -461,6 +473,7 @@ readi(struct inode *ip, char *dst, uint off, uint n)
461473

462474
// PAGEBREAK!
463475
// Write data to inode.
476+
// Caller must hold ip->lock.
464477
int
465478
writei(struct inode *ip, char *src, uint off, uint n)
466479
{

0 commit comments

Comments
 (0)