From 50f9ba390ba5caed9632b00ded6d5800af82b1e5 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 28 Mar 2011 07:12:50 +1100 Subject: [PATCH] Assorted changes to scheduling and a few 'trace' changes. This seems to make checkpoint and flush both work properly. Signed-off-by: NeilBrown --- lib/internal.h | 2 +- lib/lafs_allocated_block.c | 1 + lib/lafs_checkpoint.c | 32 +++++++++++++++++++++----------- lib/lafs_cluster_allocate.c | 2 +- lib/lafs_inode_fillblock.c | 2 +- lib/lafs_sched_blk.c | 13 ++++++++++--- 6 files changed, 35 insertions(+), 17 deletions(-) diff --git a/lib/internal.h b/lib/internal.h index ae238fa..97d2cdf 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -20,7 +20,7 @@ de_sched(struct lafs_blk *b) if (b->parent) { struct lafs_iblk *p = b->parent; - trace(2,"ds %d/%lld %d\n", p->b.ino->inum, (long long)p->b.fileaddr, + trace(2,"desched %d/%lld %d/%lld %d\n", b->ino->inum, (long long)b->fileaddr, p->b.ino->inum, (long long)p->b.fileaddr, p->sched_cnt); p->sched_cnt--; if (p->sched_cnt == 0) diff --git a/lib/lafs_allocated_block.c b/lib/lafs_allocated_block.c index 2d358be..3ab2c42 100644 --- a/lib/lafs_allocated_block.c +++ b/lib/lafs_allocated_block.c @@ -39,6 +39,7 @@ void lafs_allocated_block(struct lafs_blk *b, loff_t addr) b->flags |= B_Uninc; b->chain = p->uninc; p->uninc = b; + lafs_sched_blk(&p->b); } } diff --git a/lib/lafs_checkpoint.c b/lib/lafs_checkpoint.c index 8633b2f..0e1a64a 100644 --- a/lib/lafs_checkpoint.c +++ b/lib/lafs_checkpoint.c @@ -20,14 +20,17 @@ int lafs_checkpoint(struct lafs *fs) b = list_first_entry(&fs->leafs, struct lafs_blk, leafs); - trace(1, "checkpoint %p %d/%lld %s %p\n", b, b->ino->inum, + trace(1, "checkpoint %p %d/%lld %s-%d %p\n", b, b->ino->inum, (long long)b->fileaddr, - (b->flags & B_Index) ? "index":"data", b->parent); + (b->flags & B_Index) ? "index":"data", + (b->flags & B_Index) ? iblk(b)->sched_cnt:0, + b->parent); list_del_init(&b->leafs); if (!(b->flags & B_Index)) { struct lafs_dblk *db = dblk(b); if (b->ino->type == TypeSegmentMap) { - /* Allow parents to be processed, but freeze this */ + /* Allow parents to be processed, + * but freeze this */ de_sched(b); b->flags |= B_Sched; list_add(&b->leafs, &fs->account_leafs); continue; @@ -35,26 +38,33 @@ int lafs_checkpoint(struct lafs *fs) if (b->ino->type == TypeInodeFile && db->my_inode && db->my_inode->iblock && - db->my_inode->iblock->sched_cnt) { - de_sched(b); + db->my_inode->iblock->sched_cnt) + /* Wait for InoIdx block to be ready */ continue; - } } if (b->flags & B_Index) { struct lafs_iblk *ib = iblk(b); - if (ib->sched_cnt) { - de_sched(b); + if (ib->sched_cnt) + /* Not ready yet, leave it off the list */ continue; - } + if (ib->uninc) { - de_sched(b); lafs_incorporate(ib); - if (!(ib->b.flags & B_Sched)) + if (list_empty(&ib->b.leafs)) abort(); /* We'll pick it up next time 'round */ continue; } + if (b->flags & B_InoIdx) { + /* InoIdx block is ready, so process + * the data block. + */ + de_sched(b); + b->flags &= ~B_Dirty; + b = &b->ino->dblock->b; + b->flags |= B_Dirty; + } } if (b->flags & B_Dirty) { trace(2, "...alloc\n"); diff --git a/lib/lafs_cluster_allocate.c b/lib/lafs_cluster_allocate.c index 3e5e627..1b3251e 100644 --- a/lib/lafs_cluster_allocate.c +++ b/lib/lafs_cluster_allocate.c @@ -44,5 +44,5 @@ void lafs_cluster_allocate(struct lafs_blk *b, int cnum) abort(); } wc->remaining--; - list_add_tail(&b->leafs, &wc->blocks); + list_move_tail(&b->leafs, &wc->blocks); } diff --git a/lib/lafs_inode_fillblock.c b/lib/lafs_inode_fillblock.c index ec1aabc..9887aa4 100644 --- a/lib/lafs_inode_fillblock.c +++ b/lib/lafs_inode_fillblock.c @@ -22,7 +22,7 @@ void lafs_inode_fillblock(struct lafs_ino *ino, char *buf) lino->filetype = ino->type; lino->flags = ino->flags; - trace(1, "FILL inode %d\n", ino->type); + trace(1, "FILL inode (type=%d)\n", ino->type); switch(ino->type) { case TypeInodeFile: { diff --git a/lib/lafs_sched_blk.c b/lib/lafs_sched_blk.c index 2a740f3..8f1f79a 100644 --- a/lib/lafs_sched_blk.c +++ b/lib/lafs_sched_blk.c @@ -14,8 +14,11 @@ int lafs_sched_blk(struct lafs_blk *blk) struct lafs *fs = blk->ino->fs; blk->flags |= B_Dirty; - if (blk->flags & B_Sched) + if (blk->flags & B_Sched) { + if (list_empty(&blk->leafs)) + list_add_tail(&blk->leafs, &fs->leafs); return 0; + } if (!(blk->flags & B_Index)) { struct lafs_dblk *dblk = container_of(blk, struct lafs_dblk, b); @@ -23,9 +26,13 @@ int lafs_sched_blk(struct lafs_blk *blk) return -1; } blk->flags |= B_Sched; - if (blk->parent) + if (blk->parent) { blk->parent->sched_cnt++; - trace(1, "schedule %p\n", blk); + trace(1, "schedule %d/%d %d/%d %d\n", blk->ino->inum, (int)blk->fileaddr, + blk->parent->b.ino->inum, (int)blk->parent->b.fileaddr, + blk->parent->sched_cnt); + } else + trace(1, "schedule %d/%d\n", blk->ino->inum, (int)blk->fileaddr); list_move_tail(&blk->leafs, &fs->leafs); return 0; } -- 2.39.5