History

Merge tag 'for-5.1/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm

Pull device mapper updates from Mike Snitzer: - Update bio-based DM core to always call blk_queue_split() and update DM targets to properly advertise discard limits that blk_queue_split() looks at when dtermining to split discard. Whereby allowing DM core's own 'split_discard_bios' to be removed. - Improve DM cache target to provide support for discard passdown to the origin device. - Introduce support to directly boot to a DM mapped device from init by using dm-mod.create= module param. This eliminates the need for an elaborate initramfs that is otherwise needed to create DM devices. This feature's implementation has been worked on for quite some time (got up to v12) and is of particular interest to Android and other more embedded platforms (e.g. ARM). - Rate limit errors from the DM integrity target that were identified as the cause for recent NMI hangs due to console limitations. - Add sanity checks for user input to thin-pool and external snapshot creation. - Remove some unused leftover kmem caches from when old .request_fn request-based support was removed. - Various small cleanups and fixes to targets (e.g. typos, needless unlikely() annotations, use struct_size(), remove needless .direct_access method from dm-snapshot) * tag 'for-5.1/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm integrity: limit the rate of error messages dm snapshot: don't define direct_access if we don't support it dm cache: add support for discard passdown to the origin device dm writecache: fix typo in name for writeback_wq dm: add support to directly boot to a mapped device dm thin: add sanity checks to thin-pool and external snapshot creation dm block manager: remove redundant unlikely annotation dm verity fec: remove redundant unlikely annotation dm integrity: remove redundant unlikely annotation dm: always call blk_queue_split() in dm_process_bio() dm: fix to_sector() for 32bit dm switch: use struct_size() in kzalloc() dm: remove unused _rq_tio_cache and _rq_cache dm: eliminate 'split_discard_bios' flag from DM target interface dm: update dm_process_bio() to split bio if in ->make_request_fn()

Linus Torvalds committed 7 years ago

Commit 6cdc5772 parents 92fff53 225557421 files · +776 −148Browse files

Unified · Split

21 files
  1. Documentation/device-mapper/cache.txt +3 −0
  2. Documentation/device-mapper/dm-init.txt +114 −0
  3. drivers/md/Kconfig +12 −0
  4. drivers/md/Makefile +4 −0
  5. drivers/md/dm-cache-target.c +100 −27
  6. drivers/md/dm-init.c +303 −0
  7. drivers/md/dm-integrity.c +5 −5
  8. drivers/md/dm-ioctl.c +103 −0
  9. drivers/md/dm-raid.c +9 −5
  10. drivers/md/dm-rq.c +16 −0
  11. drivers/md/dm-rq.h +0 −16
  12. drivers/md/dm-snap.c +0 −8
  13. drivers/md/dm-switch.c +1 −2
  14. drivers/md/dm-thin.c +13 −1
  15. drivers/md/dm-verity-fec.c +3 −3
  16. drivers/md/dm-writecache.c +1 −1
  17. drivers/md/dm-zoned-target.c +0 −1
  18. drivers/md/dm.c +73 −66
  19. drivers/md/persistent-data/dm-block-manager.c +4 −4
  20. include/linux/device-mapper.h +10 −7
  21. include/uapi/linux/dm-ioctl.h +2 −2
