Lines Matching full:k
71 static inline void accounting_key_init(struct bkey_i *k, struct disk_accounting_pos *pos, in accounting_key_init() argument
74 struct bkey_i_accounting *acc = bkey_accounting_init(k); in accounting_key_init()
76 acc->k.p = disk_accounting_pos_to_bpos(pos); in accounting_key_init()
77 set_bkey_val_u64s(&acc->k, sizeof(struct bch_accounting) / sizeof(u64) + nr); in accounting_key_init()
83 struct disk_accounting_pos *k, in bch2_disk_accounting_mod() argument
87 switch (k->type) { in bch2_disk_accounting_mod()
89 bubble_sort(k->replicas.devs, k->replicas.nr_devs, u8_cmp); in bch2_disk_accounting_mod()
95 struct { __BKEY_PADDED(k, BCH_ACCOUNTING_MAX_COUNTERS); } k_i; in bch2_disk_accounting_mod()
97 accounting_key_init(&k_i.k, k, d, nr); in bch2_disk_accounting_mod()
100 ? bch2_trans_update_buffered(trans, BTREE_ID_accounting, &k_i.k) in bch2_disk_accounting_mod()
101 : bch2_accounting_mem_add(trans, bkey_i_to_s_c_accounting(&k_i.k), true); in bch2_disk_accounting_mod()
129 int bch2_accounting_validate(struct bch_fs *c, struct bkey_s_c k, in bch2_accounting_validate() argument
133 bpos_to_disk_accounting_pos(&acc_k, k.k->p); in bch2_accounting_validate()
137 bkey_fsck_err_on(bversion_zero(k.k->bversion), in bch2_accounting_validate()
190 void bch2_accounting_key_to_text(struct printbuf *out, struct disk_accounting_pos *k) in bch2_accounting_key_to_text() argument
192 if (k->type >= BCH_DISK_ACCOUNTING_TYPE_NR) { in bch2_accounting_key_to_text()
193 prt_printf(out, "unknown type %u", k->type); in bch2_accounting_key_to_text()
197 prt_str(out, disk_accounting_type_strs[k->type]); in bch2_accounting_key_to_text()
200 switch (k->type) { in bch2_accounting_key_to_text()
204 prt_printf(out, "replicas=%u", k->persistent_reserved.nr_replicas); in bch2_accounting_key_to_text()
207 bch2_replicas_entry_to_text(out, &k->replicas); in bch2_accounting_key_to_text()
210 prt_printf(out, "dev=%u data_type=", k->dev_data_type.dev); in bch2_accounting_key_to_text()
211 bch2_prt_data_type(out, k->dev_data_type.data_type); in bch2_accounting_key_to_text()
214 bch2_prt_compression_type(out, k->compression.type); in bch2_accounting_key_to_text()
217 prt_printf(out, "id=%u", k->snapshot.id); in bch2_accounting_key_to_text()
220 prt_printf(out, "btree=%s", bch2_btree_id_str(k->btree.id)); in bch2_accounting_key_to_text()
225 void bch2_accounting_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c k) in bch2_accounting_to_text() argument
227 struct bkey_s_c_accounting acc = bkey_s_c_to_accounting(k); in bch2_accounting_to_text()
229 bpos_to_disk_accounting_pos(&acc_k, k.k->p); in bch2_accounting_to_text()
233 for (unsigned i = 0; i < bch2_accounting_counters(k.k); i++) in bch2_accounting_to_text()
237 void bch2_accounting_swab(struct bkey_s k) in bch2_accounting_swab() argument
239 for (u64 *p = (u64 *) k.v; in bch2_accounting_swab()
240 p < (u64 *) bkey_val_end(k); in bch2_accounting_swab()
284 if (jset_entry_is_key(i) && i->start->k.type == KEY_TYPE_accounting) { in bch2_accounting_update_sb()
285 int ret = bch2_accounting_update_sb_one(trans->c, i->start->k.p); in bch2_accounting_update_sb()
298 if (eytzinger0_find(acc->k.data, acc->k.nr, sizeof(acc->k.data[0]), in __bch2_accounting_mem_insert()
299 accounting_pos_cmp, &a.k->p) < acc->k.nr) in __bch2_accounting_mem_insert()
303 .pos = a.k->p, in __bch2_accounting_mem_insert()
304 .bversion = a.k->bversion, in __bch2_accounting_mem_insert()
305 .nr_counters = bch2_accounting_counters(a.k), in __bch2_accounting_mem_insert()
320 if (darray_push(&acc->k, n)) in __bch2_accounting_mem_insert()
323 eytzinger0_sort(acc->k.data, acc->k.nr, sizeof(acc->k.data[0]), in __bch2_accounting_mem_insert()
338 accounting_to_replicas(&r.e, a.k->p) && in bch2_accounting_mem_insert()
365 struct accounting_mem_entry *dst = acc->k.data; in bch2_accounting_mem_gc()
367 darray_for_each(acc->k, src) { in bch2_accounting_mem_gc()
376 acc->k.nr = dst - acc->k.data; in bch2_accounting_mem_gc()
377 eytzinger0_sort(acc->k.data, acc->k.nr, sizeof(acc->k.data[0]), in bch2_accounting_mem_gc()
398 darray_for_each(acc->k, i) { in bch2_fs_replicas_usage_read()
408 bch2_accounting_mem_read_counters(acc, i - acc->k.data, §ors, 1, false); in bch2_fs_replicas_usage_read()
434 darray_for_each(acc->k, i) { in bch2_fs_accounting_read()
448 set_bkey_val_u64s(&a_out->k, i->nr_counters); in bch2_fs_accounting_read()
449 a_out->k.p = i->pos; in bch2_fs_accounting_read()
450 bch2_accounting_mem_read_counters(acc, i - acc->k.data, in bch2_fs_accounting_read()
454 out_buf->nr += bkey_bytes(&a_out->k); in bch2_fs_accounting_read()
471 eytzinger0_for_each(i, acc->k.nr) { in bch2_fs_accounting_to_text()
473 bpos_to_disk_accounting_pos(&acc_k, acc->k.data[i].pos); in bch2_fs_accounting_to_text()
481 for (unsigned j = 0; j < acc->k.data[i].nr_counters; j++) in bch2_fs_accounting_to_text()
492 darray_for_each(acc->k, e) { in bch2_accounting_free_counters()
504 darray_for_each(acc->k, e) { in bch2_gc_accounting_start()
530 unsigned idx = eytzinger0_find_ge(acc->k.data, acc->k.nr, sizeof(acc->k.data[0]), in bch2_gc_accounting_done()
533 if (idx >= acc->k.nr) in bch2_gc_accounting_done()
536 struct accounting_mem_entry *e = acc->k.data + idx; in bch2_gc_accounting_done()
578 struct { __BKEY_PADDED(k, BCH_ACCOUNTING_MAX_COUNTERS); } k_i; in bch2_gc_accounting_done()
580 accounting_key_init(&k_i.k, &acc_k, src_v, nr); in bch2_gc_accounting_done()
582 bkey_i_to_s_c_accounting(&k_i.k), in bch2_gc_accounting_done()
603 static int accounting_read_key(struct btree_trans *trans, struct bkey_s_c k) in accounting_read_key() argument
607 if (k.k->type != KEY_TYPE_accounting) in accounting_read_key()
611 int ret = bch2_accounting_mem_mod_locked(trans, bkey_s_c_to_accounting(k), in accounting_read_key()
704 BTREE_ITER_prefetch|BTREE_ITER_all_snapshots, k, ({ in bch2_accounting_read()
706 struct bkey_s_c k = bch2_btree_path_peek_slot_exact(btree_iter_path(trans, &iter), &u); in bch2_accounting_read()
707 accounting_read_key(trans, k); in bch2_accounting_read()
717 if (i->k->k.type == KEY_TYPE_accounting) { in bch2_accounting_read()
718 struct bkey_s_c k = bkey_i_to_s_c(i->k); in bch2_accounting_read() local
719 unsigned idx = eytzinger0_find(acc->k.data, acc->k.nr, in bch2_accounting_read()
720 sizeof(acc->k.data[0]), in bch2_accounting_read()
721 accounting_pos_cmp, &k.k->p); in bch2_accounting_read()
723 bool applied = idx < acc->k.nr && in bch2_accounting_read()
724 bversion_cmp(acc->k.data[idx].bversion, k.k->bversion) >= 0; in bch2_accounting_read()
730 i[1].k->k.type == KEY_TYPE_accounting && in bch2_accounting_read()
732 WARN_ON(bversion_cmp(i[0].k->k.bversion, i[1].k->k.bversion) >= 0); in bch2_accounting_read()
736 bch2_accounting_accumulate(bkey_i_to_accounting(i[1].k), in bch2_accounting_read()
737 bkey_s_c_to_accounting(k)); in bch2_accounting_read()
741 ret = accounting_read_key(trans, k); in bch2_accounting_read()
752 while (i < acc->k.nr) { in bch2_accounting_read()
753 unsigned idx = inorder_to_eytzinger0(i, acc->k.nr); in bch2_accounting_read()
756 bpos_to_disk_accounting_pos(&acc_k, acc->k.data[idx].pos); in bch2_accounting_read()
768 ret = bch2_is_zero(v, sizeof(v[0]) * acc->k.data[idx].nr_counters) in bch2_accounting_read()
771 v, acc->k.data[idx].nr_counters); in bch2_accounting_read()
774 free_percpu(acc->k.data[idx].v[0]); in bch2_accounting_read()
775 free_percpu(acc->k.data[idx].v[1]); in bch2_accounting_read()
776 darray_remove_item(&acc->k, &acc->k.data[idx]); in bch2_accounting_read()
777 eytzinger0_sort(acc->k.data, acc->k.nr, sizeof(acc->k.data[0]), in bch2_accounting_read()
791 for (unsigned i = 0; i < acc->k.nr; i++) { in bch2_accounting_read()
792 struct disk_accounting_pos k; in bch2_accounting_read() local
793 bpos_to_disk_accounting_pos(&k, acc->k.data[i].pos); in bch2_accounting_read()
798 switch (k.type) { in bch2_accounting_read()
800 usage->reserved += v[0] * k.persistent_reserved.nr_replicas; in bch2_accounting_read()
803 fs_usage_data_type_to_base(usage, k.replicas.data_type, v[0]); in bch2_accounting_read()
807 struct bch_dev *ca = bch2_dev_rcu(c, k.dev_data_type.dev); in bch2_accounting_read()
809 struct bch_dev_usage_type __percpu *d = &ca->usage->d[k.dev_data_type.data_type]; in bch2_accounting_read()
814 if (k.dev_data_type.data_type == BCH_DATA_sb || in bch2_accounting_read()
815 k.dev_data_type.data_type == BCH_DATA_journal) in bch2_accounting_read()
837 BTREE_ITER_all_snapshots, k, NULL, NULL, 0, ({ in bch2_dev_usage_remove()
839 bpos_to_disk_accounting_pos(&acc, k.k->p); in bch2_dev_usage_remove()
843 ? bch2_btree_bit_mod_buffered(trans, BTREE_ID_accounting, k.k->p, 0) in bch2_dev_usage_remove()
875 BTREE_ITER_all_snapshots, k, ({ in bch2_verify_accounting_clean()
877 struct bkey_s_c_accounting a = bkey_s_c_to_accounting(k); in bch2_verify_accounting_clean()
878 unsigned nr = bch2_accounting_counters(k.k); in bch2_verify_accounting_clean()
881 bpos_to_disk_accounting_pos(&acc_k, k.k->p); in bch2_verify_accounting_clean()
889 bch2_accounting_mem_read(c, k.k->p, v, nr); in bch2_verify_accounting_clean()
894 bch2_bkey_val_to_text(&buf, c, k); in bch2_verify_accounting_clean()
927 bch2_bkey_val_to_text(&buf, c, k); in bch2_verify_accounting_clean()
975 darray_exit(&acc->k); in bch2_fs_accounting_exit()