Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xfs: use verifier magic field in dir2 leaf verifiers

The dir2 leaf verifiers share the same underlying structure
verification code, but implement six accessor functions to multiplex
the code across the two verifiers. Further, the magic value isn't
sufficiently abstracted such that the common helper has to manually
fix up the magic from the caller on v5 filesystems.

Use the magic field in the verifier structure to eliminate the
duplicate code and clean this all up. No functional change.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

authored by

Brian Foster and committed by
Darrick J. Wong
09f42019 b8f89801

+19 -68
+19 -68
fs/xfs/libxfs/xfs_dir2_leaf.c
··· 142 142 */ 143 143 static xfs_failaddr_t 144 144 xfs_dir3_leaf_verify( 145 - struct xfs_buf *bp, 146 - uint16_t magic) 145 + struct xfs_buf *bp) 147 146 { 148 147 struct xfs_mount *mp = bp->b_target->bt_mount; 149 148 struct xfs_dir2_leaf *leaf = bp->b_addr; 150 149 151 - ASSERT(magic == XFS_DIR2_LEAF1_MAGIC || magic == XFS_DIR2_LEAFN_MAGIC); 150 + if (!xfs_verify_magic(bp, leaf->hdr.info.magic)) 151 + return __this_address; 152 152 153 153 if (xfs_sb_version_hascrc(&mp->m_sb)) { 154 154 struct xfs_dir3_leaf_hdr *leaf3 = bp->b_addr; 155 - uint16_t magic3; 156 155 157 - magic3 = (magic == XFS_DIR2_LEAF1_MAGIC) ? XFS_DIR3_LEAF1_MAGIC 158 - : XFS_DIR3_LEAFN_MAGIC; 159 - 160 - if (leaf3->info.hdr.magic != cpu_to_be16(magic3)) 161 - return __this_address; 162 156 if (!uuid_equal(&leaf3->info.uuid, &mp->m_sb.sb_meta_uuid)) 163 157 return __this_address; 164 158 if (be64_to_cpu(leaf3->info.blkno) != bp->b_bn) 165 159 return __this_address; 166 160 if (!xfs_log_check_lsn(mp, be64_to_cpu(leaf3->info.lsn))) 167 - return __this_address; 168 - } else { 169 - if (leaf->hdr.info.magic != cpu_to_be16(magic)) 170 161 return __this_address; 171 162 } 172 163 ··· 165 174 } 166 175 167 176 static void 168 - __read_verify( 169 - struct xfs_buf *bp, 170 - uint16_t magic) 177 + xfs_dir3_leaf_read_verify( 178 + struct xfs_buf *bp) 171 179 { 172 180 struct xfs_mount *mp = bp->b_target->bt_mount; 173 181 xfs_failaddr_t fa; ··· 175 185 !xfs_buf_verify_cksum(bp, XFS_DIR3_LEAF_CRC_OFF)) 176 186 xfs_verifier_error(bp, -EFSBADCRC, __this_address); 177 187 else { 178 - fa = xfs_dir3_leaf_verify(bp, magic); 188 + fa = xfs_dir3_leaf_verify(bp); 179 189 if (fa) 180 190 xfs_verifier_error(bp, -EFSCORRUPTED, fa); 181 191 } 182 192 } 183 193 184 194 static void 185 - __write_verify( 186 - struct xfs_buf *bp, 187 - uint16_t magic) 195 + xfs_dir3_leaf_write_verify( 196 + struct xfs_buf *bp) 188 197 { 189 198 struct xfs_mount *mp = bp->b_target->bt_mount; 190 199 struct xfs_buf_log_item *bip = bp->b_log_item; 191 200 struct xfs_dir3_leaf_hdr *hdr3 = bp->b_addr; 192 201 xfs_failaddr_t fa; 193 202 194 - fa = xfs_dir3_leaf_verify(bp, magic); 203 + fa = xfs_dir3_leaf_verify(bp); 195 204 if (fa) { 196 205 xfs_verifier_error(bp, -EFSCORRUPTED, fa); 197 206 return; ··· 205 216 xfs_buf_update_cksum(bp, XFS_DIR3_LEAF_CRC_OFF); 206 217 } 207 218 208 - static xfs_failaddr_t 209 - xfs_dir3_leaf1_verify( 210 - struct xfs_buf *bp) 211 - { 212 - return xfs_dir3_leaf_verify(bp, XFS_DIR2_LEAF1_MAGIC); 213 - } 214 - 215 - static void 216 - xfs_dir3_leaf1_read_verify( 217 - struct xfs_buf *bp) 218 - { 219 - __read_verify(bp, XFS_DIR2_LEAF1_MAGIC); 220 - } 221 - 222 - static void 223 - xfs_dir3_leaf1_write_verify( 224 - struct xfs_buf *bp) 225 - { 226 - __write_verify(bp, XFS_DIR2_LEAF1_MAGIC); 227 - } 228 - 229 - static xfs_failaddr_t 230 - xfs_dir3_leafn_verify( 231 - struct xfs_buf *bp) 232 - { 233 - return xfs_dir3_leaf_verify(bp, XFS_DIR2_LEAFN_MAGIC); 234 - } 235 - 236 - static void 237 - xfs_dir3_leafn_read_verify( 238 - struct xfs_buf *bp) 239 - { 240 - __read_verify(bp, XFS_DIR2_LEAFN_MAGIC); 241 - } 242 - 243 - static void 244 - xfs_dir3_leafn_write_verify( 245 - struct xfs_buf *bp) 246 - { 247 - __write_verify(bp, XFS_DIR2_LEAFN_MAGIC); 248 - } 249 - 250 219 const struct xfs_buf_ops xfs_dir3_leaf1_buf_ops = { 251 220 .name = "xfs_dir3_leaf1", 252 - .verify_read = xfs_dir3_leaf1_read_verify, 253 - .verify_write = xfs_dir3_leaf1_write_verify, 254 - .verify_struct = xfs_dir3_leaf1_verify, 221 + .magic = { cpu_to_be16(XFS_DIR2_LEAF1_MAGIC), 222 + cpu_to_be16(XFS_DIR3_LEAF1_MAGIC) }, 223 + .verify_read = xfs_dir3_leaf_read_verify, 224 + .verify_write = xfs_dir3_leaf_write_verify, 225 + .verify_struct = xfs_dir3_leaf_verify, 255 226 }; 256 227 257 228 const struct xfs_buf_ops xfs_dir3_leafn_buf_ops = { 258 229 .name = "xfs_dir3_leafn", 259 - .verify_read = xfs_dir3_leafn_read_verify, 260 - .verify_write = xfs_dir3_leafn_write_verify, 261 - .verify_struct = xfs_dir3_leafn_verify, 230 + .magic = { cpu_to_be16(XFS_DIR2_LEAFN_MAGIC), 231 + cpu_to_be16(XFS_DIR3_LEAFN_MAGIC) }, 232 + .verify_read = xfs_dir3_leaf_read_verify, 233 + .verify_write = xfs_dir3_leaf_write_verify, 234 + .verify_struct = xfs_dir3_leaf_verify, 262 235 }; 263 236 264 237 int