]> git.neil.brown.name Git - LaFS.git/commitdiff
Fix lafs_cluster_allocate to full cluster.
authorNeilBrown <neilb@suse.de>
Thu, 1 Jul 2010 06:58:54 +0000 (16:58 +1000)
committerNeilBrown <neilb@suse.de>
Fri, 2 Jul 2010 23:31:19 +0000 (09:31 +1000)
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>
cluster.c

index 330738a5d67387662d045021e97e5c3048f99531..e3dbc6446f4206f92976e157ee1f6b1125e40796 100644 (file)
--- 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);