Skip to content

Commit

Permalink
dm raid1: dont use map_context
Browse files Browse the repository at this point in the history
Don't use map_info any more in dm-raid1.

map_info was used for writes to hold the region number. For this purpose
we add a new field dm_bio_details to dm_raid1_bio_record.

map_info was used for reads to hold a pointer to dm_raid1_bio_record (if
the pointer was non-NULL, bio details were saved; if the pointer was
NULL, bio details were not saved). We use
dm_raid1_bio_record.details->bi_bdev for this purpose. If bi_bdev is
NULL, details were not saved, if bi_bdev is non-NULL, details were
saved.

Signed-off-by: Mikulas Patocka <[email protected]>
Signed-off-by: Alasdair G Kergon <[email protected]>
  • Loading branch information
Mikulas Patocka authored and kergon committed Dec 21, 2012
1 parent c7cfdf5 commit 0045d61
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions drivers/md/dm-raid1.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ static void dispatch_bios(void *context, struct bio_list *bio_list)

struct dm_raid1_bio_record {
struct mirror *m;
/* if details->bi_bdev == NULL, details were not saved */
struct dm_bio_details details;
region_t write_region;
};

/*
Expand Down Expand Up @@ -1146,12 +1148,15 @@ static int mirror_map(struct dm_target *ti, struct bio *bio,
int r, rw = bio_rw(bio);
struct mirror *m;
struct mirror_set *ms = ti->private;
struct dm_raid1_bio_record *bio_record;
struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
struct dm_raid1_bio_record *bio_record =
dm_per_bio_data(bio, sizeof(struct dm_raid1_bio_record));

bio_record->details.bi_bdev = NULL;

if (rw == WRITE) {
/* Save region for mirror_end_io() handler */
map_context->ll = dm_rh_bio_to_region(ms->rh, bio);
bio_record->write_region = dm_rh_bio_to_region(ms->rh, bio);
queue_bio(ms, bio, rw);
return DM_MAPIO_SUBMITTED;
}
Expand Down Expand Up @@ -1179,9 +1184,7 @@ static int mirror_map(struct dm_target *ti, struct bio *bio,
if (unlikely(!m))
return -EIO;

bio_record = dm_per_bio_data(bio, sizeof(struct dm_raid1_bio_record));
dm_bio_record(&bio_record->details, bio);
map_context->ptr = bio_record;
bio_record->m = m;

map_bio(m, bio);
Expand All @@ -1196,14 +1199,15 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio,
struct mirror_set *ms = (struct mirror_set *) ti->private;
struct mirror *m = NULL;
struct dm_bio_details *bd = NULL;
struct dm_raid1_bio_record *bio_record = map_context->ptr;
struct dm_raid1_bio_record *bio_record =
dm_per_bio_data(bio, sizeof(struct dm_raid1_bio_record));

/*
* We need to dec pending if this was a write.
*/
if (rw == WRITE) {
if (!(bio->bi_rw & (REQ_FLUSH | REQ_DISCARD)))
dm_rh_dec(ms->rh, map_context->ll);
dm_rh_dec(ms->rh, bio_record->write_region);
return error;
}

Expand All @@ -1214,7 +1218,7 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio,
goto out;

if (unlikely(error)) {
if (!bio_record) {
if (!bio_record->details.bi_bdev) {
/*
* There wasn't enough memory to record necessary
* information for a retry or there was no other
Expand All @@ -1239,15 +1243,15 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio,
bd = &bio_record->details;

dm_bio_restore(bd, bio);
map_context->ptr = NULL;
bio_record->details.bi_bdev = NULL;
queue_bio(ms, bio, rw);
return DM_ENDIO_INCOMPLETE;
}
DMERR("All replicated volumes dead, failing I/O");
}

out:
map_context->ptr = NULL;
bio_record->details.bi_bdev = NULL;

return error;
}
Expand Down

0 comments on commit 0045d61

Please sign in to comment.