Skip to content

Commit 1be5690

Browse files
Christoph Hellwigaxboe
authored andcommitted
dm: change ->end_io calling convention
Turn the error paramter into a pointer so that target drivers can change the value, and make sure only DM_ENDIO_* values are returned from the methods. 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 846785e commit 1be5690

File tree

10 files changed

+51
-50
lines changed

10 files changed

+51
-50
lines changed

drivers/md/dm-cache-target.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2820,7 +2820,7 @@ static int cache_map(struct dm_target *ti, struct bio *bio)
28202820
return r;
28212821
}
28222822

2823-
static int cache_end_io(struct dm_target *ti, struct bio *bio, int error)
2823+
static int cache_end_io(struct dm_target *ti, struct bio *bio, int *error)
28242824
{
28252825
struct cache *cache = ti->private;
28262826
unsigned long flags;
@@ -2838,7 +2838,7 @@ static int cache_end_io(struct dm_target *ti, struct bio *bio, int error)
28382838
bio_drop_shared_lock(cache, bio);
28392839
accounted_complete(cache, bio);
28402840

2841-
return 0;
2841+
return DM_ENDIO_DONE;
28422842
}
28432843

28442844
static int write_dirty_bitset(struct cache *cache)

drivers/md/dm-flakey.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,12 @@ static int flakey_map(struct dm_target *ti, struct bio *bio)
358358
return DM_MAPIO_REMAPPED;
359359
}
360360

361-
static int flakey_end_io(struct dm_target *ti, struct bio *bio, int error)
361+
static int flakey_end_io(struct dm_target *ti, struct bio *bio, int *error)
362362
{
363363
struct flakey_c *fc = ti->private;
364364
struct per_bio_data *pb = dm_per_bio_data(bio, sizeof(struct per_bio_data));
365365

366-
if (!error && pb->bio_submitted && (bio_data_dir(bio) == READ)) {
366+
if (!*error && pb->bio_submitted && (bio_data_dir(bio) == READ)) {
367367
if (fc->corrupt_bio_byte && (fc->corrupt_bio_rw == READ) &&
368368
all_corrupt_bio_flags_match(bio, fc)) {
369369
/*
@@ -377,11 +377,11 @@ static int flakey_end_io(struct dm_target *ti, struct bio *bio, int error)
377377
* Error read during the down_interval if drop_writes
378378
* and error_writes were not configured.
379379
*/
380-
return -EIO;
380+
*error = -EIO;
381381
}
382382
}
383383

384-
return error;
384+
return DM_ENDIO_DONE;
385385
}
386386

387387
static void flakey_status(struct dm_target *ti, status_type_t type,

drivers/md/dm-log-writes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ static int log_writes_map(struct dm_target *ti, struct bio *bio)
664664
return DM_MAPIO_REMAPPED;
665665
}
666666

667-
static int normal_end_io(struct dm_target *ti, struct bio *bio, int error)
667+
static int normal_end_io(struct dm_target *ti, struct bio *bio, int *error)
668668
{
669669
struct log_writes_c *lc = ti->private;
670670
struct per_bio_data *pb = dm_per_bio_data(bio, sizeof(struct per_bio_data));
@@ -686,7 +686,7 @@ static int normal_end_io(struct dm_target *ti, struct bio *bio, int error)
686686
spin_unlock_irqrestore(&lc->blocks_lock, flags);
687687
}
688688

689-
return error;
689+
return DM_ENDIO_DONE;
690690
}
691691

