Deleted Added
full compact
ffs_alloc.c (12861) ffs_alloc.c (12911)
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.20 1995/12/03 11:16:21 bde Exp $
34 * $Id: ffs_alloc.c,v 1.21 1995/12/15 03:36:25 peter Exp $
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/buf.h>
40#include <sys/proc.h>
41#include <sys/vnode.h>
42#include <sys/mount.h>
43#include <sys/kernel.h>
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/buf.h>
40#include <sys/proc.h>
41#include <sys/vnode.h>
42#include <sys/mount.h>
43#include <sys/kernel.h>
44#include <sys/sysctl.h>
44#include <sys/syslog.h>
45
46#include <vm/vm.h>
47
48#include <ufs/ufs/quota.h>
49#include <ufs/ufs/inode.h>
50#include <ufs/ufs/ufs_extern.h>
51
52#include <ufs/ffs/fs.h>
53#include <ufs/ffs/ffs_extern.h>
54
55extern u_long nextgennumber;
56
57typedef long allocfcn_t __P((struct inode *ip, int cg, daddr_t bpref,
58 int size));
59
60static daddr_t ffs_alloccg __P((struct inode *, int, daddr_t, int));
61static daddr_t ffs_alloccgblk __P((struct fs *, struct cg *, daddr_t));
45#include <sys/syslog.h>
46
47#include <vm/vm.h>
48
49#include <ufs/ufs/quota.h>
50#include <ufs/ufs/inode.h>
51#include <ufs/ufs/ufs_extern.h>
52
53#include <ufs/ffs/fs.h>
54#include <ufs/ffs/ffs_extern.h>
55
56extern u_long nextgennumber;
57
58typedef long allocfcn_t __P((struct inode *ip, int cg, daddr_t bpref,
59 int size));
60
61static daddr_t ffs_alloccg __P((struct inode *, int, daddr_t, int));
62static daddr_t ffs_alloccgblk __P((struct fs *, struct cg *, daddr_t));
63#ifdef notyet
62static daddr_t ffs_clusteralloc __P((struct inode *, int, daddr_t, int));
64static daddr_t ffs_clusteralloc __P((struct inode *, int, daddr_t, int));
65#endif
63static ino_t ffs_dirpref __P((struct fs *));
64static daddr_t ffs_fragextend __P((struct inode *, int, long, int, int));
65static void ffs_fserr __P((struct fs *, u_int, char *));
66static u_long ffs_hashalloc
67 __P((struct inode *, int, long, int, allocfcn_t *));
68static ino_t ffs_nodealloccg __P((struct inode *, int, daddr_t, int));
69static daddr_t ffs_mapsearch __P((struct fs *, struct cg *, daddr_t, int));
70
66static ino_t ffs_dirpref __P((struct fs *));
67static daddr_t ffs_fragextend __P((struct inode *, int, long, int, int));
68static void ffs_fserr __P((struct fs *, u_int, char *));
69static u_long ffs_hashalloc
70 __P((struct inode *, int, long, int, allocfcn_t *));
71static ino_t ffs_nodealloccg __P((struct inode *, int, daddr_t, int));
72static daddr_t ffs_mapsearch __P((struct fs *, struct cg *, daddr_t, int));
73
71void ffs_clusteracct __P((struct fs *, struct cg *, daddr_t, int));
74static void ffs_clusteracct __P((struct fs *, struct cg *, daddr_t, int));
72
73/*
74 * Allocate a block in the file system.
75 *
76 * The size of the requested block is given, which must be some
77 * multiple of fs_fsize and <= fs_bsize.
78 * A preference may be optionally specified. If a preference is given
79 * the following hierarchy is used to allocate a block:

--- 240 unchanged lines hidden (view full) ---

320 * an fs_rotdelay offset from the end of the allocation for the logical
321 * block immediately preceeding the current range. If successful, the
322 * physical block numbers in the buffer pointers and in the inode are
323 * changed to reflect the new allocation. If unsuccessful, the allocation
324 * is left unchanged. The success in doing the reallocation is returned.
325 * Note that the error return is not reflected back to the user. Rather
326 * the previous block allocation will be used.
327 */
75
76/*
77 * Allocate a block in the file system.
78 *
79 * The size of the requested block is given, which must be some
80 * multiple of fs_fsize and <= fs_bsize.
81 * A preference may be optionally specified. If a preference is given
82 * the following hierarchy is used to allocate a block:

--- 240 unchanged lines hidden (view full) ---

323 * an fs_rotdelay offset from the end of the allocation for the logical
324 * block immediately preceeding the current range. If successful, the
325 * physical block numbers in the buffer pointers and in the inode are
326 * changed to reflect the new allocation. If unsuccessful, the allocation
327 * is left unchanged. The success in doing the reallocation is returned.
328 * Note that the error return is not reflected back to the user. Rather
329 * the previous block allocation will be used.
330 */
328#include <sys/sysctl.h>
329int doasyncfree = 1;
330#ifdef DEBUG
331SYSCTL_INT(_debug, 14, doasyncfree, CTLFLAG_RW, &doasyncfree, 0, "");
332#endif
331static int doasyncfree = 1;
332SYSCTL_INT(_debug, OID_AUTO, doasyncfree, CTLFLAG_RW, &doasyncfree, 0, "");
333int
334ffs_reallocblks(ap)
335 struct vop_reallocblks_args /* {
336 struct vnode *a_vp;
337 struct cluster_save *a_buflist;
338 } */ *ap;
339{
333int
334ffs_reallocblks(ap)
335 struct vop_reallocblks_args /* {
336 struct vnode *a_vp;
337 struct cluster_save *a_buflist;
338 } */ *ap;
339{
340#if 1
340#if !defined (not_yes)
341 return (ENOSPC);
342#else
343 struct fs *fs;
344 struct inode *ip;
345 struct vnode *vp;
346 struct buf *sbp, *ebp;
347 daddr_t *bap, *sbap, *ebap = 0;
348 struct cluster_save *buflist;

--- 652 unchanged lines hidden (view full) ---

1001 fs->fs_cs(fs, cgp->cg_cgx).cs_nbfree--;
1002 cylno = cbtocylno(fs, bno);
1003 cg_blks(fs, cgp, cylno)[cbtorpos(fs, bno)]--;
1004 cg_blktot(cgp)[cylno]--;
1005 fs->fs_fmod = 1;
1006 return (cgp->cg_cgx * fs->fs_fpg + bno);
1007}
1008
341 return (ENOSPC);
342#else
343 struct fs *fs;
344 struct inode *ip;
345 struct vnode *vp;
346 struct buf *sbp, *ebp;
347 daddr_t *bap, *sbap, *ebap = 0;
348 struct cluster_save *buflist;

--- 652 unchanged lines hidden (view full) ---

1001 fs->fs_cs(fs, cgp->cg_cgx).cs_nbfree--;
1002 cylno = cbtocylno(fs, bno);
1003 cg_blks(fs, cgp, cylno)[cbtorpos(fs, bno)]--;
1004 cg_blktot(cgp)[cylno]--;
1005 fs->fs_fmod = 1;
1006 return (cgp->cg_cgx * fs->fs_fpg + bno);
1007}
1008
1009#ifdef notyet
1009/*
1010 * Determine whether a cluster can be allocated.
1011 *
1012 * We do not currently check for optimal rotational layout if there
1013 * are multiple choices in the same cylinder group. Instead we just
1014 * take the first one that we find following bpref.
1015 */
1016static daddr_t

