super.c (1ac731c529cd4d6adbce134754b51ff7d822b145) | super.c (09bdafb89a56a267c070fdb96d385934c14d2735) |
---|---|
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 */ --- 718 unchanged lines hidden (view full) --- 727 728 ret = 0; 729out: 730 return ret; 731} 732 733/* Bcache device */ 734 | 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 */ --- 718 unchanged lines hidden (view full) --- 727 728 ret = 0; 729out: 730 return ret; 731} 732 733/* Bcache device */ 734 |
735static int open_dev(struct block_device *b, fmode_t mode) | 735static int open_dev(struct gendisk *disk, blk_mode_t mode) |
736{ | 736{ |
737 struct bcache_device *d = b->bd_disk->private_data; | 737 struct bcache_device *d = disk->private_data; |
738 739 if (test_bit(BCACHE_DEV_CLOSING, &d->flags)) 740 return -ENXIO; 741 742 closure_get(&d->cl); 743 return 0; 744} 745 | 738 739 if (test_bit(BCACHE_DEV_CLOSING, &d->flags)) 740 return -ENXIO; 741 742 closure_get(&d->cl); 743 return 0; 744} 745 |
746static void release_dev(struct gendisk *b, fmode_t mode) | 746static void release_dev(struct gendisk *b) |
747{ 748 struct bcache_device *d = b->private_data; 749 750 closure_put(&d->cl); 751} 752 | 747{ 748 struct bcache_device *d = b->private_data; 749 750 closure_put(&d->cl); 751} 752 |
753static int ioctl_dev(struct block_device *b, fmode_t mode, | 753static int ioctl_dev(struct block_device *b, blk_mode_t mode, |
754 unsigned int cmd, unsigned long arg) 755{ 756 struct bcache_device *d = b->bd_disk->private_data; 757 758 return d->ioctl(d, mode, cmd, arg); 759} 760 761static const struct block_device_operations bcache_cached_ops = { --- 138 unchanged lines hidden (view full) --- 900 struct request_queue *q; 901 const size_t max_stripes = min_t(size_t, INT_MAX, 902 SIZE_MAX / sizeof(atomic_t)); 903 uint64_t n; 904 int idx; 905 906 if (!d->stripe_size) 907 d->stripe_size = 1 << 31; | 754 unsigned int cmd, unsigned long arg) 755{ 756 struct bcache_device *d = b->bd_disk->private_data; 757 758 return d->ioctl(d, mode, cmd, arg); 759} 760 761static const struct block_device_operations bcache_cached_ops = { --- 138 unchanged lines hidden (view full) --- 900 struct request_queue *q; 901 const size_t max_stripes = min_t(size_t, INT_MAX, 902 SIZE_MAX / sizeof(atomic_t)); 903 uint64_t n; 904 int idx; 905 906 if (!d->stripe_size) 907 d->stripe_size = 1 << 31; |
908 else if (d->stripe_size < BCH_MIN_STRIPE_SZ) 909 d->stripe_size = roundup(BCH_MIN_STRIPE_SZ, d->stripe_size); |
|
908 909 n = DIV_ROUND_UP_ULL(sectors, d->stripe_size); 910 if (!n || n > max_stripes) { 911 pr_err("nr_stripes too large or invalid: %llu (start sector beyond end of disk?)\n", 912 n); 913 return -ENOMEM; 914 } 915 d->nr_stripes = n; --- 448 unchanged lines hidden (view full) --- 1364 list_del(&dc->list); 1365 1366 mutex_unlock(&bch_register_lock); 1367 1368 if (dc->sb_disk) 1369 put_page(virt_to_page(dc->sb_disk)); 1370 1371 if (!IS_ERR_OR_NULL(dc->bdev)) | 910 911 n = DIV_ROUND_UP_ULL(sectors, d->stripe_size); 912 if (!n || n > max_stripes) { 913 pr_err("nr_stripes too large or invalid: %llu (start sector beyond end of disk?)\n", 914 n); 915 return -ENOMEM; 916 } 917 d->nr_stripes = n; --- 448 unchanged lines hidden (view full) --- 1366 list_del(&dc->list); 1367 1368 mutex_unlock(&bch_register_lock); 1369 1370 if (dc->sb_disk) 1371 put_page(virt_to_page(dc->sb_disk)); 1372 1373 if (!IS_ERR_OR_NULL(dc->bdev)) |
1372 blkdev_put(dc->bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); | 1374 blkdev_put(dc->bdev, dc); |
1373 1374 wake_up(&unregister_wait); 1375 1376 kobject_put(&dc->disk.kobj); 1377} 1378 1379static void cached_dev_flush(struct closure *cl) 1380{ --- 67 unchanged lines hidden (view full) --- 1448 struct cached_dev *dc) 1449{ 1450 const char *err = "cannot allocate memory"; 1451 struct cache_set *c; 1452 int ret = -ENOMEM; 1453 1454 memcpy(&dc->sb, sb, sizeof(struct cache_sb)); 1455 dc->bdev = bdev; | 1375 1376 wake_up(&unregister_wait); 1377 1378 kobject_put(&dc->disk.kobj); 1379} 1380 1381static void cached_dev_flush(struct closure *cl) 1382{ --- 67 unchanged lines hidden (view full) --- 1450 struct cached_dev *dc) 1451{ 1452 const char *err = "cannot allocate memory"; 1453 struct cache_set *c; 1454 int ret = -ENOMEM; 1455 1456 memcpy(&dc->sb, sb, sizeof(struct cache_sb)); 1457 dc->bdev = bdev; |
1456 dc->bdev->bd_holder = dc; | |
1457 dc->sb_disk = sb_disk; 1458 1459 if (cached_dev_init(dc, sb->block_size << 9)) 1460 goto err; 1461 1462 err = "error creating kobject"; 1463 if (kobject_add(&dc->disk.kobj, bdev_kobj(bdev), "bcache")) 1464 goto err; --- 253 unchanged lines hidden (view full) --- 1718 bch_cache_accounting_destroy(&c->accounting); 1719 1720 kobject_put(&c->internal); 1721 kobject_del(&c->kobj); 1722 1723 if (!IS_ERR_OR_NULL(c->gc_thread)) 1724 kthread_stop(c->gc_thread); 1725 | 1458 dc->sb_disk = sb_disk; 1459 1460 if (cached_dev_init(dc, sb->block_size << 9)) 1461 goto err; 1462 1463 err = "error creating kobject"; 1464 if (kobject_add(&dc->disk.kobj, bdev_kobj(bdev), "bcache")) 1465 goto err; --- 253 unchanged lines hidden (view full) --- 1719 bch_cache_accounting_destroy(&c->accounting); 1720 1721 kobject_put(&c->internal); 1722 kobject_del(&c->kobj); 1723 1724 if (!IS_ERR_OR_NULL(c->gc_thread)) 1725 kthread_stop(c->gc_thread); 1726 |
1726 if (!IS_ERR_OR_NULL(c->root)) | 1727 if (!IS_ERR(c->root)) |
1727 list_add(&c->root->list, &c->btree_cache); 1728 1729 /* 1730 * Avoid flushing cached nodes if cache set is retiring 1731 * due to too many I/O errors detected. 1732 */ 1733 if (!test_bit(CACHE_SET_IO_DISABLE, &c->flags)) 1734 list_for_each_entry(b, &c->btree_cache, list) { --- 347 unchanged lines hidden (view full) --- 2082 mutex_unlock(&c->bucket_lock); 2083 2084 err = "cannot allocate new UUID bucket"; 2085 if (__uuid_write(c)) 2086 goto err; 2087 2088 err = "cannot allocate new btree root"; 2089 c->root = __bch_btree_node_alloc(c, NULL, 0, true, NULL); | 1728 list_add(&c->root->list, &c->btree_cache); 1729 1730 /* 1731 * Avoid flushing cached nodes if cache set is retiring 1732 * due to too many I/O errors detected. 1733 */ 1734 if (!test_bit(CACHE_SET_IO_DISABLE, &c->flags)) 1735 list_for_each_entry(b, &c->btree_cache, list) { --- 347 unchanged lines hidden (view full) --- 2083 mutex_unlock(&c->bucket_lock); 2084 2085 err = "cannot allocate new UUID bucket"; 2086 if (__uuid_write(c)) 2087 goto err; 2088 2089 err = "cannot allocate new btree root"; 2090 c->root = __bch_btree_node_alloc(c, NULL, 0, true, NULL); |
2090 if (IS_ERR_OR_NULL(c->root)) | 2091 if (IS_ERR(c->root)) |
2091 goto err; 2092 2093 mutex_lock(&c->root->write_lock); 2094 bkey_copy_key(&c->root->key, &MAX_KEY); 2095 bch_btree_node_write(c->root, &cl); 2096 mutex_unlock(&c->root->write_lock); 2097 2098 bch_btree_set_root(c->root); --- 114 unchanged lines hidden (view full) --- 2213 2214 for (i = 0; i < RESERVE_NR; i++) 2215 free_fifo(&ca->free[i]); 2216 2217 if (ca->sb_disk) 2218 put_page(virt_to_page(ca->sb_disk)); 2219 2220 if (!IS_ERR_OR_NULL(ca->bdev)) | 2092 goto err; 2093 2094 mutex_lock(&c->root->write_lock); 2095 bkey_copy_key(&c->root->key, &MAX_KEY); 2096 bch_btree_node_write(c->root, &cl); 2097 mutex_unlock(&c->root->write_lock); 2098 2099 bch_btree_set_root(c->root); --- 114 unchanged lines hidden (view full) --- 2214 2215 for (i = 0; i < RESERVE_NR; i++) 2216 free_fifo(&ca->free[i]); 2217 2218 if (ca->sb_disk) 2219 put_page(virt_to_page(ca->sb_disk)); 2220 2221 if (!IS_ERR_OR_NULL(ca->bdev)) |
2221 blkdev_put(ca->bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); | 2222 blkdev_put(ca->bdev, ca); |
2222 2223 kfree(ca); 2224 module_put(THIS_MODULE); 2225} 2226 2227static int cache_alloc(struct cache *ca) 2228{ 2229 size_t free; --- 110 unchanged lines hidden (view full) --- 2340static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk, 2341 struct block_device *bdev, struct cache *ca) 2342{ 2343 const char *err = NULL; /* must be set for any error case */ 2344 int ret = 0; 2345 2346 memcpy(&ca->sb, sb, sizeof(struct cache_sb)); 2347 ca->bdev = bdev; | 2223 2224 kfree(ca); 2225 module_put(THIS_MODULE); 2226} 2227 2228static int cache_alloc(struct cache *ca) 2229{ 2230 size_t free; --- 110 unchanged lines hidden (view full) --- 2341static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk, 2342 struct block_device *bdev, struct cache *ca) 2343{ 2344 const char *err = NULL; /* must be set for any error case */ 2345 int ret = 0; 2346 2347 memcpy(&ca->sb, sb, sizeof(struct cache_sb)); 2348 ca->bdev = bdev; |
2348 ca->bdev->bd_holder = ca; | |
2349 ca->sb_disk = sb_disk; 2350 2351 if (bdev_max_discard_sectors((bdev))) 2352 ca->discard = CACHE_DISCARD(&ca->sb); 2353 2354 ret = cache_alloc(ca); 2355 if (ret != 0) { 2356 /* 2357 * If we failed here, it means ca->kobj is not initialized yet, 2358 * kobject_put() won't be called and there is no chance to 2359 * call blkdev_put() to bdev in bch_cache_release(). So we 2360 * explicitly call blkdev_put() here. 2361 */ | 2349 ca->sb_disk = sb_disk; 2350 2351 if (bdev_max_discard_sectors((bdev))) 2352 ca->discard = CACHE_DISCARD(&ca->sb); 2353 2354 ret = cache_alloc(ca); 2355 if (ret != 0) { 2356 /* 2357 * If we failed here, it means ca->kobj is not initialized yet, 2358 * kobject_put() won't be called and there is no chance to 2359 * call blkdev_put() to bdev in bch_cache_release(). So we 2360 * explicitly call blkdev_put() here. 2361 */ |
2362 blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); | 2362 blkdev_put(bdev, ca); |
2363 if (ret == -ENOMEM) 2364 err = "cache_alloc(): -ENOMEM"; 2365 else if (ret == -EPERM) 2366 err = "cache_alloc(): cache device is too small"; 2367 else 2368 err = "cache_alloc(): unknown error"; 2369 goto err; 2370 } --- 72 unchanged lines hidden (view full) --- 2443} 2444 2445struct async_reg_args { 2446 struct delayed_work reg_work; 2447 char *path; 2448 struct cache_sb *sb; 2449 struct cache_sb_disk *sb_disk; 2450 struct block_device *bdev; | 2363 if (ret == -ENOMEM) 2364 err = "cache_alloc(): -ENOMEM"; 2365 else if (ret == -EPERM) 2366 err = "cache_alloc(): cache device is too small"; 2367 else 2368 err = "cache_alloc(): unknown error"; 2369 goto err; 2370 } --- 72 unchanged lines hidden (view full) --- 2443} 2444 2445struct async_reg_args { 2446 struct delayed_work reg_work; 2447 char *path; 2448 struct cache_sb *sb; 2449 struct cache_sb_disk *sb_disk; 2450 struct block_device *bdev; |
2451 void *holder; |
|
2451}; 2452 2453static void register_bdev_worker(struct work_struct *work) 2454{ 2455 int fail = false; 2456 struct async_reg_args *args = 2457 container_of(work, struct async_reg_args, reg_work.work); | 2452}; 2453 2454static void register_bdev_worker(struct work_struct *work) 2455{ 2456 int fail = false; 2457 struct async_reg_args *args = 2458 container_of(work, struct async_reg_args, reg_work.work); |
2458 struct cached_dev *dc; | |
2459 | 2459 |
2460 dc = kzalloc(sizeof(*dc), GFP_KERNEL); 2461 if (!dc) { 2462 fail = true; 2463 put_page(virt_to_page(args->sb_disk)); 2464 blkdev_put(args->bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL); 2465 goto out; 2466 } 2467 | |
2468 mutex_lock(&bch_register_lock); | 2460 mutex_lock(&bch_register_lock); |
2469 if (register_bdev(args->sb, args->sb_disk, args->bdev, dc) < 0) | 2461 if (register_bdev(args->sb, args->sb_disk, args->bdev, args->holder) 2462 < 0) |
2470 fail = true; 2471 mutex_unlock(&bch_register_lock); 2472 | 2463 fail = true; 2464 mutex_unlock(&bch_register_lock); 2465 |
2473out: | |
2474 if (fail) 2475 pr_info("error %s: fail to register backing device\n", 2476 args->path); 2477 kfree(args->sb); 2478 kfree(args->path); 2479 kfree(args); 2480 module_put(THIS_MODULE); 2481} 2482 2483static void register_cache_worker(struct work_struct *work) 2484{ 2485 int fail = false; 2486 struct async_reg_args *args = 2487 container_of(work, struct async_reg_args, reg_work.work); | 2466 if (fail) 2467 pr_info("error %s: fail to register backing device\n", 2468 args->path); 2469 kfree(args->sb); 2470 kfree(args->path); 2471 kfree(args); 2472 module_put(THIS_MODULE); 2473} 2474 2475static void register_cache_worker(struct work_struct *work) 2476{ 2477 int fail = false; 2478 struct async_reg_args *args = 2479 container_of(work, struct async_reg_args, reg_work.work); |
2488 struct cache *ca; | |
2489 | 2480 |
2490 ca = kzalloc(sizeof(*ca), GFP_KERNEL); 2491 if (!ca) { 2492 fail = true; 2493 put_page(virt_to_page(args->sb_disk)); 2494 blkdev_put(args->bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL); 2495 goto out; 2496 } 2497 | |
2498 /* blkdev_put() will be called in bch_cache_release() */ | 2481 /* blkdev_put() will be called in bch_cache_release() */ |
2499 if (register_cache(args->sb, args->sb_disk, args->bdev, ca) != 0) | 2482 if (register_cache(args->sb, args->sb_disk, args->bdev, args->holder)) |
2500 fail = true; 2501 | 2483 fail = true; 2484 |
2502out: | |
2503 if (fail) 2504 pr_info("error %s: fail to register cache device\n", 2505 args->path); 2506 kfree(args->sb); 2507 kfree(args->path); 2508 kfree(args); 2509 module_put(THIS_MODULE); 2510} --- 4 unchanged lines hidden (view full) --- 2515 INIT_DELAYED_WORK(&args->reg_work, register_bdev_worker); 2516 else 2517 INIT_DELAYED_WORK(&args->reg_work, register_cache_worker); 2518 2519 /* 10 jiffies is enough for a delay */ 2520 queue_delayed_work(system_wq, &args->reg_work, 10); 2521} 2522 | 2485 if (fail) 2486 pr_info("error %s: fail to register cache device\n", 2487 args->path); 2488 kfree(args->sb); 2489 kfree(args->path); 2490 kfree(args); 2491 module_put(THIS_MODULE); 2492} --- 4 unchanged lines hidden (view full) --- 2497 INIT_DELAYED_WORK(&args->reg_work, register_bdev_worker); 2498 else 2499 INIT_DELAYED_WORK(&args->reg_work, register_cache_worker); 2500 2501 /* 10 jiffies is enough for a delay */ 2502 queue_delayed_work(system_wq, &args->reg_work, 10); 2503} 2504 |
2505static void *alloc_holder_object(struct cache_sb *sb) 2506{ 2507 if (SB_IS_BDEV(sb)) 2508 return kzalloc(sizeof(struct cached_dev), GFP_KERNEL); 2509 return kzalloc(sizeof(struct cache), GFP_KERNEL); 2510} 2511 |
|
2523static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, 2524 const char *buffer, size_t size) 2525{ 2526 const char *err; 2527 char *path = NULL; 2528 struct cache_sb *sb; 2529 struct cache_sb_disk *sb_disk; | 2512static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, 2513 const char *buffer, size_t size) 2514{ 2515 const char *err; 2516 char *path = NULL; 2517 struct cache_sb *sb; 2518 struct cache_sb_disk *sb_disk; |
2530 struct block_device *bdev; | 2519 struct block_device *bdev, *bdev2; 2520 void *holder = NULL; |
2531 ssize_t ret; 2532 bool async_registration = false; | 2521 ssize_t ret; 2522 bool async_registration = false; |
2523 bool quiet = false; |
|
2533 2534#ifdef CONFIG_BCACHE_ASYNC_REGISTRATION 2535 async_registration = true; 2536#endif 2537 2538 ret = -EBUSY; 2539 err = "failed to reference bcache module"; 2540 if (!try_module_get(THIS_MODULE)) --- 12 unchanged lines hidden (view full) --- 2553 goto out_module_put; 2554 2555 sb = kmalloc(sizeof(struct cache_sb), GFP_KERNEL); 2556 if (!sb) 2557 goto out_free_path; 2558 2559 ret = -EINVAL; 2560 err = "failed to open device"; | 2524 2525#ifdef CONFIG_BCACHE_ASYNC_REGISTRATION 2526 async_registration = true; 2527#endif 2528 2529 ret = -EBUSY; 2530 err = "failed to reference bcache module"; 2531 if (!try_module_get(THIS_MODULE)) --- 12 unchanged lines hidden (view full) --- 2544 goto out_module_put; 2545 2546 sb = kmalloc(sizeof(struct cache_sb), GFP_KERNEL); 2547 if (!sb) 2548 goto out_free_path; 2549 2550 ret = -EINVAL; 2551 err = "failed to open device"; |
2561 bdev = blkdev_get_by_path(strim(path), 2562 FMODE_READ|FMODE_WRITE|FMODE_EXCL, 2563 sb); | 2552 bdev = blkdev_get_by_path(strim(path), BLK_OPEN_READ, NULL, NULL); 2553 if (IS_ERR(bdev)) 2554 goto out_free_sb; 2555 2556 err = "failed to set blocksize"; 2557 if (set_blocksize(bdev, 4096)) 2558 goto out_blkdev_put; 2559 2560 err = read_super(sb, bdev, &sb_disk); 2561 if (err) 2562 goto out_blkdev_put; 2563 2564 holder = alloc_holder_object(sb); 2565 if (!holder) { 2566 ret = -ENOMEM; 2567 err = "cannot allocate memory"; 2568 goto out_put_sb_page; 2569 } 2570 2571 /* Now reopen in exclusive mode with proper holder */ 2572 bdev2 = blkdev_get_by_dev(bdev->bd_dev, BLK_OPEN_READ | BLK_OPEN_WRITE, 2573 holder, NULL); 2574 blkdev_put(bdev, NULL); 2575 bdev = bdev2; |
2564 if (IS_ERR(bdev)) { | 2576 if (IS_ERR(bdev)) { |
2565 if (bdev == ERR_PTR(-EBUSY)) { | 2577 ret = PTR_ERR(bdev); 2578 bdev = NULL; 2579 if (ret == -EBUSY) { |
2566 dev_t dev; 2567 2568 mutex_lock(&bch_register_lock); 2569 if (lookup_bdev(strim(path), &dev) == 0 && 2570 bch_is_open(dev)) 2571 err = "device already registered"; 2572 else 2573 err = "device busy"; 2574 mutex_unlock(&bch_register_lock); | 2580 dev_t dev; 2581 2582 mutex_lock(&bch_register_lock); 2583 if (lookup_bdev(strim(path), &dev) == 0 && 2584 bch_is_open(dev)) 2585 err = "device already registered"; 2586 else 2587 err = "device busy"; 2588 mutex_unlock(&bch_register_lock); |
2575 if (attr == &ksysfs_register_quiet) 2576 goto done; | 2589 if (attr == &ksysfs_register_quiet) { 2590 quiet = true; 2591 ret = size; 2592 } |
2577 } | 2593 } |
2578 goto out_free_sb; | 2594 goto out_free_holder; |
2579 } 2580 | 2595 } 2596 |
2581 err = "failed to set blocksize"; 2582 if (set_blocksize(bdev, 4096)) 2583 goto out_blkdev_put; 2584 2585 err = read_super(sb, bdev, &sb_disk); 2586 if (err) 2587 goto out_blkdev_put; 2588 | |
2589 err = "failed to register device"; 2590 2591 if (async_registration) { 2592 /* register in asynchronous way */ 2593 struct async_reg_args *args = 2594 kzalloc(sizeof(struct async_reg_args), GFP_KERNEL); 2595 2596 if (!args) { 2597 ret = -ENOMEM; 2598 err = "cannot allocate memory"; | 2597 err = "failed to register device"; 2598 2599 if (async_registration) { 2600 /* register in asynchronous way */ 2601 struct async_reg_args *args = 2602 kzalloc(sizeof(struct async_reg_args), GFP_KERNEL); 2603 2604 if (!args) { 2605 ret = -ENOMEM; 2606 err = "cannot allocate memory"; |
2599 goto out_put_sb_page; | 2607 goto out_free_holder; |
2600 } 2601 2602 args->path = path; 2603 args->sb = sb; 2604 args->sb_disk = sb_disk; 2605 args->bdev = bdev; | 2608 } 2609 2610 args->path = path; 2611 args->sb = sb; 2612 args->sb_disk = sb_disk; 2613 args->bdev = bdev; |
2614 args->holder = holder; |
|
2606 register_device_async(args); 2607 /* No wait and returns to user space */ 2608 goto async_done; 2609 } 2610 2611 if (SB_IS_BDEV(sb)) { | 2615 register_device_async(args); 2616 /* No wait and returns to user space */ 2617 goto async_done; 2618 } 2619 2620 if (SB_IS_BDEV(sb)) { |
2612 struct cached_dev *dc = kzalloc(sizeof(*dc), GFP_KERNEL); 2613 2614 if (!dc) { 2615 ret = -ENOMEM; 2616 err = "cannot allocate memory"; 2617 goto out_put_sb_page; 2618 } 2619 | |
2620 mutex_lock(&bch_register_lock); | 2621 mutex_lock(&bch_register_lock); |
2621 ret = register_bdev(sb, sb_disk, bdev, dc); | 2622 ret = register_bdev(sb, sb_disk, bdev, holder); |
2622 mutex_unlock(&bch_register_lock); 2623 /* blkdev_put() will be called in cached_dev_free() */ 2624 if (ret < 0) 2625 goto out_free_sb; 2626 } else { | 2623 mutex_unlock(&bch_register_lock); 2624 /* blkdev_put() will be called in cached_dev_free() */ 2625 if (ret < 0) 2626 goto out_free_sb; 2627 } else { |
2627 struct cache *ca = kzalloc(sizeof(*ca), GFP_KERNEL); 2628 2629 if (!ca) { 2630 ret = -ENOMEM; 2631 err = "cannot allocate memory"; 2632 goto out_put_sb_page; 2633 } 2634 | |
2635 /* blkdev_put() will be called in bch_cache_release() */ | 2628 /* blkdev_put() will be called in bch_cache_release() */ |
2636 ret = register_cache(sb, sb_disk, bdev, ca); | 2629 ret = register_cache(sb, sb_disk, bdev, holder); |
2637 if (ret) 2638 goto out_free_sb; 2639 } 2640 | 2630 if (ret) 2631 goto out_free_sb; 2632 } 2633 |
2641done: | |
2642 kfree(sb); 2643 kfree(path); 2644 module_put(THIS_MODULE); 2645async_done: 2646 return size; 2647 | 2634 kfree(sb); 2635 kfree(path); 2636 module_put(THIS_MODULE); 2637async_done: 2638 return size; 2639 |
2640out_free_holder: 2641 kfree(holder); |
|
2648out_put_sb_page: 2649 put_page(virt_to_page(sb_disk)); 2650out_blkdev_put: | 2642out_put_sb_page: 2643 put_page(virt_to_page(sb_disk)); 2644out_blkdev_put: |
2651 blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL); | 2645 if (bdev) 2646 blkdev_put(bdev, holder); |
2652out_free_sb: 2653 kfree(sb); 2654out_free_path: 2655 kfree(path); 2656 path = NULL; 2657out_module_put: 2658 module_put(THIS_MODULE); 2659out: | 2647out_free_sb: 2648 kfree(sb); 2649out_free_path: 2650 kfree(path); 2651 path = NULL; 2652out_module_put: 2653 module_put(THIS_MODULE); 2654out: |
2660 pr_info("error %s: %s\n", path?path:"", err); | 2655 if (!quiet) 2656 pr_info("error %s: %s\n", path?path:"", err); |
2661 return ret; 2662} 2663 2664 2665struct pdev { 2666 struct list_head list; 2667 struct cached_dev *dc; 2668}; --- 270 unchanged lines hidden --- | 2657 return ret; 2658} 2659 2660 2661struct pdev { 2662 struct list_head list; 2663 struct cached_dev *dc; 2664}; --- 270 unchanged lines hidden --- |