Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 78d7f5f7 authored by NeilBrown's avatar NeilBrown
Browse files

md/raid1: tidy up new functions: process_checks and fix_sync_read_error.



These changes are mostly cosmetic:

1/ change mddev->raid_disks to conf->raid_disks because the later is
   technically safer, though in current practice it doesn't matter in
   this particular context.
2/ Rearrange two for / if loops to have an early 'continue' so the
   body of the 'if' doesn't need to be indented so much.

Signed-off-by: default avatarNeilBrown <neilb@suse.de>
parent a68e5870
Loading
Loading
Loading
Loading
+95 −89
Original line number Diff line number Diff line
@@ -1203,6 +1203,7 @@ static int fix_sync_read_error(r1bio_t *r1_bio)
		int d = r1_bio->read_disk;
		int success = 0;
		mdk_rdev_t *rdev;
		int start;

		if (s > (PAGE_SIZE>>9))
			s = PAGE_SIZE >> 9;
@@ -1227,10 +1228,22 @@ static int fix_sync_read_error(r1bio_t *r1_bio)
				d = 0;
		} while (!success && d != r1_bio->read_disk);

		if (success) {
			int start = d;
		if (!success) {
			char b[BDEVNAME_SIZE];
			/* Cannot read from anywhere, array is toast */
			md_error(mddev, conf->mirrors[r1_bio->read_disk].rdev);
			printk(KERN_ALERT "md/raid1:%s: %s: unrecoverable I/O read error"
			       " for block %llu\n",
			       mdname(mddev),
			       bdevname(bio->bi_bdev, b),
			       (unsigned long long)r1_bio->sector);
			md_done_sync(mddev, r1_bio->sectors, 0);
			put_buf(r1_bio);
			return 0;
		}

		start = d;
		/* write it back and re-read */
			set_bit(R1BIO_Uptodate, &r1_bio->state);
		while (d != r1_bio->read_disk) {
			if (d == 0)
				d = conf->raid_disks;
@@ -1238,13 +1251,16 @@ static int fix_sync_read_error(r1bio_t *r1_bio)
			if (r1_bio->bios[d]->bi_end_io != end_sync_read)
				continue;
			rdev = conf->mirrors[d].rdev;
				atomic_add(s, &rdev->corrected_errors);
			if (sync_page_io(rdev,
					 sect,
					 s<<9,
					 bio->bi_io_vec[idx].bv_page,
						 WRITE, false) == 0)
					 WRITE, false) == 0) {
				r1_bio->bios[d]->bi_end_io = NULL;
				rdev_dec_pending(rdev, mddev);
				md_error(mddev, rdev);
			} else
				atomic_add(s, &rdev->corrected_errors);
		}
		d = start;
		while (d != r1_bio->read_disk) {
@@ -1261,23 +1277,11 @@ static int fix_sync_read_error(r1bio_t *r1_bio)
					 READ, false) == 0)
				md_error(mddev, rdev);
		}
		} else {
			char b[BDEVNAME_SIZE];
			/* Cannot read from anywhere, array is toast */
			md_error(mddev, conf->mirrors[r1_bio->read_disk].rdev);
			printk(KERN_ALERT "md/raid1:%s: %s: unrecoverable I/O read error"
			       " for block %llu\n",
			       mdname(mddev),
			       bdevname(bio->bi_bdev, b),
			       (unsigned long long)r1_bio->sector);
			md_done_sync(mddev, r1_bio->sectors, 0);
			put_buf(r1_bio);
			return 0;
		}
		sectors -= s;
		sect += s;
		idx ++;
	}
	set_bit(R1BIO_Uptodate, &r1_bio->state);
	return 1;
}

@@ -1296,7 +1300,7 @@ static int process_checks(r1bio_t *r1_bio)
	int i;

	if (!test_bit(R1BIO_Uptodate, &r1_bio->state)) {
		for (i=0; i<mddev->raid_disks; i++)
		for (i=0; i < conf->raid_disks; i++)
			if (r1_bio->bios[i]->bi_end_io == end_sync_read)
				md_error(mddev, conf->mirrors[i].rdev);

@@ -1304,7 +1308,7 @@ static int process_checks(r1bio_t *r1_bio)
		put_buf(r1_bio);
		return -1;
	}
	for (primary=0; primary<mddev->raid_disks; primary++)
	for (primary = 0; primary < conf->raid_disks; primary++)
		if (r1_bio->bios[primary]->bi_end_io == end_sync_read &&
		    test_bit(BIO_UPTODATE, &r1_bio->bios[primary]->bi_flags)) {
			r1_bio->bios[primary]->bi_end_io = NULL;
@@ -1312,12 +1316,15 @@ static int process_checks(r1bio_t *r1_bio)
			break;
		}
	r1_bio->read_disk = primary;
	for (i=0; i<mddev->raid_disks; i++)
		if (r1_bio->bios[i]->bi_end_io == end_sync_read) {
	for (i = 0; i < conf->raid_disks; i++) {
		int j;
		int vcnt = r1_bio->sectors >> (PAGE_SHIFT- 9);
		struct bio *pbio = r1_bio->bios[primary];
		struct bio *sbio = r1_bio->bios[i];
		int size;

		if (r1_bio->bios[i]->bi_end_io != end_sync_read)
			continue;

		if (test_bit(BIO_UPTODATE, &sbio->bi_flags)) {
			for (j = vcnt; j-- ; ) {
@@ -1335,11 +1342,12 @@ static int process_checks(r1bio_t *r1_bio)
			mddev->resync_mismatches += r1_bio->sectors;
		if (j < 0 || (test_bit(MD_RECOVERY_CHECK, &mddev->recovery)
			      && test_bit(BIO_UPTODATE, &sbio->bi_flags))) {
			/* No need to write to this device. */
			sbio->bi_end_io = NULL;
			rdev_dec_pending(conf->mirrors[i].rdev, mddev);
			} else {
			continue;
		}
		/* fixup the bio for reuse */
				int size;
		sbio->bi_vcnt = vcnt;
		sbio->bi_size = r1_bio->sectors << 9;
		sbio->bi_idx = 0;
@@ -1364,8 +1372,6 @@ static int process_checks(r1bio_t *r1_bio)
			       page_address(pbio->bi_io_vec[j].bv_page),
			       PAGE_SIZE);
		}

			}
	}
	return 0;
}