Commit 1a443aff authored by Joe Thornber's avatar Joe Thornber Committed by Luis Henriques

dm space map metadata: fix occasional leak of a metadata block on resize

commit 6096d91a upstream.

The metadata space map has a simplified 'bootstrap' mode that is
operational when extending the space maps.  Whilst in this mode it's
possible for some refcount decrement operations to become queued (eg, as
a result of shadowing one of the bitmap indexes).  These decrements were
not being applied when switching out of bootstrap mode.

The effect of this bug was the leaking of a 4k metadata block.  This is
detected by the latest version of thin_check as a non fatal error.
Signed-off-by: default avatarJoe Thornber <ejt@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent c8fb689c
...@@ -204,19 +204,10 @@ static void in(struct sm_metadata *smm) ...@@ -204,19 +204,10 @@ static void in(struct sm_metadata *smm)
smm->recursion_count++; smm->recursion_count++;
} }
static int out(struct sm_metadata *smm) static int apply_bops(struct sm_metadata *smm)
{ {
int r = 0; int r = 0;
/*
* If we're not recursing then very bad things are happening.
*/
if (!smm->recursion_count) {
DMERR("lost track of recursion depth");
return -ENOMEM;
}
if (smm->recursion_count == 1) {
while (!brb_empty(&smm->uncommitted)) { while (!brb_empty(&smm->uncommitted)) {
struct block_op bop; struct block_op bop;
...@@ -230,8 +221,25 @@ static int out(struct sm_metadata *smm) ...@@ -230,8 +221,25 @@ static int out(struct sm_metadata *smm)
if (r) if (r)
break; break;
} }
return r;
}
static int out(struct sm_metadata *smm)
{
int r = 0;
/*
* If we're not recursing then very bad things are happening.
*/
if (!smm->recursion_count) {
DMERR("lost track of recursion depth");
return -ENOMEM;
} }
if (smm->recursion_count == 1)
apply_bops(smm);
smm->recursion_count--; smm->recursion_count--;
return r; return r;
...@@ -702,6 +710,12 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks) ...@@ -702,6 +710,12 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
} }
old_len = smm->begin; old_len = smm->begin;
r = apply_bops(smm);
if (r) {
DMERR("%s: apply_bops failed", __func__);
goto out;
}
r = sm_ll_commit(&smm->ll); r = sm_ll_commit(&smm->ll);
if (r) if (r)
goto out; goto out;
...@@ -771,6 +785,12 @@ int dm_sm_metadata_create(struct dm_space_map *sm, ...@@ -771,6 +785,12 @@ int dm_sm_metadata_create(struct dm_space_map *sm,
if (r) if (r)
return r; return r;
r = apply_bops(smm);
if (r) {
DMERR("%s: apply_bops failed", __func__);
return r;
}
return sm_metadata_commit(sm); return sm_metadata_commit(sm);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment