super.c (5c2a634cbfaf1971cb6453fe5f86d83585257790) | super.c (a59ff6ccc2bf2e2934b31bbf734f0bc04b5ec78a) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * bcache setup/teardown code, and some metadata io - read a superblock and 4 * figure out what to do with it. 5 * 6 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com> 7 * Copyright 2012 Google, Inc. 8 */ --- 26 unchanged lines hidden (view full) --- 35 36static const char invalid_uuid[] = { 37 0xa0, 0x3e, 0xf8, 0xed, 0x3e, 0xe1, 0xb8, 0x78, 38 0xc8, 0x50, 0xfc, 0x5e, 0xcb, 0x16, 0xcd, 0x99 39}; 40 41static struct kobject *bcache_kobj; 42struct mutex bch_register_lock; | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * bcache setup/teardown code, and some metadata io - read a superblock and 4 * figure out what to do with it. 5 * 6 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com> 7 * Copyright 2012 Google, Inc. 8 */ --- 26 unchanged lines hidden (view full) --- 35 36static const char invalid_uuid[] = { 37 0xa0, 0x3e, 0xf8, 0xed, 0x3e, 0xe1, 0xb8, 0x78, 38 0xc8, 0x50, 0xfc, 0x5e, 0xcb, 0x16, 0xcd, 0x99 39}; 40 41static struct kobject *bcache_kobj; 42struct mutex bch_register_lock; |
43bool bcache_is_reboot; |
|
43LIST_HEAD(bch_cache_sets); 44static LIST_HEAD(uncached_devices); 45 46static int bcache_major; 47static DEFINE_IDA(bcache_device_idx); 48static wait_queue_head_t unregister_wait; 49struct workqueue_struct *bcache_wq; 50struct workqueue_struct *bch_journal_wq; 51 | 44LIST_HEAD(bch_cache_sets); 45static LIST_HEAD(uncached_devices); 46 47static int bcache_major; 48static DEFINE_IDA(bcache_device_idx); 49static wait_queue_head_t unregister_wait; 50struct workqueue_struct *bcache_wq; 51struct workqueue_struct *bch_journal_wq; 52 |
53 |
|
52#define BTREE_MAX_PAGES (256 * 1024 / PAGE_SIZE) 53/* limitation of partitions number on single bcache device */ 54#define BCACHE_MINORS 128 55/* limitation of bcache devices number on single system */ 56#define BCACHE_DEVICE_IDX_MAX ((1U << MINORBITS)/BCACHE_MINORS) 57 58/* Superblock */ 59 --- 2270 unchanged lines hidden (view full) --- 2330 char *path = NULL; 2331 struct cache_sb *sb = NULL; 2332 struct block_device *bdev = NULL; 2333 struct page *sb_page = NULL; 2334 2335 if (!try_module_get(THIS_MODULE)) 2336 return -EBUSY; 2337 | 54#define BTREE_MAX_PAGES (256 * 1024 / PAGE_SIZE) 55/* limitation of partitions number on single bcache device */ 56#define BCACHE_MINORS 128 57/* limitation of bcache devices number on single system */ 58#define BCACHE_DEVICE_IDX_MAX ((1U << MINORBITS)/BCACHE_MINORS) 59 60/* Superblock */ 61 --- 2270 unchanged lines hidden (view full) --- 2332 char *path = NULL; 2333 struct cache_sb *sb = NULL; 2334 struct block_device *bdev = NULL; 2335 struct page *sb_page = NULL; 2336 2337 if (!try_module_get(THIS_MODULE)) 2338 return -EBUSY; 2339 |
2340 /* For latest state of bcache_is_reboot */ 2341 smp_mb(); 2342 if (bcache_is_reboot) 2343 return -EBUSY; 2344 |
|
2338 path = kstrndup(buffer, size, GFP_KERNEL); 2339 if (!path) 2340 goto err; 2341 2342 sb = kmalloc(sizeof(struct cache_sb), GFP_KERNEL); 2343 if (!sb) 2344 goto err; 2345 --- 113 unchanged lines hidden (view full) --- 2459 kfree(pdev); 2460 } 2461 2462 return ret; 2463} 2464 2465static int bcache_reboot(struct notifier_block *n, unsigned long code, void *x) 2466{ | 2345 path = kstrndup(buffer, size, GFP_KERNEL); 2346 if (!path) 2347 goto err; 2348 2349 sb = kmalloc(sizeof(struct cache_sb), GFP_KERNEL); 2350 if (!sb) 2351 goto err; 2352 --- 113 unchanged lines hidden (view full) --- 2466 kfree(pdev); 2467 } 2468 2469 return ret; 2470} 2471 2472static int bcache_reboot(struct notifier_block *n, unsigned long code, void *x) 2473{ |
2474 if (bcache_is_reboot) 2475 return NOTIFY_DONE; 2476 |
|
2467 if (code == SYS_DOWN || 2468 code == SYS_HALT || 2469 code == SYS_POWER_OFF) { 2470 DEFINE_WAIT(wait); 2471 unsigned long start = jiffies; 2472 bool stopped = false; 2473 2474 struct cache_set *c, *tc; 2475 struct cached_dev *dc, *tdc; 2476 2477 mutex_lock(&bch_register_lock); 2478 | 2477 if (code == SYS_DOWN || 2478 code == SYS_HALT || 2479 code == SYS_POWER_OFF) { 2480 DEFINE_WAIT(wait); 2481 unsigned long start = jiffies; 2482 bool stopped = false; 2483 2484 struct cache_set *c, *tc; 2485 struct cached_dev *dc, *tdc; 2486 2487 mutex_lock(&bch_register_lock); 2488 |
2489 if (bcache_is_reboot) 2490 goto out; 2491 2492 /* New registration is rejected since now */ 2493 bcache_is_reboot = true; 2494 /* 2495 * Make registering caller (if there is) on other CPU 2496 * core know bcache_is_reboot set to true earlier 2497 */ 2498 smp_mb(); 2499 |
|
2479 if (list_empty(&bch_cache_sets) && 2480 list_empty(&uncached_devices)) 2481 goto out; 2482 | 2500 if (list_empty(&bch_cache_sets) && 2501 list_empty(&uncached_devices)) 2502 goto out; 2503 |
2504 mutex_unlock(&bch_register_lock); 2505 |
|
2483 pr_info("Stopping all devices:"); 2484 | 2506 pr_info("Stopping all devices:"); 2507 |
2508 /* 2509 * The reason bch_register_lock is not held to call 2510 * bch_cache_set_stop() and bcache_device_stop() is to 2511 * avoid potential deadlock during reboot, because cache 2512 * set or bcache device stopping process will acqurie 2513 * bch_register_lock too. 2514 * 2515 * We are safe here because bcache_is_reboot sets to 2516 * true already, register_bcache() will reject new 2517 * registration now. bcache_is_reboot also makes sure 2518 * bcache_reboot() won't be re-entered on by other thread, 2519 * so there is no race in following list iteration by 2520 * list_for_each_entry_safe(). 2521 */ |
|
2485 list_for_each_entry_safe(c, tc, &bch_cache_sets, list) 2486 bch_cache_set_stop(c); 2487 2488 list_for_each_entry_safe(dc, tdc, &uncached_devices, list) 2489 bcache_device_stop(&dc->disk); 2490 | 2522 list_for_each_entry_safe(c, tc, &bch_cache_sets, list) 2523 bch_cache_set_stop(c); 2524 2525 list_for_each_entry_safe(dc, tdc, &uncached_devices, list) 2526 bcache_device_stop(&dc->disk); 2527 |
2491 mutex_unlock(&bch_register_lock); | |
2492 2493 /* 2494 * Give an early chance for other kthreads and 2495 * kworkers to stop themselves 2496 */ 2497 schedule(); 2498 2499 /* What's a condition variable? */ --- 111 unchanged lines hidden (view full) --- 2611 2612 if (bch_request_init() || 2613 sysfs_create_files(bcache_kobj, files)) 2614 goto err; 2615 2616 bch_debug_init(); 2617 closure_debug_init(); 2618 | 2528 2529 /* 2530 * Give an early chance for other kthreads and 2531 * kworkers to stop themselves 2532 */ 2533 schedule(); 2534 2535 /* What's a condition variable? */ --- 111 unchanged lines hidden (view full) --- 2647 2648 if (bch_request_init() || 2649 sysfs_create_files(bcache_kobj, files)) 2650 goto err; 2651 2652 bch_debug_init(); 2653 closure_debug_init(); 2654 |
2655 bcache_is_reboot = false; 2656 |
|
2619 return 0; 2620err: 2621 bcache_exit(); 2622 return -ENOMEM; 2623} 2624 2625/* 2626 * Module hooks --- 13 unchanged lines hidden --- | 2657 return 0; 2658err: 2659 bcache_exit(); 2660 return -ENOMEM; 2661} 2662 2663/* 2664 * Module hooks --- 13 unchanged lines hidden --- |