super.c (119ba0f82839cd80eaef3e6991988f1403965d5b) super.c (5794351146199b9ac67a5ab1beab82be8bfd7b5d)
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

--- 1241 unchanged lines hidden (view full) ---

1250
1251 for_each_cache(ca, c, i)
1252 if (ca)
1253 kobject_put(&ca->kobj);
1254
1255 free_pages((unsigned long) c->uuids, ilog2(bucket_pages(c)));
1256 free_pages((unsigned long) c->sort, ilog2(bucket_pages(c)));
1257
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

--- 1241 unchanged lines hidden (view full) ---

1250
1251 for_each_cache(ca, c, i)
1252 if (ca)
1253 kobject_put(&ca->kobj);
1254
1255 free_pages((unsigned long) c->uuids, ilog2(bucket_pages(c)));
1256 free_pages((unsigned long) c->sort, ilog2(bucket_pages(c)));
1257
1258 kfree(c->fill_iter);
1259 if (c->bio_split)
1260 bioset_free(c->bio_split);
1258 if (c->bio_split)
1259 bioset_free(c->bio_split);
1260 if (c->fill_iter)
1261 mempool_destroy(c->fill_iter);
1261 if (c->bio_meta)
1262 mempool_destroy(c->bio_meta);
1263 if (c->search)
1264 mempool_destroy(c->search);
1265 kfree(c->devices);
1266
1267 mutex_lock(&bch_register_lock);
1268 list_del(&c->list);

--- 21 unchanged lines hidden (view full) ---

1290 kobject_del(&c->kobj);
1291
1292 if (!IS_ERR_OR_NULL(c->root))
1293 list_add(&c->root->list, &c->btree_cache);
1294
1295 /* Should skip this if we're unregistering because of an error */
1296 list_for_each_entry(b, &c->btree_cache, list)
1297 if (btree_node_dirty(b))
1262 if (c->bio_meta)
1263 mempool_destroy(c->bio_meta);
1264 if (c->search)
1265 mempool_destroy(c->search);
1266 kfree(c->devices);
1267
1268 mutex_lock(&bch_register_lock);
1269 list_del(&c->list);

--- 21 unchanged lines hidden (view full) ---

