]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/extents.h
Update bcachefs sources to 0d63ed13ea3d closures: Fix race in closure_sync()
[bcachefs-tools-debian] / libbcachefs / extents.h
index 3ba41e37d8649610e94c56e26477baec8a53c7e6..9110acae7e3ca94fea1e56d805405a4326ab73a1 100644 (file)
@@ -8,6 +8,7 @@
 
 struct bch_fs;
 struct btree_trans;
+enum bkey_invalid_flags;
 
 /* extent entries: */
 
@@ -88,6 +89,18 @@ static inline void __extent_entry_insert(struct bkey_i *k,
        memcpy_u64s_small(dst, new, extent_entry_u64s(new));
 }
 
+static inline void extent_entry_drop(struct bkey_s k, union bch_extent_entry *entry)
+{
+       union bch_extent_entry *next = extent_entry_next(entry);
+
+       /* stripes have ptrs, but their layout doesn't work with this code */
+       BUG_ON(k.k->type == KEY_TYPE_stripe);
+
+       memmove_u64s_down(entry, next,
+                         (u64 *) bkey_val_end(k) - (u64 *) next);
+       k.k->u64s -= (u64 *) next - (u64 *) entry;
+}
+
 static inline bool extent_entry_is_ptr(const union bch_extent_entry *e)
 {
        return extent_entry_type(e) == BCH_EXTENT_ENTRY_ptr;
@@ -154,11 +167,7 @@ bch2_extent_crc_unpack(const struct bkey *k, const union bch_extent_crc *crc)
                        common_fields(crc->crc32),
                };
 
-               *((__le32 *) &ret.csum.lo) = crc->crc32.csum;
-
-               memcpy(&ret.csum.lo, &crc->crc32.csum,
-                      sizeof(crc->crc32.csum));
-
+               *((__le32 *) &ret.csum.lo) = (__le32 __force) crc->crc32.csum;
                return ret;
        }
        case BCH_EXTENT_ENTRY_crc64: {
@@ -168,7 +177,7 @@ bch2_extent_crc_unpack(const struct bkey *k, const union bch_extent_crc *crc)
                        .csum.lo                = (__force __le64) crc->crc64.csum_lo,
                };
 
-               *((__le16 *) &ret.csum.hi) = crc->crc64.csum_hi;
+               *((__le16 *) &ret.csum.hi) = (__le16 __force) crc->crc64.csum_hi;
 
                return ret;
        }
@@ -193,6 +202,11 @@ static inline bool crc_is_compressed(struct bch_extent_crc_unpacked crc)
                crc.compression_type != BCH_COMPRESSION_TYPE_incompressible);
 }
 
+static inline bool crc_is_encoded(struct bch_extent_crc_unpacked crc)
+{
+       return crc.csum_type != BCH_CSUM_none || crc_is_compressed(crc);
+}
+
 /* bkey_ptrs: generically over any key type that has ptrs */
 
 struct bkey_ptrs_c {
@@ -318,6 +332,9 @@ static inline struct bkey_ptrs bch2_bkey_ptrs(struct bkey_s k)
                        (_ptr).ec = _entry->stripe_ptr;                 \
                        (_ptr).has_ec   = true;                         \
                        break;                                          \
+               default:                                                \
+                       /* nothing */                                   \
+                       break;                                          \
                }                                                       \
 out:                                                                   \
        _entry < (_end);                                                \
@@ -383,11 +400,13 @@ int bch2_bkey_pick_read_device(struct bch_fs *, struct bkey_s_c,
 
 /* KEY_TYPE_btree_ptr: */
 
-int bch2_btree_ptr_invalid(const struct bch_fs *, struct bkey_s_c, unsigned, struct printbuf *);
+int bch2_btree_ptr_invalid(const struct bch_fs *, struct bkey_s_c,
+                          enum bkey_invalid_flags, struct printbuf *);
 void bch2_btree_ptr_to_text(struct printbuf *, struct bch_fs *,
                            struct bkey_s_c);
 
-int bch2_btree_ptr_v2_invalid(const struct bch_fs *, struct bkey_s_c, unsigned, struct printbuf *);
+int bch2_btree_ptr_v2_invalid(const struct bch_fs *, struct bkey_s_c,
+                             enum bkey_invalid_flags, struct printbuf *);
 void bch2_btree_ptr_v2_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
 void bch2_btree_ptr_v2_compat(enum btree_id, unsigned, unsigned,
                              int, struct bkey_s);
@@ -427,7 +446,7 @@ bool bch2_extent_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
 /* KEY_TYPE_reservation: */
 
 int bch2_reservation_invalid(const struct bch_fs *, struct bkey_s_c,
-                            unsigned, struct printbuf *);
+                            enum bkey_invalid_flags, struct printbuf *);
 void bch2_reservation_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
 bool bch2_reservation_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);
 
