]> git.neil.brown.name Git - LaFS.git/commitdiff
Clean up error returns in lafs_reserve_block
authorNeilBrown <neilb@suse.de>
Sun, 12 Sep 2010 23:46:36 +0000 (09:46 +1000)
committerNeilBrown <neilb@suse.de>
Mon, 13 Sep 2010 05:16:00 +0000 (15:16 +1000)
We only want to consider EAGAIN if lafs_prealloc returns an error.
When other calls return an error, we want to pass exactly that error
back.

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

diff --git a/block.c b/block.c
index 15959e0861f28ff766fcf62cf80a15274545e78d..58af84de5b3ba791083fdf355e98ff3aff44c1ad 100644 (file)
--- a/block.c
+++ b/block.c
@@ -380,6 +380,8 @@ lafs_reserve_block(struct block *b, int alloc_type)
                         b);
        else
                err = lafs_setparent(dblk(b));
+       if (err)
+               return err;
 
        /* If there is already a physaddr, or the data is
         * stored in the inode, then we aren't really allocating
@@ -404,16 +406,30 @@ lafs_reserve_block(struct block *b, int alloc_type)
         */
        in_emergency = test_bit(EmergencyClean, &fs->fsstate);
        /* Allocate space in the filesystem */
-       err = err ?: lafs_prealloc(b, alloc_type);
+       err = lafs_prealloc(b, alloc_type);
+       if (err) {
+               if (alloc_type == NewSpace) {
+                       if (in_emergency)
+                               return -ENOSPC;
+                       return -EAGAIN;
+               }
+               if (alloc_type == ReleaseSpace)
+                       return -EAGAIN;
+               LAFS_BUG(1, b);
+       }
 
        /* Allocate space in the file (and quota set) */
-       if (err == 0 && b->physaddr == 0 &&
+       if (b->physaddr == 0 &&
            !test_bit(B_Index, &b->flags) &&
            !test_and_set_bit(B_Prealloc, &b->flags)) {
                err = lafs_summary_allocate(fs, b->inode, 1);
                if (err)
                        clear_bit(B_Prealloc, &b->flags);
        }
+       if (err) {
+               LAFS_BUG(alloc_type == AccountSpace, b);
+               return err;
+       }
 
        /* Having reserved the block, we need to get a segref,
         * which will involve reserving those blocks too.
@@ -429,16 +445,7 @@ lafs_reserve_block(struct block *b, int alloc_type)
               && !test_bit(B_SegRef, &b->flags))
                err = lafs_seg_ref_block(b, 0);
 
-       if (err == 0)
-               return 0;
-       if (alloc_type == NewSpace) {
-               if (in_emergency)
-                       return -ENOSPC;
-               return -EAGAIN;
-       }
-       if (alloc_type == ReleaseSpace)
-               return -EAGAIN;
-       LAFS_BUG(1, b);
+       return err;
 }
 
 int