aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-10-18 15:25:30 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-10-18 15:25:30 -0400
commit929254d8da55a046fe792e79a220f83df761305d (patch)
tree1b5ba5f4416bd512dbd230012a17dc9527df31fb
parente75437fb9322cf0ac707046a12d78a25f9d52ccf (diff)
parent56ec16cb1e1ce46354de8511eef962a417c32c92 (diff)
Merge tag 'dm-3.18' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device-mapper updates from Mike Snitzer: "I rebased the DM tree ontop of linux-block.git's 'for-3.18/core' at the beginning of October because DM core now depends on the newly introduced bioset_create_nobvec() interface. Summary: - fix DM's long-standing excessive use of memory by leveraging the new bioset_create_nobvec() interface when creating the DM's bioset - fix a few bugs in dm-bufio and dm-log-userspace - add DM core support for a DM multipath use-case that requires loading DM tables that contain devices that have failed (by allowing active and inactive DM tables to share dm_devs) - add discard support to the DM raid target; like MD raid456 the user must opt-in to raid456 discard support be specifying the devices_handle_discard_safely=Y module param" * tag 'dm-3.18' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm log userspace: fix memory leak in dm_ulog_tfr_init failure path dm bufio: when done scanning return from __scan immediately dm bufio: update last_accessed when relinking a buffer dm raid: add discard support for RAID levels 4, 5 and 6 dm raid: add discard support for RAID levels 1 and 10 dm: allow active and inactive tables to share dm_devs dm mpath: stop queueing IO when no valid paths exist dm: use bioset_create_nobvec() dm: remove nr_iovecs parameter from alloc_tio()
-rw-r--r--drivers/md/dm-bufio.c5
-rw-r--r--drivers/md/dm-ioctl.c2
-rw-r--r--drivers/md/dm-log-userspace-transfer.c2
-rw-r--r--drivers/md/dm-mpath.c4
-rw-r--r--drivers/md/dm-raid.c60
-rw-r--r--drivers/md/dm-table.c102
-rw-r--r--drivers/md/dm.c143
-rw-r--r--drivers/md/dm.h5
-rw-r--r--include/uapi/linux/dm-ioctl.h4
9 files changed, 238 insertions, 89 deletions
diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index 0505559f0965..825ca1f87639 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -465,6 +465,7 @@ static void __relink_lru(struct dm_buffer *b, int dirty)
465 c->n_buffers[dirty]++; 465 c->n_buffers[dirty]++;
466 b->list_mode = dirty; 466 b->list_mode = dirty;
467 list_move(&b->lru_list, &c->lru[dirty]); 467 list_move(&b->lru_list, &c->lru[dirty]);
468 b->last_accessed = jiffies;
468} 469}
469 470
470/*---------------------------------------------------------------- 471/*----------------------------------------------------------------
@@ -1471,9 +1472,9 @@ static long __scan(struct dm_bufio_client *c, unsigned long nr_to_scan,
1471 list_for_each_entry_safe_reverse(b, tmp, &c->lru[l], lru_list) { 1472 list_for_each_entry_safe_reverse(b, tmp, &c->lru[l], lru_list) {
1472 freed += __cleanup_old_buffer(b, gfp_mask, 0); 1473 freed += __cleanup_old_buffer(b, gfp_mask, 0);
1473 if (!--nr_to_scan) 1474 if (!--nr_to_scan)
1474 break; 1475 return freed;
1476 dm_bufio_cond_resched();
1475 } 1477 }
1476 dm_bufio_cond_resched();
1477 } 1478 }
1478 return freed; 1479 return freed;
1479} 1480}
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index 51521429fb59..0be9381365d7 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -1418,7 +1418,7 @@ static void retrieve_deps(struct dm_table *table,
1418 deps->count = count; 1418 deps->count = count;
1419 count = 0; 1419 count = 0;
1420 list_for_each_entry (dd, dm_table_get_devices(table), list) 1420 list_for_each_entry (dd, dm_table_get_devices(table), list)
1421 deps->dev[count++] = huge_encode_dev(dd->dm_dev.bdev->bd_dev); 1421 deps->dev[count++] = huge_encode_dev(dd->dm_dev->bdev->bd_dev);
1422 1422
1423 param->data_size = param->data_start + needed; 1423 param->data_size = param->data_start + needed;
1424} 1424}
diff --git a/drivers/md/dm-log-userspace-transfer.c b/drivers/md/dm-log-userspace-transfer.c
index b428c0ae63d5..39ad9664d397 100644
--- a/drivers/md/dm-log-userspace-transfer.c
+++ b/drivers/md/dm-log-userspace-transfer.c
@@ -272,7 +272,7 @@ int dm_ulog_tfr_init(void)
272 272
273 r = cn_add_callback(&ulog_cn_id, "dmlogusr", cn_ulog_callback); 273 r = cn_add_callback(&ulog_cn_id, "dmlogusr", cn_ulog_callback);
274 if (r) { 274 if (r) {
275 cn_del_callback(&ulog_cn_id); 275 kfree(prealloced_cn_msg);
276 return r; 276 return r;
277 } 277 }
278 278
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 833d7e752f06..7b6b0f0f831a 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -317,8 +317,10 @@ static void __choose_pgpath(struct multipath *m, size_t nr_bytes)
317 struct priority_group *pg; 317 struct priority_group *pg;
318 unsigned bypassed = 1; 318 unsigned bypassed = 1;
319 319
320 if (!m->nr_valid_paths) 320 if (!m->nr_valid_paths) {
321 m->queue_io = 0;
321 goto failed; 322 goto failed;
323 }
322 324
323 /* Were we instructed to switch PG? */ 325 /* Were we instructed to switch PG? */
324 if (m->next_pg) { 326 if (m->next_pg) {
diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index 4880b69e2e9e..4857fa4a5484 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) 2010-2011 Neil Brown 2 * Copyright (C) 2010-2011 Neil Brown
3 * Copyright (C) 2010-2011 Red Hat, Inc. All rights reserved. 3 * Copyright (C) 2010-2014 Red Hat, Inc. All rights reserved.
4 * 4 *
5 * This file is released under the GPL. 5 * This file is released under the GPL.
6 */ 6 */
@@ -18,6 +18,8 @@
18 18
19#define DM_MSG_PREFIX "raid" 19#define DM_MSG_PREFIX "raid"
20 20
21static bool devices_handle_discard_safely = false;
22
21/* 23/*
22 * The following flags are used by dm-raid.c to set up the array state. 24 * The following flags are used by dm-raid.c to set up the array state.
23 * They must be cleared before md_run is called. 25 * They must be cleared before md_run is called.
@@ -475,6 +477,8 @@ too_many:
475 * will form the "stripe" 477 * will form the "stripe"
476 * [[no]sync] Force or prevent recovery of the 478 * [[no]sync] Force or prevent recovery of the
477 * entire array 479 * entire array
480 * [devices_handle_discard_safely] Allow discards on RAID4/5/6; useful if RAID
481 * member device(s) properly support TRIM/UNMAP
478 * [rebuild <idx>] Rebuild the drive indicated by the index 482 * [rebuild <idx>] Rebuild the drive indicated by the index
479 * [daemon_sleep <ms>] Time between bitmap daemon work to 483 * [daemon_sleep <ms>] Time between bitmap daemon work to
480 * clear bits 484 * clear bits
@@ -1150,6 +1154,49 @@ static int analyse_superblocks(struct dm_target *ti, struct raid_set *rs)
1150} 1154}
1151 1155
1152/* 1156/*
1157 * Enable/disable discard support on RAID set depending on
1158 * RAID level and discard properties of underlying RAID members.
1159 */
1160static void configure_discard_support(struct dm_target *ti, struct raid_set *rs)
1161{
1162 int i;
1163 bool raid456;
1164
1165 /* Assume discards not supported until after checks below. */
1166 ti->discards_supported = false;
1167
1168 /* RAID level 4,5,6 require discard_zeroes_data for data integrity! */
1169 raid456 = (rs->md.level == 4 || rs->md.level == 5 || rs->md.level == 6);
1170
1171 for (i = 0; i < rs->md.raid_disks; i++) {
1172 struct request_queue *q = bdev_get_queue(rs->dev[i].rdev.bdev);
1173
1174 if (!q || !blk_queue_discard(q))
1175 return;
1176
1177 if (raid456) {
1178 if (!q->limits.discard_zeroes_data)
1179 return;
1180 if (!devices_handle_discard_safely) {
1181 DMERR("raid456 discard support disabled due to discard_zeroes_data uncertainty.");
1182 DMERR("Set dm-raid.devices_handle_discard_safely=Y to override.");
1183 return;
1184 }
1185 }
1186 }
1187
1188 /* All RAID members properly support discards */
1189 ti->discards_supported = true;
1190
1191 /*
1192 * RAID1 and RAID10 personalities require bio splitting,
1193 * RAID0/4/5/6 don't and process large discard bios properly.
1194 */
1195 ti->split_discard_bios = !!(rs->md.level == 1 || rs->md.level == 10);
1196 ti->num_discard_bios = 1;
1197}
1198
1199/*
1153 * Construct a RAID4/5/6 mapping: 1200 * Construct a RAID4/5/6 mapping:
1154 * Args: 1201 * Args:
1155 * <raid_type> <#raid_params> <raid_params> \ 1202 * <raid_type> <#raid_params> <raid_params> \
@@ -1231,6 +1278,11 @@ static int raid_ctr(struct dm_target *ti, unsigned argc, char **argv)
1231 ti->private = rs; 1278 ti->private = rs;
1232 ti->num_flush_bios = 1; 1279 ti->num_flush_bios = 1;
1233 1280
1281 /*
1282 * Disable/enable discard support on RAID set.
1283 */
1284 configure_discard_support(ti, rs);
1285
1234 mutex_lock(&rs->md.reconfig_mutex); 1286 mutex_lock(&rs->md.reconfig_mutex);
1235 ret = md_run(&rs->md); 1287 ret = md_run(&rs->md);
1236 rs->md.in_sync = 0; /* Assume already marked dirty */ 1288 rs->md.in_sync = 0; /* Assume already marked dirty */
@@ -1652,7 +1704,7 @@ static void raid_resume(struct dm_target *ti)
1652 1704
1653static struct target_type raid_target = { 1705static struct target_type raid_target = {
1654 .name = "raid", 1706 .name = "raid",
1655 .version = {1, 5, 2}, 1707 .version = {1, 6, 0},
1656 .module = THIS_MODULE, 1708 .module = THIS_MODULE,
1657 .ctr = raid_ctr, 1709 .ctr = raid_ctr,
1658 .dtr = raid_dtr, 1710 .dtr = raid_dtr,
@@ -1683,6 +1735,10 @@ static void __exit dm_raid_exit(void)
1683module_init(dm_raid_init); 1735module_init(dm_raid_init);
1684module_exit(dm_raid_exit); 1736module_exit(dm_raid_exit);
1685 1737
1738module_param(devices_handle_discard_safely, bool, 0644);
1739MODULE_PARM_DESC(devices_handle_discard_safely,
1740 "Set to Y if all devices in each array reliably return zeroes on reads from discarded regions");
1741
1686MODULE_DESCRIPTION(DM_NAME " raid4/5/6 target"); 1742MODULE_DESCRIPTION(DM_NAME " raid4/5/6 target");
1687MODULE_ALIAS("dm-raid1"); 1743MODULE_ALIAS("dm-raid1");
1688MODULE_ALIAS("dm-raid10"); 1744MODULE_ALIAS("dm-raid10");
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index f9c6cb8dbcf8..b2bd1ebf4562 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -210,15 +210,16 @@ int dm_table_create(struct dm_table **result, fmode_t mode,
210 return 0; 210 return 0;
211} 211}
212 212
213static void free_devices(struct list_head *devices) 213static void free_devices(struct list_head *devices, struct mapped_device *md)
214{ 214{
215 struct list_head *tmp, *next; 215 struct list_head *tmp, *next;
216 216
217 list_for_each_safe(tmp, next, devices) { 217 list_for_each_safe(tmp, next, devices) {
218 struct dm_dev_internal *dd = 218 struct dm_dev_internal *dd =
219 list_entry(tmp, struct dm_dev_internal, list); 219 list_entry(tmp, struct dm_dev_internal, list);
220 DMWARN("dm_table_destroy: dm_put_device call missing for %s", 220 DMWARN("%s: dm_table_destroy: dm_put_device call missing for %s",
221 dd->dm_dev.name); 221 dm_device_name(md), dd->dm_dev->name);
222 dm_put_table_device(md, dd->dm_dev);
222 kfree(dd); 223 kfree(dd);
223 } 224 }
224} 225}
@@ -247,7 +248,7 @@ void dm_table_destroy(struct dm_table *t)
247 vfree(t->highs); 248 vfree(t->highs);
248 249
249 /* free the device list */ 250 /* free the device list */
250 free_devices(&t->devices); 251 free_devices(&t->devices, t->md);
251 252
252 dm_free_md_mempools(t->mempools); 253 dm_free_md_mempools(t->mempools);
253 254
@@ -262,53 +263,13 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
262 struct dm_dev_internal *dd; 263 struct dm_dev_internal *dd;
263 264
264 list_for_each_entry (dd, l, list) 265 list_for_each_entry (dd, l, list)
265 if (dd->dm_dev.bdev->bd_dev == dev) 266 if (dd->dm_dev->bdev->bd_dev == dev)
266 return dd; 267 return dd;
267 268
268 return NULL; 269 return NULL;
269} 270}
270 271
271/* 272/*
272 * Open a device so we can use it as a map destination.
273 */
274static int open_dev(struct dm_dev_internal *d, dev_t dev,
275 struct mapped_device *md)
276{
277 static char *_claim_ptr = "I belong to device-mapper";
278 struct block_device *bdev;
279
280 int r;
281
282 BUG_ON(d->dm_dev.bdev);
283
284 bdev = blkdev_get_by_dev(dev, d->dm_dev.mode | FMODE_EXCL, _claim_ptr);
285 if (IS_ERR(bdev))
286 return PTR_ERR(bdev);
287
288 r = bd_link_disk_holder(bdev, dm_disk(md));
289 if (r) {
290 blkdev_put(bdev, d->dm_dev.mode | FMODE_EXCL);
291 return r;
292 }
293
294 d->dm_dev.bdev = bdev;
295 return 0;
296}
297
298/*
299 * Close a device that we've been using.
300 */
301static void close_dev(struct dm_dev_internal *d, struct mapped_device *md)
302{
303 if (!d->dm_dev.bdev)
304 return;
305
306 bd_unlink_disk_holder(d->dm_dev.bdev, dm_disk(md));
307 blkdev_put(d->dm_dev.bdev, d->dm_dev.mode | FMODE_EXCL);
308 d->dm_dev.bdev = NULL;
309}
310
311/*
312 * If possible, this checks an area of a destination device is invalid. 273 * If possible, this checks an area of a destination device is invalid.
313 */ 274 */
314static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev, 275static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
@@ -386,19 +347,17 @@ static int upgrade_mode(struct dm_dev_internal *dd, fmode_t new_mode,
386 struct mapped_device *md) 347 struct mapped_device *md)
387{ 348{
388 int r; 349 int r;
389 struct dm_dev_internal dd_new, dd_old; 350 struct dm_dev *old_dev, *new_dev;
390 351
391 dd_new = dd_old = *dd; 352 old_dev = dd->dm_dev;
392 353
393 dd_new.dm_dev.mode |= new_mode; 354 r = dm_get_table_device(md, dd->dm_dev->bdev->bd_dev,
394 dd_new.dm_dev.bdev = NULL; 355 dd->dm_dev->mode | new_mode, &new_dev);
395
396 r = open_dev(&dd_new, dd->dm_dev.bdev->bd_dev, md);
397 if (r) 356 if (r)
398 return r; 357 return r;
399 358
400 dd->dm_dev.mode |= new_mode; 359 dd->dm_dev = new_dev;
401 close_dev(&dd_old, md); 360 dm_put_table_device(md, old_dev);
402 361
403 return 0; 362 return 0;
404} 363}
@@ -440,27 +399,22 @@ int dm_get_device(struct dm_target *ti, const char *path, fmode_t mode,
440 if (!dd) 399 if (!dd)
441 return -ENOMEM; 400 return -ENOMEM;
442 401
443 dd->dm_dev.mode = mode; 402 if ((r = dm_get_table_device(t->md, dev, mode, &dd->dm_dev))) {
444 dd->dm_dev.bdev = NULL;
445
446 if ((r = open_dev(dd, dev, t->md))) {
447 kfree(dd); 403 kfree(dd);
448 return r; 404 return r;
449 } 405 }
450 406
451 format_dev_t(dd->dm_dev.name, dev);
452
453 atomic_set(&dd->count, 0); 407 atomic_set(&dd->count, 0);
454 list_add(&dd->list, &t->devices); 408 list_add(&dd->list, &t->devices);
455 409
456 } else if (dd->dm_dev.mode != (mode | dd->dm_dev.mode)) { 410 } else if (dd->dm_dev->mode != (mode | dd->dm_dev->mode)) {
457 r = upgrade_mode(dd, mode, t->md); 411 r = upgrade_mode(dd, mode, t->md);
458 if (r) 412 if (r)
459 return r; 413 return r;
460 } 414 }
461 atomic_inc(&dd->count); 415 atomic_inc(&dd->count);
462 416
463 *result = &dd->dm_dev; 417 *result = dd->dm_dev;
464 return 0; 418 return 0;
465} 419}
466EXPORT_SYMBOL(dm_get_device); 420EXPORT_SYMBOL(dm_get_device);
@@ -505,11 +459,23 @@ static int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev,
505 */ 459 */
506void dm_put_device(struct dm_target *ti, struct dm_dev *d) 460void dm_put_device(struct dm_target *ti, struct dm_dev *d)
507{ 461{
508 struct dm_dev_internal *dd = container_of(d, struct dm_dev_internal, 462 int found = 0;
509 dm_dev); 463 struct list_head *devices = &ti->table->devices;
464 struct dm_dev_internal *dd;
510 465
466 list_for_each_entry(dd, devices, list) {
467 if (dd->dm_dev == d) {
468 found = 1;
469 break;
470 }
471 }
472 if (!found) {
473 DMWARN("%s: device %s not in table devices list",
474 dm_device_name(ti->table->md), d->name);
475 return;
476 }
511 if (atomic_dec_and_test(&dd->count)) { 477 if (atomic_dec_and_test(&dd->count)) {
512 close_dev(dd, ti->table->md); 478 dm_put_table_device(ti->table->md, d);
513 list_del(&dd->list); 479 list_del(&dd->list);
514 kfree(dd); 480 kfree(dd);
515 } 481 }
@@ -906,7 +872,7 @@ static int dm_table_set_type(struct dm_table *t)
906 /* Non-request-stackable devices can't be used for request-based dm */ 872 /* Non-request-stackable devices can't be used for request-based dm */
907 devices = dm_table_get_devices(t); 873 devices = dm_table_get_devices(t);
908 list_for_each_entry(dd, devices, list) { 874 list_for_each_entry(dd, devices, list) {
909 if (!blk_queue_stackable(bdev_get_queue(dd->dm_dev.bdev))) { 875 if (!blk_queue_stackable(bdev_get_queue(dd->dm_dev->bdev))) {
910 DMWARN("table load rejected: including" 876 DMWARN("table load rejected: including"
911 " non-request-stackable devices"); 877 " non-request-stackable devices");
912 return -EINVAL; 878 return -EINVAL;
@@ -1043,7 +1009,7 @@ static struct gendisk * dm_table_get_integrity_disk(struct dm_table *t,
1043 struct gendisk *prev_disk = NULL, *template_disk = NULL; 1009 struct gendisk *prev_disk = NULL, *template_disk = NULL;
1044 1010
1045 list_for_each_entry(dd, devices, list) { 1011 list_for_each_entry(dd, devices, list) {
1046 template_disk = dd->dm_dev.bdev->bd_disk; 1012 template_disk = dd->dm_dev->bdev->bd_disk;
1047 if (!blk_get_integrity(template_disk)) 1013 if (!blk_get_integrity(template_disk))
1048 goto no_integrity; 1014 goto no_integrity;
1049 if (!match_all && !blk_integrity_is_initialized(template_disk)) 1015 if (!match_all && !blk_integrity_is_initialized(template_disk))
@@ -1629,7 +1595,7 @@ int dm_table_any_congested(struct dm_table *t, int bdi_bits)
1629 int r = 0; 1595 int r = 0;
1630 1596
1631 list_for_each_entry(dd, devices, list) { 1597 list_for_each_entry(dd, devices, list) {
1632 struct request_queue *q = bdev_get_queue(dd->dm_dev.bdev); 1598 struct request_queue *q = bdev_get_queue(dd->dm_dev->bdev);
1633 char b[BDEVNAME_SIZE]; 1599 char b[BDEVNAME_SIZE];
1634 1600
1635 if (likely(q)) 1601 if (likely(q))
@@ -1637,7 +1603,7 @@ int dm_table_any_congested(struct dm_table *t, int bdi_bits)
1637 else 1603 else
1638 DMWARN_LIMIT("%s: any_congested: nonexistent device %s", 1604 DMWARN_LIMIT("%s: any_congested: nonexistent device %s",
1639 dm_device_name(t->md), 1605 dm_device_name(t->md),
1640 bdevname(dd->dm_dev.bdev, b)); 1606 bdevname(dd->dm_dev->bdev, b));
1641 } 1607 }
1642 1608
1643 list_for_each_entry(cb, &t->target_callbacks, list) 1609 list_for_each_entry(cb, &t->target_callbacks, list)
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 32b958dbc499..58f3927fd7cc 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -142,6 +142,9 @@ struct mapped_device {
142 */ 142 */
143 struct dm_table *map; 143 struct dm_table *map;
144 144
145 struct list_head table_devices;
146 struct mutex table_devices_lock;
147
145 unsigned long flags; 148 unsigned long flags;
146 149
147 struct request_queue *queue; 150 struct request_queue *queue;
@@ -212,6 +215,12 @@ struct dm_md_mempools {
212 struct bio_set *bs; 215 struct bio_set *bs;
213}; 216};
214 217
218struct table_device {
219 struct list_head list;
220 atomic_t count;
221 struct dm_dev dm_dev;
222};
223
215#define RESERVED_BIO_BASED_IOS 16 224#define RESERVED_BIO_BASED_IOS 16
216#define RESERVED_REQUEST_BASED_IOS 256 225#define RESERVED_REQUEST_BASED_IOS 256
217#define RESERVED_MAX_IOS 1024 226#define RESERVED_MAX_IOS 1024
@@ -670,6 +679,120 @@ static void dm_put_live_table_fast(struct mapped_device *md) __releases(RCU)
670} 679}
671 680
672/* 681/*
682 * Open a table device so we can use it as a map destination.
683 */
684static int open_table_device(struct table_device *td, dev_t dev,
685 struct mapped_device *md)
686{
687 static char *_claim_ptr = "I belong to device-mapper";
688 struct block_device *bdev;
689
690 int r;
691
692 BUG_ON(td->dm_dev.bdev);
693
694 bdev = blkdev_get_by_dev(dev, td->dm_dev.mode | FMODE_EXCL, _claim_ptr);
695 if (IS_ERR(bdev))
696 return PTR_ERR(bdev);
697
698 r = bd_link_disk_holder(bdev, dm_disk(md));
699 if (r) {
700 blkdev_put(bdev, td->dm_dev.mode | FMODE_EXCL);
701 return r;
702 }
703
704 td->dm_dev.bdev = bdev;
705 return 0;
706}
707
708/*
709 * Close a table device that we've been using.
710 */
711static void close_table_device(struct table_device *td, struct mapped_device *md)
712{
713 if (!td->dm_dev.bdev)
714 return;
715
716 bd_unlink_disk_holder(td->dm_dev.bdev, dm_disk(md));
717 blkdev_put(td->dm_dev.bdev, td->dm_dev.mode | FMODE_EXCL);
718 td->dm_dev.bdev = NULL;
719}
720
721static struct table_device *find_table_device(struct list_head *l, dev_t dev,
722 fmode_t mode) {
723 struct table_device *td;
724
725 list_for_each_entry(td, l, list)
726 if (td->dm_dev.bdev->bd_dev == dev && td->dm_dev.mode == mode)
727 return td;
728
729 return NULL;
730}
731
732int dm_get_table_device(struct mapped_device *md, dev_t dev, fmode_t mode,
733 struct dm_dev **result) {
734 int r;
735 struct table_device *td;
736
737 mutex_lock(&md->table_devices_lock);
738 td = find_table_device(&md->table_devices, dev, mode);
739 if (!td) {
740 td = kmalloc(sizeof(*td), GFP_KERNEL);
741 if (!td) {
742 mutex_unlock(&md->table_devices_lock);
743 return -ENOMEM;
744 }
745
746 td->dm_dev.mode = mode;
747 td->dm_dev.bdev = NULL;
748
749 if ((r = open_table_device(td, dev, md))) {
750 mutex_unlock(&md->table_devices_lock);
751 kfree(td);
752 return r;
753 }
754
755 format_dev_t(td->dm_dev.name, dev);
756
757 atomic_set(&td->count, 0);
758 list_add(&td->list, &md->table_devices);
759 }
760 atomic_inc(&td->count);
761 mutex_unlock(&md->table_devices_lock);
762
763 *result = &td->dm_dev;
764 return 0;
765}
766EXPORT_SYMBOL_GPL(dm_get_table_device);
767
768void dm_put_table_device(struct mapped_device *md, struct dm_dev *d)
769{
770 struct table_device *td = container_of(d, struct table_device, dm_dev);
771
772 mutex_lock(&md->table_devices_lock);
773 if (atomic_dec_and_test(&td->count)) {
774 close_table_device(td, md);
775 list_del(&td->list);
776 kfree(td);
777 }
778 mutex_unlock(&md->table_devices_lock);
779}
780EXPORT_SYMBOL(dm_put_table_device);
781
782static void free_table_devices(struct list_head *devices)
783{
784 struct list_head *tmp, *next;
785
786 list_for_each_safe(tmp, next, devices) {
787 struct table_device *td = list_entry(tmp, struct table_device, list);
788
789 DMWARN("dm_destroy: %s still exists with %d references",
790 td->dm_dev.name, atomic_read(&td->count));
791 kfree(td);
792 }
793}
794
795/*
673 * Get the geometry associated with a dm device 796 * Get the geometry associated with a dm device
674 */ 797 */
675int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo) 798int dm_get_geometry(struct mapped_device *md, struct hd_geometry *geo)
@@ -1249,13 +1372,13 @@ static void clone_bio(struct dm_target_io *tio, struct bio *bio,
1249} 1372}
1250 1373
1251static struct dm_target_io *alloc_tio(struct clone_info *ci, 1374static struct dm_target_io *alloc_tio(struct clone_info *ci,
1252 struct dm_target *ti, int nr_iovecs, 1375 struct dm_target *ti,
1253 unsigned target_bio_nr) 1376 unsigned target_bio_nr)
1254{ 1377{
1255 struct dm_target_io *tio; 1378 struct dm_target_io *tio;
1256 struct bio *clone; 1379 struct bio *clone;
1257 1380
1258 clone = bio_alloc_bioset(GFP_NOIO, nr_iovecs, ci->md->bs); 1381 clone = bio_alloc_bioset(GFP_NOIO, 0, ci->md->bs);
1259 tio = container_of(clone, struct dm_target_io, clone); 1382 tio = container_of(clone, struct dm_target_io, clone);
1260 1383
1261 tio->io = ci->io; 1384 tio->io = ci->io;
@@ -1269,17 +1392,12 @@ static void __clone_and_map_simple_bio(struct clone_info *ci,
1269 struct dm_target *ti, 1392 struct dm_target *ti,
1270 unsigned target_bio_nr, unsigned *len) 1393 unsigned target_bio_nr, unsigned *len)
1271{ 1394{
1272 struct dm_target_io *tio = alloc_tio(ci, ti, ci->bio->bi_max_vecs, target_bio_nr); 1395 struct dm_target_io *tio = alloc_tio(ci, ti, target_bio_nr);
1273 struct bio *clone = &tio->clone; 1396 struct bio *clone = &tio->clone;
1274 1397
1275 tio->len_ptr = len; 1398 tio->len_ptr = len;
1276 1399
1277 /* 1400 __bio_clone_fast(clone, ci->bio);
1278 * Discard requests require the bio's inline iovecs be initialized.
1279 * ci->bio->bi_max_vecs is BIO_INLINE_VECS anyway, for both flush
1280 * and discard, so no need for concern about wasted bvec allocations.
1281 */
1282 __bio_clone_fast(clone, ci->bio);
1283 if (len) 1401 if (len)
1284 bio_setup_sector(clone, ci->sector, *len); 1402 bio_setup_sector(clone, ci->sector, *len);
1285 1403
@@ -1322,7 +1440,7 @@ static void __clone_and_map_data_bio(struct clone_info *ci, struct dm_target *ti
1322 num_target_bios = ti->num_write_bios(ti, bio); 1440 num_target_bios = ti->num_write_bios(ti, bio);
1323 1441
1324 for (target_bio_nr = 0; target_bio_nr < num_target_bios; target_bio_nr++) { 1442 for (target_bio_nr = 0; target_bio_nr < num_target_bios; target_bio_nr++) {
1325 tio = alloc_tio(ci, ti, 0, target_bio_nr); 1443 tio = alloc_tio(ci, ti, target_bio_nr);
1326 tio->len_ptr = len; 1444 tio->len_ptr = len;
1327 clone_bio(tio, bio, sector, *len); 1445 clone_bio(tio, bio, sector, *len);
1328 __map_bio(tio); 1446 __map_bio(tio);
@@ -1949,12 +2067,14 @@ static struct mapped_device *alloc_dev(int minor)
1949 md->type = DM_TYPE_NONE; 2067 md->type = DM_TYPE_NONE;
1950 mutex_init(&md->suspend_lock); 2068 mutex_init(&md->suspend_lock);
1951 mutex_init(&md->type_lock); 2069 mutex_init(&md->type_lock);
2070 mutex_init(&md->table_devices_lock);
1952 spin_lock_init(&md->deferred_lock); 2071 spin_lock_init(&md->deferred_lock);
1953 atomic_set(&md->holders, 1); 2072 atomic_set(&md->holders, 1);
1954 atomic_set(&md->open_count, 0); 2073 atomic_set(&md->open_count, 0);
1955 atomic_set(&md->event_nr, 0); 2074 atomic_set(&md->event_nr, 0);
1956 atomic_set(&md->uevent_seq, 0); 2075 atomic_set(&md->uevent_seq, 0);
1957 INIT_LIST_HEAD(&md->uevent_list); 2076 INIT_LIST_HEAD(&md->uevent_list);
2077 INIT_LIST_HEAD(&md->table_devices);
1958 spin_lock_init(&md->uevent_lock); 2078 spin_lock_init(&md->uevent_lock);
1959 2079
1960 md->queue = blk_alloc_queue(GFP_KERNEL); 2080 md->queue = blk_alloc_queue(GFP_KERNEL);
@@ -2040,6 +2160,7 @@ static void free_dev(struct mapped_device *md)
2040 blk_integrity_unregister(md->disk); 2160 blk_integrity_unregister(md->disk);
2041 del_gendisk(md->disk); 2161 del_gendisk(md->disk);
2042 cleanup_srcu_struct(&md->io_barrier); 2162 cleanup_srcu_struct(&md->io_barrier);
2163 free_table_devices(&md->table_devices);
2043 free_minor(minor); 2164 free_minor(minor);
2044 2165
2045 spin_lock(&_minor_lock); 2166 spin_lock(&_minor_lock);
@@ -2900,7 +3021,7 @@ struct dm_md_mempools *dm_alloc_md_mempools(unsigned type, unsigned integrity, u
2900 if (!pools->io_pool) 3021 if (!pools->io_pool)
2901 goto out; 3022 goto out;
2902 3023
2903 pools->bs = bioset_create(pool_size, front_pad); 3024 pools->bs = bioset_create_nobvec(pool_size, front_pad);
2904 if (!pools->bs) 3025 if (!pools->bs)
2905 goto out; 3026 goto out;
2906 3027
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index e81d2152fa68..988c7fb7b145 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -44,7 +44,7 @@
44struct dm_dev_internal { 44struct dm_dev_internal {
45 struct list_head list; 45 struct list_head list;
46 atomic_t count; 46 atomic_t count;
47 struct dm_dev dm_dev; 47 struct dm_dev *dm_dev;
48}; 48};
49 49
50struct dm_table; 50struct dm_table;
@@ -188,6 +188,9 @@ int dm_cancel_deferred_remove(struct mapped_device *md);
188int dm_request_based(struct mapped_device *md); 188int dm_request_based(struct mapped_device *md);
189sector_t dm_get_size(struct mapped_device *md); 189sector_t dm_get_size(struct mapped_device *md);
190struct request_queue *dm_get_md_queue(struct mapped_device *md); 190struct request_queue *dm_get_md_queue(struct mapped_device *md);
191int dm_get_table_device(struct mapped_device *md, dev_t dev, fmode_t mode,
192 struct dm_dev **result);
193void dm_put_table_device(struct mapped_device *md, struct dm_dev *d);
191struct dm_stats *dm_get_stats(struct mapped_device *md); 194struct dm_stats *dm_get_stats(struct mapped_device *md);
192 195
193int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action, 196int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
diff --git a/include/uapi/linux/dm-ioctl.h b/include/uapi/linux/dm-ioctl.h
index c8a4302093a3..3315ab21f728 100644
--- a/include/uapi/linux/dm-ioctl.h
+++ b/include/uapi/linux/dm-ioctl.h
@@ -267,9 +267,9 @@ enum {
267#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl) 267#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
268 268
269#define DM_VERSION_MAJOR 4 269#define DM_VERSION_MAJOR 4
270#define DM_VERSION_MINOR 27 270#define DM_VERSION_MINOR 28
271#define DM_VERSION_PATCHLEVEL 0 271#define DM_VERSION_PATCHLEVEL 0
272#define DM_VERSION_EXTRA "-ioctl (2013-10-30)" 272#define DM_VERSION_EXTRA "-ioctl (2014-09-17)"
273 273
274/* Status bits */ 274/* Status bits */
275#define DM_READONLY_FLAG (1 << 0) /* In/Out */ 275#define DM_READONLY_FLAG (1 << 0) /* In/Out */