]> git.neil.brown.name Git - LaFS.git/commitdiff
Rearrange code in lafs_cluster_allocate.
authorNeilBrown <neilb@suse.de>
Tue, 29 Jun 2010 11:24:27 +0000 (21:24 +1000)
committerNeilBrown <neilb@suse.de>
Tue, 29 Jun 2010 11:24:27 +0000 (21:24 +1000)
There are two loops in lafs_cluster_allocate that I want
to combine into one.
Need to get some stuff out of the way first.

EmptyIndex handling can move up to the other special-case
handling - just change writeback_done to iounlock_block.

Converting the iolock to writeback and getting a cluster reference
can also move up easily.

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

index 0dcce8fd6178cf687c39d7c6db203af3c4065152..b0fc84c9b2bf1d7af8d7e63ae3f6bd46522e9d22 100644 (file)
--- a/cluster.c
+++ b/cluster.c
@@ -681,6 +681,28 @@ int lafs_cluster_allocate(struct block *b, int cnum)
                return 0;
        }
 
+       if (test_bit(B_EmptyIndex, &b->flags)) {
+               int credits = 0;
+               if (test_and_set_bit(B_Writeback, &b->flags))
+                       LAFS_BUG(1, b);
+               lafs_iounlock_block(b);
+               lafs_allocated_block(fs, b, 0);
+               /* FIXME this is common code - make a function?? */
+               if (cnum) {
+                       if (test_and_clear_bit(B_Realloc, &b->flags))
+                               credits++;
+                       LAFS_BUG(test_bit(B_Dirty, &b->flags), b);
+               } else {
+                       if (test_and_clear_bit(B_Dirty, &b->flags))
+                               credits++;
+                       if (test_and_clear_bit(B_Realloc, &b->flags))
+                               credits++;
+               }
+               lafs_writeback_done(b);
+               lafs_space_return(fs, credits);
+               return 0;
+       }
+
        if (!test_bit(B_Index, &b->flags) &&
            LAFSI(b->inode)->type == TypeInodeFile) {
                struct inode *myi = dblk(b)->my_inode;
@@ -718,6 +740,14 @@ int lafs_cluster_allocate(struct block *b, int cnum)
                        putref(b, MKREF(leaf));
        }
 
+       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)
@@ -727,40 +757,14 @@ int lafs_cluster_allocate(struct block *b, int cnum)
        }
        if (err) {
                /* No cleaner segments - this will have to go
-                * out with a checkpoint
+                * out with a checkpoint.
+                * Block is still 'dirty' - just clear writeback flag.
                 */
-               lafs_iounlock_block(b);
-               mutex_unlock(&wc->lock);
-               return -ENOSPC;
-       }
-
-       if (test_and_set_bit(B_Writeback, &b->flags))
-               LAFS_BUG(1, b);
-       lafs_iounlock_block(b);
-
-       if (test_bit(B_EmptyIndex, &b->flags)) {
-               int credits = 0;
-               lafs_allocated_block(fs, b, 0);
-               /* FIXME this is common code - make a function?? */
-               if (cnum) {
-                       if (test_and_clear_bit(B_Realloc, &b->flags))
-                               credits++;
-                       LAFS_BUG(test_bit(B_Dirty, &b->flags), b);
-               } else {
-                       if (test_and_clear_bit(B_Dirty, &b->flags))
-                               credits++;
-                       if (test_and_clear_bit(B_Realloc, &b->flags))
-                               credits++;
-               }
-               lafs_space_return(fs, credits);
                lafs_writeback_done(b);
+               putref(b, MKREF(cluster));
                mutex_unlock(&wc->lock);
-               return 0;
+               return -ENOSPC;
        }
-       /* insert into list ensuring there is enough space
-        * in cluster head
-        */
-       getref(b, MKREF(cluster)); /* we soon own a reference in the list */
        do {
                int avail;
                /* see how much room is in cluster.