mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-30 09:16:41 +07:00
dm thin: support discard with non power of two block size
Support discards when the pool's block size is not a power of 2.
The block layer assumes discard_granularity is a power of 2 (in
blkdev_issue_discard), so we set this to the largest power of 2 that is
a divides into the number of sectors in each block, but never less than
DATA_DEV_BLOCK_SIZE_MIN_SECTORS.
This patch eliminates the "Discard support must be disabled when the
block size is not a power of 2" constraint that was imposed in commit
55f2b8b
("dm thin: support for non power of 2 pool blocksize"). That
commit was incomplete: using a block size that is not a power of 2
shouldn't mean disabling discard support on the device completely.
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
This commit is contained in:
parent
0bcf08798e
commit
28eed34e76
@ -2272,15 +2272,6 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
|
|||||||
goto out_flags_changed;
|
goto out_flags_changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* The block layer requires discard_granularity to be a power of 2.
|
|
||||||
*/
|
|
||||||
if (pf.discard_enabled && !is_power_of_2(block_size)) {
|
|
||||||
ti->error = "Discard support must be disabled when the block size is not a power of 2";
|
|
||||||
r = -EINVAL;
|
|
||||||
goto out_flags_changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
pt->pool = pool;
|
pt->pool = pool;
|
||||||
pt->ti = ti;
|
pt->ti = ti;
|
||||||
pt->metadata_dev = metadata_dev;
|
pt->metadata_dev = metadata_dev;
|
||||||
@ -2762,6 +2753,11 @@ static int pool_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
|
|||||||
return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
|
return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool block_size_is_power_of_two(struct pool *pool)
|
||||||
|
{
|
||||||
|
return pool->sectors_per_block_shift >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void set_discard_limits(struct pool_c *pt, struct queue_limits *limits)
|
static void set_discard_limits(struct pool_c *pt, struct queue_limits *limits)
|
||||||
{
|
{
|
||||||
struct pool *pool = pt->pool;
|
struct pool *pool = pt->pool;
|
||||||
@ -2775,8 +2771,15 @@ static void set_discard_limits(struct pool_c *pt, struct queue_limits *limits)
|
|||||||
if (pt->adjusted_pf.discard_passdown) {
|
if (pt->adjusted_pf.discard_passdown) {
|
||||||
data_limits = &bdev_get_queue(pt->data_dev->bdev)->limits;
|
data_limits = &bdev_get_queue(pt->data_dev->bdev)->limits;
|
||||||
limits->discard_granularity = data_limits->discard_granularity;
|
limits->discard_granularity = data_limits->discard_granularity;
|
||||||
} else
|
} else if (block_size_is_power_of_two(pool))
|
||||||
limits->discard_granularity = pool->sectors_per_block << SECTOR_SHIFT;
|
limits->discard_granularity = pool->sectors_per_block << SECTOR_SHIFT;
|
||||||
|
else
|
||||||
|
/*
|
||||||
|
* Use largest power of 2 that is a factor of sectors_per_block
|
||||||
|
* but at least DATA_DEV_BLOCK_SIZE_MIN_SECTORS.
|
||||||
|
*/
|
||||||
|
limits->discard_granularity = max(1 << (ffs(pool->sectors_per_block) - 1),
|
||||||
|
DATA_DEV_BLOCK_SIZE_MIN_SECTORS) << SECTOR_SHIFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pool_io_hints(struct dm_target *ti, struct queue_limits *limits)
|
static void pool_io_hints(struct dm_target *ti, struct queue_limits *limits)
|
||||||
|
Loading…
Reference in New Issue
Block a user