Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm space map common: fix to ensure new block isn't already in use

The space-maps track the reference counts for disk blocks allocated by
both the thin-provisioning and cache targets. There are variants for
tracking metadata blocks and data blocks.

Transactionality is implemented by never touching blocks from the
previous transaction, so we can rollback in the event of a crash.

When allocating a new block we need to ensure the block is free (has
reference count of 0) in both the current and previous transaction.
Prior to this fix we were doing this by searching for a free block in
the previous transaction, and relying on a 'begin' counter to track
where the last allocation in the current transaction was. This
'begin' field was not being updated in all code paths (eg, increment
of a data block reference count due to breaking sharing of a neighbour
block in the same btree leaf).

This fix keeps the 'begin' field, but now it's just a hint to speed up
the search. Instead the current transaction is searched for a free
block, and then the old transaction is double checked to ensure it's
free. Much simpler.

This fixes reports of sm_disk_new_block()'s BUG_ON() triggering when
DM thin-provisioning's snapshots are heavily used.

Reported-by: Eric Wheeler <dm-devel@lists.ewheeler.net>
Cc: stable@vger.kernel.org
Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>

authored by

Joe Thornber and committed by
Mike Snitzer
4feaef83 0a531c5a

+37 -3
+27
drivers/md/persistent-data/dm-space-map-common.c
··· 380 380 return -ENOSPC; 381 381 } 382 382 383 + int sm_ll_find_common_free_block(struct ll_disk *old_ll, struct ll_disk *new_ll, 384 + dm_block_t begin, dm_block_t end, dm_block_t *b) 385 + { 386 + int r; 387 + uint32_t count; 388 + 389 + do { 390 + r = sm_ll_find_free_block(new_ll, begin, new_ll->nr_blocks, b); 391 + if (r) 392 + break; 393 + 394 + /* double check this block wasn't used in the old transaction */ 395 + if (*b >= old_ll->nr_blocks) 396 + count = 0; 397 + else { 398 + r = sm_ll_lookup(old_ll, *b, &count); 399 + if (r) 400 + break; 401 + 402 + if (count) 403 + begin = *b + 1; 404 + } 405 + } while (count); 406 + 407 + return r; 408 + } 409 + 383 410 static int sm_ll_mutate(struct ll_disk *ll, dm_block_t b, 384 411 int (*mutator)(void *context, uint32_t old, uint32_t *new), 385 412 void *context, enum allocation_event *ev)
+2
drivers/md/persistent-data/dm-space-map-common.h
··· 109 109 int sm_ll_lookup(struct ll_disk *ll, dm_block_t b, uint32_t *result); 110 110 int sm_ll_find_free_block(struct ll_disk *ll, dm_block_t begin, 111 111 dm_block_t end, dm_block_t *result); 112 + int sm_ll_find_common_free_block(struct ll_disk *old_ll, struct ll_disk *new_ll, 113 + dm_block_t begin, dm_block_t end, dm_block_t *result); 112 114 int sm_ll_insert(struct ll_disk *ll, dm_block_t b, uint32_t ref_count, enum allocation_event *ev); 113 115 int sm_ll_inc(struct ll_disk *ll, dm_block_t b, enum allocation_event *ev); 114 116 int sm_ll_dec(struct ll_disk *ll, dm_block_t b, enum allocation_event *ev);
+4 -2
drivers/md/persistent-data/dm-space-map-disk.c
··· 167 167 enum allocation_event ev; 168 168 struct sm_disk *smd = container_of(sm, struct sm_disk, sm); 169 169 170 - /* FIXME: we should loop round a couple of times */ 171 - r = sm_ll_find_free_block(&smd->old_ll, smd->begin, smd->old_ll.nr_blocks, b); 170 + /* 171 + * Any block we allocate has to be free in both the old and current ll. 172 + */ 173 + r = sm_ll_find_common_free_block(&smd->old_ll, &smd->ll, smd->begin, smd->ll.nr_blocks, b); 172 174 if (r) 173 175 return r; 174 176
+4 -1
drivers/md/persistent-data/dm-space-map-metadata.c
··· 448 448 enum allocation_event ev; 449 449 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm); 450 450 451 - r = sm_ll_find_free_block(&smm->old_ll, smm->begin, smm->old_ll.nr_blocks, b); 451 + /* 452 + * Any block we allocate has to be free in both the old and current ll. 453 + */ 454 + r = sm_ll_find_common_free_block(&smm->old_ll, &smm->ll, smm->begin, smm->ll.nr_blocks, b); 452 455 if (r) 453 456 return r; 454 457