692692
/*

drivers/md/dm-mpath.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,14 +1517,15 @@ static int multipath_end_io(struct dm_target *ti, struct request *clone,
15171517
return r;
15181518
}
15191519

1520-
static int multipath_end_io_bio(struct dm_target *ti, struct bio *clone, int error)
1520+
static int multipath_end_io_bio(struct dm_target *ti, struct bio *clone, int *error)
15211521
{
15221522
struct multipath *m = ti->private;
15231523
struct dm_mpath_io *mpio = get_mpio_from_bio(clone);
15241524
struct pgpath *pgpath = mpio->pgpath;
15251525
unsigned long flags;
1526+
int r = DM_ENDIO_DONE;
15261527

1527-
if (!error || noretry_error(error))
1528+
if (!*error || noretry_error(*error))
15281529
goto done;
15291530

15301531
if (pgpath)
@@ -1533,7 +1534,7 @@ static int multipath_end_io_bio(struct dm_target *ti, struct bio *clone, int err
15331534
if (atomic_read(&m->nr_valid_paths) == 0 &&
15341535
!test_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags)) {
15351536
dm_report_EIO(m);
1536-
error = -EIO;
1537+
*error = -EIO;
15371538
goto done;
15381539
}
15391540

@@ -1546,7 +1547,7 @@ static int multipath_end_io_bio(struct dm_target *ti, struct bio *clone, int err
15461547
if (!test_bit(MPATHF_QUEUE_IO, &m->flags))
15471548
queue_work(kmultipathd, &m->process_queued_bios);
15481549

1549-
error = DM_ENDIO_INCOMPLETE;
1550+
r = DM_ENDIO_INCOMPLETE;
15501551
done:
15511552
if (pgpath) {
15521553
struct path_selector *ps = &pgpath->pg->ps;
@@ -1555,7 +1556,7 @@ static int multipath_end_io_bio(struct dm_target *ti, struct bio *clone, int err
15551556
ps->type->end_io(ps, &pgpath->path, mpio->nr_bytes);
15561557
}
15571558

1558-
return error;
1559+
return r;
15591560
}
15601561

15611562
/*

drivers/md/dm-raid1.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ static int mirror_map(struct dm_target *ti, struct bio *bio)
12361236
return DM_MAPIO_REMAPPED;
12371237
}
12381238

1239-
static int mirror_end_io(struct dm_target *ti, struct bio *bio, int error)
1239+
static int mirror_end_io(struct dm_target *ti, struct bio *bio, int *error)
12401240
{
12411241
int rw = bio_data_dir(bio);
12421242
struct mirror_set *ms = (struct mirror_set *) ti->private;
@@ -1252,16 +1252,16 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio, int error)
12521252
if (!(bio->bi_opf & REQ_PREFLUSH) &&
12531253
bio_op(bio) != REQ_OP_DISCARD)
12541254
dm_rh_dec(ms->rh, bio_record->write_region);
1255-
return error;
1255+
return DM_ENDIO_DONE;
12561256
}
12571257

1258-
if (error == -EOPNOTSUPP)
1259-
return error;
1258+
if (*error == -EOPNOTSUPP)
1259+
return DM_ENDIO_DONE;
12601260

12611261
if (bio->bi_opf & REQ_RAHEAD)
1262-
return error;
1262+
return DM_ENDIO_DONE;
12631263

1264-
if (unlikely(error)) {
1264+
if (unlikely(*error)) {
12651265
m = bio_record->m;
12661266

12671267
DMERR("Mirror read failed from %s. Trying alternative device.",
@@ -1285,7 +1285,7 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio, int error)
12851285
DMERR("All replicated volumes dead, failing I/O");
12861286
}
12871287

1288-
return error;
1288+
return DM_ENDIO_DONE;
12891289
}
12901290

12911291
static void mirror_presuspend(struct dm_target *ti)

drivers/md/dm-snap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,14 +1851,14 @@ static int snapshot_merge_map(struct dm_target *ti, struct bio *bio)
18511851
return r;
18521852
}
18531853

1854-
static int snapshot_end_io(struct dm_target *ti, struct bio *bio, int error)
1854+
static int snapshot_end_io(struct dm_target *ti, struct bio *bio, int *error)
18551855
{
18561856
struct dm_snapshot *s = ti->private;
18571857

18581858
if (is_bio_tracked(bio))
18591859
stop_tracking_chunk(s, bio);
18601860

1861-
return 0;
1861+
return DM_ENDIO_DONE;
18621862
}
18631863

18641864
static void snapshot_merge_presuspend(struct dm_target *ti)

drivers/md/dm-stripe.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -375,20 +375,20 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
375375
}
376376
}
377377

378-
static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
378+
static int stripe_end_io(struct dm_target *ti, struct bio *bio, int *error)
379379
{
380380
unsigned i;
381381
char major_minor[16];
382382
struct stripe_c *sc = ti->private;
383383

384-
if (!error)
385-
return 0; /* I/O complete */
384+
if (!*error)
385+
return DM_ENDIO_DONE; /* I/O complete */
386386

