nits
This commit is contained in:
parent
48aa917403
commit
11183588dc
34
log.c
34
log.c
|
@ -7,8 +7,8 @@
|
||||||
|
|
||||||
// Simple logging that allows concurrent FS system calls.
|
// Simple logging that allows concurrent FS system calls.
|
||||||
//
|
//
|
||||||
// A log transaction contains the updates of *multiple* FS system
|
// A log transaction contains the updates of multiple FS system
|
||||||
// calls. The logging systems only commits when there are
|
// calls. The logging system only commits when there are
|
||||||
// no FS system calls active. Thus there is never
|
// no FS system calls active. Thus there is never
|
||||||
// any reasoning required about whether a commit might
|
// any reasoning required about whether a commit might
|
||||||
// write an uncommitted system call's updates to disk.
|
// write an uncommitted system call's updates to disk.
|
||||||
|
@ -17,10 +17,7 @@
|
||||||
// its start and end. Usually begin_op() just increments
|
// its start and end. Usually begin_op() just increments
|
||||||
// the count of in-progress FS system calls and returns.
|
// the count of in-progress FS system calls and returns.
|
||||||
// But if it thinks the log is close to running out, it
|
// But if it thinks the log is close to running out, it
|
||||||
// blocks this system call, and causes the system to wait
|
// sleeps until the last outstanding end_op() commits.
|
||||||
// until end_op() indicates there are no executing FS
|
|
||||||
// system calls, at which point the last end_op() commits
|
|
||||||
// all the system calls' writes.
|
|
||||||
//
|
//
|
||||||
// The log is a physical re-do log containing disk blocks.
|
// The log is a physical re-do log containing disk blocks.
|
||||||
// The on-disk log format:
|
// The on-disk log format:
|
||||||
|
@ -52,10 +49,6 @@ struct log log;
|
||||||
static void recover_from_log(void);
|
static void recover_from_log(void);
|
||||||
static void commit();
|
static void commit();
|
||||||
|
|
||||||
// statistics, delete eventually XXX.
|
|
||||||
static int maxsize;
|
|
||||||
static int maxoutstanding;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
initlog(void)
|
initlog(void)
|
||||||
{
|
{
|
||||||
|
@ -127,7 +120,7 @@ recover_from_log(void)
|
||||||
write_head(); // clear the log
|
write_head(); // clear the log
|
||||||
}
|
}
|
||||||
|
|
||||||
// an FS system call should call begin_op() when it starts.
|
// called at the start of each FS system call.
|
||||||
void
|
void
|
||||||
begin_op(void)
|
begin_op(void)
|
||||||
{
|
{
|
||||||
|
@ -140,18 +133,14 @@ begin_op(void)
|
||||||
sleep(&log, &log.lock);
|
sleep(&log, &log.lock);
|
||||||
} else {
|
} else {
|
||||||
log.outstanding += 1;
|
log.outstanding += 1;
|
||||||
if(log.outstanding > maxoutstanding){
|
|
||||||
maxoutstanding = log.outstanding;
|
|
||||||
cprintf("%d outstanding\n", log.outstanding);
|
|
||||||
}
|
|
||||||
release(&log.lock);
|
release(&log.lock);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// an FS system call should call end_op() after it finishes.
|
// called at the end of each FS system call.
|
||||||
// can't write the disk &c while holding locks, thus do_commit.
|
// commits if this was the last outstanding operation.
|
||||||
void
|
void
|
||||||
end_op(void)
|
end_op(void)
|
||||||
{
|
{
|
||||||
|
@ -171,6 +160,8 @@ end_op(void)
|
||||||
release(&log.lock);
|
release(&log.lock);
|
||||||
|
|
||||||
if(do_commit){
|
if(do_commit){
|
||||||
|
// call commit w/o holding locks, since not allowed
|
||||||
|
// to sleep with locks.
|
||||||
commit();
|
commit();
|
||||||
acquire(&log.lock);
|
acquire(&log.lock);
|
||||||
log.committing = 0;
|
log.committing = 0;
|
||||||
|
@ -209,7 +200,7 @@ log_write(struct buf *b)
|
||||||
panic("write outside of trans");
|
panic("write outside of trans");
|
||||||
|
|
||||||
for (i = 0; i < log.lh.n; i++) {
|
for (i = 0; i < log.lh.n; i++) {
|
||||||
if (log.lh.sector[i] == b->sector) // log absorbtion?
|
if (log.lh.sector[i] == b->sector) // log absorbtion
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
log.lh.sector[i] = b->sector;
|
log.lh.sector[i] = b->sector;
|
||||||
|
@ -219,12 +210,7 @@ log_write(struct buf *b)
|
||||||
brelse(lbuf);
|
brelse(lbuf);
|
||||||
if (i == log.lh.n)
|
if (i == log.lh.n)
|
||||||
log.lh.n++;
|
log.lh.n++;
|
||||||
b->flags |= B_DIRTY; // XXX prevent eviction
|
b->flags |= B_DIRTY; // prevent eviction
|
||||||
|
|
||||||
if(log.lh.n > maxsize){
|
|
||||||
maxsize = log.lh.n;
|
|
||||||
cprintf("log size %d/%d\n", log.lh.n, LOGSIZE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//PAGEBREAK!
|
//PAGEBREAK!
|
||||||
|
|
Loading…
Reference in a new issue