BSD 4_4 release
[unix-history] / usr / src / sys / ufs / ffs / ffs_alloc.c
index 866151a..5bc3787 100644 (file)
@@ -1,10 +1,36 @@
 /*
 /*
- * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1982, 1986, 1989, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)ffs_alloc.c 7.38 (Berkeley) %G%
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)ffs_alloc.c 8.1 (Berkeley) 6/11/93
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -232,17 +258,8 @@ ffs_realloccg(ip, lbprev, bpref, osize, nsize, cred, bpp)
        bno = (daddr_t)ffs_hashalloc(ip, cg, (long)bpref, request,
            (u_long (*)())ffs_alloccg);
        if (bno > 0) {
        bno = (daddr_t)ffs_hashalloc(ip, cg, (long)bpref, request,
            (u_long (*)())ffs_alloccg);
        if (bno > 0) {
-#ifdef SECSIZE
-               obp = bread(ip->i_dev, fsbtodb(fs, bprev), osize,
-                   fs->fs_dbsize);
-#else SECSIZE
-               count = howmany(osize, CLBYTES);
-               for (i = 0; i < count; i++)
-#ifdef SECSIZE
-                       munhash(ip->i_dev, bn + i * CLBYTES / fs->fs_dbsize);
-#else SECSIZE
-                       munhash(ip->i_dev, bn + i * CLBYTES / DEV_BSIZE);
-#endif SECSIZE
+               bp->b_blkno = fsbtodb(fs, bno);
+               (void) vnode_pager_uncache(ITOV(ip));
                ffs_blkfree(ip, bprev, (long)osize);
                if (nsize < request)
                        ffs_blkfree(ip, bno + numfrags(fs, nsize),
                ffs_blkfree(ip, bprev, (long)osize);
                if (nsize < request)
                        ffs_blkfree(ip, bno + numfrags(fs, nsize),
@@ -446,9 +463,8 @@ ffs_blkpref(ip, lbn, indx, bap)
         * requested rotationally delayed by fs_rotdelay milliseconds.
         */
        nextblk = bap[indx - 1] + fs->fs_frag;
         * requested rotationally delayed by fs_rotdelay milliseconds.
         */
        nextblk = bap[indx - 1] + fs->fs_frag;
-       if (indx > fs->fs_maxcontig &&
-           bap[indx - fs->fs_maxcontig] + blkstofrags(fs, fs->fs_maxcontig)
-           != nextblk)
+       if (indx < fs->fs_maxcontig || bap[indx - fs->fs_maxcontig] +
+           blkstofrags(fs, fs->fs_maxcontig) != nextblk)
                return (nextblk);
        if (fs->fs_rotdelay != 0)
                /*
                return (nextblk);
        if (fs->fs_rotdelay != 0)
                /*
@@ -547,17 +563,12 @@ ffs_fragextend(ip, cg, bprev, osize, nsize)
                /* cannot extend across a block boundary */
                return (NULL);
        }
                /* cannot extend across a block boundary */
                return (NULL);
        }
-#ifdef SECSIZE
-       bp = bread(ip->i_dev, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize,
-           fs->fs_dbsize);
-#else SECSIZE
        error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
                (int)fs->fs_cgsize, NOCRED, &bp);
        if (error) {
                brelse(bp);
                return (NULL);
        }
        error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
                (int)fs->fs_cgsize, NOCRED, &bp);
        if (error) {
                brelse(bp);
                return (NULL);
        }
-#endif SECSIZE
        cgp = bp->b_un.b_cg;
        if (!cg_chkmagic(cgp)) {
                brelse(bp);
        cgp = bp->b_un.b_cg;
        if (!cg_chkmagic(cgp)) {
                brelse(bp);
@@ -615,17 +626,12 @@ ffs_alloccg(ip, cg, bpref, size)
        fs = ip->i_fs;
        if (fs->fs_cs(fs, cg).cs_nbfree == 0 && size == fs->fs_bsize)
                return (NULL);
        fs = ip->i_fs;
        if (fs->fs_cs(fs, cg).cs_nbfree == 0 && size == fs->fs_bsize)
                return (NULL);
-#ifdef SECSIZE
-       bp = bread(ip->i_dev, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize,
-           fs->fs_dbsize);
-#else SECSIZE
        error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
                (int)fs->fs_cgsize, NOCRED, &bp);
        if (error) {
                brelse(bp);
                return (NULL);
        }
        error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
                (int)fs->fs_cgsize, NOCRED, &bp);
        if (error) {
                brelse(bp);
                return (NULL);
        }
