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

dm: allow error target to replace bio-based and request-based targets

It may be useful to switch a request-based table to the "error" target.
Enhance the DM core to allow a hybrid target_type which is capable of
handling either bios (via .map) or requests (via .map_rq).

Add a request-based map function (.map_rq) to the "error" target_type;
making it DM's first hybrid target. Train dm_table_set_type() to prefer
the mapped device's established type (request-based or bio-based). If
the mapped device doesn't have an established type default to making the
table with the hybrid target(s) bio-based.

Tested 'dmsetup wipe_table' to work on both bio-based and request-based
devices.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Joe Jin <joe.jin@oracle.com>
Signed-off-by: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
Acked-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>

+39 -3
+20 -2
drivers/md/dm-table.c
··· 860 860 static int dm_table_set_type(struct dm_table *t) 861 861 { 862 862 unsigned i; 863 - unsigned bio_based = 0, request_based = 0; 863 + unsigned bio_based = 0, request_based = 0, hybrid = 0; 864 864 struct dm_target *tgt; 865 865 struct dm_dev_internal *dd; 866 866 struct list_head *devices; 867 + unsigned live_md_type; 867 868 868 869 for (i = 0; i < t->num_targets; i++) { 869 870 tgt = t->targets + i; 870 - if (dm_target_request_based(tgt)) 871 + if (dm_target_hybrid(tgt)) 872 + hybrid = 1; 873 + else if (dm_target_request_based(tgt)) 871 874 request_based = 1; 872 875 else 873 876 bio_based = 1; ··· 880 877 " can't be mixed up"); 881 878 return -EINVAL; 882 879 } 880 + } 881 + 882 + if (hybrid && !bio_based && !request_based) { 883 + /* 884 + * The targets can work either way. 885 + * Determine the type from the live device. 886 + * Default to bio-based if device is new. 887 + */ 888 + dm_lock_md_type(t->md); 889 + live_md_type = dm_get_md_type(t->md); 890 + dm_unlock_md_type(t->md); 891 + if (live_md_type == DM_TYPE_REQUEST_BASED) 892 + request_based = 1; 893 + else 894 + bio_based = 1; 883 895 } 884 896 885 897 if (bio_based) {
+8 -1
drivers/md/dm-target.c
··· 131 131 return -EIO; 132 132 } 133 133 134 + static int io_err_map_rq(struct dm_target *ti, struct request *clone, 135 + union map_info *map_context) 136 + { 137 + return -EIO; 138 + } 139 + 134 140 static struct target_type error_target = { 135 141 .name = "error", 136 - .version = {1, 1, 0}, 142 + .version = {1, 2, 0}, 137 143 .ctr = io_err_ctr, 138 144 .dtr = io_err_dtr, 139 145 .map = io_err_map, 146 + .map_rq = io_err_map_rq, 140 147 }; 141 148 142 149 int __init dm_target_init(void)
+11
drivers/md/dm.h
··· 89 89 #define dm_target_is_valid(t) ((t)->table) 90 90 91 91 /* 92 + * To check whether the target type is bio-based or not (request-based). 93 + */ 94 + #define dm_target_bio_based(t) ((t)->type->map != NULL) 95 + 96 + /* 92 97 * To check whether the target type is request-based or not (bio-based). 93 98 */ 94 99 #define dm_target_request_based(t) ((t)->type->map_rq != NULL) 100 + 101 + /* 102 + * To check whether the target type is a hybrid (capable of being 103 + * either request-based or bio-based). 104 + */ 105 + #define dm_target_hybrid(t) (dm_target_bio_based(t) && dm_target_request_based(t)) 95 106 96 107 /*----------------------------------------------------------------- 97 108 * A registry of target types.