Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

Pull device mapper updates from Mike Snitzer:
"Smaller set of DM changes for this merge. I've based these changes on
Jens' for-4.4/reservations branch because the associated DM changes
required it.

- Revert a dm-multipath change that caused a regression for
unprivledged users (e.g. kvm guests) that issued ioctls when a
multipath device had no available paths.

- Include Christoph's refactoring of DM's ioctl handling and add
support for passing through persistent reservations with DM
multipath.

- All other changes are very simple cleanups"

* tag 'dm-4.4-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm:
dm switch: simplify conditional in alloc_region_table()
dm delay: document that offsets are specified in sectors
dm delay: capitalize the start of an delay_ctr() error message
dm delay: Use DM_MAPIO macros instead of open-coded equivalents
dm linear: remove redundant target name from error messages
dm persistent data: eliminate unnecessary return values
dm: eliminate unused "bioset" process for each bio-based DM device
dm: convert ffs to __ffs
dm: drop NULL test before kmem_cache_destroy() and mempool_destroy()
dm: add support for passing through persistent reservations
dm: refactor ioctl handling
Revert "dm mpath: fix stalls when handling invalid ioctls"
dm: initialize non-blk-mq queue data before queue is used

+333 -215
+1
Documentation/device-mapper/delay.txt
··· 8 8 <device> <offset> <delay> [<write_device> <write_offset> <write_delay>] 9 9 10 10 With separate write parameters, the first set is only used for reads. 11 + Offsets are specified in sectors. 11 12 Delays are specified in milliseconds. 12 13 13 14 Example scripts
+7 -11
drivers/md/dm-bufio.c
··· 1598 1598 1599 1599 c->bdev = bdev; 1600 1600 c->block_size = block_size; 1601 - c->sectors_per_block_bits = ffs(block_size) - 1 - SECTOR_SHIFT; 1602 - c->pages_per_block_bits = (ffs(block_size) - 1 >= PAGE_SHIFT) ? 1603 - ffs(block_size) - 1 - PAGE_SHIFT : 0; 1604 - c->blocks_per_page_bits = (ffs(block_size) - 1 < PAGE_SHIFT ? 1605 - PAGE_SHIFT - (ffs(block_size) - 1) : 0); 1601 + c->sectors_per_block_bits = __ffs(block_size) - SECTOR_SHIFT; 1602 + c->pages_per_block_bits = (__ffs(block_size) >= PAGE_SHIFT) ? 1603 + __ffs(block_size) - PAGE_SHIFT : 0; 1604 + c->blocks_per_page_bits = (__ffs(block_size) < PAGE_SHIFT ? 1605 + PAGE_SHIFT - __ffs(block_size) : 0); 1606 1606 1607 1607 c->aux_size = aux_size; 1608 1608 c->alloc_callback = alloc_callback; ··· 1861 1861 cancel_delayed_work_sync(&dm_bufio_work); 1862 1862 destroy_workqueue(dm_bufio_wq); 1863 1863 1864 - for (i = 0; i < ARRAY_SIZE(dm_bufio_caches); i++) { 1865 - struct kmem_cache *kc = dm_bufio_caches[i]; 1866 - 1867 - if (kc) 1868 - kmem_cache_destroy(kc); 1869 - } 1864 + for (i = 0; i < ARRAY_SIZE(dm_bufio_caches); i++) 1865 + kmem_cache_destroy(dm_bufio_caches[i]); 1870 1866 1871 1867 for (i = 0; i < ARRAY_SIZE(dm_bufio_cache_names); i++) 1872 1868 kfree(dm_bufio_cache_names[i]);
+6 -2
drivers/md/dm-cache-metadata.c
··· 260 260 } 261 261 } 262 262 263 - return dm_bm_unlock(b); 263 + dm_bm_unlock(b); 264 + 265 + return 0; 264 266 } 265 267 266 268 static void __setup_mapping_info(struct dm_cache_metadata *cmd) ··· 467 465 dm_disk_bitset_init(cmd->tm, &cmd->discard_info); 468 466 sb_flags = le32_to_cpu(disk_super->flags); 469 467 cmd->clean_when_opened = test_bit(CLEAN_SHUTDOWN, &sb_flags); 470 - return dm_bm_unlock(sblock); 468 + dm_bm_unlock(sblock); 469 + 470 + return 0; 471 471 472 472 bad: 473 473 dm_bm_unlock(sblock);
+1 -1
drivers/md/dm-cache-policy-cleaner.c
··· 83 83 static int alloc_hash(struct hash *hash, unsigned elts) 84 84 { 85 85 hash->nr_buckets = next_power(elts >> 4, 16); 86 - hash->hash_bits = ffs(hash->nr_buckets) - 1; 86 + hash->hash_bits = __ffs(hash->nr_buckets); 87 87 hash->table = vzalloc(sizeof(*hash->table) * hash->nr_buckets); 88 88 89 89 return hash->table ? 0 : -ENOMEM;
+1 -1
drivers/md/dm-cache-policy-mq.c
··· 1410 1410 mq->generation_period = max((unsigned) from_cblock(cache_size), 1024U); 1411 1411 1412 1412 mq->nr_buckets = next_power(from_cblock(cache_size) / 2, 16); 1413 - mq->hash_bits = ffs(mq->nr_buckets) - 1; 1413 + mq->hash_bits = __ffs(mq->nr_buckets); 1414 1414 mq->table = vzalloc(sizeof(*mq->table) * mq->nr_buckets); 1415 1415 if (!mq->table) 1416 1416 goto bad_alloc_table;
+1 -1
drivers/md/dm-cache-policy-smq.c
··· 566 566 567 567 ht->es = es; 568 568 nr_buckets = roundup_pow_of_two(max(nr_entries / 4u, 16u)); 569 - ht->hash_bits = ffs(nr_buckets) - 1; 569 + ht->hash_bits = __ffs(nr_buckets); 570 570 571 571 ht->buckets = vmalloc(sizeof(*ht->buckets) * nr_buckets); 572 572 if (!ht->buckets)
+1 -2
drivers/md/dm-cache-target.c
··· 2309 2309 { 2310 2310 unsigned i; 2311 2311 2312 - if (cache->migration_pool) 2313 - mempool_destroy(cache->migration_pool); 2312 + mempool_destroy(cache->migration_pool); 2314 2313 2315 2314 if (cache->all_io_ds) 2316 2315 dm_deferred_set_destroy(cache->all_io_ds);
+2 -4
drivers/md/dm-crypt.c
··· 1544 1544 if (cc->bs) 1545 1545 bioset_free(cc->bs); 1546 1546 1547 - if (cc->page_pool) 1548 - mempool_destroy(cc->page_pool); 1549 - if (cc->req_pool) 1550 - mempool_destroy(cc->req_pool); 1547 + mempool_destroy(cc->page_pool); 1548 + mempool_destroy(cc->req_pool); 1551 1549 1552 1550 if (cc->iv_gen_ops && cc->iv_gen_ops->dtr) 1553 1551 cc->iv_gen_ops->dtr(cc);
+4 -3
drivers/md/dm-delay.c
··· 122 122 * <device> <offset> <delay> [<write_device> <write_offset> <write_delay>] 123 123 * 124 124 * With separate write parameters, the first set is only used for reads. 125 + * Offsets are specified in sectors. 125 126 * Delays are specified in milliseconds. 126 127 */ 127 128 static int delay_ctr(struct dm_target *ti, unsigned int argc, char **argv) ··· 133 132 int ret; 134 133 135 134 if (argc != 3 && argc != 6) { 136 - ti->error = "requires exactly 3 or 6 arguments"; 135 + ti->error = "Requires exactly 3 or 6 arguments"; 137 136 return -EINVAL; 138 137 } 139 138 ··· 238 237 unsigned long expires = 0; 239 238 240 239 if (!delay || !atomic_read(&dc->may_delay)) 241 - return 1; 240 + return DM_MAPIO_REMAPPED; 242 241 243 242 delayed = dm_per_bio_data(bio, sizeof(struct dm_delay_info)); 244 243 ··· 258 257 259 258 queue_timeout(dc, expires); 260 259 261 - return 0; 260 + return DM_MAPIO_SUBMITTED; 262 261 } 263 262 264 263 static void delay_presuspend(struct dm_target *ti)
+7 -8
drivers/md/dm-era-target.c
··· 343 343 } 344 344 } 345 345 346 - return dm_bm_unlock(b); 346 + dm_bm_unlock(b); 347 + 348 + return 0; 347 349 } 348 350 349 351 /*----------------------------------------------------------------*/ ··· 584 582 md->metadata_snap = le64_to_cpu(disk->metadata_snap); 585 583 md->archived_writesets = true; 586 584 587 - return dm_bm_unlock(sblock); 585 + dm_bm_unlock(sblock); 586 + 587 + return 0; 588 588 589 589 bad: 590 590 dm_bm_unlock(sblock); ··· 1050 1046 1051 1047 md->metadata_snap = dm_block_location(clone); 1052 1048 1053 - r = dm_tm_unlock(md->tm, clone); 1054 - if (r) { 1055 - DMERR("%s: couldn't unlock clone", __func__); 1056 - md->metadata_snap = SUPERBLOCK_LOCATION; 1057 - return r; 1058 - } 1049 + dm_tm_unlock(md->tm, clone); 1059 1050 1060 1051 return 0; 1061 1052 }
+1 -1
drivers/md/dm-exception-store.c
··· 183 183 184 184 store->chunk_size = chunk_size; 185 185 store->chunk_mask = chunk_size - 1; 186 - store->chunk_shift = ffs(chunk_size) - 1; 186 + store->chunk_shift = __ffs(chunk_size); 187 187 188 188 return 0; 189 189 }
+8 -8
drivers/md/dm-flakey.c
··· 373 373 } 374 374 } 375 375 376 - static int flakey_ioctl(struct dm_target *ti, unsigned int cmd, unsigned long arg) 376 + static int flakey_prepare_ioctl(struct dm_target *ti, 377 + struct block_device **bdev, fmode_t *mode) 377 378 { 378 379 struct flakey_c *fc = ti->private; 379 - struct dm_dev *dev = fc->dev; 380 - int r = 0; 380 + 381 + *bdev = fc->dev->bdev; 381 382 382 383 /* 383 384 * Only pass ioctls through if the device sizes match exactly. 384 385 */ 385 386 if (fc->start || 386 - ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT) 387 - r = scsi_verify_blk_ioctl(NULL, cmd); 388 - 389 - return r ? : __blkdev_driver_ioctl(dev->bdev, dev->mode, cmd, arg); 387 + ti->len != i_size_read((*bdev)->bd_inode) >> SECTOR_SHIFT) 388 + return 1; 389 + return 0; 390 390 } 391 391 392 392 static int flakey_iterate_devices(struct dm_target *ti, iterate_devices_callout_fn fn, void *data) ··· 405 405 .map = flakey_map, 406 406 .end_io = flakey_end_io, 407 407 .status = flakey_status, 408 - .ioctl = flakey_ioctl, 408 + .prepare_ioctl = flakey_prepare_ioctl, 409 409 .iterate_devices = flakey_iterate_devices, 410 410 }; 411 411
+1 -2
drivers/md/dm-io.c
··· 65 65 return client; 66 66 67 67 bad: 68 - if (client->pool) 69 - mempool_destroy(client->pool); 68 + mempool_destroy(client->pool); 70 69 kfree(client); 71 70 return ERR_PTR(-ENOMEM); 72 71 }
+10 -10
drivers/md/dm-linear.c
··· 39 39 40 40 lc = kmalloc(sizeof(*lc), GFP_KERNEL); 41 41 if (lc == NULL) { 42 - ti->error = "dm-linear: Cannot allocate linear context"; 42 + ti->error = "Cannot allocate linear context"; 43 43 return -ENOMEM; 44 44 } 45 45 46 46 ret = -EINVAL; 47 47 if (sscanf(argv[1], "%llu%c", &tmp, &dummy) != 1) { 48 - ti->error = "dm-linear: Invalid device sector"; 48 + ti->error = "Invalid device sector"; 49 49 goto bad; 50 50 } 51 51 lc->start = tmp; 52 52 53 53 ret = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &lc->dev); 54 54 if (ret) { 55 - ti->error = "dm-linear: Device lookup failed"; 55 + ti->error = "Device lookup failed"; 56 56 goto bad; 57 57 } 58 58 ··· 116 116 } 117 117 } 118 118 119 - static int linear_ioctl(struct dm_target *ti, unsigned int cmd, 120 - unsigned long arg) 119 + static int linear_prepare_ioctl(struct dm_target *ti, 120 + struct block_device **bdev, fmode_t *mode) 121 121 { 122 122 struct linear_c *lc = (struct linear_c *) ti->private; 123 123 struct dm_dev *dev = lc->dev; 124 - int r = 0; 124 + 125 + *bdev = dev->bdev; 125 126 126 127 /* 127 128 * Only pass ioctls through if the device sizes match exactly. 128 129 */ 129 130 if (lc->start || 130 131 ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT) 131 - r = scsi_verify_blk_ioctl(NULL, cmd); 132 - 133 - return r ? : __blkdev_driver_ioctl(dev->bdev, dev->mode, cmd, arg); 132 + return 1; 133 + return 0; 134 134 } 135 135 136 136 static int linear_iterate_devices(struct dm_target *ti, ··· 149 149 .dtr = linear_dtr, 150 150 .map = linear_map, 151 151 .status = linear_status, 152 - .ioctl = linear_ioctl, 152 + .prepare_ioctl = linear_prepare_ioctl, 153 153 .iterate_devices = linear_iterate_devices, 154 154 }; 155 155
+1 -2
drivers/md/dm-log-userspace-base.c
··· 313 313 out: 314 314 kfree(devices_rdata); 315 315 if (r) { 316 - if (lc->flush_entry_pool) 317 - mempool_destroy(lc->flush_entry_pool); 316 + mempool_destroy(lc->flush_entry_pool); 318 317 kfree(lc); 319 318 kfree(ctr_str); 320 319 } else {
+6 -7
drivers/md/dm-log-writes.c
··· 714 714 } 715 715 } 716 716 717 - static int log_writes_ioctl(struct dm_target *ti, unsigned int cmd, 718 - unsigned long arg) 717 + static int log_writes_prepare_ioctl(struct dm_target *ti, 718 + struct block_device **bdev, fmode_t *mode) 719 719 { 720 720 struct log_writes_c *lc = ti->private; 721 721 struct dm_dev *dev = lc->dev; 722 - int r = 0; 723 722 723 + *bdev = dev->bdev; 724 724 /* 725 725 * Only pass ioctls through if the device sizes match exactly. 726 726 */ 727 727 if (ti->len != i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT) 728 - r = scsi_verify_blk_ioctl(NULL, cmd); 729 - 730 - return r ? : __blkdev_driver_ioctl(dev->bdev, dev->mode, cmd, arg); 728 + return 1; 729 + return 0; 731 730 } 732 731 733 732 static int log_writes_iterate_devices(struct dm_target *ti, ··· 781 782 .map = log_writes_map, 782 783 .end_io = normal_end_io, 783 784 .status = log_writes_status, 784 - .ioctl = log_writes_ioctl, 785 + .prepare_ioctl = log_writes_prepare_ioctl, 785 786 .message = log_writes_message, 786 787 .iterate_devices = log_writes_iterate_devices, 787 788 .io_hints = log_writes_io_hints,
+13 -21
drivers/md/dm-mpath.c
··· 1533 1533 return r; 1534 1534 } 1535 1535 1536 - static int multipath_ioctl(struct dm_target *ti, unsigned int cmd, 1537 - unsigned long arg) 1536 + static int multipath_prepare_ioctl(struct dm_target *ti, 1537 + struct block_device **bdev, fmode_t *mode) 1538 1538 { 1539 1539 struct multipath *m = ti->private; 1540 1540 struct pgpath *pgpath; 1541 - struct block_device *bdev; 1542 - fmode_t mode; 1543 1541 unsigned long flags; 1544 1542 int r; 1545 1543 1546 - bdev = NULL; 1547 - mode = 0; 1548 1544 r = 0; 1549 1545 1550 1546 spin_lock_irqsave(&m->lock, flags); ··· 1551 1555 pgpath = m->current_pgpath; 1552 1556 1553 1557 if (pgpath) { 1554 - bdev = pgpath->path.dev->bdev; 1555 - mode = pgpath->path.dev->mode; 1558 + *bdev = pgpath->path.dev->bdev; 1559 + *mode = pgpath->path.dev->mode; 1556 1560 } 1557 1561 1558 1562 if ((pgpath && m->queue_io) || (!pgpath && m->queue_if_no_path)) 1559 1563 r = -ENOTCONN; 1560 - else if (!bdev) 1564 + else if (!*bdev) 1561 1565 r = -EIO; 1562 1566 1563 1567 spin_unlock_irqrestore(&m->lock, flags); 1564 - 1565 - /* 1566 - * Only pass ioctls through if the device sizes match exactly. 1567 - */ 1568 - if (!bdev || ti->len != i_size_read(bdev->bd_inode) >> SECTOR_SHIFT) { 1569 - int err = scsi_verify_blk_ioctl(NULL, cmd); 1570 - if (err) 1571 - r = err; 1572 - } 1573 1568 1574 1569 if (r == -ENOTCONN && !fatal_signal_pending(current)) { 1575 1570 spin_lock_irqsave(&m->lock, flags); ··· 1574 1587 dm_table_run_md_queue_async(m->ti->table); 1575 1588 } 1576 1589 1577 - return r ? : __blkdev_driver_ioctl(bdev, mode, cmd, arg); 1590 + /* 1591 + * Only pass ioctls through if the device sizes match exactly. 1592 + */ 1593 + if (!r && ti->len != i_size_read((*bdev)->bd_inode) >> SECTOR_SHIFT) 1594 + return 1; 1595 + return r; 1578 1596 } 1579 1597 1580 1598 static int multipath_iterate_devices(struct dm_target *ti, ··· 1682 1690 *---------------------------------------------------------------*/ 1683 1691 static struct target_type multipath_target = { 1684 1692 .name = "multipath", 1685 - .version = {1, 9, 0}, 1693 + .version = {1, 10, 0}, 1686 1694 .module = THIS_MODULE, 1687 1695 .ctr = multipath_ctr, 1688 1696 .dtr = multipath_dtr, ··· 1695 1703 .resume = multipath_resume, 1696 1704 .status = multipath_status, 1697 1705 .message = multipath_message, 1698 - .ioctl = multipath_ioctl, 1706 + .prepare_ioctl = multipath_prepare_ioctl, 1699 1707 .iterate_devices = multipath_iterate_devices, 1700 1708 .busy = multipath_busy, 1701 1709 };
+2 -4
drivers/md/dm-region-hash.c
··· 193 193 rh->max_recovery = max_recovery; 194 194 rh->log = log; 195 195 rh->region_size = region_size; 196 - rh->region_shift = ffs(region_size) - 1; 196 + rh->region_shift = __ffs(region_size); 197 197 rwlock_init(&rh->hash_lock); 198 198 rh->mask = nr_buckets - 1; 199 199 rh->nr_buckets = nr_buckets; ··· 249 249 if (rh->log) 250 250 dm_dirty_log_destroy(rh->log); 251 251 252 - if (rh->region_pool) 253 - mempool_destroy(rh->region_pool); 254 - 252 + mempool_destroy(rh->region_pool); 255 253 vfree(rh->buckets); 256 254 kfree(rh); 257 255 }
+1 -1
drivers/md/dm-snap-persistent.c
··· 322 322 bdev_logical_block_size(dm_snap_cow(ps->store->snap)-> 323 323 bdev) >> 9); 324 324 ps->store->chunk_mask = ps->store->chunk_size - 1; 325 - ps->store->chunk_shift = ffs(ps->store->chunk_size) - 1; 325 + ps->store->chunk_shift = __ffs(ps->store->chunk_size); 326 326 chunk_size_supplied = 0; 327 327 } 328 328
+11 -14
drivers/md/dm-switch.c
··· 99 99 if (sector_div(nr_regions, sctx->region_size)) 100 100 nr_regions++; 101 101 102 - sctx->nr_regions = nr_regions; 103 - if (sctx->nr_regions != nr_regions || sctx->nr_regions >= ULONG_MAX) { 102 + if (nr_regions >= ULONG_MAX) { 104 103 ti->error = "Region table too large"; 105 104 return -EINVAL; 106 105 } 106 + sctx->nr_regions = nr_regions; 107 107 108 108 nr_slots = nr_regions; 109 109 if (sector_div(nr_slots, sctx->region_entries_per_slot)) ··· 511 511 * 512 512 * Passthrough all ioctls to the path for sector 0 513 513 */ 514 - static int switch_ioctl(struct dm_target *ti, unsigned cmd, 515 - unsigned long arg) 514 + static int switch_prepare_ioctl(struct dm_target *ti, 515 + struct block_device **bdev, fmode_t *mode) 516 516 { 517 517 struct switch_ctx *sctx = ti->private; 518 - struct block_device *bdev; 519 - fmode_t mode; 520 518 unsigned path_nr; 521 - int r = 0; 522 519 523 520 path_nr = switch_get_path_nr(sctx, 0); 524 521 525 - bdev = sctx->path_list[path_nr].dmdev->bdev; 526 - mode = sctx->path_list[path_nr].dmdev->mode; 522 + *bdev = sctx->path_list[path_nr].dmdev->bdev; 523 + *mode = sctx->path_list[path_nr].dmdev->mode; 527 524 528 525 /* 529 526 * Only pass ioctls through if the device sizes match exactly. 530 527 */ 531 - if (ti->len + sctx->path_list[path_nr].start != i_size_read(bdev->bd_inode) >> SECTOR_SHIFT) 532 - r = scsi_verify_blk_ioctl(NULL, cmd); 533 - 534 - return r ? : __blkdev_driver_ioctl(bdev, mode, cmd, arg); 528 + if (ti->len + sctx->path_list[path_nr].start != 529 + i_size_read((*bdev)->bd_inode) >> SECTOR_SHIFT) 530 + return 1; 531 + return 0; 535 532 } 536 533 537 534 static int switch_iterate_devices(struct dm_target *ti, ··· 557 560 .map = switch_map, 558 561 .message = switch_message, 559 562 .status = switch_status, 560 - .ioctl = switch_ioctl, 563 + .prepare_ioctl = switch_prepare_ioctl, 561 564 .iterate_devices = switch_iterate_devices, 562 565 }; 563 566
+12 -4
drivers/md/dm-thin-metadata.c
··· 396 396 } 397 397 } 398 398 399 - return dm_bm_unlock(b); 399 + dm_bm_unlock(b); 400 + 401 + return 0; 400 402 } 401 403 402 404 static void __setup_btree_details(struct dm_pool_metadata *pmd) ··· 652 650 } 653 651 654 652 __setup_btree_details(pmd); 655 - return dm_bm_unlock(sblock); 653 + dm_bm_unlock(sblock); 654 + 655 + return 0; 656 656 657 657 bad_cleanup_data_sm: 658 658 dm_sm_destroy(pmd->data_sm); ··· 1301 1297 dm_btree_del(&pmd->details_info, le64_to_cpu(disk_super->device_details_root)); 1302 1298 dm_sm_dec_block(pmd->metadata_sm, held_root); 1303 1299 1304 - return dm_tm_unlock(pmd->tm, copy); 1300 + dm_tm_unlock(pmd->tm, copy); 1301 + 1302 + return 0; 1305 1303 } 1306 1304 1307 1305 int dm_pool_release_metadata_snap(struct dm_pool_metadata *pmd) ··· 1333 1327 disk_super = dm_block_data(sblock); 1334 1328 *result = le64_to_cpu(disk_super->held_root); 1335 1329 1336 - return dm_bm_unlock(sblock); 1330 + dm_bm_unlock(sblock); 1331 + 1332 + return 0; 1337 1333 } 1338 1334 1339 1335 int dm_pool_get_metadata_snap(struct dm_pool_metadata *pmd,
+7 -8
drivers/md/dm-verity.c
··· 631 631 } 632 632 } 633 633 634 - static int verity_ioctl(struct dm_target *ti, unsigned cmd, 635 - unsigned long arg) 634 + static int verity_prepare_ioctl(struct dm_target *ti, 635 + struct block_device **bdev, fmode_t *mode) 636 636 { 637 637 struct dm_verity *v = ti->private; 638 - int r = 0; 638 + 639 + *bdev = v->data_dev->bdev; 639 640 640 641 if (v->data_start || 641 642 ti->len != i_size_read(v->data_dev->bdev->bd_inode) >> SECTOR_SHIFT) 642 - r = scsi_verify_blk_ioctl(NULL, cmd); 643 - 644 - return r ? : __blkdev_driver_ioctl(v->data_dev->bdev, v->data_dev->mode, 645 - cmd, arg); 643 + return 1; 644 + return 0; 646 645 } 647 646 648 647 static int verity_iterate_devices(struct dm_target *ti, ··· 964 965 .dtr = verity_dtr, 965 966 .map = verity_map, 966 967 .status = verity_status, 967 - .ioctl = verity_ioctl, 968 + .prepare_ioctl = verity_prepare_ioctl, 968 969 .iterate_devices = verity_iterate_devices, 969 970 .io_hints = verity_io_hints, 970 971 };
+182 -27
drivers/md/dm.c
··· 24 24 #include <linux/ktime.h> 25 25 #include <linux/elevator.h> /* for rq_end_sector() */ 26 26 #include <linux/blk-mq.h> 27 + #include <linux/pr.h> 27 28 28 29 #include <trace/events/block.h> 29 30 ··· 556 555 return dm_get_geometry(md, geo); 557 556 } 558 557 559 - static int dm_blk_ioctl(struct block_device *bdev, fmode_t mode, 560 - unsigned int cmd, unsigned long arg) 558 + static int dm_get_live_table_for_ioctl(struct mapped_device *md, 559 + struct dm_target **tgt, struct block_device **bdev, 560 + fmode_t *mode, int *srcu_idx) 561 561 { 562 - struct mapped_device *md = bdev->bd_disk->private_data; 563 - int srcu_idx; 564 562 struct dm_table *map; 565 - struct dm_target *tgt; 566 - int r = -ENOTTY; 563 + int r; 567 564 568 565 retry: 569 - map = dm_get_live_table(md, &srcu_idx); 570 - 566 + r = -ENOTTY; 567 + map = dm_get_live_table(md, srcu_idx); 571 568 if (!map || !dm_table_get_size(map)) 572 569 goto out; 573 570 ··· 573 574 if (dm_table_get_num_targets(map) != 1) 574 575 goto out; 575 576 576 - tgt = dm_table_get_target(map, 0); 577 - if (!tgt->type->ioctl) 577 + *tgt = dm_table_get_target(map, 0); 578 + 579 + if (!(*tgt)->type->prepare_ioctl) 578 580 goto out; 579 581 580 582 if (dm_suspended_md(md)) { ··· 583 583 goto out; 584 584 } 585 585 586 - r = tgt->type->ioctl(tgt, cmd, arg); 586 + r = (*tgt)->type->prepare_ioctl(*tgt, bdev, mode); 587 + if (r < 0) 588 + goto out; 589 + 590 + return r; 587 591 588 592 out: 589 - dm_put_live_table(md, srcu_idx); 590 - 593 + dm_put_live_table(md, *srcu_idx); 591 594 if (r == -ENOTCONN) { 592 595 msleep(10); 593 596 goto retry; 594 597 } 598 + return r; 599 + } 595 600 601 + static int dm_blk_ioctl(struct block_device *bdev, fmode_t mode, 602 + unsigned int cmd, unsigned long arg) 603 + { 604 + struct mapped_device *md = bdev->bd_disk->private_data; 605 + struct dm_target *tgt; 606 + int srcu_idx, r; 607 + 608 + r = dm_get_live_table_for_ioctl(md, &tgt, &bdev, &mode, &srcu_idx); 609 + if (r < 0) 610 + return r; 611 + 612 + if (r > 0) { 613 + /* 614 + * Target determined this ioctl is being issued against 615 + * a logical partition of the parent bdev; so extra 616 + * validation is needed. 617 + */ 618 + r = scsi_verify_blk_ioctl(NULL, cmd); 619 + if (r) 620 + goto out; 621 + } 622 + 623 + r = __blkdev_driver_ioctl(bdev, mode, cmd, arg); 624 + out: 625 + dm_put_live_table(md, srcu_idx); 596 626 return r; 597 627 } 598 628 ··· 1764 1734 1765 1735 map = dm_get_live_table(md, &srcu_idx); 1766 1736 1767 - blk_queue_split(q, &bio, q->bio_split); 1768 - 1769 1737 generic_start_io_acct(rw, bio_sectors(bio), &dm_disk(md)->part0); 1770 1738 1771 1739 /* if we're suspended, we have to queue this io for later */ ··· 2226 2198 * This queue is new, so no concurrency on the queue_flags. 2227 2199 */ 2228 2200 queue_flag_clear_unlocked(QUEUE_FLAG_STACKABLE, md->queue); 2201 + 2202 + /* 2203 + * Initialize data that will only be used by a non-blk-mq DM queue 2204 + * - must do so here (in alloc_dev callchain) before queue is used 2205 + */ 2206 + md->queue->queuedata = md; 2207 + md->queue->backing_dev_info.congested_data = md; 2229 2208 } 2230 2209 2231 2210 static void dm_init_old_md_queue(struct mapped_device *md) ··· 2243 2208 /* 2244 2209 * Initialize aspects of queue that aren't relevant for blk-mq 2245 2210 */ 2246 - md->queue->queuedata = md; 2247 2211 md->queue->backing_dev_info.congested_fn = dm_any_congested; 2248 - md->queue->backing_dev_info.congested_data = md; 2249 - 2250 2212 blk_queue_bounce_limit(md->queue, BLK_BOUNCE_ANY); 2251 2213 } 2252 2214 ··· 2253 2221 destroy_workqueue(md->wq); 2254 2222 if (md->kworker_task) 2255 2223 kthread_stop(md->kworker_task); 2256 - if (md->io_pool) 2257 - mempool_destroy(md->io_pool); 2258 - if (md->rq_pool) 2259 - mempool_destroy(md->rq_pool); 2224 + mempool_destroy(md->io_pool); 2225 + mempool_destroy(md->rq_pool); 2260 2226 if (md->bs) 2261 2227 bioset_free(md->bs); 2262 2228 ··· 2789 2759 case DM_TYPE_BIO_BASED: 2790 2760 dm_init_old_md_queue(md); 2791 2761 blk_queue_make_request(md->queue, dm_make_request); 2762 + /* 2763 + * DM handles splitting bios as needed. Free the bio_split bioset 2764 + * since it won't be used (saves 1 process per bio-based DM device). 2765 + */ 2766 + bioset_free(md->queue->bio_split); 2767 + md->queue->bio_split = NULL; 2792 2768 break; 2793 2769 } 2794 2770 ··· 3541 3505 if (!pools) 3542 3506 return; 3543 3507 3544 - if (pools->io_pool) 3545 - mempool_destroy(pools->io_pool); 3546 - 3547 - if (pools->rq_pool) 3548 - mempool_destroy(pools->rq_pool); 3508 + mempool_destroy(pools->io_pool); 3509 + mempool_destroy(pools->rq_pool); 3549 3510 3550 3511 if (pools->bs) 3551 3512 bioset_free(pools->bs); ··· 3550 3517 kfree(pools); 3551 3518 } 3552 3519 3520 + static int dm_pr_register(struct block_device *bdev, u64 old_key, u64 new_key, 3521 + u32 flags) 3522 + { 3523 + struct mapped_device *md = bdev->bd_disk->private_data; 3524 + const struct pr_ops *ops; 3525 + struct dm_target *tgt; 3526 + fmode_t mode; 3527 + int srcu_idx, r; 3528 + 3529 + r = dm_get_live_table_for_ioctl(md, &tgt, &bdev, &mode, &srcu_idx); 3530 + if (r < 0) 3531 + return r; 3532 + 3533 + ops = bdev->bd_disk->fops->pr_ops; 3534 + if (ops && ops->pr_register) 3535 + r = ops->pr_register(bdev, old_key, new_key, flags); 3536 + else 3537 + r = -EOPNOTSUPP; 3538 + 3539 + dm_put_live_table(md, srcu_idx); 3540 + return r; 3541 + } 3542 + 3543 + static int dm_pr_reserve(struct block_device *bdev, u64 key, enum pr_type type, 3544 + u32 flags) 3545 + { 3546 + struct mapped_device *md = bdev->bd_disk->private_data; 3547 + const struct pr_ops *ops; 3548 + struct dm_target *tgt; 3549 + fmode_t mode; 3550 + int srcu_idx, r; 3551 + 3552 + r = dm_get_live_table_for_ioctl(md, &tgt, &bdev, &mode, &srcu_idx); 3553 + if (r < 0) 3554 + return r; 3555 + 3556 + ops = bdev->bd_disk->fops->pr_ops; 3557 + if (ops && ops->pr_reserve) 3558 + r = ops->pr_reserve(bdev, key, type, flags); 3559 + else 3560 + r = -EOPNOTSUPP; 3561 + 3562 + dm_put_live_table(md, srcu_idx); 3563 + return r; 3564 + } 3565 + 3566 + static int dm_pr_release(struct block_device *bdev, u64 key, enum pr_type type) 3567 + { 3568 + struct mapped_device *md = bdev->bd_disk->private_data; 3569 + const struct pr_ops *ops; 3570 + struct dm_target *tgt; 3571 + fmode_t mode; 3572 + int srcu_idx, r; 3573 + 3574 + r = dm_get_live_table_for_ioctl(md, &tgt, &bdev, &mode, &srcu_idx); 3575 + if (r < 0) 3576 + return r; 3577 + 3578 + ops = bdev->bd_disk->fops->pr_ops; 3579 + if (ops && ops->pr_release) 3580 + r = ops->pr_release(bdev, key, type); 3581 + else 3582 + r = -EOPNOTSUPP; 3583 + 3584 + dm_put_live_table(md, srcu_idx); 3585 + return r; 3586 + } 3587 + 3588 + static int dm_pr_preempt(struct block_device *bdev, u64 old_key, u64 new_key, 3589 + enum pr_type type, bool abort) 3590 + { 3591 + struct mapped_device *md = bdev->bd_disk->private_data; 3592 + const struct pr_ops *ops; 3593 + struct dm_target *tgt; 3594 + fmode_t mode; 3595 + int srcu_idx, r; 3596 + 3597 + r = dm_get_live_table_for_ioctl(md, &tgt, &bdev, &mode, &srcu_idx); 3598 + if (r < 0) 3599 + return r; 3600 + 3601 + ops = bdev->bd_disk->fops->pr_ops; 3602 + if (ops && ops->pr_preempt) 3603 + r = ops->pr_preempt(bdev, old_key, new_key, type, abort); 3604 + else 3605 + r = -EOPNOTSUPP; 3606 + 3607 + dm_put_live_table(md, srcu_idx); 3608 + return r; 3609 + } 3610 + 3611 + static int dm_pr_clear(struct block_device *bdev, u64 key) 3612 + { 3613 + struct mapped_device *md = bdev->bd_disk->private_data; 3614 + const struct pr_ops *ops; 3615 + struct dm_target *tgt; 3616 + fmode_t mode; 3617 + int srcu_idx, r; 3618 + 3619 + r = dm_get_live_table_for_ioctl(md, &tgt, &bdev, &mode, &srcu_idx); 3620 + if (r < 0) 3621 + return r; 3622 + 3623 + ops = bdev->bd_disk->fops->pr_ops; 3624 + if (ops && ops->pr_clear) 3625 + r = ops->pr_clear(bdev, key); 3626 + else 3627 + r = -EOPNOTSUPP; 3628 + 3629 + dm_put_live_table(md, srcu_idx); 3630 + return r; 3631 + } 3632 + 3633 + static const struct pr_ops dm_pr_ops = { 3634 + .pr_register = dm_pr_register, 3635 + .pr_reserve = dm_pr_reserve, 3636 + .pr_release = dm_pr_release, 3637 + .pr_preempt = dm_pr_preempt, 3638 + .pr_clear = dm_pr_clear, 3639 + }; 3640 + 3553 3641 static const struct block_device_operations dm_blk_dops = { 3554 3642 .open = dm_blk_open, 3555 3643 .release = dm_blk_close, 3556 3644 .ioctl = dm_blk_ioctl, 3557 3645 .getgeo = dm_blk_getgeo, 3646 + .pr_ops = &dm_pr_ops, 3558 3647 .owner = THIS_MODULE 3559 3648 }; 3560 3649
+2 -2
drivers/md/persistent-data/dm-array.c
··· 233 233 /* 234 234 * Unlocks an array block. 235 235 */ 236 - static int unlock_ablock(struct dm_array_info *info, struct dm_block *block) 236 + static void unlock_ablock(struct dm_array_info *info, struct dm_block *block) 237 237 { 238 - return dm_tm_unlock(info->btree_info.tm, block); 238 + dm_tm_unlock(info->btree_info.tm, block); 239 239 } 240 240 241 241 /*----------------------------------------------------------------*/
+1 -3
drivers/md/persistent-data/dm-block-manager.c
··· 578 578 } 579 579 EXPORT_SYMBOL_GPL(dm_bm_write_lock_zero); 580 580 581 - int dm_bm_unlock(struct dm_block *b) 581 + void dm_bm_unlock(struct dm_block *b) 582 582 { 583 583 struct buffer_aux *aux; 584 584 aux = dm_bufio_get_aux_data(to_buffer(b)); ··· 590 590 bl_up_read(&aux->lock); 591 591 592 592 dm_bufio_release(to_buffer(b)); 593 - 594 - return 0; 595 593 } 596 594 EXPORT_SYMBOL_GPL(dm_bm_unlock); 597 595
+1 -1
drivers/md/persistent-data/dm-block-manager.h
··· 94 94 struct dm_block_validator *v, 95 95 struct dm_block **result); 96 96 97 - int dm_bm_unlock(struct dm_block *b); 97 + void dm_bm_unlock(struct dm_block *b); 98 98 99 99 /* 100 100 * It's a common idiom to have a superblock that should be committed last.
+1 -1
drivers/md/persistent-data/dm-btree-internal.h
··· 52 52 struct dm_btree_value_type *vt); 53 53 54 54 int new_block(struct dm_btree_info *info, struct dm_block **result); 55 - int unlock_block(struct dm_btree_info *info, struct dm_block *b); 55 + void unlock_block(struct dm_btree_info *info, struct dm_block *b); 56 56 57 57 /* 58 58 * Spines keep track of the rolling locks. There are 2 variants, read-only
+9 -27
drivers/md/persistent-data/dm-btree-remove.c
··· 165 165 return 0; 166 166 } 167 167 168 - static int exit_child(struct dm_btree_info *info, struct child *c) 168 + static void exit_child(struct dm_btree_info *info, struct child *c) 169 169 { 170 - return dm_tm_unlock(info->tm, c->block); 170 + dm_tm_unlock(info->tm, c->block); 171 171 } 172 172 173 173 static void shift(struct btree_node *left, struct btree_node *right, int count) ··· 249 249 250 250 __rebalance2(info, parent, &left, &right); 251 251 252 - r = exit_child(info, &left); 253 - if (r) { 254 - exit_child(info, &right); 255 - return r; 256 - } 252 + exit_child(info, &left); 253 + exit_child(info, &right); 257 254 258 - return exit_child(info, &right); 255 + return 0; 259 256 } 260 257 261 258 /* ··· 391 394 392 395 __rebalance3(info, parent, &left, &center, &right); 393 396 394 - r = exit_child(info, &left); 395 - if (r) { 396 - exit_child(info, &center); 397 - exit_child(info, &right); 398 - return r; 399 - } 400 - 401 - r = exit_child(info, &center); 402 - if (r) { 403 - exit_child(info, &right); 404 - return r; 405 - } 406 - 407 - r = exit_child(info, &right); 408 - if (r) 409 - return r; 397 + exit_child(info, &left); 398 + exit_child(info, &center); 399 + exit_child(info, &right); 410 400 411 401 return 0; 412 402 } ··· 417 433 418 434 memcpy(n, dm_block_data(child), 419 435 dm_bm_block_size(dm_tm_get_bm(info->tm))); 420 - r = dm_tm_unlock(info->tm, child); 421 - if (r) 422 - return r; 436 + dm_tm_unlock(info->tm, child); 423 437 424 438 dm_tm_dec(info->tm, dm_block_location(child)); 425 439 return 0;
+6 -14
drivers/md/persistent-data/dm-btree-spine.c
··· 117 117 return dm_tm_new_block(info->tm, &btree_node_validator, result); 118 118 } 119 119 120 - int unlock_block(struct dm_btree_info *info, struct dm_block *b) 120 + void unlock_block(struct dm_btree_info *info, struct dm_block *b) 121 121 { 122 - return dm_tm_unlock(info->tm, b); 122 + dm_tm_unlock(info->tm, b); 123 123 } 124 124 125 125 /*----------------------------------------------------------------*/ ··· 137 137 int r = 0, i; 138 138 139 139 for (i = 0; i < s->count; i++) { 140 - int r2 = unlock_block(s->info, s->nodes[i]); 141 - if (r2 < 0) 142 - r = r2; 140 + unlock_block(s->info, s->nodes[i]); 143 141 } 144 142 145 143 return r; ··· 148 150 int r; 149 151 150 152 if (s->count == 2) { 151 - r = unlock_block(s->info, s->nodes[0]); 152 - if (r < 0) 153 - return r; 153 + unlock_block(s->info, s->nodes[0]); 154 154 s->nodes[0] = s->nodes[1]; 155 155 s->count--; 156 156 } ··· 190 194 int r = 0, i; 191 195 192 196 for (i = 0; i < s->count; i++) { 193 - int r2 = unlock_block(s->info, s->nodes[i]); 194 - if (r2 < 0) 195 - r = r2; 197 + unlock_block(s->info, s->nodes[i]); 196 198 } 197 199 198 200 return r; ··· 202 208 int r; 203 209 204 210 if (s->count == 2) { 205 - r = unlock_block(s->info, s->nodes[0]); 206 - if (r < 0) 207 - return r; 211 + unlock_block(s->info, s->nodes[0]); 208 212 s->nodes[0] = s->nodes[1]; 209 213 s->count--; 210 214 }
+3 -1
drivers/md/persistent-data/dm-btree.c
··· 141 141 n->header.value_size = cpu_to_le32(info->value_type.size); 142 142 143 143 *root = dm_block_location(b); 144 - return unlock_block(info, b); 144 + unlock_block(info, b); 145 + 146 + return 0; 145 147 } 146 148 EXPORT_SYMBOL_GPL(dm_btree_empty); 147 149
+16 -16
drivers/md/persistent-data/dm-space-map-common.c
··· 259 259 260 260 idx.blocknr = cpu_to_le64(dm_block_location(b)); 261 261 262 - r = dm_tm_unlock(ll->tm, b); 263 - if (r < 0) 264 - return r; 262 + dm_tm_unlock(ll->tm, b); 265 263 266 264 idx.nr_free = cpu_to_le32(ll->entries_per_block); 267 265 idx.none_free_before = 0; ··· 291 293 292 294 *result = sm_lookup_bitmap(dm_bitmap_data(blk), b); 293 295 294 - return dm_tm_unlock(ll->tm, blk); 296 + dm_tm_unlock(ll->tm, blk); 297 + 298 + return 0; 295 299 } 296 300 297 301 static int sm_ll_lookup_big_ref_count(struct ll_disk *ll, dm_block_t b, ··· 373 373 return r; 374 374 } 375 375 376 - r = dm_tm_unlock(ll->tm, blk); 377 - if (r < 0) 378 - return r; 376 + dm_tm_unlock(ll->tm, blk); 379 377 380 378 *result = i * ll->entries_per_block + (dm_block_t) position; 381 379 return 0; ··· 427 429 if (ref_count <= 2) { 428 430 sm_set_bitmap(bm_le, bit, ref_count); 429 431 430 - r = dm_tm_unlock(ll->tm, nb); 431 - if (r < 0) 432 - return r; 432 + dm_tm_unlock(ll->tm, nb); 433 433 434 434 if (old > 2) { 435 435 r = dm_btree_remove(&ll->ref_count_info, ··· 441 445 __le32 le_rc = cpu_to_le32(ref_count); 442 446 443 447 sm_set_bitmap(bm_le, bit, 3); 444 - r = dm_tm_unlock(ll->tm, nb); 445 - if (r < 0) 446 - return r; 448 + dm_tm_unlock(ll->tm, nb); 447 449 448 450 __dm_bless_for_disk(&le_rc); 449 451 r = dm_btree_insert(&ll->ref_count_info, ll->ref_count_root, ··· 550 556 memcpy(dm_block_data(b), &ll->mi_le, sizeof(ll->mi_le)); 551 557 ll->bitmap_root = dm_block_location(b); 552 558 553 - return dm_tm_unlock(ll->tm, b); 559 + dm_tm_unlock(ll->tm, b); 560 + 561 + return 0; 554 562 } 555 563 556 564 static int metadata_ll_open(struct ll_disk *ll) ··· 566 570 return r; 567 571 568 572 memcpy(&ll->mi_le, dm_block_data(block), sizeof(ll->mi_le)); 569 - return dm_tm_unlock(ll->tm, block); 573 + dm_tm_unlock(ll->tm, block); 574 + 575 + return 0; 570 576 } 571 577 572 578 static dm_block_t metadata_ll_max_entries(struct ll_disk *ll) ··· 588 590 memcpy(dm_block_data(b), &ll->mi_le, sizeof(ll->mi_le)); 589 591 ll->bitmap_root = dm_block_location(b); 590 592 591 - return dm_tm_unlock(ll->tm, b); 593 + dm_tm_unlock(ll->tm, b); 594 + 595 + return 0; 592 596 } 593 597 594 598 int sm_ll_new_metadata(struct ll_disk *ll, struct dm_transaction_manager *tm)
+2 -2
drivers/md/persistent-data/dm-transaction-manager.c
··· 342 342 } 343 343 EXPORT_SYMBOL_GPL(dm_tm_read_lock); 344 344 345 - int dm_tm_unlock(struct dm_transaction_manager *tm, struct dm_block *b) 345 + void dm_tm_unlock(struct dm_transaction_manager *tm, struct dm_block *b) 346 346 { 347 - return dm_bm_unlock(b); 347 + dm_bm_unlock(b); 348 348 } 349 349 EXPORT_SYMBOL_GPL(dm_tm_unlock); 350 350
+1 -1
drivers/md/persistent-data/dm-transaction-manager.h
··· 94 94 struct dm_block_validator *v, 95 95 struct dm_block **result); 96 96 97 - int dm_tm_unlock(struct dm_transaction_manager *tm, struct dm_block *b); 97 + void dm_tm_unlock(struct dm_transaction_manager *tm, struct dm_block *b); 98 98 99 99 /* 100 100 * Functions for altering the reference count of a block directly.
+3 -3
include/linux/device-mapper.h
··· 79 79 80 80 typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv); 81 81 82 - typedef int (*dm_ioctl_fn) (struct dm_target *ti, unsigned int cmd, 83 - unsigned long arg); 82 + typedef int (*dm_prepare_ioctl_fn) (struct dm_target *ti, 83 + struct block_device **bdev, fmode_t *mode); 84 84 85 85 /* 86 86 * These iteration functions are typically used to check (and combine) ··· 156 156 dm_resume_fn resume; 157 157 dm_status_fn status; 158 158 dm_message_fn message; 159 - dm_ioctl_fn ioctl; 159 + dm_prepare_ioctl_fn prepare_ioctl; 160 160 dm_busy_fn busy; 161 161 dm_iterate_devices_fn iterate_devices; 162 162 dm_io_hints_fn io_hints;
+2 -2
include/uapi/linux/dm-ioctl.h
··· 267 267 #define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl) 268 268 269 269 #define DM_VERSION_MAJOR 4 270 - #define DM_VERSION_MINOR 33 270 + #define DM_VERSION_MINOR 34 271 271 #define DM_VERSION_PATCHLEVEL 0 272 - #define DM_VERSION_EXTRA "-ioctl (2015-8-18)" 272 + #define DM_VERSION_EXTRA "-ioctl (2015-10-28)" 273 273 274 274 /* Status bits */ 275 275 #define DM_READONLY_FLAG (1 << 0) /* In/Out */