Skip to content

Commit 94563ba

Browse files
committed
dm thin: always return -ENOSPC if no_free_space is set
If pool has 'no_free_space' set it means a previous allocation already determined the pool has no free space (and failed that allocation with -ENOSPC). By always returning -ENOSPC if 'no_free_space' is set, we do not allow the pool to oscillate between allocating blocks and then not. But a side-effect of this determinism is that if a user wants to be able to allocate new blocks they'll need to reload the pool's table (to clear the 'no_free_space' flag). This reload will happen automatically if the pool's data volume is resized. But if the user takes action to free a lot of space by deleting snapshot volumes, etc the pool will no longer allow data allocations to continue without an intervening table reload. Signed-off-by: Mike Snitzer <snitzer@redhat.com> Acked-by: Joe Thornber <ejt@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
1 parent f11c1c5 commit 94563ba

1 file changed

Lines changed: 31 additions & 25 deletions

File tree

‎drivers/md/dm-thin.c‎

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,13 @@ static int alloc_data_block(struct thin_c *tc, dm_block_t *result)
918918
unsigned long flags;
919919
struct pool *pool = tc->pool;
920920

921+
/*
922+
* Once no_free_space is set we must not allow allocation to succeed.
923+
* Otherwise it is difficult to explain, debug, test and support.
924+
*/
925+
if (pool->no_free_space)
926+
return -ENOSPC;
927+
921928
r = dm_pool_get_free_block_count(pool->pmd, &free_blocks);
922929
if (r)
923930
return r;
@@ -932,31 +939,30 @@ static int alloc_data_block(struct thin_c *tc, dm_block_t *result)
932939
}
933940

934941
if (!free_blocks) {
935-
if (pool->no_free_space)
936-
return -ENOSPC;
937-
else {
938-
/*
939-
* Try to commit to see if that will free up some
940-
* more space.
941-
*/
942-
(void) commit_or_fallback(pool);
942+
/*
943+
* Try to commit to see if that will free up some
944+
* more space.
945+
*/
946+
(void) commit_or_fallback(pool);
943947

944-
r = dm_pool_get_free_block_count(pool->pmd, &free_blocks);
945-
if (r)
946-
return r;
948+
r = dm_pool_get_free_block_count(pool->pmd, &free_blocks);
949+
if (r)
950+
return r;
947951

948-
/*
949-
* If we still have no space we set a flag to avoid
950-
* doing all this checking and return -ENOSPC.
951-
*/
952-
if (!free_blocks) {
953-
DMWARN("%s: no free space available.",
954-
dm_device_name(pool->pool_md));
955-
spin_lock_irqsave(&pool->lock, flags);
956-
pool->no_free_space = 1;
957-
spin_unlock_irqrestore(&pool->lock, flags);
958-
return -ENOSPC;
959-
}
952+
/*
953+
* If we still have no space we set a flag to avoid
954+
* doing all this checking and return -ENOSPC. This
955+
* flag serves as a latch that disallows allocations from
956+
* this pool until the admin takes action (e.g. resize or
957+
* table reload).
958+
*/
959+
if (!free_blocks) {
960+
DMWARN("%s: no free space available.",
961+
dm_device_name(pool->pool_md));
962+
spin_lock_irqsave(&pool->lock, flags);
963+
pool->no_free_space = 1;
964+
spin_unlock_irqrestore(&pool->lock, flags);
965+
return -ENOSPC;
960966
}
961967
}
962968

@@ -2695,7 +2701,7 @@ static struct target_type pool_target = {
26952701
.name = "thin-pool",
26962702
.features = DM_TARGET_SINGLETON | DM_TARGET_ALWAYS_WRITEABLE |
26972703
DM_TARGET_IMMUTABLE,
2698-
.version = {1, 8, 0},
2704+
.version = {1, 9, 0},
26992705
.module = THIS_MODULE,
27002706
.ctr = pool_ctr,
27012707
.dtr = pool_dtr,
@@ -2982,7 +2988,7 @@ static int thin_iterate_devices(struct dm_target *ti,
29822988

29832989
static struct target_type thin_target = {
29842990
.name = "thin",
2985-
.version = {1, 8, 0},
2991+
.version = {1, 9, 0},
29862992
.module = THIS_MODULE,
29872993
.ctr = thin_ctr,
29882994
.dtr = thin_dtr,

0 commit comments

Comments
 (0)