Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2018 Oracle. All Rights Reserved. |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 4 | * Author: Darrick J. Wong <darrick.wong@oracle.com> |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | #include "xfs.h" |
| 7 | #include "xfs_fs.h" |
| 8 | #include "xfs_shared.h" |
| 9 | #include "xfs_format.h" |
| 10 | #include "xfs_trans_resv.h" |
| 11 | #include "xfs_mount.h" |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 12 | #include "xfs_btree.h" |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 13 | #include "xfs_log_format.h" |
| 14 | #include "xfs_trans.h" |
| 15 | #include "xfs_sb.h" |
| 16 | #include "xfs_inode.h" |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 17 | #include "xfs_alloc.h" |
| 18 | #include "xfs_alloc_btree.h" |
| 19 | #include "xfs_ialloc.h" |
| 20 | #include "xfs_ialloc_btree.h" |
| 21 | #include "xfs_rmap.h" |
| 22 | #include "xfs_rmap_btree.h" |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 23 | #include "xfs_refcount_btree.h" |
| 24 | #include "xfs_extent_busy.h" |
| 25 | #include "xfs_ag_resv.h" |
Darrick J. Wong | 7e85bc6 | 2018-05-29 22:18:11 -0700 | [diff] [blame] | 26 | #include "xfs_quota.h" |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 27 | #include "scrub/scrub.h" |
| 28 | #include "scrub/common.h" |
| 29 | #include "scrub/trace.h" |
| 30 | #include "scrub/repair.h" |
Darrick J. Wong | bc270b5 | 2018-07-29 22:37:09 -0700 | [diff] [blame] | 31 | #include "scrub/bitmap.h" |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * Attempt to repair some metadata, if the metadata is corrupt and userspace |
| 35 | * told us to fix it. This function returns -EAGAIN to mean "re-run scrub", |
| 36 | * and will set *fixed to true if it thinks it repaired anything. |
| 37 | */ |
| 38 | int |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 39 | xrep_attempt( |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 40 | struct xfs_inode *ip, |
Darrick J. Wong | 160b5a7 | 2019-04-16 08:22:00 -0700 | [diff] [blame] | 41 | struct xfs_scrub *sc) |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 42 | { |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 43 | int error = 0; |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 44 | |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 45 | trace_xrep_attempt(ip, sc->sm, error); |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 46 | |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 47 | xchk_ag_btcur_free(&sc->sa); |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 48 | |
| 49 | /* Repair whatever's broken. */ |
| 50 | ASSERT(sc->ops->repair); |
| 51 | error = sc->ops->repair(sc); |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 52 | trace_xrep_done(ip, sc->sm, error); |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 53 | switch (error) { |
| 54 | case 0: |
| 55 | /* |
| 56 | * Repair succeeded. Commit the fixes and perform a second |
| 57 | * scrub so that we can tell userspace if we fixed the problem. |
| 58 | */ |
| 59 | sc->sm->sm_flags &= ~XFS_SCRUB_FLAGS_OUT; |
Darrick J. Wong | 160b5a7 | 2019-04-16 08:22:00 -0700 | [diff] [blame] | 60 | sc->flags |= XREP_ALREADY_FIXED; |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 61 | return -EAGAIN; |
| 62 | case -EDEADLOCK: |
| 63 | case -EAGAIN: |
| 64 | /* Tell the caller to try again having grabbed all the locks. */ |
Darrick J. Wong | f8c2a22 | 2019-04-16 08:21:59 -0700 | [diff] [blame] | 65 | if (!(sc->flags & XCHK_TRY_HARDER)) { |
| 66 | sc->flags |= XCHK_TRY_HARDER; |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 67 | return -EAGAIN; |
| 68 | } |
| 69 | /* |
| 70 | * We tried harder but still couldn't grab all the resources |
| 71 | * we needed to fix it. The corruption has not been fixed, |
| 72 | * so report back to userspace. |
| 73 | */ |
| 74 | return -EFSCORRUPTED; |
| 75 | default: |
| 76 | return error; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * Complain about unfixable problems in the filesystem. We don't log |
| 82 | * corruptions when IFLAG_REPAIR wasn't set on the assumption that the driver |
| 83 | * program is xfs_scrub, which will call back with IFLAG_REPAIR set if the |
| 84 | * administrator isn't running xfs_scrub in no-repairs mode. |
| 85 | * |
| 86 | * Use this helper function because _ratelimited silently declares a static |
| 87 | * structure to track rate limiting information. |
| 88 | */ |
| 89 | void |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 90 | xrep_failure( |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 91 | struct xfs_mount *mp) |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 92 | { |
| 93 | xfs_alert_ratelimited(mp, |
| 94 | "Corruption not fixed during online repair. Unmount and run xfs_repair."); |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * Repair probe -- userspace uses this to probe if we're willing to repair a |
| 99 | * given mountpoint. |
| 100 | */ |
| 101 | int |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 102 | xrep_probe( |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 103 | struct xfs_scrub *sc) |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 104 | { |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 105 | int error = 0; |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 106 | |
Darrick J. Wong | c517b3a | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 107 | if (xchk_should_terminate(sc, &error)) |
Darrick J. Wong | 84d42ea | 2018-05-14 06:34:36 -0700 | [diff] [blame] | 108 | return error; |
| 109 | |
| 110 | return 0; |
| 111 | } |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 112 | |
| 113 | /* |
| 114 | * Roll a transaction, keeping the AG headers locked and reinitializing |
| 115 | * the btree cursors. |
| 116 | */ |
| 117 | int |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 118 | xrep_roll_ag_trans( |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 119 | struct xfs_scrub *sc) |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 120 | { |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 121 | int error; |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 122 | |
| 123 | /* Keep the AG header buffers locked so we can keep going. */ |
Darrick J. Wong | f9ed6de | 2018-08-09 22:42:53 -0700 | [diff] [blame] | 124 | if (sc->sa.agi_bp) |
| 125 | xfs_trans_bhold(sc->tp, sc->sa.agi_bp); |
| 126 | if (sc->sa.agf_bp) |
| 127 | xfs_trans_bhold(sc->tp, sc->sa.agf_bp); |
| 128 | if (sc->sa.agfl_bp) |
| 129 | xfs_trans_bhold(sc->tp, sc->sa.agfl_bp); |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 130 | |
Darrick J. Wong | f60be90 | 2019-04-24 10:39:49 -0700 | [diff] [blame] | 131 | /* |
| 132 | * Roll the transaction. We still own the buffer and the buffer lock |
| 133 | * regardless of whether or not the roll succeeds. If the roll fails, |
| 134 | * the buffers will be released during teardown on our way out of the |
| 135 | * kernel. If it succeeds, we join them to the new transaction and |
| 136 | * move on. |
| 137 | */ |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 138 | error = xfs_trans_roll(&sc->tp); |
| 139 | if (error) |
Darrick J. Wong | f60be90 | 2019-04-24 10:39:49 -0700 | [diff] [blame] | 140 | return error; |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 141 | |
| 142 | /* Join AG headers to the new transaction. */ |
Darrick J. Wong | f9ed6de | 2018-08-09 22:42:53 -0700 | [diff] [blame] | 143 | if (sc->sa.agi_bp) |
| 144 | xfs_trans_bjoin(sc->tp, sc->sa.agi_bp); |
| 145 | if (sc->sa.agf_bp) |
| 146 | xfs_trans_bjoin(sc->tp, sc->sa.agf_bp); |
| 147 | if (sc->sa.agfl_bp) |
| 148 | xfs_trans_bjoin(sc->tp, sc->sa.agfl_bp); |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 149 | |
| 150 | return 0; |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /* |
| 154 | * Does the given AG have enough space to rebuild a btree? Neither AG |
| 155 | * reservation can be critical, and we must have enough space (factoring |
| 156 | * in AG reservations) to construct a whole btree. |
| 157 | */ |
| 158 | bool |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 159 | xrep_ag_has_space( |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 160 | struct xfs_perag *pag, |
| 161 | xfs_extlen_t nr_blocks, |
| 162 | enum xfs_ag_resv_type type) |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 163 | { |
| 164 | return !xfs_ag_resv_critical(pag, XFS_AG_RESV_RMAPBT) && |
| 165 | !xfs_ag_resv_critical(pag, XFS_AG_RESV_METADATA) && |
| 166 | pag->pagf_freeblks > xfs_ag_resv_needed(pag, type) + nr_blocks; |
| 167 | } |
| 168 | |
| 169 | /* |
| 170 | * Figure out how many blocks to reserve for an AG repair. We calculate the |
| 171 | * worst case estimate for the number of blocks we'd need to rebuild one of |
| 172 | * any type of per-AG btree. |
| 173 | */ |
| 174 | xfs_extlen_t |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 175 | xrep_calc_ag_resblks( |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 176 | struct xfs_scrub *sc) |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 177 | { |
| 178 | struct xfs_mount *mp = sc->mp; |
| 179 | struct xfs_scrub_metadata *sm = sc->sm; |
| 180 | struct xfs_perag *pag; |
| 181 | struct xfs_buf *bp; |
Darrick J. Wong | 1fc25f5 | 2018-08-10 17:55:57 -0700 | [diff] [blame] | 182 | xfs_agino_t icount = NULLAGINO; |
| 183 | xfs_extlen_t aglen = NULLAGBLOCK; |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 184 | xfs_extlen_t usedlen; |
| 185 | xfs_extlen_t freelen; |
| 186 | xfs_extlen_t bnobt_sz; |
| 187 | xfs_extlen_t inobt_sz; |
| 188 | xfs_extlen_t rmapbt_sz; |
| 189 | xfs_extlen_t refcbt_sz; |
| 190 | int error; |
| 191 | |
| 192 | if (!(sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR)) |
| 193 | return 0; |
| 194 | |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 195 | pag = xfs_perag_get(mp, sm->sm_agno); |
Darrick J. Wong | 1fc25f5 | 2018-08-10 17:55:57 -0700 | [diff] [blame] | 196 | if (pag->pagi_init) { |
| 197 | /* Use in-core icount if possible. */ |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 198 | icount = pag->pagi_count; |
Darrick J. Wong | 1fc25f5 | 2018-08-10 17:55:57 -0700 | [diff] [blame] | 199 | } else { |
| 200 | /* Try to get the actual counters from disk. */ |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 201 | error = xfs_ialloc_read_agi(mp, NULL, sm->sm_agno, &bp); |
Darrick J. Wong | 1fc25f5 | 2018-08-10 17:55:57 -0700 | [diff] [blame] | 202 | if (!error) { |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 203 | icount = pag->pagi_count; |
| 204 | xfs_buf_relse(bp); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | /* Now grab the block counters from the AGF. */ |
| 209 | error = xfs_alloc_read_agf(mp, NULL, sm->sm_agno, 0, &bp); |
Darrick J. Wong | 1fc25f5 | 2018-08-10 17:55:57 -0700 | [diff] [blame] | 210 | if (!error) { |
Christoph Hellwig | 9798f61 | 2020-03-10 08:57:29 -0700 | [diff] [blame] | 211 | struct xfs_agf *agf = bp->b_addr; |
| 212 | |
| 213 | aglen = be32_to_cpu(agf->agf_length); |
| 214 | freelen = be32_to_cpu(agf->agf_freeblks); |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 215 | usedlen = aglen - freelen; |
| 216 | xfs_buf_relse(bp); |
| 217 | } |
| 218 | xfs_perag_put(pag); |
| 219 | |
Darrick J. Wong | 1fc25f5 | 2018-08-10 17:55:57 -0700 | [diff] [blame] | 220 | /* If the icount is impossible, make some worst-case assumptions. */ |
| 221 | if (icount == NULLAGINO || |
| 222 | !xfs_verify_agino(mp, sm->sm_agno, icount)) { |
| 223 | xfs_agino_t first, last; |
| 224 | |
| 225 | xfs_agino_range(mp, sm->sm_agno, &first, &last); |
| 226 | icount = last - first + 1; |
| 227 | } |
| 228 | |
| 229 | /* If the block counts are impossible, make worst-case assumptions. */ |
| 230 | if (aglen == NULLAGBLOCK || |
| 231 | aglen != xfs_ag_block_count(mp, sm->sm_agno) || |
| 232 | freelen >= aglen) { |
| 233 | aglen = xfs_ag_block_count(mp, sm->sm_agno); |
| 234 | freelen = aglen; |
| 235 | usedlen = aglen; |
| 236 | } |
| 237 | |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 238 | trace_xrep_calc_ag_resblks(mp, sm->sm_agno, icount, aglen, |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 239 | freelen, usedlen); |
| 240 | |
| 241 | /* |
| 242 | * Figure out how many blocks we'd need worst case to rebuild |
| 243 | * each type of btree. Note that we can only rebuild the |
| 244 | * bnobt/cntbt or inobt/finobt as pairs. |
| 245 | */ |
| 246 | bnobt_sz = 2 * xfs_allocbt_calc_size(mp, freelen); |
| 247 | if (xfs_sb_version_hassparseinodes(&mp->m_sb)) |
| 248 | inobt_sz = xfs_iallocbt_calc_size(mp, icount / |
| 249 | XFS_INODES_PER_HOLEMASK_BIT); |
| 250 | else |
| 251 | inobt_sz = xfs_iallocbt_calc_size(mp, icount / |
| 252 | XFS_INODES_PER_CHUNK); |
| 253 | if (xfs_sb_version_hasfinobt(&mp->m_sb)) |
| 254 | inobt_sz *= 2; |
| 255 | if (xfs_sb_version_hasreflink(&mp->m_sb)) |
| 256 | refcbt_sz = xfs_refcountbt_calc_size(mp, usedlen); |
| 257 | else |
| 258 | refcbt_sz = 0; |
| 259 | if (xfs_sb_version_hasrmapbt(&mp->m_sb)) { |
| 260 | /* |
| 261 | * Guess how many blocks we need to rebuild the rmapbt. |
| 262 | * For non-reflink filesystems we can't have more records than |
| 263 | * used blocks. However, with reflink it's possible to have |
| 264 | * more than one rmap record per AG block. We don't know how |
| 265 | * many rmaps there could be in the AG, so we start off with |
| 266 | * what we hope is an generous over-estimation. |
| 267 | */ |
| 268 | if (xfs_sb_version_hasreflink(&mp->m_sb)) |
| 269 | rmapbt_sz = xfs_rmapbt_calc_size(mp, |
| 270 | (unsigned long long)aglen * 2); |
| 271 | else |
| 272 | rmapbt_sz = xfs_rmapbt_calc_size(mp, usedlen); |
| 273 | } else { |
| 274 | rmapbt_sz = 0; |
| 275 | } |
| 276 | |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 277 | trace_xrep_calc_ag_resblks_btsize(mp, sm->sm_agno, bnobt_sz, |
Darrick J. Wong | 0a9633f | 2018-05-29 22:18:08 -0700 | [diff] [blame] | 278 | inobt_sz, rmapbt_sz, refcbt_sz); |
| 279 | |
| 280 | return max(max(bnobt_sz, inobt_sz), max(rmapbt_sz, refcbt_sz)); |
| 281 | } |
Darrick J. Wong | 73d6b42 | 2018-05-29 22:18:09 -0700 | [diff] [blame] | 282 | |
| 283 | /* Allocate a block in an AG. */ |
| 284 | int |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 285 | xrep_alloc_ag_block( |
Darrick J. Wong | 66e3237 | 2018-12-12 08:46:23 -0800 | [diff] [blame] | 286 | struct xfs_scrub *sc, |
| 287 | const struct xfs_owner_info *oinfo, |
| 288 | xfs_fsblock_t *fsbno, |
| 289 | enum xfs_ag_resv_type resv) |
Darrick J. Wong | 73d6b42 | 2018-05-29 22:18:09 -0700 | [diff] [blame] | 290 | { |
Darrick J. Wong | 66e3237 | 2018-12-12 08:46:23 -0800 | [diff] [blame] | 291 | struct xfs_alloc_arg args = {0}; |
| 292 | xfs_agblock_t bno; |
| 293 | int error; |
Darrick J. Wong | 73d6b42 | 2018-05-29 22:18:09 -0700 | [diff] [blame] | 294 | |
| 295 | switch (resv) { |
| 296 | case XFS_AG_RESV_AGFL: |
| 297 | case XFS_AG_RESV_RMAPBT: |
| 298 | error = xfs_alloc_get_freelist(sc->tp, sc->sa.agf_bp, &bno, 1); |
| 299 | if (error) |
| 300 | return error; |
| 301 | if (bno == NULLAGBLOCK) |
| 302 | return -ENOSPC; |
| 303 | xfs_extent_busy_reuse(sc->mp, sc->sa.agno, bno, |
| 304 | 1, false); |
| 305 | *fsbno = XFS_AGB_TO_FSB(sc->mp, sc->sa.agno, bno); |
| 306 | if (resv == XFS_AG_RESV_RMAPBT) |
| 307 | xfs_ag_resv_rmapbt_alloc(sc->mp, sc->sa.agno); |
| 308 | return 0; |
| 309 | default: |
| 310 | break; |
| 311 | } |
| 312 | |
| 313 | args.tp = sc->tp; |
| 314 | args.mp = sc->mp; |
| 315 | args.oinfo = *oinfo; |
| 316 | args.fsbno = XFS_AGB_TO_FSB(args.mp, sc->sa.agno, 0); |
| 317 | args.minlen = 1; |
| 318 | args.maxlen = 1; |
| 319 | args.prod = 1; |
| 320 | args.type = XFS_ALLOCTYPE_THIS_AG; |
| 321 | args.resv = resv; |
| 322 | |
| 323 | error = xfs_alloc_vextent(&args); |
| 324 | if (error) |
| 325 | return error; |
| 326 | if (args.fsbno == NULLFSBLOCK) |
| 327 | return -ENOSPC; |
| 328 | ASSERT(args.len == 1); |
| 329 | *fsbno = args.fsbno; |
| 330 | |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | /* Initialize a new AG btree root block with zero entries. */ |
| 335 | int |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 336 | xrep_init_btblock( |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 337 | struct xfs_scrub *sc, |
Darrick J. Wong | 73d6b42 | 2018-05-29 22:18:09 -0700 | [diff] [blame] | 338 | xfs_fsblock_t fsb, |
| 339 | struct xfs_buf **bpp, |
| 340 | xfs_btnum_t btnum, |
| 341 | const struct xfs_buf_ops *ops) |
| 342 | { |
| 343 | struct xfs_trans *tp = sc->tp; |
| 344 | struct xfs_mount *mp = sc->mp; |
| 345 | struct xfs_buf *bp; |
Darrick J. Wong | ce92464 | 2020-01-23 17:01:18 -0800 | [diff] [blame] | 346 | int error; |
Darrick J. Wong | 73d6b42 | 2018-05-29 22:18:09 -0700 | [diff] [blame] | 347 | |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 348 | trace_xrep_init_btblock(mp, XFS_FSB_TO_AGNO(mp, fsb), |
Darrick J. Wong | 73d6b42 | 2018-05-29 22:18:09 -0700 | [diff] [blame] | 349 | XFS_FSB_TO_AGBNO(mp, fsb), btnum); |
| 350 | |
| 351 | ASSERT(XFS_FSB_TO_AGNO(mp, fsb) == sc->sa.agno); |
Darrick J. Wong | ce92464 | 2020-01-23 17:01:18 -0800 | [diff] [blame] | 352 | error = xfs_trans_get_buf(tp, mp->m_ddev_targp, |
| 353 | XFS_FSB_TO_DADDR(mp, fsb), XFS_FSB_TO_BB(mp, 1), 0, |
| 354 | &bp); |
| 355 | if (error) |
| 356 | return error; |
Darrick J. Wong | 73d6b42 | 2018-05-29 22:18:09 -0700 | [diff] [blame] | 357 | xfs_buf_zero(bp, 0, BBTOB(bp->b_length)); |
Eric Sandeen | f5b999c | 2019-06-12 09:00:00 -0700 | [diff] [blame] | 358 | xfs_btree_init_block(mp, bp, btnum, 0, 0, sc->sa.agno); |
Darrick J. Wong | 73d6b42 | 2018-05-29 22:18:09 -0700 | [diff] [blame] | 359 | xfs_trans_buf_set_type(tp, bp, XFS_BLFT_BTREE_BUF); |
Eric Sandeen | 7f313ed | 2019-08-27 17:35:12 -0700 | [diff] [blame] | 360 | xfs_trans_log_buf(tp, bp, 0, BBTOB(bp->b_length) - 1); |
Darrick J. Wong | 73d6b42 | 2018-05-29 22:18:09 -0700 | [diff] [blame] | 361 | bp->b_ops = ops; |
| 362 | *bpp = bp; |
| 363 | |
| 364 | return 0; |
| 365 | } |
Darrick J. Wong | 64a39d8 | 2018-05-29 22:18:09 -0700 | [diff] [blame] | 366 | |
| 367 | /* |
| 368 | * Reconstructing per-AG Btrees |
| 369 | * |
| 370 | * When a space btree is corrupt, we don't bother trying to fix it. Instead, |
| 371 | * we scan secondary space metadata to derive the records that should be in |
| 372 | * the damaged btree, initialize a fresh btree root, and insert the records. |
| 373 | * Note that for rebuilding the rmapbt we scan all the primary data to |
| 374 | * generate the new records. |
| 375 | * |
| 376 | * However, that leaves the matter of removing all the metadata describing the |
| 377 | * old broken structure. For primary metadata we use the rmap data to collect |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 378 | * every extent with a matching rmap owner (bitmap); we then iterate all other |
Darrick J. Wong | 64a39d8 | 2018-05-29 22:18:09 -0700 | [diff] [blame] | 379 | * metadata structures with the same rmap owner to collect the extents that |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 380 | * cannot be removed (sublist). We then subtract sublist from bitmap to |
Darrick J. Wong | 64a39d8 | 2018-05-29 22:18:09 -0700 | [diff] [blame] | 381 | * derive the blocks that were used by the old btree. These blocks can be |
| 382 | * reaped. |
| 383 | * |
| 384 | * For rmapbt reconstructions we must use different tactics for extent |
| 385 | * collection. First we iterate all primary metadata (this excludes the old |
| 386 | * rmapbt, obviously) to generate new rmap records. The gaps in the rmap |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 387 | * records are collected as bitmap. The bnobt records are collected as |
| 388 | * sublist. As with the other btrees we subtract sublist from bitmap, and the |
Darrick J. Wong | 64a39d8 | 2018-05-29 22:18:09 -0700 | [diff] [blame] | 389 | * result (since the rmapbt lives in the free space) are the blocks from the |
| 390 | * old rmapbt. |
Darrick J. Wong | 64a39d8 | 2018-05-29 22:18:09 -0700 | [diff] [blame] | 391 | * |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 392 | * Disposal of Blocks from Old per-AG Btrees |
| 393 | * |
| 394 | * Now that we've constructed a new btree to replace the damaged one, we want |
| 395 | * to dispose of the blocks that (we think) the old btree was using. |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 396 | * Previously, we used the rmapbt to collect the extents (bitmap) with the |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 397 | * rmap owner corresponding to the tree we rebuilt, collected extents for any |
| 398 | * blocks with the same rmap owner that are owned by another data structure |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 399 | * (sublist), and subtracted sublist from bitmap. In theory the extents |
| 400 | * remaining in bitmap are the old btree's blocks. |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 401 | * |
| 402 | * Unfortunately, it's possible that the btree was crosslinked with other |
| 403 | * blocks on disk. The rmap data can tell us if there are multiple owners, so |
| 404 | * if the rmapbt says there is an owner of this block other than @oinfo, then |
| 405 | * the block is crosslinked. Remove the reverse mapping and continue. |
| 406 | * |
| 407 | * If there is one rmap record, we can free the block, which removes the |
| 408 | * reverse mapping but doesn't add the block to the free space. Our repair |
| 409 | * strategy is to hope the other metadata objects crosslinked on this block |
| 410 | * will be rebuilt (atop different blocks), thereby removing all the cross |
| 411 | * links. |
| 412 | * |
| 413 | * If there are no rmap records at all, we also free the block. If the btree |
| 414 | * being rebuilt lives in the free space (bnobt/cntbt/rmapbt) then there isn't |
| 415 | * supposed to be a rmap record and everything is ok. For other btrees there |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 416 | * had to have been an rmap entry for the block to have ended up on @bitmap, |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 417 | * so if it's gone now there's something wrong and the fs will shut down. |
| 418 | * |
| 419 | * Note: If there are multiple rmap records with only the same rmap owner as |
| 420 | * the btree we're trying to rebuild and the block is indeed owned by another |
| 421 | * data structure with the same rmap owner, then the block will be in sublist |
| 422 | * and therefore doesn't need disposal. If there are multiple rmap records |
| 423 | * with only the same rmap owner but the block is not owned by something with |
| 424 | * the same rmap owner, the block will be freed. |
| 425 | * |
| 426 | * The caller is responsible for locking the AG headers for the entire rebuild |
| 427 | * operation so that nothing else can sneak in and change the AG state while |
| 428 | * we're not looking. We also assume that the caller already invalidated any |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 429 | * buffers associated with @bitmap. |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 430 | */ |
| 431 | |
| 432 | /* |
| 433 | * Invalidate buffers for per-AG btree blocks we're dumping. This function |
| 434 | * is not intended for use with file data repairs; we have bunmapi for that. |
| 435 | */ |
| 436 | int |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 437 | xrep_invalidate_blocks( |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 438 | struct xfs_scrub *sc, |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 439 | struct xfs_bitmap *bitmap) |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 440 | { |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 441 | struct xfs_bitmap_range *bmr; |
| 442 | struct xfs_bitmap_range *n; |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 443 | struct xfs_buf *bp; |
| 444 | xfs_fsblock_t fsbno; |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 445 | |
| 446 | /* |
| 447 | * For each block in each extent, see if there's an incore buffer for |
| 448 | * exactly that block; if so, invalidate it. The buffer cache only |
| 449 | * lets us look for one buffer at a time, so we have to look one block |
| 450 | * at a time. Avoid invalidating AG headers and post-EOFS blocks |
| 451 | * because we never own those; and if we can't TRYLOCK the buffer we |
| 452 | * assume it's owned by someone else. |
| 453 | */ |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 454 | for_each_xfs_bitmap_block(fsbno, bmr, n, bitmap) { |
| 455 | /* Skip AG headers and post-EOFS blocks */ |
| 456 | if (!xfs_verify_fsbno(sc->mp, fsbno)) |
| 457 | continue; |
| 458 | bp = xfs_buf_incore(sc->mp->m_ddev_targp, |
| 459 | XFS_FSB_TO_DADDR(sc->mp, fsbno), |
| 460 | XFS_FSB_TO_BB(sc->mp, 1), XBF_TRYLOCK); |
| 461 | if (bp) { |
| 462 | xfs_trans_bjoin(sc->tp, bp); |
| 463 | xfs_trans_binval(sc->tp, bp); |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 464 | } |
| 465 | } |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | /* Ensure the freelist is the correct size. */ |
| 471 | int |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 472 | xrep_fix_freelist( |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 473 | struct xfs_scrub *sc, |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 474 | bool can_shrink) |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 475 | { |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 476 | struct xfs_alloc_arg args = {0}; |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 477 | |
| 478 | args.mp = sc->mp; |
| 479 | args.tp = sc->tp; |
| 480 | args.agno = sc->sa.agno; |
| 481 | args.alignment = 1; |
| 482 | args.pag = sc->sa.pag; |
| 483 | |
| 484 | return xfs_alloc_fix_freelist(&args, |
| 485 | can_shrink ? 0 : XFS_ALLOC_FLAG_NOSHRINK); |
| 486 | } |
| 487 | |
| 488 | /* |
| 489 | * Put a block back on the AGFL. |
| 490 | */ |
| 491 | STATIC int |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 492 | xrep_put_freelist( |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 493 | struct xfs_scrub *sc, |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 494 | xfs_agblock_t agbno) |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 495 | { |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 496 | int error; |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 497 | |
| 498 | /* Make sure there's space on the freelist. */ |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 499 | error = xrep_fix_freelist(sc, true); |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 500 | if (error) |
| 501 | return error; |
| 502 | |
| 503 | /* |
| 504 | * Since we're "freeing" a lost block onto the AGFL, we have to |
| 505 | * create an rmap for the block prior to merging it or else other |
| 506 | * parts will break. |
| 507 | */ |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 508 | error = xfs_rmap_alloc(sc->tp, sc->sa.agf_bp, sc->sa.agno, agbno, 1, |
Darrick J. Wong | 7280fed | 2018-12-12 08:46:23 -0800 | [diff] [blame] | 509 | &XFS_RMAP_OINFO_AG); |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 510 | if (error) |
| 511 | return error; |
| 512 | |
| 513 | /* Put the block on the AGFL. */ |
| 514 | error = xfs_alloc_put_freelist(sc->tp, sc->sa.agf_bp, sc->sa.agfl_bp, |
| 515 | agbno, 0); |
| 516 | if (error) |
| 517 | return error; |
| 518 | xfs_extent_busy_insert(sc->tp, sc->sa.agno, agbno, 1, |
| 519 | XFS_EXTENT_BUSY_SKIP_DISCARD); |
| 520 | |
| 521 | return 0; |
| 522 | } |
| 523 | |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 524 | /* Dispose of a single block. */ |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 525 | STATIC int |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 526 | xrep_reap_block( |
Darrick J. Wong | 66e3237 | 2018-12-12 08:46:23 -0800 | [diff] [blame] | 527 | struct xfs_scrub *sc, |
| 528 | xfs_fsblock_t fsbno, |
| 529 | const struct xfs_owner_info *oinfo, |
| 530 | enum xfs_ag_resv_type resv) |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 531 | { |
Darrick J. Wong | 66e3237 | 2018-12-12 08:46:23 -0800 | [diff] [blame] | 532 | struct xfs_btree_cur *cur; |
| 533 | struct xfs_buf *agf_bp = NULL; |
| 534 | xfs_agnumber_t agno; |
| 535 | xfs_agblock_t agbno; |
| 536 | bool has_other_rmap; |
| 537 | int error; |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 538 | |
| 539 | agno = XFS_FSB_TO_AGNO(sc->mp, fsbno); |
| 540 | agbno = XFS_FSB_TO_AGBNO(sc->mp, fsbno); |
| 541 | |
| 542 | /* |
| 543 | * If we are repairing per-inode metadata, we need to read in the AGF |
| 544 | * buffer. Otherwise, we're repairing a per-AG structure, so reuse |
| 545 | * the AGF buffer that the setup functions already grabbed. |
| 546 | */ |
| 547 | if (sc->ip) { |
| 548 | error = xfs_alloc_read_agf(sc->mp, sc->tp, agno, 0, &agf_bp); |
| 549 | if (error) |
| 550 | return error; |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 551 | } else { |
| 552 | agf_bp = sc->sa.agf_bp; |
| 553 | } |
| 554 | cur = xfs_rmapbt_init_cursor(sc->mp, sc->tp, agf_bp, agno); |
| 555 | |
| 556 | /* Can we find any other rmappings? */ |
| 557 | error = xfs_rmap_has_other_keys(cur, agbno, 1, oinfo, &has_other_rmap); |
Darrick J. Wong | ef97ef2 | 2018-07-19 12:29:10 -0700 | [diff] [blame] | 558 | xfs_btree_del_cursor(cur, error); |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 559 | if (error) |
Darrick J. Wong | ef97ef2 | 2018-07-19 12:29:10 -0700 | [diff] [blame] | 560 | goto out_free; |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 561 | |
| 562 | /* |
| 563 | * If there are other rmappings, this block is cross linked and must |
| 564 | * not be freed. Remove the reverse mapping and move on. Otherwise, |
| 565 | * we were the only owner of the block, so free the extent, which will |
| 566 | * also remove the rmap. |
| 567 | * |
| 568 | * XXX: XFS doesn't support detecting the case where a single block |
| 569 | * metadata structure is crosslinked with a multi-block structure |
| 570 | * because the buffer cache doesn't detect aliasing problems, so we |
| 571 | * can't fix 100% of crosslinking problems (yet). The verifiers will |
| 572 | * blow on writeout, the filesystem will shut down, and the admin gets |
| 573 | * to run xfs_repair. |
| 574 | */ |
| 575 | if (has_other_rmap) |
| 576 | error = xfs_rmap_free(sc->tp, agf_bp, agno, agbno, 1, oinfo); |
| 577 | else if (resv == XFS_AG_RESV_AGFL) |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 578 | error = xrep_put_freelist(sc, agbno); |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 579 | else |
| 580 | error = xfs_free_extent(sc->tp, fsbno, 1, oinfo, resv); |
| 581 | if (agf_bp != sc->sa.agf_bp) |
| 582 | xfs_trans_brelse(sc->tp, agf_bp); |
| 583 | if (error) |
| 584 | return error; |
| 585 | |
| 586 | if (sc->ip) |
| 587 | return xfs_trans_roll_inode(&sc->tp, sc->ip); |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 588 | return xrep_roll_ag_trans(sc); |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 589 | |
Darrick J. Wong | ef97ef2 | 2018-07-19 12:29:10 -0700 | [diff] [blame] | 590 | out_free: |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 591 | if (agf_bp != sc->sa.agf_bp) |
| 592 | xfs_trans_brelse(sc->tp, agf_bp); |
| 593 | return error; |
| 594 | } |
| 595 | |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 596 | /* Dispose of every block of every extent in the bitmap. */ |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 597 | int |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 598 | xrep_reap_extents( |
Darrick J. Wong | 66e3237 | 2018-12-12 08:46:23 -0800 | [diff] [blame] | 599 | struct xfs_scrub *sc, |
| 600 | struct xfs_bitmap *bitmap, |
| 601 | const struct xfs_owner_info *oinfo, |
| 602 | enum xfs_ag_resv_type type) |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 603 | { |
Darrick J. Wong | 66e3237 | 2018-12-12 08:46:23 -0800 | [diff] [blame] | 604 | struct xfs_bitmap_range *bmr; |
| 605 | struct xfs_bitmap_range *n; |
| 606 | xfs_fsblock_t fsbno; |
| 607 | int error = 0; |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 608 | |
| 609 | ASSERT(xfs_sb_version_hasrmapbt(&sc->mp->m_sb)); |
| 610 | |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 611 | for_each_xfs_bitmap_block(fsbno, bmr, n, bitmap) { |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 612 | ASSERT(sc->ip != NULL || |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 613 | XFS_FSB_TO_AGNO(sc->mp, fsbno) == sc->sa.agno); |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 614 | trace_xrep_dispose_btree_extent(sc->mp, |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 615 | XFS_FSB_TO_AGNO(sc->mp, fsbno), |
| 616 | XFS_FSB_TO_AGBNO(sc->mp, fsbno), 1); |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 617 | |
Darrick J. Wong | 86d969b | 2018-07-30 11:18:13 -0700 | [diff] [blame] | 618 | error = xrep_reap_block(sc, fsbno, oinfo, type); |
| 619 | if (error) |
Darrick J. Wong | 37a6547 | 2020-03-16 17:12:34 -0700 | [diff] [blame^] | 620 | break; |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Darrick J. Wong | 12c6510e | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 623 | return error; |
| 624 | } |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 625 | |
| 626 | /* |
| 627 | * Finding per-AG Btree Roots for AGF/AGI Reconstruction |
| 628 | * |
| 629 | * If the AGF or AGI become slightly corrupted, it may be necessary to rebuild |
| 630 | * the AG headers by using the rmap data to rummage through the AG looking for |
| 631 | * btree roots. This is not guaranteed to work if the AG is heavily damaged |
| 632 | * or the rmap data are corrupt. |
| 633 | * |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 634 | * Callers of xrep_find_ag_btree_roots must lock the AGF and AGFL |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 635 | * buffers if the AGF is being rebuilt; or the AGF and AGI buffers if the |
| 636 | * AGI is being rebuilt. It must maintain these locks until it's safe for |
| 637 | * other threads to change the btrees' shapes. The caller provides |
| 638 | * information about the btrees to look for by passing in an array of |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 639 | * xrep_find_ag_btree with the (rmap owner, buf_ops, magic) fields set. |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 640 | * The (root, height) fields will be set on return if anything is found. The |
| 641 | * last element of the array should have a NULL buf_ops to mark the end of the |
| 642 | * array. |
| 643 | * |
| 644 | * For every rmapbt record matching any of the rmap owners in btree_info, |
| 645 | * read each block referenced by the rmap record. If the block is a btree |
| 646 | * block from this filesystem matching any of the magic numbers and has a |
| 647 | * level higher than what we've already seen, remember the block and the |
| 648 | * height of the tree required to have such a block. When the call completes, |
| 649 | * we return the highest block we've found for each btree description; those |
| 650 | * should be the roots. |
| 651 | */ |
| 652 | |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 653 | struct xrep_findroot { |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 654 | struct xfs_scrub *sc; |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 655 | struct xfs_buf *agfl_bp; |
| 656 | struct xfs_agf *agf; |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 657 | struct xrep_find_ag_btree *btree_info; |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 658 | }; |
| 659 | |
| 660 | /* See if our block is in the AGFL. */ |
| 661 | STATIC int |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 662 | xrep_findroot_agfl_walk( |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 663 | struct xfs_mount *mp, |
| 664 | xfs_agblock_t bno, |
| 665 | void *priv) |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 666 | { |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 667 | xfs_agblock_t *agbno = priv; |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 668 | |
Darrick J. Wong | e7ee96d | 2019-08-28 14:37:57 -0700 | [diff] [blame] | 669 | return (*agbno == bno) ? -ECANCELED : 0; |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | /* Does this block match the btree information passed in? */ |
| 673 | STATIC int |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 674 | xrep_findroot_block( |
| 675 | struct xrep_findroot *ri, |
| 676 | struct xrep_find_ag_btree *fab, |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 677 | uint64_t owner, |
| 678 | xfs_agblock_t agbno, |
Darrick J. Wong | 1002ff4 | 2018-10-18 17:20:26 +1100 | [diff] [blame] | 679 | bool *done_with_block) |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 680 | { |
| 681 | struct xfs_mount *mp = ri->sc->mp; |
| 682 | struct xfs_buf *bp; |
| 683 | struct xfs_btree_block *btblock; |
| 684 | xfs_daddr_t daddr; |
Darrick J. Wong | 1002ff4 | 2018-10-18 17:20:26 +1100 | [diff] [blame] | 685 | int block_level; |
Darrick J. Wong | 38b6238 | 2018-10-18 17:20:35 +1100 | [diff] [blame] | 686 | int error = 0; |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 687 | |
| 688 | daddr = XFS_AGB_TO_DADDR(mp, ri->sc->sa.agno, agbno); |
| 689 | |
| 690 | /* |
| 691 | * Blocks in the AGFL have stale contents that might just happen to |
| 692 | * have a matching magic and uuid. We don't want to pull these blocks |
| 693 | * in as part of a tree root, so we have to filter out the AGFL stuff |
| 694 | * here. If the AGFL looks insane we'll just refuse to repair. |
| 695 | */ |
| 696 | if (owner == XFS_RMAP_OWN_AG) { |
| 697 | error = xfs_agfl_walk(mp, ri->agf, ri->agfl_bp, |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 698 | xrep_findroot_agfl_walk, &agbno); |
Darrick J. Wong | e7ee96d | 2019-08-28 14:37:57 -0700 | [diff] [blame] | 699 | if (error == -ECANCELED) |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 700 | return 0; |
| 701 | if (error) |
| 702 | return error; |
| 703 | } |
| 704 | |
Darrick J. Wong | 38b6238 | 2018-10-18 17:20:35 +1100 | [diff] [blame] | 705 | /* |
| 706 | * Read the buffer into memory so that we can see if it's a match for |
| 707 | * our btree type. We have no clue if it is beforehand, and we want to |
| 708 | * avoid xfs_trans_read_buf's behavior of dumping the DONE state (which |
| 709 | * will cause needless disk reads in subsequent calls to this function) |
| 710 | * and logging metadata verifier failures. |
| 711 | * |
| 712 | * Therefore, pass in NULL buffer ops. If the buffer was already in |
| 713 | * memory from some other caller it will already have b_ops assigned. |
| 714 | * If it was in memory from a previous unsuccessful findroot_block |
| 715 | * call, the buffer won't have b_ops but it should be clean and ready |
| 716 | * for us to try to verify if the read call succeeds. The same applies |
| 717 | * if the buffer wasn't in memory at all. |
| 718 | * |
| 719 | * Note: If we never match a btree type with this buffer, it will be |
| 720 | * left in memory with NULL b_ops. This shouldn't be a problem unless |
| 721 | * the buffer gets written. |
| 722 | */ |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 723 | error = xfs_trans_read_buf(mp, ri->sc->tp, mp->m_ddev_targp, daddr, |
| 724 | mp->m_bsize, 0, &bp, NULL); |
| 725 | if (error) |
| 726 | return error; |
| 727 | |
Darrick J. Wong | 38b6238 | 2018-10-18 17:20:35 +1100 | [diff] [blame] | 728 | /* Ensure the block magic matches the btree type we're looking for. */ |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 729 | btblock = XFS_BUF_TO_BLOCK(bp); |
Darrick J. Wong | 9228d75 | 2019-02-06 10:20:54 -0800 | [diff] [blame] | 730 | ASSERT(fab->buf_ops->magic[1] != 0); |
| 731 | if (btblock->bb_magic != fab->buf_ops->magic[1]) |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 732 | goto out; |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 733 | |
Darrick J. Wong | 38b6238 | 2018-10-18 17:20:35 +1100 | [diff] [blame] | 734 | /* |
| 735 | * If the buffer already has ops applied and they're not the ones for |
| 736 | * this btree type, we know this block doesn't match the btree and we |
| 737 | * can bail out. |
| 738 | * |
| 739 | * If the buffer ops match ours, someone else has already validated |
| 740 | * the block for us, so we can move on to checking if this is a root |
| 741 | * block candidate. |
| 742 | * |
| 743 | * If the buffer does not have ops, nobody has successfully validated |
| 744 | * the contents and the buffer cannot be dirty. If the magic, uuid, |
| 745 | * and structure match this btree type then we'll move on to checking |
| 746 | * if it's a root block candidate. If there is no match, bail out. |
| 747 | */ |
| 748 | if (bp->b_ops) { |
| 749 | if (bp->b_ops != fab->buf_ops) |
| 750 | goto out; |
| 751 | } else { |
| 752 | ASSERT(!xfs_trans_buf_is_dirty(bp)); |
| 753 | if (!uuid_equal(&btblock->bb_u.s.bb_uuid, |
| 754 | &mp->m_sb.sb_meta_uuid)) |
| 755 | goto out; |
Darrick J. Wong | add46b3 | 2019-02-03 14:03:59 -0800 | [diff] [blame] | 756 | /* |
| 757 | * Read verifiers can reference b_ops, so we set the pointer |
| 758 | * here. If the verifier fails we'll reset the buffer state |
| 759 | * to what it was before we touched the buffer. |
| 760 | */ |
| 761 | bp->b_ops = fab->buf_ops; |
Darrick J. Wong | 38b6238 | 2018-10-18 17:20:35 +1100 | [diff] [blame] | 762 | fab->buf_ops->verify_read(bp); |
| 763 | if (bp->b_error) { |
Darrick J. Wong | add46b3 | 2019-02-03 14:03:59 -0800 | [diff] [blame] | 764 | bp->b_ops = NULL; |
Darrick J. Wong | 38b6238 | 2018-10-18 17:20:35 +1100 | [diff] [blame] | 765 | bp->b_error = 0; |
| 766 | goto out; |
| 767 | } |
| 768 | |
| 769 | /* |
| 770 | * Some read verifiers will (re)set b_ops, so we must be |
Darrick J. Wong | add46b3 | 2019-02-03 14:03:59 -0800 | [diff] [blame] | 771 | * careful not to change b_ops after running the verifier. |
Darrick J. Wong | 38b6238 | 2018-10-18 17:20:35 +1100 | [diff] [blame] | 772 | */ |
Darrick J. Wong | 38b6238 | 2018-10-18 17:20:35 +1100 | [diff] [blame] | 773 | } |
Darrick J. Wong | 1002ff4 | 2018-10-18 17:20:26 +1100 | [diff] [blame] | 774 | |
| 775 | /* |
| 776 | * This block passes the magic/uuid and verifier tests for this btree |
| 777 | * type. We don't need the caller to try the other tree types. |
| 778 | */ |
| 779 | *done_with_block = true; |
| 780 | |
| 781 | /* |
| 782 | * Compare this btree block's level to the height of the current |
| 783 | * candidate root block. |
| 784 | * |
| 785 | * If the level matches the root we found previously, throw away both |
| 786 | * blocks because there can't be two candidate roots. |
| 787 | * |
| 788 | * If level is lower in the tree than the root we found previously, |
| 789 | * ignore this block. |
| 790 | */ |
| 791 | block_level = xfs_btree_get_level(btblock); |
| 792 | if (block_level + 1 == fab->height) { |
| 793 | fab->root = NULLAGBLOCK; |
| 794 | goto out; |
| 795 | } else if (block_level < fab->height) { |
| 796 | goto out; |
| 797 | } |
| 798 | |
| 799 | /* |
| 800 | * This is the highest block in the tree that we've found so far. |
| 801 | * Update the btree height to reflect what we've learned from this |
| 802 | * block. |
| 803 | */ |
| 804 | fab->height = block_level + 1; |
| 805 | |
| 806 | /* |
| 807 | * If this block doesn't have sibling pointers, then it's the new root |
| 808 | * block candidate. Otherwise, the root will be found farther up the |
| 809 | * tree. |
| 810 | */ |
| 811 | if (btblock->bb_u.s.bb_leftsib == cpu_to_be32(NULLAGBLOCK) && |
| 812 | btblock->bb_u.s.bb_rightsib == cpu_to_be32(NULLAGBLOCK)) |
| 813 | fab->root = agbno; |
| 814 | else |
| 815 | fab->root = NULLAGBLOCK; |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 816 | |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 817 | trace_xrep_findroot_block(mp, ri->sc->sa.agno, agbno, |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 818 | be32_to_cpu(btblock->bb_magic), fab->height - 1); |
| 819 | out: |
| 820 | xfs_trans_brelse(ri->sc->tp, bp); |
| 821 | return error; |
| 822 | } |
| 823 | |
| 824 | /* |
| 825 | * Do any of the blocks in this rmap record match one of the btrees we're |
| 826 | * looking for? |
| 827 | */ |
| 828 | STATIC int |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 829 | xrep_findroot_rmap( |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 830 | struct xfs_btree_cur *cur, |
| 831 | struct xfs_rmap_irec *rec, |
| 832 | void *priv) |
| 833 | { |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 834 | struct xrep_findroot *ri = priv; |
| 835 | struct xrep_find_ag_btree *fab; |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 836 | xfs_agblock_t b; |
Darrick J. Wong | 1002ff4 | 2018-10-18 17:20:26 +1100 | [diff] [blame] | 837 | bool done; |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 838 | int error = 0; |
| 839 | |
| 840 | /* Ignore anything that isn't AG metadata. */ |
| 841 | if (!XFS_RMAP_NON_INODE_OWNER(rec->rm_owner)) |
| 842 | return 0; |
| 843 | |
| 844 | /* Otherwise scan each block + btree type. */ |
| 845 | for (b = 0; b < rec->rm_blockcount; b++) { |
Darrick J. Wong | 1002ff4 | 2018-10-18 17:20:26 +1100 | [diff] [blame] | 846 | done = false; |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 847 | for (fab = ri->btree_info; fab->buf_ops; fab++) { |
| 848 | if (rec->rm_owner != fab->rmap_owner) |
| 849 | continue; |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 850 | error = xrep_findroot_block(ri, fab, |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 851 | rec->rm_owner, rec->rm_startblock + b, |
Darrick J. Wong | 1002ff4 | 2018-10-18 17:20:26 +1100 | [diff] [blame] | 852 | &done); |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 853 | if (error) |
| 854 | return error; |
Darrick J. Wong | 1002ff4 | 2018-10-18 17:20:26 +1100 | [diff] [blame] | 855 | if (done) |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 856 | break; |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | return 0; |
| 861 | } |
| 862 | |
| 863 | /* Find the roots of the per-AG btrees described in btree_info. */ |
| 864 | int |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 865 | xrep_find_ag_btree_roots( |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 866 | struct xfs_scrub *sc, |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 867 | struct xfs_buf *agf_bp, |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 868 | struct xrep_find_ag_btree *btree_info, |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 869 | struct xfs_buf *agfl_bp) |
| 870 | { |
| 871 | struct xfs_mount *mp = sc->mp; |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 872 | struct xrep_findroot ri; |
| 873 | struct xrep_find_ag_btree *fab; |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 874 | struct xfs_btree_cur *cur; |
| 875 | int error; |
| 876 | |
| 877 | ASSERT(xfs_buf_islocked(agf_bp)); |
| 878 | ASSERT(agfl_bp == NULL || xfs_buf_islocked(agfl_bp)); |
| 879 | |
| 880 | ri.sc = sc; |
| 881 | ri.btree_info = btree_info; |
Christoph Hellwig | 9798f61 | 2020-03-10 08:57:29 -0700 | [diff] [blame] | 882 | ri.agf = agf_bp->b_addr; |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 883 | ri.agfl_bp = agfl_bp; |
| 884 | for (fab = btree_info; fab->buf_ops; fab++) { |
| 885 | ASSERT(agfl_bp || fab->rmap_owner != XFS_RMAP_OWN_AG); |
| 886 | ASSERT(XFS_RMAP_NON_INODE_OWNER(fab->rmap_owner)); |
| 887 | fab->root = NULLAGBLOCK; |
| 888 | fab->height = 0; |
| 889 | } |
| 890 | |
| 891 | cur = xfs_rmapbt_init_cursor(mp, sc->tp, agf_bp, sc->sa.agno); |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 892 | error = xfs_rmap_query_all(cur, xrep_findroot_rmap, &ri); |
Darrick J. Wong | 0b04b6b8 | 2018-07-19 12:26:31 -0700 | [diff] [blame] | 893 | xfs_btree_del_cursor(cur, error); |
Darrick J. Wong | 04a2b7b | 2018-05-29 22:18:10 -0700 | [diff] [blame] | 894 | |
| 895 | return error; |
| 896 | } |
Darrick J. Wong | 7e85bc6 | 2018-05-29 22:18:11 -0700 | [diff] [blame] | 897 | |
| 898 | /* Force a quotacheck the next time we mount. */ |
| 899 | void |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 900 | xrep_force_quotacheck( |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 901 | struct xfs_scrub *sc, |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 902 | uint dqtype) |
Darrick J. Wong | 7e85bc6 | 2018-05-29 22:18:11 -0700 | [diff] [blame] | 903 | { |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 904 | uint flag; |
Darrick J. Wong | 7e85bc6 | 2018-05-29 22:18:11 -0700 | [diff] [blame] | 905 | |
| 906 | flag = xfs_quota_chkd_flag(dqtype); |
| 907 | if (!(flag & sc->mp->m_qflags)) |
| 908 | return; |
| 909 | |
| 910 | sc->mp->m_qflags &= ~flag; |
| 911 | spin_lock(&sc->mp->m_sb_lock); |
| 912 | sc->mp->m_sb.sb_qflags &= ~flag; |
| 913 | spin_unlock(&sc->mp->m_sb_lock); |
| 914 | xfs_log_sb(sc->tp); |
| 915 | } |
| 916 | |
| 917 | /* |
| 918 | * Attach dquots to this inode, or schedule quotacheck to fix them. |
| 919 | * |
| 920 | * This function ensures that the appropriate dquots are attached to an inode. |
| 921 | * We cannot allow the dquot code to allocate an on-disk dquot block here |
| 922 | * because we're already in transaction context with the inode locked. The |
| 923 | * on-disk dquot should already exist anyway. If the quota code signals |
| 924 | * corruption or missing quota information, schedule quotacheck, which will |
| 925 | * repair corruptions in the quota metadata. |
| 926 | */ |
| 927 | int |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 928 | xrep_ino_dqattach( |
Darrick J. Wong | 1d8a748 | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 929 | struct xfs_scrub *sc) |
Darrick J. Wong | 7e85bc6 | 2018-05-29 22:18:11 -0700 | [diff] [blame] | 930 | { |
Darrick J. Wong | 032d91f | 2018-07-19 12:29:12 -0700 | [diff] [blame] | 931 | int error; |
Darrick J. Wong | 7e85bc6 | 2018-05-29 22:18:11 -0700 | [diff] [blame] | 932 | |
| 933 | error = xfs_qm_dqattach_locked(sc->ip, false); |
| 934 | switch (error) { |
| 935 | case -EFSBADCRC: |
| 936 | case -EFSCORRUPTED: |
| 937 | case -ENOENT: |
| 938 | xfs_err_ratelimited(sc->mp, |
| 939 | "inode %llu repair encountered quota error %d, quotacheck forced.", |
| 940 | (unsigned long long)sc->ip->i_ino, error); |
| 941 | if (XFS_IS_UQUOTA_ON(sc->mp) && !sc->ip->i_udquot) |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 942 | xrep_force_quotacheck(sc, XFS_DQ_USER); |
Darrick J. Wong | 7e85bc6 | 2018-05-29 22:18:11 -0700 | [diff] [blame] | 943 | if (XFS_IS_GQUOTA_ON(sc->mp) && !sc->ip->i_gdquot) |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 944 | xrep_force_quotacheck(sc, XFS_DQ_GROUP); |
Darrick J. Wong | 7e85bc6 | 2018-05-29 22:18:11 -0700 | [diff] [blame] | 945 | if (XFS_IS_PQUOTA_ON(sc->mp) && !sc->ip->i_pdquot) |
Darrick J. Wong | b5e2196 | 2018-07-19 12:29:11 -0700 | [diff] [blame] | 946 | xrep_force_quotacheck(sc, XFS_DQ_PROJ); |
Darrick J. Wong | 7e85bc6 | 2018-05-29 22:18:11 -0700 | [diff] [blame] | 947 | /* fall through */ |
| 948 | case -ESRCH: |
| 949 | error = 0; |
| 950 | break; |
| 951 | default: |
| 952 | break; |
| 953 | } |
| 954 | |
| 955 | return error; |
| 956 | } |