PERFORCE change 189436 for review

Zheng Liu lz at FreeBSD.org
Thu Mar 3 13:50:39 UTC 2011


http://p4web.freebsd.org/@@189436?ac=10

Change 189436 by lz at 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 */


More information about the p4-projects mailing list