Skip to content

Commit 846785e

Browse files
Christoph Hellwigaxboe
authored andcommitted
dm: don't return errnos from ->map
Instead use the special DM_MAPIO_KILL return value to return -EIO just like we do for the request based path. Note that dm-log-writes returned -ENOMEM in a few places, which now becomes -EIO instead. No consumer treats -ENOMEM special so this shouldn't be an issue (and it should use a mempool to start with to make guaranteed progress). Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 14ef1e4 commit 846785e

File tree

11 files changed

+46
-33
lines changed

11 files changed

+46
-33
lines changed

drivers/md/dm-crypt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,10 +2795,10 @@ static int crypt_map(struct dm_target *ti, struct bio *bio)
27952795
* and is aligned to this size as defined in IO hints.
27962796
*/
27972797
if (unlikely((bio->bi_iter.bi_sector & ((cc->sector_size >> SECTOR_SHIFT) - 1)) != 0))
2798-
return -EIO;
2798+
return DM_MAPIO_KILL;
27992799

28002800
if (unlikely(bio->bi_iter.bi_size & (cc->sector_size - 1)))
2801-
return -EIO;
2801+
return DM_MAPIO_KILL;
28022802

28032803
io = dm_per_bio_data(bio, cc->per_bio_data_size);
28042804
crypt_io_init(io, cc, bio, dm_target_offset(ti, bio->bi_iter.bi_sector));

drivers/md/dm-flakey.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static int flakey_map(struct dm_target *ti, struct bio *bio)
321321
if (bio_data_dir(bio) == READ) {
322322
if (!fc->corrupt_bio_byte && !test_bit(DROP_WRITES, &fc->flags) &&
323323
!test_bit(ERROR_WRITES, &fc->flags))
324-
return -EIO;
324+
return DM_MAPIO_KILL;
325325
goto map_bio;
326326
}
327327

@@ -349,7 +349,7 @@ static int flakey_map(struct dm_target *ti, struct bio *bio)
349349
/*
350350
* By default, error all I/O.
351351
*/
352-
return -EIO;
352+
return DM_MAPIO_KILL;
353353
}
354354

355355
map_bio:

drivers/md/dm-integrity.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,13 +1352,13 @@ static int dm_integrity_map(struct dm_target *ti, struct bio *bio)
13521352
DMERR("Too big sector number: 0x%llx + 0x%x > 0x%llx",
13531353
(unsigned long long)dio->range.logical_sector, bio_sectors(bio),
13541354
(unsigned long long)ic->provided_data_sectors);
1355-
return -EIO;
1355+
return DM_MAPIO_KILL;
13561356
}
13571357
if (unlikely((dio->range.logical_sector | bio_sectors(bio)) & (unsigned)(ic->sectors_per_block - 1))) {
13581358
DMERR("Bio not aligned on %u sectors: 0x%llx, 0x%x",
13591359
ic->sectors_per_block,
13601360
(unsigned long long)dio->range.logical_sector, bio_sectors(bio));
1361-
return -EIO;
1361+
return DM_MAPIO_KILL;
13621362
}
13631363

13641364
if (ic->sectors_per_block > 1) {
@@ -1368,7 +1368,7 @@ static int dm_integrity_map(struct dm_target *ti, struct bio *bio)
13681368
if (unlikely((bv.bv_offset | bv.bv_len) & ((ic->sectors_per_block << SECTOR_SHIFT) - 1))) {
13691369
DMERR("Bio vector (%u,%u) is not aligned on %u-sector boundary",
13701370
bv.bv_offset, bv.bv_len, ic->sectors_per_block);
1371-
return -EIO;
1371+
return DM_MAPIO_KILL;
13721372
}
13731373
}
13741374
}
@@ -1383,18 +1383,18 @@ static int dm_integrity_map(struct dm_target *ti, struct bio *bio)
13831383
wanted_tag_size *= ic->tag_size;
13841384
if (unlikely(wanted_tag_size != bip->bip_iter.bi_size)) {
13851385
DMERR("Invalid integrity data size %u, expected %u", bip->bip_iter.bi_size, wanted_tag_size);
1386-
return -EIO;
1386+
return DM_MAPIO_KILL;
13871387
}
13881388
}
13891389
} else {
13901390
if (unlikely(bip != NULL)) {
13911391
DMERR("Unexpected integrity data when using internal hash");
1392-
return -EIO;
1392+
return DM_MAPIO_KILL;
13931393
}
13941394
}
13951395

