diff options
| -rw-r--r-- | drivers/md/dm-thin.c | 64 |
1 files changed, 39 insertions, 25 deletions
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c index d4209231069d..e99f4134dbd7 100644 --- a/drivers/md/dm-thin.c +++ b/drivers/md/dm-thin.c | |||
| @@ -509,9 +509,9 @@ enum pool_mode { | |||
| 509 | struct pool_features { | 509 | struct pool_features { |
| 510 | enum pool_mode mode; | 510 | enum pool_mode mode; |
| 511 | 511 | ||
| 512 | unsigned zero_new_blocks:1; | 512 | bool zero_new_blocks:1; |
| 513 | unsigned discard_enabled:1; | 513 | bool discard_enabled:1; |
| 514 | unsigned discard_passdown:1; | 514 | bool discard_passdown:1; |
| 515 | }; | 515 | }; |
| 516 | 516 | ||
| 517 | struct thin_c; | 517 | struct thin_c; |
| @@ -1839,6 +1839,32 @@ static void __requeue_bios(struct pool *pool) | |||
| 1839 | /*---------------------------------------------------------------- | 1839 | /*---------------------------------------------------------------- |
| 1840 | * Binding of control targets to a pool object | 1840 | * Binding of control targets to a pool object |
| 1841 | *--------------------------------------------------------------*/ | 1841 | *--------------------------------------------------------------*/ |
| 1842 | static bool data_dev_supports_discard(struct pool_c *pt) | ||
| 1843 | { | ||
| 1844 | struct request_queue *q = bdev_get_queue(pt->data_dev->bdev); | ||
| 1845 | |||
| 1846 | return q && blk_queue_discard(q); | ||
| 1847 | } | ||
| 1848 | |||
| 1849 | /* | ||
| 1850 | * If discard_passdown was enabled verify that the data device | ||
| 1851 | * supports discards. Disable discard_passdown if not; otherwise | ||
| 1852 | * -EOPNOTSUPP will be returned. | ||
| 1853 | */ | ||
| 1854 | static void disable_passdown_if_not_supported(struct pool_c *pt, | ||
| 1855 | struct pool_features *pf) | ||
| 1856 | { | ||
| 1857 | char buf[BDEVNAME_SIZE]; | ||
| 1858 | |||
| 1859 | if (!pf->discard_passdown || data_dev_supports_discard(pt)) | ||
| 1860 | return; | ||
| 1861 | |||
| 1862 | DMWARN("Discard unsupported by data device (%s): Disabling discard passdown.", | ||
| 1863 | bdevname(pt->data_dev->bdev, buf)); | ||
| 1864 | |||
| 1865 | pf->discard_passdown = false; | ||
| 1866 | } | ||
| 1867 | |||
| 1842 | static int bind_control_target(struct pool *pool, struct dm_target *ti) | 1868 | static int bind_control_target(struct pool *pool, struct dm_target *ti) |
| 1843 | { | 1869 | { |
| 1844 | struct pool_c *pt = ti->private; | 1870 | struct pool_c *pt = ti->private; |
| @@ -1855,23 +1881,9 @@ static int bind_control_target(struct pool *pool, struct dm_target *ti) | |||
| 1855 | pool->ti = ti; | 1881 | pool->ti = ti; |
| 1856 | pool->low_water_blocks = pt->low_water_blocks; | 1882 | pool->low_water_blocks = pt->low_water_blocks; |
| 1857 | pool->pf = pt->pf; | 1883 | pool->pf = pt->pf; |
| 1858 | set_pool_mode(pool, new_mode); | ||
| 1859 | 1884 | ||
| 1860 | /* | 1885 | disable_passdown_if_not_supported(pt, &pool->pf); |
| 1861 | * If discard_passdown was enabled verify that the data device | 1886 | set_pool_mode(pool, new_mode); |
| 1862 | * supports discards. Disable discard_passdown if not; otherwise | ||
| 1863 | * -EOPNOTSUPP will be returned. | ||
| 1864 | */ | ||
| 1865 | /* FIXME: pull this out into a sep fn. */ | ||
| 1866 | if (pt->pf.discard_passdown) { | ||
| 1867 | struct request_queue *q = bdev_get_queue(pt->data_dev->bdev); | ||
| 1868 | if (!q || !blk_queue_discard(q)) { | ||
| 1869 | char buf[BDEVNAME_SIZE]; | ||
| 1870 | DMWARN("Discard unsupported by data device (%s): Disabling discard passdown.", | ||
| 1871 | bdevname(pt->data_dev->bdev, buf)); | ||
| 1872 | pool->pf.discard_passdown = 0; | ||
| 1873 | } | ||
| 1874 | } | ||
| 1875 | 1887 | ||
| 1876 | return 0; | 1888 | return 0; |
| 1877 | } | 1889 | } |
| @@ -1889,9 +1901,9 @@ static void unbind_control_target(struct pool *pool, struct dm_target *ti) | |||
| 1889 | static void pool_features_init(struct pool_features *pf) | 1901 | static void pool_features_init(struct pool_features *pf) |
| 1890 | { | 1902 | { |
| 1891 | pf->mode = PM_WRITE; | 1903 | pf->mode = PM_WRITE; |
| 1892 | pf->zero_new_blocks = 1; | 1904 | pf->zero_new_blocks = true; |
| 1893 | pf->discard_enabled = 1; | 1905 | pf->discard_enabled = true; |
| 1894 | pf->discard_passdown = 1; | 1906 | pf->discard_passdown = true; |
| 1895 | } | 1907 | } |
| 1896 | 1908 | ||
| 1897 | static void __pool_destroy(struct pool *pool) | 1909 | static void __pool_destroy(struct pool *pool) |
| @@ -2119,13 +2131,13 @@ static int parse_pool_features(struct dm_arg_set *as, struct pool_features *pf, | |||
| 2119 | argc--; | 2131 | argc--; |
| 2120 | 2132 | ||
| 2121 | if (!strcasecmp(arg_name, "skip_block_zeroing")) | 2133 | if (!strcasecmp(arg_name, "skip_block_zeroing")) |
| 2122 | pf->zero_new_blocks = 0; | 2134 | pf->zero_new_blocks = false; |
| 2123 | 2135 | ||
| 2124 | else if (!strcasecmp(arg_name, "ignore_discard")) | 2136 | else if (!strcasecmp(arg_name, "ignore_discard")) |
| 2125 | pf->discard_enabled = 0; | 2137 | pf->discard_enabled = false; |
| 2126 | 2138 | ||
| 2127 | else if (!strcasecmp(arg_name, "no_discard_passdown")) | 2139 | else if (!strcasecmp(arg_name, "no_discard_passdown")) |
| 2128 | pf->discard_passdown = 0; | 2140 | pf->discard_passdown = false; |
| 2129 | 2141 | ||
| 2130 | else if (!strcasecmp(arg_name, "read_only")) | 2142 | else if (!strcasecmp(arg_name, "read_only")) |
| 2131 | pf->mode = PM_READ_ONLY; | 2143 | pf->mode = PM_READ_ONLY; |
| @@ -2261,6 +2273,7 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv) | |||
| 2261 | pt->low_water_blocks = low_water_blocks; | 2273 | pt->low_water_blocks = low_water_blocks; |
| 2262 | pt->pf = pf; | 2274 | pt->pf = pf; |
| 2263 | ti->num_flush_requests = 1; | 2275 | ti->num_flush_requests = 1; |
| 2276 | |||
| 2264 | /* | 2277 | /* |
| 2265 | * Only need to enable discards if the pool should pass | 2278 | * Only need to enable discards if the pool should pass |
| 2266 | * them down to the data device. The thin device's discard | 2279 | * them down to the data device. The thin device's discard |
| @@ -2268,6 +2281,7 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv) | |||
| 2268 | */ | 2281 | */ |
| 2269 | if (pf.discard_enabled && pf.discard_passdown) { | 2282 | if (pf.discard_enabled && pf.discard_passdown) { |
| 2270 | ti->num_discard_requests = 1; | 2283 | ti->num_discard_requests = 1; |
| 2284 | |||
| 2271 | /* | 2285 | /* |
| 2272 | * Setting 'discards_supported' circumvents the normal | 2286 | * Setting 'discards_supported' circumvents the normal |
| 2273 | * stacking of discard limits (this keeps the pool and | 2287 | * stacking of discard limits (this keeps the pool and |
