]>
Commit | Line | Data |
---|---|---|
959ef981 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
b364a9c0 DW |
2 | /* |
3 | * Copyright (C) 2018 Oracle. All Rights Reserved. | |
b364a9c0 | 4 | * Author: Darrick J. Wong <darrick.wong@oracle.com> |
b364a9c0 | 5 | */ |
a440f877 | 6 | #include "xfs.h" |
b364a9c0 | 7 | #include <stdint.h> |
b364a9c0 DW |
8 | #include <dirent.h> |
9 | #include <sys/statvfs.h> | |
b364a9c0 | 10 | #include "handle.h" |
42b4c8e8 | 11 | #include "libfrog/paths.h" |
56598728 | 12 | #include "libfrog/workqueue.h" |
b364a9c0 DW |
13 | #include "xfs_scrub.h" |
14 | #include "common.h" | |
a58400ed | 15 | #include "libfrog/bitmap.h" |
b364a9c0 DW |
16 | #include "disk.h" |
17 | #include "filemap.h" | |
ed60d210 | 18 | #include "fscounters.h" |
b364a9c0 DW |
19 | #include "inodes.h" |
20 | #include "read_verify.h" | |
21 | #include "spacemap.h" | |
22 | #include "vfs.h" | |
23 | ||
24 | /* | |
25 | * Phase 6: Verify data file integrity. | |
26 | * | |
27 | * Identify potential data block extents with GETFSMAP, then feed those | |
28 | * extents to the read-verify pool to get the verify commands batched, | |
29 | * issued, and (if there are problems) reported back to us. If there | |
30 | * are errors, we'll record the bad regions and (if available) use rmap | |
31 | * to tell us if metadata are now corrupt. Otherwise, we'll scan the | |
32 | * whole directory tree looking for files that overlap the bad regions | |
33 | * and report the paths of the now corrupt files. | |
34 | */ | |
35 | ||
f1bb1696 DW |
36 | /* Verify disk blocks with GETFSMAP */ |
37 | ||
557f98d7 | 38 | struct media_verify_state { |
f1bb1696 DW |
39 | struct read_verify_pool *rvp_data; |
40 | struct read_verify_pool *rvp_log; | |
41 | struct read_verify_pool *rvp_realtime; | |
42 | struct bitmap *d_bad; /* bytes */ | |
43 | struct bitmap *r_bad; /* bytes */ | |
44 | }; | |
45 | ||
b364a9c0 | 46 | /* Find the fd for a given device identifier. */ |
f1bb1696 DW |
47 | static struct read_verify_pool * |
48 | xfs_dev_to_pool( | |
49 | struct scrub_ctx *ctx, | |
557f98d7 | 50 | struct media_verify_state *vs, |
f1bb1696 | 51 | dev_t dev) |
b364a9c0 DW |
52 | { |
53 | if (dev == ctx->fsinfo.fs_datadev) | |
557f98d7 | 54 | return vs->rvp_data; |
b364a9c0 | 55 | else if (dev == ctx->fsinfo.fs_logdev) |
557f98d7 | 56 | return vs->rvp_log; |
b364a9c0 | 57 | else if (dev == ctx->fsinfo.fs_rtdev) |
557f98d7 | 58 | return vs->rvp_realtime; |
b364a9c0 DW |
59 | abort(); |
60 | } | |
61 | ||
62 | /* Find the device major/minor for a given file descriptor. */ | |
63 | static dev_t | |
64 | xfs_disk_to_dev( | |
65 | struct scrub_ctx *ctx, | |
66 | struct disk *disk) | |
67 | { | |
68 | if (disk == ctx->datadev) | |
69 | return ctx->fsinfo.fs_datadev; | |
70 | else if (disk == ctx->logdev) | |
71 | return ctx->fsinfo.fs_logdev; | |
72 | else if (disk == ctx->rtdev) | |
73 | return ctx->fsinfo.fs_rtdev; | |
74 | abort(); | |
75 | } | |
76 | ||
77 | struct owner_decode { | |
78 | uint64_t owner; | |
79 | const char *descr; | |
80 | }; | |
81 | ||
82 | static const struct owner_decode special_owners[] = { | |
83 | {XFS_FMR_OWN_FREE, "free space"}, | |
84 | {XFS_FMR_OWN_UNKNOWN, "unknown owner"}, | |
85 | {XFS_FMR_OWN_FS, "static FS metadata"}, | |
86 | {XFS_FMR_OWN_LOG, "journalling log"}, | |
87 | {XFS_FMR_OWN_AG, "per-AG metadata"}, | |
88 | {XFS_FMR_OWN_INOBT, "inode btree blocks"}, | |
89 | {XFS_FMR_OWN_INODES, "inodes"}, | |
90 | {XFS_FMR_OWN_REFC, "refcount btree"}, | |
91 | {XFS_FMR_OWN_COW, "CoW staging"}, | |
92 | {XFS_FMR_OWN_DEFECTIVE, "bad blocks"}, | |
93 | {0, NULL}, | |
94 | }; | |
95 | ||
96 | /* Decode a special owner. */ | |
97 | static const char * | |
98 | xfs_decode_special_owner( | |
99 | uint64_t owner) | |
100 | { | |
101 | const struct owner_decode *od = special_owners; | |
102 | ||
103 | while (od->descr) { | |
104 | if (od->owner == owner) | |
105 | return od->descr; | |
106 | od++; | |
107 | } | |
108 | ||
109 | return NULL; | |
110 | } | |
111 | ||
112 | /* Routines to translate bad physical extents into file paths and offsets. */ | |
113 | ||
ed953d26 DW |
114 | struct badfile_report { |
115 | struct scrub_ctx *ctx; | |
116 | const char *descr; | |
117 | struct xfs_bmap *bmap; | |
118 | }; | |
119 | ||
120 | /* Report on bad extents found during a media scan. */ | |
121 | static int | |
122 | report_badfile( | |
123 | uint64_t start, | |
124 | uint64_t length, | |
125 | void *arg) | |
126 | { | |
127 | struct badfile_report *br = arg; | |
128 | unsigned long long bad_offset; | |
129 | unsigned long long bad_length; | |
130 | ||
131 | /* Clamp the bad region to the file mapping. */ | |
132 | if (start < br->bmap->bm_physical) { | |
133 | length -= br->bmap->bm_physical - start; | |
134 | start = br->bmap->bm_physical; | |
135 | } | |
136 | length = min(length, br->bmap->bm_length); | |
137 | ||
138 | /* Figure out how far into the bmap is the bad mapping and report it. */ | |
139 | bad_offset = start - br->bmap->bm_physical; | |
140 | bad_length = min(start + length, | |
141 | br->bmap->bm_physical + br->bmap->bm_length) - start; | |
142 | ||
143 | str_error(br->ctx, br->descr, | |
144 | _("media error at data offset %llu length %llu."), | |
145 | br->bmap->bm_offset + bad_offset, bad_length); | |
146 | return 0; | |
147 | } | |
148 | ||
b364a9c0 DW |
149 | /* Report if this extent overlaps a bad region. */ |
150 | static bool | |
663e02a0 | 151 | report_data_loss( |
b364a9c0 DW |
152 | struct scrub_ctx *ctx, |
153 | const char *descr, | |
154 | int fd, | |
155 | int whichfork, | |
156 | struct fsxattr *fsx, | |
157 | struct xfs_bmap *bmap, | |
158 | void *arg) | |
159 | { | |
ed953d26 DW |
160 | struct badfile_report br = { |
161 | .ctx = ctx, | |
162 | .descr = descr, | |
163 | .bmap = bmap, | |
164 | }; | |
ed5f9cc7 | 165 | struct media_verify_state *vs = arg; |
b364a9c0 | 166 | struct bitmap *bmp; |
ed953d26 | 167 | int ret; |
b364a9c0 DW |
168 | |
169 | /* Only report errors for real extents. */ | |
170 | if (bmap->bm_flags & (BMV_OF_PREALLOC | BMV_OF_DELALLOC)) | |
171 | return true; | |
172 | ||
173 | if (fsx->fsx_xflags & FS_XFLAG_REALTIME) | |
ed5f9cc7 | 174 | bmp = vs->r_bad; |
b364a9c0 | 175 | else |
ed5f9cc7 | 176 | bmp = vs->d_bad; |
b364a9c0 | 177 | |
ed953d26 DW |
178 | ret = bitmap_iterate_range(bmp, bmap->bm_physical, bmap->bm_length, |
179 | report_badfile, &br); | |
180 | if (ret) { | |
181 | str_liberror(ctx, ret, descr); | |
182 | return false; | |
183 | } | |
b364a9c0 DW |
184 | return true; |
185 | } | |
186 | ||
663e02a0 DW |
187 | /* Report if the extended attribute data overlaps a bad region. */ |
188 | static bool | |
189 | report_attr_loss( | |
190 | struct scrub_ctx *ctx, | |
191 | const char *descr, | |
192 | int fd, | |
193 | int whichfork, | |
194 | struct fsxattr *fsx, | |
195 | struct xfs_bmap *bmap, | |
196 | void *arg) | |
197 | { | |
198 | struct media_verify_state *vs = arg; | |
199 | struct bitmap *bmp = vs->d_bad; | |
200 | ||
201 | /* Complain about attr fork extents that don't look right. */ | |
202 | if (bmap->bm_flags & (BMV_OF_PREALLOC | BMV_OF_DELALLOC)) { | |
203 | str_info(ctx, descr, | |
204 | _("found unexpected unwritten/delalloc attr fork extent.")); | |
205 | return true; | |
206 | } | |
207 | ||
208 | if (fsx->fsx_xflags & FS_XFLAG_REALTIME) { | |
209 | str_info(ctx, descr, | |
210 | _("found unexpected realtime attr fork extent.")); | |
211 | return true; | |
212 | } | |
213 | ||
214 | if (bitmap_test(bmp, bmap->bm_physical, bmap->bm_length)) | |
215 | str_error(ctx, descr, | |
216 | _("media error in extended attribute data.")); | |
217 | ||
218 | return true; | |
219 | } | |
220 | ||
b364a9c0 DW |
221 | /* Iterate the extent mappings of a file to report errors. */ |
222 | static bool | |
223 | xfs_report_verify_fd( | |
224 | struct scrub_ctx *ctx, | |
225 | const char *descr, | |
226 | int fd, | |
227 | void *arg) | |
228 | { | |
229 | struct xfs_bmap key = {0}; | |
230 | bool moveon; | |
231 | ||
232 | /* data fork */ | |
233 | moveon = xfs_iterate_filemaps(ctx, descr, fd, XFS_DATA_FORK, &key, | |
663e02a0 | 234 | report_data_loss, arg); |
b364a9c0 DW |
235 | if (!moveon) |
236 | return false; | |
237 | ||
238 | /* attr fork */ | |
663e02a0 DW |
239 | return xfs_iterate_filemaps(ctx, descr, fd, XFS_ATTR_FORK, &key, |
240 | report_attr_loss, arg); | |
b364a9c0 DW |
241 | } |
242 | ||
243 | /* Report read verify errors in unlinked (but still open) files. */ | |
244 | static int | |
245 | xfs_report_verify_inode( | |
246 | struct scrub_ctx *ctx, | |
247 | struct xfs_handle *handle, | |
4cca629d | 248 | struct xfs_bulkstat *bstat, |
b364a9c0 DW |
249 | void *arg) |
250 | { | |
251 | char descr[DESCR_BUFSZ]; | |
b364a9c0 DW |
252 | bool moveon; |
253 | int fd; | |
254 | int error; | |
255 | ||
b364a9c0 DW |
256 | /* Ignore linked files and things we can't open. */ |
257 | if (bstat->bs_nlink != 0) | |
258 | return 0; | |
259 | if (!S_ISREG(bstat->bs_mode) && !S_ISDIR(bstat->bs_mode)) | |
260 | return 0; | |
261 | ||
15589f0a DW |
262 | scrub_render_ino_descr(ctx, descr, DESCR_BUFSZ, |
263 | bstat->bs_ino, bstat->bs_gen, _("(unlinked)")); | |
264 | ||
b364a9c0 DW |
265 | /* Try to open the inode. */ |
266 | fd = xfs_open_handle(handle); | |
267 | if (fd < 0) { | |
268 | error = errno; | |
269 | if (error == ESTALE) | |
270 | return error; | |
271 | ||
bb5dbd06 DW |
272 | str_info(ctx, descr, |
273 | _("Disappeared during read error reporting.")); | |
b364a9c0 DW |
274 | return error; |
275 | } | |
276 | ||
277 | /* Go find the badness. */ | |
278 | moveon = xfs_report_verify_fd(ctx, descr, fd, arg); | |
6c05cc5d DW |
279 | error = close(fd); |
280 | if (error) | |
281 | str_errno(ctx, descr); | |
b364a9c0 DW |
282 | |
283 | return moveon ? 0 : XFS_ITERATE_INODES_ABORT; | |
284 | } | |
285 | ||
286 | /* Scan a directory for matches in the read verify error list. */ | |
287 | static bool | |
288 | xfs_report_verify_dir( | |
289 | struct scrub_ctx *ctx, | |
290 | const char *path, | |
291 | int dir_fd, | |
292 | void *arg) | |
293 | { | |
294 | return xfs_report_verify_fd(ctx, path, dir_fd, arg); | |
295 | } | |
296 | ||
297 | /* | |
298 | * Scan the inode associated with a directory entry for matches with | |
299 | * the read verify error list. | |
300 | */ | |
301 | static bool | |
302 | xfs_report_verify_dirent( | |
303 | struct scrub_ctx *ctx, | |
304 | const char *path, | |
305 | int dir_fd, | |
306 | struct dirent *dirent, | |
307 | struct stat *sb, | |
308 | void *arg) | |
309 | { | |
310 | bool moveon; | |
311 | int fd; | |
6c05cc5d | 312 | int error; |
b364a9c0 DW |
313 | |
314 | /* Ignore things we can't open. */ | |
315 | if (!S_ISREG(sb->st_mode) && !S_ISDIR(sb->st_mode)) | |
316 | return true; | |
317 | ||
318 | /* Ignore . and .. */ | |
319 | if (!strcmp(".", dirent->d_name) || !strcmp("..", dirent->d_name)) | |
320 | return true; | |
321 | ||
322 | /* | |
323 | * If we were given a dirent, open the associated file under | |
324 | * dir_fd for badblocks scanning. If dirent is NULL, then it's | |
325 | * the directory itself we want to scan. | |
326 | */ | |
327 | fd = openat(dir_fd, dirent->d_name, | |
328 | O_RDONLY | O_NOATIME | O_NOFOLLOW | O_NOCTTY); | |
329 | if (fd < 0) | |
330 | return true; | |
331 | ||
332 | /* Go find the badness. */ | |
333 | moveon = xfs_report_verify_fd(ctx, path, fd, arg); | |
334 | if (moveon) | |
335 | goto out; | |
336 | ||
337 | out: | |
6c05cc5d DW |
338 | error = close(fd); |
339 | if (error) | |
340 | str_errno(ctx, path); | |
b364a9c0 DW |
341 | return moveon; |
342 | } | |
343 | ||
344 | /* Given bad extent lists for the data & rtdev, find bad files. */ | |
345 | static bool | |
346 | xfs_report_verify_errors( | |
347 | struct scrub_ctx *ctx, | |
ed5f9cc7 | 348 | struct media_verify_state *vs) |
b364a9c0 | 349 | { |
b364a9c0 DW |
350 | bool moveon; |
351 | ||
b364a9c0 DW |
352 | /* Scan the directory tree to get file paths. */ |
353 | moveon = scan_fs_tree(ctx, xfs_report_verify_dir, | |
ed5f9cc7 | 354 | xfs_report_verify_dirent, vs); |
b364a9c0 DW |
355 | if (!moveon) |
356 | return false; | |
357 | ||
358 | /* Scan for unlinked files. */ | |
ed5f9cc7 | 359 | return xfs_scan_all_inodes(ctx, xfs_report_verify_inode, vs); |
b364a9c0 DW |
360 | } |
361 | ||
b364a9c0 DW |
362 | /* Report an IO error resulting from read-verify based off getfsmap. */ |
363 | static bool | |
364 | xfs_check_rmap_error_report( | |
365 | struct scrub_ctx *ctx, | |
366 | const char *descr, | |
367 | struct fsmap *map, | |
368 | void *arg) | |
369 | { | |
370 | const char *type; | |
371 | char buf[32]; | |
372 | uint64_t err_physical = *(uint64_t *)arg; | |
373 | uint64_t err_off; | |
374 | ||
375 | if (err_physical > map->fmr_physical) | |
376 | err_off = err_physical - map->fmr_physical; | |
377 | else | |
378 | err_off = 0; | |
379 | ||
380 | snprintf(buf, 32, _("disk offset %"PRIu64), | |
381 | (uint64_t)BTOBB(map->fmr_physical + err_off)); | |
382 | ||
383 | if (map->fmr_flags & FMR_OF_SPECIAL_OWNER) { | |
384 | type = xfs_decode_special_owner(map->fmr_owner); | |
385 | str_error(ctx, buf, | |
386 | _("%s failed read verification."), | |
387 | type); | |
388 | } | |
389 | ||
390 | /* | |
391 | * XXX: If we had a getparent() call we could report IO errors | |
392 | * efficiently. Until then, we'll have to scan the dir tree | |
393 | * to find the bad file's pathname. | |
394 | */ | |
395 | ||
396 | return true; | |
397 | } | |
398 | ||
399 | /* | |
400 | * Remember a read error for later, and see if rmap will tell us about the | |
401 | * owner ahead of time. | |
402 | */ | |
403 | static void | |
404 | xfs_check_rmap_ioerr( | |
405 | struct scrub_ctx *ctx, | |
406 | struct disk *disk, | |
407 | uint64_t start, | |
408 | uint64_t length, | |
409 | int error, | |
410 | void *arg) | |
411 | { | |
412 | struct fsmap keys[2]; | |
413 | char descr[DESCR_BUFSZ]; | |
557f98d7 | 414 | struct media_verify_state *vs = arg; |
b364a9c0 DW |
415 | struct bitmap *tree; |
416 | dev_t dev; | |
233fabee | 417 | int ret; |
b364a9c0 DW |
418 | |
419 | dev = xfs_disk_to_dev(ctx, disk); | |
420 | ||
421 | /* | |
422 | * If we don't have parent pointers, save the bad extent for | |
423 | * later rescanning. | |
424 | */ | |
425 | if (dev == ctx->fsinfo.fs_datadev) | |
557f98d7 | 426 | tree = vs->d_bad; |
b364a9c0 | 427 | else if (dev == ctx->fsinfo.fs_rtdev) |
557f98d7 | 428 | tree = vs->r_bad; |
b364a9c0 DW |
429 | else |
430 | tree = NULL; | |
431 | if (tree) { | |
233fabee DW |
432 | ret = bitmap_set(tree, start, length); |
433 | if (ret) | |
434 | str_liberror(ctx, ret, _("setting bad block bitmap")); | |
b364a9c0 DW |
435 | } |
436 | ||
437 | snprintf(descr, DESCR_BUFSZ, _("dev %d:%d ioerr @ %"PRIu64":%"PRIu64" "), | |
438 | major(dev), minor(dev), start, length); | |
439 | ||
440 | /* Go figure out which blocks are bad from the fsmap. */ | |
441 | memset(keys, 0, sizeof(struct fsmap) * 2); | |
442 | keys->fmr_device = dev; | |
443 | keys->fmr_physical = start; | |
444 | (keys + 1)->fmr_device = dev; | |
445 | (keys + 1)->fmr_physical = start + length - 1; | |
446 | (keys + 1)->fmr_owner = ULLONG_MAX; | |
447 | (keys + 1)->fmr_offset = ULLONG_MAX; | |
448 | (keys + 1)->fmr_flags = UINT_MAX; | |
449 | xfs_iterate_fsmap(ctx, descr, keys, xfs_check_rmap_error_report, | |
450 | &start); | |
451 | } | |
452 | ||
453 | /* Schedule a read-verify of a (data block) extent. */ | |
454 | static bool | |
455 | xfs_check_rmap( | |
456 | struct scrub_ctx *ctx, | |
457 | const char *descr, | |
458 | struct fsmap *map, | |
459 | void *arg) | |
460 | { | |
557f98d7 | 461 | struct media_verify_state *vs = arg; |
f1bb1696 | 462 | struct read_verify_pool *rvp; |
8cab77d3 | 463 | int ret; |
f1bb1696 | 464 | |
557f98d7 | 465 | rvp = xfs_dev_to_pool(ctx, vs, map->fmr_device); |
b364a9c0 DW |
466 | |
467 | dbg_printf("rmap dev %d:%d phys %"PRIu64" owner %"PRId64 | |
468 | " offset %"PRIu64" len %"PRIu64" flags 0x%x\n", | |
469 | major(map->fmr_device), minor(map->fmr_device), | |
470 | (uint64_t)map->fmr_physical, (int64_t)map->fmr_owner, | |
471 | (uint64_t)map->fmr_offset, (uint64_t)map->fmr_length, | |
472 | map->fmr_flags); | |
473 | ||
474 | /* "Unknown" extents should be verified; they could be data. */ | |
475 | if ((map->fmr_flags & FMR_OF_SPECIAL_OWNER) && | |
476 | map->fmr_owner == XFS_FMR_OWN_UNKNOWN) | |
477 | map->fmr_flags &= ~FMR_OF_SPECIAL_OWNER; | |
478 | ||
479 | /* | |
480 | * We only care about read-verifying data extents that have been | |
481 | * written to disk. This means we can skip "special" owners | |
482 | * (metadata), xattr blocks, unwritten extents, and extent maps. | |
483 | * These should all get checked elsewhere in the scrubber. | |
484 | */ | |
485 | if (map->fmr_flags & (FMR_OF_PREALLOC | FMR_OF_ATTR_FORK | | |
486 | FMR_OF_EXTENT_MAP | FMR_OF_SPECIAL_OWNER)) | |
22d658ec | 487 | return true; |
b364a9c0 DW |
488 | |
489 | /* XXX: Filter out directory data blocks. */ | |
490 | ||
491 | /* Schedule the read verify command for (eventual) running. */ | |
8cab77d3 DW |
492 | ret = read_verify_schedule_io(rvp, map->fmr_physical, map->fmr_length, |
493 | vs); | |
494 | if (ret) { | |
495 | str_liberror(ctx, ret, descr); | |
496 | return false; | |
497 | } | |
b364a9c0 | 498 | |
b364a9c0 DW |
499 | return true; |
500 | } | |
501 | ||
f1bb1696 | 502 | /* Wait for read/verify actions to finish, then return # bytes checked. */ |
8cab77d3 | 503 | static int |
f1bb1696 | 504 | clean_pool( |
8cab77d3 DW |
505 | struct read_verify_pool *rvp, |
506 | unsigned long long *bytes_checked) | |
f1bb1696 | 507 | { |
8cab77d3 DW |
508 | uint64_t pool_checked; |
509 | int ret; | |
f1bb1696 DW |
510 | |
511 | if (!rvp) | |
512 | return 0; | |
513 | ||
22d658ec DW |
514 | ret = read_verify_force_io(rvp); |
515 | if (ret) | |
516 | return ret; | |
517 | ||
8cab77d3 DW |
518 | ret = read_verify_pool_flush(rvp); |
519 | if (ret) | |
520 | goto out_destroy; | |
521 | ||
522 | ret = read_verify_bytes(rvp, &pool_checked); | |
523 | if (ret) | |
524 | goto out_destroy; | |
525 | ||
526 | *bytes_checked += pool_checked; | |
527 | out_destroy: | |
f1bb1696 DW |
528 | read_verify_pool_destroy(rvp); |
529 | return ret; | |
530 | } | |
531 | ||
b364a9c0 DW |
532 | /* |
533 | * Read verify all the file data blocks in a filesystem. Since XFS doesn't | |
534 | * do data checksums, we trust that the underlying storage will pass back | |
535 | * an IO error if it can't retrieve whatever we previously stored there. | |
536 | * If we hit an IO error, we'll record the bad blocks in a bitmap and then | |
537 | * scan the extent maps of the entire fs tree to figure (and the unlinked | |
538 | * inodes) out which files are now broken. | |
539 | */ | |
540 | bool | |
541 | xfs_scan_blocks( | |
542 | struct scrub_ctx *ctx) | |
543 | { | |
557f98d7 | 544 | struct media_verify_state vs = { NULL }; |
93ab49dd | 545 | bool moveon = false; |
233fabee | 546 | int ret; |
b364a9c0 | 547 | |
233fabee DW |
548 | ret = bitmap_alloc(&vs.d_bad); |
549 | if (ret) { | |
550 | str_liberror(ctx, ret, _("creating datadev badblock bitmap")); | |
41c08606 | 551 | goto out; |
b364a9c0 DW |
552 | } |
553 | ||
233fabee DW |
554 | ret = bitmap_alloc(&vs.r_bad); |
555 | if (ret) { | |
556 | str_liberror(ctx, ret, _("creating realtime badblock bitmap")); | |
b364a9c0 DW |
557 | goto out_dbad; |
558 | } | |
559 | ||
8cab77d3 | 560 | ret = read_verify_pool_alloc(ctx, ctx->datadev, |
3f9efb2e | 561 | ctx->mnt.fsgeom.blocksize, xfs_check_rmap_ioerr, |
8cab77d3 DW |
562 | scrub_nproc(ctx), &vs.rvp_data); |
563 | if (ret) { | |
564 | str_liberror(ctx, ret, _("creating datadev media verifier")); | |
b364a9c0 DW |
565 | goto out_rbad; |
566 | } | |
f1bb1696 | 567 | if (ctx->logdev) { |
8cab77d3 | 568 | ret = read_verify_pool_alloc(ctx, ctx->logdev, |
3f9efb2e | 569 | ctx->mnt.fsgeom.blocksize, xfs_check_rmap_ioerr, |
8cab77d3 DW |
570 | scrub_nproc(ctx), &vs.rvp_log); |
571 | if (ret) { | |
572 | str_liberror(ctx, ret, | |
573 | _("creating logdev media verifier")); | |
f1bb1696 DW |
574 | goto out_datapool; |
575 | } | |
576 | } | |
577 | if (ctx->rtdev) { | |
8cab77d3 | 578 | ret = read_verify_pool_alloc(ctx, ctx->rtdev, |
3f9efb2e | 579 | ctx->mnt.fsgeom.blocksize, xfs_check_rmap_ioerr, |
8cab77d3 DW |
580 | scrub_nproc(ctx), &vs.rvp_realtime); |
581 | if (ret) { | |
582 | str_liberror(ctx, ret, | |
583 | _("creating rtdev media verifier")); | |
f1bb1696 DW |
584 | goto out_logpool; |
585 | } | |
586 | } | |
557f98d7 | 587 | moveon = xfs_scan_all_spacemaps(ctx, xfs_check_rmap, &vs); |
b364a9c0 | 588 | if (!moveon) |
f1bb1696 | 589 | goto out_rtpool; |
8cab77d3 DW |
590 | |
591 | ret = clean_pool(vs.rvp_data, &ctx->bytes_checked); | |
592 | if (ret) { | |
593 | str_liberror(ctx, ret, _("flushing datadev verify pool")); | |
594 | moveon = false; | |
595 | } | |
596 | ||
597 | ret = clean_pool(vs.rvp_log, &ctx->bytes_checked); | |
598 | if (ret) { | |
599 | str_liberror(ctx, ret, _("flushing logdev verify pool")); | |
600 | moveon = false; | |
601 | } | |
602 | ||
603 | ret = clean_pool(vs.rvp_realtime, &ctx->bytes_checked); | |
604 | if (ret) { | |
605 | str_liberror(ctx, ret, _("flushing rtdev verify pool")); | |
606 | moveon = false; | |
607 | } | |
b364a9c0 DW |
608 | |
609 | /* Scan the whole dir tree to see what matches the bad extents. */ | |
8cab77d3 | 610 | if (moveon && (!bitmap_empty(vs.d_bad) || !bitmap_empty(vs.r_bad))) |
ed5f9cc7 | 611 | moveon = xfs_report_verify_errors(ctx, &vs); |
b364a9c0 | 612 | |
557f98d7 DW |
613 | bitmap_free(&vs.r_bad); |
614 | bitmap_free(&vs.d_bad); | |
b364a9c0 DW |
615 | return moveon; |
616 | ||
f1bb1696 | 617 | out_rtpool: |
7668d01d | 618 | if (vs.rvp_realtime) { |
4cd869e5 | 619 | read_verify_pool_abort(vs.rvp_realtime); |
557f98d7 | 620 | read_verify_pool_destroy(vs.rvp_realtime); |
7668d01d | 621 | } |
f1bb1696 | 622 | out_logpool: |
7668d01d | 623 | if (vs.rvp_log) { |
4cd869e5 | 624 | read_verify_pool_abort(vs.rvp_log); |
557f98d7 | 625 | read_verify_pool_destroy(vs.rvp_log); |
7668d01d | 626 | } |
f1bb1696 | 627 | out_datapool: |
4cd869e5 | 628 | read_verify_pool_abort(vs.rvp_data); |
557f98d7 | 629 | read_verify_pool_destroy(vs.rvp_data); |
b364a9c0 | 630 | out_rbad: |
557f98d7 | 631 | bitmap_free(&vs.r_bad); |
b364a9c0 | 632 | out_dbad: |
557f98d7 | 633 | bitmap_free(&vs.d_bad); |
41c08606 | 634 | out: |
b364a9c0 DW |
635 | return moveon; |
636 | } | |
ed60d210 DW |
637 | |
638 | /* Estimate how much work we're going to do. */ | |
639 | bool | |
640 | xfs_estimate_verify_work( | |
641 | struct scrub_ctx *ctx, | |
642 | uint64_t *items, | |
643 | unsigned int *nr_threads, | |
644 | int *rshift) | |
645 | { | |
646 | unsigned long long d_blocks; | |
647 | unsigned long long d_bfree; | |
648 | unsigned long long r_blocks; | |
649 | unsigned long long r_bfree; | |
650 | unsigned long long f_files; | |
651 | unsigned long long f_free; | |
652 | bool moveon; | |
653 | ||
654 | moveon = xfs_scan_estimate_blocks(ctx, &d_blocks, &d_bfree, | |
655 | &r_blocks, &r_bfree, &f_files, &f_free); | |
656 | if (!moveon) | |
657 | return moveon; | |
658 | ||
a749451c DW |
659 | *items = cvt_off_fsb_to_b(&ctx->mnt, |
660 | (d_blocks - d_bfree) + (r_blocks - r_bfree)); | |
ed60d210 DW |
661 | *nr_threads = disk_heads(ctx->datadev); |
662 | *rshift = 20; | |
663 | return moveon; | |
664 | } |