From owner-p4-projects@FreeBSD.ORG Thu Mar 3 13:50:39 2011 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 3351F1065670; Thu, 3 Mar 2011 13:50:39 +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 D1802106566B for ; Thu, 3 Mar 2011 13:50:38 +0000 (UTC) (envelope-from lz@FreeBSD.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id BE1B98FC19 for ; Thu, 3 Mar 2011 13:50:38 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id p23DocXe007384 for ; Thu, 3 Mar 2011 13:50:38 GMT (envelope-from lz@FreeBSD.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id p23Doc0b007376 for perforce@freebsd.org; Thu, 3 Mar 2011 13:50:38 GMT (envelope-from lz@FreeBSD.org) Date: Thu, 3 Mar 2011 13:50:38 GMT Message-Id: <201103031350.p23Doc0b007376@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to lz@FreeBSD.org using -f From: Zheng Liu To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 189436 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: Thu, 03 Mar 2011 13:50:39 -0000 http://p4web.freebsd.org/@@189436?ac=10 Change 189436 by lz@freebsd-dev on 2011/03/03 13:49:47 Fix a bug in ext2_clusteralloc(). Affected files ... .. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#35 edit Differences ... ==== //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#35 (text+ko) ==== @@ -698,10 +698,6 @@ /* printf("ext2_reallocblks not implemented\n"); */ return ENOSPC; #else - - if (doreallocblks == 0) - return (ENOSPC); - struct m_ext2fs *fs; struct inode *ip; struct vnode *vp; @@ -710,13 +706,17 @@ struct ext2mount *ump; struct cluster_save *buflist; struct indir start_ap[NIADDR + 1], end_ap[NIADDR + 1], *idp; - int32_t start_lbn, end_lbn, soff, newblk, blkno =0; + int32_t start_lbn, end_lbn, soff, newblk, blkno; int i, len, start_lvl, end_lvl, pref, ssize; vp = ap->a_vp; ip = VTOI(vp); fs = ip->i_e2fs; ump = ip->i_ump; + + if (doreallocblks == 0) + return (ENOSPC); + #ifdef UNKLAR if (fs->fs_contigsumsize <= 0) return (ENOSPC); @@ -775,7 +775,7 @@ * Find the preferred location for the cluster. */ EXT2_LOCK(ump); - pref = ext2_blkpref(ip, start_lbn, soff, sbap, blkno); + pref = ext2_blkpref(ip, start_lbn, soff, sbap, 0); /* * Search the block map looking for an allocation of the desired size. */ @@ -791,6 +791,10 @@ * block pointers in the inode and indirect blocks associated * with the file. */ +#ifdef DEBUG + printf("realloc: ino %d, lbns %jd-%jd\n\told:", ip->i_number, + (intmax_t)start_lbn, (intmax_t)end_lbn); +#endif /* DEBUG */ blkno = newblk; for (bap = &sbap[soff], i = 0; i < len; i++, blkno += fs->e2fs_fpb) { if (i == ssize) { @@ -801,6 +805,9 @@ if (buflist->bs_children[i]->b_blkno != fsbtodb(fs, *bap)) panic("ext2_reallocblks: alloc mismatch"); #endif +#ifdef DEBUG + printf(" %d,", *bap); +#endif /* DEBUG */ *bap++ = blkno; } /* @@ -836,11 +843,20 @@ /* * Last, free the old blocks and assign the new blocks to the buffers. */ +#ifdef DEBUG + printf("\n\tnew:"); +#endif for (blkno = newblk, i = 0; i < len; i++, blkno += fs->e2fs_fpb) { ext2_blkfree(ip, dbtofsb(fs, buflist->bs_children[i]->b_blkno), fs->e2fs_bsize); buflist->bs_children[i]->b_blkno = fsbtodb(fs, blkno); +#ifdef DEBUG + printf(" %d,", blkno); +#endif } +#ifdef DEBUG + printf("\n"); +#endif return (0); fail: @@ -1161,10 +1177,8 @@ struct m_ext2fs *fs; struct buf *bp; struct ext2mount *ump; - /*daddr_t bno, runstart, runlen;*/ - /*int bit, loc, end, error, start;*/ - daddr_t bno; - int error; + daddr_t bno, runstart, runlen; + int bit, loc, end, error, start; char *bbp; /* XXX ondisk32 */ fs = ip->i_e2fs; @@ -1209,7 +1223,6 @@ * first try to get 8 contigous blocks, then fall back to a single * block. */ -#if 0 if (bpref) start = dtogd(fs, bpref) / NBBY; else @@ -1261,7 +1274,6 @@ start = 0; goto retry; } -#endif /* 0 */ bno = ext2_mapsearch(fs, bbp, bpref); if (bno < 0){ @@ -1326,7 +1338,7 @@ if (dtog(fs, bpref) != cg) bpref = 0; - else + if (bpref != 0) bpref = dtogd(fs, bpref); for (run = 0, got = bpref; got < fs->e2fs_bpg; got++) { @@ -1351,15 +1363,21 @@ if (bno >= fs->e2fs_bpg) panic("ext2_clusteralloc: allocated out of group"); - for (i = 0; i < len; i++) - setbit(bbp, (daddr_t)bno + i); + for (i = 0; i < len; i += fs->e2fs_fpb) { + setbit(bbp, bno + i); + EXT2_LOCK(ump); + fs->e2fs->e2fs_fbcount--; + fs->e2fs_gd[cg].ext2bgd_nbfree--; + fs->e2fs_fmod = 1; + EXT2_UNLOCK(ump); + } bdwrite(bp); return (phy_blk(cg, fs) + bno); fail_lock: + brelse(bp); EXT2_LOCK(ump); - brelse(bp); return (0); } #endif /* FANCY_REALLOC */