hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/fs/xfs/scrub/rtbitmap.c
....@@ -9,19 +9,13 @@
99 #include "xfs_format.h"
1010 #include "xfs_trans_resv.h"
1111 #include "xfs_mount.h"
12
-#include "xfs_defer.h"
13
-#include "xfs_btree.h"
14
-#include "xfs_bit.h"
1512 #include "xfs_log_format.h"
1613 #include "xfs_trans.h"
17
-#include "xfs_sb.h"
18
-#include "xfs_alloc.h"
1914 #include "xfs_rtalloc.h"
2015 #include "xfs_inode.h"
21
-#include "scrub/xfs_scrub.h"
16
+#include "xfs_bmap.h"
2217 #include "scrub/scrub.h"
2318 #include "scrub/common.h"
24
-#include "scrub/trace.h"
2519
2620 /* Set us up with the realtime metadata locked. */
2721 int
....@@ -65,6 +59,41 @@
6559 return 0;
6660 }
6761
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
+
6897 /* Scrub the realtime bitmap. */
6998 int
7099 xchk_rtbitmap(
....@@ -72,8 +101,19 @@
72101 {
73102 int error;
74103
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
+
75111 /* Invoke the fork scrubber. */
76112 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);
77117 if (error || (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
78118 return error;
79119
....@@ -141,9 +181,8 @@
141181 startext = fsbno;
142182 endext = fsbno + len - 1;
143183 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;
147186 xfs_ilock(sc->mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
148187 error = xfs_rtalloc_extent_is_free(sc->mp, sc->tp, startext, extcount,
149188 &is_free);