]> git.neil.brown.name Git - LaFS.git/commitdiff
Improve credit handling when flushing a data block into the inode.
authorNeilBrown <neilb@suse.de>
Sat, 15 Aug 2009 07:09:24 +0000 (17:09 +1000)
committerNeilBrown <neilb@suse.de>
Sat, 15 Aug 2009 07:09:24 +0000 (17:09 +1000)
Both the credit and icredit need to be moved from the data block
to the inode data block (if needed)

cluster.c

index bc80310a8ddaea10adb5a361cd8e0e5cc559fb33..73bc3601b6e075a7173892a564b056b8b6f07b72 100644 (file)
--- a/cluster.c
+++ b/cluster.c
@@ -444,6 +444,7 @@ static int flush_data_to_inode(struct block *b)
                        return 0;
        }
        if (test_and_clear_bit(B_Dirty, &b->flags)) {
+               int credits = 1;
                /* Check size again, just in case it changed */
                size = i_size_read(b->inode);
                if (size + lai->metadata_size > sb->s_blocksize) {
@@ -453,8 +454,13 @@ static int flush_data_to_inode(struct block *b)
                                        lafs_space_return(fs, 1);
                        return 0;
                }
-               if (test_and_set_bit(B_Credit, &lai->iblock->b.flags))
-                       lafs_space_return(fs, 1);
+               if (!test_and_set_bit(B_Credit, &lai->dblock->b.flags))
+                       credits--;
+               if (test_and_clear_bit(B_UnincCredit, &b->flags))
+                       credits++;
+               if (!test_and_set_bit(B_ICredit, &lai->dblock->b.flags))
+                       credits--;
+               lafs_space_return(fs, credits);
                lafs_dirty_dblock(lai->dblock);
        } else if (test_and_clear_bit(B_Realloc, &b->flags)) {
                int credits = 1;
@@ -483,9 +489,8 @@ static int flush_data_to_inode(struct block *b)
        else
                clear_bit(B_WritePhase1, &b->flags);
 
-       if (!test_and_clear_bit(B_UnincCredit, &b->flags))
-               BUG();
-       lafs_space_return(fs, 1);
+       if (test_and_clear_bit(B_UnincCredit, &b->flags))
+               lafs_space_return(fs, 1);
 
        /* It is an awkward time to call lafs_inode_fillblock,
         * so do this one little change manually
@@ -598,7 +603,7 @@ unsigned long long lafs_cluster_allocate(struct block *b, int cnum)
                if (test_and_clear_bit(B_UnincCredit, &b->flags))
                        credits++;
 
-               /* hold two credits to be added to data block */
+               /* hold credits to be added to data block */
                b2 = &lai->dblock->b;
 
                /* We always erase the InoIdx block before the