Lines Matching full:k
107 int bch2_bkey_pick_read_device(struct bch_fs *c, struct bkey_s_c k, in bch2_bkey_pick_read_device() argument
111 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_pick_read_device()
117 if (k.k->type == KEY_TYPE_error) in bch2_bkey_pick_read_device()
121 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) { in bch2_bkey_pick_read_device()
171 int bch2_btree_ptr_validate(struct bch_fs *c, struct bkey_s_c k, in bch2_btree_ptr_validate() argument
176 bkey_fsck_err_on(bkey_val_u64s(k.k) > BCH_REPLICAS_MAX, in bch2_btree_ptr_validate()
178 "value too big (%zu > %u)", bkey_val_u64s(k.k), BCH_REPLICAS_MAX); in bch2_btree_ptr_validate()
180 ret = bch2_bkey_ptrs_validate(c, k, flags); in bch2_btree_ptr_validate()
186 struct bkey_s_c k) in bch2_btree_ptr_to_text() argument
188 bch2_bkey_ptrs_to_text(out, c, k); in bch2_btree_ptr_to_text()
191 int bch2_btree_ptr_v2_validate(struct bch_fs *c, struct bkey_s_c k, in bch2_btree_ptr_v2_validate() argument
194 struct bkey_s_c_btree_ptr_v2 bp = bkey_s_c_to_btree_ptr_v2(k); in bch2_btree_ptr_v2_validate()
197 bkey_fsck_err_on(bkey_val_u64s(k.k) > BKEY_BTREE_PTR_VAL_U64s_MAX, in bch2_btree_ptr_v2_validate()
200 bkey_val_u64s(k.k), BKEY_BTREE_PTR_VAL_U64s_MAX); in bch2_btree_ptr_v2_validate()
202 bkey_fsck_err_on(bpos_ge(bp.v->min_key, bp.k->p), in bch2_btree_ptr_v2_validate()
211 ret = bch2_bkey_ptrs_validate(c, k, flags); in bch2_btree_ptr_v2_validate()
217 struct bkey_s_c k) in bch2_btree_ptr_v2_to_text() argument
219 struct bkey_s_c_btree_ptr_v2 bp = bkey_s_c_to_btree_ptr_v2(k); in bch2_btree_ptr_v2_to_text()
228 bch2_bkey_ptrs_to_text(out, c, k); in bch2_btree_ptr_v2_to_text()
233 struct bkey_s k) in bch2_btree_ptr_v2_compat() argument
235 struct bkey_s_btree_ptr_v2 bp = bkey_s_to_btree_ptr_v2(k); in bch2_btree_ptr_v2_compat()
273 lp.crc = bch2_extent_crc_unpack(l.k, NULL); in bch2_extent_merge()
274 rp.crc = bch2_extent_crc_unpack(r.k, NULL); in bch2_extent_merge()
276 while (__bkey_ptr_next_decode(l.k, l_ptrs.end, lp, en_l) && in bch2_extent_merge()
277 __bkey_ptr_next_decode(r.k, r_ptrs.end, rp, en_r)) { in bch2_extent_merge()
337 struct bch_extent_crc_unpacked crc_l = bch2_extent_crc_unpack(l.k, entry_to_crc(en_l)); in bch2_extent_merge()
338 struct bch_extent_crc_unpacked crc_r = bch2_extent_crc_unpack(r.k, entry_to_crc(en_r)); in bch2_extent_merge()
359 bch2_extent_crc_unpack(l.k, entry_to_crc(en_l)); in bch2_extent_merge()
361 bch2_extent_crc_unpack(r.k, entry_to_crc(en_r)); in bch2_extent_merge()
391 bch2_key_resize(l.k, l.k->size + r.k->size); in bch2_extent_merge()
397 int bch2_reservation_validate(struct bch_fs *c, struct bkey_s_c k, in bch2_reservation_validate() argument
400 struct bkey_s_c_reservation r = bkey_s_c_to_reservation(k); in bch2_reservation_validate()
411 struct bkey_s_c k) in bch2_reservation_to_text() argument
413 struct bkey_s_c_reservation r = bkey_s_c_to_reservation(k); in bch2_reservation_to_text()
429 bch2_key_resize(l.k, l.k->size + r.k->size); in bch2_reservation_merge()
459 bool bch2_can_narrow_extent_crcs(struct bkey_s_c k, in bch2_can_narrow_extent_crcs() argument
462 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_can_narrow_extent_crcs()
469 bkey_for_each_crc(k.k, ptrs, crc, i) in bch2_can_narrow_extent_crcs()
485 bool bch2_bkey_narrow_crcs(struct bkey_i *k, struct bch_extent_crc_unpacked n) in bch2_bkey_narrow_crcs() argument
487 struct bkey_ptrs ptrs = bch2_bkey_ptrs(bkey_i_to_s(k)); in bch2_bkey_narrow_crcs()
495 bkey_for_each_crc(&k->k, ptrs, u, i) in bch2_bkey_narrow_crcs()
507 BUG_ON(n.live_size != k->k.size); in bch2_bkey_narrow_crcs()
510 ptrs = bch2_bkey_ptrs(bkey_i_to_s(k)); in bch2_bkey_narrow_crcs()
512 bkey_for_each_ptr_decode(&k->k, ptrs, p, i) in bch2_bkey_narrow_crcs()
514 bch2_bkey_drop_ptr_noerror(bkey_i_to_s(k), &i->ptr); in bch2_bkey_narrow_crcs()
517 bch2_extent_ptr_decoded_append(k, &p); in bch2_bkey_narrow_crcs()
559 void bch2_extent_crc_append(struct bkey_i *k, in bch2_extent_crc_append() argument
562 struct bkey_ptrs ptrs = bch2_bkey_ptrs(bkey_i_to_s(k)); in bch2_extent_crc_append()
583 k->k.u64s += extent_entry_u64s(ptrs.end); in bch2_extent_crc_append()
585 EBUG_ON(bkey_val_u64s(&k->k) > BKEY_EXTENT_VAL_U64s_MAX); in bch2_extent_crc_append()
590 unsigned bch2_bkey_nr_ptrs(struct bkey_s_c k) in bch2_bkey_nr_ptrs() argument
592 return bch2_bkey_devs(k).nr; in bch2_bkey_nr_ptrs()
595 unsigned bch2_bkey_nr_ptrs_allocated(struct bkey_s_c k) in bch2_bkey_nr_ptrs_allocated() argument
597 return k.k->type == KEY_TYPE_reservation in bch2_bkey_nr_ptrs_allocated()
598 ? bkey_s_c_to_reservation(k).v->nr_replicas in bch2_bkey_nr_ptrs_allocated()
599 : bch2_bkey_dirty_devs(k).nr; in bch2_bkey_nr_ptrs_allocated()
602 unsigned bch2_bkey_nr_ptrs_fully_allocated(struct bkey_s_c k) in bch2_bkey_nr_ptrs_fully_allocated() argument
606 if (k.k->type == KEY_TYPE_reservation) { in bch2_bkey_nr_ptrs_fully_allocated()
607 ret = bkey_s_c_to_reservation(k).v->nr_replicas; in bch2_bkey_nr_ptrs_fully_allocated()
609 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_nr_ptrs_fully_allocated()
613 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) in bch2_bkey_nr_ptrs_fully_allocated()
620 unsigned bch2_bkey_sectors_compressed(struct bkey_s_c k) in bch2_bkey_sectors_compressed() argument
622 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_sectors_compressed()
627 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) in bch2_bkey_sectors_compressed()
634 bool bch2_bkey_is_incompressible(struct bkey_s_c k) in bch2_bkey_is_incompressible() argument
636 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_is_incompressible()
640 bkey_for_each_crc(k.k, ptrs, crc, entry) in bch2_bkey_is_incompressible()
646 unsigned bch2_bkey_replicas(struct bch_fs *c, struct bkey_s_c k) in bch2_bkey_replicas() argument
648 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_replicas()
653 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) { in bch2_bkey_replicas()
694 unsigned bch2_bkey_durability(struct bch_fs *c, struct bkey_s_c k) in bch2_bkey_durability() argument
696 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_durability()
702 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) in bch2_bkey_durability()
709 static unsigned bch2_bkey_durability_safe(struct bch_fs *c, struct bkey_s_c k) in bch2_bkey_durability_safe() argument
711 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_durability_safe()
717 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) in bch2_bkey_durability_safe()
725 void bch2_bkey_extent_entry_drop(struct bkey_i *k, union bch_extent_entry *entry) in bch2_bkey_extent_entry_drop() argument
727 union bch_extent_entry *end = bkey_val_end(bkey_i_to_s(k)); in bch2_bkey_extent_entry_drop()
731 k->k.u64s -= extent_entry_u64s(entry); in bch2_bkey_extent_entry_drop()
734 void bch2_extent_ptr_decoded_append(struct bkey_i *k, in bch2_extent_ptr_decoded_append() argument
737 struct bkey_ptrs ptrs = bch2_bkey_ptrs(bkey_i_to_s(k)); in bch2_extent_ptr_decoded_append()
739 bch2_extent_crc_unpack(&k->k, NULL); in bch2_extent_ptr_decoded_append()
747 bkey_for_each_crc(&k->k, ptrs, crc, pos) in bch2_extent_ptr_decoded_append()
753 bch2_extent_crc_append(k, p->crc); in bch2_extent_ptr_decoded_append()
754 pos = bkey_val_end(bkey_i_to_s(k)); in bch2_extent_ptr_decoded_append()
757 __extent_entry_insert(k, pos, to_entry(&p->ptr)); in bch2_extent_ptr_decoded_append()
761 __extent_entry_insert(k, pos, to_entry(&p->ec)); in bch2_extent_ptr_decoded_append()
781 void bch2_bkey_drop_ptr_noerror(struct bkey_s k, struct bch_extent_ptr *ptr) in bch2_bkey_drop_ptr_noerror() argument
783 struct bkey_ptrs ptrs = bch2_bkey_ptrs(k); in bch2_bkey_drop_ptr_noerror()
787 if (k.k->type == KEY_TYPE_stripe) { in bch2_bkey_drop_ptr_noerror()
807 extent_entry_drop(k, entry); in bch2_bkey_drop_ptr_noerror()
815 extent_entry_drop(k, entry); in bch2_bkey_drop_ptr_noerror()
819 void bch2_bkey_drop_ptr(struct bkey_s k, struct bch_extent_ptr *ptr) in bch2_bkey_drop_ptr() argument
821 if (k.k->type != KEY_TYPE_stripe) { in bch2_bkey_drop_ptr()
822 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k.s_c); in bch2_bkey_drop_ptr()
826 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) in bch2_bkey_drop_ptr()
833 bool have_dirty = bch2_bkey_dirty_devs(k.s_c).nr; in bch2_bkey_drop_ptr()
835 bch2_bkey_drop_ptr_noerror(k, ptr); in bch2_bkey_drop_ptr()
844 !bch2_bkey_dirty_devs(k.s_c).nr) { in bch2_bkey_drop_ptr()
845 k.k->type = KEY_TYPE_error; in bch2_bkey_drop_ptr()
846 set_bkey_val_u64s(k.k, 0); in bch2_bkey_drop_ptr()
847 } else if (!bch2_bkey_nr_ptrs(k.s_c)) { in bch2_bkey_drop_ptr()
848 k.k->type = KEY_TYPE_deleted; in bch2_bkey_drop_ptr()
849 set_bkey_val_u64s(k.k, 0); in bch2_bkey_drop_ptr()
853 void bch2_bkey_drop_device(struct bkey_s k, unsigned dev) in bch2_bkey_drop_device() argument
855 bch2_bkey_drop_ptrs(k, ptr, ptr->dev == dev); in bch2_bkey_drop_device()
858 void bch2_bkey_drop_device_noerror(struct bkey_s k, unsigned dev) in bch2_bkey_drop_device_noerror() argument
860 bch2_bkey_drop_ptrs_noerror(k, ptr, ptr->dev == dev); in bch2_bkey_drop_device_noerror()
863 const struct bch_extent_ptr *bch2_bkey_has_device_c(struct bkey_s_c k, unsigned dev) in bch2_bkey_has_device_c() argument
865 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_has_device_c()
874 bool bch2_bkey_has_target(struct bch_fs *c, struct bkey_s_c k, unsigned target) in bch2_bkey_has_target() argument
876 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_has_target()
894 bool bch2_bkey_matches_ptr(struct bch_fs *c, struct bkey_s_c k, in bch2_bkey_matches_ptr() argument
897 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_matches_ptr()
901 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) in bch2_bkey_matches_ptr()
904 (s64) p.ptr.offset + p.crc.offset - bkey_start_offset(k.k) == in bch2_bkey_matches_ptr()
916 if (k1.k->type != k2.k->type) in bch2_extents_match()
919 if (bkey_extent_is_direct_data(k1.k)) { in bch2_extents_match()
928 bkey_for_each_ptr_decode(k1.k, ptrs1, p1, entry1) in bch2_extents_match()
929 bkey_for_each_ptr_decode(k2.k, ptrs2, p2, entry2) in bch2_extents_match()
939 (s64) p1.ptr.offset + p1.crc.offset - bkey_start_offset(k1.k) == in bch2_extents_match()
940 (s64) p2.ptr.offset + p2.crc.offset - bkey_start_offset(k2.k) && in bch2_extents_match()
971 bkey_for_each_ptr_decode(k2.k, ptrs2, p2, entry2) in bch2_extent_has_ptr()
974 (s64) p1.ptr.offset + p1.crc.offset - bkey_start_offset(k1.k) == in bch2_extent_has_ptr()
975 (s64) p2.ptr.offset + p2.crc.offset - bkey_start_offset(k2.k)) in bch2_extent_has_ptr()
995 struct bkey_s k, in bch2_extent_ptr_set_cached() argument
998 struct bkey_ptrs ptrs = bch2_bkey_ptrs(k); in bch2_extent_ptr_set_cached()
1004 bch2_bkey_drop_ptr_noerror(k, ptr); in bch2_extent_ptr_set_cached()
1013 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) in bch2_extent_ptr_set_cached()
1016 bch2_bkey_drop_ptr_noerror(k, ptr); in bch2_extent_ptr_set_cached()
1030 * Returns true if @k should be dropped entirely
1035 bool bch2_extent_normalize(struct bch_fs *c, struct bkey_s k) in bch2_extent_normalize() argument
1040 bch2_bkey_drop_ptrs(k, ptr, in bch2_extent_normalize()
1046 return bkey_deleted(k.k); in bch2_extent_normalize()
1057 struct bkey_s k) in bch2_extent_normalize_by_opts() argument
1064 ptrs = bch2_bkey_ptrs(k); in bch2_extent_normalize_by_opts()
1070 bch2_bkey_drop_ptr(k, ptr); in bch2_extent_normalize_by_opts()
1077 return bkey_deleted(k.k); in bch2_extent_normalize_by_opts()
1124 struct bkey_s_c k) in bch2_bkey_ptrs_to_text() argument
1126 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_ptrs_to_text()
1131 prt_printf(out, "durability: %u ", bch2_bkey_durability_safe(c, k)); in bch2_bkey_ptrs_to_text()
1146 bch2_extent_crc_unpack(k.k, entry_to_crc(entry)); in bch2_bkey_ptrs_to_text()
1180 struct bkey_s_c k, in extent_ptr_validate() argument
1202 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in extent_ptr_validate()
1223 int bch2_bkey_ptrs_validate(struct bch_fs *c, struct bkey_s_c k, in bch2_bkey_ptrs_validate() argument
1226 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_ptrs_validate()
1229 unsigned size_ondisk = k.k->size; in bch2_bkey_ptrs_validate()
1235 if (bkey_is_btree_ptr(k.k)) in bch2_bkey_ptrs_validate()
1244 bkey_fsck_err_on(bkey_is_btree_ptr(k.k) && in bch2_bkey_ptrs_validate()
1251 ret = extent_ptr_validate(c, k, flags, &entry->ptr, size_ondisk, false); in bch2_bkey_ptrs_validate()
1271 crc = bch2_extent_crc_unpack(k.k, entry_to_crc(entry)); in bch2_bkey_ptrs_validate()
1340 bkey_fsck_err_on(k.k->type != KEY_TYPE_extent && have_unwritten, in bch2_bkey_ptrs_validate()
1353 void bch2_ptr_swab(struct bkey_s k) in bch2_ptr_swab() argument
1355 struct bkey_ptrs ptrs = bch2_bkey_ptrs(k); in bch2_ptr_swab()
1394 const struct bch_extent_rebalance *bch2_bkey_rebalance_opts(struct bkey_s_c k) in bch2_bkey_rebalance_opts() argument
1396 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_rebalance_opts()
1406 unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *c, struct bkey_s_c k, in bch2_bkey_ptrs_need_rebalance() argument
1409 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in bch2_bkey_ptrs_need_rebalance()
1418 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) { in bch2_bkey_ptrs_need_rebalance()
1444 bool bch2_bkey_needs_rebalance(struct bch_fs *c, struct bkey_s_c k) in bch2_bkey_needs_rebalance() argument
1446 const struct bch_extent_rebalance *r = bch2_bkey_rebalance_opts(k); in bch2_bkey_needs_rebalance()
1454 k.k->type == KEY_TYPE_reflink_v && in bch2_bkey_needs_rebalance()
1455 !bch2_bkey_ptrs_need_rebalance(c, k, r->target, r->compression)) in bch2_bkey_needs_rebalance()
1461 static u64 __bch2_bkey_sectors_need_rebalance(struct bch_fs *c, struct bkey_s_c k, in __bch2_bkey_sectors_need_rebalance() argument
1464 struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); in __bch2_bkey_sectors_need_rebalance()
1472 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) { in __bch2_bkey_sectors_need_rebalance()
1485 bkey_for_each_ptr_decode(k.k, ptrs, p, entry) in __bch2_bkey_sectors_need_rebalance()
1493 u64 bch2_bkey_sectors_need_rebalance(struct bch_fs *c, struct bkey_s_c k) in bch2_bkey_sectors_need_rebalance() argument
1495 const struct bch_extent_rebalance *r = bch2_bkey_rebalance_opts(k); in bch2_bkey_sectors_need_rebalance()
1497 return r ? __bch2_bkey_sectors_need_rebalance(c, k, r->target, r->compression) : 0; in bch2_bkey_sectors_need_rebalance()
1503 struct bkey_s k = bkey_i_to_s(_k); in bch2_bkey_set_needs_rebalance() local
1509 if (!bkey_extent_is_direct_data(k.k)) in bch2_bkey_set_needs_rebalance()
1513 r = (struct bch_extent_rebalance *) bch2_bkey_rebalance_opts(k.s_c); in bch2_bkey_set_needs_rebalance()
1515 if (k.k->type == KEY_TYPE_reflink_v) { in bch2_bkey_set_needs_rebalance()
1532 needs_rebalance = bch2_bkey_ptrs_need_rebalance(c, k.s_c, target, compression); in bch2_bkey_set_needs_rebalance()
1535 union bch_extent_entry *new = bkey_val_end(k); in bch2_bkey_set_needs_rebalance()
1541 k.k->u64s += extent_entry_u64s(new); in bch2_bkey_set_needs_rebalance()
1542 } else if (!needs_rebalance && r && k.k->type != KEY_TYPE_reflink_v) { in bch2_bkey_set_needs_rebalance()
1548 extent_entry_drop(k, (union bch_extent_entry *) r); in bch2_bkey_set_needs_rebalance()
1556 int bch2_cut_front_s(struct bpos where, struct bkey_s k) in bch2_cut_front_s() argument
1558 unsigned new_val_u64s = bkey_val_u64s(k.k); in bch2_cut_front_s()
1562 if (bkey_le(where, bkey_start_pos(k.k))) in bch2_cut_front_s()
1565 EBUG_ON(bkey_gt(where, k.k->p)); in bch2_cut_front_s()
1567 sub = where.offset - bkey_start_offset(k.k); in bch2_cut_front_s()
1569 k.k->size -= sub; in bch2_cut_front_s()
1571 if (!k.k->size) { in bch2_cut_front_s()
1572 k.k->type = KEY_TYPE_deleted; in bch2_cut_front_s()
1576 switch (k.k->type) { in bch2_cut_front_s()
1579 struct bkey_ptrs ptrs = bch2_bkey_ptrs(k); in bch2_cut_front_s()
1611 struct bkey_s_reflink_p p = bkey_s_to_reflink_p(k); in bch2_cut_front_s()
1618 void *p = bkey_inline_data_p(k); in bch2_cut_front_s()
1619 unsigned bytes = bkey_inline_data_bytes(k.k); in bch2_cut_front_s()
1630 val_u64s_delta = bkey_val_u64s(k.k) - new_val_u64s; in bch2_cut_front_s()
1633 set_bkey_val_u64s(k.k, new_val_u64s); in bch2_cut_front_s()
1634 memset(bkey_val_end(k), 0, val_u64s_delta * sizeof(u64)); in bch2_cut_front_s()
1638 int bch2_cut_back_s(struct bpos where, struct bkey_s k) in bch2_cut_back_s() argument
1640 unsigned new_val_u64s = bkey_val_u64s(k.k); in bch2_cut_back_s()
1644 if (bkey_ge(where, k.k->p)) in bch2_cut_back_s()
1647 EBUG_ON(bkey_lt(where, bkey_start_pos(k.k))); in bch2_cut_back_s()
1649 len = where.offset - bkey_start_offset(k.k); in bch2_cut_back_s()
1651 k.k->p.offset = where.offset; in bch2_cut_back_s()
1652 k.k->size = len; in bch2_cut_back_s()
1655 k.k->type = KEY_TYPE_deleted; in bch2_cut_back_s()
1659 switch (k.k->type) { in bch2_cut_back_s()
1662 new_val_u64s = (bkey_inline_data_offset(k.k) + in bch2_cut_back_s()
1663 min(bkey_inline_data_bytes(k.k), k.k->size << 9)) >> 3; in bch2_cut_back_s()
1667 val_u64s_delta = bkey_val_u64s(k.k) - new_val_u64s; in bch2_cut_back_s()
1670 set_bkey_val_u64s(k.k, new_val_u64s); in bch2_cut_back_s()
1671 memset(bkey_val_end(k), 0, val_u64s_delta * sizeof(u64)); in bch2_cut_back_s()