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
206206 in a separate btree, which improves speed of shutting
207207 down the cache.
208208
209+ no_discard_passdown : disable passing down discards from the cache
210+ to the origin's data device.
211+
209212 A policy called 'default' is always registered. This is an alias for
210213 the policy we currently think is giving best all round performance.
211214
Documentation/device-mapper/dm-init.txt+114−0
@@ -0,0 +1,114 @@
1+Early creation of mapped devices
2+====================================
3+
4+It is possible to configure a device-mapper device to act as the root device for
5+your system in two ways.
6+
7+The first is to build an initial ramdisk which boots to a minimal userspace
8+which configures the device, then pivot_root(8) in to it.
9+
10+The 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+
13+The format is specified as a string of data separated by commas and optionally
14+semi-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+
19+So the format will look like this:
20+
21+ dm-mod.create=<name>,<uuid>,<minor>,<flags>,<table>[,<table>+][;<name>,<uuid>,<minor>,<flags>,<table>[,<table>+]+]
22+
23+Where,
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+
31+The dm line should be equivalent to the one used by the dmsetup tool with the
32+--concise argument.
33+
34+Target types
35+============
36+
37+Not all target types are available as there are serious risks in allowing
38+activation of certain DM targets without first using userspace tools to check
39+the 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+
61+If the target is not listed above, it is constrained by default (not tested).
62+
63+Examples
64+========
65+An example of booting to a linear array made up of user-mode linux block
66+devices:
67+
68+ dm-mod.create="lroot,,,rw, 0 4096 linear 98:16 0, 4096 4096 linear 98:32 0" root=/dev/dm-0
69+
70+This will boot to a rw dm-linear target of 8192 sectors split across two block
71+devices identified by their major:minor numbers. After boot, udev will rename
72+this target to /dev/mapper/lroot (depending on the rules). No uuid was assigned.
73+
74+An example of multiple device-mappers, with the dm-mod.create="..." contents is shown here
75+split 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+
85+Other 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
436436
437437 If unsure, say N.
438438
439+config 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+
439451 config DM_UEVENT
440452 bool "DM uevents"
441453 depends on BLK_DEV_DM
drivers/md/Makefile+4−0
@@ -69,6 +69,10 @@ obj-$(CONFIG_DM_INTEGRITY) += dm-integrity.o · 68 unmodified lines
6969 obj-$(CONFIG_DM_ZONED) += dm-zoned.o
7070 obj-$(CONFIG_DM_WRITECACHE) += dm-writecache.o
7171
72+ifeq ($(CONFIG_DM_INIT),y)
73+dm-mod-objs += dm-init.o
74+endif
75+
7276 ifeq ($(CONFIG_DM_UEVENT),y)
7377 dm-mod-objs += dm-uevent.o
7478 endif
drivers/md/dm-cache-target.c+100−27
@@ -353,6 +353,7 @@ struct cache_features { · 352 unmodified lines
353353 enum cache_metadata_mode mode;
354354 enum cache_io_mode io_mode;
355355 unsigned metadata_version;
356+ bool discard_passdown:1;
356357 };
357358
358359 struct cache_stats {
@@ -1899,7 +1900,11 @@ static bool process_discard_bio(struct cache *cache, struct bio *bio) · 1540 unmodified lines
18991900 b = to_dblock(from_dblock(b) + 1);
19001901 }
19011902
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);
19031908
19041909 return false;
19051910 }
@@ -2233,13 +2238,14 @@ static void init_features(struct cache_features *cf) · 327 unmodified lines
22332238 cf->mode = CM_WRITE;
22342239 cf->io_mode = CM_IO_WRITEBACK;
22352240 cf->metadata_version = 1;
2241+ cf->discard_passdown = true;
22362242 }
22372243
22382244 static int parse_features(struct cache_args *ca, struct dm_arg_set *as,
22392245 char **error)
22402246 {
22412247 static const struct dm_arg _args[] = {
2242− {0, 2, "Invalid number of cache feature arguments"},
2248+ {0, 3, "Invalid number of cache feature arguments"},
22432249 };
22442250
22452251 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
22742280 else if (!strcasecmp(arg, "metadata2"))
22752281 cf->metadata_version = 2;
22762282
2283+ else if (!strcasecmp(arg, "no_discard_passdown"))
2284+ cf->discard_passdown = false;
2285+
22772286 else {
22782287 *error = "Unrecognised cache feature requested";
22792288 return -EINVAL;
@@ -2496,7 +2505,6 @@ static int cache_create(struct cache_args *ca, struct cache **result) · 216 unmodified lines
24962505
24972506 ti->num_discard_bios = 1;
24982507 ti->discards_supported = true;
2499− ti->split_discard_bios = false;
25002508
25012509 ti->per_io_data_size = sizeof(struct per_bio_data);
25022510
@@ -3120,6 +3128,39 @@ static void cache_resume(struct dm_target *ti) · 617 unmodified lines
31203128 do_waker(&cache->waker.work);
31213129 }
31223130
3131+static 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+
31233164 /*
31243165 * Status format:
31253166 *
@@ -3186,25 +3227,7 @@ static void cache_status(struct dm_target *ti, status_type_t type, · 60 unmodified lines
31863227 (unsigned) atomic_read(&cache->stats.promotion),
31873228 (unsigned long) atomic_read(&cache->nr_dirty));
31883229
3189− if (cache->features.metadata_version == 2)
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− }
3230+ emit_flags(cache, result, maxlen, &sz);
32083231
32093232 DMEMIT("2 migration_threshold %llu ", (unsigned long long) cache->migration_threshold);
32103233
@@ -3433,14 +3456,62 @@ static int cache_iterate_devices(struct dm_target *ti, · 222 unmodified lines
34333456 return r;
34343457 }
34353458
3459+static 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+ */
3470+static 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+
34363493 static void set_discard_limits(struct cache *cache, struct queue_limits *limits)
34373494 {
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+
34383506 /*
3439− * FIXME: these limits may be incompatible with the cache device
3507+ * 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.
34403509 */
3441− limits->max_discard_sectors = min_t(sector_t, cache->discard_block_size * 1024,
3442− cache->origin_sectors);
3443− limits->discard_granularity = cache->discard_block_size << SECTOR_SHIFT;
3510+ limits->max_discard_sectors = origin_limits->max_discard_sectors;
3511+ limits->max_hw_discard_sectors = origin_limits->max_hw_discard_sectors;
3512+ limits->discard_granularity = origin_limits->discard_granularity;
3513+ limits->discard_alignment = origin_limits->discard_alignment;
3514+ limits->discard_misaligned = origin_limits->discard_misaligned;
34443515 }
34453516
34463517 static 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
34573528 blk_limits_io_min(limits, cache->sectors_per_block << SECTOR_SHIFT);
34583529 blk_limits_io_opt(limits, cache->sectors_per_block << SECTOR_SHIFT);
34593530 }
3531+
3532+ disable_passdown_if_not_supported(cache);
34603533 set_discard_limits(cache, limits);
34613534 }
34623535
@@ -3464,7 +3537,7 @@ static void cache_io_hints(struct dm_target *ti, struct queue_limits *limits) · 1 unmodified line
34643537
34653538 static struct target_type cache_target = {
34663539 .name = "cache",
3467− .version = {2, 0, 0},
3540+ .version = {2, 1, 0},
34683541 .module = THIS_MODULE,
34693542 .ctr = cache_ctr,
34703543 .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+
22+static 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+
32+struct 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+
39+const char *dm_allowed_targets[] __initconst = {
40+ "crypt",
41+ "delay",
42+ "linear",
43+ "snapshot-origin",
44+ "striped",
45+ "verity",
46+};
47+
48+static 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+
59+static 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+ */
83+static 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+ */
106+static 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+ */
157+static 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+ */
187+static 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+ */
232+static 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+ */
264+static 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+ }
294+out:
295+ kfree(str);
296+ dm_setup_cleanup(&devices);
297+ return r;
298+}
299+
300+late_initcall(dm_init_init);
301+
302+module_param(create, charp, 0);
303+MODULE_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
11221122 return r;
11231123
11241124 data = dm_bufio_read(ic->bufio, *metadata_block, &b);
1125− if (unlikely(IS_ERR(data)))
1125+ if (IS_ERR(data))
11261126 return PTR_ERR(data);
11271127
11281128 to_copy = min((1U << SECTOR_SHIFT << ic->log2_buffer_sectors) - *metadata_offset, total_size);
@@ -1368,8 +1368,8 @@ again: · 239 unmodified lines
13681368 checksums_ptr - checksums, !dio->write ? TAG_CMP : TAG_WRITE);
13691369 if (unlikely(r)) {
13701370 if (r > 0) {
1371− DMERR("Checksum failed at sector 0x%llx",
1372− (unsigned long long)(sector - ((r + ic->tag_size - 1) / ic->tag_size)));
1371+ DMERR_LIMIT("Checksum failed at sector 0x%llx",
1372+ (unsigned long long)(sector - ((r + ic->tag_size - 1) / ic->tag_size)));
13731373 r = -EILSEQ;
13741374 atomic64_inc(&ic->number_of_mismatches);
13751375 }
@@ -1561,8 +1561,8 @@ retry_kmap: · 185 unmodified lines
15611561
15621562 integrity_sector_checksum(ic, logical_sector, mem + bv.bv_offset, checksums_onstack);
15631563 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",
1565− (unsigned long long)logical_sector);
1564+ DMERR_LIMIT("Checksum failed when reading from journal, at sector 0x%llx",
1565+ (unsigned long long)logical_sector);
15661566 }
15671567 }
15681568 #endif
drivers/md/dm-ioctl.c+103−0
@@ -2018,3 +2018,106 @@ out: · 2017 unmodified lines
20182018
20192019 return r;
20202020 }
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+ */
2040+int __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+
2117+err_destroy_table:
2118+ dm_table_destroy(t);
2119+err_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
29862986 }
29872987 }
29882988
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));
29942989 ti->num_discard_bios = 1;
29952990 }
29962991
@@ -3747,6 +3742,15 @@ static void raid_io_hints(struct dm_target *ti, struct queue_limits *limits) · 750 unmodified lines
37473742
37483743 blk_limits_io_min(limits, chunk_size);
37493744 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+ }
37503754 }
37513755
37523756 static void raid_postsuspend(struct dm_target *ti)
drivers/md/dm-rq.c+16−0
@@ -12,6 +12,22 @@ · 11 unmodified lines
1212
1313 #define DM_MSG_PREFIX "core-rq"
1414
15+/*
16+ * One of these is allocated per request.
17+ */
18+struct 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+
1531 #define DM_MQ_NR_HW_QUEUES 1
1632 #define DM_MQ_QUEUE_DEPTH 2048
1733 static 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
1616
1717 struct mapped_device;
1818
19−/*
20− * One of these is allocated per request.
21− */
22−struct 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−
3519 /*
3620 * For request-based dm - the bio clones we allocate are embedded in these
3721 * 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
23382338 return do_origin(o->dev, bio);
23392339 }
23402340
2341−static 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−
23482341 /*
23492342 * Set the target "max_io_len" field to the minimum of all the snapshots'
23502343 * chunk sizes.
@@ -2404,7 +2397,6 @@ static struct target_type origin_target = { · 53 unmodified lines
24042397 .postsuspend = origin_postsuspend,
24052398 .status = origin_status,
24062399 .iterate_devices = origin_iterate_devices,
2407− .direct_access = origin_dax_direct_access,
24082400 };
24092401
24102402 static 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
6161 {
6262 struct switch_ctx *sctx;
6363
64− sctx = kzalloc(sizeof(struct switch_ctx) + nr_paths * sizeof(struct switch_path),
65− GFP_KERNEL);
64+ sctx = kzalloc(struct_size(sctx, path_list, nr_paths), GFP_KERNEL);
6665 if (!sctx)
6766 return NULL;
6867
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
32833283 as.argc = argc;
32843284 as.argv = argv;
32853285
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+
32863293 /*
32873294 * Set default pool features.
32883295 */
@@ -4167,6 +4174,12 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv) · 878 unmodified lines
41674174 tc->sort_bio_list = RB_ROOT;
41684175
41694176 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+
41704183 r = dm_get_device(ti, argv[2], FMODE_READ, &origin_dev);
41714184 if (r) {
41724185 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
42274240 if (tc->pool->pf.discard_enabled) {
42284241 ti->discards_supported = true;
42294242 ti->num_discard_bios = 1;
4230− ti->split_discard_bios = false;
42314243 }
42324244
42334245 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
7373 *offset = (unsigned)(position - (block << v->data_dev_block_bits));
7474
7575 res = dm_bufio_read(v->fec->bufio, v->fec->start + block, buf);
76− if (unlikely(IS_ERR(res))) {
76+ if (IS_ERR(res)) {
7777 DMERR("%s: FEC %llu: parity read failed (block %llu): %ld",
7878 v->data_dev->name, (unsigned long long)rsb,
7979 (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
163163 dm_bufio_release(buf);
164164
165165 par = fec_read_parity(v, rsb, block_offset, &offset, &buf);
166− if (unlikely(IS_ERR(par)))
166+ if (IS_ERR(par))
167167 return PTR_ERR(par);
168168 }
169169 }
@@ -253,7 +253,7 @@ static int fec_read_bufs(struct dm_verity *v, struct dm_verity_io *io, · 83 unmodified lines
253253 }
254254
255255 bbuf = dm_bufio_read(bufio, block, &buf);
256− if (unlikely(IS_ERR(bbuf))) {
256+ if (IS_ERR(bbuf)) {
257257 DMWARN_LIMIT("%s: FEC %llu: read failed (%llu): %ld",
258258 v->data_dev->name,
259259 (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
18591859 goto bad;
18601860 }
18611861
1862− wc->writeback_wq = alloc_workqueue("writecache-writeabck", WQ_MEM_RECLAIM, 1);
1862+ wc->writeback_wq = alloc_workqueue("writecache-writeback", WQ_MEM_RECLAIM, 1);
18631863 if (!wc->writeback_wq) {
18641864 r = -ENOMEM;
18651865 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
727727 ti->per_io_data_size = sizeof(struct dmz_bioctx);
728728 ti->flush_supported = true;
729729 ti->discards_supported = true;
730− ti->split_discard_bios = true;
731730
732731 /* The exposed capacity is the number of chunks that can be mapped */
733732 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
158158 struct dm_dev dm_dev;
159159 };
160160
161−static struct kmem_cache *_rq_tio_cache;
162−static struct kmem_cache *_rq_cache;
163−
164161 /*
165162 * Bio-based DM's mempools' reserved IOs set by the user.
166163 */
@@ -222,20 +219,11 @@ static unsigned dm_get_numa_node(void) · 55 unmodified lines
222219
223220 static int __init local_init(void)
224221 {
225− int r = -ENOMEM;
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;
222+ int r;
235223
236224 r = dm_uevent_init();
237225 if (r)
238− goto out_free_rq_cache;
226+ return r;
239227
240228 deferred_remove_workqueue = alloc_workqueue("kdmremove", WQ_UNBOUND, 1);
241229 if (!deferred_remove_workqueue) {
@@ -257,10 +245,6 @@ out_free_workqueue: · 15 unmodified lines
257245 destroy_workqueue(deferred_remove_workqueue);
258246 out_uevent_exit:
259247 dm_uevent_exit();
260−out_free_rq_cache:
261− kmem_cache_destroy(_rq_cache);
262−out_free_rq_tio_cache:
263− kmem_cache_destroy(_rq_tio_cache);
264248
265249 return r;
266250 }
@@ -270,8 +254,6 @@ static void local_exit(void) · 3 unmodified lines
270254 flush_scheduled_work();
271255 destroy_workqueue(deferred_remove_workqueue);
272256
273− kmem_cache_destroy(_rq_cache);
274− kmem_cache_destroy(_rq_tio_cache);
275257 unregister_blkdev(_major, _name);
276258 dm_uevent_exit();
277259
@@ -1478,17 +1460,10 @@ static unsigned get_num_write_zeroes_bios(struct dm_target *ti) · 1200 unmodified lines
14781460 return ti->num_write_zeroes_bios;
14791461 }
14801462
1481−typedef bool (*is_split_required_fn)(struct dm_target *ti);
1482−
1483−static bool is_split_required_for_discard(struct dm_target *ti)
1484−{
1485− return ti->split_discard_bios;
1486−}
1487−
14881463 static 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)
14901465 {
1491− unsigned len;
1466+ unsigned len = ci->sector_count;
14921467
14931468 /*
14941469 * 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
14991474 if (!num_bios)
15001475 return -EOPNOTSUPP;
15011476
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−
15071477 __send_duplicate_bios(ci, ti, num_bios, &len);
15081478
15091479 ci->sector += len;
@@ -1514,23 +1484,38 @@ static int __send_changing_extent_only(struct clone_info *ci, struct dm_target * · 4 unmodified lines
15141484
15151485 static int __send_discard(struct clone_info *ci, struct dm_target *ti)
15161486 {
1517− return __send_changing_extent_only(ci, ti, get_num_discard_bios(ti),
1518− is_split_required_for_discard(ti));
1487+ return __send_changing_extent_only(ci, ti, get_num_discard_bios(ti));
15191488 }
15201489
15211490 static int __send_secure_erase(struct clone_info *ci, struct dm_target *ti)
15221491 {
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));
15241493 }
15251494
15261495 static int __send_write_same(struct clone_info *ci, struct dm_target *ti)
15271496 {
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));
15291498 }
15301499
15311500 static int __send_write_zeroes(struct clone_info *ci, struct dm_target *ti)
15321501 {
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+
1505+static 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;
15341519 }
15351520
15361521 static 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
15651550 if (!dm_target_is_valid(ti))
15661551 return -EIO;
15671552
1568− if (unlikely(__process_abnormal_io(ci, ti, &r)))
1553+ if (__process_abnormal_io(ci, ti, &r))
15691554 return r;
15701555
15711556 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
16011586 blk_qc_t ret = BLK_QC_T_NONE;
16021587 int error = 0;
16031588
1604− if (unlikely(!map)) {
1605− bio_io_error(bio);
1606− return ret;
1607− }
1608−
1609− blk_queue_split(md->queue, &bio);
1610−
16111589 init_clone_info(&ci, md, map, bio);
16121590
16131591 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
16751653 * Optimized variant of __split_and_process_bio that leverages the
16761654 * fact that targets that use it do _not_ have a need to split bios.
16771655 */
1678−static blk_qc_t __process_bio(struct mapped_device *md,
1679− struct dm_table *map, struct bio *bio)
1656+static blk_qc_t __process_bio(struct mapped_device *md, struct dm_table *map,
1657+ struct bio *bio, struct dm_target *ti)
16801658 {
16811659 struct clone_info ci;
16821660 blk_qc_t ret = BLK_QC_T_NONE;
16831661 int error = 0;
16841662
1685− if (unlikely(!map)) {
1686− bio_io_error(bio);
1687− return ret;
1688− }
1689−
16901663 init_clone_info(&ci, md, map, bio);
16911664
16921665 if (bio->bi_opf & REQ_PREFLUSH) {
@@ -1704,21 +1677,11 @@ static blk_qc_t __process_bio(struct mapped_device *md, · 11 unmodified lines
17041677 error = __send_empty_flush(&ci);
17051678 /* dec_pending submits any data associated with flush */
17061679 } else {
1707− struct dm_target *ti = md->immutable_target;
17081680 struct dm_target_io *tio;
17091681
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−
17191682 ci.bio = bio;
17201683 ci.sector_count = bio_sectors(bio);
1721− if (unlikely(__process_abnormal_io(&ci, ti, &error)))
1684+ if (__process_abnormal_io(&ci, ti, &error))
17221685 goto out;
17231686
17241687 tio = alloc_tio(&ci, ti, 0, GFP_NOIO);
@@ -1730,11 +1693,55 @@ out: · 5 unmodified lines
17301693 return ret;
17311694 }
17321695
1696+static 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+
17331713 static blk_qc_t dm_process_bio(struct mapped_device *md,
17341714 struct dm_table *map, struct bio *bio)
17351715 {
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+
17361743 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);
17381745 else
17391746 return __split_and_process_bio(md, map, bio);
17401747 }
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
462462 int r;
463463
464464 p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result);
465− if (unlikely(IS_ERR(p)))
465+ if (IS_ERR(p))
466466 return PTR_ERR(p);
467467
468468 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
498498 return -EPERM;
499499
500500 p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result);
501− if (unlikely(IS_ERR(p)))
501+ if (IS_ERR(p))
502502 return PTR_ERR(p);
503503
504504 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
531531 int r;
532532
533533 p = dm_bufio_get(bm->bufio, b, (struct dm_buffer **) result);
534− if (unlikely(IS_ERR(p)))
534+ if (IS_ERR(p))
535535 return PTR_ERR(p);
536536 if (unlikely(!p))
537537 return -EWOULDBLOCK;
@@ -567,7 +567,7 @@ int dm_bm_write_lock_zero(struct dm_block_manager *bm, · 29 unmodified lines
567567 return -EPERM;
568568
569569 p = dm_bufio_new(bm->bufio, b, (struct dm_buffer **) result);
570− if (unlikely(IS_ERR(p)))
570+ if (IS_ERR(p))
571571 return PTR_ERR(p);
572572
573573 memset(p, 0, dm_bm_block_size(bm));
include/linux/device-mapper.h+10−7
@@ -10,6 +10,7 @@ · 9 unmodified lines
1010
1111 #include <linux/bio.h>
1212 #include <linux/blkdev.h>
13+#include <linux/dm-ioctl.h>
1314 #include <linux/math64.h>
1415 #include <linux/ratelimit.h>
1516
@@ -315,12 +316,6 @@ struct dm_target { · 299 unmodified lines
315316 * whether or not its underlying devices have support.
316317 */
317318 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;
324319 };
325320
326321 /* 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
431426 struct blk_zone *zones, unsigned int *nr_zones);
432427 union map_info *dm_get_rq_mapinfo(struct request *rq);
433428
429+/*
430+ * Device mapper functions to parse and create devices specified by the
431+ * parameter "dm-mod.create="
432+ */
433+int __init dm_early_create(struct dm_ioctl *dmi,
434+ struct dm_target_spec **spec_array,
435+ char **target_params_array);
436+
434437 struct queue_limits *dm_get_queue_limits(struct mapped_device *md);
435438
436439 /*
@@ -609,7 +612,7 @@ do { \ · 172 unmodified lines
609612 */
610613 #define dm_target_offset(ti, sector) ((sector) - (ti)->begin)
611614
612−static inline sector_t to_sector(unsigned long n)
615+static inline sector_t to_sector(unsigned long long n)
613616 {
614617 return (n >> SECTOR_SHIFT);
615618 }
include/uapi/linux/dm-ioctl.h+2−2
@@ -270,9 +270,9 @@ enum { · 269 unmodified lines
270270 #define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
271271
272272 #define DM_VERSION_MAJOR 4
273−#define DM_VERSION_MINOR 39
273+#define DM_VERSION_MINOR 40
274274 #define DM_VERSION_PATCHLEVEL 0
275−#define DM_VERSION_EXTRA "-ioctl (2018-04-03)"
275+#define DM_VERSION_EXTRA "-ioctl (2019-01-18)"
276276
277277 /* Status bits */
278278 #define DM_READONLY_FLAG (1 << 0) /* In/Out */