ffs_alloc.c (6ddbf1e299be72c5a9aefd61feefea91b16eafa7) | ffs_alloc.c (6ab46d52a5be5dd8055899247f0dcac05f3a481c) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)ffs_alloc.c 8.8 (Berkeley) 2/21/94 | 1/* 2 * Copyright (c) 1982, 1986, 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)ffs_alloc.c 8.8 (Berkeley) 2/21/94 |
34 * $Id: ffs_alloc.c,v 1.23 1996/01/05 18:31:45 wollman Exp $ | 34 * $Id: ffs_alloc.c,v 1.24 1996/05/08 04:29:07 gpalmer Exp $ |
35 */ 36 37#include "opt_quota.h" 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/buf.h> 42#include <sys/proc.h> --- 606 unchanged lines hidden (view full) --- 649 fs->fs_cgrotor = cg; 650 return (fs->fs_fpg * cg + fs->fs_frag); 651 } 652 for (cg = 0; cg <= startcg; cg++) 653 if (fs->fs_cs(fs, cg).cs_nbfree >= avgbfree) { 654 fs->fs_cgrotor = cg; 655 return (fs->fs_fpg * cg + fs->fs_frag); 656 } | 35 */ 36 37#include "opt_quota.h" 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/buf.h> 42#include <sys/proc.h> --- 606 unchanged lines hidden (view full) --- 649 fs->fs_cgrotor = cg; 650 return (fs->fs_fpg * cg + fs->fs_frag); 651 } 652 for (cg = 0; cg <= startcg; cg++) 653 if (fs->fs_cs(fs, cg).cs_nbfree >= avgbfree) { 654 fs->fs_cgrotor = cg; 655 return (fs->fs_fpg * cg + fs->fs_frag); 656 } |
657 return (NULL); | 657 return (0); |
658 } 659 /* 660 * One or more previous blocks have been laid out. If less 661 * than fs_maxcontig previous blocks are contiguous, the 662 * next block is requested contiguously, otherwise it is 663 * requested rotationally delayed by fs_rotdelay milliseconds. 664 */ 665 nextblk = bap[indx - 1] + fs->fs_frag; --- 85 unchanged lines hidden (view full) --- 751 register struct cg *cgp; 752 struct buf *bp; 753 long bno; 754 int frags, bbase; 755 int i, error; 756 757 fs = ip->i_fs; 758 if (fs->fs_cs(fs, cg).cs_nffree < numfrags(fs, nsize - osize)) | 658 } 659 /* 660 * One or more previous blocks have been laid out. If less 661 * than fs_maxcontig previous blocks are contiguous, the 662 * next block is requested contiguously, otherwise it is 663 * requested rotationally delayed by fs_rotdelay milliseconds. 664 */ 665 nextblk = bap[indx - 1] + fs->fs_frag; --- 85 unchanged lines hidden (view full) --- 751 register struct cg *cgp; 752 struct buf *bp; 753 long bno; 754 int frags, bbase; 755 int i, error; 756 757 fs = ip->i_fs; 758 if (fs->fs_cs(fs, cg).cs_nffree < numfrags(fs, nsize - osize)) |
759 return (NULL); | 759 return (0); |
760 frags = numfrags(fs, nsize); 761 bbase = fragnum(fs, bprev); 762 if (bbase > fragnum(fs, (bprev + frags - 1))) { 763 /* cannot extend across a block boundary */ | 760 frags = numfrags(fs, nsize); 761 bbase = fragnum(fs, bprev); 762 if (bbase > fragnum(fs, (bprev + frags - 1))) { 763 /* cannot extend across a block boundary */ |
764 return (NULL); | 764 return (0); |
765 } 766 error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), 767 (int)fs->fs_cgsize, NOCRED, &bp); 768 if (error) { 769 brelse(bp); | 765 } 766 error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), 767 (int)fs->fs_cgsize, NOCRED, &bp); 768 if (error) { 769 brelse(bp); |
770 return (NULL); | 770 return (0); |
771 } 772 cgp = (struct cg *)bp->b_data; 773 if (!cg_chkmagic(cgp)) { 774 brelse(bp); | 771 } 772 cgp = (struct cg *)bp->b_data; 773 if (!cg_chkmagic(cgp)) { 774 brelse(bp); |
775 return (NULL); | 775 return (0); |
776 } 777 cgp->cg_time = time.tv_sec; 778 bno = dtogd(fs, bprev); 779 for (i = numfrags(fs, osize); i < frags; i++) 780 if (isclr(cg_blksfree(cgp), bno + i)) { 781 brelse(bp); | 776 } 777 cgp->cg_time = time.tv_sec; 778 bno = dtogd(fs, bprev); 779 for (i = numfrags(fs, osize); i < frags; i++) 780 if (isclr(cg_blksfree(cgp), bno + i)) { 781 brelse(bp); |
782 return (NULL); | 782 return (0); |
783 } 784 /* 785 * the current fragment can be extended 786 * deduct the count on fragment being extended into 787 * increase the count on the remaining fragment (if any) 788 * allocate the extended piece 789 */ 790 for (i = frags; i < fs->fs_frag - bbase; i++) --- 29 unchanged lines hidden (view full) --- 820 register struct fs *fs; 821 register struct cg *cgp; 822 struct buf *bp; 823 register int i; 824 int error, bno, frags, allocsiz; 825 826 fs = ip->i_fs; 827 if (fs->fs_cs(fs, cg).cs_nbfree == 0 && size == fs->fs_bsize) | 783 } 784 /* 785 * the current fragment can be extended 786 * deduct the count on fragment being extended into 787 * increase the count on the remaining fragment (if any) 788 * allocate the extended piece 789 */ 790 for (i = frags; i < fs->fs_frag - bbase; i++) --- 29 unchanged lines hidden (view full) --- 820 register struct fs *fs; 821 register struct cg *cgp; 822 struct buf *bp; 823 register int i; 824 int error, bno, frags, allocsiz; 825 826 fs = ip->i_fs; 827 if (fs->fs_cs(fs, cg).cs_nbfree == 0 && size == fs->fs_bsize) |
828 return (NULL); | 828 return (0); |
829 error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), 830 (int)fs->fs_cgsize, NOCRED, &bp); 831 if (error) { 832 brelse(bp); | 829 error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), 830 (int)fs->fs_cgsize, NOCRED, &bp); 831 if (error) { 832 brelse(bp); |
833 return (NULL); | 833 return (0); |
834 } 835 cgp = (struct cg *)bp->b_data; 836 if (!cg_chkmagic(cgp) || 837 (cgp->cg_cs.cs_nbfree == 0 && size == fs->fs_bsize)) { 838 brelse(bp); | 834 } 835 cgp = (struct cg *)bp->b_data; 836 if (!cg_chkmagic(cgp) || 837 (cgp->cg_cs.cs_nbfree == 0 && size == fs->fs_bsize)) { 838 brelse(bp); |
839 return (NULL); | 839 return (0); |
840 } 841 cgp->cg_time = time.tv_sec; 842 if (size == fs->fs_bsize) { 843 bno = ffs_alloccgblk(fs, cgp, bpref); 844 bdwrite(bp); 845 return (bno); 846 } 847 /* --- 7 unchanged lines hidden (view full) --- 855 break; 856 if (allocsiz == fs->fs_frag) { 857 /* 858 * no fragments were available, so a block will be 859 * allocated, and hacked up 860 */ 861 if (cgp->cg_cs.cs_nbfree == 0) { 862 brelse(bp); | 840 } 841 cgp->cg_time = time.tv_sec; 842 if (size == fs->fs_bsize) { 843 bno = ffs_alloccgblk(fs, cgp, bpref); 844 bdwrite(bp); 845 return (bno); 846 } 847 /* --- 7 unchanged lines hidden (view full) --- 855 break; 856 if (allocsiz == fs->fs_frag) { 857 /* 858 * no fragments were available, so a block will be 859 * allocated, and hacked up 860 */ 861 if (cgp->cg_cs.cs_nbfree == 0) { 862 brelse(bp); |
863 return (NULL); | 863 return (0); |
864 } 865 bno = ffs_alloccgblk(fs, cgp, bpref); 866 bpref = dtogd(fs, bno); 867 for (i = frags; i < fs->fs_frag; i++) 868 setbit(cg_blksfree(cgp), bpref + i); 869 i = fs->fs_frag - frags; 870 cgp->cg_cs.cs_nffree += i; 871 fs->fs_cstotal.cs_nffree += i; 872 fs->fs_cs(fs, cg).cs_nffree += i; 873 fs->fs_fmod = 1; 874 cgp->cg_frsum[i]++; 875 bdwrite(bp); 876 return (bno); 877 } 878 bno = ffs_mapsearch(fs, cgp, bpref, allocsiz); 879 if (bno < 0) { 880 brelse(bp); | 864 } 865 bno = ffs_alloccgblk(fs, cgp, bpref); 866 bpref = dtogd(fs, bno); 867 for (i = frags; i < fs->fs_frag; i++) 868 setbit(cg_blksfree(cgp), bpref + i); 869 i = fs->fs_frag - frags; 870 cgp->cg_cs.cs_nffree += i; 871 fs->fs_cstotal.cs_nffree += i; 872 fs->fs_cs(fs, cg).cs_nffree += i; 873 fs->fs_fmod = 1; 874 cgp->cg_frsum[i]++; 875 bdwrite(bp); 876 return (bno); 877 } 878 bno = ffs_mapsearch(fs, cgp, bpref, allocsiz); 879 if (bno < 0) { 880 brelse(bp); |
881 return (NULL); | 881 return (0); |
882 } 883 for (i = 0; i < frags; i++) 884 clrbit(cg_blksfree(cgp), bno + i); 885 cgp->cg_cs.cs_nffree -= frags; 886 fs->fs_cstotal.cs_nffree -= frags; 887 fs->fs_cs(fs, cg).cs_nffree -= frags; 888 fs->fs_fmod = 1; 889 cgp->cg_frsum[allocsiz]--; --- 97 unchanged lines hidden (view full) --- 987 } 988norot: 989 /* 990 * no blocks in the requested cylinder, so take next 991 * available one in this cylinder group. 992 */ 993 bno = ffs_mapsearch(fs, cgp, bpref, (int)fs->fs_frag); 994 if (bno < 0) | 882 } 883 for (i = 0; i < frags; i++) 884 clrbit(cg_blksfree(cgp), bno + i); 885 cgp->cg_cs.cs_nffree -= frags; 886 fs->fs_cstotal.cs_nffree -= frags; 887 fs->fs_cs(fs, cg).cs_nffree -= frags; 888 fs->fs_fmod = 1; 889 cgp->cg_frsum[allocsiz]--; --- 97 unchanged lines hidden (view full) --- 987 } 988norot: 989 /* 990 * no blocks in the requested cylinder, so take next 991 * available one in this cylinder group. 992 */ 993 bno = ffs_mapsearch(fs, cgp, bpref, (int)fs->fs_frag); 994 if (bno < 0) |
995 return (NULL); | 995 return (0); |
996 cgp->cg_rotor = bno; 997gotit: 998 blkno = fragstoblks(fs, bno); 999 ffs_clrblock(fs, cg_blksfree(cgp), (long)blkno); 1000 ffs_clusteracct(fs, cgp, blkno, -1); 1001 cgp->cg_cs.cs_nbfree--; 1002 fs->fs_cstotal.cs_nbfree--; 1003 fs->fs_cs(fs, cgp->cg_cgx).cs_nbfree--; --- 113 unchanged lines hidden (view full) --- 1117{ 1118 register struct fs *fs; 1119 register struct cg *cgp; 1120 struct buf *bp; 1121 int error, start, len, loc, map, i; 1122 1123 fs = ip->i_fs; 1124 if (fs->fs_cs(fs, cg).cs_nifree == 0) | 996 cgp->cg_rotor = bno; 997gotit: 998 blkno = fragstoblks(fs, bno); 999 ffs_clrblock(fs, cg_blksfree(cgp), (long)blkno); 1000 ffs_clusteracct(fs, cgp, blkno, -1); 1001 cgp->cg_cs.cs_nbfree--; 1002 fs->fs_cstotal.cs_nbfree--; 1003 fs->fs_cs(fs, cgp->cg_cgx).cs_nbfree--; --- 113 unchanged lines hidden (view full) --- 1117{ 1118 register struct fs *fs; 1119 register struct cg *cgp; 1120 struct buf *bp; 1121 int error, start, len, loc, map, i; 1122 1123 fs = ip->i_fs; 1124 if (fs->fs_cs(fs, cg).cs_nifree == 0) |
1125 return (NULL); | 1125 return (0); |
1126 error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), 1127 (int)fs->fs_cgsize, NOCRED, &bp); 1128 if (error) { 1129 brelse(bp); | 1126 error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), 1127 (int)fs->fs_cgsize, NOCRED, &bp); 1128 if (error) { 1129 brelse(bp); |
1130 return (NULL); | 1130 return (0); |
1131 } 1132 cgp = (struct cg *)bp->b_data; 1133 if (!cg_chkmagic(cgp) || cgp->cg_cs.cs_nifree == 0) { 1134 brelse(bp); | 1131 } 1132 cgp = (struct cg *)bp->b_data; 1133 if (!cg_chkmagic(cgp) || cgp->cg_cs.cs_nifree == 0) { 1134 brelse(bp); |
1135 return (NULL); | 1135 return (0); |
1136 } 1137 cgp->cg_time = time.tv_sec; 1138 if (ipref) { 1139 ipref %= fs->fs_ipg; 1140 if (isclr(cg_inosused(cgp), ipref)) 1141 goto gotit; 1142 } 1143 start = cgp->cg_irotor / NBBY; --- 371 unchanged lines hidden --- | 1136 } 1137 cgp->cg_time = time.tv_sec; 1138 if (ipref) { 1139 ipref %= fs->fs_ipg; 1140 if (isclr(cg_inosused(cgp), ipref)) 1141 goto gotit; 1142 } 1143 start = cgp->cg_irotor / NBBY; --- 371 unchanged lines hidden --- |