From c227e42f80190e2e05b9c2fe641411d547b7bedd Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sat, 26 Jun 2010 09:25:18 +1000 Subject: [PATCH] Tidy up and re-factor lafs_phase_flip There is some common code that can be extracted. That code doesn't need any locking that I can find. Once that is moved out, the rest can be made a lot neater too. Signed-off-by: NeilBrown --- index.c | 104 ++++++++++++++++++++++---------------------------------- 1 file changed, 40 insertions(+), 64 deletions(-) diff --git a/index.c b/index.c index 1244ce6..2870d67 100644 --- a/index.c +++ b/index.c @@ -451,6 +451,34 @@ loop: } } +static void flip_phase(struct block *b) +{ + struct indexblock *p; + int oldphase = !!test_bit(B_Phase1, &b->flags); + + if (oldphase) + clear_bit(B_Phase1, &b->flags); + else + set_bit(B_Phase1, &b->flags); + + p = 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); + + /* 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_ICredit, &b->flags) && + test_and_clear_bit(B_NICredit, &b->flags)) + set_bit(B_ICredit, &b->flags); +} + void lafs_phase_flip(struct fs *fs, struct indexblock *ib) { /* We are performing a checkpoint, this block has been written @@ -466,7 +494,6 @@ void lafs_phase_flip(struct fs *fs, struct indexblock *ib) * For InoIdx, we transfer the pinning and Credits to the * Data block rather than release them. */ - struct indexblock *p = NULL; int oldphase = !!test_bit(B_Phase1, &ib->b.flags); struct block *ulist; @@ -514,46 +541,14 @@ void lafs_phase_flip(struct fs *fs, struct indexblock *ib) return; } - 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, &ib->b.flags); - else - set_bit(B_Phase1, &ib->b.flags); - - 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, &ib->b.flags) && - test_and_clear_bit(B_NCredit, &ib->b.flags)) - set_bit(B_Credit, &ib->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); + flip_phase(&ib->b); - 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(ib); - } - - } else { + if (test_bit(B_InoIdx, &ib->b.flags)) { struct lafs_inode *lai = LAFSI(ib->b.inode); struct datablock *db = lai->dblock; struct inode *ino = db->b.inode; spin_lock(&ino->i_data.private_lock); - lai->cblocks += lai->pblocks; lai->pblocks = 0; lai->ciblocks += lai->piblocks; @@ -564,37 +559,18 @@ void lafs_phase_flip(struct fs *fs, struct indexblock *ib) lai->md.fs.pblocks_used; lai->md.fs.pblocks_used = 0; } - - if (oldphase) - clear_bit(B_Phase1, &ib->b.flags); - else - set_bit(B_Phase1, &ib->b.flags); - - p = ib->b.parent; - if (p) { - atomic_inc(&p->pincnt[1-oldphase]); - atomic_dec(&p->pincnt[oldphase]); - } else - LAFS_BUG(!test_bit(B_Root, &ib->b.flags), &ib->b); - - /* move 'next' credits to 'here' */ - 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, &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(&ib->b, ReleaseSpace) < 0) - pin_all_children(ib); - /* maybe data block needs to be on leaf list */ - lafs_refile(&LAFSI(ib->b.inode)->dblock->b, 0); + lafs_refile(&db->b, 0); + } - // FIXME move Dirty/UnincCredit to data block + 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(ib); } spin_lock(&ib->b.inode->i_data.private_lock); @@ -620,9 +596,9 @@ void lafs_phase_flip(struct fs *fs, struct indexblock *ib) LAFS_BUG(ib->uninc_next, &ib->b); lafs_refile(&ib->b, 0); - if (p) + if (ib->b.parent) /* Parent may need to be attached to a phase_leafs now */ - lafs_refile(&p->b, 0); + lafs_refile(&ib->b.parent->b, 0); } /* -- 2.39.5