summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-09-02 19:35:26 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-09-02 19:35:26 -0400
commit1e1a4e8f439113b7820bc7150569f685e1cc2b43 (patch)
tree25a201240e619f7d766638fee57d8cfc55ec0bb9
parentd975f309a8b250e67b66eabeb56be6989c783629 (diff)
parentcc7da0ba9c96699592d0a69d7d146ac6adcc18e7 (diff)
Merge tag 'dm-4.3-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper update from Mike Snitzer: - a couple small cleanups in dm-cache, dm-verity, persistent-data's dm-btree, and DM core. - a 4.1-stable fix for dm-cache that fixes the leaking of deferred bio prison cells - a 4.2-stable fix that adds feature reporting for the dm-stats features added in 4.2 - improve DM-snapshot to not invalidate the on-disk snapshot if snapshot device write overflow occurs; but a write overflow triggered through the origin device will still invalidate the snapshot. - optimize DM-thinp's async discard submission a bit now that late bio splitting has been included in block core. - switch DM-cache's SMQ policy lock from using a mutex to a spinlock; improves performance on very low latency devices (eg. NVMe SSD). - document DM RAID 4/5/6's discard support [ I did not pull the slab changes, which weren't appropriate for this tree, and weren't obviously the right thing to do anyway. At the very least they need some discussion and explanation before getting merged. Because not pulling the actual tagged commit but doing a partial pull instead, this merge commit thus also obviously is missing the git signature from the original tag ] * tag 'dm-4.3-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm cache: fix use after freeing migrations dm cache: small cleanups related to deferred prison cell cleanup dm cache: fix leaking of deferred bio prison cells dm raid: document RAID 4/5/6 discard support dm stats: report precise_timestamps and histogram in @stats_list output dm thin: optimize async discard submission dm snapshot: don't invalidate on-disk image on snapshot write overflow dm: remove unlikely() before IS_ERR() dm: do not override error code returned from dm_get_device() dm: test return value for DM_MAPIO_SUBMITTED dm verity: remove unused mempool dm cache: move wake_waker() from free_migrations() to where it is needed dm btree remove: remove unused function get_nr_entries() dm btree: remove unused "dm_block_t root" parameter in btree_split_sibling() dm cache policy smq: change the mutex to a spinlock
-rw-r--r--Documentation/device-mapper/dm-raid.txt31
-rw-r--r--Documentation/device-mapper/statistics.txt4
-rw-r--r--drivers/md/dm-cache-policy-smq.c110
-rw-r--r--drivers/md/dm-cache-target.c39
-rw-r--r--drivers/md/dm-crypt.c4
-rw-r--r--drivers/md/dm-delay.c16
-rw-r--r--drivers/md/dm-flakey.c6
-rw-r--r--drivers/md/dm-linear.c7
-rw-r--r--drivers/md/dm-log-writes.c11
-rw-r--r--drivers/md/dm-raid1.c8
-rw-r--r--drivers/md/dm-snap-persistent.c2
-rw-r--r--drivers/md/dm-snap.c20
-rw-r--r--drivers/md/dm-stats.c14
-rw-r--r--drivers/md/dm-stripe.c8
-rw-r--r--drivers/md/dm-thin.c89
-rw-r--r--drivers/md/dm-verity.c17
-rw-r--r--drivers/md/dm.c2
-rw-r--r--drivers/md/persistent-data/dm-block-manager.c8
-rw-r--r--drivers/md/persistent-data/dm-btree-remove.c22
-rw-r--r--drivers/md/persistent-data/dm-btree.c6
-rw-r--r--include/uapi/linux/dm-ioctl.h4
21 files changed, 190 insertions, 238 deletions
diff --git a/Documentation/device-mapper/dm-raid.txt b/Documentation/device-mapper/dm-raid.txt
index cb12af3b51c2..df2d636b6088 100644
--- a/Documentation/device-mapper/dm-raid.txt
+++ b/Documentation/device-mapper/dm-raid.txt
@@ -209,6 +209,37 @@ include:
209 "repair" - Initiate a repair of the array. 209 "repair" - Initiate a repair of the array.
210 "reshape"- Currently unsupported (-EINVAL). 210 "reshape"- Currently unsupported (-EINVAL).
211 211
212
213Discard Support
214---------------
215The implementation of discard support among hardware vendors varies.
216When a block is discarded, some storage devices will return zeroes when
217the block is read. These devices set the 'discard_zeroes_data'
218attribute. Other devices will return random data. Confusingly, some
219devices that advertise 'discard_zeroes_data' will not reliably return
220zeroes when discarded blocks are read! Since RAID 4/5/6 uses blocks
221from a number of devices to calculate parity blocks and (for performance
222reasons) relies on 'discard_zeroes_data' being reliable, it is important
223that the devices be consistent. Blocks may be discarded in the middle
224of a RAID 4/5/6 stripe and if subsequent read results are not
225consistent, the parity blocks may be calculated differently at any time;
226making the parity blocks useless for redundancy. It is important to
227understand how your hardware behaves with discards if you are going to
228enable discards with RAID 4/5/6.
229
230Since the behavior of storage devices is unreliable in this respect,
231even when reporting 'discard_zeroes_data', by default RAID 4/5/6
232discard support is disabled -- this ensures data integrity at the
233expense of losing some performance.
234
235Storage devices that properly support 'discard_zeroes_data' are
236increasingly whitelisted in the kernel and can thus be trusted.
237
238For trusted devices, the following dm-raid module parameter can be set
239to safely enable discard support for RAID 4/5/6:
240 'devices_handle_discards_safely'
241
242
212Version History 243Version History
213--------------- 244---------------
2141.0.0 Initial version. Support for RAID 4/5/6 2451.0.0 Initial version. Support for RAID 4/5/6
diff --git a/Documentation/device-mapper/statistics.txt b/Documentation/device-mapper/statistics.txt
index 4919b2dfd1b3..6f5ef944ca4c 100644
--- a/Documentation/device-mapper/statistics.txt
+++ b/Documentation/device-mapper/statistics.txt
@@ -121,6 +121,10 @@ Messages
121 121
122 Output format: 122 Output format:
123 <region_id>: <start_sector>+<length> <step> <program_id> <aux_data> 123 <region_id>: <start_sector>+<length> <step> <program_id> <aux_data>
124 precise_timestamps histogram:n1,n2,n3,...
125
126 The strings "precise_timestamps" and "histogram" are printed only
127 if they were specified when creating the region.
124 128
125 @stats_print <region_id> [<starting_line> <number_of_lines>] 129 @stats_print <region_id> [<starting_line> <number_of_lines>]
126 130
diff --git a/drivers/md/dm-cache-policy-smq.c b/drivers/md/dm-cache-policy-smq.c
index 200366c62231..1ffbeb1b3ea6 100644
--- a/drivers/md/dm-cache-policy-smq.c
+++ b/drivers/md/dm-cache-policy-smq.c
@@ -772,7 +772,7 @@ struct smq_policy {
772 struct dm_cache_policy policy; 772 struct dm_cache_policy policy;
773 773
774 /* protects everything */ 774 /* protects everything */
775 struct mutex lock; 775 spinlock_t lock;
776 dm_cblock_t cache_size; 776 dm_cblock_t cache_size;
777 sector_t cache_block_size; 777 sector_t cache_block_size;
778 778
@@ -807,13 +807,7 @@ struct smq_policy {
807 /* 807 /*
808 * Keeps track of time, incremented by the core. We use this to 808 * Keeps track of time, incremented by the core. We use this to
809 * avoid attributing multiple hits within the same tick. 809 * avoid attributing multiple hits within the same tick.
810 *
811 * Access to tick_protected should be done with the spin lock held.
812 * It's copied to tick at the start of the map function (within the
813 * mutex).
814 */ 810 */
815 spinlock_t tick_lock;
816 unsigned tick_protected;
817 unsigned tick; 811 unsigned tick;
818 812
819 /* 813 /*
@@ -1296,46 +1290,20 @@ static void smq_destroy(struct dm_cache_policy *p)
1296 kfree(mq); 1290 kfree(mq);
1297} 1291}
1298 1292
1299static void copy_tick(struct smq_policy *mq)
1300{
1301 unsigned long flags, tick;
1302
1303 spin_lock_irqsave(&mq->tick_lock, flags);
1304 tick = mq->tick_protected;
1305 if (tick != mq->tick) {
1306 update_sentinels(mq);
1307 end_hotspot_period(mq);
1308 end_cache_period(mq);
1309 mq->tick = tick;
1310 }
1311 spin_unlock_irqrestore(&mq->tick_lock, flags);
1312}
1313
1314static bool maybe_lock(struct smq_policy *mq, bool can_block)
1315{
1316 if (can_block) {
1317 mutex_lock(&mq->lock);
1318 return true;
1319 } else
1320 return mutex_trylock(&mq->lock);
1321}
1322
1323static int smq_map(struct dm_cache_policy *p, dm_oblock_t oblock, 1293static int smq_map(struct dm_cache_policy *p, dm_oblock_t oblock,
1324 bool can_block, bool can_migrate, bool fast_promote, 1294 bool can_block, bool can_migrate, bool fast_promote,
1325 struct bio *bio, struct policy_locker *locker, 1295 struct bio *bio, struct policy_locker *locker,
1326 struct policy_result *result) 1296 struct policy_result *result)
1327{ 1297{
1328 int r; 1298 int r;
1299 unsigned long flags;
1329 struct smq_policy *mq = to_smq_policy(p); 1300 struct smq_policy *mq = to_smq_policy(p);
1330 1301
1331 result->op = POLICY_MISS; 1302 result->op = POLICY_MISS;
1332 1303
1333 if (!maybe_lock(mq, can_block)) 1304 spin_lock_irqsave(&mq->lock, flags);
1334 return -EWOULDBLOCK;
1335
1336 copy_tick(mq);
1337 r = map(mq, bio, oblock, can_migrate, fast_promote, locker, result); 1305 r = map(mq, bio, oblock, can_migrate, fast_promote, locker, result);
1338 mutex_unlock(&mq->lock); 1306 spin_unlock_irqrestore(&mq->lock, flags);
1339 1307
1340 return r; 1308 return r;
1341} 1309}
@@ -1343,20 +1311,18 @@ static int smq_map(struct dm_cache_policy *p, dm_oblock_t oblock,
1343static int smq_lookup(struct dm_cache_policy *p, dm_oblock_t oblock, dm_cblock_t *cblock) 1311static int smq_lookup(struct dm_cache_policy *p, dm_oblock_t oblock, dm_cblock_t *cblock)
1344{ 1312{
1345 int r; 1313 int r;
1314 unsigned long flags;
1346 struct smq_policy *mq = to_smq_policy(p); 1315 struct smq_policy *mq = to_smq_policy(p);
1347 struct entry *e; 1316 struct entry *e;
1348 1317
1349 if (!mutex_trylock(&mq->lock)) 1318 spin_lock_irqsave(&mq->lock, flags);
1350 return -EWOULDBLOCK;
1351
1352 e = h_lookup(&mq->table, oblock); 1319 e = h_lookup(&mq->table, oblock);
1353 if (e) { 1320 if (e) {
1354 *cblock = infer_cblock(mq, e); 1321 *cblock = infer_cblock(mq, e);
1355 r = 0; 1322 r = 0;
1356 } else 1323 } else
1357 r = -ENOENT; 1324 r = -ENOENT;
1358 1325 spin_unlock_irqrestore(&mq->lock, flags);
1359 mutex_unlock(&mq->lock);
1360 1326
1361 return r; 1327 return r;
1362} 1328}
@@ -1375,20 +1341,22 @@ static void __smq_set_clear_dirty(struct smq_policy *mq, dm_oblock_t oblock, boo
1375 1341
1376static void smq_set_dirty(struct dm_cache_policy *p, dm_oblock_t oblock) 1342static void smq_set_dirty(struct dm_cache_policy *p, dm_oblock_t oblock)
1377{ 1343{
1344 unsigned long flags;
1378 struct smq_policy *mq = to_smq_policy(p); 1345 struct smq_policy *mq = to_smq_policy(p);
1379 1346
1380 mutex_lock(&mq->lock); 1347 spin_lock_irqsave(&mq->lock, flags);
1381 __smq_set_clear_dirty(mq, oblock, true); 1348 __smq_set_clear_dirty(mq, oblock, true);
1382 mutex_unlock(&mq->lock); 1349 spin_unlock_irqrestore(&mq->lock, flags);
1383} 1350}
1384 1351
1385static void smq_clear_dirty(struct dm_cache_policy *p, dm_oblock_t oblock) 1352static void smq_clear_dirty(struct dm_cache_policy *p, dm_oblock_t oblock)
1386{ 1353{
1387 struct smq_policy *mq = to_smq_policy(p); 1354 struct smq_policy *mq = to_smq_policy(p);
1355 unsigned long flags;
1388 1356
1389 mutex_lock(&mq->lock); 1357 spin_lock_irqsave(&mq->lock, flags);
1390 __smq_set_clear_dirty(mq, oblock, false); 1358 __smq_set_clear_dirty(mq, oblock, false);
1391 mutex_unlock(&mq->lock); 1359 spin_unlock_irqrestore(&mq->lock, flags);
1392} 1360}
1393 1361
1394static int smq_load_mapping(struct dm_cache_policy *p, 1362static int smq_load_mapping(struct dm_cache_policy *p,
@@ -1433,14 +1401,14 @@ static int smq_walk_mappings(struct dm_cache_policy *p, policy_walk_fn fn,
1433 struct smq_policy *mq = to_smq_policy(p); 1401 struct smq_policy *mq = to_smq_policy(p);
1434 int r = 0; 1402 int r = 0;
1435 1403
1436 mutex_lock(&mq->lock); 1404 /*
1437 1405 * We don't need to lock here since this method is only called once
1406 * the IO has stopped.
1407 */
1438 r = smq_save_hints(mq, &mq->clean, fn, context); 1408 r = smq_save_hints(mq, &mq->clean, fn, context);
1439 if (!r) 1409 if (!r)
1440 r = smq_save_hints(mq, &mq->dirty, fn, context); 1410 r = smq_save_hints(mq, &mq->dirty, fn, context);
1441 1411
1442 mutex_unlock(&mq->lock);
1443
1444 return r; 1412 return r;
1445} 1413}
1446 1414
@@ -1458,10 +1426,11 @@ static void __remove_mapping(struct smq_policy *mq, dm_oblock_t oblock)
1458static void smq_remove_mapping(struct dm_cache_policy *p, dm_oblock_t oblock) 1426static void smq_remove_mapping(struct dm_cache_policy *p, dm_oblock_t oblock)
1459{ 1427{
1460 struct smq_policy *mq = to_smq_policy(p); 1428 struct smq_policy *mq = to_smq_policy(p);
1429 unsigned long flags;
1461 1430
1462 mutex_lock(&mq->lock); 1431 spin_lock_irqsave(&mq->lock, flags);
1463 __remove_mapping(mq, oblock); 1432 __remove_mapping(mq, oblock);
1464 mutex_unlock(&mq->lock); 1433 spin_unlock_irqrestore(&mq->lock, flags);
1465} 1434}
1466 1435
1467static int __remove_cblock(struct smq_policy *mq, dm_cblock_t cblock) 1436static int __remove_cblock(struct smq_policy *mq, dm_cblock_t cblock)
@@ -1480,11 +1449,12 @@ static int __remove_cblock(struct smq_policy *mq, dm_cblock_t cblock)
1480static int smq_remove_cblock(struct dm_cache_policy *p, dm_cblock_t cblock) 1449static int smq_remove_cblock(struct dm_cache_policy *p, dm_cblock_t cblock)
1481{ 1450{
1482 int r; 1451 int r;
1452 unsigned long flags;
1483 struct smq_policy *mq = to_smq_policy(p); 1453 struct smq_policy *mq = to_smq_policy(p);
1484 1454
1485 mutex_lock(&mq->lock); 1455 spin_lock_irqsave(&mq->lock, flags);
1486 r = __remove_cblock(mq, cblock); 1456 r = __remove_cblock(mq, cblock);
1487 mutex_unlock(&mq->lock); 1457 spin_unlock_irqrestore(&mq->lock, flags);
1488 1458
1489 return r; 1459 return r;
1490} 1460}
@@ -1537,11 +1507,12 @@ static int smq_writeback_work(struct dm_cache_policy *p, dm_oblock_t *oblock,
1537 dm_cblock_t *cblock, bool critical_only) 1507 dm_cblock_t *cblock, bool critical_only)
1538{ 1508{
1539 int r; 1509 int r;
1510 unsigned long flags;
1540 struct smq_policy *mq = to_smq_policy(p); 1511 struct smq_policy *mq = to_smq_policy(p);
1541 1512
1542 mutex_lock(&mq->lock); 1513 spin_lock_irqsave(&mq->lock, flags);
1543 r = __smq_writeback_work(mq, oblock, cblock, critical_only); 1514 r = __smq_writeback_work(mq, oblock, cblock, critical_only);
1544 mutex_unlock(&mq->lock); 1515 spin_unlock_irqrestore(&mq->lock, flags);
1545 1516
1546 return r; 1517 return r;
1547} 1518}
@@ -1562,21 +1533,23 @@ static void __force_mapping(struct smq_policy *mq,
1562static void smq_force_mapping(struct dm_cache_policy *p, 1533static void smq_force_mapping(struct dm_cache_policy *p,
1563 dm_oblock_t current_oblock, dm_oblock_t new_oblock) 1534 dm_oblock_t current_oblock, dm_oblock_t new_oblock)
1564{ 1535{
1536 unsigned long flags;
1565 struct smq_policy *mq = to_smq_policy(p); 1537 struct smq_policy *mq = to_smq_policy(p);
1566 1538
1567 mutex_lock(&mq->lock); 1539 spin_lock_irqsave(&mq->lock, flags);
1568 __force_mapping(mq, current_oblock, new_oblock); 1540 __force_mapping(mq, current_oblock, new_oblock);
1569 mutex_unlock(&mq->lock); 1541 spin_unlock_irqrestore(&mq->lock, flags);
1570} 1542}
1571 1543
1572static dm_cblock_t smq_residency(struct dm_cache_policy *p) 1544static dm_cblock_t smq_residency(struct dm_cache_policy *p)
1573{ 1545{
1574 dm_cblock_t r; 1546 dm_cblock_t r;
1547 unsigned long flags;
1575 struct smq_policy *mq = to_smq_policy(p); 1548 struct smq_policy *mq = to_smq_policy(p);
1576 1549
1577 mutex_lock(&mq->lock); 1550 spin_lock_irqsave(&mq->lock, flags);
1578 r = to_cblock(mq->cache_alloc.nr_allocated); 1551 r = to_cblock(mq->cache_alloc.nr_allocated);
1579 mutex_unlock(&mq->lock); 1552 spin_unlock_irqrestore(&mq->lock, flags);
1580 1553
1581 return r; 1554 return r;
1582} 1555}
@@ -1586,15 +1559,12 @@ static void smq_tick(struct dm_cache_policy *p, bool can_block)
1586 struct smq_policy *mq = to_smq_policy(p); 1559 struct smq_policy *mq = to_smq_policy(p);
1587 unsigned long flags; 1560 unsigned long flags;
1588 1561
1589 spin_lock_irqsave(&mq->tick_lock, flags); 1562 spin_lock_irqsave(&mq->lock, flags);
1590 mq->tick_protected++; 1563 mq->tick++;
1591 spin_unlock_irqrestore(&mq->tick_lock, flags); 1564 update_sentinels(mq);
1592 1565 end_hotspot_period(mq);
1593 if (can_block) { 1566 end_cache_period(mq);
1594 mutex_lock(&mq->lock); 1567 spin_unlock_irqrestore(&mq->lock, flags);
1595 copy_tick(mq);
1596 mutex_unlock(&mq->lock);
1597 }
1598} 1568}
1599 1569
1600/* Init the policy plugin interface function pointers. */ 1570/* Init the policy plugin interface function pointers. */
@@ -1694,10 +1664,8 @@ static struct dm_cache_policy *smq_create(dm_cblock_t cache_size,
1694 } else 1664 } else
1695 mq->cache_hit_bits = NULL; 1665 mq->cache_hit_bits = NULL;
1696 1666
1697 mq->tick_protected = 0;
1698 mq->tick = 0; 1667 mq->tick = 0;
1699 mutex_init(&mq->lock); 1668 spin_lock_init(&mq->lock);
1700 spin_lock_init(&mq->tick_lock);
1701 1669
1702 q_init(&mq->hotspot, &mq->es, NR_HOTSPOT_LEVELS); 1670 q_init(&mq->hotspot, &mq->es, NR_HOTSPOT_LEVELS);
1703 mq->hotspot.nr_top_levels = 8; 1671 mq->hotspot.nr_top_levels = 8;
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index 7245071778db..dd90d1236f4a 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -424,7 +424,6 @@ static void free_migration(struct dm_cache_migration *mg)
424 wake_up(&cache->migration_wait); 424 wake_up(&cache->migration_wait);
425 425
426 mempool_free(mg, cache->migration_pool); 426 mempool_free(mg, cache->migration_pool);
427 wake_worker(cache);
428} 427}
429 428
430static int prealloc_data_structs(struct cache *cache, struct prealloc *p) 429static int prealloc_data_structs(struct cache *cache, struct prealloc *p)
@@ -1064,14 +1063,6 @@ static void dec_io_migrations(struct cache *cache)
1064 atomic_dec(&cache->nr_io_migrations); 1063 atomic_dec(&cache->nr_io_migrations);
1065} 1064}
1066 1065
1067static void __cell_release(struct cache *cache, struct dm_bio_prison_cell *cell,
1068 bool holder, struct bio_list *bios)
1069{
1070 (holder ? dm_cell_release : dm_cell_release_no_holder)
1071 (cache->prison, cell, bios);
1072 free_prison_cell(cache, cell);
1073}
1074
1075static bool discard_or_flush(struct bio *bio) 1066static bool discard_or_flush(struct bio *bio)
1076{ 1067{
1077 return bio->bi_rw & (REQ_FLUSH | REQ_FUA | REQ_DISCARD); 1068 return bio->bi_rw & (REQ_FLUSH | REQ_FUA | REQ_DISCARD);
@@ -1079,14 +1070,13 @@ static bool discard_or_flush(struct bio *bio)
1079 1070
1080static void __cell_defer(struct cache *cache, struct dm_bio_prison_cell *cell) 1071static void __cell_defer(struct cache *cache, struct dm_bio_prison_cell *cell)
1081{ 1072{
1082 if (discard_or_flush(cell->holder)) 1073 if (discard_or_flush(cell->holder)) {
1083 /* 1074 /*
1084 * We have to handle these bios 1075 * We have to handle these bios individually.
1085 * individually.
1086 */ 1076 */
1087 __cell_release(cache, cell, true, &cache->deferred_bios); 1077 dm_cell_release(cache->prison, cell, &cache->deferred_bios);
1088 1078 free_prison_cell(cache, cell);
1089 else 1079 } else
1090 list_add_tail(&cell->user_list, &cache->deferred_cells); 1080 list_add_tail(&cell->user_list, &cache->deferred_cells);
1091} 1081}
1092 1082
@@ -1113,7 +1103,7 @@ static void cell_defer(struct cache *cache, struct dm_bio_prison_cell *cell, boo
1113static void cell_error_with_code(struct cache *cache, struct dm_bio_prison_cell *cell, int err) 1103static void cell_error_with_code(struct cache *cache, struct dm_bio_prison_cell *cell, int err)
1114{ 1104{
1115 dm_cell_error(cache->prison, cell, err); 1105 dm_cell_error(cache->prison, cell, err);
1116 dm_bio_prison_free_cell(cache->prison, cell); 1106 free_prison_cell(cache, cell);
1117} 1107}
1118 1108
1119static void cell_requeue(struct cache *cache, struct dm_bio_prison_cell *cell) 1109static void cell_requeue(struct cache *cache, struct dm_bio_prison_cell *cell)
@@ -1123,8 +1113,11 @@ static void cell_requeue(struct cache *cache, struct dm_bio_prison_cell *cell)
1123 1113
1124static void free_io_migration(struct dm_cache_migration *mg) 1114static void free_io_migration(struct dm_cache_migration *mg)
1125{ 1115{
1126 dec_io_migrations(mg->cache); 1116 struct cache *cache = mg->cache;
1117
1118 dec_io_migrations(cache);
1127 free_migration(mg); 1119 free_migration(mg);
1120 wake_worker(cache);
1128} 1121}
1129 1122
1130static void migration_failure(struct dm_cache_migration *mg) 1123static void migration_failure(struct dm_cache_migration *mg)
@@ -1351,16 +1344,18 @@ static void issue_discard(struct dm_cache_migration *mg)
1351{ 1344{
1352 dm_dblock_t b, e; 1345 dm_dblock_t b, e;
1353 struct bio *bio = mg->new_ocell->holder; 1346 struct bio *bio = mg->new_ocell->holder;
1347 struct cache *cache = mg->cache;
1354 1348
1355 calc_discard_block_range(mg->cache, bio, &b, &e); 1349 calc_discard_block_range(cache, bio, &b, &e);
1356 while (b != e) { 1350 while (b != e) {
1357 set_discard(mg->cache, b); 1351 set_discard(cache, b);
1358 b = to_dblock(from_dblock(b) + 1); 1352 b = to_dblock(from_dblock(b) + 1);
1359 } 1353 }
1360 1354
1361 bio_endio(bio); 1355 bio_endio(bio);
1362 cell_defer(mg->cache, mg->new_ocell, false); 1356 cell_defer(cache, mg->new_ocell, false);
1363 free_migration(mg); 1357 free_migration(mg);
1358 wake_worker(cache);
1364} 1359}
1365 1360
1366static void issue_copy_or_discard(struct dm_cache_migration *mg) 1361static void issue_copy_or_discard(struct dm_cache_migration *mg)
@@ -1729,6 +1724,8 @@ static void remap_cell_to_origin_clear_discard(struct cache *cache,
1729 remap_to_origin(cache, bio); 1724 remap_to_origin(cache, bio);
1730 issue(cache, bio); 1725 issue(cache, bio);
1731 } 1726 }
1727
1728 free_prison_cell(cache, cell);
1732} 1729}
1733 1730
1734static void remap_cell_to_cache_dirty(struct cache *cache, struct dm_bio_prison_cell *cell, 1731static void remap_cell_to_cache_dirty(struct cache *cache, struct dm_bio_prison_cell *cell,
@@ -1763,6 +1760,8 @@ static void remap_cell_to_cache_dirty(struct cache *cache, struct dm_bio_prison_
1763 remap_to_cache(cache, bio, cblock); 1760 remap_to_cache(cache, bio, cblock);
1764 issue(cache, bio); 1761 issue(cache, bio);
1765 } 1762 }
1763
1764 free_prison_cell(cache, cell);
1766} 1765}
1767 1766
1768/*----------------------------------------------------------------*/ 1767/*----------------------------------------------------------------*/
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index ba5c2105f4e6..d60c88df5234 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -1811,11 +1811,13 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1811 } 1811 }
1812 cc->iv_offset = tmpll; 1812 cc->iv_offset = tmpll;
1813 1813
1814 if (dm_get_device(ti, argv[3], dm_table_get_mode(ti->table), &cc->dev)) { 1814 ret = dm_get_device(ti, argv[3], dm_table_get_mode(ti->table), &cc->dev);
1815 if (ret) {
1815 ti->error = "Device lookup failed"; 1816 ti->error = "Device lookup failed";
1816 goto bad; 1817 goto bad;
1817 } 1818 }
1818 1819
1820 ret = -EINVAL;
1819 if (sscanf(argv[4], "%llu%c", &tmpll, &dummy) != 1) { 1821 if (sscanf(argv[4], "%llu%c", &tmpll, &dummy) != 1) {
1820 ti->error = "Invalid device sector"; 1822 ti->error = "Invalid device sector";
1821 goto bad; 1823 goto bad;
diff --git a/drivers/md/dm-delay.c b/drivers/md/dm-delay.c
index 57b6a1901c91..b34f6e27293d 100644
--- a/drivers/md/dm-delay.c
+++ b/drivers/md/dm-delay.c
@@ -129,6 +129,7 @@ static int delay_ctr(struct dm_target *ti, unsigned int argc, char **argv)
129 struct delay_c *dc; 129 struct delay_c *dc;
130 unsigned long long tmpll; 130 unsigned long long tmpll;
131 char dummy; 131 char dummy;
132 int ret;
132 133
133 if (argc != 3 && argc != 6) { 134 if (argc != 3 && argc != 6) {
134 ti->error = "requires exactly 3 or 6 arguments"; 135 ti->error = "requires exactly 3 or 6 arguments";
@@ -143,6 +144,7 @@ static int delay_ctr(struct dm_target *ti, unsigned int argc, char **argv)
143 144
144 dc->reads = dc->writes = 0; 145 dc->reads = dc->writes = 0;
145 146
147 ret = -EINVAL;
146 if (sscanf(argv[1], "%llu%c", &tmpll, &dummy) != 1) { 148 if (sscanf(argv[1], "%llu%c", &tmpll, &dummy) != 1) {
147 ti->error = "Invalid device sector"; 149 ti->error = "Invalid device sector";
148 goto bad; 150 goto bad;
@@ -154,12 +156,14 @@ static int delay_ctr(struct dm_target *ti, unsigned int argc, char **argv)
154 goto bad; 156 goto bad;
155 } 157 }
156 158
157 if (dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), 159 ret = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table),
158 &dc->dev_read)) { 160 &dc->dev_read);
161 if (ret) {
159 ti->error = "Device lookup failed"; 162 ti->error = "Device lookup failed";
160 goto bad; 163 goto bad;
161 } 164 }
162 165
166 ret = -EINVAL;
163 dc->dev_write = NULL; 167 dc->dev_write = NULL;
164 if (argc == 3) 168 if (argc == 3)
165 goto out; 169 goto out;
@@ -175,13 +179,15 @@ static int delay_ctr(struct dm_target *ti, unsigned int argc, char **argv)
175 goto bad_dev_read; 179 goto bad_dev_read;
176 } 180 }
177 181
178 if (dm_get_device(ti, argv[3], dm_table_get_mode(ti->table), 182 ret = dm_get_device(ti, argv[3], dm_table_get_mode(ti->table),
179 &dc->dev_write)) { 183 &dc->dev_write);
184 if (ret) {
180 ti->error = "Write device lookup failed"; 185 ti->error = "Write device lookup failed";
181 goto bad_dev_read; 186 goto bad_dev_read;
182 } 187 }
183 188
184out: 189out:
190 ret = -EINVAL;
185 dc->kdelayd_wq = alloc_workqueue("kdelayd", WQ_MEM_RECLAIM, 0); 191 dc->kdelayd_wq = alloc_workqueue("kdelayd", WQ_MEM_RECLAIM, 0);
186 if (!dc->kdelayd_wq) { 192 if (!dc->kdelayd_wq) {
187 DMERR("Couldn't start kdelayd"); 193 DMERR("Couldn't start kdelayd");
@@ -208,7 +214,7 @@ bad_dev_read:
208 dm_put_device(ti, dc->dev_read); 214 dm_put_device(ti, dc->dev_read);
209bad: 215bad:
210 kfree(dc); 216 kfree(dc);
211 return -EINVAL; 217 return ret;
212} 218}
213 219
214static void delay_dtr(struct dm_target *ti) 220static void delay_dtr(struct dm_target *ti)
diff --git a/drivers/md/dm-flakey.c b/drivers/md/dm-flakey.c
index afab13bd683e..645e8b4f808e 100644
--- a/drivers/md/dm-flakey.c
+++ b/drivers/md/dm-flakey.c
@@ -183,6 +183,7 @@ static int flakey_ctr(struct dm_target *ti, unsigned int argc, char **argv)
183 183
184 devname = dm_shift_arg(&as); 184 devname = dm_shift_arg(&as);
185 185
186 r = -EINVAL;
186 if (sscanf(dm_shift_arg(&as), "%llu%c", &tmpll, &dummy) != 1) { 187 if (sscanf(dm_shift_arg(&as), "%llu%c", &tmpll, &dummy) != 1) {
187 ti->error = "Invalid device sector"; 188 ti->error = "Invalid device sector";
188 goto bad; 189 goto bad;
@@ -211,7 +212,8 @@ static int flakey_ctr(struct dm_target *ti, unsigned int argc, char **argv)
211 if (r) 212 if (r)
212 goto bad; 213 goto bad;
213 214
214 if (dm_get_device(ti, devname, dm_table_get_mode(ti->table), &fc->dev)) { 215 r = dm_get_device(ti, devname, dm_table_get_mode(ti->table), &fc->dev);
216 if (r) {
215 ti->error = "Device lookup failed"; 217 ti->error = "Device lookup failed";
216 goto bad; 218 goto bad;
217 } 219 }
@@ -224,7 +226,7 @@ static int flakey_ctr(struct dm_target *ti, unsigned int argc, char **argv)
224 226
225bad: 227bad:
226 kfree(fc); 228 kfree(fc);
227 return -EINVAL; 229 return r;
228} 230}
229 231
230static void flakey_dtr(struct dm_target *ti) 232static void flakey_dtr(struct dm_target *ti)
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c
index 7dd5fc8e3eea..436f5c9b6aea 100644
--- a/drivers/md/dm-linear.c
+++ b/drivers/md/dm-linear.c
@@ -30,6 +30,7 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
30 struct linear_c *lc; 30 struct linear_c *lc;
31 unsigned long long tmp; 31 unsigned long long tmp;
32 char dummy; 32 char dummy;
33 int ret;
33 34
34 if (argc != 2) { 35 if (argc != 2) {
35 ti->error = "Invalid argument count"; 36 ti->error = "Invalid argument count";
@@ -42,13 +43,15 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
42 return -ENOMEM; 43 return -ENOMEM;
43 } 44 }
44 45
46 ret = -EINVAL;
45 if (sscanf(argv[1], "%llu%c", &tmp, &dummy) != 1) { 47 if (sscanf(argv[1], "%llu%c", &tmp, &dummy) != 1) {
46 ti->error = "dm-linear: Invalid device sector"; 48 ti->error = "dm-linear: Invalid device sector";
47 goto bad; 49 goto bad;
48 } 50 }
49 lc->start = tmp; 51 lc->start = tmp;
50 52
51 if (dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &lc->dev)) { 53 ret = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &lc->dev);
54 if (ret) {
52 ti->error = "dm-linear: Device lookup failed"; 55 ti->error = "dm-linear: Device lookup failed";
53 goto bad; 56 goto bad;
54 } 57 }
@@ -61,7 +64,7 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
61 64
62 bad: 65 bad:
63 kfree(lc); 66 kfree(lc);
64 return -EINVAL; 67 return ret;
65} 68}
66 69
67static void linear_dtr(struct dm_target *ti) 70static void linear_dtr(struct dm_target *ti)
diff --git a/drivers/md/dm-log-writes.c b/drivers/md/dm-log-writes.c
index 316cc3fb741f..b2912dbac8bc 100644
--- a/drivers/md/dm-log-writes.c
+++ b/drivers/md/dm-log-writes.c
@@ -417,6 +417,7 @@ static int log_writes_ctr(struct dm_target *ti, unsigned int argc, char **argv)
417 struct log_writes_c *lc; 417 struct log_writes_c *lc;
418 struct dm_arg_set as; 418 struct dm_arg_set as;
419 const char *devname, *logdevname; 419 const char *devname, *logdevname;
420 int ret;
420 421
421 as.argc = argc; 422 as.argc = argc;
422 as.argv = argv; 423 as.argv = argv;
@@ -440,18 +441,22 @@ static int log_writes_ctr(struct dm_target *ti, unsigned int argc, char **argv)
440 atomic_set(&lc->pending_blocks, 0); 441 atomic_set(&lc->pending_blocks, 0);
441 442
442 devname = dm_shift_arg(&as); 443 devname = dm_shift_arg(&as);
443 if (dm_get_device(ti, devname, dm_table_get_mode(ti->table), &lc->dev)) { 444 ret = dm_get_device(ti, devname, dm_table_get_mode(ti->table), &lc->dev);
445 if (ret) {
444 ti->error = "Device lookup failed"; 446 ti->error = "Device lookup failed";
445 goto bad; 447 goto bad;
446 } 448 }
447 449
448 logdevname = dm_shift_arg(&as); 450 logdevname = dm_shift_arg(&as);
449 if (dm_get_device(ti, logdevname, dm_table_get_mode(ti->table), &lc->logdev)) { 451 ret = dm_get_device(ti, logdevname, dm_table_get_mode(ti->table),
452 &lc->logdev);
453 if (ret) {
450 ti->error = "Log device lookup failed"; 454 ti->error = "Log device lookup failed";
451 dm_put_device(ti, lc->dev); 455 dm_put_device(ti, lc->dev);
452 goto bad; 456 goto bad;
453 } 457 }
454 458
459 ret = -EINVAL;
455 lc->log_kthread = kthread_run(log_writes_kthread, lc, "log-write"); 460 lc->log_kthread = kthread_run(log_writes_kthread, lc, "log-write");
456 if (!lc->log_kthread) { 461 if (!lc->log_kthread) {
457 ti->error = "Couldn't alloc kthread"; 462 ti->error = "Couldn't alloc kthread";
@@ -476,7 +481,7 @@ static int log_writes_ctr(struct dm_target *ti, unsigned int argc, char **argv)
476 481
477bad: 482bad:
478 kfree(lc); 483 kfree(lc);
479 return -EINVAL; 484 return ret;
480} 485}
481 486
482static int log_mark(struct log_writes_c *lc, char *data) 487static int log_mark(struct log_writes_c *lc, char *data)
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index e1eabfb2f52d..f2a363a89629 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -945,16 +945,18 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
945{ 945{
946 unsigned long long offset; 946 unsigned long long offset;
947 char dummy; 947 char dummy;
948 int ret;
948 949
949 if (sscanf(argv[1], "%llu%c", &offset, &dummy) != 1) { 950 if (sscanf(argv[1], "%llu%c", &offset, &dummy) != 1) {
950 ti->error = "Invalid offset"; 951 ti->error = "Invalid offset";
951 return -EINVAL; 952 return -EINVAL;
952 } 953 }
953 954
954 if (dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), 955 ret = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table),
955 &ms->mirror[mirror].dev)) { 956 &ms->mirror[mirror].dev);
957 if (ret) {
956 ti->error = "Device lookup failure"; 958 ti->error = "Device lookup failure";
957 return -ENXIO; 959 return ret;
958 } 960 }
959 961
960 ms->mirror[mirror].ms = ms; 962 ms->mirror[mirror].ms = ms;
diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c
index 808b8419bc48..bf71583296f7 100644
--- a/drivers/md/dm-snap-persistent.c
+++ b/drivers/md/dm-snap-persistent.c
@@ -533,7 +533,7 @@ static int read_exceptions(struct pstore *ps,
533 chunk = area_location(ps, ps->current_area); 533 chunk = area_location(ps, ps->current_area);
534 534
535 area = dm_bufio_read(client, chunk, &bp); 535 area = dm_bufio_read(client, chunk, &bp);
536 if (unlikely(IS_ERR(area))) { 536 if (IS_ERR(area)) {
537 r = PTR_ERR(area); 537 r = PTR_ERR(area);
538 goto ret_destroy_bufio; 538 goto ret_destroy_bufio;
539 } 539 }
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index d10b6876018e..c0bcd6516dfe 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -63,6 +63,13 @@ struct dm_snapshot {
63 */ 63 */
64 int valid; 64 int valid;
65 65
66 /*
67 * The snapshot overflowed because of a write to the snapshot device.
68 * We don't have to invalidate the snapshot in this case, but we need
69 * to prevent further writes.
70 */
71 int snapshot_overflowed;
72
66 /* Origin writes don't trigger exceptions until this is set */ 73 /* Origin writes don't trigger exceptions until this is set */
67 int active; 74 int active;
68 75
@@ -1152,6 +1159,7 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1152 1159
1153 s->ti = ti; 1160 s->ti = ti;
1154 s->valid = 1; 1161 s->valid = 1;
1162 s->snapshot_overflowed = 0;
1155 s->active = 0; 1163 s->active = 0;
1156 atomic_set(&s->pending_exceptions_count, 0); 1164 atomic_set(&s->pending_exceptions_count, 0);
1157 s->exception_start_sequence = 0; 1165 s->exception_start_sequence = 0;
@@ -1301,6 +1309,7 @@ static void __handover_exceptions(struct dm_snapshot *snap_src,
1301 1309
1302 snap_dest->ti->max_io_len = snap_dest->store->chunk_size; 1310 snap_dest->ti->max_io_len = snap_dest->store->chunk_size;
1303 snap_dest->valid = snap_src->valid; 1311 snap_dest->valid = snap_src->valid;
1312 snap_dest->snapshot_overflowed = snap_src->snapshot_overflowed;
1304 1313
1305 /* 1314 /*
1306 * Set source invalid to ensure it receives no further I/O. 1315 * Set source invalid to ensure it receives no further I/O.
@@ -1691,7 +1700,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio)
1691 * to copy an exception */ 1700 * to copy an exception */
1692 down_write(&s->lock); 1701 down_write(&s->lock);
1693 1702
1694 if (!s->valid) { 1703 if (!s->valid || (unlikely(s->snapshot_overflowed) && bio_rw(bio) == WRITE)) {
1695 r = -EIO; 1704 r = -EIO;
1696 goto out_unlock; 1705 goto out_unlock;
1697 } 1706 }
@@ -1715,7 +1724,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio)
1715 pe = alloc_pending_exception(s); 1724 pe = alloc_pending_exception(s);
1716 down_write(&s->lock); 1725 down_write(&s->lock);
1717 1726
1718 if (!s->valid) { 1727 if (!s->valid || s->snapshot_overflowed) {
1719 free_pending_exception(pe); 1728 free_pending_exception(pe);
1720 r = -EIO; 1729 r = -EIO;
1721 goto out_unlock; 1730 goto out_unlock;
@@ -1730,7 +1739,8 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio)
1730 1739
1731 pe = __find_pending_exception(s, pe, chunk); 1740 pe = __find_pending_exception(s, pe, chunk);
1732 if (!pe) { 1741 if (!pe) {
1733 __invalidate_snapshot(s, -ENOMEM); 1742 s->snapshot_overflowed = 1;
1743 DMERR("Snapshot overflowed: Unable to allocate exception.");
1734 r = -EIO; 1744 r = -EIO;
1735 goto out_unlock; 1745 goto out_unlock;
1736 } 1746 }
@@ -1990,6 +2000,8 @@ static void snapshot_status(struct dm_target *ti, status_type_t type,
1990 DMEMIT("Invalid"); 2000 DMEMIT("Invalid");
1991 else if (snap->merge_failed) 2001 else if (snap->merge_failed)
1992 DMEMIT("Merge failed"); 2002 DMEMIT("Merge failed");
2003 else if (snap->snapshot_overflowed)
2004 DMEMIT("Overflow");
1993 else { 2005 else {
1994 if (snap->store->type->usage) { 2006 if (snap->store->type->usage) {
1995 sector_t total_sectors, sectors_allocated, 2007 sector_t total_sectors, sectors_allocated,
@@ -2353,7 +2365,7 @@ static struct target_type origin_target = {
2353 2365
2354static struct target_type snapshot_target = { 2366static struct target_type snapshot_target = {
2355 .name = "snapshot", 2367 .name = "snapshot",
2356 .version = {1, 13, 0}, 2368 .version = {1, 14, 0},
2357 .module = THIS_MODULE, 2369 .module = THIS_MODULE,
2358 .ctr = snapshot_ctr, 2370 .ctr = snapshot_ctr,
2359 .dtr = snapshot_dtr, 2371 .dtr = snapshot_dtr,
diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
index 8a8b48fa901a..8289804ccd99 100644
--- a/drivers/md/dm-stats.c
+++ b/drivers/md/dm-stats.c
@@ -457,12 +457,24 @@ static int dm_stats_list(struct dm_stats *stats, const char *program,
457 list_for_each_entry(s, &stats->list, list_entry) { 457 list_for_each_entry(s, &stats->list, list_entry) {
458 if (!program || !strcmp(program, s->program_id)) { 458 if (!program || !strcmp(program, s->program_id)) {
459 len = s->end - s->start; 459 len = s->end - s->start;
460 DMEMIT("%d: %llu+%llu %llu %s %s\n", s->id, 460 DMEMIT("%d: %llu+%llu %llu %s %s", s->id,
461 (unsigned long long)s->start, 461 (unsigned long long)s->start,
462 (unsigned long long)len, 462 (unsigned long long)len,
463 (unsigned long long)s->step, 463 (unsigned long long)s->step,
464 s->program_id, 464 s->program_id,
465 s->aux_data); 465 s->aux_data);
466 if (s->stat_flags & STAT_PRECISE_TIMESTAMPS)
467 DMEMIT(" precise_timestamps");
468 if (s->n_histogram_entries) {
469 unsigned i;
470 DMEMIT(" histogram:");
471 for (i = 0; i < s->n_histogram_entries; i++) {
472 if (i)
473 DMEMIT(",");
474 DMEMIT("%llu", s->histogram_boundaries[i]);
475 }
476 }
477 DMEMIT("\n");
466 } 478 }
467 } 479 }
468 mutex_unlock(&stats->mutex); 480 mutex_unlock(&stats->mutex);
diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
index 484029db8cba..797ddb900b06 100644
--- a/drivers/md/dm-stripe.c
+++ b/drivers/md/dm-stripe.c
@@ -75,13 +75,15 @@ static int get_stripe(struct dm_target *ti, struct stripe_c *sc,
75{ 75{
76 unsigned long long start; 76 unsigned long long start;
77 char dummy; 77 char dummy;
78 int ret;
78 79
79 if (sscanf(argv[1], "%llu%c", &start, &dummy) != 1) 80 if (sscanf(argv[1], "%llu%c", &start, &dummy) != 1)
80 return -EINVAL; 81 return -EINVAL;
81 82
82 if (dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), 83 ret = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table),
83 &sc->stripe[stripe].dev)) 84 &sc->stripe[stripe].dev);
84 return -ENXIO; 85 if (ret)
86 return ret;
85 87
86 sc->stripe[stripe].physical_start = start; 88 sc->stripe[stripe].physical_start = start;
87 89
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index 271a66249363..6578b7bc1fbb 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -332,9 +332,6 @@ struct thin_c {
332 * 332 *
333 * Description: 333 * Description:
334 * Asynchronously issue a discard request for the sectors in question. 334 * Asynchronously issue a discard request for the sectors in question.
335 * NOTE: this variant of blk-core's blkdev_issue_discard() is a stop-gap
336 * that is being kept local to DM thinp until the block changes to allow
337 * late bio splitting land upstream.
338 */ 335 */
339static int __blkdev_issue_discard_async(struct block_device *bdev, sector_t sector, 336static int __blkdev_issue_discard_async(struct block_device *bdev, sector_t sector,
340 sector_t nr_sects, gfp_t gfp_mask, unsigned long flags, 337 sector_t nr_sects, gfp_t gfp_mask, unsigned long flags,
@@ -342,91 +339,36 @@ static int __blkdev_issue_discard_async(struct block_device *bdev, sector_t sect
342{ 339{
343 struct request_queue *q = bdev_get_queue(bdev); 340 struct request_queue *q = bdev_get_queue(bdev);
344 int type = REQ_WRITE | REQ_DISCARD; 341 int type = REQ_WRITE | REQ_DISCARD;
345 unsigned int max_discard_sectors, granularity;
346 int alignment;
347 struct bio *bio; 342 struct bio *bio;
348 int ret = 0;
349 struct blk_plug plug;
350 343
351 if (!q) 344 if (!q || !nr_sects)
352 return -ENXIO; 345 return -ENXIO;
353 346
354 if (!blk_queue_discard(q)) 347 if (!blk_queue_discard(q))
355 return -EOPNOTSUPP; 348 return -EOPNOTSUPP;
356 349
357 /* Zero-sector (unknown) and one-sector granularities are the same. */
358 granularity = max(q->limits.discard_granularity >> 9, 1U);
359 alignment = (bdev_discard_alignment(bdev) >> 9) % granularity;
360
361 /*
362 * Ensure that max_discard_sectors is of the proper
363 * granularity, so that requests stay aligned after a split.
364 */
365 max_discard_sectors = min(q->limits.max_discard_sectors, UINT_MAX >> 9);
366 max_discard_sectors -= max_discard_sectors % granularity;
367 if (unlikely(!max_discard_sectors)) {
368 /* Avoid infinite loop below. Being cautious never hurts. */
369 return -EOPNOTSUPP;
370 }
371
372 if (flags & BLKDEV_DISCARD_SECURE) { 350 if (flags & BLKDEV_DISCARD_SECURE) {
373 if (!blk_queue_secdiscard(q)) 351 if (!blk_queue_secdiscard(q))
374 return -EOPNOTSUPP; 352 return -EOPNOTSUPP;
375 type |= REQ_SECURE; 353 type |= REQ_SECURE;
376 } 354 }
377 355
378 blk_start_plug(&plug); 356 /*
379 while (nr_sects) { 357 * Required bio_put occurs in bio_endio thanks to bio_chain below
380 unsigned int req_sects; 358 */
381 sector_t end_sect, tmp; 359 bio = bio_alloc(gfp_mask, 1);
382 360 if (!bio)
383 /* 361 return -ENOMEM;
384 * Required bio_put occurs in bio_endio thanks to bio_chain below
385 */
386 bio = bio_alloc(gfp_mask, 1);
387 if (!bio) {
388 ret = -ENOMEM;
389 break;
390 }
391
392 req_sects = min_t(sector_t, nr_sects, max_discard_sectors);
393
394 /*
395 * If splitting a request, and the next starting sector would be
396 * misaligned, stop the discard at the previous aligned sector.
397 */
398 end_sect = sector + req_sects;
399 tmp = end_sect;
400 if (req_sects < nr_sects &&
401 sector_div(tmp, granularity) != alignment) {
402 end_sect = end_sect - alignment;
403 sector_div(end_sect, granularity);
404 end_sect = end_sect * granularity + alignment;
405 req_sects = end_sect - sector;
406 }
407
408 bio_chain(bio, parent_bio);
409
410 bio->bi_iter.bi_sector = sector;
411 bio->bi_bdev = bdev;
412 362
413 bio->bi_iter.bi_size = req_sects << 9; 363 bio_chain(bio, parent_bio);
414 nr_sects -= req_sects;
415 sector = end_sect;
416 364
417 submit_bio(type, bio); 365 bio->bi_iter.bi_sector = sector;
366 bio->bi_bdev = bdev;
367 bio->bi_iter.bi_size = nr_sects << 9;
418 368
419 /* 369 submit_bio(type, bio);
420 * We can loop for a long time in here, if someone does
421 * full device discards (like mkfs). Be nice and allow
422 * us to schedule out to avoid softlocking if preempt
423 * is disabled.
424 */
425 cond_resched();
426 }
427 blk_finish_plug(&plug);
428 370
429 return ret; 371 return 0;
430} 372}
431 373
432static bool block_size_is_power_of_two(struct pool *pool) 374static bool block_size_is_power_of_two(struct pool *pool)
@@ -1543,9 +1485,8 @@ static void process_discard_cell_no_passdown(struct thin_c *tc,
1543} 1485}
1544 1486
1545/* 1487/*
1546 * FIXME: DM local hack to defer parent bios's end_io until we 1488 * __bio_inc_remaining() is used to defer parent bios's end_io until
1547 * _know_ all chained sub range discard bios have completed. 1489 * we _know_ all chained sub range discard bios have completed.
1548 * Will go away once late bio splitting lands upstream!
1549 */ 1490 */
1550static inline void __bio_inc_remaining(struct bio *bio) 1491static inline void __bio_inc_remaining(struct bio *bio)
1551{ 1492{
diff --git a/drivers/md/dm-verity.c b/drivers/md/dm-verity.c
index c137dcb147b8..edc624bccf9a 100644
--- a/drivers/md/dm-verity.c
+++ b/drivers/md/dm-verity.c
@@ -26,8 +26,6 @@
26#define DM_VERITY_ENV_LENGTH 42 26#define DM_VERITY_ENV_LENGTH 42
27#define DM_VERITY_ENV_VAR_NAME "DM_VERITY_ERR_BLOCK_NR" 27#define DM_VERITY_ENV_VAR_NAME "DM_VERITY_ERR_BLOCK_NR"
28 28
29#define DM_VERITY_IO_VEC_INLINE 16
30#define DM_VERITY_MEMPOOL_SIZE 4
31#define DM_VERITY_DEFAULT_PREFETCH_SIZE 262144 29#define DM_VERITY_DEFAULT_PREFETCH_SIZE 262144
32 30
33#define DM_VERITY_MAX_LEVELS 63 31#define DM_VERITY_MAX_LEVELS 63
@@ -76,8 +74,6 @@ struct dm_verity {
76 enum verity_mode mode; /* mode for handling verification errors */ 74 enum verity_mode mode; /* mode for handling verification errors */
77 unsigned corrupted_errs;/* Number of errors for corrupted blocks */ 75 unsigned corrupted_errs;/* Number of errors for corrupted blocks */
78 76
79 mempool_t *vec_mempool; /* mempool of bio vector */
80
81 struct workqueue_struct *verify_wq; 77 struct workqueue_struct *verify_wq;
82 78
83 /* starting blocks for each tree level. 0 is the lowest level. */ 79 /* starting blocks for each tree level. 0 is the lowest level. */
@@ -271,7 +267,7 @@ static int verity_verify_level(struct dm_verity_io *io, sector_t block,
271 verity_hash_at_level(v, block, level, &hash_block, &offset); 267 verity_hash_at_level(v, block, level, &hash_block, &offset);
272 268
273 data = dm_bufio_read(v->bufio, hash_block, &buf); 269 data = dm_bufio_read(v->bufio, hash_block, &buf);
274 if (unlikely(IS_ERR(data))) 270 if (IS_ERR(data))
275 return PTR_ERR(data); 271 return PTR_ERR(data);
276 272
277 aux = dm_bufio_get_aux_data(buf); 273 aux = dm_bufio_get_aux_data(buf);
@@ -677,9 +673,6 @@ static void verity_dtr(struct dm_target *ti)
677 if (v->verify_wq) 673 if (v->verify_wq)
678 destroy_workqueue(v->verify_wq); 674 destroy_workqueue(v->verify_wq);
679 675
680 if (v->vec_mempool)
681 mempool_destroy(v->vec_mempool);
682
683 if (v->bufio) 676 if (v->bufio)
684 dm_bufio_client_destroy(v->bufio); 677 dm_bufio_client_destroy(v->bufio);
685 678
@@ -948,14 +941,6 @@ static int verity_ctr(struct dm_target *ti, unsigned argc, char **argv)
948 941
949 ti->per_bio_data_size = roundup(sizeof(struct dm_verity_io) + v->shash_descsize + v->digest_size * 2, __alignof__(struct dm_verity_io)); 942 ti->per_bio_data_size = roundup(sizeof(struct dm_verity_io) + v->shash_descsize + v->digest_size * 2, __alignof__(struct dm_verity_io));
950 943
951 v->vec_mempool = mempool_create_kmalloc_pool(DM_VERITY_MEMPOOL_SIZE,
952 BIO_MAX_PAGES * sizeof(struct bio_vec));
953 if (!v->vec_mempool) {
954 ti->error = "Cannot allocate vector mempool";
955 r = -ENOMEM;
956 goto bad;
957 }
958
959 /* WQ_UNBOUND greatly improves performance when running on ramdisk */ 944 /* WQ_UNBOUND greatly improves performance when running on ramdisk */
960 v->verify_wq = alloc_workqueue("kverityd", WQ_CPU_INTENSIVE | WQ_MEM_RECLAIM | WQ_UNBOUND, num_online_cpus()); 945 v->verify_wq = alloc_workqueue("kverityd", WQ_CPU_INTENSIVE | WQ_MEM_RECLAIM | WQ_UNBOUND, num_online_cpus());
961 if (!v->verify_wq) { 946 if (!v->verify_wq) {
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 6ffc01bb85f2..6264781dc69a 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1464,7 +1464,7 @@ static void __map_bio(struct dm_target_io *tio)
1464 md = tio->io->md; 1464 md = tio->io->md;
1465 dec_pending(tio->io, r); 1465 dec_pending(tio->io, r);
1466 free_tio(md, tio); 1466 free_tio(md, tio);
1467 } else if (r) { 1467 } else if (r != DM_MAPIO_SUBMITTED) {
1468 DMWARN("unimplemented target map return value: %d", r); 1468 DMWARN("unimplemented target map return value: %d", r);
1469 BUG(); 1469 BUG();
1470 } 1470 }
diff --git a/drivers/md/persistent-data/dm-block-manager.c b/drivers/md/persistent-data/dm-block-manager.c
index 4d6c9b689eaa..88dbe7b97c2c 100644
--- a/drivers/md/persistent-data/dm-block-manager.c
+++ b/drivers/md/persistent-data/dm-block-manager.c
@@ -454,7 +454,7 @@ int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b,
454 int r; 454 int r;
455 455
456 p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result); 456 p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result);
457 if (unlikely(IS_ERR(p))) 457 if (IS_ERR(p))
458 return PTR_ERR(p); 458 return PTR_ERR(p);
459 459
460 aux = dm_bufio_get_aux_data(to_buffer(*result)); 460 aux = dm_bufio_get_aux_data(to_buffer(*result));
@@ -490,7 +490,7 @@ int dm_bm_write_lock(struct dm_block_manager *bm,
490 return -EPERM; 490 return -EPERM;
491 491
492 p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result); 492 p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result);
493 if (unlikely(IS_ERR(p))) 493 if (IS_ERR(p))
494 return PTR_ERR(p); 494 return PTR_ERR(p);
495 495
496 aux = dm_bufio_get_aux_data(to_buffer(*result)); 496 aux = dm_bufio_get_aux_data(to_buffer(*result));
@@ -523,7 +523,7 @@ int dm_bm_read_try_lock(struct dm_block_manager *bm,
523 int r; 523 int r;
524 524
525 p = dm_bufio_get(bm->bufio, b, (struct dm_buffer **) result); 525 p = dm_bufio_get(bm->bufio, b, (struct dm_buffer **) result);
526 if (unlikely(IS_ERR(p))) 526 if (IS_ERR(p))
527 return PTR_ERR(p); 527 return PTR_ERR(p);
528 if (unlikely(!p)) 528 if (unlikely(!p))
529 return -EWOULDBLOCK; 529 return -EWOULDBLOCK;
@@ -559,7 +559,7 @@ int dm_bm_write_lock_zero(struct dm_block_manager *bm,
559 return -EPERM; 559 return -EPERM;
560 560
561 p = dm_bufio_new(bm->bufio, b, (struct dm_buffer **) result); 561 p = dm_bufio_new(bm->bufio, b, (struct dm_buffer **) result);
562 if (unlikely(IS_ERR(p))) 562 if (IS_ERR(p))
563 return PTR_ERR(p); 563 return PTR_ERR(p);
564 564
565 memset(p, 0, dm_bm_block_size(bm)); 565 memset(p, 0, dm_bm_block_size(bm));
diff --git a/drivers/md/persistent-data/dm-btree-remove.c b/drivers/md/persistent-data/dm-btree-remove.c
index 4222f774cf36..421a36c593e3 100644
--- a/drivers/md/persistent-data/dm-btree-remove.c
+++ b/drivers/md/persistent-data/dm-btree-remove.c
@@ -409,29 +409,11 @@ static int rebalance3(struct shadow_spine *s, struct dm_btree_info *info,
409 return 0; 409 return 0;
410} 410}
411 411
412static int get_nr_entries(struct dm_transaction_manager *tm,
413 dm_block_t b, uint32_t *result)
414{
415 int r;
416 struct dm_block *block;
417 struct btree_node *n;
418
419 r = dm_tm_read_lock(tm, b, &btree_node_validator, &block);
420 if (r)
421 return r;
422
423 n = dm_block_data(block);
424 *result = le32_to_cpu(n->header.nr_entries);
425
426 return dm_tm_unlock(tm, block);
427}
428
429static int rebalance_children(struct shadow_spine *s, 412static int rebalance_children(struct shadow_spine *s,
430 struct dm_btree_info *info, 413 struct dm_btree_info *info,
431 struct dm_btree_value_type *vt, uint64_t key) 414 struct dm_btree_value_type *vt, uint64_t key)
432{ 415{
433 int i, r, has_left_sibling, has_right_sibling; 416 int i, r, has_left_sibling, has_right_sibling;
434 uint32_t child_entries;
435 struct btree_node *n; 417 struct btree_node *n;
436 418
437 n = dm_block_data(shadow_current(s)); 419 n = dm_block_data(shadow_current(s));
@@ -458,10 +440,6 @@ static int rebalance_children(struct shadow_spine *s,
458 if (i < 0) 440 if (i < 0)
459 return -ENODATA; 441 return -ENODATA;
460 442
461 r = get_nr_entries(info->tm, value64(n, i), &child_entries);
462 if (r)
463 return r;
464
465 has_left_sibling = i > 0; 443 has_left_sibling = i > 0;
466 has_right_sibling = i < (le32_to_cpu(n->header.nr_entries) - 1); 444 has_right_sibling = i < (le32_to_cpu(n->header.nr_entries) - 1);
467 445
diff --git a/drivers/md/persistent-data/dm-btree.c b/drivers/md/persistent-data/dm-btree.c
index c7726cebc495..b6cec258cc21 100644
--- a/drivers/md/persistent-data/dm-btree.c
+++ b/drivers/md/persistent-data/dm-btree.c
@@ -420,8 +420,8 @@ EXPORT_SYMBOL_GPL(dm_btree_lookup);
420 * 420 *
421 * Where A* is a shadow of A. 421 * Where A* is a shadow of A.
422 */ 422 */
423static int btree_split_sibling(struct shadow_spine *s, dm_block_t root, 423static int btree_split_sibling(struct shadow_spine *s, unsigned parent_index,
424 unsigned parent_index, uint64_t key) 424 uint64_t key)
425{ 425{
426 int r; 426 int r;
427 size_t size; 427 size_t size;
@@ -625,7 +625,7 @@ static int btree_insert_raw(struct shadow_spine *s, dm_block_t root,
625 if (top) 625 if (top)
626 r = btree_split_beneath(s, key); 626 r = btree_split_beneath(s, key);
627 else 627 else
628 r = btree_split_sibling(s, root, i, key); 628 r = btree_split_sibling(s, i, key);
629 629
630 if (r < 0) 630 if (r < 0)
631 return r; 631 return r;
diff --git a/include/uapi/linux/dm-ioctl.h b/include/uapi/linux/dm-ioctl.h
index 061aca3a962d..d34611e35a30 100644
--- a/include/uapi/linux/dm-ioctl.h
+++ b/include/uapi/linux/dm-ioctl.h
@@ -267,9 +267,9 @@ enum {
267#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl) 267#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
268 268
269#define DM_VERSION_MAJOR 4 269#define DM_VERSION_MAJOR 4
270#define DM_VERSION_MINOR 32 270#define DM_VERSION_MINOR 33
271#define DM_VERSION_PATCHLEVEL 0 271#define DM_VERSION_PATCHLEVEL 0
272#define DM_VERSION_EXTRA "-ioctl (2015-6-26)" 272#define DM_VERSION_EXTRA "-ioctl (2015-8-18)"
273 273
274/* Status bits */ 274/* Status bits */
275#define DM_READONLY_FLAG (1 << 0) /* In/Out */ 275#define DM_READONLY_FLAG (1 << 0) /* In/Out */