clarify some FS comments

This commit is contained in:
Robert Morris 2011-10-11 06:41:37 -04:00
parent d73dd097a5
commit a5fbfe418a
6 changed files with 69 additions and 46 deletions

22
log.c
View file

@ -42,7 +42,7 @@ struct log {
struct spinlock lock;
int start;
int size;
int intrans;
int busy; // a transaction is active
int dev;
struct logheader lh;
};
@ -75,7 +75,7 @@ install_trans(void)
struct buf *lbuf = bread(log.dev, log.start+tail+1); // read log block
struct buf *dbuf = bread(log.dev, log.lh.sector[tail]); // read dst
memmove(dbuf->data, lbuf->data, BSIZE); // copy block to dst
bwrite(dbuf); // flush dst to disk
bwrite(dbuf); // write dst to disk
brelse(lbuf);
brelse(dbuf);
}
@ -95,7 +95,9 @@ read_head(void)
brelse(buf);
}
// Write in-memory log header to disk, committing log entries till head
// Write in-memory log header to disk.
// This is the true point at which the
// current transaction commits.
static void
write_head(void)
{
@ -123,10 +125,10 @@ void
begin_trans(void)
{
acquire(&log.lock);
while (log.intrans) {
while (log.busy) {
sleep(&log, &log.lock);
}
log.intrans = 1;
log.busy = 1;
release(&log.lock);
}
@ -134,14 +136,14 @@ void
commit_trans(void)
{
if (log.lh.n > 0) {
write_head(); // Causes all blocks till log.head to be commited
install_trans(); // Install all the transactions till head
write_head(); // Write header to disk -- the real commit
install_trans(); // Now install writes to home locations
log.lh.n = 0;
write_head(); // Reclaim log
write_head(); // Erase the transaction from the log
}
acquire(&log.lock);
log.intrans = 0;
log.busy = 0;
wakeup(&log);
release(&log.lock);
}
@ -161,7 +163,7 @@ log_write(struct buf *b)
if (log.lh.n >= LOGSIZE || log.lh.n >= log.size - 1)
panic("too big a transaction");
if (!log.intrans)
if (!log.busy)
panic("write outside of trans");
for (i = 0; i < log.lh.n; i++) {