1 From 2c43fd26e46734430122b8d2ad3024bb532df3ef Mon Sep 17 00:00:00 2001
2 From: Joe Thornber <ejt@redhat.com>
3 Date: Thu, 11 Dec 2014 11:12:19 +0000
4 Subject: dm thin: fix missing out-of-data-space to write mode transition if blocks are released
6 From: Joe Thornber <ejt@redhat.com>
8 commit 2c43fd26e46734430122b8d2ad3024bb532df3ef upstream.
10 Discard bios and thin device deletion have the potential to release data
11 blocks. If the thin-pool is in out-of-data-space mode, and blocks were
12 released, transition the thin-pool back to full write mode.
14 The correct time to do this is just after the thin-pool metadata commit.
15 It cannot be done before the commit because the space maps will not
16 allow immediate reuse of the data blocks in case there's a rollback
17 following power failure.
19 Signed-off-by: Joe Thornber <ejt@redhat.com>
20 Signed-off-by: Mike Snitzer <snitzer@redhat.com>
21 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
24 drivers/md/dm-thin.c | 22 ++++++++++++++++++++--
25 1 file changed, 20 insertions(+), 2 deletions(-)
27 --- a/drivers/md/dm-thin.c
28 +++ b/drivers/md/dm-thin.c
29 @@ -990,6 +990,24 @@ static void schedule_external_copy(struc
30 schedule_zero(tc, virt_block, data_dest, cell, bio);
33 +static void set_pool_mode(struct pool *pool, enum pool_mode new_mode);
35 +static void check_for_space(struct pool *pool)
40 + if (get_pool_mode(pool) != PM_OUT_OF_DATA_SPACE)
43 + r = dm_pool_get_free_block_count(pool->pmd, &nr_free);
48 + set_pool_mode(pool, PM_WRITE);
52 * A non-zero return indicates read_only or fail_io mode.
53 * Many callers don't care about the return value.
54 @@ -1004,6 +1022,8 @@ static int commit(struct pool *pool)
55 r = dm_pool_commit_metadata(pool->pmd);
57 metadata_operation_failed(pool, "dm_pool_commit_metadata", r);
59 + check_for_space(pool);
63 @@ -1022,8 +1042,6 @@ static void check_low_water_mark(struct
67 -static void set_pool_mode(struct pool *pool, enum pool_mode new_mode);
69 static int alloc_data_block(struct thin_c *tc, dm_block_t *result)