@@ -518,6 +537,7 @@ static inline bool bkey_extent_is_allocation(const struct bkey *k)
        case KEY_TYPE_reflink_v:
        case KEY_TYPE_inline_data:
        case KEY_TYPE_indirect_inline_data:
+       case KEY_TYPE_error:
                return true;
        default:
                return false;
@@ -630,6 +650,8 @@ void bch2_bkey_extent_entry_drop(struct bkey_i *, union bch_extent_entry *);
 
 static inline void bch2_bkey_append_ptr(struct bkey_i *k, struct bch_extent_ptr ptr)
 {
+       struct bch_extent_ptr *dest;
+
        EBUG_ON(bch2_bkey_has_device(bkey_i_to_s(k), ptr.dev));
 
        switch (k->k.type) {
@@ -639,10 +661,8 @@ static inline void bch2_bkey_append_ptr(struct bkey_i *k, struct bch_extent_ptr
                EBUG_ON(bkey_val_u64s(&k->k) >= BKEY_EXTENT_VAL_U64s_MAX);
 
                ptr.type = 1 << BCH_EXTENT_ENTRY_ptr;
-
-               memcpy((void *) &k->v + bkey_val_bytes(&k->k),
-                      &ptr,
-                      sizeof(ptr));
+               dest = (struct bch_extent_ptr *)((void *) &k->v + bkey_val_bytes(&k->k));
+               *dest = ptr;
                k->k.u64s++;
                break;
        default:
@@ -686,10 +706,18 @@ bool bch2_extent_normalize(struct bch_fs *, struct bkey_s);
 void bch2_bkey_ptrs_to_text(struct printbuf *, struct bch_fs *,
                            struct bkey_s_c);
 int bch2_bkey_ptrs_invalid(const struct bch_fs *, struct bkey_s_c,
-                          unsigned, struct printbuf *);
+                          enum bkey_invalid_flags, struct printbuf *);
 
 void bch2_ptr_swab(struct bkey_s);
 
+const struct bch_extent_rebalance *bch2_bkey_rebalance_opts(struct bkey_s_c);
+unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *, struct bkey_s_c,
+                                      unsigned, unsigned);
+bool bch2_bkey_needs_rebalance(struct bch_fs *, struct bkey_s_c);
+
+int bch2_bkey_set_needs_rebalance(struct bch_fs *, struct bkey_i *,
+                                 unsigned, unsigned);
+
 /* Generic extent code: */
 
 enum bch_extent_overlap {
@@ -734,22 +762,4 @@ static inline void bch2_key_resize(struct bkey *k, unsigned new_size)
        k->size = new_size;
 }
 
-/*
- * In extent_sort_fix_overlapping(), insert_fixup_extent(),
- * extent_merge_inline() - we're modifying keys in place that are packed. To do
- * that we have to unpack the key, modify the unpacked key - then this
- * copies/repacks the unpacked to the original as necessary.
- */
-static inline void extent_save(struct btree *b, struct bkey_packed *dst,
-                              struct bkey *src)
-{
-       struct bkey_format *f = &b->format;
-       struct bkey_i *dst_unpacked;
-
-       if ((dst_unpacked = packed_to_bkey(dst)))
-               dst_unpacked->k = *src;
-       else
-               BUG_ON(!bch2_bkey_pack_key(dst, src, f));
-}
-
 #endif /* _BCACHEFS_EXTENTS_H */