387387
if (bio->bi_opf & REQ_RAHEAD)
388-
return error;
388+
return DM_ENDIO_DONE;
389389

390-
if (error == -EOPNOTSUPP)
391-
return error;
390+
if (*error == -EOPNOTSUPP)
391+
return DM_ENDIO_DONE;
392392

393393
memset(major_minor, 0, sizeof(major_minor));
394394
sprintf(major_minor, "%d:%d",
@@ -409,7 +409,7 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
409409
schedule_work(&sc->trigger_event);
410410
}
411411

412-
return error;
412+
return DM_ENDIO_DONE;
413413
}
414414

415415
static int stripe_iterate_devices(struct dm_target *ti,

drivers/md/dm-thin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4177,7 +4177,7 @@ static int thin_map(struct dm_target *ti, struct bio *bio)
41774177
return thin_bio_map(ti, bio);
41784178
}
41794179

4180-
static int thin_endio(struct dm_target *ti, struct bio *bio, int err)
4180+
static int thin_endio(struct dm_target *ti, struct bio *bio, int *err)
41814181
{
41824182
unsigned long flags;
41834183
struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
@@ -4212,7 +4212,7 @@ static int thin_endio(struct dm_target *ti, struct bio *bio, int err)
42124212
if (h->cell)
42134213
cell_defer_no_holder(h->tc, h->cell);
42144214

4215-
return 0;
4215+
return DM_ENDIO_DONE;
42164216
}
42174217

42184218
static void thin_presuspend(struct dm_target *ti)

drivers/md/dm.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -845,24 +845,7 @@ static void clone_endio(struct bio *bio)
845845
struct mapped_device *md = tio->io->md;
846846
dm_endio_fn endio = tio->ti->type->end_io;
847847

848-
if (endio) {
849-
r = endio(tio->ti, bio, error);
850-
if (r < 0 || r == DM_ENDIO_REQUEUE)
851-
/*
852-
* error and requeue request are handled
853-
* in dec_pending().
854-
*/
855-
error = r;
856-
else if (r == DM_ENDIO_INCOMPLETE)
857-
/* The target will handle the io */
858-
return;
859-
else if (r) {
860-
DMWARN("unimplemented target endio return value: %d", r);
861-
BUG();
862-
}
863-
}
864-
865-
if (unlikely(r == -EREMOTEIO)) {
848+
if (unlikely(error == -EREMOTEIO)) {
866849
if (bio_op(bio) == REQ_OP_WRITE_SAME &&
867850
!bdev_get_queue(bio->bi_bdev)->limits.max_write_same_sectors)
868851
disable_write_same(md);
@@ -871,6 +854,23 @@ static void clone_endio(struct bio *bio)
871854
disable_write_zeroes(md);
872855
}
873856

857+
if (endio) {
858+
r = endio(tio->ti, bio, &error);
859+
switch (r) {
860+
case DM_ENDIO_REQUEUE:
861+
error = DM_ENDIO_REQUEUE;
862+
/*FALLTHRU*/
863+
case DM_ENDIO_DONE:
864+
break;
865+
case DM_ENDIO_INCOMPLETE:
866+
/* The target will handle the io */
867+
return;
868+
default:
869+
DMWARN("unimplemented target endio return value: %d", r);
870+
BUG();
871+
}
872+
}
873+
874874
free_tio(tio);
875875
dec_pending(io, error);
876876
}

include/linux/device-mapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ typedef void (*dm_release_clone_request_fn) (struct request *clone);
7272
* 2 : The target wants to push back the io
7373
*/
7474
typedef int (*dm_endio_fn) (struct dm_target *ti,
75-
struct bio *bio, int error);
75+
struct bio *bio, int *error);
7676
typedef int (*dm_request_endio_fn) (struct dm_target *ti,
7777
struct request *clone, int error,
7878
union map_info *map_context);

0 commit comments

Comments
 (0)