aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/dm.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-06-12 16:33:29 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-06-12 16:33:29 -0400
commit0e04c641b199435f3779454055f6a7de258ecdfc (patch)
tree9b79da0c52240bf4b96270ac12356ad75da6f739 /drivers/md/dm.c
parent7550cfab3d4053b54f16e2fe337affde71d1eb51 (diff)
parent09869de57ed2728ae3c619803932a86cb0e2c4f8 (diff)
Merge tag 'dm-3.16-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper updates from Mike Snitzer: "This pull request is later than I'd have liked because I was waiting for some performance data to help finally justify sending the long-standing dm-crypt cpu scalability improvements upstream. Unfortunately we came up short, so those dm-crypt changes will continue to wait, but it seems we're not far off. . Add dm_accept_partial_bio interface to DM core to allow DM targets to only process a portion of a bio, the remainder being sent in the next bio. This enables the old dm snapshot-origin target to only split write bios on chunk boundaries, read bios are now sent to the origin device unchanged. . Add DM core support for disabling WRITE SAME if the underlying SCSI layer disables it due to command failure. . Reduce lock contention in DM's bio-prison. . A few small cleanups and fixes to dm-thin and dm-era" * tag 'dm-3.16-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm thin: update discard_granularity to reflect the thin-pool blocksize dm bio prison: implement per bucket locking in the dm_bio_prison hash table dm: remove symbol export for dm_set_device_limits dm: disable WRITE SAME if it fails dm era: check for a non-NULL metadata object before closing it dm thin: return ENOSPC instead of EIO when error_if_no_space enabled dm thin: cleanup noflush_work to use a proper completion dm snapshot: do not split read bios sent to snapshot-origin target dm snapshot: allocate a per-target structure for snapshot-origin target dm: introduce dm_accept_partial_bio dm: change sector_count member in clone_info from sector_t to unsigned
Diffstat (limited to 'drivers/md/dm.c')
-rw-r--r--drivers/md/dm.c86
1 files changed, 72 insertions, 14 deletions
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index aa9e093343d4..437d99045ef2 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -755,6 +755,14 @@ static void dec_pending(struct dm_io *io, int error)
755 } 755 }
756} 756}
757 757
758static void disable_write_same(struct mapped_device *md)
759{
760 struct queue_limits *limits = dm_get_queue_limits(md);
761
762 /* device doesn't really support WRITE SAME, disable it */
763 limits->max_write_same_sectors = 0;
764}
765
758static void clone_endio(struct bio *bio, int error) 766static void clone_endio(struct bio *bio, int error)
759{ 767{
760 int r = 0; 768 int r = 0;
@@ -783,6 +791,10 @@ static void clone_endio(struct bio *bio, int error)
783 } 791 }
784 } 792 }
785 793
794 if (unlikely(r == -EREMOTEIO && (bio->bi_rw & REQ_WRITE_SAME) &&
795 !bdev_get_queue(bio->bi_bdev)->limits.max_write_same_sectors))
796 disable_write_same(md);
797
786 free_tio(md, tio); 798 free_tio(md, tio);
787 dec_pending(io, error); 799 dec_pending(io, error);
788} 800}
@@ -977,6 +989,10 @@ static void dm_done(struct request *clone, int error, bool mapped)
977 r = rq_end_io(tio->ti, clone, error, &tio->info); 989 r = rq_end_io(tio->ti, clone, error, &tio->info);
978 } 990 }
979 991
992 if (unlikely(r == -EREMOTEIO && (clone->cmd_flags & REQ_WRITE_SAME) &&
993 !clone->q->limits.max_write_same_sectors))
994 disable_write_same(tio->md);
995
980 if (r <= 0) 996 if (r <= 0)
981 /* The target wants to complete the I/O */ 997 /* The target wants to complete the I/O */
982 dm_end_request(clone, r); 998 dm_end_request(clone, r);
@@ -1110,6 +1126,46 @@ int dm_set_target_max_io_len(struct dm_target *ti, sector_t len)
1110} 1126}
1111EXPORT_SYMBOL_GPL(dm_set_target_max_io_len); 1127EXPORT_SYMBOL_GPL(dm_set_target_max_io_len);
1112 1128
1129/*
1130 * A target may call dm_accept_partial_bio only from the map routine. It is
1131 * allowed for all bio types except REQ_FLUSH.
1132 *
1133 * dm_accept_partial_bio informs the dm that the target only wants to process
1134 * additional n_sectors sectors of the bio and the rest of the data should be
1135 * sent in a next bio.
1136 *
1137 * A diagram that explains the arithmetics:
1138 * +--------------------+---------------+-------+
1139 * | 1 | 2 | 3 |
1140 * +--------------------+---------------+-------+
1141 *
1142 * <-------------- *tio->len_ptr --------------->
1143 * <------- bi_size ------->
1144 * <-- n_sectors -->
1145 *
1146 * Region 1 was already iterated over with bio_advance or similar function.
1147 * (it may be empty if the target doesn't use bio_advance)
1148 * Region 2 is the remaining bio size that the target wants to process.
1149 * (it may be empty if region 1 is non-empty, although there is no reason
1150 * to make it empty)
1151 * The target requires that region 3 is to be sent in the next bio.
1152 *
1153 * If the target wants to receive multiple copies of the bio (via num_*bios, etc),
1154 * the partially processed part (the sum of regions 1+2) must be the same for all
1155 * copies of the bio.
1156 */
1157void dm_accept_partial_bio(struct bio *bio, unsigned n_sectors)
1158{
1159 struct dm_target_io *tio = container_of(bio, struct dm_target_io, clone);
1160 unsigned bi_size = bio->bi_iter.bi_size >> SECTOR_SHIFT;
1161 BUG_ON(bio->bi_rw & REQ_FLUSH);
1162 BUG_ON(bi_size > *tio->len_ptr);
1163 BUG_ON(n_sectors > bi_size);
1164 *tio->len_ptr -= bi_size - n_sectors;
1165 bio->bi_iter.bi_size = n_sectors << SECTOR_SHIFT;
1166}
1167EXPORT_SYMBOL_GPL(dm_accept_partial_bio);
1168
1113static void __map_bio(struct dm_target_io *tio) 1169static void __map_bio(struct dm_target_io *tio)
1114{ 1170{
1115 int r; 1171 int r;
@@ -1152,10 +1208,10 @@ struct clone_info {
1152 struct bio *bio; 1208 struct bio *bio;
1153 struct dm_io *io; 1209 struct dm_io *io;
1154 sector_t sector; 1210 sector_t sector;
1155 sector_t sector_count; 1211 unsigned sector_count;
1156}; 1212};
1157 1213
1158static void bio_setup_sector(struct bio *bio, sector_t sector, sector_t len) 1214static void bio_setup_sector(struct bio *bio, sector_t sector, unsigned len)
1159{ 1215{
1160 bio->bi_iter.bi_sector = sector; 1216 bio->bi_iter.bi_sector = sector;
1161 bio->bi_iter.bi_size = to_bytes(len); 1217 bio->bi_iter.bi_size = to_bytes(len);
@@ -1200,11 +1256,13 @@ static struct dm_target_io *alloc_tio(struct clone_info *ci,
1200 1256
1201static void __clone_and_map_simple_bio(struct clone_info *ci, 1257static void __clone_and_map_simple_bio(struct clone_info *ci,
1202 struct dm_target *ti, 1258 struct dm_target *ti,
1203 unsigned target_bio_nr, sector_t len) 1259 unsigned target_bio_nr, unsigned *len)
1204{ 1260{
1205 struct dm_target_io *tio = alloc_tio(ci, ti, ci->bio->bi_max_vecs, target_bio_nr); 1261 struct dm_target_io *tio = alloc_tio(ci, ti, ci->bio->bi_max_vecs, target_bio_nr);
1206 struct bio *clone = &tio->clone; 1262 struct bio *clone = &tio->clone;
1207 1263
1264 tio->len_ptr = len;
1265
1208 /* 1266 /*
1209 * Discard requests require the bio's inline iovecs be initialized. 1267 * Discard requests require the bio's inline iovecs be initialized.
1210 * ci->bio->bi_max_vecs is BIO_INLINE_VECS anyway, for both flush 1268 * ci->bio->bi_max_vecs is BIO_INLINE_VECS anyway, for both flush
@@ -1212,13 +1270,13 @@ static void __clone_and_map_simple_bio(struct clone_info *ci,
1212 */ 1270 */
1213 __bio_clone_fast(clone, ci->bio); 1271 __bio_clone_fast(clone, ci->bio);
1214 if (len) 1272 if (len)
1215 bio_setup_sector(clone, ci->sector, len); 1273 bio_setup_sector(clone, ci->sector, *len);
1216 1274
1217 __map_bio(tio); 1275 __map_bio(tio);
1218} 1276}
1219 1277
1220static void __send_duplicate_bios(struct clone_info *ci, struct dm_target *ti, 1278static void __send_duplicate_bios(struct clone_info *ci, struct dm_target *ti,
1221 unsigned num_bios, sector_t len) 1279 unsigned num_bios, unsigned *len)
1222{ 1280{
1223 unsigned target_bio_nr; 1281 unsigned target_bio_nr;
1224 1282
@@ -1233,13 +1291,13 @@ static int __send_empty_flush(struct clone_info *ci)
1233 1291
1234 BUG_ON(bio_has_data(ci->bio)); 1292 BUG_ON(bio_has_data(ci->bio));
1235 while ((ti = dm_table_get_target(ci->map, target_nr++))) 1293 while ((ti = dm_table_get_target(ci->map, target_nr++)))
1236 __send_duplicate_bios(ci, ti, ti->num_flush_bios, 0); 1294 __send_duplicate_bios(ci, ti, ti->num_flush_bios, NULL);
1237 1295
1238 return 0; 1296 return 0;
1239} 1297}
1240 1298
1241static void __clone_and_map_data_bio(struct clone_info *ci, struct dm_target *ti, 1299static void __clone_and_map_data_bio(struct clone_info *ci, struct dm_target *ti,
1242 sector_t sector, unsigned len) 1300 sector_t sector, unsigned *len)
1243{ 1301{
1244 struct bio *bio = ci->bio; 1302 struct bio *bio = ci->bio;
1245 struct dm_target_io *tio; 1303 struct dm_target_io *tio;
@@ -1254,7 +1312,8 @@ static void __clone_and_map_data_bio(struct clone_info *ci, struct dm_target *ti
1254 1312
1255 for (target_bio_nr = 0; target_bio_nr < num_target_bios; target_bio_nr++) { 1313 for (target_bio_nr = 0; target_bio_nr < num_target_bios; target_bio_nr++) {
1256 tio = alloc_tio(ci, ti, 0, target_bio_nr); 1314 tio = alloc_tio(ci, ti, 0, target_bio_nr);
1257 clone_bio(tio, bio, sector, len); 1315 tio->len_ptr = len;
1316 clone_bio(tio, bio, sector, *len);
1258 __map_bio(tio); 1317 __map_bio(tio);
1259 } 1318 }
1260} 1319}
@@ -1283,7 +1342,7 @@ static int __send_changing_extent_only(struct clone_info *ci,
1283 is_split_required_fn is_split_required) 1342 is_split_required_fn is_split_required)
1284{ 1343{
1285 struct dm_target *ti; 1344 struct dm_target *ti;
1286 sector_t len; 1345 unsigned len;
1287 unsigned num_bios; 1346 unsigned num_bios;
1288 1347
1289 do { 1348 do {
@@ -1302,11 +1361,11 @@ static int __send_changing_extent_only(struct clone_info *ci,
1302 return -EOPNOTSUPP; 1361 return -EOPNOTSUPP;
1303 1362
1304 if (is_split_required && !is_split_required(ti)) 1363 if (is_split_required && !is_split_required(ti))
1305 len = min(ci->sector_count, max_io_len_target_boundary(ci->sector, ti)); 1364 len = min((sector_t)ci->sector_count, max_io_len_target_boundary(ci->sector, ti));
1306 else 1365 else
1307 len = min(ci->sector_count, max_io_len(ci->sector, ti)); 1366 len = min((sector_t)ci->sector_count, max_io_len(ci->sector, ti));
1308 1367
1309 __send_duplicate_bios(ci, ti, num_bios, len); 1368 __send_duplicate_bios(ci, ti, num_bios, &len);
1310 1369
1311 ci->sector += len; 1370 ci->sector += len;
1312 } while (ci->sector_count -= len); 1371 } while (ci->sector_count -= len);
@@ -1345,7 +1404,7 @@ static int __split_and_process_non_flush(struct clone_info *ci)
1345 1404
1346 len = min_t(sector_t, max_io_len(ci->sector, ti), ci->sector_count); 1405 len = min_t(sector_t, max_io_len(ci->sector, ti), ci->sector_count);
1347 1406
1348 __clone_and_map_data_bio(ci, ti, ci->sector, len); 1407 __clone_and_map_data_bio(ci, ti, ci->sector, &len);
1349 1408
1350 ci->sector += len; 1409 ci->sector += len;
1351 ci->sector_count -= len; 1410 ci->sector_count -= len;
@@ -1439,7 +1498,6 @@ static int dm_merge_bvec(struct request_queue *q,
1439 * just one page. 1498 * just one page.
1440 */ 1499 */
1441 else if (queue_max_hw_sectors(q) <= PAGE_SIZE >> 9) 1500 else if (queue_max_hw_sectors(q) <= PAGE_SIZE >> 9)
1442
1443 max_size = 0; 1501 max_size = 0;
1444 1502
1445out: 1503out: