From owner-p4-projects@FreeBSD.ORG Mon May 17 09:20:52 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 170E01065673; Mon, 17 May 2010 09:20:52 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CFFB5106566B for ; Mon, 17 May 2010 09:20:51 +0000 (UTC) (envelope-from lz@FreeBSD.org) Received: from repoman.freebsd.org (unknown [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id BD6048FC0A for ; Mon, 17 May 2010 09:20:51 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o4H9Kpth093011 for ; Mon, 17 May 2010 09:20:51 GMT (envelope-from lz@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o4H9Kpdf093009 for perforce@freebsd.org; Mon, 17 May 2010 09:20:51 GMT (envelope-from lz@FreeBSD.org) Date: Mon, 17 May 2010 09:20:51 GMT Message-Id: <201005170920.o4H9Kpdf093009@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to lz@FreeBSD.org using -f From: Zheng Liu To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 178372 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 May 2010 09:20:52 -0000 http://p4web.freebsd.org/@@178372?ac=10 Change 178372 by lz@gnehzuil-freebsd on 2010/05/17 09:20:22 Fix a bug when call ext2_mapsearch() function. * When calling ext2_mapsearch() fucntion, Cylinder group maybe does not have a free block Affected files ... .. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#11 edit Differences ... ==== //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#11 (text+ko) ==== @@ -65,7 +65,7 @@ static void ext2_add_rsv_win(struct m_ext2fs *, struct ext2_rsv_win *); static u_long ext2_alloc_blk(struct m_ext2fs *, struct inode *, int cg, struct buf *, int32_t, struct ext2_rsv_win *); -static int ext2_alloc_new_rsv_win(struct inode *, struct ext2_rsv_win *, int32_t, +static u_long ext2_alloc_new_rsv_win(struct inode *, struct ext2_rsv_win *, int32_t, struct m_ext2fs *, int, struct buf *); static int ext2_find_next_rsv_win(struct ext2_rsv_win *, struct ext2_rsv_win *, struct m_ext2fs *, int32_t, int); @@ -179,7 +179,7 @@ if (prev->rw_start > bpref) prev = RB_PREV(ext2_rsv_win_tree, root, prev); - return next; + return prev; } /* @@ -203,6 +203,7 @@ if (cur <= rsv->rw_end) cur = rsv->rw_end + 1; + /* TODO: need to be improved */ if (dtog(fs, cur) != cg) return -1; @@ -232,7 +233,7 @@ /* * Try to allocate a new reservation window. */ -static int +static u_long ext2_alloc_new_rsv_win(struct inode *ip, struct ext2_rsv_win *rp, int32_t bpref, struct m_ext2fs *fs, int cg, struct buf *bp) { @@ -255,7 +256,7 @@ * So try to allocate it in other group. */ if (dtog(fs, bpref) != cg) - return 0; + bpref = 0; if (bpref != 0) { bpref = dtogd(fs, bpref); if (isclr(bbp, bpref)) @@ -280,7 +281,10 @@ } } - bpref = ext2_mapsearch(fs, bbp, bpref); + EXT2_LOCK(ump); + if (fs->e2fs_gd[cg].ext2bgd_nbfree > 0) + bpref = ext2_mapsearch(fs, bbp, bpref); + EXT2_UNLOCK(ump); if (bpref < 0) return 0; goto allocated1; @@ -293,7 +297,10 @@ ext2_remove_rsv_win(fs, rp); mtx_unlock_spin(&fs->e2fs_rsv_lock); - bpref = ext2_mapsearch(fs, bbp, bpref); + EXT2_LOCK(ump); + if (fs->e2fs_gd[cg].ext2bgd_nbfree > 0) + bpref = ext2_mapsearch(fs, bbp, bpref); + EXT2_UNLOCK(ump); if (bpref < 0) return 0; goto allocated1; @@ -321,7 +328,10 @@ ext2_remove_rsv_win(fs, rp); mtx_unlock_spin(&fs->e2fs_rsv_lock); - bpref = ext2_mapsearch(fs, bbp, bpref); + EXT2_LOCK(ump); + if (fs->e2fs_gd[cg].ext2bgd_nbfree > 0) + bpref = ext2_mapsearch(fs, bbp, bpref); + EXT2_UNLOCK(ump); if (bpref < 0) return 0; goto allocated1; @@ -359,7 +369,7 @@ struct ext2mount *ump; u_long start; char *bbp; - u_long bno; + daddr_t bno = -1; ump = ip->i_ump; bbp = (char *)bp->b_data; @@ -377,7 +387,10 @@ ext2_remove_rsv_win(fs, rp); mtx_unlock_spin(&fs->e2fs_rsv_lock); - bno = ext2_mapsearch(fs, bbp, bpref); + EXT2_LOCK(ump); + if (fs->e2fs_gd[cg].ext2bgd_nbfree > 0) + bno = ext2_mapsearch(fs, bbp, bpref); + EXT2_UNLOCK(ump); if (bno < 0) return 0; goto allocated; @@ -411,7 +424,7 @@ */ if (rp->rw_end == EXT2_RWI_NOT_ALLOCATED) { return ext2_alloc_new_rsv_win(ip, rp, bpref, fs, cg, bp); - } else if (rp->rw_start + rp->rw_alloc_hit - 1 == rp->rw_end) { + } else if (rp->rw_start + rp->rw_alloc_hit > rp->rw_end) { return ext2_alloc_new_rsv_win(ip, rp, rp->rw_end, fs, cg, bp); } @@ -481,7 +494,7 @@ /* Read block bitmap from buffer */ EXT2_UNLOCK(ump); error = bread(ip->i_devvp, - fsbtodb(fs, fs->e2fs_gd[i].ext2bgd_b_bitmap), + fsbtodb(fs, fs->e2fs_gd[cg].ext2bgd_b_bitmap), (int)fs->e2fs_bsize, NOCRED, &bp); if (error) { brelse(bp); @@ -489,7 +502,7 @@ } EXT2_IRSV_LOCK(ip); - bno = ext2_rsvalloc(fs, ip, i, bp, bpref, size); + bno = ext2_rsvalloc(fs, ip, cg, bp, bpref, size); EXT2_IRSV_UNLOCK(ip); if (bno > 0) goto allocated; @@ -511,16 +524,16 @@ return (0); } -ioerror: - ext2_fserr(fs, cred->cr_uid, "file system IO error"); - uprintf("\n%s: write failed, file system IO error\n", fs->e2fs_fsmnt); - return EIO; - nospace: EXT2_UNLOCK(ump); ext2_fserr(fs, cred->cr_uid, "file system full"); uprintf("\n%s: write failed, file system is full\n", fs->e2fs_fsmnt); return (ENOSPC); + +ioerror: + ext2_fserr(fs, cred->cr_uid, "file system IO error"); + uprintf("\n%s: write failed, file system IO error\n", fs->e2fs_fsmnt); + return EIO; } /*