From 58d788c21014c8cf42c19d2931f1cb30a1b9d66b Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 28 Jul 2010 21:56:29 +1000 Subject: [PATCH] Tidy up choose_free_inum a bit. The exact semantics of *bp and when refs were held were a little confusing. So only set *bp on function-exit while holding a ref on im, and if the is set on function entry, drop the ref on it and on im. Signed-off-by: NeilBrown --- inode.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/inode.c b/inode.c index 7bd89bd..0db0b49 100644 --- a/inode.c +++ b/inode.c @@ -1195,8 +1195,6 @@ choose_free_inum(struct fs *fs, struct inode *filesys, u32 *inump, int err; int bit; - mutex_lock_nested(&im->i_mutex, I_MUTEX_QUOTA); -retry: if (*bp) { struct inode *i = (*bp)->b.inode; putdref(*bp, MKREF(cfi_map)); @@ -1204,6 +1202,8 @@ retry: *bp = NULL; } + mutex_lock_nested(&im->i_mutex, I_MUTEX_QUOTA); +retry: bnum = LAFSI(im)->md.inodemap.thisblock; if (bnum == NoBlock || @@ -1260,13 +1260,13 @@ retry: err = -ENOSPC; if (!b) goto abort; - *bp = b; err = lafs_find_block(b, NOADOPT); if (err) goto abort; if (b->b.physaddr == 0 && !test_bit(B_Valid, &b->b.flags)) { LAFSI(im)->md.inodemap.nextbit = (fs->blocksize<<3) + 1; + putdref(b,MKREF(cfi_map)); goto retry; } err = lafs_read_block(b); @@ -1280,10 +1280,12 @@ retry: fs->blocksize<<3, bit); unmap_dblock(b, buf); LAFSI(im)->md.inodemap.nextbit = bit+1; - if (bit >= fs->blocksize<<3) + if (bit >= fs->blocksize<<3) { + putdref(b,MKREF(cfi_map)); goto retry; - + } mutex_unlock(&im->i_mutex); + *bp = b; *inump = bit + (bnum << (im->i_blkbits + 3)); return 0; -- 2.39.5