Skip to contentSkip to conversation

dm space map common: make sure new space is used during extend

PATCH New Mike Snitzer 1 participant 2 messages Jan 8, 2014 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 dm space map common: make sure new space is used during extend

From: Joe Thornber <[email protected]>

When extending a low level space map we should update nr_blocks at the start so the new space is used for the index entries.

Otherwise extend can fail, e.g.: sm_metadata_extend call sequence that fails:
-> sm_ll_extend

    -> dm_tm_new_block -> dm_sm_new_block -> sm_bootstrap_new_block
    => returns -ENOSPC because smm->begin == smm->ll.nr_blocks
---
 drivers/md/persistent-data/dm-space-map-common.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/md/persistent-data/dm-space-map-common.c +5 -1
index 466a60b..aacbe70 100644
@@ -245,6 +245,10 @@ int sm_ll_extend(struct ll_disk *ll, dm_block_t extra_blocks)
 		return -EINVAL;
 	}
 
+	/*
+	 * We need to set this before the dm_tm_new_block() call below.
+	 */
+	ll->nr_blocks = nr_blocks;
 	for (i = old_blocks; i < blocks; i++) {
 		struct dm_block *b;
 		struct disk_index_entry idx;
@@ -252,6 +256,7 @@ int sm_ll_extend(struct ll_disk *ll, dm_block_t extra_blocks)
 		r = dm_tm_new_block(ll->tm, &dm_sm_bitmap_validator, &b);
 		if (r < 0)
 			return r;
+
 		idx.blocknr = cpu_to_le64(dm_block_location(b));
 
 		r = dm_tm_unlock(ll->tm, b);
@@ -266,7 +271,6 @@ int sm_ll_extend(struct ll_disk *ll, dm_block_t extra_blocks)
 			return r;
 	}
 
-	ll->nr_blocks = nr_blocks;
 	return 0;
 }
 
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH 2/2 dm space map metadata: fix extending the space map

From: Joe Thornber <[email protected]>

When extending a metadata space map we should do the first commit whilst still in bootstrap mode -- a mode where all blocks get allocated in the new area.

That way the commit overhead is allocated from the newly added space. Otherwise we risk running out of space.

With this fix, and the previous commit "dm space map common: make sure new space is used during extend", the following device mapper testsuite test passes:
dmtest run --suite thin-provisioning -n /resize_metadata_no_io/

---
 drivers/md/persistent-data/dm-space-map-metadata.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/md/persistent-data/dm-space-map-metadata.c +13 -5
index e930844..bfbfe03 100644
@@ -608,20 +608,28 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
 	 * Flick into a mode where all blocks get allocated in the new area.
 	 */
 	smm->begin = old_len;
-	memcpy(&smm->sm, &bootstrap_ops, sizeof(smm->sm));
+	memcpy(sm, &bootstrap_ops, sizeof(*sm));
 
 	/*
 	 * Extend.
 	 */
 	r = sm_ll_extend(&smm->ll, extra_blocks);
+	if (r)
+		goto out;
+
+	for (i = old_len; !r && i < smm->begin; i++) {
+		r = sm_ll_inc(&smm->ll, i, &ev);
+		if (r)
+			goto out;
+	}
 
+	r = sm_metadata_commit(sm);
+
+out:
 	/*
 	 * Switch back to normal behaviour.
 	 */
-	memcpy(&smm->sm, &ops, sizeof(smm->sm));
-	for (i = old_len; !r && i < smm->begin; i++)
-		r = sm_ll_inc(&smm->ll, i, &ev);
-
+	memcpy(sm, &ops, sizeof(*sm));
 	return r;
 }
 
Signature · 1 line
1.8.1.4