Skip to content

Commit d445bd9

Browse files
jthornbersnitm
authored andcommitted
dm thin: fix passdown_double_checking_shared_status()
Commit 00a0ea3 ("dm thin: do not queue freed thin mapping for next stage processing") changed process_prepared_discard_passdown_pt1() to increment all the blocks being discarded until after the passdown had completed to avoid them being prematurely reused. IO issued to a thin device that breaks sharing with a snapshot, followed by a discard issued to snapshot(s) that previously shared the block(s), results in passdown_double_checking_shared_status() being called to iterate through the blocks double checking their reference count is zero and issuing the passdown if so. So a side effect of commit 00a0ea3 is passdown_double_checking_shared_status() was broken. Fix this by checking if the block reference count is greater than 1. Also, rename dm_pool_block_is_used() to dm_pool_block_is_shared(). Fixes: 00a0ea3 ("dm thin: do not queue freed thin mapping for next stage processing") Cc: stable@vger.kernel.org # 4.9+ Reported-by: ryan.p.norwood@gmail.com Signed-off-by: Joe Thornber <ejt@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
1 parent 1856b9f commit d445bd9

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

drivers/md/dm-thin-metadata.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,15 +1678,15 @@ int dm_thin_remove_range(struct dm_thin_device *td,
16781678
return r;
16791679
}
16801680

1681-
int dm_pool_block_is_used(struct dm_pool_metadata *pmd, dm_block_t b, bool *result)
1681+
int dm_pool_block_is_shared(struct dm_pool_metadata *pmd, dm_block_t b, bool *result)
16821682
{
16831683
int r;
16841684
uint32_t ref_count;
16851685

16861686
down_read(&pmd->root_lock);
16871687
r = dm_sm_get_count(pmd->data_sm, b, &ref_count);
16881688
if (!r)
1689-
*result = (ref_count != 0);
1689+
*result = (ref_count > 1);
16901690
up_read(&pmd->root_lock);
16911691

16921692
return r;

drivers/md/dm-thin-metadata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ int dm_pool_get_metadata_dev_size(struct dm_pool_metadata *pmd,
195195

196196
int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result);
197197

198-
int dm_pool_block_is_used(struct dm_pool_metadata *pmd, dm_block_t b, bool *result);
198+
int dm_pool_block_is_shared(struct dm_pool_metadata *pmd, dm_block_t b, bool *result);
199199

200200
int dm_pool_inc_data_range(struct dm_pool_metadata *pmd, dm_block_t b, dm_block_t e);
201201
int dm_pool_dec_data_range(struct dm_pool_metadata *pmd, dm_block_t b, dm_block_t e);

drivers/md/dm-thin.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ static void passdown_double_checking_shared_status(struct dm_thin_new_mapping *m
10481048
* passdown we have to check that these blocks are now unused.
10491049
*/
10501050
int r = 0;
1051-
bool used = true;
1051+
bool shared = true;
10521052
struct thin_c *tc = m->tc;
10531053
struct pool *pool = tc->pool;
10541054
dm_block_t b = m->data_block, e, end = m->data_block + m->virt_end - m->virt_begin;
@@ -1058,11 +1058,11 @@ static void passdown_double_checking_shared_status(struct dm_thin_new_mapping *m
10581058
while (b != end) {
10591059
/* find start of unmapped run */
10601060
for (; b < end; b++) {
1061-
r = dm_pool_block_is_used(pool->pmd, b, &used);
1061+
r = dm_pool_block_is_shared(pool->pmd, b, &shared);
10621062
if (r)
10631063
goto out;
10641064

1065-
if (!used)
1065+
if (!shared)
10661066
break;
10671067
}
10681068

@@ -1071,11 +1071,11 @@ static void passdown_double_checking_shared_status(struct dm_thin_new_mapping *m
10711071

10721072
/* find end of run */
10731073
for (e = b + 1; e != end; e++) {
1074-
r = dm_pool_block_is_used(pool->pmd, e, &used);
1074+
r = dm_pool_block_is_shared(pool->pmd, e, &shared);
10751075
if (r)
10761076
goto out;
10771077

1078-
if (used)
1078+
if (shared)
10791079
break;
10801080
}
10811081

0 commit comments

Comments
 (0)