Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 Mar 2011 08:33:02 GMT
From:      Zheng Liu <lz@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 189957 for review
Message-ID:  <201103130833.p2D8X23o066056@skunkworks.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@189957?ac=10

Change 189957 by lz@freebsd-dev on 2011/03/13 08:32:49

	       Cleanups in ext2_clusteralloc() and ext2_clusteracct().

Affected files ...

.. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#40 edit
.. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_subr.c#4 edit

Differences ...

==== //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#40 (text+ko) ====

@@ -1308,8 +1308,8 @@
         struct ext2mount *ump;
         struct buf *bp;
         char *bbp;
-        int error, i, bit, loc, end, start;
-        daddr_t bno = 0, runstart, runlen;
+        int error, i, bit, got, loc, run;
+        daddr_t bno;
         int32_t *lp;
 
         fs = ip->i_e2fs;
@@ -1354,62 +1354,39 @@
         EXT2_UNLOCK(ump);
 
         /* Search the cluster map to find a big enough cluster like ffs. */
-        if (bpref)
-                start = dtogd(fs, bpref) / NBBY;
-        else
-                start = 0;
-        end = howmany(fs->e2fs->e2fs_fpg, NBBY) - start;
-        runlen = 0;
-        runstart = 0;
-        for (loc = start; loc < end; loc++) {
-                if (bbp[loc] == (char)0xff) {
-                        runlen = 0;
-                        continue;
-                }
-
-                if (runlen == 0) {
-                        bit = ffs(bbp[loc]) - 1;
-                        runlen += bit;
-                        if (runlen >= len) {
-                                bno = loc * NBBY;
-                                goto gotit;
-                        }
-
-                        bit = fls(bbp[loc]);
-                        runlen = NBBY - bit;
-                        runstart = loc * NBBY + bit;
-                } else if (bbp[loc] == 0) {
-                        runlen += NBBY;
+        if (dtog(fs, bpref) != cg)
+                bpref = 0;
+        if (bpref != 0)
+                bpref = dtogd(fs, bpref);
+        loc = bpref / NBBY;
+        bit = 1 << (bpref % NBBY);
+        for (run = 0, got = bpref; got < fs->e2fs->e2fs_fpg; got++) {
+                if ((bbp[loc] & bit) != 0) {
+                        run = 0;
                 } else {
-                        bit = ffs(bbp[loc]) - 1;
-                        runlen += bit;
-                        if (runlen >= len) {
-                                bno = runstart;
-                                goto gotit;
-                        }
-
-                        bit = fls(bbp[loc]);
-                        runlen = NBBY - bit;
-                        runstart = loc * NBBY + bit;
+                        run++;
+                        if (run == len)
+                                break;
                 }
-
-                if (runlen >= len) {
-                        bno = runstart;
-                        goto gotit;
+                if ((got & (NBBY - 1)) != (NBBY - 1))
+                        bit <<= 1;
+                else {
+                        loc++;
+                        bit = 1;
                 }
         }
 
-gotit:
-        if (bno == 0 || bno + len >= fs->e2fs->e2fs_fpg)
+        if (got >= fs->e2fs->e2fs_fpg)
                 goto fail_lock;
 
         /*
          * Allocate the cluster that we have found.
          */
-        for (i = 0; i < len; i++)
-                if (!isclr(bbp, bno + i))
+        for (i = 1; i < len; i++)
+                if (!isclr(bbp, got - run + i))
                         panic("ext2_clusteralloc: map mismatch");
                 
+        bno = got - run + 1;
         if (bno >= fs->e2fs->e2fs_fpg)
                 panic("ext2_clusteralloc: allocated out of group");
 

==== //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_subr.c#4 (text+ko) ====

@@ -131,20 +131,16 @@
 {
         int32_t *sump = fs->e2fs_clustersum[cg].cs_sum;
         int32_t *lp;
-        int i, forw, back, start, end, map = 0, bit, loc;
-        int fpgn = howmany(fs->e2fs->e2fs_fpg, NBBY);
+        int i, forw, back, start, end, bit, loc;
 
         /* Initialize the cluster summary array. */
         if (fs->e2fs_clustersum[cg].cs_init == 0) {
                 int run = 0;
-
-                end = fpgn;
                 bit = 1;
                 loc = 0;
-                map = bbp[loc++];
 
-                for (i = 0; i < fs->e2fs->e2fs_fpg && loc < end; i++) {
-                        if ((map & bit) == 0)
+                for (i = 0; i < fs->e2fs->e2fs_fpg; i++) {
+                        if ((bbp[loc] & bit) == 0)
                                 run++;
                         else if (run != 0) {
                                 if (run > fs->e2fs_contigsumsize)
@@ -152,10 +148,10 @@
                                 sump[run]++;
                                 run = 0;
                         }
-                        if ((i & (NBBY - 1)) != (NBBY - 1))
+                        if ((i & (NBBY - 1)) != (NBBY - 1)) {
                                 bit <<= 1;
-                        else {
-                                map = bbp[loc++];
+                        } else {
+                                loc++;
                                 bit = 1;
                         }
                 }
@@ -172,26 +168,18 @@
 
         /* Find the size of the cluster going forward. */
         start = bno + 1;
-        loc = start / NBBY;
         end = start + fs->e2fs_contigsumsize;
         if (end > fs->e2fs->e2fs_fpg)
                 end = fs->e2fs->e2fs_fpg;
-        if (loc < fpgn)
-                map = bbp[loc++];
+        loc = start / NBBY;
         bit = 1 << (start % NBBY);
         for (i = start; i < end; i++) {
-                if ((map & bit) != 0)
+                if ((bbp[loc] & bit) != 0)
                         break;
                 if ((i & (NBBY - 1)) != (NBBY - 1)) {
                         bit <<= 1;
                 } else {
-                        /*
-                         * XXX: off-by-one.
-                         * when loc == howmany(fs->e2fs->e2fs_fpg, NBBY),
-                         * bbp[loc++] will cause kernel crash.
-                         */
-                        if (loc < fpgn)
-                                map = bbp[loc++];
+                        loc++;
                         bit = 1;
                 }
         }
@@ -199,19 +187,18 @@
 
         /* Find the size of the cluster going backward. */
         start = bno - 1;
-        loc = start / NBBY;
         end = start - fs->e2fs_contigsumsize;
         if (end < 0)
                 end = -1;
-        map = bbp[loc--];
+        loc = start / NBBY;
         bit = 1 << (start % NBBY);
         for (i = start; i > end; i--) {
-                if ((map & bit) != 0)
+                if ((bbp[loc] & bit) != 0)
                         break;
                 if ((i & (NBBY - 1)) != 0) {
                         bit >>= 1;
                 } else {
-                        map = bbp[loc--];
+                        loc--;
                         bit = 1 << (NBBY - 1);
                 }
         }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201103130833.p2D8X23o066056>