diff options
Diffstat (limited to 'drivers/md/dm.c')
-rw-r--r-- | drivers/md/dm.c | 114 |
1 files changed, 85 insertions, 29 deletions
diff --git a/drivers/md/dm.c b/drivers/md/dm.c index ae1219893948..549b815999a1 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c | |||
@@ -1044,7 +1044,10 @@ static void free_rq_clone(struct request *clone) | |||
1044 | struct dm_rq_target_io *tio = clone->end_io_data; | 1044 | struct dm_rq_target_io *tio = clone->end_io_data; |
1045 | 1045 | ||
1046 | blk_rq_unprep_clone(clone); | 1046 | blk_rq_unprep_clone(clone); |
1047 | free_clone_request(tio->md, clone); | 1047 | if (clone->q && clone->q->mq_ops) |
1048 | tio->ti->type->release_clone_rq(clone); | ||
1049 | else | ||
1050 | free_clone_request(tio->md, clone); | ||
1048 | free_rq_tio(tio); | 1051 | free_rq_tio(tio); |
1049 | } | 1052 | } |
1050 | 1053 | ||
@@ -1086,7 +1089,8 @@ static void dm_unprep_request(struct request *rq) | |||
1086 | rq->special = NULL; | 1089 | rq->special = NULL; |
1087 | rq->cmd_flags &= ~REQ_DONTPREP; | 1090 | rq->cmd_flags &= ~REQ_DONTPREP; |
1088 | 1091 | ||
1089 | free_rq_clone(clone); | 1092 | if (clone) |
1093 | free_rq_clone(clone); | ||
1090 | } | 1094 | } |
1091 | 1095 | ||
1092 | /* | 1096 | /* |
@@ -1185,6 +1189,13 @@ static void dm_softirq_done(struct request *rq) | |||
1185 | struct dm_rq_target_io *tio = rq->special; | 1189 | struct dm_rq_target_io *tio = rq->special; |
1186 | struct request *clone = tio->clone; | 1190 | struct request *clone = tio->clone; |
1187 | 1191 | ||
1192 | if (!clone) { | ||
1193 | blk_end_request_all(rq, tio->error); | ||
1194 | rq_completed(tio->md, rq_data_dir(rq), false); | ||
1195 | free_rq_tio(tio); | ||
1196 | return; | ||
1197 | } | ||
1198 | |||
1188 | if (rq->cmd_flags & REQ_FAILED) | 1199 | if (rq->cmd_flags & REQ_FAILED) |
1189 | mapped = false; | 1200 | mapped = false; |
1190 | 1201 | ||
@@ -1207,7 +1218,7 @@ static void dm_complete_request(struct request *rq, int error) | |||
1207 | * Complete the not-mapped clone and the original request with the error status | 1218 | * Complete the not-mapped clone and the original request with the error status |
1208 | * through softirq context. | 1219 | * through softirq context. |
1209 | * Target's rq_end_io() function isn't called. | 1220 | * Target's rq_end_io() function isn't called. |
1210 | * This may be used when the target's map_rq() function fails. | 1221 | * This may be used when the target's map_rq() or clone_and_map_rq() functions fail. |
1211 | */ | 1222 | */ |
1212 | static void dm_kill_unmapped_request(struct request *rq, int error) | 1223 | static void dm_kill_unmapped_request(struct request *rq, int error) |
1213 | { | 1224 | { |
@@ -1222,13 +1233,15 @@ static void end_clone_request(struct request *clone, int error) | |||
1222 | { | 1233 | { |
1223 | struct dm_rq_target_io *tio = clone->end_io_data; | 1234 | struct dm_rq_target_io *tio = clone->end_io_data; |
1224 | 1235 | ||
1225 | /* | 1236 | if (!clone->q->mq_ops) { |
1226 | * For just cleaning up the information of the queue in which | 1237 | /* |
1227 | * the clone was dispatched. | 1238 | * For just cleaning up the information of the queue in which |
1228 | * The clone is *NOT* freed actually here because it is alloced from | 1239 | * the clone was dispatched. |
1229 | * dm own mempool and REQ_ALLOCED isn't set in clone->cmd_flags. | 1240 | * The clone is *NOT* freed actually here because it is alloced |
1230 | */ | 1241 | * from dm own mempool (REQ_ALLOCED isn't set). |
1231 | __blk_put_request(clone->q, clone); | 1242 | */ |
1243 | __blk_put_request(clone->q, clone); | ||
1244 | } | ||
1232 | 1245 | ||
1233 | /* | 1246 | /* |
1234 | * Actual request completion is done in a softirq context which doesn't | 1247 | * Actual request completion is done in a softirq context which doesn't |
@@ -1789,6 +1802,8 @@ static struct dm_rq_target_io *prep_tio(struct request *rq, | |||
1789 | struct mapped_device *md, gfp_t gfp_mask) | 1802 | struct mapped_device *md, gfp_t gfp_mask) |
1790 | { | 1803 | { |
1791 | struct dm_rq_target_io *tio; | 1804 | struct dm_rq_target_io *tio; |
1805 | int srcu_idx; | ||
1806 | struct dm_table *table; | ||
1792 | 1807 | ||
1793 | tio = alloc_rq_tio(md, gfp_mask); | 1808 | tio = alloc_rq_tio(md, gfp_mask); |
1794 | if (!tio) | 1809 | if (!tio) |
@@ -1802,10 +1817,15 @@ static struct dm_rq_target_io *prep_tio(struct request *rq, | |||
1802 | memset(&tio->info, 0, sizeof(tio->info)); | 1817 | memset(&tio->info, 0, sizeof(tio->info)); |
1803 | init_kthread_work(&tio->work, map_tio_request); | 1818 | init_kthread_work(&tio->work, map_tio_request); |
1804 | 1819 | ||
1805 | if (!clone_rq(rq, md, tio, gfp_mask)) { | 1820 | table = dm_get_live_table(md, &srcu_idx); |
1806 | free_rq_tio(tio); | 1821 | if (!dm_table_mq_request_based(table)) { |
1807 | return NULL; | 1822 | if (!clone_rq(rq, md, tio, gfp_mask)) { |
1823 | dm_put_live_table(md, srcu_idx); | ||
1824 | free_rq_tio(tio); | ||
1825 | return NULL; | ||
1826 | } | ||
1808 | } | 1827 | } |
1828 | dm_put_live_table(md, srcu_idx); | ||
1809 | 1829 | ||
1810 | return tio; | 1830 | return tio; |
1811 | } | 1831 | } |
@@ -1835,17 +1855,36 @@ static int dm_prep_fn(struct request_queue *q, struct request *rq) | |||
1835 | 1855 | ||
1836 | /* | 1856 | /* |
1837 | * Returns: | 1857 | * Returns: |
1838 | * 0 : the request has been processed (not requeued) | 1858 | * 0 : the request has been processed |
1839 | * !0 : the request has been requeued | 1859 | * DM_MAPIO_REQUEUE : the original request needs to be requeued |
1860 | * < 0 : the request was completed due to failure | ||
1840 | */ | 1861 | */ |
1841 | static int map_request(struct dm_target *ti, struct request *rq, | 1862 | static int map_request(struct dm_target *ti, struct request *rq, |
1842 | struct mapped_device *md) | 1863 | struct mapped_device *md) |
1843 | { | 1864 | { |
1844 | int r, requeued = 0; | 1865 | int r; |
1845 | struct dm_rq_target_io *tio = rq->special; | 1866 | struct dm_rq_target_io *tio = rq->special; |
1846 | struct request *clone = tio->clone; | 1867 | struct request *clone = NULL; |
1868 | |||
1869 | if (tio->clone) { | ||
1870 | clone = tio->clone; | ||
1871 | r = ti->type->map_rq(ti, clone, &tio->info); | ||
1872 | } else { | ||
1873 | r = ti->type->clone_and_map_rq(ti, rq, &tio->info, &clone); | ||
1874 | if (r < 0) { | ||
1875 | /* The target wants to complete the I/O */ | ||
1876 | dm_kill_unmapped_request(rq, r); | ||
1877 | return r; | ||
1878 | } | ||
1879 | if (IS_ERR(clone)) | ||
1880 | return DM_MAPIO_REQUEUE; | ||
1881 | if (setup_clone(clone, rq, tio, GFP_KERNEL)) { | ||
1882 | /* -ENOMEM */ | ||
1883 | ti->type->release_clone_rq(clone); | ||
1884 | return DM_MAPIO_REQUEUE; | ||
1885 | } | ||
1886 | } | ||
1847 | 1887 | ||
1848 | r = ti->type->map_rq(ti, clone, &tio->info); | ||
1849 | switch (r) { | 1888 | switch (r) { |
1850 | case DM_MAPIO_SUBMITTED: | 1889 | case DM_MAPIO_SUBMITTED: |
1851 | /* The target has taken the I/O to submit by itself later */ | 1890 | /* The target has taken the I/O to submit by itself later */ |
@@ -1859,7 +1898,6 @@ static int map_request(struct dm_target *ti, struct request *rq, | |||
1859 | case DM_MAPIO_REQUEUE: | 1898 | case DM_MAPIO_REQUEUE: |
1860 | /* The target wants to requeue the I/O */ | 1899 | /* The target wants to requeue the I/O */ |
1861 | dm_requeue_unmapped_request(clone); | 1900 | dm_requeue_unmapped_request(clone); |
1862 | requeued = 1; | ||
1863 | break; | 1901 | break; |
1864 | default: | 1902 | default: |
1865 | if (r > 0) { | 1903 | if (r > 0) { |
@@ -1869,17 +1907,20 @@ static int map_request(struct dm_target *ti, struct request *rq, | |||
1869 | 1907 | ||
1870 | /* The target wants to complete the I/O */ | 1908 | /* The target wants to complete the I/O */ |
1871 | dm_kill_unmapped_request(rq, r); | 1909 | dm_kill_unmapped_request(rq, r); |
1872 | break; | 1910 | return r; |
1873 | } | 1911 | } |
1874 | 1912 | ||
1875 | return requeued; | 1913 | return 0; |
1876 | } | 1914 | } |
1877 | 1915 | ||
1878 | static void map_tio_request(struct kthread_work *work) | 1916 | static void map_tio_request(struct kthread_work *work) |
1879 | { | 1917 | { |
1880 | struct dm_rq_target_io *tio = container_of(work, struct dm_rq_target_io, work); | 1918 | struct dm_rq_target_io *tio = container_of(work, struct dm_rq_target_io, work); |
1919 | struct request *rq = tio->orig; | ||
1920 | struct mapped_device *md = tio->md; | ||
1881 | 1921 | ||
1882 | map_request(tio->ti, tio->orig, tio->md); | 1922 | if (map_request(tio->ti, rq, md) == DM_MAPIO_REQUEUE) |
1923 | dm_requeue_unmapped_original_request(md, rq); | ||
1883 | } | 1924 | } |
1884 | 1925 | ||
1885 | static void dm_start_request(struct mapped_device *md, struct request *orig) | 1926 | static void dm_start_request(struct mapped_device *md, struct request *orig) |
@@ -2459,6 +2500,14 @@ unsigned dm_get_md_type(struct mapped_device *md) | |||
2459 | return md->type; | 2500 | return md->type; |
2460 | } | 2501 | } |
2461 | 2502 | ||
2503 | static bool dm_md_type_request_based(struct mapped_device *md) | ||
2504 | { | ||
2505 | unsigned table_type = dm_get_md_type(md); | ||
2506 | |||
2507 | return (table_type == DM_TYPE_REQUEST_BASED || | ||
2508 | table_type == DM_TYPE_MQ_REQUEST_BASED); | ||
2509 | } | ||
2510 | |||
2462 | struct target_type *dm_get_immutable_target_type(struct mapped_device *md) | 2511 | struct target_type *dm_get_immutable_target_type(struct mapped_device *md) |
2463 | { | 2512 | { |
2464 | return md->immutable_target_type; | 2513 | return md->immutable_target_type; |
@@ -2511,8 +2560,7 @@ static int dm_init_request_based_queue(struct mapped_device *md) | |||
2511 | */ | 2560 | */ |
2512 | int dm_setup_md_queue(struct mapped_device *md) | 2561 | int dm_setup_md_queue(struct mapped_device *md) |
2513 | { | 2562 | { |
2514 | if ((dm_get_md_type(md) == DM_TYPE_REQUEST_BASED) && | 2563 | if (dm_md_type_request_based(md) && !dm_init_request_based_queue(md)) { |
2515 | !dm_init_request_based_queue(md)) { | ||
2516 | DMWARN("Cannot initialize queue for request-based mapped device"); | 2564 | DMWARN("Cannot initialize queue for request-based mapped device"); |
2517 | return -EINVAL; | 2565 | return -EINVAL; |
2518 | } | 2566 | } |
@@ -3184,27 +3232,35 @@ struct dm_md_mempools *dm_alloc_md_mempools(unsigned type, unsigned integrity, u | |||
3184 | { | 3232 | { |
3185 | struct dm_md_mempools *pools = kzalloc(sizeof(*pools), GFP_KERNEL); | 3233 | struct dm_md_mempools *pools = kzalloc(sizeof(*pools), GFP_KERNEL); |
3186 | struct kmem_cache *cachep; | 3234 | struct kmem_cache *cachep; |
3187 | unsigned int pool_size; | 3235 | unsigned int pool_size = 0; |
3188 | unsigned int front_pad; | 3236 | unsigned int front_pad; |
3189 | 3237 | ||
3190 | if (!pools) | 3238 | if (!pools) |
3191 | return NULL; | 3239 | return NULL; |
3192 | 3240 | ||
3193 | if (type == DM_TYPE_BIO_BASED) { | 3241 | switch (type) { |
3242 | case DM_TYPE_BIO_BASED: | ||
3194 | cachep = _io_cache; | 3243 | cachep = _io_cache; |
3195 | pool_size = dm_get_reserved_bio_based_ios(); | 3244 | pool_size = dm_get_reserved_bio_based_ios(); |
3196 | front_pad = roundup(per_bio_data_size, __alignof__(struct dm_target_io)) + offsetof(struct dm_target_io, clone); | 3245 | front_pad = roundup(per_bio_data_size, __alignof__(struct dm_target_io)) + offsetof(struct dm_target_io, clone); |
3197 | } else if (type == DM_TYPE_REQUEST_BASED) { | 3246 | break; |
3198 | cachep = _rq_tio_cache; | 3247 | case DM_TYPE_REQUEST_BASED: |
3199 | pool_size = dm_get_reserved_rq_based_ios(); | 3248 | pool_size = dm_get_reserved_rq_based_ios(); |
3200 | pools->rq_pool = mempool_create_slab_pool(pool_size, _rq_cache); | 3249 | pools->rq_pool = mempool_create_slab_pool(pool_size, _rq_cache); |
3201 | if (!pools->rq_pool) | 3250 | if (!pools->rq_pool) |
3202 | goto out; | 3251 | goto out; |
3252 | /* fall through to setup remaining rq-based pools */ | ||
3253 | case DM_TYPE_MQ_REQUEST_BASED: | ||
3254 | cachep = _rq_tio_cache; | ||
3255 | if (!pool_size) | ||
3256 | pool_size = dm_get_reserved_rq_based_ios(); | ||
3203 | front_pad = offsetof(struct dm_rq_clone_bio_info, clone); | 3257 | front_pad = offsetof(struct dm_rq_clone_bio_info, clone); |
3204 | /* per_bio_data_size is not used. See __bind_mempools(). */ | 3258 | /* per_bio_data_size is not used. See __bind_mempools(). */ |
3205 | WARN_ON(per_bio_data_size != 0); | 3259 | WARN_ON(per_bio_data_size != 0); |
3206 | } else | 3260 | break; |
3261 | default: | ||
3207 | goto out; | 3262 | goto out; |
3263 | } | ||
3208 | 3264 | ||
3209 | pools->io_pool = mempool_create_slab_pool(pool_size, cachep); | 3265 | pools->io_pool = mempool_create_slab_pool(pool_size, cachep); |
3210 | if (!pools->io_pool) | 3266 | if (!pools->io_pool) |