diff options
-rw-r--r-- | drivers/md/dm-thin-metadata.c | 20 | ||||
-rw-r--r-- | drivers/md/dm-thin-metadata.h | 2 | ||||
-rw-r--r-- | drivers/md/dm-thin.c | 14 |
3 files changed, 34 insertions, 2 deletions
diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c index 8a30ad54bd46..7da347665552 100644 --- a/drivers/md/dm-thin-metadata.c +++ b/drivers/md/dm-thin-metadata.c | |||
@@ -1349,6 +1349,12 @@ dm_thin_id dm_thin_dev_id(struct dm_thin_device *td) | |||
1349 | return td->id; | 1349 | return td->id; |
1350 | } | 1350 | } |
1351 | 1351 | ||
1352 | /* | ||
1353 | * Check whether @time (of block creation) is older than @td's last snapshot. | ||
1354 | * If so then the associated block is shared with the last snapshot device. | ||
1355 | * Any block on a device created *after* the device last got snapshotted is | ||
1356 | * necessarily not shared. | ||
1357 | */ | ||
1352 | static bool __snapshotted_since(struct dm_thin_device *td, uint32_t time) | 1358 | static bool __snapshotted_since(struct dm_thin_device *td, uint32_t time) |
1353 | { | 1359 | { |
1354 | return td->snapshotted_time > time; | 1360 | return td->snapshotted_time > time; |
@@ -1458,6 +1464,20 @@ int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block) | |||
1458 | return r; | 1464 | return r; |
1459 | } | 1465 | } |
1460 | 1466 | ||
1467 | int dm_pool_block_is_used(struct dm_pool_metadata *pmd, dm_block_t b, bool *result) | ||
1468 | { | ||
1469 | int r; | ||
1470 | uint32_t ref_count; | ||
1471 | |||
1472 | down_read(&pmd->root_lock); | ||
1473 | r = dm_sm_get_count(pmd->data_sm, b, &ref_count); | ||
1474 | if (!r) | ||
1475 | *result = (ref_count != 0); | ||
1476 | up_read(&pmd->root_lock); | ||
1477 | |||
1478 | return r; | ||
1479 | } | ||
1480 | |||
1461 | bool dm_thin_changed_this_transaction(struct dm_thin_device *td) | 1481 | bool dm_thin_changed_this_transaction(struct dm_thin_device *td) |
1462 | { | 1482 | { |
1463 | int r; | 1483 | int r; |
diff --git a/drivers/md/dm-thin-metadata.h b/drivers/md/dm-thin-metadata.h index 7bcc0e1d6238..2edf5dbac76a 100644 --- a/drivers/md/dm-thin-metadata.h +++ b/drivers/md/dm-thin-metadata.h | |||
@@ -181,6 +181,8 @@ int dm_pool_get_data_block_size(struct dm_pool_metadata *pmd, sector_t *result); | |||
181 | 181 | ||
182 | int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result); | 182 | int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result); |
183 | 183 | ||
184 | int dm_pool_block_is_used(struct dm_pool_metadata *pmd, dm_block_t b, bool *result); | ||
185 | |||
184 | /* | 186 | /* |
185 | * Returns -ENOSPC if the new size is too small and already allocated | 187 | * Returns -ENOSPC if the new size is too small and already allocated |
186 | * blocks would be lost. | 188 | * blocks would be lost. |
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c index da65febdb6c4..51e656a3002c 100644 --- a/drivers/md/dm-thin.c +++ b/drivers/md/dm-thin.c | |||
@@ -512,6 +512,7 @@ struct dm_thin_new_mapping { | |||
512 | unsigned quiesced:1; | 512 | unsigned quiesced:1; |
513 | unsigned prepared:1; | 513 | unsigned prepared:1; |
514 | unsigned pass_discard:1; | 514 | unsigned pass_discard:1; |
515 | unsigned definitely_not_shared:1; | ||
515 | 516 | ||
516 | struct thin_c *tc; | 517 | struct thin_c *tc; |
517 | dm_block_t virt_block; | 518 | dm_block_t virt_block; |
@@ -683,7 +684,15 @@ static void process_prepared_discard_passdown(struct dm_thin_new_mapping *m) | |||
683 | cell_defer_no_holder(tc, m->cell2); | 684 | cell_defer_no_holder(tc, m->cell2); |
684 | 685 | ||
685 | if (m->pass_discard) | 686 | if (m->pass_discard) |
686 | remap_and_issue(tc, m->bio, m->data_block); | 687 | if (m->definitely_not_shared) |
688 | remap_and_issue(tc, m->bio, m->data_block); | ||
689 | else { | ||
690 | bool used = false; | ||
691 | if (dm_pool_block_is_used(tc->pool->pmd, m->data_block, &used) || used) | ||
692 | bio_endio(m->bio, 0); | ||
693 | else | ||
694 | remap_and_issue(tc, m->bio, m->data_block); | ||
695 | } | ||
687 | else | 696 | else |
688 | bio_endio(m->bio, 0); | 697 | bio_endio(m->bio, 0); |
689 | 698 | ||
@@ -1036,7 +1045,8 @@ static void process_discard(struct thin_c *tc, struct bio *bio) | |||
1036 | */ | 1045 | */ |
1037 | m = get_next_mapping(pool); | 1046 | m = get_next_mapping(pool); |
1038 | m->tc = tc; | 1047 | m->tc = tc; |
1039 | m->pass_discard = (!lookup_result.shared) && pool->pf.discard_passdown; | 1048 | m->pass_discard = pool->pf.discard_passdown; |
1049 | m->definitely_not_shared = !lookup_result.shared; | ||
1040 | m->virt_block = block; | 1050 | m->virt_block = block; |
1041 | m->data_block = lookup_result.block; | 1051 | m->data_block = lookup_result.block; |
1042 | m->cell = cell; | 1052 | m->cell = cell; |