13961396
if (unlikely(ic->mode == 'R') && unlikely(dio->write))
1397-
return -EIO;
1397+
return DM_MAPIO_KILL;
13981398

13991399
get_area_and_offset(ic, dio->range.logical_sector, &area, &offset);
14001400
dio->metadata_block = get_metadata_sector_and_offset(ic, area, offset, &dio->metadata_offset);

drivers/md/dm-log-writes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ static int log_writes_map(struct dm_target *ti, struct bio *bio)
586586
spin_lock_irq(&lc->blocks_lock);
587587
lc->logging_enabled = false;
588588
spin_unlock_irq(&lc->blocks_lock);
589-
return -ENOMEM;
589+
return DM_MAPIO_KILL;
590590
}
591591
INIT_LIST_HEAD(&block->list);
592592
pb->block = block;
@@ -639,7 +639,7 @@ static int log_writes_map(struct dm_target *ti, struct bio *bio)
639639
spin_lock_irq(&lc->blocks_lock);
640640
lc->logging_enabled = false;
641641
spin_unlock_irq(&lc->blocks_lock);
642-
return -ENOMEM;
642+
return DM_MAPIO_KILL;
643643
}
644644

645645
src = kmap_atomic(bv.bv_page);

drivers/md/dm-mpath.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ static int __multipath_map_bio(struct multipath *m, struct bio *bio, struct dm_m
559559
if (test_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags))
560560
return DM_MAPIO_REQUEUE;
561561
dm_report_EIO(m);
562-
return -EIO;
562+
return DM_MAPIO_KILL;
563563
}
564564

565565
mpio->pgpath = pgpath;
@@ -621,11 +621,18 @@ static void process_queued_bios(struct work_struct *work)
621621
blk_start_plug(&plug);
622622
while ((bio = bio_list_pop(&bios))) {
623623
r = __multipath_map_bio(m, bio, get_mpio_from_bio(bio));
624-
if (r < 0 || r == DM_MAPIO_REQUEUE) {
624+
switch (r) {
625+
case DM_MAPIO_KILL:
626+
r = -EIO;
627+
/*FALLTHRU*/
628+
case DM_MAPIO_REQUEUE:
625629
bio->bi_error = r;
626630
bio_endio(bio);
627-
} else if (r == DM_MAPIO_REMAPPED)
631+
break;
632+
case DM_MAPIO_REMAPPED:
628633
generic_make_request(bio);
634+
break;
635+
}
629636
}
630637
blk_finish_plug(&plug);
631638
}

drivers/md/dm-raid1.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,14 +1207,14 @@ static int mirror_map(struct dm_target *ti, struct bio *bio)
12071207

12081208
r = log->type->in_sync(log, dm_rh_bio_to_region(ms->rh, bio), 0);
12091209
if (r < 0 && r != -EWOULDBLOCK)
1210-
return r;
1210+
return DM_MAPIO_KILL;
12111211

12121212
/*
12131213
* If region is not in-sync queue the bio.
12141214
*/
12151215
if (!r || (r == -EWOULDBLOCK)) {
12161216
if (bio->bi_opf & REQ_RAHEAD)
1217-
return -EIO;
1217+
return DM_MAPIO_KILL;
12181218

12191219
queue_bio(ms, bio, rw);
12201220
return DM_MAPIO_SUBMITTED;
@@ -1226,7 +1226,7 @@ static int mirror_map(struct dm_target *ti, struct bio *bio)
12261226
*/
12271227
m = choose_mirror(ms, bio->bi_iter.bi_sector);
12281228
if (unlikely(!m))
1229-
return -EIO;
1229+
return DM_MAPIO_KILL;
12301230

12311231
dm_bio_record(&bio_record->details, bio);
12321232
bio_record->m = m;

drivers/md/dm-snap.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,15 +1690,15 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio)
16901690
/* Full snapshots are not usable */
16911691
/* To get here the table must be live so s->active is always set. */
16921692
if (!s->valid)
1693-
return -EIO;
1693+
return DM_MAPIO_KILL;
16941694

16951695
/* FIXME: should only take write lock if we need
16961696
* to copy an exception */
16971697
down_write(&s->lock);
16981698

