super.c (6f10f7d1b02b1bbc305f88d7696445dd38b13881) | super.c (1fae7cf05293d3a2c9e59c1bc59372322386467c) |
---|---|
1/* 2 * bcache setup/teardown code, and some metadata io - read a superblock and 3 * figure out what to do with it. 4 * 5 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com> 6 * Copyright 2012 Google, Inc. 7 */ 8 --- 401 unchanged lines hidden (view full) --- 410 411 return NULL; 412} 413 414static int __uuid_write(struct cache_set *c) 415{ 416 BKEY_PADDED(key) k; 417 struct closure cl; | 1/* 2 * bcache setup/teardown code, and some metadata io - read a superblock and 3 * figure out what to do with it. 4 * 5 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com> 6 * Copyright 2012 Google, Inc. 7 */ 8 --- 401 unchanged lines hidden (view full) --- 410 411 return NULL; 412} 413 414static int __uuid_write(struct cache_set *c) 415{ 416 BKEY_PADDED(key) k; 417 struct closure cl; |
418 closure_init_stack(&cl); | |
419 | 418 |
419 closure_init_stack(&cl); |
|
420 lockdep_assert_held(&bch_register_lock); 421 422 if (bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, 1, true)) 423 return 1; 424 425 SET_KEY_SIZE(&k.key, c->sb.bucket_size); 426 uuid_io(c, REQ_OP_WRITE, 0, &k.key, &cl); 427 closure_sync(&cl); --- 23 unchanged lines hidden (view full) --- 451 return u; 452 453 return NULL; 454} 455 456static struct uuid_entry *uuid_find_empty(struct cache_set *c) 457{ 458 static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; | 420 lockdep_assert_held(&bch_register_lock); 421 422 if (bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, 1, true)) 423 return 1; 424 425 SET_KEY_SIZE(&k.key, c->sb.bucket_size); 426 uuid_io(c, REQ_OP_WRITE, 0, &k.key, &cl); 427 closure_sync(&cl); --- 23 unchanged lines hidden (view full) --- 451 return u; 452 453 return NULL; 454} 455 456static struct uuid_entry *uuid_find_empty(struct cache_set *c) 457{ 458 static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; |
459 |
|
459 return uuid_find(c, zero_uuid); 460} 461 462/* 463 * Bucket priorities/gens: 464 * 465 * For each bucket, we store on disk its 466 * 8 bit gen --- 147 unchanged lines hidden (view full) --- 614 } 615} 616 617/* Bcache device */ 618 619static int open_dev(struct block_device *b, fmode_t mode) 620{ 621 struct bcache_device *d = b->bd_disk->private_data; | 460 return uuid_find(c, zero_uuid); 461} 462 463/* 464 * Bucket priorities/gens: 465 * 466 * For each bucket, we store on disk its 467 * 8 bit gen --- 147 unchanged lines hidden (view full) --- 615 } 616} 617 618/* Bcache device */ 619 620static int open_dev(struct block_device *b, fmode_t mode) 621{ 622 struct bcache_device *d = b->bd_disk->private_data; |
623 |
|
622 if (test_bit(BCACHE_DEV_CLOSING, &d->flags)) 623 return -ENXIO; 624 625 closure_get(&d->cl); 626 return 0; 627} 628 629static void release_dev(struct gendisk *b, fmode_t mode) 630{ 631 struct bcache_device *d = b->private_data; | 624 if (test_bit(BCACHE_DEV_CLOSING, &d->flags)) 625 return -ENXIO; 626 627 closure_get(&d->cl); 628 return 0; 629} 630 631static void release_dev(struct gendisk *b, fmode_t mode) 632{ 633 struct bcache_device *d = b->private_data; |
634 |
|
632 closure_put(&d->cl); 633} 634 635static int ioctl_dev(struct block_device *b, fmode_t mode, 636 unsigned int cmd, unsigned long arg) 637{ 638 struct bcache_device *d = b->bd_disk->private_data; 639 struct cached_dev *dc = container_of(d, struct cached_dev, disk); --- 274 unchanged lines hidden (view full) --- 914 kfree(env[1]); 915 kfree(env[2]); 916 return; 917 } 918 919 if (!d->c && 920 BDEV_STATE(&dc->sb) != BDEV_STATE_NONE) { 921 struct closure cl; | 635 closure_put(&d->cl); 636} 637 638static int ioctl_dev(struct block_device *b, fmode_t mode, 639 unsigned int cmd, unsigned long arg) 640{ 641 struct bcache_device *d = b->bd_disk->private_data; 642 struct cached_dev *dc = container_of(d, struct cached_dev, disk); --- 274 unchanged lines hidden (view full) --- 917 kfree(env[1]); 918 kfree(env[2]); 919 return; 920 } 921 922 if (!d->c && 923 BDEV_STATE(&dc->sb) != BDEV_STATE_NONE) { 924 struct closure cl; |
925 |
|
922 closure_init_stack(&cl); 923 924 SET_BDEV_STATE(&dc->sb, BDEV_STATE_STALE); 925 bch_write_bdev_super(dc, &cl); 926 closure_sync(&cl); 927 } 928 929 add_disk(d->disk); --- 41 unchanged lines hidden (view full) --- 971 972 cancel_delayed_work_sync(&dc->writeback_rate_update); 973} 974 975static void cached_dev_detach_finish(struct work_struct *w) 976{ 977 struct cached_dev *dc = container_of(w, struct cached_dev, detach); 978 struct closure cl; | 926 closure_init_stack(&cl); 927 928 SET_BDEV_STATE(&dc->sb, BDEV_STATE_STALE); 929 bch_write_bdev_super(dc, &cl); 930 closure_sync(&cl); 931 } 932 933 add_disk(d->disk); --- 41 unchanged lines hidden (view full) --- 975 976 cancel_delayed_work_sync(&dc->writeback_rate_update); 977} 978 979static void cached_dev_detach_finish(struct work_struct *w) 980{ 981 struct cached_dev *dc = container_of(w, struct cached_dev, detach); 982 struct closure cl; |
983 |
|
979 closure_init_stack(&cl); 980 981 BUG_ON(!test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags)); 982 BUG_ON(refcount_read(&dc->count)); 983 984 mutex_lock(&bch_register_lock); 985 986 if (test_and_clear_bit(BCACHE_DEV_WB_RUNNING, &dc->disk.flags)) --- 111 unchanged lines hidden (view full) --- 1098 } 1099 1100 /* Deadlocks since we're called via sysfs... 1101 sysfs_remove_file(&dc->kobj, &sysfs_attach); 1102 */ 1103 1104 if (bch_is_zero(u->uuid, 16)) { 1105 struct closure cl; | 984 closure_init_stack(&cl); 985 986 BUG_ON(!test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags)); 987 BUG_ON(refcount_read(&dc->count)); 988 989 mutex_lock(&bch_register_lock); 990 991 if (test_and_clear_bit(BCACHE_DEV_WB_RUNNING, &dc->disk.flags)) --- 111 unchanged lines hidden (view full) --- 1103 } 1104 1105 /* Deadlocks since we're called via sysfs... 1106 sysfs_remove_file(&dc->kobj, &sysfs_attach); 1107 */ 1108 1109 if (bch_is_zero(u->uuid, 16)) { 1110 struct closure cl; |
1111 |
|
1106 closure_init_stack(&cl); 1107 1108 memcpy(u->uuid, dc->sb.uuid, 16); 1109 memcpy(u->label, dc->sb.label, SB_LABEL_SIZE); 1110 u->first_reg = u->last_reg = rtime; 1111 bch_uuid_write(c); 1112 1113 memcpy(dc->sb.set_uuid, c->sb.set_uuid, 16); --- 201 unchanged lines hidden (view full) --- 1315 struct bcache_device *d = container_of(kobj, struct bcache_device, 1316 kobj); 1317 kfree(d); 1318} 1319 1320static void flash_dev_free(struct closure *cl) 1321{ 1322 struct bcache_device *d = container_of(cl, struct bcache_device, cl); | 1112 closure_init_stack(&cl); 1113 1114 memcpy(u->uuid, dc->sb.uuid, 16); 1115 memcpy(u->label, dc->sb.label, SB_LABEL_SIZE); 1116 u->first_reg = u->last_reg = rtime; 1117 bch_uuid_write(c); 1118 1119 memcpy(dc->sb.set_uuid, c->sb.set_uuid, 16); --- 201 unchanged lines hidden (view full) --- 1321 struct bcache_device *d = container_of(kobj, struct bcache_device, 1322 kobj); 1323 kfree(d); 1324} 1325 1326static void flash_dev_free(struct closure *cl) 1327{ 1328 struct bcache_device *d = container_of(cl, struct bcache_device, cl); |
1329 |
|
1323 mutex_lock(&bch_register_lock); 1324 atomic_long_sub(bcache_dev_sectors_dirty(d), 1325 &d->c->flash_dev_dirty_sectors); 1326 bcache_device_free(d); 1327 mutex_unlock(&bch_register_lock); 1328 kobject_put(&d->kobj); 1329} 1330 --- 145 unchanged lines hidden (view full) --- 1476 1477 bch_cache_set_unregister(c); 1478 return true; 1479} 1480 1481void bch_cache_set_release(struct kobject *kobj) 1482{ 1483 struct cache_set *c = container_of(kobj, struct cache_set, kobj); | 1330 mutex_lock(&bch_register_lock); 1331 atomic_long_sub(bcache_dev_sectors_dirty(d), 1332 &d->c->flash_dev_dirty_sectors); 1333 bcache_device_free(d); 1334 mutex_unlock(&bch_register_lock); 1335 kobject_put(&d->kobj); 1336} 1337 --- 145 unchanged lines hidden (view full) --- 1483 1484 bch_cache_set_unregister(c); 1485 return true; 1486} 1487 1488void bch_cache_set_release(struct kobject *kobj) 1489{ 1490 struct cache_set *c = container_of(kobj, struct cache_set, kobj); |
1491 |
|
1484 kfree(c); 1485 module_put(THIS_MODULE); 1486} 1487 1488static void cache_set_free(struct closure *cl) 1489{ 1490 struct cache_set *c = container_of(cl, struct cache_set, cl); 1491 struct cache *ca; --- 174 unchanged lines hidden (view full) --- 1666 1667#define alloc_bucket_pages(gfp, c) \ 1668 ((void *) __get_free_pages(__GFP_ZERO|gfp, ilog2(bucket_pages(c)))) 1669 1670struct cache_set *bch_cache_set_alloc(struct cache_sb *sb) 1671{ 1672 int iter_size; 1673 struct cache_set *c = kzalloc(sizeof(struct cache_set), GFP_KERNEL); | 1492 kfree(c); 1493 module_put(THIS_MODULE); 1494} 1495 1496static void cache_set_free(struct closure *cl) 1497{ 1498 struct cache_set *c = container_of(cl, struct cache_set, cl); 1499 struct cache *ca; --- 174 unchanged lines hidden (view full) --- 1674 1675#define alloc_bucket_pages(gfp, c) \ 1676 ((void *) __get_free_pages(__GFP_ZERO|gfp, ilog2(bucket_pages(c)))) 1677 1678struct cache_set *bch_cache_set_alloc(struct cache_sb *sb) 1679{ 1680 int iter_size; 1681 struct cache_set *c = kzalloc(sizeof(struct cache_set), GFP_KERNEL); |
1682 |
|
1674 if (!c) 1675 return NULL; 1676 1677 __module_get(THIS_MODULE); 1678 closure_init(&c->cl, NULL); 1679 set_closure_fn(&c->cl, cache_set_free, system_wq); 1680 1681 closure_init(&c->caching, &c->cl); --- 529 unchanged lines hidden (view full) --- 2211 2212 err = read_super(sb, bdev, &sb_page); 2213 if (err) 2214 goto err_close; 2215 2216 err = "failed to register device"; 2217 if (SB_IS_BDEV(sb)) { 2218 struct cached_dev *dc = kzalloc(sizeof(*dc), GFP_KERNEL); | 1683 if (!c) 1684 return NULL; 1685 1686 __module_get(THIS_MODULE); 1687 closure_init(&c->cl, NULL); 1688 set_closure_fn(&c->cl, cache_set_free, system_wq); 1689 1690 closure_init(&c->caching, &c->cl); --- 529 unchanged lines hidden (view full) --- 2220 2221 err = read_super(sb, bdev, &sb_page); 2222 if (err) 2223 goto err_close; 2224 2225 err = "failed to register device"; 2226 if (SB_IS_BDEV(sb)) { 2227 struct cached_dev *dc = kzalloc(sizeof(*dc), GFP_KERNEL); |
2228 |
|
2219 if (!dc) 2220 goto err_close; 2221 2222 mutex_lock(&bch_register_lock); 2223 register_bdev(sb, sb_page, bdev, dc); 2224 mutex_unlock(&bch_register_lock); 2225 } else { 2226 struct cache *ca = kzalloc(sizeof(*ca), GFP_KERNEL); | 2229 if (!dc) 2230 goto err_close; 2231 2232 mutex_lock(&bch_register_lock); 2233 register_bdev(sb, sb_page, bdev, dc); 2234 mutex_unlock(&bch_register_lock); 2235 } else { 2236 struct cache *ca = kzalloc(sizeof(*ca), GFP_KERNEL); |
2237 |
|
2227 if (!ca) 2228 goto err_close; 2229 2230 if (register_cache(sb, sb_page, bdev, ca) != 0) 2231 goto err; 2232 } 2233out: 2234 if (sb_page) --- 132 unchanged lines hidden --- | 2238 if (!ca) 2239 goto err_close; 2240 2241 if (register_cache(sb, sb_page, bdev, ca) != 0) 2242 goto err; 2243 } 2244out: 2245 if (sb_page) --- 132 unchanged lines hidden --- |