md/raid1: small cleanup in raid1_end_read/write_request
Both functions use conf->mirrors[mirror].rdev several times, so improve readability by storing this in a local variable. Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Shaohua Li <shli@fb.com>
This commit is contained in:
@ -319,14 +319,13 @@ static void raid1_end_read_request(struct bio *bio)
|
|||||||
{
|
{
|
||||||
int uptodate = !bio->bi_error;
|
int uptodate = !bio->bi_error;
|
||||||
struct r1bio *r1_bio = bio->bi_private;
|
struct r1bio *r1_bio = bio->bi_private;
|
||||||
int mirror;
|
|
||||||
struct r1conf *conf = r1_bio->mddev->private;
|
struct r1conf *conf = r1_bio->mddev->private;
|
||||||
|
struct md_rdev *rdev = conf->mirrors[r1_bio->read_disk].rdev;
|
||||||
|
|
||||||
mirror = r1_bio->read_disk;
|
|
||||||
/*
|
/*
|
||||||
* this branch is our 'one mirror IO has finished' event handler:
|
* this branch is our 'one mirror IO has finished' event handler:
|
||||||
*/
|
*/
|
||||||
update_head_pos(mirror, r1_bio);
|
update_head_pos(r1_bio->read_disk, r1_bio);
|
||||||
|
|
||||||
if (uptodate)
|
if (uptodate)
|
||||||
set_bit(R1BIO_Uptodate, &r1_bio->state);
|
set_bit(R1BIO_Uptodate, &r1_bio->state);
|
||||||
@ -339,14 +338,14 @@ static void raid1_end_read_request(struct bio *bio)
|
|||||||
spin_lock_irqsave(&conf->device_lock, flags);
|
spin_lock_irqsave(&conf->device_lock, flags);
|
||||||
if (r1_bio->mddev->degraded == conf->raid_disks ||
|
if (r1_bio->mddev->degraded == conf->raid_disks ||
|
||||||
(r1_bio->mddev->degraded == conf->raid_disks-1 &&
|
(r1_bio->mddev->degraded == conf->raid_disks-1 &&
|
||||||
test_bit(In_sync, &conf->mirrors[mirror].rdev->flags)))
|
test_bit(In_sync, &rdev->flags)))
|
||||||
uptodate = 1;
|
uptodate = 1;
|
||||||
spin_unlock_irqrestore(&conf->device_lock, flags);
|
spin_unlock_irqrestore(&conf->device_lock, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uptodate) {
|
if (uptodate) {
|
||||||
raid_end_bio_io(r1_bio);
|
raid_end_bio_io(r1_bio);
|
||||||
rdev_dec_pending(conf->mirrors[mirror].rdev, conf->mddev);
|
rdev_dec_pending(rdev, conf->mddev);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* oops, read error:
|
* oops, read error:
|
||||||
@ -356,7 +355,7 @@ static void raid1_end_read_request(struct bio *bio)
|
|||||||
KERN_ERR "md/raid1:%s: %s: "
|
KERN_ERR "md/raid1:%s: %s: "
|
||||||
"rescheduling sector %llu\n",
|
"rescheduling sector %llu\n",
|
||||||
mdname(conf->mddev),
|
mdname(conf->mddev),
|
||||||
bdevname(conf->mirrors[mirror].rdev->bdev,
|
bdevname(rdev->bdev,
|
||||||
b),
|
b),
|
||||||
(unsigned long long)r1_bio->sector);
|
(unsigned long long)r1_bio->sector);
|
||||||
set_bit(R1BIO_ReadError, &r1_bio->state);
|
set_bit(R1BIO_ReadError, &r1_bio->state);
|
||||||
@ -403,20 +402,18 @@ static void r1_bio_write_done(struct r1bio *r1_bio)
|
|||||||
static void raid1_end_write_request(struct bio *bio)
|
static void raid1_end_write_request(struct bio *bio)
|
||||||
{
|
{
|
||||||
struct r1bio *r1_bio = bio->bi_private;
|
struct r1bio *r1_bio = bio->bi_private;
|
||||||
int mirror, behind = test_bit(R1BIO_BehindIO, &r1_bio->state);
|
int behind = test_bit(R1BIO_BehindIO, &r1_bio->state);
|
||||||
struct r1conf *conf = r1_bio->mddev->private;
|
struct r1conf *conf = r1_bio->mddev->private;
|
||||||
struct bio *to_put = NULL;
|
struct bio *to_put = NULL;
|
||||||
|
int mirror = find_bio_disk(r1_bio, bio);
|
||||||
mirror = find_bio_disk(r1_bio, bio);
|
struct md_rdev *rdev = conf->mirrors[mirror].rdev;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 'one mirror IO has finished' event handler:
|
* 'one mirror IO has finished' event handler:
|
||||||
*/
|
*/
|
||||||
if (bio->bi_error) {
|
if (bio->bi_error) {
|
||||||
set_bit(WriteErrorSeen,
|
set_bit(WriteErrorSeen, &rdev->flags);
|
||||||
&conf->mirrors[mirror].rdev->flags);
|
if (!test_and_set_bit(WantReplacement, &rdev->flags))
|
||||||
if (!test_and_set_bit(WantReplacement,
|
|
||||||
&conf->mirrors[mirror].rdev->flags))
|
|
||||||
set_bit(MD_RECOVERY_NEEDED, &
|
set_bit(MD_RECOVERY_NEEDED, &
|
||||||
conf->mddev->recovery);
|
conf->mddev->recovery);
|
||||||
|
|
||||||
@ -445,13 +442,12 @@ static void raid1_end_write_request(struct bio *bio)
|
|||||||
* before rdev->recovery_offset, but for simplicity we don't
|
* before rdev->recovery_offset, but for simplicity we don't
|
||||||
* check this here.
|
* check this here.
|
||||||
*/
|
*/
|
||||||
if (test_bit(In_sync, &conf->mirrors[mirror].rdev->flags) &&
|
if (test_bit(In_sync, &rdev->flags) &&
|
||||||
!test_bit(Faulty, &conf->mirrors[mirror].rdev->flags))
|
!test_bit(Faulty, &rdev->flags))
|
||||||
set_bit(R1BIO_Uptodate, &r1_bio->state);
|
set_bit(R1BIO_Uptodate, &r1_bio->state);
|
||||||
|
|
||||||
/* Maybe we can clear some bad blocks. */
|
/* Maybe we can clear some bad blocks. */
|
||||||
if (is_badblock(conf->mirrors[mirror].rdev,
|
if (is_badblock(rdev, r1_bio->sector, r1_bio->sectors,
|
||||||
r1_bio->sector, r1_bio->sectors,
|
|
||||||
&first_bad, &bad_sectors)) {
|
&first_bad, &bad_sectors)) {
|
||||||
r1_bio->bios[mirror] = IO_MADE_GOOD;
|
r1_bio->bios[mirror] = IO_MADE_GOOD;
|
||||||
set_bit(R1BIO_MadeGood, &r1_bio->state);
|
set_bit(R1BIO_MadeGood, &r1_bio->state);
|
||||||
@ -459,7 +455,7 @@ static void raid1_end_write_request(struct bio *bio)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (behind) {
|
if (behind) {
|
||||||
if (test_bit(WriteMostly, &conf->mirrors[mirror].rdev->flags))
|
if (test_bit(WriteMostly, &rdev->flags))
|
||||||
atomic_dec(&r1_bio->behind_remaining);
|
atomic_dec(&r1_bio->behind_remaining);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -483,8 +479,7 @@ static void raid1_end_write_request(struct bio *bio)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (r1_bio->bios[mirror] == NULL)
|
if (r1_bio->bios[mirror] == NULL)
|
||||||
rdev_dec_pending(conf->mirrors[mirror].rdev,
|
rdev_dec_pending(rdev, conf->mddev);
|
||||||
conf->mddev);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Let's see if all mirrored write operations have finished
|
* Let's see if all mirrored write operations have finished
|
||||||
|
Reference in New Issue
Block a user