Skip to content

Commit aa39477

Browse files
committed
Merge tag 'dm-3.19-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper fixes from Mike Snitzer: "Thre stable fixes and one fix for a regression introduced during 3.19 merge: - Fix inability to discard used space when the thin-pool target is in out-of-data-space mode and also transition the thin-pool back to write mode once free space is made available. - Fix DM core bio-based end_io bug that prevented proper post-processing of the error code returned from the block layer. - Fix crash in DM thin-pool due to thin device being added to the pool's active_thins list before properly initializing the thin device's refcount" * tag 'dm-3.19-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm: fix missed error code if .end_io isn't implemented by target_type dm thin: fix crash by initializing thin device's refcount and completion earlier dm thin: fix missing out-of-data-space to write mode transition if blocks are released dm thin: fix inability to discard blocks when in out-of-data-space mode
2 parents 48ec833 + 5164bec commit aa39477

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

drivers/md/dm-thin.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,24 @@ static void schedule_external_copy(struct thin_c *tc, dm_block_t virt_block,
11271127
schedule_zero(tc, virt_block, data_dest, cell, bio);
11281128
}
11291129

1130+
static void set_pool_mode(struct pool *pool, enum pool_mode new_mode);
1131+
1132+
static void check_for_space(struct pool *pool)
1133+
{
1134+
int r;
1135+
dm_block_t nr_free;
1136+
1137+
if (get_pool_mode(pool) != PM_OUT_OF_DATA_SPACE)
1138+
return;
1139+
1140+
r = dm_pool_get_free_block_count(pool->pmd, &nr_free);
1141+
if (r)
1142+
return;
1143+
1144+
if (nr_free)
1145+
set_pool_mode(pool, PM_WRITE);
1146+
}
1147+
11301148
/*
11311149
* A non-zero return indicates read_only or fail_io mode.
11321150
* Many callers don't care about the return value.
@@ -1141,6 +1159,8 @@ static int commit(struct pool *pool)
11411159
r = dm_pool_commit_metadata(pool->pmd);
11421160
if (r)
11431161
metadata_operation_failed(pool, "dm_pool_commit_metadata", r);
1162+
else
1163+
check_for_space(pool);
11441164

11451165
return r;
11461166
}
@@ -1159,8 +1179,6 @@ static void check_low_water_mark(struct pool *pool, dm_block_t free_blocks)
11591179
}
11601180
}
11611181

1162-
static void set_pool_mode(struct pool *pool, enum pool_mode new_mode);
1163-
11641182
static int alloc_data_block(struct thin_c *tc, dm_block_t *result)
11651183
{
11661184
int r;
@@ -2155,7 +2173,7 @@ static void set_pool_mode(struct pool *pool, enum pool_mode new_mode)
21552173
pool->process_cell = process_cell_read_only;
21562174
pool->process_discard_cell = process_discard_cell;
21572175
pool->process_prepared_mapping = process_prepared_mapping;
2158-
pool->process_prepared_discard = process_prepared_discard_passdown;
2176+
pool->process_prepared_discard = process_prepared_discard;
21592177

21602178
if (!pool->pf.error_if_no_space && no_space_timeout)
21612179
queue_delayed_work(pool->wq, &pool->no_space_timeout, no_space_timeout);
@@ -3814,6 +3832,8 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
38143832
r = -EINVAL;
38153833
goto bad;
38163834
}
3835+
atomic_set(&tc->refcount, 1);
3836+
init_completion(&tc->can_destroy);
38173837
list_add_tail_rcu(&tc->list, &tc->pool->active_thins);
38183838
spin_unlock_irqrestore(&tc->pool->lock, flags);
38193839
/*
@@ -3826,9 +3846,6 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
38263846

38273847
dm_put(pool_md);
38283848

3829-
atomic_set(&tc->refcount, 1);
3830-
init_completion(&tc->can_destroy);
3831-
38323849
return 0;
38333850

38343851
bad:

drivers/md/dm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ static void disable_write_same(struct mapped_device *md)
899899

900900
static void clone_endio(struct bio *bio, int error)
901901
{
902-
int r = 0;
902+
int r = error;
903903
struct dm_target_io *tio = container_of(bio, struct dm_target_io, clone);
904904
struct dm_io *io = tio->io;
905905
struct mapped_device *md = tio->io->md;

0 commit comments

Comments
 (0)