diff options
author | Darrick J. Wong <darrick.wong@oracle.com> | 2016-01-04 00:13:21 -0500 |
---|---|---|
committer | Dave Chinner <david@fromorbit.com> | 2016-01-04 00:13:21 -0500 |
commit | c5ab131ba0df8c1f1f52ffa6214d60aafeeddbd0 (patch) | |
tree | 84b78b9a7026519bca6ee11778377c97eb02d5f4 /fs/xfs | |
parent | 96f859d52bcb1c6ea6f3388d39862bf7143e2f30 (diff) |
libxfs: refactor short btree block verification
Create xfs_btree_sblock_verify() to verify short-format btree blocks
(i.e. the per-AG btrees with 32-bit block pointers) instead of
open-coding them.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Diffstat (limited to 'fs/xfs')
-rw-r--r-- | fs/xfs/libxfs/xfs_alloc_btree.c | 34 | ||||
-rw-r--r-- | fs/xfs/libxfs/xfs_btree.c | 58 | ||||
-rw-r--r-- | fs/xfs/libxfs/xfs_btree.h | 3 | ||||
-rw-r--r-- | fs/xfs/libxfs/xfs_ialloc_btree.c | 26 |
4 files changed, 67 insertions, 54 deletions
diff --git a/fs/xfs/libxfs/xfs_alloc_btree.c b/fs/xfs/libxfs/xfs_alloc_btree.c index eb8bbfe85484..444626ddbd1b 100644 --- a/fs/xfs/libxfs/xfs_alloc_btree.c +++ b/fs/xfs/libxfs/xfs_alloc_btree.c | |||
@@ -293,14 +293,7 @@ xfs_allocbt_verify( | |||
293 | level = be16_to_cpu(block->bb_level); | 293 | level = be16_to_cpu(block->bb_level); |
294 | switch (block->bb_magic) { | 294 | switch (block->bb_magic) { |
295 | case cpu_to_be32(XFS_ABTB_CRC_MAGIC): | 295 | case cpu_to_be32(XFS_ABTB_CRC_MAGIC): |
296 | if (!xfs_sb_version_hascrc(&mp->m_sb)) | 296 | if (!xfs_btree_sblock_v5hdr_verify(bp)) |
297 | return false; | ||
298 | if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid)) | ||
299 | return false; | ||
300 | if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn)) | ||
301 | return false; | ||
302 | if (pag && | ||
303 | be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno) | ||
304 | return false; | 297 | return false; |
305 | /* fall through */ | 298 | /* fall through */ |
306 | case cpu_to_be32(XFS_ABTB_MAGIC): | 299 | case cpu_to_be32(XFS_ABTB_MAGIC): |
@@ -311,14 +304,7 @@ xfs_allocbt_verify( | |||
311 | return false; | 304 | return false; |
312 | break; | 305 | break; |
313 | case cpu_to_be32(XFS_ABTC_CRC_MAGIC): | 306 | case cpu_to_be32(XFS_ABTC_CRC_MAGIC): |
314 | if (!xfs_sb_version_hascrc(&mp->m_sb)) | 307 | if (!xfs_btree_sblock_v5hdr_verify(bp)) |
315 | return false; | ||
316 | if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid)) | ||
317 | return false; | ||
318 | if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn)) | ||
319 | return false; | ||
320 | if (pag && | ||
321 | be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno) | ||
322 | return false; | 308 | return false; |
323 | /* fall through */ | 309 | /* fall through */ |
324 | case cpu_to_be32(XFS_ABTC_MAGIC): | 310 | case cpu_to_be32(XFS_ABTC_MAGIC): |
@@ -332,21 +318,7 @@ xfs_allocbt_verify( | |||
332 | return false; | 318 | return false; |
333 | } | 319 | } |
334 | 320 | ||
335 | /* numrecs verification */ | 321 | return xfs_btree_sblock_verify(bp, mp->m_alloc_mxr[level != 0]); |
336 | if (be16_to_cpu(block->bb_numrecs) > mp->m_alloc_mxr[level != 0]) | ||
337 | return false; | ||
338 | |||
339 | /* sibling pointer verification */ | ||
340 | if (!block->bb_u.s.bb_leftsib || | ||
341 | (be32_to_cpu(block->bb_u.s.bb_leftsib) >= mp->m_sb.sb_agblocks && | ||
342 | block->bb_u.s.bb_leftsib != cpu_to_be32(NULLAGBLOCK))) | ||
343 | return false; | ||
344 | if (!block->bb_u.s.bb_rightsib || | ||
345 | (be32_to_cpu(block->bb_u.s.bb_rightsib) >= mp->m_sb.sb_agblocks && | ||
346 | block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK))) | ||
347 | return false; | ||
348 | |||
349 | return true; | ||
350 | } | 322 | } |
351 | 323 | ||
352 | static void | 324 | static void |
diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c index af1bbee5586e..a0eb18ce3ad3 100644 --- a/fs/xfs/libxfs/xfs_btree.c +++ b/fs/xfs/libxfs/xfs_btree.c | |||
@@ -4080,3 +4080,61 @@ xfs_btree_change_owner( | |||
4080 | 4080 | ||
4081 | return 0; | 4081 | return 0; |
4082 | } | 4082 | } |
4083 | |||
4084 | /** | ||
4085 | * xfs_btree_sblock_v5hdr_verify() -- verify the v5 fields of a short-format | ||
4086 | * btree block | ||
4087 | * | ||
4088 | * @bp: buffer containing the btree block | ||
4089 | * @max_recs: pointer to the m_*_mxr max records field in the xfs mount | ||
4090 | * @pag_max_level: pointer to the per-ag max level field | ||
4091 | */ | ||
4092 | bool | ||
4093 | xfs_btree_sblock_v5hdr_verify( | ||
4094 | struct xfs_buf *bp) | ||
4095 | { | ||
4096 | struct xfs_mount *mp = bp->b_target->bt_mount; | ||
4097 | struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp); | ||
4098 | struct xfs_perag *pag = bp->b_pag; | ||
4099 | |||
4100 | if (!xfs_sb_version_hascrc(&mp->m_sb)) | ||
4101 | return false; | ||
4102 | if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid)) | ||
4103 | return false; | ||
4104 | if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn)) | ||
4105 | return false; | ||
4106 | if (pag && be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno) | ||
4107 | return false; | ||
4108 | return true; | ||
4109 | } | ||
4110 | |||
4111 | /** | ||
4112 | * xfs_btree_sblock_verify() -- verify a short-format btree block | ||
4113 | * | ||
4114 | * @bp: buffer containing the btree block | ||
4115 | * @max_recs: maximum records allowed in this btree node | ||
4116 | */ | ||
4117 | bool | ||
4118 | xfs_btree_sblock_verify( | ||
4119 | struct xfs_buf *bp, | ||
4120 | unsigned int max_recs) | ||
4121 | { | ||
4122 | struct xfs_mount *mp = bp->b_target->bt_mount; | ||
4123 | struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp); | ||
4124 | |||
4125 | /* numrecs verification */ | ||
4126 | if (be16_to_cpu(block->bb_numrecs) > max_recs) | ||
4127 | return false; | ||
4128 | |||
4129 | /* sibling pointer verification */ | ||
4130 | if (!block->bb_u.s.bb_leftsib || | ||
4131 | (be32_to_cpu(block->bb_u.s.bb_leftsib) >= mp->m_sb.sb_agblocks && | ||
4132 | block->bb_u.s.bb_leftsib != cpu_to_be32(NULLAGBLOCK))) | ||
4133 | return false; | ||
4134 | if (!block->bb_u.s.bb_rightsib || | ||
4135 | (be32_to_cpu(block->bb_u.s.bb_rightsib) >= mp->m_sb.sb_agblocks && | ||
4136 | block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK))) | ||
4137 | return false; | ||
4138 | |||
4139 | return true; | ||
4140 | } | ||
diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h index 992dec0638f3..2e874be70209 100644 --- a/fs/xfs/libxfs/xfs_btree.h +++ b/fs/xfs/libxfs/xfs_btree.h | |||
@@ -472,4 +472,7 @@ static inline int xfs_btree_get_level(struct xfs_btree_block *block) | |||
472 | #define XFS_BTREE_TRACE_ARGR(c, r) | 472 | #define XFS_BTREE_TRACE_ARGR(c, r) |
473 | #define XFS_BTREE_TRACE_CURSOR(c, t) | 473 | #define XFS_BTREE_TRACE_CURSOR(c, t) |
474 | 474 | ||
475 | bool xfs_btree_sblock_v5hdr_verify(struct xfs_buf *bp); | ||
476 | bool xfs_btree_sblock_verify(struct xfs_buf *bp, unsigned int max_recs); | ||
477 | |||
475 | #endif /* __XFS_BTREE_H__ */ | 478 | #endif /* __XFS_BTREE_H__ */ |
diff --git a/fs/xfs/libxfs/xfs_ialloc_btree.c b/fs/xfs/libxfs/xfs_ialloc_btree.c index 6dd44f9ea727..c679f3c05b63 100644 --- a/fs/xfs/libxfs/xfs_ialloc_btree.c +++ b/fs/xfs/libxfs/xfs_ialloc_btree.c | |||
@@ -221,7 +221,6 @@ xfs_inobt_verify( | |||
221 | { | 221 | { |
222 | struct xfs_mount *mp = bp->b_target->bt_mount; | 222 | struct xfs_mount *mp = bp->b_target->bt_mount; |
223 | struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp); | 223 | struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp); |
224 | struct xfs_perag *pag = bp->b_pag; | ||
225 | unsigned int level; | 224 | unsigned int level; |
226 | 225 | ||
227 | /* | 226 | /* |
@@ -237,14 +236,7 @@ xfs_inobt_verify( | |||
237 | switch (block->bb_magic) { | 236 | switch (block->bb_magic) { |
238 | case cpu_to_be32(XFS_IBT_CRC_MAGIC): | 237 | case cpu_to_be32(XFS_IBT_CRC_MAGIC): |
239 | case cpu_to_be32(XFS_FIBT_CRC_MAGIC): | 238 | case cpu_to_be32(XFS_FIBT_CRC_MAGIC): |
240 | if (!xfs_sb_version_hascrc(&mp->m_sb)) | 239 | if (!xfs_btree_sblock_v5hdr_verify(bp)) |
241 | return false; | ||
242 | if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid)) | ||
243 | return false; | ||
244 | if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn)) | ||
245 | return false; | ||
246 | if (pag && | ||
247 | be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno) | ||
248 | return false; | 240 | return false; |
249 | /* fall through */ | 241 | /* fall through */ |
250 | case cpu_to_be32(XFS_IBT_MAGIC): | 242 | case cpu_to_be32(XFS_IBT_MAGIC): |
@@ -254,24 +246,12 @@ xfs_inobt_verify( | |||
254 | return 0; | 246 | return 0; |
255 | } | 247 | } |
256 | 248 | ||
257 | /* numrecs and level verification */ | 249 | /* level verification */ |
258 | level = be16_to_cpu(block->bb_level); | 250 | level = be16_to_cpu(block->bb_level); |
259 | if (level >= mp->m_in_maxlevels) | 251 | if (level >= mp->m_in_maxlevels) |
260 | return false; | 252 | return false; |
261 | if (be16_to_cpu(block->bb_numrecs) > mp->m_inobt_mxr[level != 0]) | ||
262 | return false; | ||
263 | |||
264 | /* sibling pointer verification */ | ||
265 | if (!block->bb_u.s.bb_leftsib || | ||
266 | (be32_to_cpu(block->bb_u.s.bb_leftsib) >= mp->m_sb.sb_agblocks && | ||
267 | block->bb_u.s.bb_leftsib != cpu_to_be32(NULLAGBLOCK))) | ||
268 | return false; | ||
269 | if (!block->bb_u.s.bb_rightsib || | ||
270 | (be32_to_cpu(block->bb_u.s.bb_rightsib) >= mp->m_sb.sb_agblocks && | ||
271 | block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK))) | ||
272 | return false; | ||
273 | 253 | ||
274 | return true; | 254 | return xfs_btree_sblock_verify(bp, mp->m_inobt_mxr[level != 0]); |
275 | } | 255 | } |
276 | 256 | ||
277 | static void | 257 | static void |