]>
Commit | Line | Data |
---|---|---|
2bd0ea18 | 1 | /* |
9911e5dc | 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
2bd0ea18 NS |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms of version 2 of the GNU General Public License as | |
6 | * published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it would be useful, but | |
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
11 | * | |
12 | * Further, this software is distributed without any warranty that it is | |
13 | * free of the rightful claim of any third person regarding infringement | |
14 | * or the like. Any license provided herein, whether implied or | |
15 | * otherwise, applies only to this software file. Patent licenses, if | |
16 | * any, provided herein do not apply to combinations of this program with | |
17 | * other software, or any other product whatsoever. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; if not, write the Free Software Foundation, Inc., 59 | |
21 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. | |
22 | * | |
23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, | |
24 | * Mountain View, CA 94043, or: | |
25 | * | |
26 | * http://www.sgi.com | |
27 | * | |
28 | * For further information regarding this notice, see: | |
29 | * | |
30 | * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ | |
31 | */ | |
32 | ||
33 | #include <libxfs.h> | |
34 | #include <malloc.h> | |
35 | #include "avl.h" | |
36 | #include "globals.h" | |
37 | #include "incore.h" | |
38 | #include "agheader.h" | |
39 | #include "protos.h" | |
40 | #include "err_protos.h" | |
41 | ||
42 | /* | |
43 | * push a block allocation record onto list. assumes list | |
44 | * if set to NULL if empty. | |
45 | */ | |
46 | void | |
47 | record_allocation(ba_rec_t *addr, ba_rec_t *list) | |
48 | { | |
49 | addr->next = list; | |
50 | list = addr; | |
51 | ||
52 | return; | |
53 | } | |
54 | ||
55 | void | |
56 | free_allocations(ba_rec_t *list) | |
57 | { | |
58 | ba_rec_t *current = list; | |
59 | ||
60 | while (list != NULL) { | |
61 | list = list->next; | |
62 | free(current); | |
63 | current = list; | |
64 | } | |
65 | ||
66 | return; | |
67 | } | |
68 | ||
69 | /* ba bmap setupstuff. setting/getting state is in incore.h */ | |
70 | ||
71 | void | |
72 | setup_bmap(xfs_agnumber_t agno, xfs_agblock_t numblocks, xfs_drtbno_t rtblocks) | |
73 | { | |
74 | int i; | |
75 | xfs_drfsbno_t size; | |
76 | ||
77 | ba_bmap = (__uint64_t**)malloc(agno*sizeof(__uint64_t *)); | |
78 | if (!ba_bmap) { | |
79 | do_error("couldn't allocate block map pointers\n"); | |
80 | return; | |
81 | } | |
82 | for (i = 0; i < agno; i++) { | |
83 | int size; | |
84 | ||
85 | size = roundup(numblocks * (NBBY/XR_BB),sizeof(__uint64_t)); | |
86 | ||
87 | ba_bmap[i] = (__uint64_t*)memalign(sizeof(__uint64_t), size); | |
88 | if (!ba_bmap[i]) { | |
89 | do_error("couldn't allocate block map, size = %d\n", | |
90 | numblocks); | |
91 | return; | |
92 | } | |
93 | bzero(ba_bmap[i], size); | |
94 | } | |
95 | ||
96 | if (rtblocks == 0) { | |
97 | rt_ba_bmap = NULL; | |
98 | return; | |
99 | } | |
100 | ||
101 | size = roundup(rtblocks * (NBBY/XR_BB), sizeof(__uint64_t)); | |
102 | ||
103 | rt_ba_bmap=(__uint64_t*)memalign(sizeof(__uint64_t), size); | |
104 | if (!rt_ba_bmap) { | |
105 | do_error( | |
106 | "couldn't allocate real-time block map, size = %llu\n", | |
107 | rtblocks); | |
108 | return; | |
109 | } | |
110 | ||
111 | /* | |
112 | * start all real-time as free blocks | |
113 | */ | |
114 | set_bmap_rt(rtblocks); | |
115 | ||
116 | return; | |
117 | } | |
118 | ||
119 | /* ARGSUSED */ | |
120 | void | |
121 | teardown_rt_bmap(xfs_mount_t *mp) | |
122 | { | |
123 | if (rt_ba_bmap != NULL) { | |
124 | free(rt_ba_bmap); | |
125 | rt_ba_bmap = NULL; | |
126 | } | |
127 | ||
128 | return; | |
129 | } | |
130 | ||
131 | /* ARGSUSED */ | |
132 | void | |
133 | teardown_ag_bmap(xfs_mount_t *mp, xfs_agnumber_t agno) | |
134 | { | |
135 | ASSERT(ba_bmap[agno] != NULL); | |
136 | ||
137 | free(ba_bmap[agno]); | |
138 | ba_bmap[agno] = NULL; | |
139 | ||
140 | return; | |
141 | } | |
142 | ||
143 | /* ARGSUSED */ | |
144 | void | |
145 | teardown_bmap_finish(xfs_mount_t *mp) | |
146 | { | |
147 | free(ba_bmap); | |
148 | ba_bmap = NULL; | |
149 | ||
150 | return; | |
151 | } | |
152 | ||
153 | void | |
154 | teardown_bmap(xfs_mount_t *mp) | |
155 | { | |
156 | xfs_agnumber_t i; | |
157 | ||
158 | for (i = 0; i < mp->m_sb.sb_agcount; i++) { | |
159 | teardown_ag_bmap(mp, i); | |
160 | } | |
161 | ||
162 | teardown_rt_bmap(mp); | |
163 | teardown_bmap_finish(mp); | |
164 | ||
165 | return; | |
166 | } | |
167 | ||
168 | /* | |
169 | * block map initialization routines -- realtime, log, fs | |
170 | */ | |
171 | void | |
172 | set_bmap_rt(xfs_drtbno_t num) | |
173 | { | |
174 | xfs_drtbno_t j; | |
175 | xfs_drtbno_t size; | |
176 | ||
177 | /* | |
178 | * for now, initialize all realtime blocks to be free | |
179 | * (state == XR_E_FREE) | |
180 | */ | |
181 | size = howmany(num * (NBBY/XR_BB), sizeof(__uint64_t)); | |
182 | ||
183 | for (j = 0; j < size; j++) | |
184 | rt_ba_bmap[j] = 0x2222222222222222LL; | |
185 | ||
186 | return; | |
187 | } | |
188 | ||
189 | void | |
190 | set_bmap_log(xfs_mount_t *mp) | |
191 | { | |
192 | xfs_dfsbno_t logend, i; | |
193 | ||
194 | if (mp->m_sb.sb_logstart == 0) | |
195 | return; | |
196 | ||
197 | logend = mp->m_sb.sb_logstart + mp->m_sb.sb_logblocks; | |
198 | ||
199 | for (i = mp->m_sb.sb_logstart; i < logend ; i++) { | |
200 | set_fsbno_state(mp, i, XR_E_INUSE_FS); | |
201 | } | |
202 | ||
203 | return; | |
204 | } | |
205 | ||
206 | void | |
207 | set_bmap_fs(xfs_mount_t *mp) | |
208 | { | |
209 | xfs_agnumber_t i; | |
210 | xfs_agblock_t j; | |
211 | xfs_agblock_t end; | |
212 | ||
213 | /* | |
214 | * AG header is 4 sectors | |
215 | */ | |
216 | end = howmany(4 * mp->m_sb.sb_sectsize, mp->m_sb.sb_blocksize); | |
217 | ||
218 | for (i = 0; i < mp->m_sb.sb_agcount; i++) | |
219 | for (j = 0; j < end; j++) | |
220 | set_agbno_state(mp, i, j, XR_E_INUSE_FS); | |
221 | ||
222 | return; | |
223 | } | |
224 | ||
225 | #if 0 | |
226 | void | |
227 | set_bmap_fs_bt(xfs_mount_t *mp) | |
228 | { | |
229 | xfs_agnumber_t i; | |
230 | xfs_agblock_t j; | |
231 | xfs_agblock_t begin; | |
232 | xfs_agblock_t end; | |
233 | ||
234 | begin = bnobt_root; | |
235 | end = inobt_root + 1; | |
236 | ||
237 | for (i = 0; i < mp->m_sb.sb_agcount; i++) { | |
238 | /* | |
239 | * account for btree roots | |
240 | */ | |
241 | for (j = begin; j < end; j++) | |
242 | set_agbno_state(mp, i, j, XR_E_INUSE_FS); | |
243 | } | |
244 | ||
245 | return; | |
246 | } | |
247 | #endif | |
248 | ||
249 | void | |
250 | incore_init(xfs_mount_t *mp) | |
251 | { | |
252 | int agcount = mp->m_sb.sb_agcount; | |
253 | extern void incore_ino_init(xfs_mount_t *); | |
254 | extern void incore_ext_init(xfs_mount_t *); | |
255 | ||
256 | /* init block alloc bmap */ | |
257 | ||
258 | setup_bmap(agcount, mp->m_sb.sb_agblocks, mp->m_sb.sb_rextents); | |
259 | incore_ino_init(mp); | |
260 | incore_ext_init(mp); | |
261 | ||
262 | /* initialize random globals now that we know the fs geometry */ | |
263 | ||
264 | inodes_per_block = mp->m_sb.sb_inopblock; | |
265 | ||
266 | return; | |
267 | } | |
268 | ||
269 | #if defined(XR_BMAP_TRACE) || defined(XR_BMAP_DBG) | |
270 | int | |
271 | get_agbno_state(xfs_mount_t *mp, xfs_agnumber_t agno, | |
272 | xfs_agblock_t ag_blockno) | |
273 | { | |
274 | __uint64_t *addr; | |
275 | ||
276 | addr = ba_bmap[(agno)] + (ag_blockno)/XR_BB_NUM; | |
277 | ||
278 | return((*addr >> (((ag_blockno)%XR_BB_NUM)*XR_BB)) & XR_BB_MASK); | |
279 | } | |
280 | ||
281 | void set_agbno_state(xfs_mount_t *mp, xfs_agnumber_t agno, | |
282 | xfs_agblock_t ag_blockno, int state) | |
283 | { | |
284 | __uint64_t *addr; | |
285 | ||
286 | addr = ba_bmap[(agno)] + (ag_blockno)/XR_BB_NUM; | |
287 | ||
288 | *addr = (((*addr) & | |
289 | (~((__uint64_t) XR_BB_MASK << (((ag_blockno)%XR_BB_NUM)*XR_BB)))) | | |
290 | (((__uint64_t) (state)) << (((ag_blockno)%XR_BB_NUM)*XR_BB))); | |
291 | } | |
292 | ||
293 | int | |
294 | get_fsbno_state(xfs_mount_t *mp, xfs_dfsbno_t blockno) | |
295 | { | |
296 | return(get_agbno_state(mp, XFS_FSB_TO_AGNO(mp, blockno), | |
297 | XFS_FSB_TO_AGBNO(mp, blockno))); | |
298 | } | |
299 | ||
300 | void | |
301 | set_fsbno_state(xfs_mount_t *mp, xfs_dfsbno_t blockno, int state) | |
302 | { | |
303 | set_agbno_state(mp, XFS_FSB_TO_AGNO(mp, blockno), | |
304 | XFS_FSB_TO_AGBNO(mp, blockno), state); | |
305 | ||
306 | return; | |
307 | } | |
308 | #endif |