Commit | Line | Data |
---|---|---|
da7c5cc6 | 1 | /* |
cc050d2c | 2 | * Copyright (c) 1991 Regents of the University of California. |
7188ac27 | 3 | * All rights reserved. |
da7c5cc6 | 4 | * |
b702c21d | 5 | * %sccs.include.redist.c% |
7188ac27 | 6 | * |
6ab5dba7 | 7 | * @(#)ufs_inode.c 7.42 (Berkeley) %G% |
da7c5cc6 | 8 | */ |
5d5124a1 | 9 | |
cc050d2c KB |
10 | #include <sys/param.h> |
11 | #include <sys/systm.h> | |
12 | #include <sys/proc.h> | |
13 | #include <sys/vnode.h> | |
14 | #include <sys/mount.h> | |
15 | #include <sys/kernel.h> | |
5d5124a1 | 16 | |
cc050d2c KB |
17 | #include <ufs/ufs/quota.h> |
18 | #include <ufs/ufs/inode.h> | |
19 | #include <ufs/ufs/ufsmount.h> | |
20 | #include <ufs/ufs/ufs_extern.h> | |
c6f5111d | 21 | |
cc050d2c | 22 | u_long nextgennumber; /* Next generation number to assign. */ |
6ab5dba7 | 23 | int prtactive = 0; /* 1 => print out reclaim of active vnodes */ |
3ebac878 | 24 | |
cc050d2c | 25 | int |
1259a9f9 | 26 | ufs_init() |
5d5124a1 | 27 | { |
cc050d2c | 28 | static int first = 1; |
5d5124a1 | 29 | |
cc050d2c KB |
30 | if (!first) |
31 | return (0); | |
32 | first = 0; | |
2e64ab65 | 33 | |
cc050d2c KB |
34 | #ifdef DIAGNOSTIC |
35 | if (VN_MAXPRIVATE < sizeof(struct inode)) | |
36 | panic("ufs_init: inode too small"); | |
1259a9f9 | 37 | #endif |
cc050d2c KB |
38 | ufs_ihashinit(); |
39 | dqinit(); | |
7188ac27 KM |
40 | return (0); |
41 | } | |
3ebac878 | 42 | |
5d5124a1 | 43 | /* |
a1e9dd57 | 44 | * Unlock and decrement the reference count of an inode structure. |
5d5124a1 | 45 | */ |
cc050d2c KB |
46 | void |
47 | ufs_iput(ip) | |
7494ef16 | 48 | register struct inode *ip; |
5d5124a1 | 49 | { |
ff56f48a | 50 | |
5c2ba954 | 51 | if ((ip->i_flag & ILOCKED) == 0) |
ff56f48a | 52 | panic("iput"); |
a388503d | 53 | IUNLOCK(ip); |
7188ac27 | 54 | vrele(ITOV(ip)); |
ff56f48a KM |
55 | } |
56 | ||
5d5124a1 | 57 | /* |
a1e9dd57 KM |
58 | * Reclaim an inode so that it can be used for other purposes. |
59 | */ | |
cc050d2c | 60 | int |
a1e9dd57 KM |
61 | ufs_reclaim(vp) |
62 | register struct vnode *vp; | |
63 | { | |
cc050d2c | 64 | register struct inode *ip; |
4b61628b | 65 | int i; |
a1e9dd57 | 66 | |
0811b508 | 67 | if (prtactive && vp->v_usecount != 0) |
e038406d | 68 | vprint("ufs_reclaim: pushing active", vp); |
a1e9dd57 KM |
69 | /* |
70 | * Remove the inode from its hash chain. | |
71 | */ | |
cc050d2c | 72 | ip = VTOI(vp); |
a1e9dd57 KM |
73 | remque(ip); |
74 | ip->i_forw = ip; | |
75 | ip->i_back = ip; | |
76 | /* | |
77 | * Purge old data structures associated with the inode. | |
78 | */ | |
79 | cache_purge(vp); | |
80 | if (ip->i_devvp) { | |
81 | vrele(ip->i_devvp); | |
82 | ip->i_devvp = 0; | |
83 | } | |
84 | #ifdef QUOTA | |
4b61628b KM |
85 | for (i = 0; i < MAXQUOTAS; i++) { |
86 | if (ip->i_dquot[i] != NODQUOT) { | |
87 | dqrele(vp, ip->i_dquot[i]); | |
88 | ip->i_dquot[i] = NODQUOT; | |
89 | } | |
90 | } | |
a1e9dd57 | 91 | #endif |
a1e9dd57 KM |
92 | ip->i_flag = 0; |
93 | return (0); | |
94 | } | |
95 | ||
d6a210b8 | 96 | /* |
7494ef16 | 97 | * Lock an inode. If its already locked, set the WANT bit and sleep. |
d6a210b8 | 98 | */ |
cc050d2c KB |
99 | void |
100 | ufs_ilock(ip) | |
7494ef16 | 101 | register struct inode *ip; |
d6a210b8 BJ |
102 | { |
103 | ||
7188ac27 KM |
104 | while (ip->i_flag & ILOCKED) { |
105 | ip->i_flag |= IWANT; | |
c6f5111d | 106 | if (ip->i_spare0 == curproc->p_pid) |
71c4cb8d | 107 | panic("locking against myself"); |
c6f5111d | 108 | ip->i_spare1 = curproc->p_pid; |
7188ac27 KM |
109 | (void) sleep((caddr_t)ip, PINOD); |
110 | } | |
71c4cb8d | 111 | ip->i_spare1 = 0; |
c6f5111d | 112 | ip->i_spare0 = curproc->p_pid; |
7188ac27 | 113 | ip->i_flag |= ILOCKED; |
7032a385 | 114 | curproc->p_spare[2]++; |
d6a210b8 BJ |
115 | } |
116 | ||
117 | /* | |
7494ef16 | 118 | * Unlock an inode. If WANT bit is on, wakeup. |
d6a210b8 | 119 | */ |
cc050d2c KB |
120 | void |
121 | ufs_iunlock(ip) | |
7494ef16 | 122 | register struct inode *ip; |
d6a210b8 BJ |
123 | { |
124 | ||
7188ac27 | 125 | if ((ip->i_flag & ILOCKED) == 0) |
cc050d2c | 126 | vprint("ufs_iunlock: unlocked inode", ITOV(ip)); |
71c4cb8d | 127 | ip->i_spare0 = 0; |
7188ac27 | 128 | ip->i_flag &= ~ILOCKED; |
7032a385 | 129 | curproc->p_spare[2]--; |
7188ac27 KM |
130 | if (ip->i_flag&IWANT) { |
131 | ip->i_flag &= ~IWANT; | |
132 | wakeup((caddr_t)ip); | |
133 | } | |
134 | } |