// SPDX-License-Identifier: GPL-2.0 /* Maximum size of each resync request */ #define RESYNC_BLOCK_SIZE (64*1024) #define RESYNC_PAGES ((RESYNC_BLOCK_SIZE + PAGE_SIZE-1) / PAGE_SIZE)
/* * Number of guaranteed raid bios in case of extreme VM load:
*/ #define NR_RAID_BIOS 256
/* when we get a read error on a read-only array, we redirect to another * device without failing the first device, or trying to over-write to * correct the read error. To keep track of bad blocks on a per-bio * level, we store IO_BLOCKED in the appropriate 'bios' pointer
*/ #define IO_BLOCKED ((struct bio *)1) /* When we successfully write to a known bad-block, we need to remove the * bad-block marking which must be done from process context. So we record * the success by setting devs[n].bio to IO_MADE_GOOD
*/ #define IO_MADE_GOOD ((struct bio *)2)
/* * 'strct resync_pages' stores actual pages used for doing the resync * IO, and it is per-bio, so make .bi_private points to it.
*/ staticinlinestruct resync_pages *get_resync_pages(struct bio *bio)
{ return bio->bi_private;
}
/* generally called after bio_reset() for reseting bvec */ staticvoid md_bio_reset_resync_pages(struct bio *bio, struct resync_pages *rp, int size)
{ int idx = 0;
/* initialize bvec table again */ do { struct page *page = resync_fetch_page(rp, idx); int len = min_t(int, size, PAGE_SIZE);
bio->bi_next = NULL;
bio_set_dev(bio, rdev->bdev); if (test_bit(Faulty, &rdev->flags))
bio_io_error(bio); elseif (unlikely(bio_op(bio) == REQ_OP_DISCARD &&
!bdev_max_discard_sectors(bio->bi_bdev))) /* Just ignore it */
bio_endio(bio); else
submit_bio_noacct(bio);
}
staticinlinebool raid1_add_bio_to_plug(struct mddev *mddev, struct bio *bio,
blk_plug_cb_fn unplug, int copies)
{ struct raid1_plug_cb *plug = NULL; struct blk_plug_cb *cb;
/* * If bitmap is not enabled, it's safe to submit the io directly, and * this can get optimal performance.
*/ if (!mddev->bitmap_ops->enabled(mddev)) {
raid1_submit_write(bio); returntrue;
}
cb = blk_check_plugged(unplug, mddev, sizeof(*plug)); if (!cb) returnfalse;
/* * current->bio_list will be set under submit_bio() context, in this case bitmap * io will be added to the list and wait for current io submission to finish, * while current io submission must wait for bitmap io to be done. In order to * avoid such deadlock, submit bitmap io asynchronously.
*/ staticinlinevoid raid1_prepare_flush_writes(struct mddev *mddev)
{
mddev->bitmap_ops->unplug(mddev, current->bio_list == NULL);
}
/* * Used by fix_read_error() to decay the per rdev read_errors. * We halve the read error count for every hour that has elapsed * since the last recorded read error.
*/ staticinlinevoid check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
{ long cur_time_mon; unsignedlong hours_since_last; unsignedint read_errors = atomic_read(&rdev->read_errors);
cur_time_mon = ktime_get_seconds();
if (rdev->last_read_error == 0) { /* first time we've seen a read error */
rdev->last_read_error = cur_time_mon; return;
}
/* * if hours_since_last is > the number of bits in read_errors * just set read errors to 0. We do this to avoid * overflowing the shift of read_errors by hours_since_last.
*/ if (hours_since_last >= 8 * sizeof(read_errors))
atomic_set(&rdev->read_errors, 0); else
atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
}
staticinlinebool exceed_read_errors(struct mddev *mddev, struct md_rdev *rdev)
{ int max_read_errors = atomic_read(&mddev->max_corr_read_errors); int read_errors;
/** * raid1_check_read_range() - check a given read range for bad blocks, * available read length is returned; * @rdev: the rdev to read; * @this_sector: read position; * @len: read length; * * helper function for read_balance() * * 1) If there are no bad blocks in the range, @len is returned; * 2) If the range are all bad blocks, 0 is returned; * 3) If there are partial bad blocks: * - If the bad block range starts after @this_sector, the length of first * good region is returned; * - If the bad block range starts before @this_sector, 0 is returned and * the @len is updated to the offset into the region before we get to the * good blocks;
*/ staticinlineint raid1_check_read_range(struct md_rdev *rdev,
sector_t this_sector, int *len)
{
sector_t first_bad;
sector_t bad_sectors;
/* no bad block overlap */ if (!is_badblock(rdev, this_sector, *len, &first_bad, &bad_sectors)) return *len;
/* * bad block range starts offset into our range so we can return the * number of sectors before the bad blocks start.
*/ if (first_bad > this_sector) return first_bad - this_sector;
/* read range is fully consumed by bad blocks. */ if (this_sector + *len <= first_bad + bad_sectors) return 0;
/* * final case, bad block range starts before or at the start of our * range but does not cover our entire range so we still return 0 but * update the length with the number of sectors before we get to the * good ones.
*/
*len = first_bad + bad_sectors - this_sector; return 0;
}
/* * Check if read should choose the first rdev. * * Balance on the whole device if no resync is going on (recovery is ok) or * below the resync window. Otherwise, take the first readable disk.
*/ staticinlinebool raid1_should_read_first(struct mddev *mddev,
sector_t this_sector, int len)
{ if ((mddev->resync_offset < this_sector + len)) returntrue;
if (mddev_is_clustered(mddev) &&
mddev->cluster_ops->area_resyncing(mddev, READ, this_sector,
this_sector + len)) returntrue;
returnfalse;
}
/* * bio with REQ_RAHEAD or REQ_NOWAIT can fail at anytime, before such IO is * submitted to the underlying disks, hence don't record badblocks or retry * in this case.
*/ staticinlinebool raid1_should_handle_error(struct bio *bio)
{ return !(bio->bi_opf & (REQ_RAHEAD | REQ_NOWAIT));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.