16991699
if (!s->valid || (unlikely(s->snapshot_overflowed) &&
17001700
bio_data_dir(bio) == WRITE)) {
1701-
r = -EIO;
1701+
r = DM_MAPIO_KILL;
17021702
goto out_unlock;
17031703
}
17041704

@@ -1723,7 +1723,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio)
17231723

17241724
if (!s->valid || s->snapshot_overflowed) {
17251725
free_pending_exception(pe);
1726-
r = -EIO;
1726+
r = DM_MAPIO_KILL;
17271727
goto out_unlock;
17281728
}
17291729

@@ -1741,7 +1741,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio)
17411741
DMERR("Snapshot overflowed: Unable to allocate exception.");
17421742
} else
17431743
__invalidate_snapshot(s, -ENOMEM);
1744-
r = -EIO;
1744+
r = DM_MAPIO_KILL;
17451745
goto out_unlock;
17461746
}
17471747
}

drivers/md/dm-target.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static void io_err_dtr(struct dm_target *tt)
128128

129129
static int io_err_map(struct dm_target *tt, struct bio *bio)
130130
{
131-
return -EIO;
131+
return DM_MAPIO_KILL;
132132
}
133133

134134
static int io_err_clone_and_map_rq(struct dm_target *ti, struct request *rq,

drivers/md/dm-verity-target.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,17 +643,17 @@ static int verity_map(struct dm_target *ti, struct bio *bio)
643643
if (((unsigned)bio->bi_iter.bi_sector | bio_sectors(bio)) &
644644
((1 << (v->data_dev_block_bits - SECTOR_SHIFT)) - 1)) {
645645
DMERR_LIMIT("unaligned io");
646-
return -EIO;
646+
return DM_MAPIO_KILL;
647647
}
648648

649649
if (bio_end_sector(bio) >>
650650
(v->data_dev_block_bits - SECTOR_SHIFT) > v->data_blocks) {
651651
DMERR_LIMIT("io out of range");
652-
return -EIO;
652+
return DM_MAPIO_KILL;
653653
}
654654

655655
if (bio_data_dir(bio) == WRITE)
656-
return -EIO;
656+
return DM_MAPIO_KILL;
657657

658658
io = dm_per_bio_data(bio, ti->per_io_data_size);
659659
io->v = v;

drivers/md/dm-zero.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ static int zero_map(struct dm_target *ti, struct bio *bio)
3939
case REQ_OP_READ:
4040
if (bio->bi_opf & REQ_RAHEAD) {
4141
/* readahead of null bytes only wastes buffer cache */
42-
return -EIO;
42+
return DM_MAPIO_KILL;
4343
}
4444
zero_fill_bio(bio);
4545
break;
4646
case REQ_OP_WRITE:
4747
/* writes get silently dropped */
4848
break;
4949
default:
50-
return -EIO;
50+
return DM_MAPIO_KILL;
5151
}
5252

5353
bio_endio(bio);

drivers/md/dm.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,18 +1084,24 @@ static void __map_bio(struct dm_target_io *tio)
10841084
r = ti->type->map(ti, clone);
10851085
dm_offload_end(&o);
10861086

1087-
if (r == DM_MAPIO_REMAPPED) {
1087+
switch (r) {
1088+
case DM_MAPIO_SUBMITTED:
1089+
break;
1090+
case DM_MAPIO_REMAPPED:
10881091
/* the bio has been remapped so dispatch it */
1089-
10901092
trace_block_bio_remap(bdev_get_queue(clone->bi_bdev), clone,
10911093
tio->io->bio->bi_bdev->bd_dev, sector);
1092-
10931094
generic_make_request(clone);
1094-
} else if (r < 0 || r == DM_MAPIO_REQUEUE) {
1095+
break;
1096+
case DM_MAPIO_KILL:
1097+
r = -EIO;
1098+
/*FALLTHRU*/
1099+
case DM_MAPIO_REQUEUE:
10951100
/* error the io and bail out, or requeue it if needed */
10961101
dec_pending(tio->io, r);
10971102
free_tio(tio);
1098-
} else if (r != DM_MAPIO_SUBMITTED) {
1103+
break;
1104+
default:
10991105
DMWARN("unimplemented target map return value: %d", r);
11001106
BUG();
11011107
}

0 commit comments

Comments
 (0)