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 <neilb@suse.de>
*/
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)
)
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;
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);