1291 kobject_del(&c->kobj);
1292
1293 if (!IS_ERR_OR_NULL(c->root))
1294 list_add(&c->root->list, &c->btree_cache);
1295
1296 /* Should skip this if we're unregistering because of an error */
1297 list_for_each_entry(b, &c->btree_cache, list)
1298 if (btree_node_dirty(b))
1298 bch_btree_write(b, true, NULL);
1299 bch_btree_node_write(b, NULL);
1299
1300 closure_return(cl);
1301}
1302
1303static void __cache_set_unregister(struct closure *cl)
1304{
1305 struct cache_set *c = container_of(cl, struct cache_set, caching);
1306 struct cached_dev *dc, *t;

--- 62 unchanged lines hidden (view full) ---

1369 c->nr_uuids = bucket_bytes(c) / sizeof(struct uuid_entry);
1370
1371 c->btree_pages = c->sb.bucket_size / PAGE_SECTORS;
1372 if (c->btree_pages > BTREE_MAX_PAGES)
1373 c->btree_pages = max_t(int, c->btree_pages / 4,
1374 BTREE_MAX_PAGES);
1375
1376 mutex_init(&c->bucket_lock);
1300
1301 closure_return(cl);
1302}
1303
1304static void __cache_set_unregister(struct closure *cl)
1305{
1306 struct cache_set *c = container_of(cl, struct cache_set, caching);
1307 struct cached_dev *dc, *t;

--- 62 unchanged lines hidden (view full) ---

1370 c->nr_uuids = bucket_bytes(c) / sizeof(struct uuid_entry);
1371
1372 c->btree_pages = c->sb.bucket_size / PAGE_SECTORS;
1373 if (c->btree_pages > BTREE_MAX_PAGES)
1374 c->btree_pages = max_t(int, c->btree_pages / 4,
1375 BTREE_MAX_PAGES);
1376
1377 mutex_init(&c->bucket_lock);
1377 mutex_init(&c->fill_lock);
1378 mutex_init(&c->sort_lock);
1379 spin_lock_init(&c->sort_time_lock);
1380 closure_init_unlocked(&c->sb_write);
1381 closure_init_unlocked(&c->uuid_write);
1382 spin_lock_init(&c->btree_read_time_lock);
1383 bch_moving_init_cache_set(c);
1384
1385 INIT_LIST_HEAD(&c->list);

--- 9 unchanged lines hidden (view full) ---

1395
1396 iter_size = (sb->bucket_size / sb->block_size + 1) *
1397 sizeof(struct btree_iter_set);
1398
1399 if (!(c->devices = kzalloc(c->nr_uuids * sizeof(void *), GFP_KERNEL)) ||
1400 !(c->bio_meta = mempool_create_kmalloc_pool(2,
1401 sizeof(struct bbio) + sizeof(struct bio_vec) *
1402 bucket_pages(c))) ||
1378 mutex_init(&c->sort_lock);
1379 spin_lock_init(&c->sort_time_lock);
1380 closure_init_unlocked(&c->sb_write);
1381 closure_init_unlocked(&c->uuid_write);
1382 spin_lock_init(&c->btree_read_time_lock);
1383 bch_moving_init_cache_set(c);
1384
1385 INIT_LIST_HEAD(&c->list);

--- 9 unchanged lines hidden (view full) ---

1395
1396 iter_size = (sb->bucket_size / sb->block_size + 1) *
1397 sizeof(struct btree_iter_set);
1398
1399 if (!(c->devices = kzalloc(c->nr_uuids * sizeof(void *), GFP_KERNEL)) ||
1400 !(c->bio_meta = mempool_create_kmalloc_pool(2,
1401 sizeof(struct bbio) + sizeof(struct bio_vec) *
1402 bucket_pages(c))) ||
1403 !(c->fill_iter = mempool_create_kmalloc_pool(1, iter_size)) ||
1403 !(c->bio_split = bioset_create(4, offsetof(struct bbio, bio))) ||
1404 !(c->bio_split = bioset_create(4, offsetof(struct bbio, bio))) ||
1404 !(c->fill_iter = kmalloc(iter_size, GFP_KERNEL)) ||
1405 !(c->sort = alloc_bucket_pages(GFP_KERNEL, c)) ||
1406 !(c->uuids = alloc_bucket_pages(GFP_KERNEL, c)) ||
1407 bch_journal_alloc(c) ||
1408 bch_btree_cache_alloc(c) ||
1409 bch_open_buckets_alloc(c))
1410 goto err;
1411
1405 !(c->sort = alloc_bucket_pages(GFP_KERNEL, c)) ||
1406 !(c->uuids = alloc_bucket_pages(GFP_KERNEL, c)) ||
1407 bch_journal_alloc(c) ||
1408 bch_btree_cache_alloc(c) ||
1409 bch_open_buckets_alloc(c))
1410 goto err;
1411
1412 c->fill_iter->size = sb->bucket_size / sb->block_size;
1413
1414 c->congested_read_threshold_us = 2000;
1415 c->congested_write_threshold_us = 20000;
1416 c->error_limit = 8 << IO_ERROR_SHIFT;
1417
1418 return c;
1419err:
1420 bch_cache_set_unregister(c);
1421 return NULL;

--- 124 unchanged lines hidden (view full) ---

1546 goto err_unlock_gc;
1547
1548 err = "cannot allocate new btree root";
1549 c->root = bch_btree_node_alloc(c, 0, &op.cl);
1550 if (IS_ERR_OR_NULL(c->root))
1551 goto err_unlock_gc;
1552
1553 bkey_copy_key(&c->root->key, &MAX_KEY);
1412 c->congested_read_threshold_us = 2000;
1413 c->congested_write_threshold_us = 20000;
1414 c->error_limit = 8 << IO_ERROR_SHIFT;
1415
1416 return c;
1417err:
1418 bch_cache_set_unregister(c);
1419 return NULL;

--- 124 unchanged lines hidden (view full) ---

1544 goto err_unlock_gc;
1545
1546 err = "cannot allocate new btree root";
1547 c->root = bch_btree_node_alloc(c, 0, &op.cl);
1548 if (IS_ERR_OR_NULL(c->root))
1549 goto err_unlock_gc;
1550
1551 bkey_copy_key(&c->root->key, &MAX_KEY);
1554 bch_btree_write(c->root, true, &op);
1552 bch_btree_node_write(c->root, &op.cl);
1555
1556 bch_btree_set_root(c->root);
1557 rw_unlock(true, c->root);
1558
1559 /*
1560 * We don't want to write the first journal entry until
1561 * everything is set up - fortunately journal entries won't be
1562 * written until the SET_CACHE_SYNC() here:

--- 434 unchanged lines hidden ---
1553
1554 bch_btree_set_root(c->root);
1555 rw_unlock(true, c->root);
1556
1557 /*
1558 * We don't want to write the first journal entry until
1559 * everything is set up - fortunately journal entries won't be
1560 * written until the SET_CACHE_SYNC() here:

--- 434 unchanged lines hidden ---