summaryrefslogtreecommitdiff
path: root/drivers/md/raid10.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.com>2017-03-15 14:05:13 +1100
committerShaohua Li <shli@fb.com>2017-03-22 19:17:24 -0700
commit6b6c8110e173ce10f2b169d82a6670001f7184d1 (patch)
treed7d2603e322b4671f50a4fe3a4e904013deea686 /drivers/md/raid10.c
parent97d53438081edd25ccb1de34051efe084d240828 (diff)
md/raid1, raid10: move rXbio accounting closer to allocation.
When raid1 or raid10 find they will need to allocate a new r1bio/r10bio, in order to work around a known bad block, they account for the allocation well before the allocation is made. This separation makes the correctness less obvious and requires comments. The accounting needs to be a little before: before the first rXbio is submitted, but that is all. So move the accounting down to where it makes more sense. Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: Shaohua Li <shli@fb.com>
Diffstat (limited to 'drivers/md/raid10.c')
-rw-r--r--drivers/md/raid10.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index e89a8d78a9ed..c7c5b2693fc9 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1384,18 +1384,8 @@ retry_write:
goto retry_write;
}
- if (max_sectors < r10_bio->sectors) {
- /* We are splitting this into multiple parts, so
- * we need to prepare for allocating another r10_bio.
- */
+ if (max_sectors < r10_bio->sectors)
r10_bio->sectors = max_sectors;
- spin_lock_irq(&conf->device_lock);
- if (bio->bi_phys_segments == 0)
- bio->bi_phys_segments = 2;
- else
- bio->bi_phys_segments++;
- spin_unlock_irq(&conf->device_lock);
- }
sectors_handled = r10_bio->sector + max_sectors -
bio->bi_iter.bi_sector;
@@ -1505,10 +1495,16 @@ retry_write:
*/
if (sectors_handled < bio_sectors(bio)) {
- one_write_done(r10_bio);
- /* We need another r10_bio. It has already been counted
+ /* We need another r10_bio and it needs to be counted
* in bio->bi_phys_segments.
*/
+ spin_lock_irq(&conf->device_lock);
+ if (bio->bi_phys_segments == 0)
+ bio->bi_phys_segments = 2;
+ else
+ bio->bi_phys_segments++;
+ spin_unlock_irq(&conf->device_lock);
+ one_write_done(r10_bio);
r10_bio = mempool_alloc(conf->r10bio_pool, GFP_NOIO);
r10_bio->master_bio = bio;