aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
authorAlasdair G Kergon <agk@redhat.com>2013-03-01 17:45:46 -0500
committerAlasdair G Kergon <agk@redhat.com>2013-03-01 17:45:46 -0500
commitbd2a49b86d9aae0c505dcc99c0a073f9da2cc889 (patch)
treecf11f71d96195abd2035695c5acf1fd2c0c789b1 /drivers/md
parent88ae4c5294b319431c8c2ec86495b2de295adf62 (diff)
dm: clean up clone_bio
Remove the no-longer-used struct bio_set argument from clone_bio and split_bvec. Use tio->ti in __map_bio() instead of passing in ti. Factor out some code for setting up cloned bios. Take target_request_nr as a parameter to alloc_tio(). Signed-off-by: Mike Snitzer <snitzer@redhat.com> Cc: Joe Thornber <ejt@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/dm.c102
1 files changed, 57 insertions, 45 deletions
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 38486df61f58..4521d72637c2 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -985,12 +985,13 @@ int dm_set_target_max_io_len(struct dm_target *ti, sector_t len)
985} 985}
986EXPORT_SYMBOL_GPL(dm_set_target_max_io_len); 986EXPORT_SYMBOL_GPL(dm_set_target_max_io_len);
987 987
988static void __map_bio(struct dm_target *ti, struct dm_target_io *tio) 988static void __map_bio(struct dm_target_io *tio)
989{ 989{
990 int r; 990 int r;
991 sector_t sector; 991 sector_t sector;
992 struct mapped_device *md; 992 struct mapped_device *md;
993 struct bio *clone = &tio->clone; 993 struct bio *clone = &tio->clone;
994 struct dm_target *ti = tio->ti;
994 995
995 clone->bi_end_io = clone_endio; 996 clone->bi_end_io = clone_endio;
996 clone->bi_private = tio; 997 clone->bi_private = tio;
@@ -1031,32 +1032,54 @@ struct clone_info {
1031 unsigned short idx; 1032 unsigned short idx;
1032}; 1033};
1033 1034
1035static void bio_setup_sector(struct bio *bio, sector_t sector, sector_t len)
1036{
1037 bio->bi_sector = sector;
1038 bio->bi_size = to_bytes(len);
1039}
1040
1041static void bio_setup_bv(struct bio *bio, unsigned short idx, unsigned short bv_count)
1042{
1043 bio->bi_idx = idx;
1044 bio->bi_vcnt = idx + bv_count;
1045 bio->bi_flags &= ~(1 << BIO_SEG_VALID);
1046}
1047
1048static void clone_bio_integrity(struct bio *bio, struct bio *clone,
1049 unsigned short idx, unsigned len, unsigned offset,
1050 unsigned trim)
1051{
1052 if (!bio_integrity(bio))
1053 return;
1054
1055 bio_integrity_clone(clone, bio, GFP_NOIO);
1056
1057 if (trim)
1058 bio_integrity_trim(clone, bio_sector_offset(bio, idx, offset), len);
1059}
1060
1034/* 1061/*
1035 * Creates a little bio that just does part of a bvec. 1062 * Creates a little bio that just does part of a bvec.
1036 */ 1063 */
1037static void split_bvec(struct dm_target_io *tio, struct bio *bio, 1064static void split_bvec(struct dm_target_io *tio, struct bio *bio,
1038 sector_t sector, unsigned short idx, unsigned int offset, 1065 sector_t sector, unsigned short idx, unsigned int offset,
1039 unsigned int len, struct bio_set *bs) 1066 unsigned int len)
1040{ 1067{
1041 struct bio *clone = &tio->clone; 1068 struct bio *clone = &tio->clone;
1042 struct bio_vec *bv = bio->bi_io_vec + idx; 1069 struct bio_vec *bv = bio->bi_io_vec + idx;
1043 1070
1044 *clone->bi_io_vec = *bv; 1071 *clone->bi_io_vec = *bv;
1045 1072
1046 clone->bi_sector = sector; 1073 bio_setup_sector(clone, sector, len);
1074
1047 clone->bi_bdev = bio->bi_bdev; 1075 clone->bi_bdev = bio->bi_bdev;
1048 clone->bi_rw = bio->bi_rw; 1076 clone->bi_rw = bio->bi_rw;
1049 clone->bi_vcnt = 1; 1077 clone->bi_vcnt = 1;
1050 clone->bi_size = to_bytes(len);
1051 clone->bi_io_vec->bv_offset = offset; 1078 clone->bi_io_vec->bv_offset = offset;
1052 clone->bi_io_vec->bv_len = clone->bi_size; 1079 clone->bi_io_vec->bv_len = clone->bi_size;
1053 clone->bi_flags |= 1 << BIO_CLONED; 1080 clone->bi_flags |= 1 << BIO_CLONED;
1054 1081
1055 if (bio_integrity(bio)) { 1082 clone_bio_integrity(bio, clone, idx, len, offset, 1);
1056 bio_integrity_clone(clone, bio, GFP_NOIO);
1057 bio_integrity_trim(clone,
1058 bio_sector_offset(bio, idx, offset), len);
1059 }
1060} 1083}
1061 1084
1062/* 1085/*
@@ -1064,29 +1087,23 @@ static void split_bvec(struct dm_target_io *tio, struct bio *bio,
1064 */ 1087 */
1065static void clone_bio(struct dm_target_io *tio, struct bio *bio, 1088static void clone_bio(struct dm_target_io *tio, struct bio *bio,
1066 sector_t sector, unsigned short idx, 1089 sector_t sector, unsigned short idx,
1067 unsigned short bv_count, unsigned int len, 1090 unsigned short bv_count, unsigned int len)
1068 struct bio_set *bs)
1069{ 1091{
1070 struct bio *clone = &tio->clone; 1092 struct bio *clone = &tio->clone;
1093 unsigned trim = 0;
1071 1094
1072 __bio_clone(clone, bio); 1095 __bio_clone(clone, bio);
1073 clone->bi_sector = sector; 1096 bio_setup_sector(clone, sector, len);
1074 clone->bi_idx = idx; 1097 bio_setup_bv(clone, idx, bv_count);
1075 clone->bi_vcnt = idx + bv_count; 1098
1076 clone->bi_size = to_bytes(len); 1099 if (idx != bio->bi_idx || clone->bi_size < bio->bi_size)
1077 clone->bi_flags &= ~(1 << BIO_SEG_VALID); 1100 trim = 1;
1078 1101 clone_bio_integrity(bio, clone, idx, len, 0, trim);
1079 if (bio_integrity(bio)) {
1080 bio_integrity_clone(clone, bio, GFP_NOIO);
1081
1082 if (idx != bio->bi_idx || clone->bi_size < bio->bi_size)
1083 bio_integrity_trim(clone,
1084 bio_sector_offset(bio, idx, 0), len);
1085 }
1086} 1102}
1087 1103
1088static struct dm_target_io *alloc_tio(struct clone_info *ci, 1104static struct dm_target_io *alloc_tio(struct clone_info *ci,
1089 struct dm_target *ti, int nr_iovecs) 1105 struct dm_target *ti, int nr_iovecs,
1106 unsigned target_request_nr)
1090{ 1107{
1091 struct dm_target_io *tio; 1108 struct dm_target_io *tio;
1092 struct bio *clone; 1109 struct bio *clone;
@@ -1097,7 +1114,7 @@ static struct dm_target_io *alloc_tio(struct clone_info *ci,
1097 tio->io = ci->io; 1114 tio->io = ci->io;
1098 tio->ti = ti; 1115 tio->ti = ti;
1099 memset(&tio->info, 0, sizeof(tio->info)); 1116 memset(&tio->info, 0, sizeof(tio->info));
1100 tio->target_request_nr = 0; 1117 tio->target_request_nr = target_request_nr;
1101 1118
1102 return tio; 1119 return tio;
1103} 1120}
@@ -1105,24 +1122,19 @@ static struct dm_target_io *alloc_tio(struct clone_info *ci,
1105static void __issue_target_request(struct clone_info *ci, struct dm_target *ti, 1122static void __issue_target_request(struct clone_info *ci, struct dm_target *ti,
1106 unsigned request_nr, sector_t len) 1123 unsigned request_nr, sector_t len)
1107{ 1124{
1108 struct dm_target_io *tio = alloc_tio(ci, ti, ci->bio->bi_max_vecs); 1125 struct dm_target_io *tio = alloc_tio(ci, ti, ci->bio->bi_max_vecs, request_nr);
1109 struct bio *clone = &tio->clone; 1126 struct bio *clone = &tio->clone;
1110 1127
1111 tio->target_request_nr = request_nr;
1112
1113 /* 1128 /*
1114 * Discard requests require the bio's inline iovecs be initialized. 1129 * Discard requests require the bio's inline iovecs be initialized.
1115 * ci->bio->bi_max_vecs is BIO_INLINE_VECS anyway, for both flush 1130 * ci->bio->bi_max_vecs is BIO_INLINE_VECS anyway, for both flush
1116 * and discard, so no need for concern about wasted bvec allocations. 1131 * and discard, so no need for concern about wasted bvec allocations.
1117 */ 1132 */
1118
1119 __bio_clone(clone, ci->bio); 1133 __bio_clone(clone, ci->bio);
1120 if (len) { 1134 if (len)
1121 clone->bi_sector = ci->sector; 1135 bio_setup_sector(clone, ci->sector, len);
1122 clone->bi_size = to_bytes(len);
1123 }
1124 1136
1125 __map_bio(ti, tio); 1137 __map_bio(tio);
1126} 1138}
1127 1139
1128static void __issue_target_requests(struct clone_info *ci, struct dm_target *ti, 1140static void __issue_target_requests(struct clone_info *ci, struct dm_target *ti,
@@ -1154,10 +1166,10 @@ static void __clone_and_map_simple(struct clone_info *ci, struct dm_target *ti)
1154 struct bio *bio = ci->bio; 1166 struct bio *bio = ci->bio;
1155 struct dm_target_io *tio; 1167 struct dm_target_io *tio;
1156 1168
1157 tio = alloc_tio(ci, ti, bio->bi_max_vecs); 1169 tio = alloc_tio(ci, ti, bio->bi_max_vecs, 0);
1158 clone_bio(tio, bio, ci->sector, ci->idx, bio->bi_vcnt - ci->idx, 1170 clone_bio(tio, bio, ci->sector, ci->idx, bio->bi_vcnt - ci->idx,
1159 ci->sector_count, ci->md->bs); 1171 ci->sector_count);
1160 __map_bio(ti, tio); 1172 __map_bio(tio);
1161 ci->sector_count = 0; 1173 ci->sector_count = 0;
1162} 1174}
1163 1175
@@ -1271,10 +1283,9 @@ static int __clone_and_map(struct clone_info *ci)
1271 len += bv_len; 1283 len += bv_len;
1272 } 1284 }
1273 1285
1274 tio = alloc_tio(ci, ti, bio->bi_max_vecs); 1286 tio = alloc_tio(ci, ti, bio->bi_max_vecs, 0);
1275 clone_bio(tio, bio, ci->sector, ci->idx, i - ci->idx, len, 1287 clone_bio(tio, bio, ci->sector, ci->idx, i - ci->idx, len);
1276 ci->md->bs); 1288 __map_bio(tio);
1277 __map_bio(ti, tio);
1278 1289
1279 ci->sector += len; 1290 ci->sector += len;
1280 ci->sector_count -= len; 1291 ci->sector_count -= len;
@@ -1299,11 +1310,11 @@ static int __clone_and_map(struct clone_info *ci)
1299 1310
1300 len = min(remaining, max); 1311 len = min(remaining, max);
1301 1312
1302 tio = alloc_tio(ci, ti, 1); 1313 tio = alloc_tio(ci, ti, 1, 0);
1303 split_bvec(tio, bio, ci->sector, ci->idx, 1314 split_bvec(tio, bio, ci->sector, ci->idx,
1304 bv->bv_offset + offset, len, ci->md->bs); 1315 bv->bv_offset + offset, len);
1305 1316
1306 __map_bio(ti, tio); 1317 __map_bio(tio);
1307 1318
1308 ci->sector += len; 1319 ci->sector += len;
1309 ci->sector_count -= len; 1320 ci->sector_count -= len;
@@ -1341,6 +1352,7 @@ static void __split_and_process_bio(struct mapped_device *md, struct bio *bio)
1341 ci.idx = bio->bi_idx; 1352 ci.idx = bio->bi_idx;
1342 1353
1343 start_io_acct(ci.io); 1354 start_io_acct(ci.io);
1355
1344 if (bio->bi_rw & REQ_FLUSH) { 1356 if (bio->bi_rw & REQ_FLUSH) {
1345 ci.bio = &ci.md->flush_bio; 1357 ci.bio = &ci.md->flush_bio;
1346 ci.sector_count = 0; 1358 ci.sector_count = 0;