xfs_scrub: refactor to XFS_IOC_VERIFY_MEDIA
PATCH v11 2/2 xfs_scrub: refactor to XFS_IOC_VERIFY_MEDIA
Hi all,
Originally, this was a single patch inside the autonomous self healing patchset. However, various issues brought up during review of the v9 codebase made it obvious that more cleanups were necessary prior to shifting xfs_scrub to use the new media verification ioctl. Therefore, the xfs_scrub changes have been broken out into a separate patchset to contain the refactorings and new functionality.
v11: various minor bug fixes detected by static checkers
v10: decouple the spacemap iterator and the read-verify pool code,
simplify the read-verify apis, use a fixed limit of 8 verify IO threads per device, improve the log media error reporting
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
With a bit of luck, this should all go splendidly. Comments and questions are, as always, welcome.
--D
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=scrub-media-verify-ioctl
---
Commits in this patchset:
* libfrog: allow bitmap_free to handle a null bitmap pointer
* mkfs: rename byte unit conversion macros
* libfrog: lift *BYTES helpers to convert.h
* xfs_scrub: report truncated devices as media errors
* xfs_scrub: fix i18n of the decode_special_owner return value
* scrub: remove the unused io_disk field in struct read_verify
* xfs_scrub: move read verification scheduling to phase6.c
* scrub: simplify the read_verify_pool_alloc interface
* xfs_scrub: don't pass the io_end_arg around everywhere
* scrub: use enum xfs_device for read verification
* xfs_scrub: rename nr_io_threads
* scrub: simplify verifier threads calculation
* xfs_scrub: move disk media verification error injection
* xfs_scrub: use the verify media ioctl during phase 6 if possible
* scrub: don't allocate disk for ioctl-based media verify
* xfs_scrub: perform media scanning of the log region
* xfs_scrub: index read-verify pools by xfs_device ids
* xfs_scrub: move failmap and other outputs into read_verify_pool
* xfs_scrub: clean up device-related error messages
* xfs_scrub: drop SCSI_VERIFY code from disk.
* xfs_scrub: raise media verification IO limits
--- libfrog/convert.h | 7 + scrub/disk.h | 2 scrub/fscounters.h | 2 scrub/read_verify.h | 34 ++- scrub/spacemap.h | 5 scrub/xfs_scrub.h | 9 - db/bmap_inflate.c | 2 doc/README-env-vars.txt | 1 libfrog/bitmap.c | 3 libfrog/convert.c | 7 - mdrestore/xfs_mdrestore.c | 5 mkfs/xfs_mkfs.c | 38 ++-- repair/agbtree.c | 3 repair/bmap_repair.c | 3 repair/rmap.c | 3 repair/xfs_repair.c | 5 scrub/common.c | 19 +- scrub/disk.c | 204 -------------------- scrub/fscounters.c | 4 scrub/phase1.c | 91 +++++++-- scrub/phase5.c | 6 - scrub/phase6.c | 424 +++++++++++++++++++++--------------------- scrub/phase7.c | 7 + scrub/phase8.c | 3 scrub/read_verify.c | 451 +++++++++++++++++++++++++++++++++------------ scrub/xfs_scrub.c | 1 26 files changed, 701 insertions(+), 638 deletions(-)
PATCH 1/21 libfrog: allow bitmap_free to handle a null bitmap pointer
From: Darrick J. Wong <[email protected]>
Allow bitmap_free() callers to pass a pointer to a NULL pointer. This will help subsequent refactorings in xfs_scrub have cleaner bitmap_free callsites.
--- libfrog/bitmap.c | 3 +++ repair/rmap.c | 3 +-- scrub/phase5.c | 6 ++---- 3 files changed, 6 insertions(+), 6 deletions(-)
libfrog/bitmap.c +3 -0
@@ -109,6 +109,9 @@ bitmap_free(struct bitmap_node *ext; bmap = *bmapp; +if (!bmap) +return ; +avl_for_each_safe (bmap->bt_tree, node, n) { ext = container_of(node, struct bitmap_node, btn_node);free (ext);
repair/rmap.c +1 -2
@@ -752,8 +752,7 @@ rmap_commit_agbtree_mappings( err:if (agflbp)libxfs_buf_relse (agflbp); -if (own_ag_bitmap) -bitmap_free (&own_ag_bitmap); +bitmap_free (&own_ag_bitmap);return error; }
scrub/phase5.c +2 -4
@@ -897,10 +897,8 @@ _("Filesystem has errors, skipping connectivity checks."));scrub_report_preen_triggers (ctx); out_lock:pthread_mutex_destroy (&ncs.lock); -if (ncs.new_deferred) -bitmap_free (&ncs.new_deferred); -if (ncs.cur_deferred) -bitmap_free (&ncs.cur_deferred); +bitmap_free (&ncs.new_deferred); +bitmap_free (&ncs.cur_deferred);return ret; }
PATCH 2/21 mkfs: rename byte unit conversion macros
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Rename these macros so that we can promote the generic ones in the next patch.
--- mkfs/xfs_mkfs.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-)
mkfs/xfs_mkfs.c +17 -16
@@ -18,9 +18,10 @@#include "proto.h" #include <ini.h> -#define TERABYTES (count, blog) ((uint64_t)(count) << (40 - (blog))) -#define GIGABYTES (count, blog) ((uint64_t)(count) << (30 - (blog))) -#define MEGABYTES (count, blog) ((uint64_t)(count) << (20 - (blog))) +/* Convert a quantity of mega/giga/terabytes into units of blocks */ +#define TERABLOCKS (count, blog) ((uint64_t)(count) << (40 - (blog))) +#define GIGABLOCKS (count, blog) ((uint64_t)(count) << (30 - (blog))) +#define MEGABLOCKS (count, blog) ((uint64_t)(count) << (20 - (blog)))/* * Realistically, the log should never be smaller than 64MB. Studies by the
@@ -28,7 +29,7 @@* latency of the xlog grant head waitqueue when running a heavy metadata * update workload when the log size is at least 64MB. */ -#define XFS_MIN_REALISTIC_LOG_BLOCKS (blog) (MEGABYTES(64, (blog))) +#define XFS_MIN_REALISTIC_LOG_BLOCKS (blog) (MEGABLOCKS(64, (blog)))/* * Use this macro before we have superblock and mount structure to
@@ -3443,7 +3444,7 @@ validate_supported(* * 64MB * (8 / 7) * 4 = 293MB */ -if (mp->m_sb.sb_dblocks <MEGABYTES (300 , mp->m_sb.sb_blocklog)) { +if (mp->m_sb.sb_dblocks <MEGABLOCKS (300 , mp->m_sb.sb_blocklog)) {fprintf (stderr,_ ("Filesystem must be larger than 300MB.\n" ));usage ();
@@ -3559,7 +3560,7 @@ _("%s: Volume reports invalid stripe unit (%d) and stripe width (%d), ignoring.\ BBTOB(ft->data.sunit), BBTOB(ft->data.swidth)); ft->data.sunit =0 ; ft->data.swidth =0 ; - }else if (cfg->dblocks <GIGABYTES (1 , cfg->blocklog)) { + }else if (cfg->dblocks <GIGABLOCKS (1 , cfg->blocklog)) {/* * Don't use automatic stripe detection if the device * size is less than 1GB because the performance gains
@@ -4056,7 +4057,7 @@ calc_concurrency_ag_geometry(*/ try_threads = nr_threads; try_agsize = cfg->dblocks / try_threads; -if (try_agsize <GIGABYTES (4 , cfg->blocklog)) { +if (try_agsize <GIGABLOCKS (4 , cfg->blocklog)) { do { try_threads--; if (try_threads <= def_agcount) {
@@ -4065,7 +4066,7 @@ calc_concurrency_ag_geometry( } try_agsize = cfg->dblocks / try_threads; - }while (try_agsize <GIGABYTES (4 , cfg->blocklog)); + }while (try_agsize <GIGABLOCKS (4 , cfg->blocklog)); goto out; }
@@ -4413,7 +4414,7 @@ calc_concurrency_rtgroup_geometry(*/ try_threads = nr_threads; try_rgsize = cfg->rtblocks / try_threads; -if (try_rgsize <GIGABYTES (4 , cfg->blocklog)) { +if (try_rgsize <GIGABLOCKS (4 , cfg->blocklog)) { do { try_threads--; if (try_threads <= def_rgcount) {
@@ -4422,7 +4423,7 @@ calc_concurrency_rtgroup_geometry( } try_rgsize = cfg->rtblocks / try_threads; - }while (try_rgsize <GIGABYTES (4 , cfg->blocklog)); + }while (try_rgsize <GIGABLOCKS (4 , cfg->blocklog)); goto out; }
@@ -4516,7 +4517,7 @@ _("rgsize (%s) not a multiple of fs blk size (%d)\n"),* If nobody specified a realtime device or the rtgroup size, * try 1TB, rounded down to the nearest rt extent. */ - cfg->rgsize =TERABYTES (1 , cfg->blocklog); + cfg->rgsize =TERABLOCKS (1 , cfg->blocklog); cfg->rgsize -= cfg->rgsize % cfg->rtextblocks; cfg->rgcount =0 ; }else if (cfg->rtblocks < cfg->rtextblocks *2 ) {
@@ -4651,7 +4652,7 @@ _("rgsize (%s) not a multiple of fs blk size (%d)\n"), (cfg->rtblocks % cfg->rgcount !=0 ); }else {/* 256MB zones just like typical SMR HDDs */ - cfg->rgsize =MEGABYTES (256 , cfg->blocklog); + cfg->rgsize =MEGABLOCKS (256 , cfg->blocklog); cfg->rgcount = cfg->rtblocks / cfg->rgsize + (cfg->rtblocks % cfg->rgsize !=0 ); }
@@ -4692,9 +4693,9 @@ calculate_imaxpct(* - under 1 TB, use XFS_DFL_IMAXIMUM_PCT (25%). */ -if (cfg->dblocks <TERABYTES (1 , cfg->blocklog)) +if (cfg->dblocks <TERABLOCKS (1 , cfg->blocklog)) cfg->imaxpct =XFS_DFL_IMAXIMUM_PCT ; -else if (cfg->dblocks <TERABYTES (50 , cfg->blocklog)) +else if (cfg->dblocks <TERABLOCKS (50 , cfg->blocklog)) cfg->imaxpct =5 ;else cfg->imaxpct =1 ;
@@ -5016,7 +5017,7 @@ calc_concurrency_logblocks(* If this filesystem is smaller than a gigabyte, there's little to be * gained from making the log larger. */ -if (cfg->dblocks <GIGABYTES (1 , cfg->blocklog)) +if (cfg->dblocks <GIGABLOCKS (1 , cfg->blocklog)) goto out;/*
@@ -5279,7 +5280,7 @@ _("max log size %d smaller than min log size %d, filesystem is too small\n"), XFS_MIN_REALISTIC_LOG_BLOCKS(cfg->blocklog));/* And for a tiny filesystem, use the absolute minimum size */ -if (cfg->dblocks <MEGABYTES (300 , cfg->blocklog)) +if (cfg->dblocks <MEGABLOCKS (300 , cfg->blocklog)) cfg->logblocks = min_logblocks;/* Ensure the chosen size fits within log size requirements */
PATCH 3/21 libfrog: lift *BYTES helpers to convert.h
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move these byte unit conversion macros to convert.h and amend the macros to cast to unsigned long long to avoid shifting issues. Now we can use these same macros throughout the codebase instead of opencoding shifts and possibly suffering from integer shifting problems.
--- libfrog/convert.h | 7 +++++++ db/bmap_inflate.c | 2 +- libfrog/convert.c | 7 ------- mdrestore/xfs_mdrestore.c | 5 +++-- mkfs/xfs_mkfs.c | 5 +++-- repair/agbtree.c | 3 ++- repair/bmap_repair.c | 3 ++- repair/xfs_repair.c | 5 +++-- scrub/common.c | 17 +++++++++-------- scrub/phase8.c | 3 ++- 10 files changed, 32 insertions(+), 25 deletions(-)
libfrog/convert.h +7 -0
@@ -22,4 +22,11 @@ extern uid_t uid_from_string(char *user);extern gid_t gid_from_string (char *group);extern prid_t prid_from_string (char *project); +#define EXABYTES (x) ((unsigned long long)(x) << 60) +#define PETABYTES (x) ((unsigned long long)(x) << 50) +#define TERABYTES (x) ((unsigned long long)(x) << 40) +#define GIGABYTES (x) ((unsigned long long)(x) << 30) +#define MEGABYTES (x) ((unsigned long long)(x) << 20) +#define KILOBYTES (x) ((unsigned long long)(x) << 10) +#endif /* __LIBFROG_CONVERT_H__ */
db/bmap_inflate.c +1 -1
@@ -437,7 +437,7 @@ bmapinflate_f(struct xfs_trans *tp;char *p;unsigned long long nextents =0 ; -unsigned long long dirty_bytes =60U <<20 ;/* 60MiB */ +unsigned long long dirty_bytes =MEGABYTES (60 );unsigned long long dirty_blocks;unsigned int resblks;bool estimate = false;
libfrog/convert.c +0 -7
@@ -173,13 +173,6 @@ cvt_u16(return i; } -#define EXABYTES (x) ((long long)(x) << 60) -#define PETABYTES (x) ((long long)(x) << 50) -#define TERABYTES (x) ((long long)(x) << 40) -#define GIGABYTES (x) ((long long)(x) << 30) -#define MEGABYTES (x) ((long long)(x) << 20) -#define KILOBYTES (x) ((long long)(x) << 10) - long long cvtnum( size_t blksize,
mdrestore/xfs_mdrestore.c +3 -2
@@ -8,6 +8,7 @@#include "xfs_metadump.h" #include <libfrog/platform.h> #include "libfrog/div64.h" +#include "libfrog/convert.h" union mdrestore_headers {__be32 magic;
@@ -92,10 +93,10 @@ final_print_progress(if (!mdrestore.show_progress) goto done; -if (bytes_read <= (*cursor <<20 )) +if (bytes_read <=MEGABYTES (*cursor)) goto done; -print_progress ("%lld MB read" ,howmany_64 (bytes_read,1U <<20 )); +print_progress ("%lld MB read" ,howmany_64 (bytes_read,MEGABYTES (1 ))); done:if (mdrestore.progress_since_warning)
mkfs/xfs_mkfs.c +3 -2
@@ -15,6 +15,7 @@#include "libfrog/dahashselftest.h" #include "libfrog/fsproperties.h" #include "libfrog/zones.h" +#include "libfrog/convert.h" #include "proto.h" #include <ini.h>
@@ -558,7 +559,7 @@ static struct opt_params iopts = { .conflicts = { { NULL, LAST_CONFLICT } }, .convert = true, .minval = 1, - .maxval = 1ULL << 30, /* 1GiB */ + .maxval = GIGABYTES(1), .defaultval = SUBOPT_NEEDS_VAL, }, },
@@ -1576,7 +1577,7 @@ discard_blocks(int fd, uint64_t nsectors, int quiet) {uint64_t offset =0 ;/* Discard the device 2G at a time */ -const uint64_t step =2ULL <<30 ; +const uint64_t step =GIGABYTES (2 );const uint64_t count =BBTOB (nsectors);/*
repair/agbtree.c +2 -1
@@ -6,6 +6,7 @@#include <libxfs.h> #include "err_protos.h" #include "libfrog/bitmap.h" +#include "libfrog/convert.h" #include "slab.h" #include "rmap.h" #include "incore.h"
@@ -23,7 +24,7 @@ init_rebuild(memset (btr,0 ,sizeof (struct bt_rebuild ));bulkload_init_ag (&btr->newbt, sc, oinfo,NULLFSBLOCK ); - btr->bload.max_dirty =XFS_B_TO_FSBT (sc->mp,256U <<10 );/* 256K */ + btr->bload.max_dirty =XFS_B_TO_FSBT (sc->mp,KILOBYTES (256 ));bulkload_estimate_ag_slack (sc, &btr->bload, est_agfreeblocks); }
repair/bmap_repair.c +2 -1
@@ -15,6 +15,7 @@#include "bulkload.h" #include "bmap_repair.h" #include "libfrog/util.h" +#include "libfrog/convert.h" /* * Inode Fork Block Mapping (BMBT) Repair
@@ -499,7 +500,7 @@ xrep_bmap_btree_load( rb->bmap_bload.get_records = xrep_bmap_get_records; rb->bmap_bload.claim_block = xrep_bmap_claim_block; rb->bmap_bload.iroot_size = xrep_bmap_iroot_size; - rb->bmap_bload.max_dirty =XFS_B_TO_FSBT (sc->mp,256U <<10 );/* 256K */ + rb->bmap_bload.max_dirty =XFS_B_TO_FSBT (sc->mp,KILOBYTES (256 ));/* * Always make the btree as small as possible, since we might need the
repair/xfs_repair.c +3 -2
@@ -28,6 +28,7 @@#include "quotacheck.h" #include "rcbag_btree.h" #include "rt.h" +#include "libfrog/convert.h" /* * option tables for getsubopt calls
@@ -1321,8 +1322,8 @@ main(int argc, char **argv) } max_mem -= mem_used; -if (max_mem >= (1 <<30 )) - max_mem =1 <<30 ; +if (max_mem >=GIGABYTES (1 )) + max_mem =GIGABYTES (1 ); libxfs_bhash_size = max_mem / (HASH_CACHE_RATIO * (igeo->inode_cluster_size >>10 ));if (libxfs_bhash_size <512 )
scrub/common.c +9 -8
@@ -11,6 +11,7 @@#include "libfrog/paths.h" #include "libfrog/getparents.h" #include "libfrog/handle_priv.h" +#include "libfrog/convert.h" #include "xfs_scrub.h" #include "common.h" #include "progress.h"
@@ -218,18 +219,18 @@ auto_space_units( {if (debug >1 ) goto no_prefix; -if (bytes > (1ULL <<40 )) { +if (bytes >TERABYTES (1 )) { *units ="TiB" ; -return (double )bytes / (1ULL <<40 ); - }else if (bytes > (1ULL <<30 )) { +return (double )bytes /TERABYTES (1 ); + }else if (bytes >GIGABYTES (1 )) { *units ="GiB" ; -return (double )bytes / (1ULL <<30 ); - }else if (bytes > (1ULL <<20 )) { +return (double )bytes /GIGABYTES (1 ); + }else if (bytes >MEGABYTES (1 )) { *units ="MiB" ; -return (double )bytes / (1ULL <<20 ); - }else if (bytes > (1ULL <<10 )) { +return (double )bytes /MEGABYTES (1 ); + }else if (bytes >KILOBYTES (1 )) { *units ="KiB" ; -return (double )bytes / (1ULL <<10 ); +return (double )bytes /KILOBYTES (1 ); } no_prefix:
scrub/phase8.c +2 -1
@@ -12,6 +12,7 @@#include "libfrog/paths.h" #include "libfrog/workqueue.h" #include "libfrog/histogram.h" +#include "libfrog/convert.h" #include "xfs_scrub.h" #include "common.h" #include "progress.h"
@@ -51,7 +52,7 @@ fstrim_ok(* call so that we can implement decent progress reporting and CPU resource * control. Pick a prime number of gigabytes for interest. */ -#define FSTRIM_MAX_BYTES (11ULL << 30) +#define FSTRIM_MAX_BYTES GIGABYTES(11)/* Trim a certain range of the filesystem. */ static int
PATCH 4/21 xfs_scrub: report truncated devices as media errors
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
If we encounter a zero-length read of an xfs device but don't hit any actual media errors, we won't report the truncated device. Fix that. Also fix the mistake that flushing the verify-pools of the log/rt devices doesn't actually cause scrub to abort.
--- scrub/phase6.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
scrub/phase6.c +6 -2
@@ -782,9 +782,13 @@ phase6_func(* If the verify flush didn't work or we found no bad blocks, we're * done! No errors detected. */ -if (ret || ret2 || ret3) +if (ret || ret2 || ret3) { + ret |= ret2 | ret3;/* caller only cares about non-zero/zero */ goto out_rbad; -if (bitmap_empty (vs.d_bad) &&bitmap_empty (vs.r_bad)) + } +if (bitmap_empty (vs.d_bad) && !vs.d_trunc && +bitmap_empty (vs.r_bad) && !vs.r_trunc && + !vs.l_trunc) goto out_rbad;/* Scan the whole dir tree to see what matches the bad extents. */
PATCH 5/21 xfs_scrub: fix i18n of the decode_special_owner return value
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The function decode_special_owner turns a special fsmap owner into a printable string value. However, it does not query the gettext catalog for a local language translation, which leads to annoying multilanguage failure messages. Fix that by adding the appropriate wrappers.
--- scrub/phase6.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
scrub/phase6.c +11 -11
@@ -123,16 +123,16 @@ struct owner_decode { };static const struct owner_decode special_owners[] = { - {XFS_FMR_OWN_FREE ,"free space" }, - {XFS_FMR_OWN_UNKNOWN ,"unknown owner" }, - {XFS_FMR_OWN_FS ,"static FS metadata" }, - {XFS_FMR_OWN_LOG ,"journalling log" }, - {XFS_FMR_OWN_AG ,"per-AG metadata" }, - {XFS_FMR_OWN_INOBT ,"inode btree blocks" }, - {XFS_FMR_OWN_INODES ,"inodes" }, - {XFS_FMR_OWN_REFC ,"refcount btree" }, - {XFS_FMR_OWN_COW ,"CoW staging" }, - {XFS_FMR_OWN_DEFECTIVE ,"bad blocks" }, + {XFS_FMR_OWN_FREE ,N_ ("free space" )}, + {XFS_FMR_OWN_UNKNOWN ,N_ ("unknown owner" )}, + {XFS_FMR_OWN_FS ,N_ ("static FS metadata" )}, + {XFS_FMR_OWN_LOG ,N_ ("journalling log" )}, + {XFS_FMR_OWN_AG ,N_ ("per-AG metadata" )}, + {XFS_FMR_OWN_INOBT ,N_ ("inode btree blocks" )}, + {XFS_FMR_OWN_INODES ,N_ ("inodes" )}, + {XFS_FMR_OWN_REFC ,N_ ("refcount btree" )}, + {XFS_FMR_OWN_COW ,N_ ("CoW staging" )}, + {XFS_FMR_OWN_DEFECTIVE ,N_ ("bad blocks" )}, {0 ,NULL }, };
@@ -145,7 +145,7 @@ decode_special_owner(while (od->descr) {if (od->owner == owner) -return od->descr; +return _ (od->descr); od++; }
PATCH 6/21 scrub: remove the unused io_disk field in struct read_verify
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
--- scrub/read_verify.c | 1 - 1 file changed, 1 deletion(-)
scrub/read_verify.c +0 -1
@@ -51,7 +51,6 @@ rvp_io_max_size(void)struct read_verify {void *io_end_arg; -struct disk *io_disk;uint64_t io_start;/* bytes */ uint64_t io_length;/* bytes */ };
PATCH 7/21 xfs_scrub: move read verification scheduling to phase6.c
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Right now there's a weird coupling between read_verify.c and spacemap.c:
Anyone using a read_verify_pool is required to tell the pool how many threads it's going to use to call read_verify_schedule_io. This is because the read_verify_pool accumulates verification requests on a per-thread basis to try to combine adjacent written regions for media verification. However, the verification requests are made from the phase6.c callback (check_rmap) that is called from the workers created by scrub_scan_all_spacemaps.
Yeah, that's confusing: implementation details of spacemap.c must be inferred by phase6.c and passed to read_verify.c.
Let's fix this by moving the per-thread schedule accumulation to phase6.c before the next patches constrain the number of IO threads sending verification requests to the kernel.
--- scrub/read_verify.h | 16 +++++-- scrub/spacemap.h | 5 ++ scrub/phase6.c | 63 ++++++++++++++++++++++----- scrub/read_verify.c | 121 ++++++++++++++++++--------------------------------- 4 files changed, 112 insertions(+), 93 deletions(-)
scrub/read_verify.h +12 -4
@@ -10,6 +10,13 @@ struct scrub_ctx;struct read_verify_pool ;struct disk ; +struct read_verify_schedule { +struct read_verify_pool *rvp; +void *io_end_arg; +uint64_t io_start;/* bytes */ +uint64_t io_length;/* bytes */ +}; +/* Function called when an IO error happens. */ typedef void (*read_verify_ioerr_fn_t)(struct scrub_ctx *ctx, struct disk *disk, uint64_t start, uint64_t length,
@@ -17,15 +24,16 @@ typedef void (*read_verify_ioerr_fn_t)(struct scrub_ctx *ctx,int read_verify_pool_alloc (struct scrub_ctx *ctx,struct disk *disk,size_t miniosz,read_verify_ioerr_fn_t ioerr_fn, -unsigned int submitter_threads,struct read_verify_pool **prvp);void read_verify_pool_abort (struct read_verify_pool *rvp);int read_verify_pool_flush (struct read_verify_pool *rvp);void read_verify_pool_destroy (struct read_verify_pool *rvp); -int read_verify_schedule_io (struct read_verify_pool *rvp,uint64_t start, -uint64_t length,void *end_arg); -int read_verify_force_io (struct read_verify_pool *rvp); +int read_verify_schedule_now (struct read_verify_schedule *rs); +bool try_read_verify_schedule_io (struct read_verify_schedule *rs, +struct read_verify_pool *rvp,uint64_t start,uint64_t length, +void *end_arg); +int read_verify_bytes (struct read_verify_pool *rvp,uint64_t *bytes);#endif /* XFS_SCRUB_READ_VERIFY_H_ */
scrub/spacemap.h +5 -0
@@ -18,4 +18,9 @@ int scrub_iterate_fsmap(struct scrub_ctx *ctx, struct fsmap *keys,int scrub_scan_all_spacemaps (struct scrub_ctx *ctx,scrub_fsmap_iter_fn fn,void *arg); +static inline unsigned int scrub_scan_spacemaps_nproc (struct scrub_ctx *ctx) +{ +return scrub_nproc (ctx); +} +#endif /* XFS_SCRUB_SPACEMAP_H_ */
scrub/phase6.c +53 -10
135 lines not on this page · raw message
scrub/read_verify.c +42 -79
213 lines not on this page · raw message
PATCH 8/21 scrub: simplify the read_verify_pool_alloc interface
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Don't pass the miniosize as that's always the fs block size.
--- scrub/read_verify.h | 2 +- scrub/phase6.c | 9 +++------ scrub/read_verify.c | 12 ++---------- 3 files changed, 6 insertions(+), 17 deletions(-)
scrub/read_verify.h +1 -1
@@ -23,7 +23,7 @@ typedef void (*read_verify_ioerr_fn_t)(struct scrub_ctx *ctx, int error, void *arg);int read_verify_pool_alloc (struct scrub_ctx *ctx,struct disk *disk, -size_t miniosz,read_verify_ioerr_fn_t ioerr_fn, +read_verify_ioerr_fn_t ioerr_fn,struct read_verify_pool **prvp);void read_verify_pool_abort (struct read_verify_pool *rvp);int read_verify_pool_flush (struct read_verify_pool *rvp);
scrub/phase6.c +3 -6
@@ -761,16 +761,14 @@ phase6_func( goto out_dbad; } - ret =read_verify_pool_alloc (ctx, ctx->datadev, - ctx->mnt.fsgeom.blocksize, remember_ioerr, + ret =read_verify_pool_alloc (ctx, ctx->datadev, remember_ioerr, &vs.rvp_data);if (ret) {str_liberror (ctx, ret,_ ("creating datadev media verifier" )); goto out_rbad; }if (ctx->logdev) { - ret =read_verify_pool_alloc (ctx, ctx->logdev, - ctx->mnt.fsgeom.blocksize, remember_ioerr, + ret =read_verify_pool_alloc (ctx, ctx->logdev, remember_ioerr, &vs.rvp_log);if (ret) { str_liberror(ctx, ret,
@@ -779,8 +777,7 @@ phase6_func( } }if (ctx->rtdev) { - ret =read_verify_pool_alloc (ctx, ctx->rtdev, - ctx->mnt.fsgeom.blocksize, remember_ioerr, + ret =read_verify_pool_alloc (ctx, ctx->rtdev, remember_ioerr, &vs.rvp_realtime);if (ret) { str_liberror(ctx, ret,
scrub/read_verify.c +2 -10
@@ -74,14 +74,12 @@ struct read_verify_pool {* Create a thread pool to run read verifiers. * * @disk is the disk we want to verify. -* @miniosz is the minimum size of an IO to expect (in bytes). * @ioerr_fn will be called when IO errors occur. */ int read_verify_pool_alloc (struct scrub_ctx *ctx,struct disk *disk, -size_t miniosz,read_verify_ioerr_fn_t ioerr_fn,struct read_verify_pool **prvp) {
@@ -89,13 +87,7 @@ read_verify_pool_alloc(unsigned int verifier_threads =disk_heads (disk);int ret; -/* -* The minimum IO size must be a multiple of the disk sector size -* and a factor of the max io size. -*/ -if (miniosz % disk->d_lbasize) -return EINVAL ; -if (rvp_io_max_size () % miniosz) +if (rvp_io_max_size () % ctx->mnt.fsgeom.blocksize)return EINVAL ; rvp =calloc (1 ,sizeof (struct read_verify_pool ));
@@ -109,7 +101,7 @@ read_verify_pool_alloc( ret =ptcounter_alloc (verifier_threads, &rvp->verified_bytes);if (ret) goto out_buf; - rvp->miniosz = miniosz; + rvp->miniosz = ctx->mnt.fsgeom.blocksize; rvp->ctx = ctx; rvp->disk = disk; rvp->ioerr_fn = ioerr_fn;
PATCH 9/21 xfs_scrub: don't pass the io_end_arg around everywhere
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The value is the same across all callers and read-verify pools, so let's just pass it into read_verify_pool_alloc instead of making temporary aliases everywhere and increasing memory usage.
--- scrub/read_verify.h | 6 ++---- scrub/phase6.c | 10 +++++----- scrub/read_verify.c | 15 +++++++-------- 3 files changed, 14 insertions(+), 17 deletions(-)
scrub/read_verify.h +2 -4
@@ -12,7 +12,6 @@ struct disk;struct read_verify_schedule {struct read_verify_pool *rvp; -void *io_end_arg;uint64_t io_start;/* bytes */ uint64_t io_length;/* bytes */ };
@@ -23,7 +22,7 @@ typedef void (*read_verify_ioerr_fn_t)(struct scrub_ctx *ctx, int error, void *arg);int read_verify_pool_alloc (struct scrub_ctx *ctx,struct disk *disk, -read_verify_ioerr_fn_t ioerr_fn, +read_verify_ioerr_fn_t ioerr_fn,void *ioerr_arg,struct read_verify_pool **prvp);void read_verify_pool_abort (struct read_verify_pool *rvp);int read_verify_pool_flush (struct read_verify_pool *rvp);
@@ -31,8 +30,7 @@ void read_verify_pool_destroy(struct read_verify_pool *rvp);int read_verify_schedule_now (struct read_verify_schedule *rs);bool try_read_verify_schedule_io (struct read_verify_schedule *rs, -struct read_verify_pool *rvp,uint64_t start,uint64_t length, -void *end_arg); +struct read_verify_pool *rvp,uint64_t start,uint64_t length);int read_verify_bytes (struct read_verify_pool *rvp,uint64_t *bytes);
scrub/phase6.c +5 -5
@@ -645,7 +645,7 @@ check_rmap(/* Schedule the read verify command for (eventual) running. */ scheduled =try_read_verify_schedule_io (rs, rvp, map->fmr_physical, - map->fmr_length, vs); + map->fmr_length);if (scheduled)return 0 ;
@@ -656,7 +656,7 @@ check_rmap( } scheduled =try_read_verify_schedule_io (rs, rvp, map->fmr_physical, - map->fmr_length, vs); + map->fmr_length);assert (scheduled);return 0 ; }
@@ -761,7 +761,7 @@ phase6_func( goto out_dbad; } - ret =read_verify_pool_alloc (ctx, ctx->datadev, remember_ioerr, + ret =read_verify_pool_alloc (ctx, ctx->datadev, remember_ioerr, &vs, &vs.rvp_data);if (ret) {str_liberror (ctx, ret,_ ("creating datadev media verifier" ));
@@ -769,7 +769,7 @@ phase6_func( }if (ctx->logdev) { ret =read_verify_pool_alloc (ctx, ctx->logdev, remember_ioerr, - &vs.rvp_log); + &vs, &vs.rvp_log);if (ret) {str_liberror (ctx, ret,_ ("creating logdev media verifier" ));
@@ -778,7 +778,7 @@ phase6_func( }if (ctx->rtdev) { ret =read_verify_pool_alloc (ctx, ctx->rtdev, remember_ioerr, - &vs.rvp_realtime); + &vs, &vs.rvp_realtime);if (ret) {str_liberror (ctx, ret,_ ("creating rtdev media verifier" ));
scrub/read_verify.c +7 -8
@@ -49,7 +49,6 @@ rvp_io_max_size(void)#define RVP_IO_BATCH_LOCALITY (65536)struct read_verify { -void *io_end_arg;uint64_t io_start;/* bytes */ uint64_t io_length;/* bytes */ };
@@ -60,6 +59,7 @@ struct read_verify_pool {void *readbuf;/* read buffer */ struct ptcounter *verified_bytes;struct disk *disk;/* which disk? */ +void *ioerr_arg;read_verify_ioerr_fn_t ioerr_fn;/* io error callback */ size_t miniosz;/* minimum io size, bytes */
@@ -81,6 +81,7 @@ read_verify_pool_alloc(struct scrub_ctx *ctx, struct disk *disk, read_verify_ioerr_fn_t ioerr_fn, + void *ioerr_arg, struct read_verify_pool **prvp) { struct read_verify_pool *rvp;
@@ -105,6 +106,7 @@ read_verify_pool_alloc( rvp->ctx = ctx; rvp->disk = disk; rvp->ioerr_fn = ioerr_fn; + rvp->ioerr_arg = ioerr_arg; ret = -workqueue_create (&rvp->wq, (struct xfs_mount *)rvp, verifier_threads ==1 ?0 : verifier_threads);if (ret)
@@ -223,14 +225,14 @@ read_verify( rvp->disk->d_fd, rv->io_start, sz, read_error); rvp->ioerr_fn (rvp->ctx, rvp->disk, rv->io_start, sz, - read_error, rv->io_end_arg); + read_error, rvp->ioerr_arg); }else if (sz ==0 ) {/* No bytes at all? Did we hit the end of the disk? */ dbg_printf ("EOF %d @ %" PRIu64" %zu err %d\n" , rvp->disk->d_fd, rv->io_start, sz, read_error); rvp->ioerr_fn (rvp->ctx, rvp->disk, rv->io_start, sz, - read_error, rv->io_end_arg); + read_error, rvp->ioerr_arg);break ; }else if (sz < len) {/*
@@ -291,7 +293,6 @@ read_verify_schedule_now(return errno; } - tmp->io_end_arg = rs->io_end_arg; tmp->io_start = rs->io_start; tmp->io_length = rs->io_length;
@@ -318,8 +319,7 @@ try_read_verify_schedule_io(struct read_verify_schedule *rs, struct read_verify_pool *rvp, uint64_t start, - uint64_t length, - void *end_arg) + uint64_t length) { uint64_t req_end;uint64_t rv_end;
@@ -338,7 +338,6 @@ try_read_verify_schedule_io( rs->rvp = rvp; rs->io_start = start; rs->io_length = length; - rs->io_end_arg = end_arg;return true; }
@@ -348,7 +347,7 @@ try_read_verify_schedule_io(* reporting is the same, and the two extents are close, * we can combine them. */ -if (rs->rvp == rvp && rs->io_length >0 && end_arg == rs->io_end_arg && +if (rs->rvp == rvp && rs->io_length >0 && ((start >= rs->io_start && start <= rv_end +RVP_IO_BATCH_LOCALITY ) || (rs->io_start >= start && rs->io_start <= req_end +RVP_IO_BATCH_LOCALITY ))) {
PATCH 10/21 scrub: use enum xfs_device for read verification
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Passing the disk pointer and then translating back to an index is a bit confusing. Rewrite the read_verify and related code to pass around an enum xfs_device and use that to identify the device.
The disks are placed in an array so that they can be trivially indexed using the xfs device. Because the value start at 1 this adds an unused slot, but such a minor waste does not matter in the overall scheme of things.
--- scrub/read_verify.h | 5 +-- scrub/xfs_scrub.h | 6 +-- scrub/phase1.c | 26 +++++++------ scrub/phase6.c | 101 ++++++++++++++++++++++++++------------------------- scrub/read_verify.c | 38 +++++++++---------- 5 files changed, 86 insertions(+), 90 deletions(-)
scrub/read_verify.h +2 -3
@@ -8,7 +8,6 @@struct scrub_ctx ;struct read_verify_pool ; -struct disk ;struct read_verify_schedule {struct read_verify_pool *rvp;
@@ -18,10 +17,10 @@ struct read_verify_schedule {/* Function called when an IO error happens. */ typedef void (*read_verify_ioerr_fn_t )(struct scrub_ctx *ctx, -struct disk *disk,uint64_t start,uint64_t length, +enum xfs_device dev,uint64_t start,uint64_t length,int error,void *arg); -int read_verify_pool_alloc (struct scrub_ctx *ctx,struct disk *disk, +int read_verify_pool_alloc (struct scrub_ctx *ctx,enum xfs_device dev,read_verify_ioerr_fn_t ioerr_fn,void *ioerr_arg,struct read_verify_pool **prvp);void read_verify_pool_abort (struct read_verify_pool *rvp);
scrub/xfs_scrub.h +2 -4
@@ -57,10 +57,8 @@ struct scrub_ctx {struct statvfs mnt_sv;struct statfs mnt_sf; -/* Open block devices */ -struct disk *datadev; -struct disk *logdev; -struct disk *rtdev; +/* Open block devices for legacy verify */ +struct disk *verify_disks[XFS_DEV_RT +1 ];/* What does the user want us to do? */ enum scrub_mode mode;
scrub/phase1.c +13 -13
@@ -96,12 +96,12 @@ scrub_cleanup(if (ctx->fshandle)free_handle (ctx->fshandle, ctx->fshandle_len); -if (ctx->rtdev) -disk_close (ctx->rtdev); -if (ctx->logdev) -disk_close (ctx->logdev); -if (ctx->datadev) -disk_close (ctx->datadev); +if (ctx->verify_disks[XFS_DEV_DATA ]) +disk_close (ctx->verify_disks[XFS_DEV_DATA ]); +if (ctx->verify_disks[XFS_DEV_LOG ]) +disk_close (ctx->verify_disks[XFS_DEV_LOG ]); +if (ctx->verify_disks[XFS_DEV_RT ]) +disk_close (ctx->verify_disks[XFS_DEV_RT ]);fshandle_destroy (); error = -xfd_close (&ctx->mnt);if (error)
@@ -349,13 +349,13 @@ _("Unable to find realtime device path.")); }/* Open the raw devices. */ - ctx->datadev =disk_open (ctx->fsinfo.fs_name); -if (!ctx->datadev) { + ctx->verify_disks[XFS_DEV_DATA ] =disk_open (ctx->fsinfo.fs_name); +if (!ctx->verify_disks[XFS_DEV_DATA ]) {str_error (ctx, ctx->mntpoint,_ ("Unable to open data device." ));return ECANCELED ; } - ctx->nr_io_threads =disk_heads (ctx->datadev); + ctx->nr_io_threads =disk_heads (ctx->verify_disks[XFS_DEV_DATA ]);if (verbose) {fprintf (stdout,_ ("%s: using %d threads to scrub.\n" ), ctx->mntpoint,scrub_nproc (ctx));
@@ -363,16 +363,16 @@ _("Unable to find realtime device path.")); }if (ctx->fsinfo.fs_log) { - ctx->logdev =disk_open (ctx->fsinfo.fs_log); -if (!ctx->logdev) { + ctx->verify_disks[XFS_DEV_LOG ] =disk_open (ctx->fsinfo.fs_log); +if (!ctx->verify_disks[XFS_DEV_LOG ]) {str_error (ctx, ctx->mntpoint,_ ("Unable to open external log device." ));return ECANCELED ; } }if (ctx->fsinfo.fs_rt) { - ctx->rtdev =disk_open (ctx->fsinfo.fs_rt); -if (!ctx->rtdev) { + ctx->verify_disks[XFS_DEV_RT ] =disk_open (ctx->fsinfo.fs_rt); +if (!ctx->verify_disks[XFS_DEV_RT ]) {str_error (ctx, ctx->mntpoint,_ ("Unable to open realtime device." ));return ECANCELED ;
scrub/phase6.c +51 -50
192 lines not on this page · raw message
scrub/read_verify.c +18 -20
@@ -58,10 +58,10 @@ struct read_verify_pool {struct scrub_ctx *ctx;/* scrub context */ void *readbuf;/* read buffer */ struct ptcounter *verified_bytes; -struct disk *disk;/* which disk? */ void *ioerr_arg;read_verify_ioerr_fn_t ioerr_fn;/* io error callback */ size_t miniosz;/* minimum io size, bytes */ +enum xfs_device dev;/* which device? */ /* * Store a runtime error code here so that we can stop the pool and
@@ -73,19 +73,19 @@ struct read_verify_pool {/* * Create a thread pool to run read verifiers. * -* @disk is the disk we want to verify. * @ioerr_fn will be called when IO errors occur. */ int read_verify_pool_alloc (struct scrub_ctx *ctx, -struct disk *disk, +enum xfs_device dev,read_verify_ioerr_fn_t ioerr_fn,void *ioerr_arg,struct read_verify_pool **prvp) {struct read_verify_pool *rvp; -unsigned int verifier_threads =disk_heads (disk); +unsigned int verifier_threads = +disk_heads (ctx->verify_disks[XFS_DEV_DATA ]);int ret;if (rvp_io_max_size () % ctx->mnt.fsgeom.blocksize)
@@ -104,7 +104,7 @@ read_verify_pool_alloc( goto out_buf; rvp->miniosz = ctx->mnt.fsgeom.blocksize; rvp->ctx = ctx; - rvp->disk = disk; + rvp->dev = dev; rvp->ioerr_fn = ioerr_fn; rvp->ioerr_arg = ioerr_arg; ret = -workqueue_create(&rvp->wq, (struct xfs_mount *)rvp,
@@ -179,10 +179,10 @@ read_verify(while (rv->io_length >0 ) { read_error =0 ; len =min (rv->io_length, io_max_size); -dbg_printf ("diskverify %d %" PRIu64" %zu\n" , rvp->disk->d_fd, +dbg_printf ("diskverify %u %" PRIu64" %zu\n" , rvp->dev, rv->io_start, len); - sz =disk_read_verify (rvp->disk, rvp->readbuf, rv->io_start, - len); + sz =disk_read_verify (rvp->ctx->verify_disks[rvp->dev], + rvp->readbuf, rv->io_start, len);if (sz == len && io_max_size < rvp->miniosz) {/* * If the verify request was 100% successful and less
@@ -221,17 +221,15 @@ read_verify(* io_start to the next miniosz block. */ sz = rvp->miniosz - (rv->io_start % rvp->miniosz); -dbg_printf ("IOERR %d @ %" PRIu64" %zu err %d\n" , - rvp->disk->d_fd, rv->io_start, sz, - read_error); - rvp->ioerr_fn (rvp->ctx, rvp->disk, rv->io_start, sz, +dbg_printf ("IOERR %u @ %" PRIu64" %zu err %d\n" , + rvp->dev, rv->io_start, sz, read_error); + rvp->ioerr_fn (rvp->ctx, rvp->dev, rv->io_start, sz, read_error, rvp->ioerr_arg); }else if (sz ==0 ) {/* No bytes at all? Did we hit the end of the disk? */ -dbg_printf ("EOF %d @ %" PRIu64" %zu err %d\n" , - rvp->disk->d_fd, rv->io_start, sz, - read_error); - rvp->ioerr_fn (rvp->ctx, rvp->disk, rv->io_start, sz, +dbg_printf ("EOF %u @ %" PRIu64" %zu err %d\n" , + rvp->dev, rv->io_start, sz, read_error); + rvp->ioerr_fn (rvp->ctx, rvp->dev, rv->io_start, sz, read_error, rvp->ioerr_arg);break ; }else if (sz < len) {
@@ -245,8 +243,8 @@ read_verify(* next full block. */ io_max_size = rvp->miniosz - (sz % rvp->miniosz); -dbg_printf ("SHORT %d READ @ %" PRIu64" %zu try for %zd\n" , - rvp->disk->d_fd, rv->io_start, sz, +dbg_printf ("SHORT %u READ @ %" PRIu64" %zu try for %zd\n" , + rvp->dev, rv->io_start, sz, io_max_size); }else {/* We should never get back more bytes than we asked. */
@@ -279,8 +277,8 @@ read_verify_schedule_now(if (!rvp)return 0 ; -dbg_printf ("verify fd %d start %" PRIu64" len %" PRIu64"\n" , - rvp->disk->d_fd, rs->io_start, rs->io_length); +dbg_printf ("verify dev %u start %" PRIu64" len %" PRIu64"\n" , + rvp->dev, rs->io_start, rs->io_length);/* Worker thread saw a runtime error, don't queue more. */ if (rvp->runtime_error)
PATCH 11/21 xfs_scrub: rename nr_io_threads
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
This variable really describes the number of threads that we should start up to scan metadata. Rename it to reduce confusion with the media verification code, which also initiates IO.
--- scrub/xfs_scrub.h | 2 +- scrub/common.c | 2 +- scrub/phase1.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
scrub/xfs_scrub.h +1 -1
@@ -70,7 +70,7 @@ struct scrub_ctx {struct xfs_fd mnt;/* Number of threads for metadata scrubbing */ -unsigned int nr_io_threads; +unsigned int nr_scan_threads;/* XFS specific geometry */ struct fs_path fsinfo;
scrub/common.c +1 -1
@@ -275,7 +275,7 @@ scrub_nproc( {if (force_nr_threads)return force_nr_threads; -return ctx->nr_io_threads; +return ctx->nr_scan_threads; }/*
scrub/phase1.c +1 -1
@@ -355,7 +355,7 @@ _("Unable to find realtime device path."));return ECANCELED ; } - ctx->nr_io_threads =disk_heads (ctx->verify_disks[XFS_DEV_DATA ]); + ctx->nr_scan_threads =disk_heads (ctx->verify_disks[XFS_DEV_DATA ]);if (verbose) {fprintf (stdout,_ ("%s: using %d threads to scrub.\n" ), ctx->mntpoint,scrub_nproc (ctx));
PATCH 12/21 scrub: simplify verifier threads calculation
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Throwing all CPUs at verifying seems like a bad idea for foreground scrub, as does abusing I/O opt/min as that says absolutely nothing about parallelism. I can't really think of a better way than manually configuring this except maybe kernel hints. But the current decisions are not good defaults, and also are the only user of struct disk for file systems using the kernel verify ioctl.
The best default seems to be 8, because verification speed increases diminish above that level. Note that background service mode now obeys the thread count restrictions.
--- scrub/read_verify.h | 2 ++ scrub/phase6.c | 10 +++++----- scrub/read_verify.c | 20 ++++++++++++++++++-- 3 files changed, 25 insertions(+), 7 deletions(-)
scrub/read_verify.h +2 -0
@@ -33,4 +33,6 @@ bool try_read_verify_schedule_io(struct read_verify_schedule *rs,int read_verify_bytes (struct read_verify_pool *rvp,uint64_t *bytes); +unsigned int read_verify_nproc (struct scrub_ctx *ctx); +#endif /* XFS_SCRUB_READ_VERIFY_H_ */
scrub/phase6.c +5 -5
@@ -889,11 +889,11 @@ phase6_estimate(* can contribute to the progress counter. Hence we need to set * nr_threads appropriately to handle that many threads. */ - *nr_threads =disk_heads (ctx->verify_disks[XFS_DEV_DATA ]); -if (ctx->verify_disks[XFS_DEV_RT ]) - *nr_threads +=disk_heads (ctx->verify_disks[XFS_DEV_RT ]); -if (ctx->verify_disks[XFS_DEV_LOG ]) - *nr_threads +=disk_heads (ctx->verify_disks[XFS_DEV_LOG ]); + *nr_threads =read_verify_nproc (ctx); +if (ctx->fsinfo.fs_rt) + *nr_threads +=read_verify_nproc (ctx); +if (ctx->fsinfo.fs_log) + *nr_threads +=read_verify_nproc (ctx); *rshift =20 ;return 0 ; }
scrub/read_verify.c +18 -2
@@ -70,6 +70,22 @@ struct read_verify_pool {int runtime_error; }; +unsigned int +read_verify_nproc ( +struct scrub_ctx *ctx) +{ +if (force_nr_threads) +return force_nr_threads; + +/* +* Throwing all CPUs at verifying seems like a bad idea for foreground +* scrub, as does abusing I/O opt/min as that says absolutely nothing +* about parallelism. The authors observed diminishing returns on +* verification speed past 8 IO threads, so that's the default. +*/ +return 8 ; +} +/* * Create a thread pool to run read verifiers. *
@@ -84,8 +100,8 @@ read_verify_pool_alloc( struct read_verify_pool **prvp) {struct read_verify_pool *rvp; -unsigned int verifier_threads = -disk_heads (ctx->verify_disks[XFS_DEV_DATA ]); +const unsigned int verifier_threads = +read_verify_nproc (ctx);int ret;if (rvp_io_max_size () % ctx->mnt.fsgeom.blocksize)
PATCH 13/21 xfs_scrub: move disk media verification error injection
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
This isn't really disk-related since it's a knob to make the read_verify_pool pretend that the media is defective. Move this code before we add a new media verify path that doesn't require the disk abstraction.
--- scrub/disk.c | 71 ------------------------------------------- scrub/read_verify.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 73 deletions(-)
scrub/disk.c +0 -71
@@ -266,63 +266,6 @@ disk_close(#define LBASIZE (d) (1ULL << (d)->d_lbalog)#define BTOLBA (d, bytes) (((uint64_t)(bytes) + LBASIZE(d) - 1) >> (d)->d_lbalog) -/* Simulate disk errors. */ -static int -disk_simulate_read_error ( -struct disk *disk, -uint64_t start, -uint64_t *length) -{ -static int64_t interval; -uint64_t start_interval; - -/* Simulated disk errors are disabled. */ -if (interval <0 ) -return 0 ; - -/* Figure out the disk read error interval. */ -if (interval ==0 ) { -char *p; - -/* Pretend there's bad media every so often, in bytes. */ - p =getenv ("XFS_SCRUB_DISK_ERROR_INTERVAL" ); -if (p ==NULL ) { - interval =-1 ; -return 0 ; - } - interval =strtoull (p,NULL ,10 ); - interval &= ~((1U << disk->d_lbalog) -1 ); - } -if (interval <=0 ) { - interval =-1 ; -return 0 ; - } - -/* -* We simulate disk errors by pretending that there are media errors at -* predetermined intervals across the disk. If a read verify request -* crosses one of those intervals we shorten it so that the next read -* will start on an interval threshold. If the read verify request -* starts on an interval threshold, we send back EIO as if it had -* failed. -*/ -if ((start % interval) ==0 ) { -dbg_printf ("fd %d: simulating disk error at %" PRIu64".\n" , - disk->d_fd, start); -return EIO ; - } - - start_interval = start / interval; -if (start_interval != (start + *length) / interval) { - *length = ((start_interval +1 ) * interval) - start; -dbg_printf ( -"fd %d: simulating short read at %" PRIu64" to length %" PRIu64".\n" , - disk->d_fd, start, *length); - } - -return 0 ; -} -/* Read-verify an extent of a disk device. */ ssize_t disk_read_verify(
@@ -331,20 +274,6 @@ disk_read_verify( uint64_t start, uint64_t length) { - if (debug) { - int ret; - - ret =disk_simulate_read_error (disk, start, &length); -if (ret) { - errno = ret; -return -1 ; - } - -/* Don't actually issue the IO */ -if (getenv ("XFS_SCRUB_DISK_VERIFY_SKIP" )) -return length; - } -/* Convert to logical block size. */ if (disk->d_flags &DISK_FLAG_SCSI_VERIFY ) return disk_scsi_verify(disk, BTOLBAT(disk, start),
scrub/read_verify.c +83 -2
97 lines not on this page · raw message
PATCH 14/21 xfs_scrub: use the verify media ioctl during phase 6 if possible
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
If the kernel suppots the XFS_IOC_VERIFY_MEDIA ioctl, use that to perform the phase 6 media scan instead of pwrite or the SCSI VERIFY command. This enables better integration with xfs_healer and fsnotify; and reduces the amount of work that userspace has to do.
--- scrub/xfs_scrub.h | 1 + scrub/phase1.c | 18 ++++++++++++++++++ scrub/read_verify.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 4 deletions(-)
scrub/xfs_scrub.h +1 -0
@@ -79,6 +79,7 @@ struct scrub_ctx {/* Data block read verification buffer */ void *readbuf; +bool no_verify_ioctl;/* Mutable scrub state; use lock. */ pthread_mutex_t lock;
scrub/phase1.c +18 -0
@@ -213,6 +213,22 @@ mode_from_autofsck( goto summarize; } +/* Does the XFS driver support media scanning its own disks? */ +static void +configure_xfs_verify ( +struct scrub_ctx *ctx) +{ +struct xfs_verify_media me = { +/* just probe for support using an empty range */ + .me_start_daddr =0 , + .me_end_daddr =0 , + .me_dev =XFS_DEV_DATA , + }; + +if (ioctl (ctx->mnt.fd,XFS_IOC_VERIFY_MEDIA , &me)) + ctx->no_verify_ioctl = true; +} +/* * Bind to the mountpoint, read the XFS geometry, bind to the block devices. * Anything we've already built will be cleaned up by scrub_cleanup.
@@ -379,6 +395,8 @@ _("Unable to find realtime device path.")); } } +configure_xfs_verify (ctx); +/* * Everything's set up, which means any failures recorded after * this point are most probably corruption errors (as opposed to
scrub/read_verify.c +40 -4
67 lines not on this page · raw message
PATCH 15/21 scrub: don't allocate disk for ioctl-based media verify
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
When the kernel provides the data verification ioctl there is no point in allocating struct disk and thus opening the underlying devices. Refactor the code so that we don't have to do that, with the added benefit of keeping the read verification self-contained in read_verify.c for the case where the kernel provides the ioctl.
--- scrub/phase1.c | 65 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 20 deletions(-)
scrub/phase1.c +45 -20
@@ -213,8 +213,39 @@ mode_from_autofsck( goto summarize; } +/* +* We can't do XFS_IOC_VERIFY_MEDIA media verification, so we need to fall back +* to reading the disk. We already opened the data device, now we need to open +* the rt and log devices for media verification. +*/ +static int +configure_xfs_verify_fallback ( +struct scrub_ctx *ctx) +{ +if (ctx->fsinfo.fs_log) { + ctx->verify_disks[XFS_DEV_LOG ] =disk_open (ctx->fsinfo.fs_log); +if (!ctx->verify_disks[XFS_DEV_LOG ]) { +str_error (ctx, ctx->mntpoint, +_ ("Unable to open external log device." )); +return ECANCELED ; + } + } + +if (ctx->fsinfo.fs_rt) { + ctx->verify_disks[XFS_DEV_RT ] =disk_open (ctx->fsinfo.fs_rt); +if (!ctx->verify_disks[XFS_DEV_RT ]) { +str_error (ctx, ctx->mntpoint, +_ ("Unable to open realtime device." )); +return ECANCELED ; + } + } + + ctx->no_verify_ioctl = true; +return 0 ; +} +/* Does the XFS driver support media scanning its own disks? */ -static void +static bool configure_xfs_verify (struct scrub_ctx *ctx) {
@@ -225,8 +256,7 @@ configure_xfs_verify( .me_dev = XFS_DEV_DATA, }; -if (ioctl (ctx->mnt.fd,XFS_IOC_VERIFY_MEDIA , &me)) - ctx->no_verify_ioctl = true; +return ioctl (ctx->mnt.fd,XFS_IOC_VERIFY_MEDIA , &me) ==0 ; }/*
@@ -378,24 +408,19 @@ _("Unable to find realtime device path."));fflush (stdout); } -if (ctx->fsinfo.fs_log) { - ctx->verify_disks[XFS_DEV_LOG ] =disk_open (ctx->fsinfo.fs_log); -if (!ctx->verify_disks[XFS_DEV_LOG ]) { -str_error (ctx, ctx->mntpoint, -_ ("Unable to open external log device." )); -return ECANCELED ; - } +if (configure_xfs_verify (ctx)) { +/* +* ioctl-based media verification is enabled and we already set +* nr_io_threads from the data device, so we no longer need to +* keep this open. +*/ +disk_close (ctx->verify_disks[XFS_DEV_DATA ]); + ctx->verify_disks[XFS_DEV_DATA ] =NULL ; + }else { + error =configure_xfs_verify_fallback (ctx); +if (error) +return error; } -if (ctx->fsinfo.fs_rt) { - ctx->verify_disks[XFS_DEV_RT ] =disk_open (ctx->fsinfo.fs_rt); -if (!ctx->verify_disks[XFS_DEV_RT ]) { -str_error (ctx, ctx->mntpoint, -_ ("Unable to open realtime device." )); -return ECANCELED ; - } - } - -configure_xfs_verify (ctx);/* * Everything's set up, which means any failures recorded after
PATCH 16/21 xfs_scrub: perform media scanning of the log region
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Scan the log area for media errors because a defect in a region could prevent the user from being able to perform log recovery.
--- scrub/fscounters.h | 2 +- scrub/fscounters.c | 4 +++- scrub/phase6.c | 44 ++++++++++++++++++++++++++++++++++++-------- scrub/phase7.c | 7 ++++++- 4 files changed, 46 insertions(+), 11 deletions(-)
scrub/fscounters.h +1 -1
@@ -9,7 +9,7 @@int scrub_scan_estimate_blocks (struct scrub_ctx *ctx,unsigned long long *d_blocks,unsigned long long *d_bfree,unsigned long long *r_blocks,unsigned long long *r_bfree, -unsigned long long *f_files_used); +unsigned long long *f_files_used,unsigned long long *l_blocks);int scrub_count_all_inodes (struct scrub_ctx *ctx,uint64_t *count);#endif /* XFS_SCRUB_FSCOUNTERS_H_ */
scrub/fscounters.c +3 -1
@@ -125,7 +125,8 @@ scrub_scan_estimate_blocks(unsigned long long *d_bfree, unsigned long long *r_blocks, unsigned long long *r_bfree, - unsigned long long *f_files_used) + unsigned long long *f_files_used, + unsigned long long *l_blocks) { struct xfs_fsop_counts fc;int error;
@@ -140,6 +141,7 @@ scrub_scan_estimate_blocks( *r_blocks = ctx->mnt.fsgeom.rtblocks; *r_bfree = fc.freertx * ctx->mnt.fsgeom.rtextsize; *f_files_used = fc.allocino - fc.freeino; + *l_blocks = ctx->mnt.fsgeom.logblocks;return 0 ; }
scrub/phase6.c +36 -8
112 lines not on this page · raw message
scrub/phase7.c +6 -1
@@ -170,6 +170,7 @@ phase7_func(unsigned long long d_bfree;unsigned long long r_blocks;unsigned long long r_bfree; +unsigned long long l_blocks;bool complain;int ip;int error;
@@ -223,7 +224,7 @@ phase7_func( } error =scrub_scan_estimate_blocks (ctx, &d_blocks, &d_bfree, &r_blocks, - &r_bfree, &used_files); + &r_bfree, &used_files, &l_blocks);if (error) {str_liberror (ctx, error,_ ("estimating verify work" ));return error;
@@ -243,6 +244,10 @@ phase7_func( stat_data = totalcount.dbytes; stat_rt = totalcount.rbytes; +/* only count internal logs for data device summary */ +if (!ctx->fsinfo.fs_log) + used_data +=cvt_off_fsb_to_b (&ctx->mnt, l_blocks); +/* * Complain if the counts are off by more than 10% unless * the inaccuracy is less than 32MB worth of blocks or 100 inodes.
PATCH 17/21 xfs_scrub: index read-verify pools by xfs_device ids
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Refactor the read-verify pool array in struct media_verify_state so that we can index them via enum xfs_device. This will enable further cleanups in the next few patches.
--- scrub/phase6.c | 103 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 48 deletions(-)
scrub/phase6.c +55 -48
@@ -42,9 +42,8 @@struct media_verify_state {struct ptvar *verify_schedules; -struct read_verify_pool *rvp_data; -struct read_verify_pool *rvp_log; -struct read_verify_pool *rvp_realtime; +struct read_verify_pool *rvp[XFS_DEV_RT +1 ]; +struct bitmap *d_bad;/* bytes */ struct bitmap *r_bad;/* bytes */ struct bitmap *l_bad;/* bytes */
@@ -53,28 +52,24 @@ struct media_verify_state { bool l_trunc:1; }; -/* Find the fd for a given device identifier. */ -static struct read_verify_pool * -dev_to_pool ( -struct scrub_ctx *ctx, -struct media_verify_state *vs, -dev_t dev) +/* Return XFS device index from fsmap device. */ +static enum xfs_device +from_fsmap_dev ( +struct scrub_ctx *ctx, +dev_t dev) {if (ctx->mnt.fsgeom.rtstart) { -if (dev ==XFS_DEV_DATA ) -return vs->rvp_data; -if (dev ==XFS_DEV_LOG ) -return vs->rvp_log; -if (dev ==XFS_DEV_RT ) -return vs->rvp_realtime; - }else { -if (dev == ctx->fsinfo.fs_datadev) -return vs->rvp_data; -if (dev == ctx->fsinfo.fs_logdev) -return vs->rvp_log; -if (dev == ctx->fsinfo.fs_rtdev) -return vs->rvp_realtime; +if (dev <XFS_DEV_DATA || dev >XFS_DEV_RT ) +abort (); +return dev; } + +if (dev == ctx->fsinfo.fs_datadev) +return XFS_DEV_DATA ; +if (dev == ctx->fsinfo.fs_logdev) +return XFS_DEV_LOG ; +if (dev == ctx->fsinfo.fs_rtdev) +return XFS_DEV_RT ;abort (); }
@@ -611,13 +606,12 @@ check_rmap( void *arg) {struct media_verify_state *vs = arg; -struct read_verify_pool *rvp; +struct read_verify_pool *rvp = + vs->rvp[from_fsmap_dev (ctx, map->fmr_device)];struct read_verify_schedule *rs;bool scheduled;int ret; - rvp =dev_to_pool (ctx, vs, map->fmr_device); - dbg_printf("rmap dev %d:%d phys %"PRIu64" owner %"PRId64 " offset %"PRIu64" len %"PRIu64" flags 0x%x\n", major(map->fmr_device), minor(map->fmr_device),
@@ -686,11 +680,13 @@ force_one_verify(/* Wait for read/verify actions to finish, then return # bytes checked. */ static int clean_pool ( -struct read_verify_pool *rvp, -unsigned long long *bytes_checked) +struct media_verify_state *vs, +enum xfs_device dev, +unsigned long long *bytes_checked) { -uint64_t pool_checked; -int ret; +struct read_verify_pool *rvp = vs->rvp[dev]; +uint64_t pool_checked; +int ret;if (!rvp)return 0 ;
@@ -749,6 +745,27 @@ remember_ioerr(str_liberror (ctx, ret,_ ("setting bad block bitmap" )); } +static inline int +alloc_pool ( +struct scrub_ctx *ctx, +struct media_verify_state *vs, +enum xfs_device dev) +{ +return read_verify_pool_alloc (ctx, dev, remember_ioerr, vs, + &vs->rvp[dev]); +} + +static inline void +free_pool ( +struct media_verify_state *vs, +enum xfs_device dev) +{ +if (vs->rvp[dev]) { +read_verify_pool_abort (vs->rvp[dev]); +read_verify_pool_destroy (vs->rvp[dev]); + } +} +/* * Read verify all the file data blocks in a filesystem. Since XFS doesn't * do data checksums, we trust that the underlying storage will pass back
@@ -782,15 +799,13 @@ phase6_func( goto out_rbad; } - ret =read_verify_pool_alloc (ctx,XFS_DEV_DATA , remember_ioerr, &vs, - &vs.rvp_data); + ret =alloc_pool (ctx, &vs,XFS_DEV_DATA );if (ret) {str_liberror (ctx, ret,_ ("creating datadev media verifier" )); goto out_lbad; }if (ctx->fsinfo.fs_log) { - ret =read_verify_pool_alloc (ctx,XFS_DEV_LOG , remember_ioerr, - &vs, &vs.rvp_log); + ret =alloc_pool (ctx, &vs,XFS_DEV_LOG );if (ret) {str_liberror (ctx, ret,_ ("creating logdev media verifier" ));
@@ -798,8 +813,7 @@ phase6_func( } }if (ctx->fsinfo.fs_rt) { - ret =read_verify_pool_alloc (ctx,XFS_DEV_RT , remember_ioerr, - &vs, &vs.rvp_realtime); + ret =alloc_pool (ctx, &vs,XFS_DEV_RT );if (ret) {str_liberror (ctx, ret,_ ("creating rtdev media verifier" ));
@@ -825,15 +839,15 @@ phase6_func(ptvar_free (vs.verify_schedules); vs.verify_schedules =NULL ; - ret =clean_pool (vs.rvp_data, &ctx->bytes_checked); + ret =clean_pool (&vs,XFS_DEV_DATA , &ctx->bytes_checked);if (ret)str_liberror (ctx, ret,_ ("flushing datadev verify pool" )); - ret2 =clean_pool (vs.rvp_log, &ctx->bytes_checked); + ret2 =clean_pool (&vs,XFS_DEV_LOG , &ctx->bytes_checked);if (ret2)str_liberror (ctx, ret2,_ ("flushing logdev verify pool" )); - ret3 =clean_pool (vs.rvp_realtime, &ctx->bytes_checked); + ret3 =clean_pool (&vs,XFS_DEV_RT , &ctx->bytes_checked);if (ret3)str_liberror (ctx, ret3,_ ("flushing rtdev verify pool" ));
@@ -861,18 +875,11 @@ phase6_func( out_schedules:ptvar_free (vs.verify_schedules); out_rtpool: -if (vs.rvp_realtime) { -read_verify_pool_abort (vs.rvp_realtime); -read_verify_pool_destroy (vs.rvp_realtime); - } +free_pool (&vs,XFS_DEV_RT ); out_logpool: -if (vs.rvp_log) { -read_verify_pool_abort (vs.rvp_log); -read_verify_pool_destroy (vs.rvp_log); - } +free_pool (&vs,XFS_DEV_LOG ); out_datapool: -read_verify_pool_abort (vs.rvp_data); -read_verify_pool_destroy (vs.rvp_data); +free_pool (&vs,XFS_DEV_DATA ); out_lbad:bitmap_free (&vs.l_bad); out_rbad:
PATCH 18/21 xfs_scrub: move failmap and other outputs into read_verify_pool
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Remove all the indirect verify IO error function calls and whatnot by making the read_verify_pool track the ranges of failed media and other problems. Add some new helper functions that report on the outcome of the read verifciation so that phase6 can report on what happened.
--- scrub/read_verify.h | 13 +++- scrub/phase6.c | 184 +++++++++++++-------------------------------------- scrub/read_verify.c | 145 +++++++++++++++++++++++++++++++++++----- 3 files changed, 184 insertions(+), 158 deletions(-)
scrub/read_verify.h +11 -2
@@ -21,7 +21,6 @@ typedef void (*read_verify_ioerr_fn_t)(struct scrub_ctx *ctx, int error, void *arg);int read_verify_pool_alloc (struct scrub_ctx *ctx,enum xfs_device dev, -read_verify_ioerr_fn_t ioerr_fn,void *ioerr_arg,struct read_verify_pool **prvp);void read_verify_pool_abort (struct read_verify_pool *rvp);int read_verify_pool_flush (struct read_verify_pool *rvp);
@@ -31,7 +30,17 @@ int read_verify_schedule_now(struct read_verify_schedule *rs);bool try_read_verify_schedule_io (struct read_verify_schedule *rs,struct read_verify_pool *rvp,uint64_t start,uint64_t length); -int read_verify_bytes (struct read_verify_pool *rvp,uint64_t *bytes); +bool read_verify_ok (const struct read_verify_pool *rvp); +bool read_verify_truncated (const struct read_verify_pool *rvp); +uint64_t read_verify_progress (const struct read_verify_pool *rvp); + +int read_verify_iterate_failed (struct read_verify_pool *rvp, +int (*fn)(uint64_t ,uint64_t ,void *),void *arg); +int read_verify_iterate_failed_range (struct read_verify_pool *rvp, +uint64_t start,uint64_t length, +int (*fn)(uint64_t ,uint64_t ,void *),void *arg); +bool read_verify_has_failed (struct read_verify_pool *rvp,uint64_t start, +uint64_t len);unsigned int read_verify_nproc (struct scrub_ctx *ctx);
scrub/phase6.c +47 -137
311 lines not on this page · raw message
scrub/read_verify.c +126 -19
228 lines not on this page · raw message
PATCH 19/21 xfs_scrub: clean up device-related error messages
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Use consistent terminology for the data/log/rt device in the error messages.
--- scrub/phase6.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
scrub/phase6.c +8 -8
@@ -551,7 +551,7 @@ report_all_media_errors( ret =report_disk_ioerrs (ctx, vs,XFS_DEV_DATA );if (ret) { -str_liberror (ctx, ret,_ ("walking datadev io errors" )); +str_liberror (ctx, ret,_ ("walking data device io errors" ));return ret; }
@@ -563,7 +563,7 @@ report_all_media_errors( ret =report_disk_ioerrs (ctx, vs,XFS_DEV_RT );if (ret) { -str_liberror (ctx, ret,_ ("walking rtdev io errors" )); +str_liberror (ctx, ret,_ ("walking rt device io errors" ));return ret; }
@@ -725,14 +725,14 @@ phase6_func( ret =alloc_pool (ctx, &vs,XFS_DEV_DATA );if (ret) { -str_liberror (ctx, ret,_ ("creating datadev media verifier" )); +str_liberror (ctx, ret,_ ("creating data device media verifier" ));return ret; }if (ctx->fsinfo.fs_log) { ret =alloc_pool (ctx, &vs,XFS_DEV_LOG );if (ret) {str_liberror (ctx, ret, -_ ("creating logdev media verifier" )); +_ ("creating log device media verifier" )); goto out_datapool; } }
@@ -740,7 +740,7 @@ phase6_func( ret =alloc_pool (ctx, &vs,XFS_DEV_RT );if (ret) {str_liberror (ctx, ret, -_ ("creating rtdev media verifier" )); +_ ("creating rt device media verifier" )); goto out_logpool; } }
@@ -765,15 +765,15 @@ phase6_func( ret =clean_pool (&vs,XFS_DEV_DATA , &ctx->bytes_checked, &ok);if (ret) -str_liberror (ctx, ret,_ ("flushing datadev verify pool" )); +str_liberror (ctx, ret,_ ("flushing data device verify pool" )); ret2 =clean_pool (&vs,XFS_DEV_LOG , &ctx->bytes_checked, &ok);if (ret2) -str_liberror (ctx, ret2,_ ("flushing logdev verify pool" )); +str_liberror (ctx, ret2,_ ("flushing log device verify pool" )); ret3 =clean_pool (&vs,XFS_DEV_RT , &ctx->bytes_checked, &ok);if (ret3) -str_liberror (ctx, ret3,_ ("flushing rtdev verify pool" )); +str_liberror (ctx, ret3,_ ("flushing rt device verify pool" ));/* * If the verify flush didn't work or we found no bad blocks, we're
PATCH 20/21 xfs_scrub: drop SCSI_VERIFY code from disk.
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Now that we have a media verification ioctl in the kernel, drop the SCSI_VERIFY code, which enables us to drop the dependency on sg and obviates the need to fix some unit-handling bugs in the HDIO_GETGEO code.
A subsequent patch will enable larger verification IO sizes, which this old code cannot handle.
--- scrub/disk.h | 2 - doc/README-env-vars.txt | 1 scrub/disk.c | 133 ----------------------------------------------- scrub/read_verify.c | 5 -- scrub/xfs_scrub.c | 1 5 files changed, 1 insertion(+), 141 deletions(-)
scrub/disk.h +0 -2
@@ -6,7 +6,6 @@ #ifndef XFS_SCRUB_DISK_H_ #define XFS_SCRUB_DISK_H_ -#define DISK_FLAG_SCSI_VERIFY 0x1 struct disk { struct stat d_sb; int d_fd;
@@ -15,7 +14,6 @@ struct disk {unsigned int d_flags;unsigned int d_blksize;/* bytes */ uint64_t d_size;/* bytes */ -uint64_t d_start;/* bytes */ };unsigned int disk_heads (struct disk *disk);
doc/README-env-vars.txt +0 -1
@@ -17,7 +17,6 @@ Known debug tweaks (pass -d and set the environment variable): XFS_SCRUB_FORCE_ERROR -- pretend all metadata is corrupt XFS_SCRUB_FORCE_REPAIR -- repair all metadata even if it's ok XFS_SCRUB_NO_KERNEL -- pretend there is no kernel ioctl -XFS_SCRUB_NO_SCSI_VERIFY -- disable SCSI VERIFY (if present) XFS_SCRUB_PHASE -- run only this scrub phase XFS_SCRUB_THREADS -- start exactly this number of threads
scrub/disk.c +0 -133
173 lines not on this page · raw message
scrub/read_verify.c +1 -4
@@ -27,10 +27,7 @@* pool takes care of issuing multiple IOs to the device, if possible. */ -/* -* Perform all IO in 32M chunks. This cannot exceed 65536 sectors -* because that's the biggest SCSI VERIFY(16) we dare to send. -*/ +/* Perform all verification IO in 32M chunks. */ #define RVP_IO_MAX_SIZE (33554432)/*
scrub/xfs_scrub.c +0 -1
@@ -111,7 +111,6 @@* XFS_SCRUB_FORCE_ERROR -- pretend all metadata is corrupt * XFS_SCRUB_FORCE_REPAIR -- repair all metadata even if it's ok * XFS_SCRUB_NO_KERNEL -- pretend there is no kernel ioctl -* XFS_SCRUB_NO_SCSI_VERIFY -- disable SCSI VERIFY (if present) * XFS_SCRUB_PHASE -- run only this scrub phase * XFS_SCRUB_THREADS -- start exactly this number of threads * XFS_SCRUB_DISK_ERROR_INTERVAL-- simulate a disk error every this many bytes
PATCH 21/21 xfs_scrub: raise media verification IO limits
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
To avoid starving other threads of disk IO resources, the read-verify pool limits the size of verification IOs to limit bandwidth consumption, and it is willing to over-verify some amount of unwritten media to reduce the number of verification IO requests sent to the device.
However, these limits were set in 2018 when areal densities were lower and disk bandwidth was more limited. Increase them now to reduce scan time on the author's system by 10% in foreground and 50% in background mode.
--- scrub/read_verify.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)
scrub/read_verify.c +23 -8
@@ -10,6 +10,7 @@#include "libfrog/workqueue.h" #include "libfrog/paths.h" #include "libfrog/bitmap.h" +#include "libfrog/convert.h" #include "xfs_scrub.h" #include "common.h" #include "counter.h"
@@ -28,23 +29,36 @@*/ /* Perform all verification IO in 32M chunks. */ -#define RVP_IO_MAX_SIZE (33554432) +#define RVP_IO_MAX_SIZE MEGABYTES(32)/* -* If we're running in the background then we perform IO in 128k chunks +* If we're running in the background then we perform IO in 256k chunks * to reduce the load on the IO subsystem. */ -#define RVP_BACKGROUND_IO_MAX_SIZE (131072) +#define RVP_BG_IO_MAX_SIZE KILOBYTES(256)/* What's the real maximum IO size? */ static inline unsigned int rvp_io_max_size (void ) { -return bg_mode >0 ?RVP_BACKGROUND_IO_MAX_SIZE :RVP_IO_MAX_SIZE ; +return bg_mode >0 ?RVP_BG_IO_MAX_SIZE :RVP_IO_MAX_SIZE ; } -/* Tolerate 64k holes in adjacent read verify requests. */ -#define RVP_IO_BATCH_LOCALITY (65536) +/* Tolerate 2M holes in adjacent read verify requests. */ +#define RVP_IO_BATCH_LOCALITY MEGABYTES(2) + +/* +* Tolerate 256k holes in adjacent read verify requests when running in the +* background. +*/ +#define RVP_BG_IO_BATCH_LOCALITY KILOBYTES(256) + +/* How many holes are we willing to verify to reduce IO count? */ +static inline unsigned int +rvp_io_batch_locality (void ) +{ +return bg_mode >0 ?RVP_BG_IO_BATCH_LOCALITY :RVP_IO_BATCH_LOCALITY ; +}struct read_verify {uint64_t io_start;/* bytes */
@@ -500,6 +514,7 @@ try_read_verify_schedule_io( {uint64_t req_end;uint64_t rv_end; +const unsigned int locality =rvp_io_batch_locality ();assert (rvp->readbuf);
@@ -525,9 +540,9 @@ try_read_verify_schedule_io(* we can combine them. */ if (rs->rvp == rvp && rs->io_length >0 && - ((start >= rs->io_start && start <= rv_end +RVP_IO_BATCH_LOCALITY ) || + ((start >= rs->io_start && start <= rv_end + locality) || (rs->io_start >= start && - rs->io_start <= req_end +RVP_IO_BATCH_LOCALITY ))) { + rs->io_start <= req_end + locality))) { rs->io_start =min (rs->io_start, start); rs->io_length =max (req_end, rv_end) - rs->io_start;