Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] dm: map and endio return code clarification

Tighten the use of return values from the target map and end_io functions.
Values of 2 and above are now explictly reserved for future use. There are no
existing targets using such values.

The patch has no effect on existing behaviour.

o Reserve return values of 2 and above from target map functions.
Any positive value currently indicates "mapping complete", but all
existing drivers use the value 1. We now make that a requirement
so we can assign new meaning to higher values in future.

The new definition of return values from target map functions is:
< 0 : error
= 0 : The target will handle the io (DM_MAPIO_SUBMITTED).
= 1 : Mapping completed (DM_MAPIO_REMAPPED).
> 1 : Reserved (undefined). Previously this was the same as '= 1'.

o Reserve return values of 2 and above from target end_io functions
for similar reasons.
DM_ENDIO_INCOMPLETE is introduced for a return value of 1.

Test results:

I have tested by using the multipath target.

I/Os succeed when valid paths exist.

I/Os are queued in the multipath target when there are no valid paths and
queue_if_no_path is set.

I/Os fail when there are no valid paths and queue_if_no_path is not set.

Signed-off-by: Kiyoshi Ueda <k-ueda@ct.jp.nec.com>
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Cc: dm-devel@redhat.com
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Kiyoshi Ueda and committed by
Linus Torvalds
45cbcd79 a3d77d35

+22 -4
+10 -3
drivers/md/dm.c
··· 482 482 r = endio(tio->ti, bio, error, &tio->info); 483 483 if (r < 0) 484 484 error = r; 485 - else if (r > 0) 486 - /* the target wants another shot at the io */ 485 + else if (r == DM_ENDIO_INCOMPLETE) 486 + /* The target will handle the io */ 487 487 return 1; 488 + else if (r) { 489 + DMWARN("unimplemented target endio return value: %d", r); 490 + BUG(); 491 + } 488 492 } 489 493 490 494 dec_pending(tio->io, error); ··· 546 542 atomic_inc(&tio->io->io_count); 547 543 sector = clone->bi_sector; 548 544 r = ti->type->map(ti, clone, &tio->info); 549 - if (r > 0) { 545 + if (r == DM_MAPIO_REMAPPED) { 550 546 /* the bio has been remapped so dispatch it */ 551 547 552 548 blk_add_trace_remap(bdev_get_queue(clone->bi_bdev), clone, ··· 564 560 clone->bi_private = md->bs; 565 561 bio_put(clone); 566 562 free_tio(md, tio); 563 + } else if (r) { 564 + DMWARN("unimplemented target map return value: %d", r); 565 + BUG(); 567 566 } 568 567 } 569 568
+11
drivers/md/dm.h
··· 33 33 #define SECTOR_SHIFT 9 34 34 35 35 /* 36 + * Definitions of return values from target end_io function. 37 + */ 38 + #define DM_ENDIO_INCOMPLETE 1 39 + 40 + /* 41 + * Definitions of return values from target map function. 42 + */ 43 + #define DM_MAPIO_SUBMITTED 0 44 + #define DM_MAPIO_REMAPPED 1 45 + 46 + /* 36 47 * Suspend feature flags 37 48 */ 38 49 #define DM_SUSPEND_LOCKFS_FLAG (1 << 0)
+1 -1
include/linux/device-mapper.h
··· 39 39 * The map function must return: 40 40 * < 0: error 41 41 * = 0: The target will handle the io by resubmitting it later 42 - * > 0: simple remap complete 42 + * = 1: simple remap complete 43 43 */ 44 44 typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio, 45 45 union map_info *map_context);