From: NeilBrown Date: Thu, 1 Jul 2010 06:58:54 +0000 (+1000) Subject: Fix lafs_cluster_allocate to full cluster. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=abb2bbbde356f784c745632cbb41d51acfcaf5bd;p=LaFS.git Fix lafs_cluster_allocate to full cluster. When we unified the two loops in lafs_cluster_allocate, we broke handling for a nearly-full cluster. We need to require wc->remaining is at least 1 before we even consider a cluster_insert. Signed-off-by: NeilBrown --- diff --git a/cluster.c b/cluster.c index 330738a..e3dbc64 100644 --- a/cluster.c +++ b/cluster.c @@ -762,7 +762,7 @@ int lafs_cluster_allocate(struct block *b, int cnum) */ if (wc->cluster_space >= (sizeof(struct group_head) + sizeof(struct descriptor)) || - (wc->remaining > 1 && + (wc->remaining > 2 && wc->chead_blocks < MAX_CHEAD_BLOCKS && (wc->chead_blocks+1) * sb->s_blocksize <= PAGE_SIZE) ) @@ -771,7 +771,10 @@ int lafs_cluster_allocate(struct block *b, int cnum) avail = 1; else avail = 0; - used = cluster_insert(&wc->slhead, &wc->clhead, b, avail); + if (wc->remaining < 1) + used = -1; + else + used = cluster_insert(&wc->slhead, &wc->clhead, b, avail); if (used >= 0) break; @@ -804,6 +807,7 @@ int lafs_cluster_allocate(struct block *b, int cnum) wc->cluster_space += sb->s_blocksize; } wc->remaining--; + BUG_ON(wc->remaining < 0); if (wc->remaining == 0) cluster_flush(fs, cnum); mutex_unlock(&wc->lock);