Commit 50dd842a authored by Joe Thornber's avatar Joe Thornber Committed by Mike Snitzer

dm space map metadata: fix ref counting bug when bootstrapping a new space map

When applying block operations (BOPs) do not remove them from the
uncommitted BOP ring-buffer until after they've been applied -- in case
we recurse.

Also, perform BOP_INC operation, in dm_sm_metadata_create() and
sm_metadata_extend(), in terms of the uncommitted BOP ring-buffer rather
than using direct calls to sm_ll_inc().
Signed-off-by: default avatarJoe Thornber <ejt@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Cc: stable@vger.kernel.org
parent 49e99fc7
...@@ -136,7 +136,7 @@ static int brb_push(struct bop_ring_buffer *brb, ...@@ -136,7 +136,7 @@ static int brb_push(struct bop_ring_buffer *brb,
return 0; return 0;
} }
static int brb_pop(struct bop_ring_buffer *brb, struct block_op *result) static int brb_peek(struct bop_ring_buffer *brb, struct block_op *result)
{ {
struct block_op *bop; struct block_op *bop;
...@@ -147,6 +147,17 @@ static int brb_pop(struct bop_ring_buffer *brb, struct block_op *result) ...@@ -147,6 +147,17 @@ static int brb_pop(struct bop_ring_buffer *brb, struct block_op *result)
result->type = bop->type; result->type = bop->type;
result->block = bop->block; result->block = bop->block;
return 0;
}
static int brb_pop(struct bop_ring_buffer *brb)
{
struct block_op *bop;
if (brb_empty(brb))
return -ENODATA;
bop = brb->bops + brb->begin;
brb->begin = brb_next(brb, brb->begin); brb->begin = brb_next(brb, brb->begin);
return 0; return 0;
...@@ -211,7 +222,7 @@ static int apply_bops(struct sm_metadata *smm) ...@@ -211,7 +222,7 @@ static int apply_bops(struct sm_metadata *smm)
while (!brb_empty(&smm->uncommitted)) { while (!brb_empty(&smm->uncommitted)) {
struct block_op bop; struct block_op bop;
r = brb_pop(&smm->uncommitted, &bop); r = brb_peek(&smm->uncommitted, &bop);
if (r) { if (r) {
DMERR("bug in bop ring buffer"); DMERR("bug in bop ring buffer");
break; break;
...@@ -220,6 +231,8 @@ static int apply_bops(struct sm_metadata *smm) ...@@ -220,6 +231,8 @@ static int apply_bops(struct sm_metadata *smm)
r = commit_bop(smm, &bop); r = commit_bop(smm, &bop);
if (r) if (r)
break; break;
brb_pop(&smm->uncommitted);
} }
return r; return r;
...@@ -683,7 +696,6 @@ static struct dm_space_map bootstrap_ops = { ...@@ -683,7 +696,6 @@ static struct dm_space_map bootstrap_ops = {
static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks) static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
{ {
int r, i; int r, i;
enum allocation_event ev;
struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm); struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
dm_block_t old_len = smm->ll.nr_blocks; dm_block_t old_len = smm->ll.nr_blocks;
...@@ -705,11 +717,12 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks) ...@@ -705,11 +717,12 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
* allocate any new blocks. * allocate any new blocks.
*/ */
do { do {
for (i = old_len; !r && i < smm->begin; i++) { for (i = old_len; !r && i < smm->begin; i++)
r = sm_ll_inc(&smm->ll, i, &ev); r = add_bop(smm, BOP_INC, i);
if (r)
goto out; if (r)
} goto out;
old_len = smm->begin; old_len = smm->begin;
r = apply_bops(smm); r = apply_bops(smm);
...@@ -754,7 +767,6 @@ int dm_sm_metadata_create(struct dm_space_map *sm, ...@@ -754,7 +767,6 @@ int dm_sm_metadata_create(struct dm_space_map *sm,
{ {
int r; int r;
dm_block_t i; dm_block_t i;
enum allocation_event ev;
struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm); struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
smm->begin = superblock + 1; smm->begin = superblock + 1;
...@@ -782,7 +794,7 @@ int dm_sm_metadata_create(struct dm_space_map *sm, ...@@ -782,7 +794,7 @@ int dm_sm_metadata_create(struct dm_space_map *sm,
* allocated blocks that they were built from. * allocated blocks that they were built from.
*/ */
for (i = superblock; !r && i < smm->begin; i++) for (i = superblock; !r && i < smm->begin; i++)
r = sm_ll_inc(&smm->ll, i, &ev); r = add_bop(smm, BOP_INC, i);
if (r) if (r)
return r; return r;
......
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