PERFORCE change 189166 for review
Zheng Liu
lz at FreeBSD.org
Sat Feb 26 01:51:15 UTC 2011
http://p4web.freebsd.org/@@189166?ac=10
Change 189166 by lz at freebsd-dev on 2011/02/26 01:51:06
ext2_reallocblks() and ext2_clusteralloc() functions cleanups.
Affected files ...
.. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#34 edit
Differences ...
==== //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#34 (text+ko) ====
@@ -678,7 +678,7 @@
*/
#ifdef FANCY_REALLOC
-static int doasyncfree = 1;
+static int doasyncfree = 0;
SYSCTL_INT(_vfs_ext2fs, OID_AUTO, doasyncfree, CTLFLAG_RW, &doasyncfree, 0,
"Use asychronous writes to update block pointers when freeing blocks");
@@ -699,6 +699,9 @@
return ENOSPC;
#else
+ if (doreallocblks == 0)
+ return (ENOSPC);
+
struct m_ext2fs *fs;
struct inode *ip;
struct vnode *vp;
@@ -754,11 +757,6 @@
soff = idp->in_off;
}
/*
- * Find the preferred location for the cluster.
- */
- EXT2_LOCK(ump);
- pref = ext2_blkpref(ip, start_lbn, soff, sbap, blkno);
- /*
* If the block range spans two block maps, get the second map.
*/
if (end_lvl == 0 || (idp = &end_ap[end_lvl - 1])->in_off + 1 >= len) {
@@ -769,17 +767,20 @@
panic("ext2_reallocblk: start == end");
#endif
ssize = len - (idp->in_off + 1);
- if (bread(vp, idp->in_lbn, (int)fs->e2fs_bsize, NOCRED, &ebp)){
- EXT2_UNLOCK(ump);
+ if (bread(vp, idp->in_lbn, (int)fs->e2fs_bsize, NOCRED, &ebp))
goto fail;
- }
ebap = (int32_t *)ebp->b_data;
}
/*
+ * Find the preferred location for the cluster.
+ */
+ EXT2_LOCK(ump);
+ pref = ext2_blkpref(ip, start_lbn, soff, sbap, blkno);
+ /*
* Search the block map looking for an allocation of the desired size.
*/
if ((newblk = (int32_t)ext2_hashalloc(ip, dtog(fs, pref), pref,
- len, ext2_clusteralloc)) == 0){
+ len, ext2_clusteralloc)) == 0) {
EXT2_UNLOCK(ump);
goto fail;
}
@@ -792,9 +793,10 @@
*/
blkno = newblk;
for (bap = &sbap[soff], i = 0; i < len; i++, blkno += fs->e2fs_fpb) {
- if (i == ssize)
+ if (i == ssize) {
bap = ebap;
soff = -i;
+ }
#ifdef DIAGNOSTIC
if (buflist->bs_children[i]->b_blkno != fsbtodb(fs, *bap))
panic("ext2_reallocblks: alloc mismatch");
@@ -851,80 +853,6 @@
#endif /* FANCY_REALLOC */
}
-static daddr_t
-ext2_clusteralloc(struct inode *ip, int cg, daddr_t bpref, int len)
-{
- struct m_ext2fs *fs;
- struct ext2mount *ump;
- struct buf *bp;
- int error, i, got, run;
- char *bbp;
- daddr_t bno;
-
- fs = ip->i_e2fs;
- ump = ip->i_ump;
-
- /*
- * TODO: we need to define a new member in m_ext2fs structure
- * to save max cluster. But for simplicity, we assume that the
- * max cluster is equal to the number of blocks per group.
- */
- if (fs->e2fs_gd[cg].ext2bgd_nbfree < len)
- return (0);
-
- EXT2_UNLOCK(ump);
- error = bread(ip->i_devvp,
- fsbtodb(fs, fs->e2fs_gd[cg].ext2bgd_b_bitmap),
- (int)fs->e2fs_bsize, NOCRED, &bp);
- if (error)
- goto fail_lock;
-
- bbp = (char *)bp->b_data;
- bp->b_xflags |= BX_BKGRDWRITE;
-
- /*
- * TODO: check to see if a cluster of the needed size is
- * available in this cg.
- */
-
- if (dtog(fs, bpref) != cg)
- bpref = 0;
- else
- bpref = dtogd(fs, bpref);
-
- for (run = 0, got = bpref; got < fs->e2fs_bpg; got++) {
- if (!isclr(bbp, got))
- run = 0;
- else {
- run++;
- if (run == len)
- break;
- }
- }
-
- if (got >= fs->e2fs_bpg)
- goto fail_lock;
-
- 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_bpg)
- panic("ext2_clusteralloc: allocated out of group");
-
- for (i = 0; i < len; i++)
- setbit(bbp, (daddr_t)bno + i);
-
- bdwrite(bp);
-
- return (phy_blk(cg, fs) + bno);
-
-fail_lock:
- EXT2_LOCK(ump);
- brelse(bp);
- return (0);
-}
-
/*
* Allocate an inode in the file system.
*
@@ -1295,10 +1223,6 @@
runlen = 0;
continue;
}
- if (bbp[loc] == (char)0xff) {
- runlen = 0;
- continue;
- }
/* Start of a run, find the number of high clear bits. */
if (runlen == 0) {
@@ -1313,7 +1237,7 @@
* Finish the current run. If it isn't long
* enough, start a new one.
*/
- bit = fls(bbp[loc]) - 1;
+ bit = ffs(bbp[loc]) - 1;
runlen += bit;
if (runlen >= 8) {
bno = runstart;
@@ -1339,12 +1263,12 @@
}
#endif /* 0 */
- bno = ext2_mapsearch(fs, bbp, bpref);
- if (bno < 0){
- brelse(bp);
- EXT2_LOCK(ump);
- return (0);
- }
+ bno = ext2_mapsearch(fs, bbp, bpref);
+ if (bno < 0){
+ brelse(bp);
+ EXT2_LOCK(ump);
+ return (0);
+ }
gotit:
#ifdef DIAGNOSTIC
if (isset(bbp, bno)) {
@@ -1363,6 +1287,83 @@
return (cg * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + bno);
}
+#ifdef FANCY_REALLOC
+static daddr_t
+ext2_clusteralloc(struct inode *ip, int cg, daddr_t bpref, int len)
+{
+ struct m_ext2fs *fs;
+ struct ext2mount *ump;
+ struct buf *bp;
+ int error, i, got, run;
+ char *bbp;
+ daddr_t bno;
+
+ fs = ip->i_e2fs;
+ ump = ip->i_ump;
+
+ /*
+ * TODO: we need to define a new member in m_ext2fs structure
+ * to save max cluster. But for simplicity, we assume that the
+ * max cluster is equal to the number of blocks per group.
+ */
+ if (fs->e2fs_gd[cg].ext2bgd_nbfree < len)
+ return (0);
+
+ EXT2_UNLOCK(ump);
+ error = bread(ip->i_devvp,
+ fsbtodb(fs, fs->e2fs_gd[cg].ext2bgd_b_bitmap),
+ (int)fs->e2fs_bsize, NOCRED, &bp);
+ if (error)
+ goto fail_lock;
+
+ bbp = (char *)bp->b_data;
+ bp->b_xflags |= BX_BKGRDWRITE;
+
+ /*
+ * TODO: check to see if a cluster of the needed size is
+ * available in this cg.
+ */
+
+ if (dtog(fs, bpref) != cg)
+ bpref = 0;
+ else
+ bpref = dtogd(fs, bpref);
+
+ for (run = 0, got = bpref; got < fs->e2fs_bpg; got++) {
+ if (!isclr(bbp, got))
+ run = 0;
+ else {
+ run++;
+ if (run == len)
+ break;
+ }
+ }
+
+ if (got >= fs->e2fs_bpg)
+ goto fail_lock;
+ /*
+ * Allocate the cluster that we have found.
+ */
+ 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_bpg)
+ panic("ext2_clusteralloc: allocated out of group");
+
+ for (i = 0; i < len; i++)
+ setbit(bbp, (daddr_t)bno + i);
+
+ bdwrite(bp);
+ return (phy_blk(cg, fs) + bno);
+
+fail_lock:
+ EXT2_LOCK(ump);
+ brelse(bp);
+ return (0);
+}
+#endif /* FANCY_REALLOC */
+
/*
* Determine whether an inode can be allocated.
*
More information about the p4-projects
mailing list