diff options
Diffstat (limited to 'drivers/md/bcache/debug.c')
| -rw-r--r-- | drivers/md/bcache/debug.c | 178 |
1 files changed, 20 insertions, 158 deletions
diff --git a/drivers/md/bcache/debug.c b/drivers/md/bcache/debug.c index 89fd5204924e..88e6411eab4f 100644 --- a/drivers/md/bcache/debug.c +++ b/drivers/md/bcache/debug.c | |||
| @@ -47,11 +47,10 @@ const char *bch_ptr_status(struct cache_set *c, const struct bkey *k) | |||
| 47 | return ""; | 47 | return ""; |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | struct keyprint_hack bch_pkey(const struct bkey *k) | 50 | int bch_bkey_to_text(char *buf, size_t size, const struct bkey *k) |
| 51 | { | 51 | { |
| 52 | unsigned i = 0; | 52 | unsigned i = 0; |
| 53 | struct keyprint_hack r; | 53 | char *out = buf, *end = buf + size; |
| 54 | char *out = r.s, *end = r.s + KEYHACK_SIZE; | ||
| 55 | 54 | ||
| 56 | #define p(...) (out += scnprintf(out, end - out, __VA_ARGS__)) | 55 | #define p(...) (out += scnprintf(out, end - out, __VA_ARGS__)) |
| 57 | 56 | ||
| @@ -75,16 +74,14 @@ struct keyprint_hack bch_pkey(const struct bkey *k) | |||
| 75 | if (KEY_CSUM(k)) | 74 | if (KEY_CSUM(k)) |
| 76 | p(" cs%llu %llx", KEY_CSUM(k), k->ptr[1]); | 75 | p(" cs%llu %llx", KEY_CSUM(k), k->ptr[1]); |
| 77 | #undef p | 76 | #undef p |
| 78 | return r; | 77 | return out - buf; |
| 79 | } | 78 | } |
| 80 | 79 | ||
| 81 | struct keyprint_hack bch_pbtree(const struct btree *b) | 80 | int bch_btree_to_text(char *buf, size_t size, const struct btree *b) |
| 82 | { | 81 | { |
| 83 | struct keyprint_hack r; | 82 | return scnprintf(buf, size, "%zu level %i/%i", |
| 84 | 83 | PTR_BUCKET_NR(b->c, &b->key, 0), | |
| 85 | snprintf(r.s, 40, "%zu level %i/%i", PTR_BUCKET_NR(b->c, &b->key, 0), | 84 | b->level, b->c->root ? b->c->root->level : -1); |
| 86 | b->level, b->c->root ? b->c->root->level : -1); | ||
| 87 | return r; | ||
| 88 | } | 85 | } |
| 89 | 86 | ||
| 90 | #if defined(CONFIG_BCACHE_DEBUG) || defined(CONFIG_BCACHE_EDEBUG) | 87 | #if defined(CONFIG_BCACHE_DEBUG) || defined(CONFIG_BCACHE_EDEBUG) |
| @@ -100,10 +97,12 @@ static void dump_bset(struct btree *b, struct bset *i) | |||
| 100 | { | 97 | { |
| 101 | struct bkey *k; | 98 | struct bkey *k; |
| 102 | unsigned j; | 99 | unsigned j; |
| 100 | char buf[80]; | ||
| 103 | 101 | ||
| 104 | for (k = i->start; k < end(i); k = bkey_next(k)) { | 102 | for (k = i->start; k < end(i); k = bkey_next(k)) { |
| 103 | bch_bkey_to_text(buf, sizeof(buf), k); | ||
| 105 | printk(KERN_ERR "block %zu key %zi/%u: %s", index(i, b), | 104 | printk(KERN_ERR "block %zu key %zi/%u: %s", index(i, b), |
| 106 | (uint64_t *) k - i->d, i->keys, pkey(k)); | 105 | (uint64_t *) k - i->d, i->keys, buf); |
| 107 | 106 | ||
| 108 | for (j = 0; j < KEY_PTRS(k); j++) { | 107 | for (j = 0; j < KEY_PTRS(k); j++) { |
| 109 | size_t n = PTR_BUCKET_NR(b->c, k, j); | 108 | size_t n = PTR_BUCKET_NR(b->c, k, j); |
| @@ -144,7 +143,7 @@ void bch_btree_verify(struct btree *b, struct bset *new) | |||
| 144 | v->written = 0; | 143 | v->written = 0; |
| 145 | v->level = b->level; | 144 | v->level = b->level; |
| 146 | 145 | ||
| 147 | bch_btree_read(v); | 146 | bch_btree_node_read(v); |
| 148 | closure_wait_event(&v->io.wait, &cl, | 147 | closure_wait_event(&v->io.wait, &cl, |
| 149 | atomic_read(&b->io.cl.remaining) == -1); | 148 | atomic_read(&b->io.cl.remaining) == -1); |
| 150 | 149 | ||
| @@ -200,7 +199,7 @@ void bch_data_verify(struct search *s) | |||
| 200 | if (!check) | 199 | if (!check) |
| 201 | return; | 200 | return; |
| 202 | 201 | ||
| 203 | if (bch_bio_alloc_pages(check, GFP_NOIO)) | 202 | if (bio_alloc_pages(check, GFP_NOIO)) |
| 204 | goto out_put; | 203 | goto out_put; |
| 205 | 204 | ||
| 206 | check->bi_rw = READ_SYNC; | 205 | check->bi_rw = READ_SYNC; |
| @@ -252,6 +251,7 @@ static void vdump_bucket_and_panic(struct btree *b, const char *fmt, | |||
| 252 | va_list args) | 251 | va_list args) |
| 253 | { | 252 | { |
| 254 | unsigned i; | 253 | unsigned i; |
| 254 | char buf[80]; | ||
| 255 | 255 | ||
| 256 | console_lock(); | 256 | console_lock(); |
| 257 | 257 | ||
| @@ -262,7 +262,8 @@ static void vdump_bucket_and_panic(struct btree *b, const char *fmt, | |||
| 262 | 262 | ||
| 263 | console_unlock(); | 263 | console_unlock(); |
| 264 | 264 | ||
| 265 | panic("at %s\n", pbtree(b)); | 265 | bch_btree_to_text(buf, sizeof(buf), b); |
| 266 | panic("at %s\n", buf); | ||
| 266 | } | 267 | } |
| 267 | 268 | ||
| 268 | void bch_check_key_order_msg(struct btree *b, struct bset *i, | 269 | void bch_check_key_order_msg(struct btree *b, struct bset *i, |
| @@ -337,6 +338,7 @@ static ssize_t bch_dump_read(struct file *file, char __user *buf, | |||
| 337 | { | 338 | { |
| 338 | struct dump_iterator *i = file->private_data; | 339 | struct dump_iterator *i = file->private_data; |
| 339 | ssize_t ret = 0; | 340 | ssize_t ret = 0; |
| 341 | char kbuf[80]; | ||
| 340 | 342 | ||
| 341 | while (size) { | 343 | while (size) { |
| 342 | struct keybuf_key *w; | 344 | struct keybuf_key *w; |
| @@ -355,11 +357,12 @@ static ssize_t bch_dump_read(struct file *file, char __user *buf, | |||
| 355 | if (i->bytes) | 357 | if (i->bytes) |
| 356 | break; | 358 | break; |
| 357 | 359 | ||
| 358 | w = bch_keybuf_next_rescan(i->c, &i->keys, &MAX_KEY); | 360 | w = bch_keybuf_next_rescan(i->c, &i->keys, &MAX_KEY, dump_pred); |
| 359 | if (!w) | 361 | if (!w) |
| 360 | break; | 362 | break; |
| 361 | 363 | ||
| 362 | i->bytes = snprintf(i->buf, PAGE_SIZE, "%s\n", pkey(&w->key)); | 364 | bch_bkey_to_text(kbuf, sizeof(kbuf), &w->key); |
| 365 | i->bytes = snprintf(i->buf, PAGE_SIZE, "%s\n", kbuf); | ||
| 363 | bch_keybuf_del(&i->keys, w); | 366 | bch_keybuf_del(&i->keys, w); |
| 364 | } | 367 | } |
| 365 | 368 | ||
| @@ -377,7 +380,7 @@ static int bch_dump_open(struct inode *inode, struct file *file) | |||
| 377 | 380 | ||
| 378 | file->private_data = i; | 381 | file->private_data = i; |
| 379 | i->c = c; | 382 | i->c = c; |
| 380 | bch_keybuf_init(&i->keys, dump_pred); | 383 | bch_keybuf_init(&i->keys); |
| 381 | i->keys.last_scanned = KEY(0, 0, 0); | 384 | i->keys.last_scanned = KEY(0, 0, 0); |
| 382 | 385 | ||
| 383 | return 0; | 386 | return 0; |
| @@ -409,142 +412,6 @@ void bch_debug_init_cache_set(struct cache_set *c) | |||
| 409 | 412 | ||
| 410 | #endif | 413 | #endif |
| 411 | 414 | ||
| 412 | /* Fuzz tester has rotted: */ | ||
| 413 | #if 0 | ||
| 414 | |||
| 415 | static ssize_t btree_fuzz(struct kobject *k, struct kobj_attribute *a, | ||
| 416 | const char *buffer, size_t size) | ||
| 417 | { | ||
| 418 | void dump(struct btree *b) | ||
| 419 | { | ||
| 420 | struct bset *i; | ||
| 421 | |||
| 422 | for (i = b->sets[0].data; | ||
| 423 | index(i, b) < btree_blocks(b) && | ||
| 424 | i->seq == b->sets[0].data->seq; | ||
| 425 | i = ((void *) i) + set_blocks(i, b->c) * block_bytes(b->c)) | ||
| 426 | dump_bset(b, i); | ||
| 427 | } | ||
| 428 | |||
| 429 | struct cache_sb *sb; | ||
| 430 | struct cache_set *c; | ||
| 431 | struct btree *all[3], *b, *fill, *orig; | ||
| 432 | int j; | ||
| 433 | |||
| 434 | struct btree_op op; | ||
| 435 | bch_btree_op_init_stack(&op); | ||
| 436 | |||
| 437 | sb = kzalloc(sizeof(struct cache_sb), GFP_KERNEL); | ||
| 438 | if (!sb) | ||
| 439 | return -ENOMEM; | ||
| 440 | |||
| 441 | sb->bucket_size = 128; | ||
| 442 | sb->block_size = 4; | ||
| 443 | |||
| 444 | c = bch_cache_set_alloc(sb); | ||
| 445 | if (!c) | ||
| 446 | return -ENOMEM; | ||
| 447 | |||
| 448 | for (j = 0; j < 3; j++) { | ||
| 449 | BUG_ON(list_empty(&c->btree_cache)); | ||
| 450 | all[j] = list_first_entry(&c->btree_cache, struct btree, list); | ||
| 451 | list_del_init(&all[j]->list); | ||
| 452 | |||
| 453 | all[j]->key = KEY(0, 0, c->sb.bucket_size); | ||
| 454 | bkey_copy_key(&all[j]->key, &MAX_KEY); | ||
| 455 | } | ||
| 456 | |||
| 457 | b = all[0]; | ||
| 458 | fill = all[1]; | ||
| 459 | orig = all[2]; | ||
| 460 | |||
| 461 | while (1) { | ||
| 462 | for (j = 0; j < 3; j++) | ||
| 463 | all[j]->written = all[j]->nsets = 0; | ||
| 464 | |||
| 465 | bch_bset_init_next(b); | ||
| 466 | |||
| 467 | while (1) { | ||
| 468 | struct bset *i = write_block(b); | ||
| 469 | struct bkey *k = op.keys.top; | ||
| 470 | unsigned rand; | ||
| 471 | |||
| 472 | bkey_init(k); | ||
| 473 | rand = get_random_int(); | ||
| 474 | |||
| 475 | op.type = rand & 1 | ||
| 476 | ? BTREE_INSERT | ||
| 477 | : BTREE_REPLACE; | ||
| 478 | rand >>= 1; | ||
| 479 | |||
| 480 | SET_KEY_SIZE(k, bucket_remainder(c, rand)); | ||
| 481 | rand >>= c->bucket_bits; | ||
| 482 | rand &= 1024 * 512 - 1; | ||
| 483 | rand += c->sb.bucket_size; | ||
| 484 | SET_KEY_OFFSET(k, rand); | ||
| 485 | #if 0 | ||
| 486 | SET_KEY_PTRS(k, 1); | ||
| 487 | #endif | ||
| 488 | bch_keylist_push(&op.keys); | ||
| 489 | bch_btree_insert_keys(b, &op); | ||
| 490 | |||
| 491 | if (should_split(b) || | ||
| 492 | set_blocks(i, b->c) != | ||
| 493 | __set_blocks(i, i->keys + 15, b->c)) { | ||
| 494 | i->csum = csum_set(i); | ||
| 495 | |||
| 496 | memcpy(write_block(fill), | ||
| 497 | i, set_bytes(i)); | ||
| 498 | |||
| 499 | b->written += set_blocks(i, b->c); | ||
| 500 | fill->written = b->written; | ||
| 501 | if (b->written == btree_blocks(b)) | ||
| 502 | break; | ||
| 503 | |||
| 504 | bch_btree_sort_lazy(b); | ||
| 505 | bch_bset_init_next(b); | ||
| 506 | } | ||
| 507 | } | ||
| 508 | |||
| 509 | memcpy(orig->sets[0].data, | ||
| 510 | fill->sets[0].data, | ||
| 511 | btree_bytes(c)); | ||
| 512 | |||
| 513 | bch_btree_sort(b); | ||
| 514 | fill->written = 0; | ||
| 515 | bch_btree_read_done(&fill->io.cl); | ||
| 516 | |||
| 517 | if (b->sets[0].data->keys != fill->sets[0].data->keys || | ||
| 518 | memcmp(b->sets[0].data->start, | ||
| 519 | fill->sets[0].data->start, | ||
| 520 | b->sets[0].data->keys * sizeof(uint64_t))) { | ||
| 521 | struct bset *i = b->sets[0].data; | ||
| 522 | struct bkey *k, *l; | ||
| 523 | |||
| 524 | for (k = i->start, | ||
| 525 | l = fill->sets[0].data->start; | ||
| 526 | k < end(i); | ||
| 527 | k = bkey_next(k), l = bkey_next(l)) | ||
| 528 | if (bkey_cmp(k, l) || | ||
| 529 | KEY_SIZE(k) != KEY_SIZE(l)) | ||
| 530 | pr_err("key %zi differs: %s != %s", | ||
| 531 | (uint64_t *) k - i->d, | ||
| 532 | pkey(k), pkey(l)); | ||
| 533 | |||
| 534 | for (j = 0; j < 3; j++) { | ||
| 535 | pr_err("**** Set %i ****", j); | ||
| 536 | dump(all[j]); | ||
| 537 | } | ||
| 538 | panic("\n"); | ||
| 539 | } | ||
| 540 | |||
| 541 | pr_info("fuzz complete: %i keys", b->sets[0].data->keys); | ||
| 542 | } | ||
| 543 | } | ||
| 544 | |||
| 545 | kobj_attribute_write(fuzz, btree_fuzz); | ||
| 546 | #endif | ||
| 547 | |||
| 548 | void bch_debug_exit(void) | 415 | void bch_debug_exit(void) |
| 549 | { | 416 | { |
| 550 | if (!IS_ERR_OR_NULL(debug)) | 417 | if (!IS_ERR_OR_NULL(debug)) |
| @@ -554,11 +421,6 @@ void bch_debug_exit(void) | |||
| 554 | int __init bch_debug_init(struct kobject *kobj) | 421 | int __init bch_debug_init(struct kobject *kobj) |
| 555 | { | 422 | { |
| 556 | int ret = 0; | 423 | int ret = 0; |
| 557 | #if 0 | ||
| 558 | ret = sysfs_create_file(kobj, &ksysfs_fuzz.attr); | ||
| 559 | if (ret) | ||
| 560 | return ret; | ||
| 561 | #endif | ||
| 562 | 424 | ||
| 563 | debug = debugfs_create_dir("bcache", NULL); | 425 | debug = debugfs_create_dir("bcache", NULL); |
| 564 | return ret; | 426 | return ret; |
