Lines Matching +full:key +full:- +full:release
1 // SPDX-License-Identifier: GPL-2.0
36 struct btree *v = c->verify_data; in bch2_btree_verify_replica()
37 struct btree_node *n_ondisk = c->verify_ondisk; in bch2_btree_verify_replica()
38 struct btree_node *n_sorted = c->verify_data->data; in bch2_btree_verify_replica()
39 struct bset *sorted, *inmemory = &b->data->keys; in bch2_btree_verify_replica()
47 bio = bio_alloc_bioset(ca->disk_sb.bdev, in bch2_btree_verify_replica()
51 &c->btree_bio); in bch2_btree_verify_replica()
52 bio->bi_iter.bi_sector = pick.ptr.offset; in bch2_btree_verify_replica()
58 percpu_ref_put(&ca->io_ref); in bch2_btree_verify_replica()
62 v->written = 0; in bch2_btree_verify_replica()
66 n_sorted = c->verify_data->data; in bch2_btree_verify_replica()
67 sorted = &n_sorted->keys; in bch2_btree_verify_replica()
69 if (inmemory->u64s != sorted->u64s || in bch2_btree_verify_replica()
70 memcmp(inmemory->start, in bch2_btree_verify_replica()
71 sorted->start, in bch2_btree_verify_replica()
72 vstruct_end(inmemory) - (void *) inmemory->start)) { in bch2_btree_verify_replica()
85 while (offset < v->written) { in bch2_btree_verify_replica()
87 i = &n_ondisk->keys; in bch2_btree_verify_replica()
88 sectors = vstruct_blocks(n_ondisk, c->block_bits) << in bch2_btree_verify_replica()
89 c->block_bits; in bch2_btree_verify_replica()
93 i = &bne->keys; in bch2_btree_verify_replica()
95 sectors = vstruct_blocks(bne, c->block_bits) << in bch2_btree_verify_replica()
96 c->block_bits; in bch2_btree_verify_replica()
105 for (j = 0; j < le16_to_cpu(inmemory->u64s); j++) in bch2_btree_verify_replica()
106 if (inmemory->_data[j] != sorted->_data[j]) in bch2_btree_verify_replica()
110 bch_err(c, "verify failed at key %u", j); in bch2_btree_verify_replica()
115 if (v->written != b->written) { in bch2_btree_verify_replica()
117 b->written, v->written); in bch2_btree_verify_replica()
130 struct bset *inmemory = &b->data->keys; in __bch2_btree_verify()
134 if (c->opts.nochanges) in __bch2_btree_verify()
138 mutex_lock(&c->verify_lock); in __bch2_btree_verify()
140 if (!c->verify_ondisk) { in __bch2_btree_verify()
141 c->verify_ondisk = kvmalloc(btree_buf_bytes(b), GFP_KERNEL); in __bch2_btree_verify()
142 if (!c->verify_ondisk) in __bch2_btree_verify()
146 if (!c->verify_data) { in __bch2_btree_verify()
147 c->verify_data = __bch2_btree_node_mem_alloc(c); in __bch2_btree_verify()
148 if (!c->verify_data) in __bch2_btree_verify()
151 list_del_init(&c->verify_data->list); in __bch2_btree_verify()
154 BUG_ON(b->nsets != 1); in __bch2_btree_verify()
156 for (k = inmemory->start; k != vstruct_last(inmemory); k = bkey_p_next(k)) in __bch2_btree_verify()
157 if (k->type == KEY_TYPE_btree_ptr_v2) in __bch2_btree_verify()
158 ((struct bch_btree_ptr_v2 *) bkeyp_val(&b->format, k))->mem_ptr = 0; in __bch2_btree_verify()
160 v = c->verify_data; in __bch2_btree_verify()
161 bkey_copy(&v->key, &b->key); in __bch2_btree_verify()
162 v->c.level = b->c.level; in __bch2_btree_verify()
163 v->c.btree_id = b->c.btree_id; in __bch2_btree_verify()
166 ptrs = bch2_bkey_ptrs_c(bkey_i_to_s_c(&b->key)); in __bch2_btree_verify()
167 bkey_for_each_ptr_decode(&b->key.k, ptrs, p, entry) in __bch2_btree_verify()
173 bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key)); in __bch2_btree_verify()
178 mutex_unlock(&c->verify_lock); in __bch2_btree_verify()
192 if (bch2_bkey_pick_read_device(c, bkey_i_to_s_c(&b->key), NULL, &pick) <= 0) { in bch2_btree_node_ondisk_to_text()
209 bio = bio_alloc_bioset(ca->disk_sb.bdev, in bch2_btree_node_ondisk_to_text()
213 &c->btree_bio); in bch2_btree_node_ondisk_to_text()
214 bio->bi_iter.bi_sector = pick.ptr.offset; in bch2_btree_node_ondisk_to_text()
231 i = &n_ondisk->keys; in bch2_btree_node_ondisk_to_text()
242 if (bch2_crc_cmp(csum, n_ondisk->csum)) { in bch2_btree_node_ondisk_to_text()
249 sectors = vstruct_sectors(n_ondisk, c->block_bits); in bch2_btree_node_ondisk_to_text()
253 i = &bne->keys; in bch2_btree_node_ondisk_to_text()
255 if (i->seq != n_ondisk->keys.seq) in bch2_btree_node_ondisk_to_text()
267 if (bch2_crc_cmp(csum, bne->csum)) { in bch2_btree_node_ondisk_to_text()
274 sectors = vstruct_sectors(bne, c->block_bits); in bch2_btree_node_ondisk_to_text()
279 le16_to_cpu(i->version), in bch2_btree_node_ondisk_to_text()
280 le64_to_cpu(i->journal_seq)); in bch2_btree_node_ondisk_to_text()
285 for (k = i->start; k != vstruct_last(i); k = bkey_p_next(k)) { in bch2_btree_node_ondisk_to_text()
298 percpu_ref_put(&ca->io_ref); in bch2_btree_node_ondisk_to_text()
321 if (i->buf.pos) { in flush_buf()
322 size_t bytes = min_t(size_t, i->buf.pos, i->size); in flush_buf()
323 int copied = bytes - copy_to_user(i->ubuf, i->buf.buf, bytes); in flush_buf()
325 i->ret += copied; in flush_buf()
326 i->ubuf += copied; in flush_buf()
327 i->size -= copied; in flush_buf()
328 i->buf.pos -= copied; in flush_buf()
329 memmove(i->buf.buf, i->buf.buf + copied, i->buf.pos); in flush_buf()
332 return -EFAULT; in flush_buf()
335 return i->size ? 0 : i->ret; in flush_buf()
340 struct btree_debug *bd = inode->i_private; in bch2_dump_open()
345 return -ENOMEM; in bch2_dump_open()
347 file->private_data = i; in bch2_dump_open()
348 i->from = POS_MIN; in bch2_dump_open()
349 i->iter = 0; in bch2_dump_open()
350 i->c = container_of(bd, struct bch_fs, btree_debug[bd->id]); in bch2_dump_open()
351 i->id = bd->id; in bch2_dump_open()
352 i->buf = PRINTBUF; in bch2_dump_open()
359 struct dump_iter *i = file->private_data; in bch2_dump_release()
361 printbuf_exit(&i->buf); in bch2_dump_release()
369 struct dump_iter *i = file->private_data; in bch2_read_btree()
371 i->ubuf = buf; in bch2_read_btree()
372 i->size = size; in bch2_read_btree()
373 i->ret = 0; in bch2_read_btree()
376 bch2_trans_run(i->c, in bch2_read_btree()
377 for_each_btree_key(trans, iter, i->id, i->from, in bch2_read_btree()
380 bch2_bkey_val_to_text(&i->buf, i->c, k); in bch2_read_btree()
381 prt_newline(&i->buf); in bch2_read_btree()
383 i->from = bpos_successor(iter.pos); in bch2_read_btree()
386 i->ret; in bch2_read_btree()
392 .release = bch2_dump_release,
399 struct dump_iter *i = file->private_data; in bch2_read_btree_formats()
401 i->ubuf = buf; in bch2_read_btree_formats()
402 i->size = size; in bch2_read_btree_formats()
403 i->ret = 0; in bch2_read_btree_formats()
409 if (bpos_eq(SPOS_MAX, i->from)) in bch2_read_btree_formats()
410 return i->ret; in bch2_read_btree_formats()
412 return bch2_trans_run(i->c, in bch2_read_btree_formats()
413 for_each_btree_node(trans, iter, i->id, i->from, 0, b, ({ in bch2_read_btree_formats()
414 bch2_btree_node_to_text(&i->buf, i->c, b); in bch2_read_btree_formats()
415 i->from = !bpos_eq(SPOS_MAX, b->key.k.p) in bch2_read_btree_formats()
416 ? bpos_successor(b->key.k.p) in bch2_read_btree_formats()
417 : b->key.k.p; in bch2_read_btree_formats()
420 }))) ?: i->ret; in bch2_read_btree_formats()
426 .release = bch2_dump_release,
433 struct dump_iter *i = file->private_data; in bch2_read_bfloat_failed()
435 i->ubuf = buf; in bch2_read_bfloat_failed()
436 i->size = size; in bch2_read_bfloat_failed()
437 i->ret = 0; in bch2_read_bfloat_failed()
440 bch2_trans_run(i->c, in bch2_read_bfloat_failed()
441 for_each_btree_key(trans, iter, i->id, i->from, in bch2_read_bfloat_failed()
445 &btree_iter_path(trans, &iter)->l[0]; in bch2_read_bfloat_failed()
447 bch2_btree_node_iter_peek(&l->iter, l->b); in bch2_read_bfloat_failed()
449 if (bpos_gt(l->b->key.k.p, i->prev_node)) { in bch2_read_bfloat_failed()
450 bch2_btree_node_to_text(&i->buf, i->c, l->b); in bch2_read_bfloat_failed()
451 i->prev_node = l->b->key.k.p; in bch2_read_bfloat_failed()
454 bch2_bfloat_to_text(&i->buf, l->b, _k); in bch2_read_bfloat_failed()
456 i->from = bpos_successor(iter.pos); in bch2_read_bfloat_failed()
459 i->ret; in bch2_read_bfloat_failed()
465 .release = bch2_dump_release,
472 if (!out->nr_tabstops) in bch2_cached_btree_node_to_text()
475 prt_printf(out, "%px btree=%s l=%u\n", b, bch2_btree_id_str(b->c.btree_id), b->c.level); in bch2_cached_btree_node_to_text()
479 bch2_bkey_val_to_text(out, c, bkey_i_to_s_c(&b->key)); in bch2_cached_btree_node_to_text()
483 prt_bitflags(out, bch2_btree_node_flags, b->flags); in bch2_cached_btree_node_to_text()
486 prt_printf(out, "pcpu read locks:\t%u\n", b->c.lock.readers != NULL); in bch2_cached_btree_node_to_text()
487 prt_printf(out, "written:\t%u\n", b->written); in bch2_cached_btree_node_to_text()
488 prt_printf(out, "writes blocked:\t%u\n", !list_empty_careful(&b->write_blocked)); in bch2_cached_btree_node_to_text()
489 prt_printf(out, "will make reachable:\t%lx\n", b->will_make_reachable); in bch2_cached_btree_node_to_text()
492 &b->writes[0].journal, b->writes[0].journal.seq); in bch2_cached_btree_node_to_text()
494 &b->writes[1].journal, b->writes[1].journal.seq); in bch2_cached_btree_node_to_text()
502 struct dump_iter *i = file->private_data; in bch2_cached_btree_nodes_read()
503 struct bch_fs *c = i->c; in bch2_cached_btree_nodes_read()
507 i->ubuf = buf; in bch2_cached_btree_nodes_read()
508 i->size = size; in bch2_cached_btree_nodes_read()
509 i->ret = 0; in bch2_cached_btree_nodes_read()
521 i->buf.atomic++; in bch2_cached_btree_nodes_read()
522 tbl = rht_dereference_rcu(c->btree_cache.table.tbl, in bch2_cached_btree_nodes_read()
523 &c->btree_cache.table); in bch2_cached_btree_nodes_read()
524 if (i->iter < tbl->size) { in bch2_cached_btree_nodes_read()
525 rht_for_each_entry_rcu(b, pos, tbl, i->iter, hash) in bch2_cached_btree_nodes_read()
526 bch2_cached_btree_node_to_text(&i->buf, c, b); in bch2_cached_btree_nodes_read()
527 i->iter++; in bch2_cached_btree_nodes_read()
531 --i->buf.atomic; in bch2_cached_btree_nodes_read()
535 if (i->buf.allocation_failure) in bch2_cached_btree_nodes_read()
536 ret = -ENOMEM; in bch2_cached_btree_nodes_read()
541 return ret ?: i->ret; in bch2_cached_btree_nodes_read()
547 .release = bch2_dump_release,
559 cmp(pos, pos->next) > 0) { in list_sort()
560 struct list_head *pos2, *next = pos->next; in list_sort()
580 struct dump_iter *i = file->private_data; in bch2_btree_transactions_read()
581 struct bch_fs *c = i->c; in bch2_btree_transactions_read()
585 i->ubuf = buf; in bch2_btree_transactions_read()
586 i->size = size; in bch2_btree_transactions_read()
587 i->ret = 0; in bch2_btree_transactions_read()
589 seqmutex_lock(&c->btree_trans_lock); in bch2_btree_transactions_read()
590 list_sort(&c->btree_trans_list, list_ptr_order_cmp); in bch2_btree_transactions_read()
592 list_for_each_entry(trans, &c->btree_trans_list, list) { in bch2_btree_transactions_read()
593 if ((ulong) trans <= i->iter) in bch2_btree_transactions_read()
596 i->iter = (ulong) trans; in bch2_btree_transactions_read()
598 if (!closure_get_not_zero(&trans->ref)) in bch2_btree_transactions_read()
601 u32 seq = seqmutex_unlock(&c->btree_trans_lock); in bch2_btree_transactions_read()
603 bch2_btree_trans_to_text(&i->buf, trans); in bch2_btree_transactions_read()
605 prt_printf(&i->buf, "backtrace:\n"); in bch2_btree_transactions_read()
606 printbuf_indent_add(&i->buf, 2); in bch2_btree_transactions_read()
607 bch2_prt_task_backtrace(&i->buf, trans->locking_wait.task, 0, GFP_KERNEL); in bch2_btree_transactions_read()
608 printbuf_indent_sub(&i->buf, 2); in bch2_btree_transactions_read()
609 prt_newline(&i->buf); in bch2_btree_transactions_read()
611 closure_put(&trans->ref); in bch2_btree_transactions_read()
617 if (!seqmutex_relock(&c->btree_trans_lock, seq)) in bch2_btree_transactions_read()
620 seqmutex_unlock(&c->btree_trans_lock); in bch2_btree_transactions_read()
622 if (i->buf.allocation_failure) in bch2_btree_transactions_read()
623 ret = -ENOMEM; in bch2_btree_transactions_read()
628 return ret ?: i->ret; in bch2_btree_transactions_read()
634 .release = bch2_dump_release,
641 struct dump_iter *i = file->private_data; in bch2_journal_pins_read()
642 struct bch_fs *c = i->c; in bch2_journal_pins_read()
646 i->ubuf = buf; in bch2_journal_pins_read()
647 i->size = size; in bch2_journal_pins_read()
648 i->ret = 0; in bch2_journal_pins_read()
655 if (!i->size) in bch2_journal_pins_read()
661 done = bch2_journal_seq_pins_to_text(&i->buf, &c->journal, &i->iter); in bch2_journal_pins_read()
662 i->iter++; in bch2_journal_pins_read()
665 if (i->buf.allocation_failure) in bch2_journal_pins_read()
666 return -ENOMEM; in bch2_journal_pins_read()
668 return i->ret; in bch2_journal_pins_read()
674 .release = bch2_dump_release,
681 struct dump_iter *i = file->private_data; in bch2_btree_updates_read()
682 struct bch_fs *c = i->c; in bch2_btree_updates_read()
685 i->ubuf = buf; in bch2_btree_updates_read()
686 i->size = size; in bch2_btree_updates_read()
687 i->ret = 0; in bch2_btree_updates_read()
689 if (!i->iter) { in bch2_btree_updates_read()
690 bch2_btree_updates_to_text(&i->buf, c); in bch2_btree_updates_read()
691 i->iter++; in bch2_btree_updates_read()
698 if (i->buf.allocation_failure) in bch2_btree_updates_read()
699 return -ENOMEM; in bch2_btree_updates_read()
701 return i->ret; in bch2_btree_updates_read()
707 .release = bch2_dump_release,
713 struct bch_fs *c = inode->i_private; in btree_transaction_stats_open()
718 return -ENOMEM; in btree_transaction_stats_open()
720 i->iter = 1; in btree_transaction_stats_open()
721 i->c = c; in btree_transaction_stats_open()
722 i->buf = PRINTBUF; in btree_transaction_stats_open()
723 file->private_data = i; in btree_transaction_stats_open()
730 struct dump_iter *i = file->private_data; in btree_transaction_stats_release()
732 printbuf_exit(&i->buf); in btree_transaction_stats_release()
741 struct dump_iter *i = file->private_data; in btree_transaction_stats_read()
742 struct bch_fs *c = i->c; in btree_transaction_stats_read()
745 i->ubuf = buf; in btree_transaction_stats_read()
746 i->size = size; in btree_transaction_stats_read()
747 i->ret = 0; in btree_transaction_stats_read()
750 struct btree_transaction_stats *s = &c->btree_transaction_stats[i->iter]; in btree_transaction_stats_read()
756 if (!i->size) in btree_transaction_stats_read()
759 if (i->iter == ARRAY_SIZE(bch2_btree_transaction_fns) || in btree_transaction_stats_read()
760 !bch2_btree_transaction_fns[i->iter]) in btree_transaction_stats_read()
763 prt_printf(&i->buf, "%s:\n", bch2_btree_transaction_fns[i->iter]); in btree_transaction_stats_read()
764 printbuf_indent_add(&i->buf, 2); in btree_transaction_stats_read()
766 mutex_lock(&s->lock); in btree_transaction_stats_read()
768 prt_printf(&i->buf, "Max mem used: %u\n", s->max_mem); in btree_transaction_stats_read()
769 prt_printf(&i->buf, "Transaction duration:\n"); in btree_transaction_stats_read()
771 printbuf_indent_add(&i->buf, 2); in btree_transaction_stats_read()
772 bch2_time_stats_to_text(&i->buf, &s->duration); in btree_transaction_stats_read()
773 printbuf_indent_sub(&i->buf, 2); in btree_transaction_stats_read()
776 prt_printf(&i->buf, "Lock hold times:\n"); in btree_transaction_stats_read()
778 printbuf_indent_add(&i->buf, 2); in btree_transaction_stats_read()
779 bch2_time_stats_to_text(&i->buf, &s->lock_hold_times); in btree_transaction_stats_read()
780 printbuf_indent_sub(&i->buf, 2); in btree_transaction_stats_read()
783 if (s->max_paths_text) { in btree_transaction_stats_read()
784 prt_printf(&i->buf, "Maximum allocated btree paths (%u):\n", s->nr_max_paths); in btree_transaction_stats_read()
786 printbuf_indent_add(&i->buf, 2); in btree_transaction_stats_read()
787 prt_str_indented(&i->buf, s->max_paths_text); in btree_transaction_stats_read()
788 printbuf_indent_sub(&i->buf, 2); in btree_transaction_stats_read()
791 mutex_unlock(&s->lock); in btree_transaction_stats_read()
793 printbuf_indent_sub(&i->buf, 2); in btree_transaction_stats_read()
794 prt_newline(&i->buf); in btree_transaction_stats_read()
795 i->iter++; in btree_transaction_stats_read()
798 if (i->buf.allocation_failure) in btree_transaction_stats_read()
799 return -ENOMEM; in btree_transaction_stats_read()
801 return i->ret; in btree_transaction_stats_read()
807 .release = btree_transaction_stats_release,
817 seqmutex_lock(&c->btree_trans_lock); in btree_deadlock_to_text()
818 list_sort(&c->btree_trans_list, list_ptr_order_cmp); in btree_deadlock_to_text()
820 list_for_each_entry(trans, &c->btree_trans_list, list) { in btree_deadlock_to_text()
826 if (!closure_get_not_zero(&trans->ref)) in btree_deadlock_to_text()
829 u32 seq = seqmutex_unlock(&c->btree_trans_lock); in btree_deadlock_to_text()
833 closure_put(&trans->ref); in btree_deadlock_to_text()
838 if (!seqmutex_relock(&c->btree_trans_lock, seq)) in btree_deadlock_to_text()
841 seqmutex_unlock(&c->btree_trans_lock); in btree_deadlock_to_text()
847 struct dump_iter *i = file->private_data; in bch2_btree_deadlock_read()
848 struct bch_fs *c = i->c; in bch2_btree_deadlock_read()
851 i->ubuf = buf; in bch2_btree_deadlock_read()
852 i->size = size; in bch2_btree_deadlock_read()
853 i->ret = 0; in bch2_btree_deadlock_read()
855 if (!i->iter) { in bch2_btree_deadlock_read()
856 btree_deadlock_to_text(&i->buf, c); in bch2_btree_deadlock_read()
857 i->iter++; in bch2_btree_deadlock_read()
860 if (i->buf.allocation_failure) in bch2_btree_deadlock_read()
861 ret = -ENOMEM; in bch2_btree_deadlock_read()
866 return ret ?: i->ret; in bch2_btree_deadlock_read()
872 .release = bch2_dump_release,
878 if (!IS_ERR_OR_NULL(c->fs_debug_dir)) in bch2_fs_debug_exit()
879 debugfs_remove_recursive(c->fs_debug_dir); in bch2_fs_debug_exit()
886 d = debugfs_create_dir(bch2_btree_id_str(bd->id), c->btree_debug_dir); in bch2_fs_debug_btree_init()
892 debugfs_create_file("bfloat-failed", 0400, d, bd, in bch2_fs_debug_btree_init()
904 snprintf(name, sizeof(name), "%pU", c->sb.user_uuid.b); in bch2_fs_debug_init()
905 c->fs_debug_dir = debugfs_create_dir(name, bch_debug); in bch2_fs_debug_init()
906 if (IS_ERR_OR_NULL(c->fs_debug_dir)) in bch2_fs_debug_init()
909 debugfs_create_file("cached_btree_nodes", 0400, c->fs_debug_dir, in bch2_fs_debug_init()
910 c->btree_debug, &cached_btree_nodes_ops); in bch2_fs_debug_init()
912 debugfs_create_file("btree_transactions", 0400, c->fs_debug_dir, in bch2_fs_debug_init()
913 c->btree_debug, &btree_transactions_ops); in bch2_fs_debug_init()
915 debugfs_create_file("journal_pins", 0400, c->fs_debug_dir, in bch2_fs_debug_init()
916 c->btree_debug, &journal_pins_ops); in bch2_fs_debug_init()
918 debugfs_create_file("btree_updates", 0400, c->fs_debug_dir, in bch2_fs_debug_init()
919 c->btree_debug, &btree_updates_ops); in bch2_fs_debug_init()
921 debugfs_create_file("btree_transaction_stats", 0400, c->fs_debug_dir, in bch2_fs_debug_init()
924 debugfs_create_file("btree_deadlock", 0400, c->fs_debug_dir, in bch2_fs_debug_init()
925 c->btree_debug, &btree_deadlock_ops); in bch2_fs_debug_init()
927 c->btree_debug_dir = debugfs_create_dir("btrees", c->fs_debug_dir); in bch2_fs_debug_init()
928 if (IS_ERR_OR_NULL(c->btree_debug_dir)) in bch2_fs_debug_init()
931 for (bd = c->btree_debug; in bch2_fs_debug_init()
932 bd < c->btree_debug + ARRAY_SIZE(c->btree_debug); in bch2_fs_debug_init()
934 bd->id = bd - c->btree_debug; in bch2_fs_debug_init()