From: NeilBrown Date: Sat, 15 Aug 2009 07:09:24 +0000 (+1000) Subject: Improve credit handling when flushing a data block into the inode. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=ca74c5ed81f3336a0e8ee393fd2c561e573e540d;p=LaFS.git Improve credit handling when flushing a data block into the inode. Both the credit and icredit need to be moved from the data block to the inode data block (if needed) --- diff --git a/cluster.c b/cluster.c index bc80310..73bc360 100644 --- a/cluster.c +++ b/cluster.c @@ -444,6 +444,7 @@ static int flush_data_to_inode(struct block *b) return 0; } if (test_and_clear_bit(B_Dirty, &b->flags)) { + int credits = 1; /* Check size again, just in case it changed */ size = i_size_read(b->inode); if (size + lai->metadata_size > sb->s_blocksize) { @@ -453,8 +454,13 @@ static int flush_data_to_inode(struct block *b) lafs_space_return(fs, 1); return 0; } - if (test_and_set_bit(B_Credit, &lai->iblock->b.flags)) - lafs_space_return(fs, 1); + if (!test_and_set_bit(B_Credit, &lai->dblock->b.flags)) + credits--; + if (test_and_clear_bit(B_UnincCredit, &b->flags)) + credits++; + if (!test_and_set_bit(B_ICredit, &lai->dblock->b.flags)) + credits--; + lafs_space_return(fs, credits); lafs_dirty_dblock(lai->dblock); } else if (test_and_clear_bit(B_Realloc, &b->flags)) { int credits = 1; @@ -483,9 +489,8 @@ static int flush_data_to_inode(struct block *b) else clear_bit(B_WritePhase1, &b->flags); - if (!test_and_clear_bit(B_UnincCredit, &b->flags)) - BUG(); - lafs_space_return(fs, 1); + if (test_and_clear_bit(B_UnincCredit, &b->flags)) + lafs_space_return(fs, 1); /* It is an awkward time to call lafs_inode_fillblock, * so do this one little change manually @@ -598,7 +603,7 @@ unsigned long long lafs_cluster_allocate(struct block *b, int cnum) if (test_and_clear_bit(B_UnincCredit, &b->flags)) credits++; - /* hold two credits to be added to data block */ + /* hold credits to be added to data block */ b2 = &lai->dblock->b; /* We always erase the InoIdx block before the