From 6de9b0989d211e6983184ba085ee0f6c9d585fa5 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 21 Jun 2010 11:32:12 +1000 Subject: [PATCH] Change lafs_phase_flip to take an indexblock As lafs_phase_flip is only ever passed an indexblock, make that explicit in the signature, and remove any tests for B_Index and they will always be True. Signed-off-by: NeilBrown --- checkpoint.c | 2 +- index.c | 154 +++++++++++++++++++++++---------------------------- lafs.h | 2 +- 3 files changed, 72 insertions(+), 86 deletions(-) diff --git a/checkpoint.c b/checkpoint.c index 06c236e..30007ee 100644 --- a/checkpoint.c +++ b/checkpoint.c @@ -396,7 +396,7 @@ static void do_checkpoint(void *data) } else if (test_bit(B_Index, &b->flags)) { if (atomic_read(&iblk(b)->pincnt[oldphase]) == 0) { - lafs_phase_flip(fs, b); + lafs_phase_flip(fs, iblk(b)); unlock = 0; } } else { diff --git a/index.c b/index.c index f8e50a3..fc3d0c1 100644 --- a/index.c +++ b/index.c @@ -412,38 +412,37 @@ void lafs_pin_block_ph(struct block *b, int ph) lafs_refile(b, 0); } -static void pin_all_children(struct block *b) +static void pin_all_children(struct indexblock *ib) { struct indexblock *p; int depth = 0; - struct fs *fs = fs_from_inode(b->inode); + struct fs *fs = fs_from_inode(ib->b.inode); int ph = fs->phase; recurse: - p = iblk(b); - b = list_entry(&p->children, struct block, siblings); + p = ib; + ib = list_entry(&p->children, struct indexblock, b.siblings); loop: - list_for_each_entry_continue(b, &p->children, siblings) { - if (test_bit(B_Index, &b->flags)) { + list_for_each_entry_continue(ib, &p->children, b.siblings) { + if (test_bit(B_Index, &ib->b.flags)) { /* recurse down */ depth++; goto recurse; } else { - set_phase(b, ph); - lafs_refile(b, 0); + set_phase(&ib->b, ph); + lafs_refile(&ib->b, 0); } } if (depth) { depth--; - b = &p->b; - p = b->parent; + ib = p; + p = ib->b.parent; goto loop; } } - -void lafs_phase_flip(struct fs *fs, struct block *b) +void lafs_phase_flip(struct fs *fs, struct indexblock *ib) { /* We are performing a checkpoint, this block has been written * out and now needs to be flipped into the next phase. @@ -458,99 +457,86 @@ void lafs_phase_flip(struct fs *fs, struct block *b) * For InoIdx, we transfer the pinning and Credits to the * Data block rather than release them. */ - struct indexblock *ib = iblk(b); struct indexblock *p = NULL; - int oldphase = !!test_bit(B_Phase1, &b->flags); + int oldphase = !!test_bit(B_Phase1, &ib->b.flags); struct block *ulist; - dprintk("FLIP %s\n", strblk(b)); + dprintk("FLIP %s\n", strblk(&ib->b)); - LAFS_BUG(!test_bit(B_Pinned, &b->flags), b); - LAFS_BUG(!test_bit(B_Index, &b->flags), b); - LAFS_BUG(b->parent == NULL && !test_bit(B_Root, &b->flags), b); - LAFS_BUG(ib->uninc_table.pending_cnt, b); - LAFS_BUG(atomic_read(&ib->pincnt[oldphase]), b); - LAFS_BUG(!test_bit(B_IOLock, &b->flags), b); + LAFS_BUG(!test_bit(B_Pinned, &ib->b.flags), &ib->b); + LAFS_BUG(!test_bit(B_Index, &ib->b.flags), &ib->b); + LAFS_BUG(ib->b.parent == NULL && !test_bit(B_Root, &ib->b.flags), &ib->b); + LAFS_BUG(ib->uninc_table.pending_cnt, &ib->b); + LAFS_BUG(atomic_read(&ib->pincnt[oldphase]), &ib->b); + LAFS_BUG(!test_bit(B_IOLock, &ib->b.flags), &ib->b); /* If this is the only reference, and pincnts are zero * and all relevant flags are clear, then don't flip * phase but unpin. */ - if (test_bit(B_Pinned, &b->flags) && - !test_bit(B_PinPending, &b->flags) && - !test_bit(B_Dirty, &b->flags) && - !test_bit(B_Realloc, &b->flags) && - atomic_read(&b->refcnt) == 1 && /* This is us */ - (!test_bit(B_Index, &b->flags) || - (iblk(b)->uninc_table.pending_cnt == 0 && - iblk(b)->uninc == NULL && - iblk(b)->uninc_next == NULL && - atomic_read(&iblk(b)->pincnt[0]) == 0 && - atomic_read(&iblk(b)->pincnt[1]) == 0)) && - (!test_bit(B_InoIdx, &b->flags) || - !(test_bit(B_PinPending, &LAFSI(b->inode)->dblock->b.flags) - || test_bit(B_Dirty, &LAFSI(b->inode)->dblock->b.flags) - || test_bit(B_Realloc, &LAFSI(b->inode)->dblock->b.flags))) + if (test_bit(B_Pinned, &ib->b.flags) && + !test_bit(B_PinPending, &ib->b.flags) && + !test_bit(B_Dirty, &ib->b.flags) && + !test_bit(B_Realloc, &ib->b.flags) && + atomic_read(&ib->b.refcnt) == 1 && /* This is us */ + + ib->uninc_table.pending_cnt == 0 && + ib->uninc == NULL && + ib->uninc_next == NULL && + atomic_read(&ib->pincnt[0]) == 0 && + atomic_read(&ib->pincnt[1]) == 0 && + + (!test_bit(B_InoIdx, &ib->b.flags) || + !(test_bit(B_PinPending, &LAFSI(ib->b.inode)->dblock->b.flags) + || test_bit(B_Dirty, &LAFSI(ib->b.inode)->dblock->b.flags) + || test_bit(B_Realloc, &LAFSI(ib->b.inode)->dblock->b.flags))) ) { - if (!test_bit(B_Index, &b->flags) && - LAFSI(b->inode)->type == TypeInodeFile && - test_and_clear_bit(I_Dirty, &LAFSI(dblk(b)->my_inode)->iflags)) { - /* Need to keep pinned in new phase and make new - * changes. - */ - atomic_inc(&b->parent->pincnt[1-oldphase]); - atomic_dec(&b->parent->pincnt[oldphase]); - if (oldphase) - clear_bit(B_Phase1, &b->flags); - else - set_bit(B_Phase1, &b->flags); - lafs_dirty_inode(b->inode); - } else if (test_and_clear_bit(B_Pinned, &b->flags)) { - if (!test_bit(B_Root, &b->flags)) { - atomic_dec(&b->parent->pincnt[oldphase]); - lafs_refile(&b->parent->b, 0); + if (test_and_clear_bit(B_Pinned, &ib->b.flags)) { + if (!test_bit(B_Root, &ib->b.flags)) { + atomic_dec(&ib->b.parent->pincnt[oldphase]); + lafs_refile(&ib->b.parent->b, 0); } - lafs_inode_checkpin(b->inode); + lafs_inode_checkpin(ib->b.inode); } - lafs_iounlock_block(b); + lafs_iounlock_block(&ib->b); return; } - if (!test_bit(B_InoIdx, &b->flags)) { - struct inode *ino = b->inode; + if (!test_bit(B_InoIdx, &ib->b.flags)) { + struct inode *ino = ib->b.inode; spin_lock(&ino->i_data.private_lock); if (oldphase) - clear_bit(B_Phase1, &b->flags); + clear_bit(B_Phase1, &ib->b.flags); else - set_bit(B_Phase1, &b->flags); + set_bit(B_Phase1, &ib->b.flags); - p = b->parent; + p = ib->b.parent; atomic_inc(&p->pincnt[1-oldphase]); atomic_dec(&p->pincnt[oldphase]); /* move 'next' credits to 'here' */ - if (!test_bit(B_Credit, &b->flags) && - test_and_clear_bit(B_NCredit, &b->flags)) - set_bit(B_Credit, &b->flags); + if (!test_bit(B_Credit, &ib->b.flags) && + test_and_clear_bit(B_NCredit, &ib->b.flags)) + set_bit(B_Credit, &ib->b.flags); - if (!test_bit(B_ICredit, &b->flags) && - test_and_clear_bit(B_NICredit, &b->flags)) - set_bit(B_ICredit, &b->flags); + if (!test_bit(B_ICredit, &ib->b.flags) && + test_and_clear_bit(B_NICredit, &ib->b.flags)) + set_bit(B_ICredit, &ib->b.flags); spin_unlock(&ino->i_data.private_lock); - if (lafs_prealloc(b, ReleaseSpace) < 0) { + if (lafs_prealloc(&ib->b, ReleaseSpace) < 0) { /* Couldn't get all N*Credit, so * Pin all children to this phase, so they * won't be needed. */ - pin_all_children(b); + pin_all_children(ib); } } else { - struct lafs_inode *lai = LAFSI(b->inode); + struct lafs_inode *lai = LAFSI(ib->b.inode); struct datablock *db = lai->dblock; struct inode *ino = db->b.inode; @@ -560,7 +546,7 @@ void lafs_phase_flip(struct fs *fs, struct block *b) lai->pblocks = 0; lai->ciblocks += lai->piblocks; lai->piblocks = 0; - if (lai->filesys == b->inode) { + if (lai->filesys == ib->b.inode) { /* Root of filesystem */ lai->md.fs.cblocks_used += lai->md.fs.pblocks_used; @@ -568,30 +554,30 @@ void lafs_phase_flip(struct fs *fs, struct block *b) } if (oldphase) - clear_bit(B_Phase1, &b->flags); + clear_bit(B_Phase1, &ib->b.flags); else - set_bit(B_Phase1, &b->flags); + set_bit(B_Phase1, &ib->b.flags); - p = b->parent; + p = ib->b.parent; if (p) { atomic_inc(&p->pincnt[1-oldphase]); atomic_dec(&p->pincnt[oldphase]); } else - LAFS_BUG(!test_bit(B_Root, &b->flags), b); + LAFS_BUG(!test_bit(B_Root, &ib->b.flags), &ib->b); /* move 'next' credits to 'here' */ - if (!test_bit(B_Credit, &b->flags) && - test_and_clear_bit(B_NCredit, &b->flags)) - set_bit(B_Credit, &b->flags); + if (!test_bit(B_Credit, &ib->b.flags) && + test_and_clear_bit(B_NCredit, &ib->b.flags)) + set_bit(B_Credit, &ib->b.flags); - if (!test_bit(B_ICredit, &b->flags) && - test_and_clear_bit(B_NICredit, &b->flags)) - set_bit(B_ICredit, &b->flags); + if (!test_bit(B_ICredit, &ib->b.flags) && + test_and_clear_bit(B_NICredit, &ib->b.flags)) + set_bit(B_ICredit, &ib->b.flags); spin_unlock(&ino->i_data.private_lock); - if (lafs_prealloc(b, ReleaseSpace) < 0) - pin_all_children(b); + if (lafs_prealloc(&ib->b, ReleaseSpace) < 0) + pin_all_children(ib); // FIXME move Dirty/UnincCredit to data block } @@ -600,7 +586,7 @@ void lafs_phase_flip(struct fs *fs, struct block *b) ulist = ib->uninc_next; ib->uninc_next = NULL; - lafs_iounlock_block(b); + lafs_iounlock_block(&ib->b); if (ulist) lafs_dirty_iblock(ib); @@ -617,7 +603,7 @@ void lafs_phase_flip(struct fs *fs, struct block *b) } LAFS_BUG(ib->uninc_next, &ib->b); - lafs_refile(b, 0); + lafs_refile(&ib->b, 0); if (p) /* Parent may need to be attached to a phase_leafs now */ lafs_refile(&p->b, 0); diff --git a/lafs.h b/lafs.h index 39faeeb..91c6531 100644 --- a/lafs.h +++ b/lafs.h @@ -642,7 +642,7 @@ static inline void lafs_pin_block(struct block *b) lafs_pin_block_ph(b, fs_from_inode(b->inode)->phase); } int lafs_add_block_address(struct fs *fs, struct block *blk); -void lafs_phase_flip(struct fs *fs, struct block *b); +void lafs_phase_flip(struct fs *fs, struct indexblock *ib); struct indexblock * __must_check lafs_make_iblock(struct inode *ino, int adopt, int async, REFARG); struct indexblock * -- 2.39.5