]>
Commit | Line | Data |
---|---|---|
2bd0ea18 | 1 | /* |
da23017d NS |
2 | * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
dfc130f3 | 4 | * |
da23017d NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
2bd0ea18 | 7 | * published by the Free Software Foundation. |
dfc130f3 | 8 | * |
da23017d NS |
9 | * This program is distributed in the hope that it would be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
dfc130f3 | 13 | * |
da23017d NS |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write the Free Software Foundation, | |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
2bd0ea18 NS |
17 | */ |
18 | ||
6b803e5a | 19 | #include "libxfs.h" |
1164bde5 DC |
20 | #include "threads.h" |
21 | #include "prefetch.h" | |
2bd0ea18 NS |
22 | #include "avl.h" |
23 | #include "globals.h" | |
24 | #include "agheader.h" | |
25 | #include "incore.h" | |
26 | #include "protos.h" | |
27 | #include "err_protos.h" | |
28 | #include "dinode.h" | |
2bd0ea18 NS |
29 | #include "bmap.h" |
30 | #include "versions.h" | |
31 | #include "dir2.h" | |
06fbdda9 | 32 | #include "progress.h" |
9e0f480e DW |
33 | #include "slab.h" |
34 | #include "rmap.h" | |
2bd0ea18 | 35 | |
9e0f480e | 36 | bool collect_rmaps; |
2bd0ea18 | 37 | |
2bd0ea18 NS |
38 | /* |
39 | * null out quota inode fields in sb if they point to non-existent inodes. | |
40 | * this isn't as redundant as it looks since it's possible that the sb field | |
41 | * might be set but the imap and inode(s) agree that the inode is | |
42 | * free in which case they'd never be cleared so the fields wouldn't | |
43 | * be cleared by process_dinode(). | |
44 | */ | |
8b8a6b02 | 45 | static void |
2bd0ea18 NS |
46 | quotino_check(xfs_mount_t *mp) |
47 | { | |
48 | ino_tree_node_t *irec; | |
49 | ||
50 | if (mp->m_sb.sb_uquotino != NULLFSINO && mp->m_sb.sb_uquotino != 0) { | |
6411f39c BN |
51 | if (verify_inum(mp, mp->m_sb.sb_uquotino)) |
52 | irec = NULL; | |
53 | else | |
1ae311d5 | 54 | irec = find_inode_rec(mp, |
6411f39c BN |
55 | XFS_INO_TO_AGNO(mp, mp->m_sb.sb_uquotino), |
56 | XFS_INO_TO_AGINO(mp, mp->m_sb.sb_uquotino)); | |
2bd0ea18 NS |
57 | |
58 | if (irec == NULL || is_inode_free(irec, | |
59 | mp->m_sb.sb_uquotino - irec->ino_startnum)) { | |
60 | mp->m_sb.sb_uquotino = NULLFSINO; | |
61 | lost_uquotino = 1; | |
62 | } else | |
63 | lost_uquotino = 0; | |
64 | } | |
65 | ||
b36eef04 | 66 | if (mp->m_sb.sb_gquotino != NULLFSINO && mp->m_sb.sb_gquotino != 0) { |
6411f39c BN |
67 | if (verify_inum(mp, mp->m_sb.sb_gquotino)) |
68 | irec = NULL; | |
69 | else | |
1ae311d5 | 70 | irec = find_inode_rec(mp, |
6411f39c BN |
71 | XFS_INO_TO_AGNO(mp, mp->m_sb.sb_gquotino), |
72 | XFS_INO_TO_AGINO(mp, mp->m_sb.sb_gquotino)); | |
2bd0ea18 NS |
73 | |
74 | if (irec == NULL || is_inode_free(irec, | |
b36eef04 NS |
75 | mp->m_sb.sb_gquotino - irec->ino_startnum)) { |
76 | mp->m_sb.sb_gquotino = NULLFSINO; | |
0340d706 | 77 | lost_gquotino = 1; |
2bd0ea18 | 78 | } else |
0340d706 CS |
79 | lost_gquotino = 0; |
80 | } | |
81 | ||
82 | if (mp->m_sb.sb_pquotino != NULLFSINO && mp->m_sb.sb_pquotino != 0) { | |
83 | if (verify_inum(mp, mp->m_sb.sb_pquotino)) | |
84 | irec = NULL; | |
85 | else | |
86 | irec = find_inode_rec(mp, | |
87 | XFS_INO_TO_AGNO(mp, mp->m_sb.sb_pquotino), | |
88 | XFS_INO_TO_AGINO(mp, mp->m_sb.sb_pquotino)); | |
89 | ||
90 | if (irec == NULL || is_inode_free(irec, | |
91 | mp->m_sb.sb_pquotino - irec->ino_startnum)) { | |
92 | mp->m_sb.sb_pquotino = NULLFSINO; | |
93 | lost_pquotino = 1; | |
94 | } else | |
95 | lost_pquotino = 0; | |
2bd0ea18 NS |
96 | } |
97 | } | |
98 | ||
8b8a6b02 | 99 | static void |
2bd0ea18 NS |
100 | quota_sb_check(xfs_mount_t *mp) |
101 | { | |
102 | /* | |
103 | * if the sb says we have quotas and we lost both, | |
104 | * signal a superblock downgrade. that will cause | |
105 | * the quota flags to get zeroed. (if we only lost | |
106 | * one quota inode, do nothing and complain later.) | |
107 | * | |
108 | * if the sb says we have quotas but we didn't start out | |
109 | * with any quota inodes, signal a superblock downgrade. | |
110 | * | |
111 | * The sb downgrades are so that older systems can mount | |
112 | * the filesystem. | |
113 | * | |
114 | * if the sb says we don't have quotas but it looks like | |
115 | * we do have quota inodes, then signal a superblock upgrade. | |
116 | * | |
117 | * if the sb says we don't have quotas and we have no | |
118 | * quota inodes, then leave will enough alone. | |
119 | */ | |
120 | ||
121 | if (fs_quotas && | |
122 | (mp->m_sb.sb_uquotino == NULLFSINO || mp->m_sb.sb_uquotino == 0) && | |
0340d706 CS |
123 | (mp->m_sb.sb_gquotino == NULLFSINO || mp->m_sb.sb_gquotino == 0) && |
124 | (mp->m_sb.sb_pquotino == NULLFSINO || mp->m_sb.sb_pquotino == 0)) { | |
2bd0ea18 NS |
125 | lost_quotas = 1; |
126 | fs_quotas = 0; | |
127 | } else if (!verify_inum(mp, mp->m_sb.sb_uquotino) && | |
0340d706 CS |
128 | !verify_inum(mp, mp->m_sb.sb_gquotino) && |
129 | !verify_inum(mp, mp->m_sb.sb_pquotino)) { | |
2bd0ea18 NS |
130 | fs_quotas = 1; |
131 | } | |
132 | } | |
133 | ||
134 | ||
2556c98b BN |
135 | static void |
136 | process_ag_func( | |
137 | work_queue_t *wq, | |
138 | xfs_agnumber_t agno, | |
139 | void *arg) | |
3b6ac903 | 140 | { |
2556c98b | 141 | wait_for_inode_prefetch(arg); |
3b6ac903 | 142 | do_log(_(" - agno = %d\n"), agno); |
2556c98b | 143 | process_aginodes(wq->mp, arg, agno, 0, 1, 0); |
bd758142 | 144 | blkmap_free_final(); |
2556c98b | 145 | cleanup_inode_prefetch(arg); |
3b6ac903 MV |
146 | |
147 | /* | |
148 | * now recycle the per-AG duplicate extent records | |
149 | */ | |
150 | release_dup_extent_tree(agno); | |
151 | } | |
152 | ||
2556c98b BN |
153 | static void |
154 | process_ags( | |
155 | xfs_mount_t *mp) | |
156 | { | |
b7f12e53 DW |
157 | xfs_agnumber_t i; |
158 | int error; | |
159 | ||
1164bde5 | 160 | do_inode_prefetch(mp, ag_stride, process_ag_func, true, false); |
b7f12e53 | 161 | for (i = 0; i < mp->m_sb.sb_agcount; i++) { |
2d273771 | 162 | error = rmap_finish_collecting_fork_recs(mp, i); |
b7f12e53 DW |
163 | if (error) |
164 | do_error( | |
165 | _("unable to finish adding attr/data fork reverse-mapping data for AG %u.\n"), | |
166 | i); | |
167 | } | |
2556c98b BN |
168 | } |
169 | ||
713b6817 DW |
170 | static void |
171 | check_rmap_btrees( | |
172 | work_queue_t *wq, | |
173 | xfs_agnumber_t agno, | |
174 | void *arg) | |
175 | { | |
176 | int error; | |
177 | ||
2d273771 | 178 | error = rmap_add_fixed_ag_rec(wq->mp, agno); |
713b6817 DW |
179 | if (error) |
180 | do_error( | |
181 | _("unable to add AG %u metadata reverse-mapping data.\n"), agno); | |
182 | ||
2d273771 | 183 | error = rmap_fold_raw_recs(wq->mp, agno); |
713b6817 DW |
184 | if (error) |
185 | do_error( | |
186 | _("unable to merge AG %u metadata reverse-mapping data.\n"), agno); | |
11b9e510 | 187 | |
2d273771 | 188 | error = rmaps_verify_btree(wq->mp, agno); |
11b9e510 DW |
189 | if (error) |
190 | do_error( | |
191 | _("%s while checking reverse-mappings"), | |
192 | strerror(-error)); | |
713b6817 DW |
193 | } |
194 | ||
00f34bca DW |
195 | static void |
196 | compute_ag_refcounts( | |
197 | work_queue_t *wq, | |
198 | xfs_agnumber_t agno, | |
199 | void *arg) | |
200 | { | |
201 | int error; | |
202 | ||
203 | error = compute_refcounts(wq->mp, agno); | |
204 | if (error) | |
205 | do_error( | |
206 | _("%s while computing reference count records.\n"), | |
207 | strerror(-error)); | |
208 | } | |
209 | ||
ca8d7d6a DW |
210 | static void |
211 | process_inode_reflink_flags( | |
212 | struct work_queue *wq, | |
213 | xfs_agnumber_t agno, | |
214 | void *arg) | |
215 | { | |
216 | int error; | |
217 | ||
218 | error = fix_inode_reflink_flags(wq->mp, agno); | |
219 | if (error) | |
220 | do_error( | |
221 | _("%s while fixing inode reflink flags.\n"), | |
222 | strerror(-error)); | |
223 | } | |
224 | ||
80dbc783 DW |
225 | static void |
226 | check_refcount_btrees( | |
227 | work_queue_t *wq, | |
228 | xfs_agnumber_t agno, | |
229 | void *arg) | |
230 | { | |
231 | int error; | |
232 | ||
233 | error = check_refcounts(wq->mp, agno); | |
234 | if (error) | |
235 | do_error( | |
236 | _("%s while checking reference counts"), | |
237 | strerror(-error)); | |
238 | } | |
239 | ||
713b6817 DW |
240 | static void |
241 | process_rmap_data( | |
242 | struct xfs_mount *mp) | |
243 | { | |
244 | struct work_queue wq; | |
245 | xfs_agnumber_t i; | |
246 | ||
2d273771 | 247 | if (!rmap_needs_work(mp)) |
713b6817 DW |
248 | return; |
249 | ||
250 | create_work_queue(&wq, mp, libxfs_nproc()); | |
251 | for (i = 0; i < mp->m_sb.sb_agcount; i++) | |
252 | queue_work(&wq, check_rmap_btrees, i, NULL); | |
253 | destroy_work_queue(&wq); | |
00f34bca DW |
254 | |
255 | if (!xfs_sb_version_hasreflink(&mp->m_sb)) | |
256 | return; | |
257 | ||
258 | create_work_queue(&wq, mp, libxfs_nproc()); | |
259 | for (i = 0; i < mp->m_sb.sb_agcount; i++) | |
260 | queue_work(&wq, compute_ag_refcounts, i, NULL); | |
261 | destroy_work_queue(&wq); | |
ca8d7d6a DW |
262 | |
263 | create_work_queue(&wq, mp, libxfs_nproc()); | |
80dbc783 | 264 | for (i = 0; i < mp->m_sb.sb_agcount; i++) { |
ca8d7d6a | 265 | queue_work(&wq, process_inode_reflink_flags, i, NULL); |
80dbc783 DW |
266 | queue_work(&wq, check_refcount_btrees, i, NULL); |
267 | } | |
ca8d7d6a | 268 | destroy_work_queue(&wq); |
713b6817 | 269 | } |
2556c98b | 270 | |
2bd0ea18 NS |
271 | void |
272 | phase4(xfs_mount_t *mp) | |
273 | { | |
274 | ino_tree_node_t *irec; | |
5a35bf2c DC |
275 | xfs_rtblock_t bno; |
276 | xfs_rtblock_t rt_start; | |
2bd0ea18 NS |
277 | xfs_extlen_t rt_len; |
278 | xfs_agnumber_t i; | |
279 | xfs_agblock_t j; | |
280 | xfs_agblock_t ag_end; | |
8961bfde | 281 | xfs_extlen_t blen; |
2bd0ea18 NS |
282 | int ag_hdr_len = 4 * mp->m_sb.sb_sectsize; |
283 | int ag_hdr_block; | |
284 | int bstate; | |
dfc130f3 | 285 | |
2d273771 | 286 | if (rmap_needs_work(mp)) |
9e0f480e | 287 | collect_rmaps = true; |
2bd0ea18 NS |
288 | ag_hdr_block = howmany(ag_hdr_len, mp->m_sb.sb_blocksize); |
289 | ||
507f4e33 NS |
290 | do_log(_("Phase 4 - check for duplicate blocks...\n")); |
291 | do_log(_(" - setting up duplicate extent list...\n")); | |
2bd0ea18 | 292 | |
06fbdda9 MV |
293 | set_progress_msg(PROG_FMT_DUP_EXTENT, (__uint64_t) glob_agcount); |
294 | ||
1ae311d5 | 295 | irec = find_inode_rec(mp, XFS_INO_TO_AGNO(mp, mp->m_sb.sb_rootino), |
2bd0ea18 NS |
296 | XFS_INO_TO_AGINO(mp, mp->m_sb.sb_rootino)); |
297 | ||
298 | /* | |
299 | * we always have a root inode, even if it's free... | |
300 | * if the root is free, forget it, lost+found is already gone | |
301 | */ | |
302 | if (is_inode_free(irec, 0) || !inode_isadir(irec, 0)) { | |
303 | need_root_inode = 1; | |
304 | if (no_modify) | |
507f4e33 | 305 | do_warn(_("root inode would be lost\n")); |
2bd0ea18 | 306 | else |
507f4e33 | 307 | do_warn(_("root inode lost\n")); |
2bd0ea18 NS |
308 | } |
309 | ||
2bd0ea18 NS |
310 | for (i = 0; i < mp->m_sb.sb_agcount; i++) { |
311 | ag_end = (i < mp->m_sb.sb_agcount - 1) ? mp->m_sb.sb_agblocks : | |
312 | mp->m_sb.sb_dblocks - | |
5a35bf2c | 313 | (xfs_rfsblock_t) mp->m_sb.sb_agblocks * i; |
8961bfde | 314 | |
2bd0ea18 NS |
315 | /* |
316 | * set up duplicate extent list for this ag | |
317 | */ | |
8961bfde BN |
318 | for (j = ag_hdr_block; j < ag_end; j += blen) { |
319 | bstate = get_bmap_ext(i, j, ag_end, &blen); | |
320 | switch (bstate) { | |
2bd0ea18 NS |
321 | case XR_E_BAD_STATE: |
322 | default: | |
507f4e33 NS |
323 | do_warn( |
324 | _("unknown block state, ag %d, block %d\n"), | |
2bd0ea18 NS |
325 | i, j); |
326 | /* fall through .. */ | |
327 | case XR_E_UNKNOWN: | |
328 | case XR_E_FREE1: | |
329 | case XR_E_FREE: | |
330 | case XR_E_INUSE: | |
331 | case XR_E_INUSE_FS: | |
332 | case XR_E_INO: | |
333 | case XR_E_FS_MAP: | |
2bd0ea18 NS |
334 | break; |
335 | case XR_E_MULT: | |
8961bfde | 336 | add_dup_extent(i, j, blen); |
2bd0ea18 NS |
337 | break; |
338 | } | |
339 | } | |
8961bfde | 340 | |
06fbdda9 | 341 | PROG_RPT_INC(prog_rpt_done[i], 1); |
2bd0ea18 | 342 | } |
06fbdda9 | 343 | print_final_rpt(); |
2bd0ea18 NS |
344 | |
345 | /* | |
346 | * initialize realtime bitmap | |
347 | */ | |
348 | rt_start = 0; | |
349 | rt_len = 0; | |
350 | ||
351 | for (bno = 0; bno < mp->m_sb.sb_rextents; bno++) { | |
95650c4d | 352 | bstate = get_rtbmap(bno); |
2bd0ea18 NS |
353 | switch (bstate) { |
354 | case XR_E_BAD_STATE: | |
355 | default: | |
5d1b7f0f CH |
356 | do_warn( |
357 | _("unknown rt extent state, extent %" PRIu64 "\n"), | |
507f4e33 | 358 | bno); |
2bd0ea18 NS |
359 | /* fall through .. */ |
360 | case XR_E_UNKNOWN: | |
361 | case XR_E_FREE1: | |
362 | case XR_E_FREE: | |
363 | case XR_E_INUSE: | |
364 | case XR_E_INUSE_FS: | |
365 | case XR_E_INO: | |
366 | case XR_E_FS_MAP: | |
367 | if (rt_start == 0) | |
368 | continue; | |
369 | else { | |
370 | /* | |
371 | * add extent and reset extent state | |
372 | */ | |
373 | add_rt_dup_extent(rt_start, rt_len); | |
374 | rt_start = 0; | |
375 | rt_len = 0; | |
376 | } | |
377 | break; | |
378 | case XR_E_MULT: | |
379 | if (rt_start == 0) { | |
380 | rt_start = bno; | |
381 | rt_len = 1; | |
382 | } else if (rt_len == MAXEXTLEN) { | |
383 | /* | |
384 | * large extent case | |
385 | */ | |
386 | add_rt_dup_extent(rt_start, rt_len); | |
387 | rt_start = bno; | |
388 | rt_len = 1; | |
389 | } else | |
390 | rt_len++; | |
391 | break; | |
392 | } | |
393 | } | |
394 | ||
395 | /* | |
396 | * catch tail-case, extent hitting the end of the ag | |
397 | */ | |
398 | if (rt_start != 0) | |
399 | add_rt_dup_extent(rt_start, rt_len); | |
400 | ||
401 | /* | |
402 | * initialize bitmaps for all AGs | |
403 | */ | |
c1f7a46c | 404 | reset_bmaps(mp); |
2bd0ea18 | 405 | |
507f4e33 | 406 | do_log(_(" - check for inodes claiming duplicate blocks...\n")); |
06fbdda9 | 407 | set_progress_msg(PROG_FMT_DUP_BLOCKS, (__uint64_t) mp->m_sb.sb_icount); |
add3cb90 BN |
408 | |
409 | /* | |
410 | * ok, now process the inodes -- signal 2-pass check per inode. | |
411 | * first pass checks if the inode conflicts with a known | |
412 | * duplicate extent. if so, the inode is cleared and second | |
413 | * pass is skipped. second pass sets the block bitmap | |
414 | * for all blocks claimed by the inode. directory | |
415 | * and attribute processing is turned OFF since we did that | |
416 | * already in phase 3. | |
417 | */ | |
2556c98b | 418 | process_ags(mp); |
713b6817 DW |
419 | |
420 | /* | |
421 | * Process all the reverse-mapping data that we collected. This | |
00f34bca DW |
422 | * involves checking the rmap data against the btree, computing |
423 | * reference counts based on the rmap data, and checking the counts | |
424 | * against the refcount btree. | |
713b6817 DW |
425 | */ |
426 | process_rmap_data(mp); | |
427 | ||
06fbdda9 | 428 | print_final_rpt(); |
2bd0ea18 NS |
429 | |
430 | /* | |
431 | * free up memory used to track trealtime duplicate extents | |
432 | */ | |
433 | if (rt_start != 0) | |
434 | free_rt_dup_extent_tree(mp); | |
435 | ||
436 | /* | |
437 | * ensure consistency of quota inode pointers in superblock, | |
438 | * make sure they point to real inodes | |
439 | */ | |
440 | quotino_check(mp); | |
441 | quota_sb_check(mp); | |
442 | } |