From: NeilBrown Date: Sun, 12 Sep 2010 23:46:36 +0000 (+1000) Subject: Clean up error returns in lafs_reserve_block X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=4d88ac01c1cd69759b4a30e72f7c1336d91bb77b;p=LaFS.git Clean up error returns in lafs_reserve_block 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 --- diff --git a/block.c b/block.c index 15959e0..58af84d 100644 --- 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