Documentation/device-mapper/cache.txt+3−0
@@ -206,6 +206,9 @@ Optional feature arguments are: · 205 unmodified lines
206 in a separate btree, which improves speed of shutting206 in a separate btree, which improves speed of shutting
207 down the cache.207 down the cache.
208 208
209 no_discard_passdown : disable passing down discards from the cache
210 to the origin's data device.
211
209A policy called 'default' is always registered. This is an alias for212A policy called 'default' is always registered. This is an alias for
210the policy we currently think is giving best all round performance.213the policy we currently think is giving best all round performance.
211 214
Documentation/device-mapper/dm-init.txt+114−0
@@ -0,0 +1,114 @@
1Early creation of mapped devices
2====================================
3
4It is possible to configure a device-mapper device to act as the root device for
5your system in two ways.
6
7The first is to build an initial ramdisk which boots to a minimal userspace
8which configures the device, then pivot_root(8) in to it.
9
10The second is to create one or more device-mappers using the module parameter
11"dm-mod.create=" through the kernel boot command line argument.
12
13The format is specified as a string of data separated by commas and optionally
14semi-colons, where:
15 - a comma is used to separate fields like name, uuid, flags and table
16 (specifies one device)
17 - a semi-colon is used to separate devices.
18
19So the format will look like this:
20
21 dm-mod.create=<name>,<uuid>,<minor>,<flags>,<table>[,<table>+][;<name>,<uuid>,<minor>,<flags>,<table>[,<table>+]+]
22
23Where,
24 <name> ::= The device name.
25 <uuid> ::= xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | ""
26 <minor> ::= The device minor number | ""
27 <flags> ::= "ro" | "rw"
28 <table> ::= <start_sector> <num_sectors> <target_type> <target_args>
29 <target_type> ::= "verity" | "linear" | ... (see list below)
30
31The dm line should be equivalent to the one used by the dmsetup tool with the
32--concise argument.
33
34Target types
35============
36
37Not all target types are available as there are serious risks in allowing
38activation of certain DM targets without first using userspace tools to check
39the validity of associated metadata.
40
41 "cache": constrained, userspace should verify cache device
42 "crypt": allowed
43 "delay": allowed
44 "era": constrained, userspace should verify metadata device
45 "flakey": constrained, meant for test
46 "linear": allowed
47 "log-writes": constrained, userspace should verify metadata device
48 "mirror": constrained, userspace should verify main/mirror device
49 "raid": constrained, userspace should verify metadata device
50 "snapshot": constrained, userspace should verify src/dst device
51 "snapshot-origin": allowed
52 "snapshot-merge": constrained, userspace should verify src/dst device
53 "striped": allowed
54 "switch": constrained, userspace should verify dev path
55 "thin": constrained, requires dm target message from userspace
56 "thin-pool": constrained, requires dm target message from userspace
57 "verity": allowed
58 "writecache": constrained, userspace should verify cache device
59 "zero": constrained, not meant for rootfs
60
61If the target is not listed above, it is constrained by default (not tested).
62
63Examples
64========
65An example of booting to a linear array made up of user-mode linux block
66devices:
67
68 dm-mod.create="lroot,,,rw, 0 4096 linear 98:16 0, 4096 4096 linear 98:32 0" root=/dev/dm-0
69
70This will boot to a rw dm-linear target of 8192 sectors split across two block
71devices identified by their major:minor numbers. After boot, udev will rename
72this target to /dev/mapper/lroot (depending on the rules). No uuid was assigned.
73
74An example of multiple device-mappers, with the dm-mod.create="..." contents is shown here
75split on multiple lines for readability:
76
77 vroot,,,ro,
78 0 1740800 verity 254:0 254:0 1740800 sha1
79 76e9be054b15884a9fa85973e9cb274c93afadb6
80 5b3549d54d6c7a3837b9b81ed72e49463a64c03680c47835bef94d768e5646fe;
81 vram,,,rw,
82 0 32768 linear 1:0 0,
83 32768 32768 linear 1:1 0
84
85Other examples (per target):
86
87"crypt":
88 dm-crypt,,8,ro,
89 0 1048576 crypt aes-xts-plain64
90 babebabebabebabebabebabebabebabebabebabebabebabebabebabebabebabe 0
91 /dev/sda 0 1 allow_discards
92
93"delay":
94 dm-delay,,4,ro,0 409600 delay /dev/sda1 0 500
95
96"linear":
97 dm-linear,,,rw,
98 0 32768 linear /dev/sda1 0,
99 32768 1024000 linear /dev/sda2 0,
100 1056768 204800 linear /dev/sda3 0,
101 1261568 512000 linear /dev/sda4 0
102
103"snapshot-origin":
104 dm-snap-orig,,4,ro,0 409600 snapshot-origin 8:2
105
106"striped":
107 dm-striped,,4,ro,0 1638400 striped 4 4096
108 /dev/sda1 0 /dev/sda2 0 /dev/sda3 0 /dev/sda4 0
109
110"verity":
111 dm-verity,,4,ro,
112 0 1638400 verity 1 8:1 8:2 4096 4096 204800 1 sha256
113 fb1a5a0f00deb908d8b53cb270858975e76cf64105d412ce764225d53b8f3cfd
114 51934789604d1b92399c52e7cb149d1b3a1b74bbbcb103b2a0aaacbed5c08584
drivers/md/Kconfig+12−0
@@ -436,6 +436,18 @@ config DM_DELAY · 435 unmodified lines
436 436
437 If unsure, say N.437 If unsure, say N.
438 438
439config DM_INIT
440 bool "DM \"dm-mod.create=\" parameter support"
441 depends on BLK_DEV_DM=y
442 ---help---
443 Enable "dm-mod.create=" parameter to create mapped devices at init time.
444 This option is useful to allow mounting rootfs without requiring an
445 initramfs.
446 See Documentation/device-mapper/dm-init.txt for dm-mod.create="..."
447 format.
448
449 If unsure, say N.
450
439config DM_UEVENT451config DM_UEVENT
440 bool "DM uevents"452 bool "DM uevents"
441 depends on BLK_DEV_DM453 depends on BLK_DEV_DM
drivers/md/Makefile+4−0
@@ -69,6 +69,10 @@ obj-$(CONFIG_DM_INTEGRITY) += dm-integrity.o · 68 unmodified lines
69obj-$(CONFIG_DM_ZONED) += dm-zoned.o69obj-$(CONFIG_DM_ZONED) += dm-zoned.o
70obj-$(CONFIG_DM_WRITECACHE) += dm-writecache.o70obj-$(CONFIG_DM_WRITECACHE) += dm-writecache.o
71 71
72ifeq ($(CONFIG_DM_INIT),y)
73dm-mod-objs += dm-init.o
74endif
75
72ifeq ($(CONFIG_DM_UEVENT),y)76ifeq ($(CONFIG_DM_UEVENT),y)
73dm-mod-objs += dm-uevent.o77dm-mod-objs += dm-uevent.o
74endif78endif
drivers/md/dm-cache-target.c+100−27
@@ -353,6 +353,7 @@ struct cache_features { · 352 unmodified lines
353 enum cache_metadata_mode mode;353 enum cache_metadata_mode mode;
354 enum cache_io_mode io_mode;354 enum cache_io_mode io_mode;
355 unsigned metadata_version;355 unsigned metadata_version;
356 bool discard_passdown:1;
356};357};
357 358
358struct cache_stats {359struct cache_stats {
@@ -1899,7 +1900,11 @@ static bool process_discard_bio(struct cache *cache, struct bio *bio) · 1540 unmodified lines
1899 b = to_dblock(from_dblock(b) + 1);1900 b = to_dblock(from_dblock(b) + 1);
1900 }1901 }
1901 1902
1902 bio_endio(bio);1903 if (cache->features.discard_passdown) {
1904 remap_to_origin(cache, bio);
1905 generic_make_request(bio);
1906 } else
1907 bio_endio(bio);
1903 1908
1904 return false;1909 return false;
1905}1910}
@@ -2233,13 +2238,14 @@ static void init_features(struct cache_features *cf) · 327 unmodified lines
2233 cf->mode = CM_WRITE;2238 cf->mode = CM_WRITE;
2234 cf->io_mode = CM_IO_WRITEBACK;2239 cf->io_mode = CM_IO_WRITEBACK;
2235 cf->metadata_version = 1;2240 cf->metadata_version = 1;
2241 cf->discard_passdown = true;
2236}2242}
2237 2243
2238static int parse_features(struct cache_args *ca, struct dm_arg_set *as,2244static int parse_features(struct cache_args *ca, struct dm_arg_set *as,
2239 char **error)2245 char **error)
2240{2246{
2241 static const struct dm_arg _args[] = {2247 static const struct dm_arg _args[] = {
2242 {0, 2, "Invalid number of cache feature arguments"},2248 {0, 3, "Invalid number of cache feature arguments"},
2243 };2249 };
2244 2250
2245 int r, mode_ctr = 0;2251 int r, mode_ctr = 0;
@@ -2274,6 +2280,9 @@ static int parse_features(struct cache_args *ca, struct dm_arg_set *as, · 28 unmodified lines
2274 else if (!strcasecmp(arg, "metadata2"))2280 else if (!strcasecmp(arg, "metadata2"))
2275 cf->metadata_version = 2;2281 cf->metadata_version = 2;
2276 2282
2283 else if (!strcasecmp(arg, "no_discard_passdown"))
2284 cf->discard_passdown = false;
2285
2277 else {2286 else {
2278 *error = "Unrecognised cache feature requested";2287 *error = "Unrecognised cache feature requested";
2279 return -EINVAL;2288 return -EINVAL;
@@ -2496,7 +2505,6 @@ static int cache_create(struct cache_args *ca, struct cache **result) · 216 unmodified lines
2496 2505
2497 ti->num_discard_bios = 1;2506 ti->num_discard_bios = 1;
2498 ti->discards_supported = true;2507 ti->discards_supported = true;
2499 ti->split_discard_bios = false;
2500 2508
2501 ti->per_io_data_size = sizeof(struct per_bio_data);2509 ti->per_io_data_size = sizeof(struct per_bio_data);
2502 2510
@@ -3120,6 +3128,39 @@ static void cache_resume(struct dm_target *ti) · 617 unmodified lines
3120 do_waker(&cache->waker.work);3128 do_waker(&cache->waker.work);
3121}3129}
3122 3130
3131static void emit_flags(struct cache *cache, char *result,
3132 unsigned maxlen, ssize_t *sz_ptr)
3133{
3134 ssize_t sz = *sz_ptr;
3135 struct cache_features *cf = &cache->features;
3136 unsigned count = (cf->metadata_version == 2) + !cf->discard_passdown + 1;
3137
3138 DMEMIT("%u ", count);
3139
3140 if (cf->metadata_version == 2)
3141 DMEMIT("metadata2 ");
3142
3143 if (writethrough_mode(cache))
3144 DMEMIT("writethrough ");
3145
3146 else if (passthrough_mode(cache))
3147 DMEMIT("passthrough ");
3148
3149 else if (writeback_mode(cache))
3150 DMEMIT("writeback ");
3151
3152 else {
3153 DMEMIT("unknown ");
3154 DMERR("%s: internal error: unknown io mode: %d",
3155 cache_device_name(cache), (int) cf->io_mode);
3156 }
3157
3158 if (!cf->discard_passdown)
3159 DMEMIT("no_discard_passdown ");
3160
3161 *sz_ptr = sz;
3162}
3163
3123/*3164/*
3124 * Status format:3165 * Status format:
3125 *3166 *
@@ -3186,25 +3227,7 @@ static void cache_status(struct dm_target *ti, status_type_t type, · 60 unmodified lines
3186 (unsigned) atomic_read(&cache->stats.promotion),3227 (unsigned) atomic_read(&cache->stats.promotion),
3187 (unsigned long) atomic_read(&cache->nr_dirty));3228 (unsigned long) atomic_read(&cache->nr_dirty));
3188 3229
3189 if (cache->features.metadata_version == 2)3230 emit_flags(cache, result, maxlen, &sz);
3190 DMEMIT("2 metadata2 ");
3191 else
3192 DMEMIT("1 ");
3193
3194 if (writethrough_mode(cache))
3195 DMEMIT("writethrough ");
3196
3197 else if (passthrough_mode(cache))
3198 DMEMIT("passthrough ");
3199
3200 else if (writeback_mode(cache))
3201 DMEMIT("writeback ");
3202
3203 else {
3204 DMERR("%s: internal error: unknown io mode: %d",
3205 cache_device_name(cache), (int) cache->features.io_mode);
3206 goto err;
3207 }
3208 3231
3209 DMEMIT("2 migration_threshold %llu ", (unsigned long long) cache->migration_threshold);3232 DMEMIT("2 migration_threshold %llu ", (unsigned long long) cache->migration_threshold);
3210 3233
@@ -3433,14 +3456,62 @@ static int cache_iterate_devices(struct dm_target *ti, · 222 unmodified lines
3433 return r;3456 return r;
3434}3457}
3435 3458
3459static bool origin_dev_supports_discard(struct block_device *origin_bdev)
3460{
3461 struct request_queue *q = bdev_get_queue(origin_bdev);
3462
3463 return q && blk_queue_discard(q);
3464}
3465
3466/*
3467 * If discard_passdown was enabled verify that the origin device
3468 * supports discards. Disable discard_passdown if not.
3469 */
3470static void disable_passdown_if_not_supported(struct cache *cache)
3471{
3472 struct block_device *origin_bdev = cache->origin_dev->bdev;
3473 struct queue_limits *origin_limits = &bdev_get_queue(origin_bdev)->limits;
3474 const char *reason = NULL;
3475 char buf[BDEVNAME_SIZE];
3476
3477 if (!cache->features.discard_passdown)
3478 return;
3479
3480 if (!origin_dev_supports_discard(origin_bdev))
3481 reason = "discard unsupported";
3482
3483 else if (origin_limits->max_discard_sectors < cache->sectors_per_block)
3484 reason = "max discard sectors smaller than a block";
3485
3486 if (reason) {
3487 DMWARN("Origin device (%s) %s: Disabling discard passdown.",
3488 bdevname(origin_bdev, buf), reason);
3489 cache->features.discard_passdown = false;
3490 }
3491}
3492
3436static void set_discard_limits(struct cache *cache, struct queue_limits *limits)3493static void set_discard_limits(struct cache *cache, struct queue_limits *limits)
3437{3494{
3495 struct block_device *origin_bdev = cache->origin_dev->bdev;
3496 struct queue_limits *origin_limits = &bdev_get_queue(origin_bdev)->limits;
3497
3498 if (!cache->features.discard_passdown) {
3499 /* No passdown is done so setting own virtual limits */
3500 limits->max_discard_sectors = min_t(sector_t, cache->discard_block_size * 1024,
3501 cache->origin_sectors);
3502 limits->discard_granularity = cache->discard_block_size << SECTOR_SHIFT;
3503 return;
3504 }
3505
3438 /*3506 /*
3439 * FIXME: these limits may be incompatible with the cache device3507 * cache_iterate_devices() is stacking both origin and fast device limits
3508 * but discards aren't passed to fast device, so inherit origin's limits.
3440 */3509 */
3441 limits->max_discard_sectors = min_t(sector_t, cache->discard_block_size * 1024,3510 limits->max_discard_sectors = origin_limits->max_discard_sectors;
3442 cache->origin_sectors);3511 limits->max_hw_discard_sectors = origin_limits->max_hw_discard_sectors;
3443 limits->discard_granularity = cache->discard_block_size << SECTOR_SHIFT;3512 limits->discard_granularity = origin_limits->discard_granularity;
3513 limits->discard_alignment = origin_limits->discard_alignment;
3514 limits->discard_misaligned = origin_limits->discard_misaligned;
3444}3515}
3445 3516
3446static void cache_io_hints(struct dm_target *ti, struct queue_limits *limits)3517static void cache_io_hints(struct dm_target *ti, struct queue_limits *limits)
@@ -3457,6 +3528,8 @@ static void cache_io_hints(struct dm_target *ti, struct queue_limits *limits) · 10 unmodified lines
3457 blk_limits_io_min(limits, cache->sectors_per_block << SECTOR_SHIFT);3528 blk_limits_io_min(limits, cache->sectors_per_block << SECTOR_SHIFT);
3458 blk_limits_io_opt(limits, cache->sectors_per_block << SECTOR_SHIFT);3529 blk_limits_io_opt(limits, cache->sectors_per_block << SECTOR_SHIFT);
3459 }3530 }
3531
3532 disable_passdown_if_not_supported(cache);
3460 set_discard_limits(cache, limits);3533 set_discard_limits(cache, limits);
3461}3534}
3462 3535
@@ -3464,7 +3537,7 @@ static void cache_io_hints(struct dm_target *ti, struct queue_limits *limits) · 1 unmodified line
3464 3537
3465static struct target_type cache_target = {3538static struct target_type cache_target = {
3466 .name = "cache",3539 .name = "cache",
3467 .version = {2, 0, 0},3540 .version = {2, 1, 0},
3468 .module = THIS_MODULE,3541 .module = THIS_MODULE,
3469 .ctr = cache_ctr,3542 .ctr = cache_ctr,
3470 .dtr = cache_dtr,3543 .dtr = cache_dtr,
drivers/md/dm-init.c+303−0
@@ -0,0 +1,303 @@
1// SPDX-License-Identifier: GPL-2.0
2
3/*
4 * dm-init.c
5 * Copyright (C) 2017 The Chromium OS Authors <chromium-os-dev@chromium.org>
6 *
7 * This file is released under the GPLv2.
8 */
9
10#include <linux/ctype.h>
11#include <linux/device.h>
12#include <linux/device-mapper.h>
13#include <linux/init.h>
14#include <linux/list.h>
15#include <linux/moduleparam.h>
16
17#define DM_MSG_PREFIX "init"
18#define DM_MAX_DEVICES 256
19#define DM_MAX_TARGETS 256
20#define DM_MAX_STR_SIZE 4096
21
22static char *create;
23
24/*
25 * Format: dm-mod.create=<name>,<uuid>,<minor>,<flags>,<table>[,<table>+][;<name>,<uuid>,<minor>,<flags>,<table>[,<table>+]+]
26 * Table format: <start_sector> <num_sectors> <target_type> <target_args>
27 *
28 * See Documentation/device-mapper/dm-init.txt for dm-mod.create="..." format
29 * details.
30 */
31
32struct dm_device {
33 struct dm_ioctl dmi;
34 struct dm_target_spec *table[DM_MAX_TARGETS];
35 char *target_args_array[DM_MAX_TARGETS];
36 struct list_head list;
37};
38
39const char *dm_allowed_targets[] __initconst = {
40 "crypt",
41 "delay",
42 "linear",
43 "snapshot-origin",
44 "striped",
45 "verity",
46};
47
48static int __init dm_verify_target_type(const char *target)
49{
50 unsigned int i;
51
52 for (i = 0; i < ARRAY_SIZE(dm_allowed_targets); i++) {
53 if (!strcmp(dm_allowed_targets[i], target))
54 return 0;
55 }
56 return -EINVAL;
57}
58
59static void __init dm_setup_cleanup(struct list_head *devices)
60{
61 struct dm_device *dev, *tmp;
62 unsigned int i;
63
64 list_for_each_entry_safe(dev, tmp, devices, list) {
65 list_del(&dev->list);
66 for (i = 0; i < dev->dmi.target_count; i++) {
67 kfree(dev->table[i]);
68 kfree(dev->target_args_array[i]);
69 }
70 kfree(dev);
71 }
72}
73
74/**
75 * str_field_delimit - delimit a string based on a separator char.
76 * @str: the pointer to the string to delimit.
77 * @separator: char that delimits the field
78 *
79 * Find a @separator and replace it by '\0'.
80 * Remove leading and trailing spaces.
81 * Return the remainder string after the @separator.
82 */
83static char __init *str_field_delimit(char **str, char separator)
84{
85 char *s;
86
87 /* TODO: add support for escaped characters */
88 *str = skip_spaces(*str);
89 s = strchr(*str, separator);
90 /* Delimit the field and remove trailing spaces */
91 if (s)
92 *s = '\0';
93 *str = strim(*str);
94 return s ? ++s : NULL;
95}
96
97/**
98 * dm_parse_table_entry - parse a table entry
99 * @dev: device to store the parsed information.
100 * @str: the pointer to a string with the format:
101 * <start_sector> <num_sectors> <target_type> <target_args>[, ...]
102 *
103 * Return the remainder string after the table entry, i.e, after the comma which
104 * delimits the entry or NULL if reached the end of the string.
105 */
106static char __init *dm_parse_table_entry(struct dm_device *dev, char *str)
107{
108 const unsigned int n = dev->dmi.target_count - 1;
109 struct dm_target_spec *sp;
110 unsigned int i;
111 /* fields: */
112 char *field[4];
113 char *next;
114
115 field[0] = str;
116 /* Delimit first 3 fields that are separated by space */
117 for (i = 0; i < ARRAY_SIZE(field) - 1; i++) {
118 field[i + 1] = str_field_delimit(&field[i], ' ');
119 if (!field[i + 1])
120 return ERR_PTR(-EINVAL);
121 }
122 /* Delimit last field that can be terminated by comma */
123 next = str_field_delimit(&field[i], ',');
124
125 sp = kzalloc(sizeof(*sp), GFP_KERNEL);
126 if (!sp)
127 return ERR_PTR(-ENOMEM);
128 dev->table[n] = sp;
129
130 /* start_sector */
131 if (kstrtoull(field[0], 0, &sp->sector_start))
132 return ERR_PTR(-EINVAL);
133 /* num_sector */
134 if (kstrtoull(field[1], 0, &sp->length))
135 return ERR_PTR(-EINVAL);
136 /* target_type */
137 strscpy(sp->target_type, field[2], sizeof(sp->target_type));
138 if (dm_verify_target_type(sp->target_type)) {
139 DMERR("invalid type \"%s\"", sp->target_type);
140 return ERR_PTR(-EINVAL);
141 }
142 /* target_args */
143 dev->target_args_array[n] = kstrndup(field[3], GFP_KERNEL,
144 DM_MAX_STR_SIZE);
145 if (!dev->target_args_array[n])
146 return ERR_PTR(-ENOMEM);
147
148 return next;
149}
150
151/**
152 * dm_parse_table - parse "dm-mod.create=" table field
153 * @dev: device to store the parsed information.
154 * @str: the pointer to a string with the format:
155 * <table>[,<table>+]
156 */
157static int __init dm_parse_table(struct dm_device *dev, char *str)
158{
159 char *table_entry = str;
160
161 while (table_entry) {
162 DMDEBUG("parsing table \"%s\"", str);
163 if (++dev->dmi.target_count >= DM_MAX_TARGETS) {
164 DMERR("too many targets %u > %d",
165 dev->dmi.target_count, DM_MAX_TARGETS);
166 return -EINVAL;
167 }
168 table_entry = dm_parse_table_entry(dev, table_entry);
169 if (IS_ERR(table_entry)) {
170 DMERR("couldn't parse table");
171 return PTR_ERR(table_entry);
172 }
173 }
174
175 return 0;
176}
177
178/**
179 * dm_parse_device_entry - parse a device entry
180 * @dev: device to store the parsed information.
181 * @str: the pointer to a string with the format:
182 * name,uuid,minor,flags,table[; ...]
183 *
184 * Return the remainder string after the table entry, i.e, after the semi-colon
185 * which delimits the entry or NULL if reached the end of the string.
186 */
187static char __init *dm_parse_device_entry(struct dm_device *dev, char *str)
188{
189 /* There are 5 fields: name,uuid,minor,flags,table; */
190 char *field[5];
191 unsigned int i;
192 char *next;
193
194 field[0] = str;
195 /* Delimit first 4 fields that are separated by comma */
196 for (i = 0; i < ARRAY_SIZE(field) - 1; i++) {
197 field[i+1] = str_field_delimit(&field[i], ',');
198 if (!field[i+1])
199 return ERR_PTR(-EINVAL);
200 }
201 /* Delimit last field that can be delimited by semi-colon */
202 next = str_field_delimit(&field[i], ';');
203
204 /* name */
205 strscpy(dev->dmi.name, field[0], sizeof(dev->dmi.name));
206 /* uuid */
207 strscpy(dev->dmi.uuid, field[1], sizeof(dev->dmi.uuid));
208 /* minor */
209 if (strlen(field[2])) {
210 if (kstrtoull(field[2], 0, &dev->dmi.dev))
211 return ERR_PTR(-EINVAL);
212 dev->dmi.flags |= DM_PERSISTENT_DEV_FLAG;
213 }
214 /* flags */
215 if (!strcmp(field[3], "ro"))
216 dev->dmi.flags |= DM_READONLY_FLAG;
217 else if (strcmp(field[3], "rw"))
218 return ERR_PTR(-EINVAL);
219 /* table */
220 if (dm_parse_table(dev, field[4]))
221 return ERR_PTR(-EINVAL);
222
223 return next;
224}
225
226/**
227 * dm_parse_devices - parse "dm-mod.create=" argument
228 * @devices: list of struct dm_device to store the parsed information.
229 * @str: the pointer to a string with the format:
230 * <device>[;<device>+]
231 */
232static int __init dm_parse_devices(struct list_head *devices, char *str)
233{
234 unsigned long ndev = 0;
235 struct dm_device *dev;
236 char *device = str;
237
238 DMDEBUG("parsing \"%s\"", str);
239 while (device) {
240 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
241 if (!dev)
242 return -ENOMEM;
243 list_add_tail(&dev->list, devices);
244
245 if (++ndev >= DM_MAX_DEVICES) {
246 DMERR("too many targets %u > %d",
247 dev->dmi.target_count, DM_MAX_TARGETS);
248 return -EINVAL;
249 }
250
251 device = dm_parse_device_entry(dev, device);
252 if (IS_ERR(device)) {
253 DMERR("couldn't parse device");
254 return PTR_ERR(device);
255 }
256 }
257
258 return 0;
259}
260
261/**
262 * dm_init_init - parse "dm-mod.create=" argument and configure drivers
263 */
264static int __init dm_init_init(void)
265{
266 struct dm_device *dev;
267 LIST_HEAD(devices);
268 char *str;
269 int r;
270
271 if (!create)
272 return 0;
273
274 if (strlen(create) >= DM_MAX_STR_SIZE) {
275 DMERR("Argument is too big. Limit is %d\n", DM_MAX_STR_SIZE);
276 return -EINVAL;
277 }
278 str = kstrndup(create, GFP_KERNEL, DM_MAX_STR_SIZE);
279 if (!str)
280 return -ENOMEM;
281
282 r = dm_parse_devices(&devices, str);
283 if (r)
284 goto out;
285
286 DMINFO("waiting for all devices to be available before creating mapped devices\n");
287 wait_for_device_probe();
288
289 list_for_each_entry(dev, &devices, list) {
290 if (dm_early_create(&dev->dmi, dev->table,
291 dev->target_args_array))
292 break;
293 }
294out:
295 kfree(str);
296 dm_setup_cleanup(&devices);
297 return r;
298}
299
300late_initcall(dm_init_init);
301
302module_param(create, charp, 0);
303MODULE_PARM_DESC(create, "Create a mapped device in early boot");
drivers/md/dm-integrity.c+5−5
@@ -1122,7 +1122,7 @@ static int dm_integrity_rw_tag(struct dm_integrity_c *ic, unsigned char *tag, se · 1121 unmodified lines
1122 return r;1122 return r;
1123 1123
1124 data = dm_bufio_read(ic->bufio, *metadata_block, &b);1124 data = dm_bufio_read(ic->bufio, *metadata_block, &b);
1125 if (unlikely(IS_ERR(data)))1125 if (IS_ERR(data))
1126 return PTR_ERR(data);1126 return PTR_ERR(data);
1127 1127
1128 to_copy = min((1U << SECTOR_SHIFT << ic->log2_buffer_sectors) - *metadata_offset, total_size);1128 to_copy = min((1U << SECTOR_SHIFT << ic->log2_buffer_sectors) - *metadata_offset, total_size);
@@ -1368,8 +1368,8 @@ again: · 239 unmodified lines
1368 checksums_ptr - checksums, !dio->write ? TAG_CMP : TAG_WRITE);1368 checksums_ptr - checksums, !dio->write ? TAG_CMP : TAG_WRITE);
1369 if (unlikely(r)) {1369 if (unlikely(r)) {
1370 if (r > 0) {1370 if (r > 0) {
1371 DMERR("Checksum failed at sector 0x%llx",1371 DMERR_LIMIT("Checksum failed at sector 0x%llx",
1372 (unsigned long long)(sector - ((r + ic->tag_size - 1) / ic->tag_size)));1372 (unsigned long long)(sector - ((r + ic->tag_size - 1) / ic->tag_size)));
1373 r = -EILSEQ;1373 r = -EILSEQ;
1374 atomic64_inc(&ic->number_of_mismatches);1374 atomic64_inc(&ic->number_of_mismatches);
1375 }1375 }
@@ -1561,8 +1561,8 @@ retry_kmap: · 185 unmodified lines
1561 1561
1562 integrity_sector_checksum(ic, logical_sector, mem + bv.bv_offset, checksums_onstack);1562 integrity_sector_checksum(ic, logical_sector, mem + bv.bv_offset, checksums_onstack);
1563 if (unlikely(memcmp(checksums_onstack, journal_entry_tag(ic, je), ic->tag_size))) {1563 if (unlikely(memcmp(checksums_onstack, journal_entry_tag(ic, je), ic->tag_size))) {
1564 DMERR("Checksum failed when reading from journal, at sector 0x%llx",1564 DMERR_LIMIT("Checksum failed when reading from journal, at sector 0x%llx",
1565 (unsigned long long)logical_sector);1565 (unsigned long long)logical_sector);
1566 }1566 }
1567 }1567 }
1568#endif1568#endif
drivers/md/dm-ioctl.c+103−0
@@ -2018,3 +2018,106 @@ out: · 2017 unmodified lines
2018 2018
2019 return r;2019 return r;
2020}2020}
2021
2022
2023/**
2024 * dm_early_create - create a mapped device in early boot.
2025 *
2026 * @dmi: Contains main information of the device mapping to be created.
2027 * @spec_array: array of pointers to struct dm_target_spec. Describes the
2028 * mapping table of the device.
2029 * @target_params_array: array of strings with the parameters to a specific
2030 * target.
2031 *
2032 * Instead of having the struct dm_target_spec and the parameters for every
2033 * target embedded at the end of struct dm_ioctl (as performed in a normal
2034 * ioctl), pass them as arguments, so the caller doesn't need to serialize them.
2035 * The size of the spec_array and target_params_array is given by
2036 * @dmi->target_count.
2037 * This function is supposed to be called in early boot, so locking mechanisms
2038 * to protect against concurrent loads are not required.
2039 */
2040int __init dm_early_create(struct dm_ioctl *dmi,
2041 struct dm_target_spec **spec_array,
2042 char **target_params_array)
2043{
2044 int r, m = DM_ANY_MINOR;
2045 struct dm_table *t, *old_map;
2046 struct mapped_device *md;
2047 unsigned int i;
2048
2049 if (!dmi->target_count)
2050 return -EINVAL;
2051
2052 r = check_name(dmi->name);
2053 if (r)
2054 return r;
2055
2056 if (dmi->flags & DM_PERSISTENT_DEV_FLAG)
2057 m = MINOR(huge_decode_dev(dmi->dev));
2058
2059 /* alloc dm device */
2060 r = dm_create(m, &md);
2061 if (r)
2062 return r;
2063
2064 /* hash insert */
2065 r = dm_hash_insert(dmi->name, *dmi->uuid ? dmi->uuid : NULL, md);
2066 if (r)
2067 goto err_destroy_dm;
2068
2069 /* alloc table */
2070 r = dm_table_create(&t, get_mode(dmi), dmi->target_count, md);
2071 if (r)
2072 goto err_destroy_dm;
2073
2074 /* add targets */
2075 for (i = 0; i < dmi->target_count; i++) {
2076 r = dm_table_add_target(t, spec_array[i]->target_type,
2077 (sector_t) spec_array[i]->sector_start,
2078 (sector_t) spec_array[i]->length,
2079 target_params_array[i]);
2080 if (r) {
2081 DMWARN("error adding target to table");
2082 goto err_destroy_table;
2083 }
2084 }
2085
2086 /* finish table */
2087 r = dm_table_complete(t);
2088 if (r)
2089 goto err_destroy_table;
2090
2091 md->type = dm_table_get_type(t);
2092 /* setup md->queue to reflect md's type (may block) */
2093 r = dm_setup_md_queue(md, t);
2094 if (r) {
2095 DMWARN("unable to set up device queue for new table.");
2096 goto err_destroy_table;
2097 }
2098
2099 /* Set new map */
2100 dm_suspend(md, 0);
2101 old_map = dm_swap_table(md, t);
2102 if (IS_ERR(old_map)) {
2103 r = PTR_ERR(old_map);
2104 goto err_destroy_table;
2105 }
2106 set_disk_ro(dm_disk(md), !!(dmi->flags & DM_READONLY_FLAG));
2107
2108 /* resume device */
2109 r = dm_resume(md);
2110 if (r)
2111 goto err_destroy_table;
2112
2113 DMINFO("%s (%s) is ready", md->disk->disk_name, dmi->name);
2114 dm_put(md);
2115 return 0;
2116
2117err_destroy_table:
2118 dm_table_destroy(t);
2119err_destroy_dm:
2120 dm_put(md);
2121 dm_destroy(md);
2122 return r;
2123}
drivers/md/dm-raid.c+9−5
@@ -2986,11 +2986,6 @@ static void configure_discard_support(struct raid_set *rs) · 2985 unmodified lines
2986 }2986 }
2987 }2987 }
2988 2988
2989 /*
2990 * RAID1 and RAID10 personalities require bio splitting,
2991 * RAID0/4/5/6 don't and process large discard bios properly.
2992 */
2993 ti->split_discard_bios = !!(rs_is_raid1(rs) || rs_is_raid10(rs));
2994 ti->num_discard_bios = 1;2989 ti->num_discard_bios = 1;
2995}2990}
2996 2991
@@ -3747,6 +3742,15 @@ static void raid_io_hints(struct dm_target *ti, struct queue_limits *limits) · 750 unmodified lines
3747 3742
3748 blk_limits_io_min(limits, chunk_size);3743 blk_limits_io_min(limits, chunk_size);
3749 blk_limits_io_opt(limits, chunk_size * mddev_data_stripes(rs));3744 blk_limits_io_opt(limits, chunk_size * mddev_data_stripes(rs));
3745
3746 /*
3747 * RAID1 and RAID10 personalities require bio splitting,
3748 * RAID0/4/5/6 don't and process large discard bios properly.
3749 */
3750 if (rs_is_raid1(rs) || rs_is_raid10(rs)) {
3751 limits->discard_granularity = chunk_size;
3752 limits->max_discard_sectors = chunk_size;
3753 }
3750}3754}
3751 3755
3752static void raid_postsuspend(struct dm_target *ti)3756static void raid_postsuspend(struct dm_target *ti)
drivers/md/dm-rq.c+16−0
@@ -12,6 +12,22 @@ · 11 unmodified lines
12 12
13#define DM_MSG_PREFIX "core-rq"13#define DM_MSG_PREFIX "core-rq"
14 14
15/*
16 * One of these is allocated per request.
17 */
18struct dm_rq_target_io {
19 struct mapped_device *md;
20 struct dm_target *ti;
21 struct request *orig, *clone;
22 struct kthread_work work;
23 blk_status_t error;
24 union map_info info;
25 struct dm_stats_aux stats_aux;
26 unsigned long duration_jiffies;
27 unsigned n_sectors;
28 unsigned completed;
29};
30
15#define DM_MQ_NR_HW_QUEUES 131#define DM_MQ_NR_HW_QUEUES 1
16#define DM_MQ_QUEUE_DEPTH 204832#define DM_MQ_QUEUE_DEPTH 2048
17static unsigned dm_mq_nr_hw_queues = DM_MQ_NR_HW_QUEUES;33static unsigned dm_mq_nr_hw_queues = DM_MQ_NR_HW_QUEUES;
drivers/md/dm-rq.h+0−16
@@ -16,22 +16,6 @@ · 15 unmodified lines
16 16
17struct mapped_device;17struct mapped_device;
18 18
19/*
20 * One of these is allocated per request.
21 */
22struct dm_rq_target_io {
23 struct mapped_device *md;
24 struct dm_target *ti;
25 struct request *orig, *clone;
26 struct kthread_work work;
27 blk_status_t error;
28 union map_info info;
29 struct dm_stats_aux stats_aux;
30 unsigned long duration_jiffies;
31 unsigned n_sectors;
32 unsigned completed;
33};
34
35/*19/*
36 * For request-based dm - the bio clones we allocate are embedded in these20 * For request-based dm - the bio clones we allocate are embedded in these
37 * structs.21 * structs.
drivers/md/dm-snap.c+0−8
@@ -2338,13 +2338,6 @@ static int origin_map(struct dm_target *ti, struct bio *bio) · 2337 unmodified lines
2338 return do_origin(o->dev, bio);2338 return do_origin(o->dev, bio);
2339}2339}
2340 2340
2341static long origin_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
2342 long nr_pages, void **kaddr, pfn_t *pfn)
2343{
2344 DMWARN("device does not support dax.");
2345 return -EIO;
2346}
2347
2348/*2341/*
2349 * Set the target "max_io_len" field to the minimum of all the snapshots'2342 * Set the target "max_io_len" field to the minimum of all the snapshots'
2350 * chunk sizes.2343 * chunk sizes.
@@ -2404,7 +2397,6 @@ static struct target_type origin_target = { · 53 unmodified lines
2404 .postsuspend = origin_postsuspend,2397 .postsuspend = origin_postsuspend,
2405 .status = origin_status,2398 .status = origin_status,
2406 .iterate_devices = origin_iterate_devices,2399 .iterate_devices = origin_iterate_devices,
2407 .direct_access = origin_dax_direct_access,
2408};2400};
2409 2401
2410static struct target_type snapshot_target = {2402static struct target_type snapshot_target = {
drivers/md/dm-switch.c+1−2
@@ -61,8 +61,7 @@ static struct switch_ctx *alloc_switch_ctx(struct dm_target *ti, unsigned nr_pat · 60 unmodified lines
61{61{
62 struct switch_ctx *sctx;62 struct switch_ctx *sctx;
63 63
64 sctx = kzalloc(sizeof(struct switch_ctx) + nr_paths * sizeof(struct switch_path),64 sctx = kzalloc(struct_size(sctx, path_list, nr_paths), GFP_KERNEL);
65 GFP_KERNEL);
66 if (!sctx)65 if (!sctx)
67 return NULL;66 return NULL;
68 67
drivers/md/dm-thin.c+13−1
@@ -3283,6 +3283,13 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv) · 3282 unmodified lines
3283 as.argc = argc;3283 as.argc = argc;
3284 as.argv = argv;3284 as.argv = argv;
3285 3285
3286 /* make sure metadata and data are different devices */
3287 if (!strcmp(argv[0], argv[1])) {
3288 ti->error = "Error setting metadata or data device";
3289 r = -EINVAL;
3290 goto out_unlock;
3291 }
3292
3286 /*3293 /*
3287 * Set default pool features.3294 * Set default pool features.
3288 */3295 */
@@ -4167,6 +4174,12 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv) · 878 unmodified lines
4167 tc->sort_bio_list = RB_ROOT;4174 tc->sort_bio_list = RB_ROOT;
4168 4175
4169 if (argc == 3) {4176 if (argc == 3) {
4177 if (!strcmp(argv[0], argv[2])) {
4178 ti->error = "Error setting origin device";
4179 r = -EINVAL;
4180 goto bad_origin_dev;
4181 }
4182
4170 r = dm_get_device(ti, argv[2], FMODE_READ, &origin_dev);4183 r = dm_get_device(ti, argv[2], FMODE_READ, &origin_dev);
4171 if (r) {4184 if (r) {
4172 ti->error = "Error opening origin device";4185 ti->error = "Error opening origin device";
@@ -4227,7 +4240,6 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv) · 54 unmodified lines
4227 if (tc->pool->pf.discard_enabled) {4240 if (tc->pool->pf.discard_enabled) {
4228 ti->discards_supported = true;4241 ti->discards_supported = true;
4229 ti->num_discard_bios = 1;4242 ti->num_discard_bios = 1;
4230 ti->split_discard_bios = false;
4231 }4243 }
4232 4244
4233 mutex_unlock(&dm_thin_pool_table.mutex);4245 mutex_unlock(&dm_thin_pool_table.mutex);
drivers/md/dm-verity-fec.c+3−3
@@ -73,7 +73,7 @@ static u8 *fec_read_parity(struct dm_verity *v, u64 rsb, int index, · 72 unmodified lines
73 *offset = (unsigned)(position - (block << v->data_dev_block_bits));73 *offset = (unsigned)(position - (block << v->data_dev_block_bits));
74 74
75 res = dm_bufio_read(v->fec->bufio, v->fec->start + block, buf);75 res = dm_bufio_read(v->fec->bufio, v->fec->start + block, buf);
76 if (unlikely(IS_ERR(res))) {76 if (IS_ERR(res)) {
77 DMERR("%s: FEC %llu: parity read failed (block %llu): %ld",77 DMERR("%s: FEC %llu: parity read failed (block %llu): %ld",
78 v->data_dev->name, (unsigned long long)rsb,78 v->data_dev->name, (unsigned long long)rsb,
79 (unsigned long long)(v->fec->start + block),79 (unsigned long long)(v->fec->start + block),
@@ -163,7 +163,7 @@ static int fec_decode_bufs(struct dm_verity *v, struct dm_verity_fec_io *fio, · 83 unmodified lines
163 dm_bufio_release(buf);163 dm_bufio_release(buf);
164 164
165 par = fec_read_parity(v, rsb, block_offset, &offset, &buf);165 par = fec_read_parity(v, rsb, block_offset, &offset, &buf);
166 if (unlikely(IS_ERR(par)))166 if (IS_ERR(par))
167 return PTR_ERR(par);167 return PTR_ERR(par);
168 }168 }
169 }169 }
@@ -253,7 +253,7 @@ static int fec_read_bufs(struct dm_verity *v, struct dm_verity_io *io, · 83 unmodified lines
253 }253 }
254 254
255 bbuf = dm_bufio_read(bufio, block, &buf);255 bbuf = dm_bufio_read(bufio, block, &buf);
256 if (unlikely(IS_ERR(bbuf))) {256 if (IS_ERR(bbuf)) {
257 DMWARN_LIMIT("%s: FEC %llu: read failed (%llu): %ld",257 DMWARN_LIMIT("%s: FEC %llu: read failed (%llu): %ld",
258 v->data_dev->name,258 v->data_dev->name,
259 (unsigned long long)rsb,259 (unsigned long long)rsb,
drivers/md/dm-writecache.c+1−1
@@ -1859,7 +1859,7 @@ static int writecache_ctr(struct dm_target *ti, unsigned argc, char **argv) · 1858 unmodified lines
1859 goto bad;1859 goto bad;
1860 }1860 }
1861 1861
1862 wc->writeback_wq = alloc_workqueue("writecache-writeabck", WQ_MEM_RECLAIM, 1);1862 wc->writeback_wq = alloc_workqueue("writecache-writeback", WQ_MEM_RECLAIM, 1);
1863 if (!wc->writeback_wq) {1863 if (!wc->writeback_wq) {
1864 r = -ENOMEM;1864 r = -ENOMEM;
1865 ti->error = "Could not allocate writeback workqueue";1865 ti->error = "Could not allocate writeback workqueue";
drivers/md/dm-zoned-target.c+0−1
@@ -727,7 +727,6 @@ static int dmz_ctr(struct dm_target *ti, unsigned int argc, char **argv) · 726 unmodified lines
727 ti->per_io_data_size = sizeof(struct dmz_bioctx);727 ti->per_io_data_size = sizeof(struct dmz_bioctx);
728 ti->flush_supported = true;728 ti->flush_supported = true;
729 ti->discards_supported = true;729 ti->discards_supported = true;
730 ti->split_discard_bios = true;
731 730
732 /* The exposed capacity is the number of chunks that can be mapped */731 /* The exposed capacity is the number of chunks that can be mapped */
733 ti->len = (sector_t)dmz_nr_chunks(dmz->metadata) << dev->zone_nr_sectors_shift;732 ti->len = (sector_t)dmz_nr_chunks(dmz->metadata) << dev->zone_nr_sectors_shift;
drivers/md/dm.c+73−66
@@ -158,9 +158,6 @@ struct table_device { · 157 unmodified lines
158 struct dm_dev dm_dev;158 struct dm_dev dm_dev;
159};159};
160 160
161static struct kmem_cache *_rq_tio_cache;
162static struct kmem_cache *_rq_cache;
163
164/*161/*
165 * Bio-based DM's mempools' reserved IOs set by the user.162 * Bio-based DM's mempools' reserved IOs set by the user.
166 */163 */
@@ -222,20 +219,11 @@ static unsigned dm_get_numa_node(void) · 55 unmodified lines
222 219
223static int __init local_init(void)220static int __init local_init(void)
224{221{
225 int r = -ENOMEM;222 int r;
226
227 _rq_tio_cache = KMEM_CACHE(dm_rq_target_io, 0);
228 if (!_rq_tio_cache)
229 return r;
230
231 _rq_cache = kmem_cache_create("dm_old_clone_request", sizeof(struct request),
232 __alignof__(struct request), 0, NULL);
233 if (!_rq_cache)
234 goto out_free_rq_tio_cache;
235 223
236 r = dm_uevent_init();224 r = dm_uevent_init();
237 if (r)225 if (r)
238 goto out_free_rq_cache;226 return r;
239 227
240 deferred_remove_workqueue = alloc_workqueue("kdmremove", WQ_UNBOUND, 1);228 deferred_remove_workqueue = alloc_workqueue("kdmremove", WQ_UNBOUND, 1);
241 if (!deferred_remove_workqueue) {229 if (!deferred_remove_workqueue) {
@@ -257,10 +245,6 @@ out_free_workqueue: · 15 unmodified lines
257 destroy_workqueue(deferred_remove_workqueue);245 destroy_workqueue(deferred_remove_workqueue);
258out_uevent_exit:246out_uevent_exit:
259 dm_uevent_exit();247 dm_uevent_exit();
260out_free_rq_cache:
261 kmem_cache_destroy(_rq_cache);
262out_free_rq_tio_cache:
263 kmem_cache_destroy(_rq_tio_cache);
264 248
265 return r;249 return r;
266}250}
@@ -270,8 +254,6 @@ static void local_exit(void) · 3 unmodified lines
270 flush_scheduled_work();254 flush_scheduled_work();
271 destroy_workqueue(deferred_remove_workqueue);255 destroy_workqueue(deferred_remove_workqueue);
272 256
273 kmem_cache_destroy(_rq_cache);
274 kmem_cache_destroy(_rq_tio_cache);
275 unregister_blkdev(_major, _name);257 unregister_blkdev(_major, _name);
276 dm_uevent_exit();258 dm_uevent_exit();
277 259
@@ -1478,17 +1460,10 @@ static unsigned get_num_write_zeroes_bios(struct dm_target *ti) · 1200 unmodified lines
1478 return ti->num_write_zeroes_bios;1460 return ti->num_write_zeroes_bios;
1479}1461}
1480 1462
1481typedef bool (*is_split_required_fn)(struct dm_target *ti);
1482
1483static bool is_split_required_for_discard(struct dm_target *ti)
1484{
1485 return ti->split_discard_bios;
1486}
1487
1488static int __send_changing_extent_only(struct clone_info *ci, struct dm_target *ti,1463static int __send_changing_extent_only(struct clone_info *ci, struct dm_target *ti,
1489 unsigned num_bios, bool is_split_required)1464 unsigned num_bios)
1490{1465{
1491 unsigned len;1466 unsigned len = ci->sector_count;
1492 1467
1493 /*1468 /*
1494 * Even though the device advertised support for this type of1469 * Even though the device advertised support for this type of
@@ -1499,11 +1474,6 @@ static int __send_changing_extent_only(struct clone_info *ci, struct dm_target * · 4 unmodified lines
1499 if (!num_bios)1474 if (!num_bios)
1500 return -EOPNOTSUPP;1475 return -EOPNOTSUPP;
1501 1476
1502 if (!is_split_required)
1503 len = min((sector_t)ci->sector_count, max_io_len_target_boundary(ci->sector, ti));
1504 else
1505 len = min((sector_t)ci->sector_count, max_io_len(ci->sector, ti));
1506
1507 __send_duplicate_bios(ci, ti, num_bios, &len);1477 __send_duplicate_bios(ci, ti, num_bios, &len);
1508 1478
1509 ci->sector += len;1479 ci->sector += len;
@@ -1514,23 +1484,38 @@ static int __send_changing_extent_only(struct clone_info *ci, struct dm_target * · 4 unmodified lines
1514 1484
1515static int __send_discard(struct clone_info *ci, struct dm_target *ti)1485static int __send_discard(struct clone_info *ci, struct dm_target *ti)
1516{1486{
1517 return __send_changing_extent_only(ci, ti, get_num_discard_bios(ti),1487 return __send_changing_extent_only(ci, ti, get_num_discard_bios(ti));
1518 is_split_required_for_discard(ti));
1519}1488}
1520 1489
1521static int __send_secure_erase(struct clone_info *ci, struct dm_target *ti)1490static int __send_secure_erase(struct clone_info *ci, struct dm_target *ti)
1522{1491{
1523 return __send_changing_extent_only(ci, ti, get_num_secure_erase_bios(ti), false);1492 return __send_changing_extent_only(ci, ti, get_num_secure_erase_bios(ti));
1524}1493}
1525 1494
1526static int __send_write_same(struct clone_info *ci, struct dm_target *ti)1495static int __send_write_same(struct clone_info *ci, struct dm_target *ti)
1527{1496{
1528 return __send_changing_extent_only(ci, ti, get_num_write_same_bios(ti), false);1497 return __send_changing_extent_only(ci, ti, get_num_write_same_bios(ti));
1529}1498}
1530 1499
1531static int __send_write_zeroes(struct clone_info *ci, struct dm_target *ti)1500static int __send_write_zeroes(struct clone_info *ci, struct dm_target *ti)
1532{1501{
1533 return __send_changing_extent_only(ci, ti, get_num_write_zeroes_bios(ti), false);1502 return __send_changing_extent_only(ci, ti, get_num_write_zeroes_bios(ti));
1503}
1504
1505static bool is_abnormal_io(struct bio *bio)
1506{
1507 bool r = false;
1508
1509 switch (bio_op(bio)) {
1510 case REQ_OP_DISCARD:
1511 case REQ_OP_SECURE_ERASE:
1512 case REQ_OP_WRITE_SAME:
1513 case REQ_OP_WRITE_ZEROES:
1514 r = true;
1515 break;
1516 }
1517
1518 return r;
1534}1519}
1535 1520
1536static bool __process_abnormal_io(struct clone_info *ci, struct dm_target *ti,1521static bool __process_abnormal_io(struct clone_info *ci, struct dm_target *ti,
@@ -1565,7 +1550,7 @@ static int __split_and_process_non_flush(struct clone_info *ci) · 28 unmodified lines
1565 if (!dm_target_is_valid(ti))1550 if (!dm_target_is_valid(ti))
1566 return -EIO;1551 return -EIO;
1567 1552
1568 if (unlikely(__process_abnormal_io(ci, ti, &r)))1553 if (__process_abnormal_io(ci, ti, &r))
1569 return r;1554 return r;
1570 1555
1571 len = min_t(sector_t, max_io_len(ci->sector, ti), ci->sector_count);1556 len = min_t(sector_t, max_io_len(ci->sector, ti), ci->sector_count);
@@ -1601,13 +1586,6 @@ static blk_qc_t __split_and_process_bio(struct mapped_device *md, · 29 unmodified lines
1601 blk_qc_t ret = BLK_QC_T_NONE;1586 blk_qc_t ret = BLK_QC_T_NONE;
1602 int error = 0;1587 int error = 0;
1603 1588
1604 if (unlikely(!map)) {
1605 bio_io_error(bio);
1606 return ret;
1607 }
1608
1609 blk_queue_split(md->queue, &bio);
1610
1611 init_clone_info(&ci, md, map, bio);1589 init_clone_info(&ci, md, map, bio);
1612 1590
1613 if (bio->bi_opf & REQ_PREFLUSH) {1591 if (bio->bi_opf & REQ_PREFLUSH) {
@@ -1675,18 +1653,13 @@ static blk_qc_t __split_and_process_bio(struct mapped_device *md, · 61 unmodified lines
1675 * Optimized variant of __split_and_process_bio that leverages the1653 * Optimized variant of __split_and_process_bio that leverages the
1676 * fact that targets that use it do _not_ have a need to split bios.1654 * fact that targets that use it do _not_ have a need to split bios.
1677 */1655 */
1678static blk_qc_t __process_bio(struct mapped_device *md,1656static blk_qc_t __process_bio(struct mapped_device *md, struct dm_table *map,
1679 struct dm_table *map, struct bio *bio)1657 struct bio *bio, struct dm_target *ti)
1680{1658{
1681 struct clone_info ci;1659 struct clone_info ci;
1682 blk_qc_t ret = BLK_QC_T_NONE;1660 blk_qc_t ret = BLK_QC_T_NONE;
1683 int error = 0;1661 int error = 0;
1684 1662
1685 if (unlikely(!map)) {
1686 bio_io_error(bio);
1687 return ret;
1688 }
1689
1690 init_clone_info(&ci, md, map, bio);1663 init_clone_info(&ci, md, map, bio);
1691 1664
1692 if (bio->bi_opf & REQ_PREFLUSH) {1665 if (bio->bi_opf & REQ_PREFLUSH) {
@@ -1704,21 +1677,11 @@ static blk_qc_t __process_bio(struct mapped_device *md, · 11 unmodified lines
1704 error = __send_empty_flush(&ci);1677 error = __send_empty_flush(&ci);
1705 /* dec_pending submits any data associated with flush */1678 /* dec_pending submits any data associated with flush */
1706 } else {1679 } else {
1707 struct dm_target *ti = md->immutable_target;
1708 struct dm_target_io *tio;1680 struct dm_target_io *tio;
1709 1681
1710 /*
1711 * Defend against IO still getting in during teardown
1712 * - as was seen for a time with nvme-fcloop
1713 */
1714 if (WARN_ON_ONCE(!ti || !dm_target_is_valid(ti))) {
1715 error = -EIO;
1716 goto out;
1717 }
1718
1719 ci.bio = bio;1682 ci.bio = bio;
1720 ci.sector_count = bio_sectors(bio);1683 ci.sector_count = bio_sectors(bio);
1721 if (unlikely(__process_abnormal_io(&ci, ti, &error)))1684 if (__process_abnormal_io(&ci, ti, &error))
1722 goto out;1685 goto out;
1723 1686
1724 tio = alloc_tio(&ci, ti, 0, GFP_NOIO);1687 tio = alloc_tio(&ci, ti, 0, GFP_NOIO);
@@ -1730,11 +1693,55 @@ out: · 5 unmodified lines
1730 return ret;1693 return ret;
1731}1694}
1732 1695
1696static void dm_queue_split(struct mapped_device *md, struct dm_target *ti, struct bio **bio)
1697{
1698 unsigned len, sector_count;
1699
1700 sector_count = bio_sectors(*bio);
1701 len = min_t(sector_t, max_io_len((*bio)->bi_iter.bi_sector, ti), sector_count);
1702
1703 if (sector_count > len) {
1704 struct bio *split = bio_split(*bio, len, GFP_NOIO, &md->queue->bio_split);
1705
1706 bio_chain(split, *bio);
1707 trace_block_split(md->queue, split, (*bio)->bi_iter.bi_sector);
1708 generic_make_request(*bio);
1709 *bio = split;
1710 }
1711}
1712
1733static blk_qc_t dm_process_bio(struct mapped_device *md,1713static blk_qc_t dm_process_bio(struct mapped_device *md,
1734 struct dm_table *map, struct bio *bio)1714 struct dm_table *map, struct bio *bio)
1735{1715{
1716 blk_qc_t ret = BLK_QC_T_NONE;
1717 struct dm_target *ti = md->immutable_target;
1718
1719 if (unlikely(!map)) {
1720 bio_io_error(bio);
1721 return ret;
1722 }
1723
1724 if (!ti) {
1725 ti = dm_table_find_target(map, bio->bi_iter.bi_sector);
1726 if (unlikely(!ti || !dm_target_is_valid(ti))) {
1727 bio_io_error(bio);
1728 return ret;
1729 }
1730 }
1731
1732 /*
1733 * If in ->make_request_fn we need to use blk_queue_split(), otherwise
1734 * queue_limits for abnormal requests (e.g. discard, writesame, etc)
1735 * won't be imposed.
1736 */
1737 if (current->bio_list) {
1738 blk_queue_split(md->queue, &bio);
1739 if (!is_abnormal_io(bio))
1740 dm_queue_split(md, ti, &bio);
1741 }
1742
1736 if (dm_get_md_type(md) == DM_TYPE_NVME_BIO_BASED)1743 if (dm_get_md_type(md) == DM_TYPE_NVME_BIO_BASED)
1737 return __process_bio(md, map, bio);1744 return __process_bio(md, map, bio, ti);
1738 else1745 else
1739 return __split_and_process_bio(md, map, bio);1746 return __split_and_process_bio(md, map, bio);
1740}1747}
drivers/md/persistent-data/dm-block-manager.c+4−4
@@ -462,7 +462,7 @@ int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b, · 461 unmodified lines
462 int r;462 int r;
463 463
464 p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result);464 p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result);
465 if (unlikely(IS_ERR(p)))465 if (IS_ERR(p))
466 return PTR_ERR(p);466 return PTR_ERR(p);
467 467
468 aux = dm_bufio_get_aux_data(to_buffer(*result));468 aux = dm_bufio_get_aux_data(to_buffer(*result));
@@ -498,7 +498,7 @@ int dm_bm_write_lock(struct dm_block_manager *bm, · 29 unmodified lines
498 return -EPERM;498 return -EPERM;
499 499
500 p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result);500 p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result);
501 if (unlikely(IS_ERR(p)))501 if (IS_ERR(p))
502 return PTR_ERR(p);502 return PTR_ERR(p);
503 503
504 aux = dm_bufio_get_aux_data(to_buffer(*result));504 aux = dm_bufio_get_aux_data(to_buffer(*result));
@@ -531,7 +531,7 @@ int dm_bm_read_try_lock(struct dm_block_manager *bm, · 26 unmodified lines
531 int r;531 int r;
532 532
533 p = dm_bufio_get(bm->bufio, b, (struct dm_buffer **) result);533 p = dm_bufio_get(bm->bufio, b, (struct dm_buffer **) result);
534 if (unlikely(IS_ERR(p)))534 if (IS_ERR(p))
535 return PTR_ERR(p);535 return PTR_ERR(p);
536 if (unlikely(!p))536 if (unlikely(!p))
537 return -EWOULDBLOCK;537 return -EWOULDBLOCK;
@@ -567,7 +567,7 @@ int dm_bm_write_lock_zero(struct dm_block_manager *bm, · 29 unmodified lines
567 return -EPERM;567 return -EPERM;
568 568
569 p = dm_bufio_new(bm->bufio, b, (struct dm_buffer **) result);569 p = dm_bufio_new(bm->bufio, b, (struct dm_buffer **) result);
570 if (unlikely(IS_ERR(p)))570 if (IS_ERR(p))
571 return PTR_ERR(p);571 return PTR_ERR(p);
572 572
573 memset(p, 0, dm_bm_block_size(bm));573 memset(p, 0, dm_bm_block_size(bm));
include/linux/device-mapper.h+10−7
@@ -10,6 +10,7 @@ · 9 unmodified lines
10 10
11#include <linux/bio.h>11#include <linux/bio.h>
12#include <linux/blkdev.h>12#include <linux/blkdev.h>
13#include <linux/dm-ioctl.h>
13#include <linux/math64.h>14#include <linux/math64.h>
14#include <linux/ratelimit.h>15#include <linux/ratelimit.h>
15 16
@@ -315,12 +316,6 @@ struct dm_target { · 299 unmodified lines
315 * whether or not its underlying devices have support.316 * whether or not its underlying devices have support.
316 */317 */
317 bool discards_supported:1;318 bool discards_supported:1;
318
319 /*
320 * Set if the target required discard bios to be split
321 * on max_io_len boundary.
322 */
323 bool split_discard_bios:1;
324};319};
325 320
326/* Each target can link one of these into the table */321/* Each target can link one of these into the table */
@@ -431,6 +426,14 @@ void dm_remap_zone_report(struct dm_target *ti, sector_t start, · 104 unmodified lines
431 struct blk_zone *zones, unsigned int *nr_zones);426 struct blk_zone *zones, unsigned int *nr_zones);
432union map_info *dm_get_rq_mapinfo(struct request *rq);427union map_info *dm_get_rq_mapinfo(struct request *rq);
433 428
429/*
430 * Device mapper functions to parse and create devices specified by the
431 * parameter "dm-mod.create="
432 */
433int __init dm_early_create(struct dm_ioctl *dmi,
434 struct dm_target_spec **spec_array,
435 char **target_params_array);
436
434struct queue_limits *dm_get_queue_limits(struct mapped_device *md);437struct queue_limits *dm_get_queue_limits(struct mapped_device *md);
435 438
436/*439/*
@@ -609,7 +612,7 @@ do { \ · 172 unmodified lines
609 */612 */
610#define dm_target_offset(ti, sector) ((sector) - (ti)->begin)613#define dm_target_offset(ti, sector) ((sector) - (ti)->begin)
611 614
612static inline sector_t to_sector(unsigned long n)615static inline sector_t to_sector(unsigned long long n)
613{616{
614 return (n >> SECTOR_SHIFT);617 return (n >> SECTOR_SHIFT);
615}618}
include/uapi/linux/dm-ioctl.h+2−2
@@ -270,9 +270,9 @@ enum { · 269 unmodified lines
270#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)270#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
271 271
272#define DM_VERSION_MAJOR 4272#define DM_VERSION_MAJOR 4
273#define DM_VERSION_MINOR 39273#define DM_VERSION_MINOR 40
274#define DM_VERSION_PATCHLEVEL 0274#define DM_VERSION_PATCHLEVEL 0
275#define DM_VERSION_EXTRA "-ioctl (2018-04-03)"275#define DM_VERSION_EXTRA "-ioctl (2019-01-18)"
276 276
277/* Status bits */277/* Status bits */
278#define DM_READONLY_FLAG (1 << 0) /* In/Out */278#define DM_READONLY_FLAG (1 << 0) /* In/Out */