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

Configure Feed

Select the types of activity you want to include in your feed.

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

Pull device mapper fixes from Mike Snitzer:

- fix a particularly nasty DM core bug in a 4.15 refcount_t conversion.

- fix various targets to dm_register_target after module __init
resources created; otherwise racing lvm2 commands could result in a
NULL pointer during initialization of associated DM kernel module.

- fix regression in bio-based DM multipath queue_if_no_path handling.

- fix DM bufio's shrinker to reclaim more than one buffer per scan.

* tag 'for-4.15/dm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm:
dm bufio: fix shrinker scans when (nr_to_scan < retain_target)
dm mpath: fix bio-based multipath queue_if_no_path handling
dm: fix various targets to dm_register_target after module __init resources created
dm table: fix regression from improper dm_dev_internal.count refcount_t conversion

+100 -62
+6 -2
drivers/md/dm-bufio.c
··· 1611 1611 int l; 1612 1612 struct dm_buffer *b, *tmp; 1613 1613 unsigned long freed = 0; 1614 - unsigned long count = nr_to_scan; 1614 + unsigned long count = c->n_buffers[LIST_CLEAN] + 1615 + c->n_buffers[LIST_DIRTY]; 1615 1616 unsigned long retain_target = get_retain_buffers(c); 1616 1617 1617 1618 for (l = 0; l < LIST_SIZE; l++) { ··· 1648 1647 dm_bufio_shrink_count(struct shrinker *shrink, struct shrink_control *sc) 1649 1648 { 1650 1649 struct dm_bufio_client *c = container_of(shrink, struct dm_bufio_client, shrinker); 1650 + unsigned long count = READ_ONCE(c->n_buffers[LIST_CLEAN]) + 1651 + READ_ONCE(c->n_buffers[LIST_DIRTY]); 1652 + unsigned long retain_target = get_retain_buffers(c); 1651 1653 1652 - return READ_ONCE(c->n_buffers[LIST_CLEAN]) + READ_ONCE(c->n_buffers[LIST_DIRTY]); 1654 + return (count < retain_target) ? 0 : (count - retain_target); 1653 1655 } 1654 1656 1655 1657 /*
+6 -6
drivers/md/dm-cache-target.c
··· 3472 3472 { 3473 3473 int r; 3474 3474 3475 - r = dm_register_target(&cache_target); 3476 - if (r) { 3477 - DMERR("cache target registration failed: %d", r); 3478 - return r; 3479 - } 3480 - 3481 3475 migration_cache = KMEM_CACHE(dm_cache_migration, 0); 3482 3476 if (!migration_cache) { 3483 3477 dm_unregister_target(&cache_target); 3484 3478 return -ENOMEM; 3479 + } 3480 + 3481 + r = dm_register_target(&cache_target); 3482 + if (r) { 3483 + DMERR("cache target registration failed: %d", r); 3484 + return r; 3485 3485 } 3486 3486 3487 3487 return 0;
+51 -16
drivers/md/dm-mpath.c
··· 458 458 } while (0) 459 459 460 460 /* 461 + * Check whether bios must be queued in the device-mapper core rather 462 + * than here in the target. 463 + * 464 + * If MPATHF_QUEUE_IF_NO_PATH and MPATHF_SAVED_QUEUE_IF_NO_PATH hold 465 + * the same value then we are not between multipath_presuspend() 466 + * and multipath_resume() calls and we have no need to check 467 + * for the DMF_NOFLUSH_SUSPENDING flag. 468 + */ 469 + static bool __must_push_back(struct multipath *m, unsigned long flags) 470 + { 471 + return ((test_bit(MPATHF_QUEUE_IF_NO_PATH, &flags) != 472 + test_bit(MPATHF_SAVED_QUEUE_IF_NO_PATH, &flags)) && 473 + dm_noflush_suspending(m->ti)); 474 + } 475 + 476 + /* 477 + * Following functions use READ_ONCE to get atomic access to 478 + * all m->flags to avoid taking spinlock 479 + */ 480 + static bool must_push_back_rq(struct multipath *m) 481 + { 482 + unsigned long flags = READ_ONCE(m->flags); 483 + return test_bit(MPATHF_QUEUE_IF_NO_PATH, &flags) || __must_push_back(m, flags); 484 + } 485 + 486 + static bool must_push_back_bio(struct multipath *m) 487 + { 488 + unsigned long flags = READ_ONCE(m->flags); 489 + return __must_push_back(m, flags); 490 + } 491 + 492 + /* 461 493 * Map cloned requests (request-based multipath) 462 494 */ 463 495 static int multipath_clone_and_map(struct dm_target *ti, struct request *rq, ··· 510 478 pgpath = choose_pgpath(m, nr_bytes); 511 479 512 480 if (!pgpath) { 513 - if (test_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags)) 481 + if (must_push_back_rq(m)) 514 482 return DM_MAPIO_DELAY_REQUEUE; 515 483 dm_report_EIO(m); /* Failed */ 516 484 return DM_MAPIO_KILL; ··· 585 553 } 586 554 587 555 if (!pgpath) { 588 - if (test_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags)) 556 + if (must_push_back_bio(m)) 589 557 return DM_MAPIO_REQUEUE; 590 558 dm_report_EIO(m); 591 559 return DM_MAPIO_KILL; ··· 683 651 assign_bit(MPATHF_SAVED_QUEUE_IF_NO_PATH, &m->flags, 684 652 (save_old_value && test_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags)) || 685 653 (!save_old_value && queue_if_no_path)); 686 - assign_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags, 687 - queue_if_no_path || dm_noflush_suspending(m->ti)); 654 + assign_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags, queue_if_no_path); 688 655 spin_unlock_irqrestore(&m->lock, flags); 689 656 690 657 if (!queue_if_no_path) { ··· 1517 1486 fail_path(pgpath); 1518 1487 1519 1488 if (atomic_read(&m->nr_valid_paths) == 0 && 1520 - !test_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags)) { 1489 + !must_push_back_rq(m)) { 1521 1490 if (error == BLK_STS_IOERR) 1522 1491 dm_report_EIO(m); 1523 1492 /* complete with the original error */ ··· 1552 1521 1553 1522 if (atomic_read(&m->nr_valid_paths) == 0 && 1554 1523 !test_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags)) { 1555 - dm_report_EIO(m); 1556 - *error = BLK_STS_IOERR; 1524 + if (must_push_back_bio(m)) { 1525 + r = DM_ENDIO_REQUEUE; 1526 + } else { 1527 + dm_report_EIO(m); 1528 + *error = BLK_STS_IOERR; 1529 + } 1557 1530 goto done; 1558 1531 } 1559 1532 ··· 1992 1957 { 1993 1958 int r; 1994 1959 1995 - r = dm_register_target(&multipath_target); 1996 - if (r < 0) { 1997 - DMERR("request-based register failed %d", r); 1998 - r = -EINVAL; 1999 - goto bad_register_target; 2000 - } 2001 - 2002 1960 kmultipathd = alloc_workqueue("kmpathd", WQ_MEM_RECLAIM, 0); 2003 1961 if (!kmultipathd) { 2004 1962 DMERR("failed to create workqueue kmpathd"); ··· 2013 1985 goto bad_alloc_kmpath_handlerd; 2014 1986 } 2015 1987 1988 + r = dm_register_target(&multipath_target); 1989 + if (r < 0) { 1990 + DMERR("request-based register failed %d", r); 1991 + r = -EINVAL; 1992 + goto bad_register_target; 1993 + } 1994 + 2016 1995 return 0; 2017 1996 1997 + bad_register_target: 1998 + destroy_workqueue(kmpath_handlerd); 2018 1999 bad_alloc_kmpath_handlerd: 2019 2000 destroy_workqueue(kmultipathd); 2020 2001 bad_alloc_kmultipathd: 2021 - dm_unregister_target(&multipath_target); 2022 - bad_register_target: 2023 2002 return r; 2024 2003 } 2025 2004
+24 -24
drivers/md/dm-snap.c
··· 2411 2411 return r; 2412 2412 } 2413 2413 2414 - r = dm_register_target(&snapshot_target); 2415 - if (r < 0) { 2416 - DMERR("snapshot target register failed %d", r); 2417 - goto bad_register_snapshot_target; 2418 - } 2419 - 2420 - r = dm_register_target(&origin_target); 2421 - if (r < 0) { 2422 - DMERR("Origin target register failed %d", r); 2423 - goto bad_register_origin_target; 2424 - } 2425 - 2426 - r = dm_register_target(&merge_target); 2427 - if (r < 0) { 2428 - DMERR("Merge target register failed %d", r); 2429 - goto bad_register_merge_target; 2430 - } 2431 - 2432 2414 r = init_origin_hash(); 2433 2415 if (r) { 2434 2416 DMERR("init_origin_hash failed."); ··· 2431 2449 goto bad_pending_cache; 2432 2450 } 2433 2451 2452 + r = dm_register_target(&snapshot_target); 2453 + if (r < 0) { 2454 + DMERR("snapshot target register failed %d", r); 2455 + goto bad_register_snapshot_target; 2456 + } 2457 + 2458 + r = dm_register_target(&origin_target); 2459 + if (r < 0) { 2460 + DMERR("Origin target register failed %d", r); 2461 + goto bad_register_origin_target; 2462 + } 2463 + 2464 + r = dm_register_target(&merge_target); 2465 + if (r < 0) { 2466 + DMERR("Merge target register failed %d", r); 2467 + goto bad_register_merge_target; 2468 + } 2469 + 2434 2470 return 0; 2435 2471 2436 - bad_pending_cache: 2437 - kmem_cache_destroy(exception_cache); 2438 - bad_exception_cache: 2439 - exit_origin_hash(); 2440 - bad_origin_hash: 2441 - dm_unregister_target(&merge_target); 2442 2472 bad_register_merge_target: 2443 2473 dm_unregister_target(&origin_target); 2444 2474 bad_register_origin_target: 2445 2475 dm_unregister_target(&snapshot_target); 2446 2476 bad_register_snapshot_target: 2477 + kmem_cache_destroy(pending_cache); 2478 + bad_pending_cache: 2479 + kmem_cache_destroy(exception_cache); 2480 + bad_exception_cache: 2481 + exit_origin_hash(); 2482 + bad_origin_hash: 2447 2483 dm_exception_store_exit(); 2448 2484 2449 2485 return r;
+3 -2
drivers/md/dm-table.c
··· 453 453 454 454 refcount_set(&dd->count, 1); 455 455 list_add(&dd->list, &t->devices); 456 + goto out; 456 457 457 458 } else if (dd->dm_dev->mode != (mode | dd->dm_dev->mode)) { 458 459 r = upgrade_mode(dd, mode, t->md); 459 460 if (r) 460 461 return r; 461 - refcount_inc(&dd->count); 462 462 } 463 - 463 + refcount_inc(&dd->count); 464 + out: 464 465 *result = dd->dm_dev; 465 466 return 0; 466 467 }
+10 -12
drivers/md/dm-thin.c
··· 4355 4355 4356 4356 static int __init dm_thin_init(void) 4357 4357 { 4358 - int r; 4358 + int r = -ENOMEM; 4359 4359 4360 4360 pool_table_init(); 4361 4361 4362 + _new_mapping_cache = KMEM_CACHE(dm_thin_new_mapping, 0); 4363 + if (!_new_mapping_cache) 4364 + return r; 4365 + 4362 4366 r = dm_register_target(&thin_target); 4363 4367 if (r) 4364 - return r; 4368 + goto bad_new_mapping_cache; 4365 4369 4366 4370 r = dm_register_target(&pool_target); 4367 4371 if (r) 4368 - goto bad_pool_target; 4369 - 4370 - r = -ENOMEM; 4371 - 4372 - _new_mapping_cache = KMEM_CACHE(dm_thin_new_mapping, 0); 4373 - if (!_new_mapping_cache) 4374 - goto bad_new_mapping_cache; 4372 + goto bad_thin_target; 4375 4373 4376 4374 return 0; 4377 4375 4378 - bad_new_mapping_cache: 4379 - dm_unregister_target(&pool_target); 4380 - bad_pool_target: 4376 + bad_thin_target: 4381 4377 dm_unregister_target(&thin_target); 4378 + bad_new_mapping_cache: 4379 + kmem_cache_destroy(_new_mapping_cache); 4382 4380 4383 4381 return r; 4384 4382 }