.. | .. |
---|
9 | 9 | #include "xfs_format.h" |
---|
10 | 10 | #include "xfs_trans_resv.h" |
---|
11 | 11 | #include "xfs_mount.h" |
---|
12 | | -#include "xfs_defer.h" |
---|
13 | | -#include "xfs_btree.h" |
---|
14 | | -#include "xfs_bit.h" |
---|
15 | 12 | #include "xfs_log_format.h" |
---|
16 | 13 | #include "xfs_trans.h" |
---|
17 | | -#include "xfs_sb.h" |
---|
18 | | -#include "xfs_alloc.h" |
---|
19 | 14 | #include "xfs_rtalloc.h" |
---|
20 | 15 | #include "xfs_inode.h" |
---|
21 | | -#include "scrub/xfs_scrub.h" |
---|
| 16 | +#include "xfs_bmap.h" |
---|
22 | 17 | #include "scrub/scrub.h" |
---|
23 | 18 | #include "scrub/common.h" |
---|
24 | | -#include "scrub/trace.h" |
---|
25 | 19 | |
---|
26 | 20 | /* Set us up with the realtime metadata locked. */ |
---|
27 | 21 | int |
---|
.. | .. |
---|
65 | 59 | return 0; |
---|
66 | 60 | } |
---|
67 | 61 | |
---|
| 62 | +/* Make sure the entire rtbitmap file is mapped with written extents. */ |
---|
| 63 | +STATIC int |
---|
| 64 | +xchk_rtbitmap_check_extents( |
---|
| 65 | + struct xfs_scrub *sc) |
---|
| 66 | +{ |
---|
| 67 | + struct xfs_mount *mp = sc->mp; |
---|
| 68 | + struct xfs_bmbt_irec map; |
---|
| 69 | + xfs_rtblock_t off; |
---|
| 70 | + int nmap; |
---|
| 71 | + int error = 0; |
---|
| 72 | + |
---|
| 73 | + for (off = 0; off < mp->m_sb.sb_rbmblocks;) { |
---|
| 74 | + if (xchk_should_terminate(sc, &error) || |
---|
| 75 | + (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)) |
---|
| 76 | + break; |
---|
| 77 | + |
---|
| 78 | + /* Make sure we have a written extent. */ |
---|
| 79 | + nmap = 1; |
---|
| 80 | + error = xfs_bmapi_read(mp->m_rbmip, off, |
---|
| 81 | + mp->m_sb.sb_rbmblocks - off, &map, &nmap, |
---|
| 82 | + XFS_DATA_FORK); |
---|
| 83 | + if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, off, &error)) |
---|
| 84 | + break; |
---|
| 85 | + |
---|
| 86 | + if (nmap != 1 || !xfs_bmap_is_written_extent(&map)) { |
---|
| 87 | + xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, off); |
---|
| 88 | + break; |
---|
| 89 | + } |
---|
| 90 | + |
---|
| 91 | + off += map.br_blockcount; |
---|
| 92 | + } |
---|
| 93 | + |
---|
| 94 | + return error; |
---|
| 95 | +} |
---|
| 96 | + |
---|
68 | 97 | /* Scrub the realtime bitmap. */ |
---|
69 | 98 | int |
---|
70 | 99 | xchk_rtbitmap( |
---|
.. | .. |
---|
72 | 101 | { |
---|
73 | 102 | int error; |
---|
74 | 103 | |
---|
| 104 | + /* Is the size of the rtbitmap correct? */ |
---|
| 105 | + if (sc->mp->m_rbmip->i_d.di_size != |
---|
| 106 | + XFS_FSB_TO_B(sc->mp, sc->mp->m_sb.sb_rbmblocks)) { |
---|
| 107 | + xchk_ino_set_corrupt(sc, sc->mp->m_rbmip->i_ino); |
---|
| 108 | + return 0; |
---|
| 109 | + } |
---|
| 110 | + |
---|
75 | 111 | /* Invoke the fork scrubber. */ |
---|
76 | 112 | error = xchk_metadata_inode_forks(sc); |
---|
| 113 | + if (error || (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)) |
---|
| 114 | + return error; |
---|
| 115 | + |
---|
| 116 | + error = xchk_rtbitmap_check_extents(sc); |
---|
77 | 117 | if (error || (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)) |
---|
78 | 118 | return error; |
---|
79 | 119 | |
---|
.. | .. |
---|
141 | 181 | startext = fsbno; |
---|
142 | 182 | endext = fsbno + len - 1; |
---|
143 | 183 | do_div(startext, sc->mp->m_sb.sb_rextsize); |
---|
144 | | - if (do_div(endext, sc->mp->m_sb.sb_rextsize)) |
---|
145 | | - endext++; |
---|
146 | | - extcount = endext - startext; |
---|
| 184 | + do_div(endext, sc->mp->m_sb.sb_rextsize); |
---|
| 185 | + extcount = endext - startext + 1; |
---|
147 | 186 | xfs_ilock(sc->mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP); |
---|
148 | 187 | error = xfs_rtalloc_extent_is_free(sc->mp, sc->tp, startext, extcount, |
---|
149 | 188 | &is_free); |
---|