]> git.neil.brown.name Git - LaFS.git/commitdiff
combine two loops in lafs_cluster_allocate
authorNeilBrown <neilb@suse.de>
Tue, 29 Jun 2010 11:34:24 +0000 (21:34 +1000)
committerNeilBrown <neilb@suse.de>
Fri, 2 Jul 2010 23:31:19 +0000 (09:31 +1000)
There are two loops which try to cluster_flush to get enough space.
One calls new_segment, the other assumes cluster_flush will do
that, which it might or might not.

Combine these into a single loop, and move the handling of
error from new_segment closer to the call.

Signed-off-by: NeilBrown <neilb@suse.de>
cluster.c

index b0fc84c9b2bf1d7af8d7e63ae3f6bd46522e9d22..abfdb516db5d9c29205a9079bb18b041ac45b931 100644 (file)
--- a/cluster.c
+++ b/cluster.c
@@ -743,28 +743,9 @@ int lafs_cluster_allocate(struct block *b, int cnum)
        if (test_and_set_bit(B_Writeback, &b->flags))
                LAFS_BUG(1, b);
        lafs_iounlock_block(b);
-       /* insert into list ensuring there is enough space
-        * in cluster head
-        */
+
        getref(b, MKREF(cluster)); /* we soon own a reference in the list */
 
-       while (!err && wc->remaining < 2) {
-               // printk("Call flush - remaining = %d\n", wc->remaining);
-               if (wc->slhead.b == NULL)
-                       err = new_segment(fs, cnum);
-               else
-                       cluster_flush(fs, cnum);
-       }
-       if (err) {
-               /* No cleaner segments - this will have to go
-                * out with a checkpoint.
-                * Block is still 'dirty' - just clear writeback flag.
-                */
-               lafs_writeback_done(b);
-               putref(b, MKREF(cluster));
-               mutex_unlock(&wc->lock);
-               return -ENOSPC;
-       }
        do {
                int avail;
                /* see how much room is in cluster.
@@ -788,7 +769,21 @@ int lafs_cluster_allocate(struct block *b, int cnum)
                if (used < 0) {
                        /* won't fit */
                        // printk("Wont fit - used = %d\n", used);
-                       cluster_flush(fs, cnum);
+                       if (wc->slhead.b == NULL) {
+                               err = new_segment(fs, cnum);
+                               if (err) {
+                                       /* No cleaner segments - this will have to go
+                                        * out with a checkpoint.
+                                        * Block is still 'dirty' - just clear 
+                                        * writeback flag.
+                                        */
+                                       lafs_writeback_done(b);
+                                       putref(b, MKREF(cluster));
+                                       mutex_unlock(&wc->lock);
+                                       return -ENOSPC;
+                               }
+                       } else
+                               cluster_flush(fs, cnum);
                } else
                        lafs_io_wake(b);
        } while (used < 0);