-#endif SECSIZE
        cgp = bp->b_un.b_cg;
        if (!cg_chkmagic(cgp) ||
            (cgp->cg_cs.cs_nbfree == 0 && size == fs->fs_bsize)) {
        cgp = bp->b_un.b_cg;
        if (!cg_chkmagic(cgp) ||
            (cgp->cg_cs.cs_nbfree == 0 && size == fs->fs_bsize)) {
@@ -730,10 +736,13 @@ ffs_alloccgblk(fs, cgp, bpref)
                goto norot;
        if (fs->fs_cpc == 0) {
                /*
                goto norot;
        if (fs->fs_cpc == 0) {
                /*
-                * block layout info is not available, so just have
-                * to take any block in this cylinder.
+                * Block layout information is not available.
+                * Leaving bpref unchanged means we take the
+                * next available free block following the one 
+                * we just allocated. Hopefully this will at
+                * least hit a track cache on drives of unknown
+                * geometry (e.g. SCSI).
                 */
                 */
-               bpref = howmany(fs->fs_spc * cylno, NSPF(fs));
                goto norot;
        }
        /*
                goto norot;
        }
        /*
@@ -821,17 +830,12 @@ ffs_ialloccg(ip, cg, ipref, mode)
        fs = ip->i_fs;
        if (fs->fs_cs(fs, cg).cs_nifree == 0)
                return (NULL);
        fs = ip->i_fs;
        if (fs->fs_cs(fs, cg).cs_nifree == 0)
                return (NULL);
-#ifdef SECSIZE
-       bp = bread(ip->i_dev, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize,
-           fs->fs_dbsize);
-#else SECSIZE
        error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
                (int)fs->fs_cgsize, NOCRED, &bp);
        if (error) {
                brelse(bp);
                return (NULL);
        }
        error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
                (int)fs->fs_cgsize, NOCRED, &bp);
        if (error) {
                brelse(bp);
                return (NULL);
        }
-#endif SECSIZE
        cgp = bp->b_un.b_cg;
        if (!cg_chkmagic(cgp) || cgp->cg_cs.cs_nifree == 0) {
                brelse(bp);
        cgp = bp->b_un.b_cg;
        if (!cg_chkmagic(cgp) || cgp->cg_cs.cs_nifree == 0) {
                brelse(bp);
@@ -914,17 +918,12 @@ ffs_blkfree(ip, bno, size)
                ffs_fserr(fs, ip->i_uid, "bad block");
                return;
        }
                ffs_fserr(fs, ip->i_uid, "bad block");
                return;
        }
-#ifdef SECSIZE
-       bp = bread(ip->i_dev, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize,
-           fs->fs_dbsize);
-#else SECSIZE
        error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
                (int)fs->fs_cgsize, NOCRED, &bp);
        if (error) {
                brelse(bp);
                return;
        }
        error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
                (int)fs->fs_cgsize, NOCRED, &bp);
        if (error) {
                brelse(bp);
                return;
        }
-#endif SECSIZE
        cgp = bp->b_un.b_cg;
        if (!cg_chkmagic(cgp)) {
                brelse(bp);
        cgp = bp->b_un.b_cg;
        if (!cg_chkmagic(cgp)) {
                brelse(bp);
@@ -1018,17 +1017,12 @@ ffs_vfree(ap)
                panic("ifree: range: dev = 0x%x, ino = %d, fs = %s\n",
                    pip->i_dev, ino, fs->fs_fsmnt);
        cg = itog(fs, ino);
                panic("ifree: range: dev = 0x%x, ino = %d, fs = %s\n",
                    pip->i_dev, ino, fs->fs_fsmnt);
        cg = itog(fs, ino);
-#ifdef SECSIZE
-       bp = bread(ip->i_dev, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize,
-           fs->fs_dbsize);
-#else SECSIZE
        error = bread(pip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
                (int)fs->fs_cgsize, NOCRED, &bp);
        if (error) {
                brelse(bp);
                return (0);
        }
        error = bread(pip->i_devvp, fsbtodb(fs, cgtod(fs, cg)),
                (int)fs->fs_cgsize, NOCRED, &bp);
        if (error) {
                brelse(bp);
                return (0);
        }
-#endif SECSIZE
        cgp = bp->b_un.b_cg;
        if (!cg_chkmagic(cgp)) {
                brelse(bp);
        cgp = bp->b_un.b_cg;
        if (!cg_chkmagic(cgp)) {
                brelse(bp);