Lines Matching full:k

104 int bch2_bkey_pick_read_device(struct bch_fs *c, struct bkey_s_c k,  in bch2_bkey_pick_read_device()  argument
108 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_pick_read_device()
115 if (k.k->type == KEY_TYPE_error) in bch2_bkey_pick_read_device()
118 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) { in bch2_bkey_pick_read_device()
167 int bch2_btree_ptr_invalid(struct bch_fs *c, struct bkey_s_c k, in bch2_btree_ptr_invalid() argument
173 bkey_fsck_err_on(bkey_val_u64s(k.k) > BCH_REPLICAS_MAX, c, err, in bch2_btree_ptr_invalid()
175 "value too big (%zu > %u)", bkey_val_u64s(k.k), BCH_REPLICAS_MAX); in bch2_btree_ptr_invalid()
177 ret = bch2_bkey_ptrs_invalid(c, k, flags, err); in bch2_btree_ptr_invalid()
183 struct bkey_s_c k) in bch2_btree_ptr_to_text() argument
185 bch2_bkey_ptrs_to_text(out, c, k); in bch2_btree_ptr_to_text()
188 int bch2_btree_ptr_v2_invalid(struct bch_fs *c, struct bkey_s_c k, in bch2_btree_ptr_v2_invalid() argument
194 bkey_fsck_err_on(bkey_val_u64s(k.k) > BKEY_BTREE_PTR_VAL_U64s_MAX, c, err, in bch2_btree_ptr_v2_invalid()
197 bkey_val_u64s(k.k), BKEY_BTREE_PTR_VAL_U64s_MAX); in bch2_btree_ptr_v2_invalid()
199 ret = bch2_bkey_ptrs_invalid(c, k, flags, err); in bch2_btree_ptr_v2_invalid()
205 struct bkey_s_c k) in bch2_btree_ptr_v2_to_text() argument
207 struct bkey_s_c_btree_ptr_v2 bp = bkey_s_c_to_btree_ptr_v2(k); in bch2_btree_ptr_v2_to_text()
216 bch2_bkey_ptrs_to_text(out, c, k); in bch2_btree_ptr_v2_to_text()
221 struct bkey_s k) in bch2_btree_ptr_v2_compat() argument
223 struct bkey_s_btree_ptr_v2 bp = bkey_s_to_btree_ptr_v2(k); in bch2_btree_ptr_v2_compat()
262 lp.crc = bch2_extent_crc_unpack(l.k, NULL); in bch2_extent_merge()
263 rp.crc = bch2_extent_crc_unpack(r.k, NULL); in bch2_extent_merge()
265 while (__bkey_ptr_next_decode(l.k, l_ptrs.end, lp, en_l) && in bch2_extent_merge()
266 __bkey_ptr_next_decode(r.k, r_ptrs.end, rp, en_r)) { in bch2_extent_merge()
322 struct bch_extent_crc_unpacked crc_l = bch2_extent_crc_unpack(l.k, entry_to_crc(en_l)); in bch2_extent_merge()
323 struct bch_extent_crc_unpacked crc_r = bch2_extent_crc_unpack(r.k, entry_to_crc(en_r)); in bch2_extent_merge()
344 bch2_extent_crc_unpack(l.k, entry_to_crc(en_l)); in bch2_extent_merge()
346 bch2_extent_crc_unpack(r.k, entry_to_crc(en_r)); in bch2_extent_merge()
376 bch2_key_resize(l.k, l.k->size + r.k->size); in bch2_extent_merge()
382 int bch2_reservation_invalid(struct bch_fs *c, struct bkey_s_c k, in bch2_reservation_invalid() argument
386 struct bkey_s_c_reservation r = bkey_s_c_to_reservation(k); in bch2_reservation_invalid()
397 struct bkey_s_c k) in bch2_reservation_to_text() argument
399 struct bkey_s_c_reservation r = bkey_s_c_to_reservation(k); in bch2_reservation_to_text()
415 bch2_key_resize(l.k, l.k->size + r.k->size); in bch2_reservation_merge()
445 bool bch2_can_narrow_extent_crcs(struct bkey_s_c k, in bch2_can_narrow_extent_crcs() argument
448 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_can_narrow_extent_crcs()
455 bkey_for_each_crc(k.k, ptrs, crc, i) in bch2_can_narrow_extent_crcs()
471 bool bch2_bkey_narrow_crcs(struct bkey_i *k, struct bch_extent_crc_unpacked n) in bch2_bkey_narrow_crcs() argument
473 struct bkey_ptrs ptrs = bch2_bkey_ptrs(bkey_i_to_s(k)); in bch2_bkey_narrow_crcs()
481 bkey_for_each_crc(&k->k, ptrs, u, i) in bch2_bkey_narrow_crcs()
493 BUG_ON(n.live_size != k->k.size); in bch2_bkey_narrow_crcs()
496 ptrs = bch2_bkey_ptrs(bkey_i_to_s(k)); in bch2_bkey_narrow_crcs()
498 bkey_for_each_ptr_decode(&k->k, ptrs, p, i) in bch2_bkey_narrow_crcs()
500 bch2_bkey_drop_ptr_noerror(bkey_i_to_s(k), &i->ptr); in bch2_bkey_narrow_crcs()
503 bch2_extent_ptr_decoded_append(k, &p); in bch2_bkey_narrow_crcs()
545 void bch2_extent_crc_append(struct bkey_i *k, in bch2_extent_crc_append() argument
548 struct bkey_ptrs ptrs = bch2_bkey_ptrs(bkey_i_to_s(k)); in bch2_extent_crc_append()
569 k->k.u64s += extent_entry_u64s(ptrs.end); in bch2_extent_crc_append()
571 EBUG_ON(bkey_val_u64s(&k->k) > BKEY_EXTENT_VAL_U64s_MAX); in bch2_extent_crc_append()
576 unsigned bch2_bkey_nr_ptrs(struct bkey_s_c k) in bch2_bkey_nr_ptrs() argument
578 return bch2_bkey_devs(k).nr; in bch2_bkey_nr_ptrs()
581 unsigned bch2_bkey_nr_ptrs_allocated(struct bkey_s_c k) in bch2_bkey_nr_ptrs_allocated() argument
583 return k.k->type == KEY_TYPE_reservation in bch2_bkey_nr_ptrs_allocated()
584 ? bkey_s_c_to_reservation(k).v->nr_replicas in bch2_bkey_nr_ptrs_allocated()
585 : bch2_bkey_dirty_devs(k).nr; in bch2_bkey_nr_ptrs_allocated()
588 unsigned bch2_bkey_nr_ptrs_fully_allocated(struct bkey_s_c k) in bch2_bkey_nr_ptrs_fully_allocated() argument
592 if (k.k->type == KEY_TYPE_reservation) { in bch2_bkey_nr_ptrs_fully_allocated()
593 ret = bkey_s_c_to_reservation(k).v->nr_replicas; in bch2_bkey_nr_ptrs_fully_allocated()
595 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_nr_ptrs_fully_allocated()
599 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) in bch2_bkey_nr_ptrs_fully_allocated()
606 unsigned bch2_bkey_sectors_compressed(struct bkey_s_c k) in bch2_bkey_sectors_compressed() argument
608 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_sectors_compressed()
613 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) in bch2_bkey_sectors_compressed()
620 bool bch2_bkey_is_incompressible(struct bkey_s_c k) in bch2_bkey_is_incompressible() argument
622 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_is_incompressible()
626 bkey_for_each_crc(k.k, ptrs, crc, entry) in bch2_bkey_is_incompressible()
632 unsigned bch2_bkey_replicas(struct bch_fs *c, struct bkey_s_c k) in bch2_bkey_replicas() argument
634 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_replicas()
639 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) { in bch2_bkey_replicas()
680 unsigned bch2_bkey_durability(struct bch_fs *c, struct bkey_s_c k) in bch2_bkey_durability() argument
682 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_durability()
687 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) in bch2_bkey_durability()
693 static unsigned bch2_bkey_durability_safe(struct bch_fs *c, struct bkey_s_c k) in bch2_bkey_durability_safe() argument
695 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_durability_safe()
700 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) in bch2_bkey_durability_safe()
707 void bch2_bkey_extent_entry_drop(struct bkey_i *k, union bch_extent_entry *entry) in bch2_bkey_extent_entry_drop() argument
709 union bch_extent_entry *end = bkey_val_end(bkey_i_to_s(k)); in bch2_bkey_extent_entry_drop()
713 k->k.u64s -= extent_entry_u64s(entry); in bch2_bkey_extent_entry_drop()
716 void bch2_extent_ptr_decoded_append(struct bkey_i *k, in bch2_extent_ptr_decoded_append() argument
719 struct bkey_ptrs ptrs = bch2_bkey_ptrs(bkey_i_to_s(k)); in bch2_extent_ptr_decoded_append()
721 bch2_extent_crc_unpack(&k->k, NULL); in bch2_extent_ptr_decoded_append()
729 bkey_for_each_crc(&k->k, ptrs, crc, pos) in bch2_extent_ptr_decoded_append()
735 bch2_extent_crc_append(k, p->crc); in bch2_extent_ptr_decoded_append()
736 pos = bkey_val_end(bkey_i_to_s(k)); in bch2_extent_ptr_decoded_append()
739 __extent_entry_insert(k, pos, to_entry(&p->ptr)); in bch2_extent_ptr_decoded_append()
743 __extent_entry_insert(k, pos, to_entry(&p->ec)); in bch2_extent_ptr_decoded_append()
763 union bch_extent_entry *bch2_bkey_drop_ptr_noerror(struct bkey_s k, in bch2_bkey_drop_ptr_noerror() argument
766 struct bkey_ptrs ptrs = bch2_bkey_ptrs(k); in bch2_bkey_drop_ptr_noerror()
786 extent_entry_drop(k, entry); in bch2_bkey_drop_ptr_noerror()
795 extent_entry_drop(k, entry); in bch2_bkey_drop_ptr_noerror()
802 union bch_extent_entry *bch2_bkey_drop_ptr(struct bkey_s k, in bch2_bkey_drop_ptr() argument
805 bool have_dirty = bch2_bkey_dirty_devs(k.s_c).nr; in bch2_bkey_drop_ptr()
807 bch2_bkey_drop_ptr_noerror(k, ptr); in bch2_bkey_drop_ptr()
816 !bch2_bkey_dirty_devs(k.s_c).nr) { in bch2_bkey_drop_ptr()
817 k.k->type = KEY_TYPE_error; in bch2_bkey_drop_ptr()
818 set_bkey_val_u64s(k.k, 0); in bch2_bkey_drop_ptr()
820 } else if (!bch2_bkey_nr_ptrs(k.s_c)) { in bch2_bkey_drop_ptr()
821 k.k->type = KEY_TYPE_deleted; in bch2_bkey_drop_ptr()
822 set_bkey_val_u64s(k.k, 0); in bch2_bkey_drop_ptr()
829 void bch2_bkey_drop_device(struct bkey_s k, unsigned dev) in bch2_bkey_drop_device() argument
833 bch2_bkey_drop_ptrs(k, ptr, ptr->dev == dev); in bch2_bkey_drop_device()
836 void bch2_bkey_drop_device_noerror(struct bkey_s k, unsigned dev) in bch2_bkey_drop_device_noerror() argument
838 struct bch_extent_ptr *ptr = bch2_bkey_has_device(k, dev); in bch2_bkey_drop_device_noerror()
841 bch2_bkey_drop_ptr_noerror(k, ptr); in bch2_bkey_drop_device_noerror()
844 const struct bch_extent_ptr *bch2_bkey_has_device_c(struct bkey_s_c k, unsigned dev) in bch2_bkey_has_device_c() argument
846 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_has_device_c()
855 bool bch2_bkey_has_target(struct bch_fs *c, struct bkey_s_c k, unsigned target) in bch2_bkey_has_target() argument
857 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_has_target()
868 bool bch2_bkey_matches_ptr(struct bch_fs *c, struct bkey_s_c k, in bch2_bkey_matches_ptr() argument
871 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_matches_ptr()
875 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) in bch2_bkey_matches_ptr()
878 (s64) p.ptr.offset + p.crc.offset - bkey_start_offset(k.k) == in bch2_bkey_matches_ptr()
890 if (k1.k->type != k2.k->type) in bch2_extents_match()
893 if (bkey_extent_is_direct_data(k1.k)) { in bch2_extents_match()
902 bkey_for_each_ptr_decode(k1.k, ptrs1, p1, entry1) in bch2_extents_match()
903 bkey_for_each_ptr_decode(k2.k, ptrs2, p2, entry2) in bch2_extents_match()
906 (s64) p1.ptr.offset + p1.crc.offset - bkey_start_offset(k1.k) == in bch2_extents_match()
907 (s64) p2.ptr.offset + p2.crc.offset - bkey_start_offset(k2.k)) in bch2_extents_match()
924 bkey_for_each_ptr_decode(k2.k, ptrs2, p2, entry2) in bch2_extent_has_ptr()
927 (s64) p1.ptr.offset + p1.crc.offset - bkey_start_offset(k1.k) == in bch2_extent_has_ptr()
928 (s64) p2.ptr.offset + p2.crc.offset - bkey_start_offset(k2.k)) in bch2_extent_has_ptr()
934 void bch2_extent_ptr_set_cached(struct bkey_s k, struct bch_extent_ptr *ptr) in bch2_extent_ptr_set_cached() argument
936 struct bkey_ptrs ptrs = bch2_bkey_ptrs(k); in bch2_extent_ptr_set_cached()
944 extent_entry_drop(k, ec); in bch2_extent_ptr_set_cached()
960 * Returns true if @k should be dropped entirely
965 bool bch2_extent_normalize(struct bch_fs *c, struct bkey_s k) in bch2_extent_normalize() argument
969 bch2_bkey_drop_ptrs(k, ptr, in bch2_extent_normalize()
973 return bkey_deleted(k.k); in bch2_extent_normalize()
977 struct bkey_s_c k) in bch2_bkey_ptrs_to_text() argument
979 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_ptrs_to_text()
984 prt_printf(out, "durability: %u ", bch2_bkey_durability_safe(c, k)); in bch2_bkey_ptrs_to_text()
1020 bch2_extent_crc_unpack(k.k, entry_to_crc(entry)); in bch2_bkey_ptrs_to_text()
1059 struct bkey_s_c k, in extent_ptr_invalid() argument
1066 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in extent_ptr_invalid()
1107 int bch2_bkey_ptrs_invalid(struct bch_fs *c, struct bkey_s_c k, in bch2_bkey_ptrs_invalid() argument
1111 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_ptrs_invalid()
1114 unsigned size_ondisk = k.k->size; in bch2_bkey_ptrs_invalid()
1120 if (bkey_is_btree_ptr(k.k)) in bch2_bkey_ptrs_invalid()
1129 bkey_fsck_err_on(bkey_is_btree_ptr(k.k) && in bch2_bkey_ptrs_invalid()
1136 ret = extent_ptr_invalid(c, k, flags, &entry->ptr, in bch2_bkey_ptrs_invalid()
1157 crc = bch2_extent_crc_unpack(k.k, entry_to_crc(entry)); in bch2_bkey_ptrs_invalid()
1219 bkey_fsck_err_on(k.k->type != KEY_TYPE_extent && have_unwritten, c, err, in bch2_bkey_ptrs_invalid()
1232 void bch2_ptr_swab(struct bkey_s k) in bch2_ptr_swab() argument
1234 struct bkey_ptrs ptrs = bch2_bkey_ptrs(k); in bch2_ptr_swab()
1270 const struct bch_extent_rebalance *bch2_bkey_rebalance_opts(struct bkey_s_c k) in bch2_bkey_rebalance_opts() argument
1272 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_rebalance_opts()
1282 unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *c, struct bkey_s_c k, in bch2_bkey_ptrs_need_rebalance() argument
1285 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_ptrs_need_rebalance()
1294 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) { in bch2_bkey_ptrs_need_rebalance()
1320 bool bch2_bkey_needs_rebalance(struct bch_fs *c, struct bkey_s_c k) in bch2_bkey_needs_rebalance() argument
1322 const struct bch_extent_rebalance *r = bch2_bkey_rebalance_opts(k); in bch2_bkey_needs_rebalance()
1330 k.k->type == KEY_TYPE_reflink_v && in bch2_bkey_needs_rebalance()
1331 !bch2_bkey_ptrs_need_rebalance(c, k, r->target, r->compression)) in bch2_bkey_needs_rebalance()
1340 struct bkey_s k = bkey_i_to_s(_k); in bch2_bkey_set_needs_rebalance() local
1346 if (!bkey_extent_is_direct_data(k.k)) in bch2_bkey_set_needs_rebalance()
1350 r = (struct bch_extent_rebalance *) bch2_bkey_rebalance_opts(k.s_c); in bch2_bkey_set_needs_rebalance()
1352 if (k.k->type == KEY_TYPE_reflink_v) { in bch2_bkey_set_needs_rebalance()
1369 needs_rebalance = bch2_bkey_ptrs_need_rebalance(c, k.s_c, target, compression); in bch2_bkey_set_needs_rebalance()
1372 union bch_extent_entry *new = bkey_val_end(k); in bch2_bkey_set_needs_rebalance()
1378 k.k->u64s += extent_entry_u64s(new); in bch2_bkey_set_needs_rebalance()
1379 } else if (!needs_rebalance && r && k.k->type != KEY_TYPE_reflink_v) { in bch2_bkey_set_needs_rebalance()
1385 extent_entry_drop(k, (union bch_extent_entry *) r); in bch2_bkey_set_needs_rebalance()
1393 int bch2_cut_front_s(struct bpos where, struct bkey_s k) in bch2_cut_front_s() argument
1395 unsigned new_val_u64s = bkey_val_u64s(k.k); in bch2_cut_front_s()
1399 if (bkey_le(where, bkey_start_pos(k.k))) in bch2_cut_front_s()
1402 EBUG_ON(bkey_gt(where, k.k->p)); in bch2_cut_front_s()
1404 sub = where.offset - bkey_start_offset(k.k); in bch2_cut_front_s()
1406 k.k->size -= sub; in bch2_cut_front_s()
1408 if (!k.k->size) { in bch2_cut_front_s()
1409 k.k->type = KEY_TYPE_deleted; in bch2_cut_front_s()
1413 switch (k.k->type) { in bch2_cut_front_s()
1416 struct bkey_ptrs ptrs = bch2_bkey_ptrs(k); in bch2_cut_front_s()
1448 struct bkey_s_reflink_p p = bkey_s_to_reflink_p(k); in bch2_cut_front_s()
1455 void *p = bkey_inline_data_p(k); in bch2_cut_front_s()
1456 unsigned bytes = bkey_inline_data_bytes(k.k); in bch2_cut_front_s()
1467 val_u64s_delta = bkey_val_u64s(k.k) - new_val_u64s; in bch2_cut_front_s()
1470 set_bkey_val_u64s(k.k, new_val_u64s); in bch2_cut_front_s()
1471 memset(bkey_val_end(k), 0, val_u64s_delta * sizeof(u64)); in bch2_cut_front_s()
1475 int bch2_cut_back_s(struct bpos where, struct bkey_s k) in bch2_cut_back_s() argument
1477 unsigned new_val_u64s = bkey_val_u64s(k.k); in bch2_cut_back_s()
1481 if (bkey_ge(where, k.k->p)) in bch2_cut_back_s()
1484 EBUG_ON(bkey_lt(where, bkey_start_pos(k.k))); in bch2_cut_back_s()
1486 len = where.offset - bkey_start_offset(k.k); in bch2_cut_back_s()
1488 k.k->p.offset = where.offset; in bch2_cut_back_s()
1489 k.k->size = len; in bch2_cut_back_s()
1492 k.k->type = KEY_TYPE_deleted; in bch2_cut_back_s()
1496 switch (k.k->type) { in bch2_cut_back_s()
1499 new_val_u64s = (bkey_inline_data_offset(k.k) + in bch2_cut_back_s()
1500 min(bkey_inline_data_bytes(k.k), k.k->size << 9)) >> 3; in bch2_cut_back_s()
1504 val_u64s_delta = bkey_val_u64s(k.k) - new_val_u64s; in bch2_cut_back_s()
1507 set_bkey_val_u64s(k.k, new_val_u64s); in bch2_cut_back_s()
1508 memset(bkey_val_end(k), 0, val_u64s_delta * sizeof(u64)); in bch2_cut_back_s()