--- 72 unchanged lines hidden (view full) ---

1089 panic("ffs_clusteralloc: lost block");
1090 bdwrite(bp);
1091 return (bno);
1092
1093fail:
1094 brelse(bp);
1095 return (0);
1096}
1010/*
1011 * Determine whether a cluster can be allocated.
1012 *
1013 * We do not currently check for optimal rotational layout if there
1014 * are multiple choices in the same cylinder group. Instead we just
1015 * take the first one that we find following bpref.
1016 */
1017static daddr_t

--- 72 unchanged lines hidden (view full) ---

1090 panic("ffs_clusteralloc: lost block");
1091 bdwrite(bp);
1092 return (bno);
1093
1094fail:
1095 brelse(bp);
1096 return (0);
1097}
1098#endif
1097
1098/*
1099 * Determine whether an inode can be allocated.
1100 *
1101 * Check to see if an inode is available, and if it is,
1102 * allocate it using the following policy:
1103 * 1) allocate the requested inode.
1104 * 2) allocate the next available inode after the requested

--- 305 unchanged lines hidden (view full) ---

1410 return (-1);
1411}
1412
1413/*
1414 * Update the cluster map because of an allocation or free.
1415 *
1416 * Cnt == 1 means free; cnt == -1 means allocating.
1417 */
1099
1100/*
1101 * Determine whether an inode can be allocated.
1102 *
1103 * Check to see if an inode is available, and if it is,
1104 * allocate it using the following policy:
1105 * 1) allocate the requested inode.
1106 * 2) allocate the next available inode after the requested

--- 305 unchanged lines hidden (view full) ---

1412 return (-1);
1413}
1414
1415/*
1416 * Update the cluster map because of an allocation or free.
1417 *
1418 * Cnt == 1 means free; cnt == -1 means allocating.
1419 */
1418void
1420static void
1419ffs_clusteracct(fs, cgp, blkno, cnt)
1420 struct fs *fs;
1421 struct cg *cgp;
1422 daddr_t blkno;
1423 int cnt;
1424{
1425 long *sump;
1426 u_char *freemapp, *mapp;

--- 84 unchanged lines hidden ---
1421ffs_clusteracct(fs, cgp, blkno, cnt)
1422 struct fs *fs;
1423 struct cg *cgp;
1424 daddr_t blkno;
1425 int cnt;
1426{
1427 long *sump;
1428 u_char *freemapp, *mapp;

--- 84 unchanged lines hidden ---