aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Thornber <ejt@redhat.com>2013-12-17 12:09:40 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-02-13 16:48:01 -0500
commit614319dfb0fb5da7fd2f96eb06df96bd3a04cbdd (patch)
treefa2599b2c36b6cc187ffc9f6c6959a213c569e14
parent42e0de9d0e77debb0a34024729cd34068af68bd8 (diff)
dm thin: fix discard support to a previously shared block
commit 19fa1a6756ed9e92daa9537c03b47d6b55cc2316 upstream. If a snapshot is created and later deleted the origin dm_thin_device's snapshotted_time will have been updated to reflect the snapshot's creation time. The 'shared' flag in the dm_thin_lookup_result struct returned from dm_thin_find_block() is an approximation based on snapshotted_time -- this is done to avoid 0(n), or worse, time complexity. In this case, the shared flag would be true. But because the 'shared' flag reflects an approximation a block can be incorrectly assumed to be shared (e.g. false positive for 'shared' because the snapshot no longer exists). This could result in discards issued to a thin device not being passed down to the pool's underlying data device. To fix this we double check that a thin block is really still in-use after a mapping is removed using dm_pool_block_is_used(). If the reference count for a block is now zero the discard is allowed to be passed down. Also add a 'definitely_not_shared' member to the dm_thin_new_mapping structure -- reflects that the 'shared' flag in the response from dm_thin_find_block() can only be held as definitive if false is returned. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1043527 Signed-off-by: Joe Thornber <ejt@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/md/dm-thin-metadata.c20
-rw-r--r--drivers/md/dm-thin-metadata.h2
-rw-r--r--drivers/md/dm-thin.c14
3 files changed, 34 insertions, 2 deletions
diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
index 60bce435f4fa..33ac3be2e836 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 */
1352static bool __snapshotted_since(struct dm_thin_device *td, uint32_t time) 1358static 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
1467int 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
1461bool dm_thin_changed_this_transaction(struct dm_thin_device *td) 1481bool 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 845ebbe589a9..125c09444019 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
182int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result); 182int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result);
183 183
184int 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 e36f81e282eb..d8f1d4e673f6 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
@@ -1032,7 +1041,8 @@ static void process_discard(struct thin_c *tc, struct bio *bio)
1032 */ 1041 */
1033 m = get_next_mapping(pool); 1042 m = get_next_mapping(pool);
1034 m->tc = tc; 1043 m->tc = tc;
1035 m->pass_discard = (!lookup_result.shared) && pool->pf.discard_passdown; 1044 m->pass_discard = pool->pf.discard_passdown;
1045 m->definitely_not_shared = !lookup_result.shared;
1036 m->virt_block = block; 1046 m->virt_block = block;
1037 m->data_block = lookup_result.block; 1047 m->data_block = lookup_result.block;
1038 m->cell = cell; 1048 m->cell = cell;