aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/dm-thin-metadata.c
diff options
context:
space:
mode:
authorJoe Thornber <ejt@redhat.com>2013-12-17 12:09:40 -0500
committerMike Snitzer <snitzer@redhat.com>2014-01-07 10:11:43 -0500
commit19fa1a6756ed9e92daa9537c03b47d6b55cc2316 (patch)
tree5e4957a39759e385227995fff9a6e1aa3c99550a /drivers/md/dm-thin-metadata.c
parent16961b042db8cc5cf75d782b4255193ad56e1d4f (diff)
dm thin: fix discard support to a previously shared block
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> Cc: stable@vger.kernel.org
Diffstat (limited to 'drivers/md/dm-thin-metadata.c')
-rw-r--r--drivers/md/dm-thin-metadata.c20
1 files changed, 20 insertions, 0 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 */
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;