]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/bcachefs_format.h
Merge pull request #196 from Conan-Kudo/spec-libexecdir
[bcachefs-tools-debian] / libbcachefs / bcachefs_format.h
index 99749f3315fec5fafb0b6d051ca01f0b7384834a..2105198daf3be3a0bc61cf8fa7d5880e37b0d74b 100644 (file)
@@ -151,7 +151,11 @@ struct bpos {
 #else
 #error edit for your odd byteorder.
 #endif
-} __packed __aligned(4);
+} __packed
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+__aligned(4)
+#endif
+;
 
 #define KEY_INODE_MAX                  ((__u64)~0ULL)
 #define KEY_OFFSET_MAX                 ((__u64)~0ULL)
@@ -303,6 +307,13 @@ struct bkey_i {
        struct bch_val  v;
 };
 
+#define POS_KEY(_pos)                                                  \
+((struct bkey) {                                                       \
+       .u64s           = BKEY_U64s,                                    \
+       .format         = KEY_FORMAT_CURRENT,                           \
+       .p              = _pos,                                         \
+})
+
 #define KEY(_inode, _offset, _size)                                    \
 ((struct bkey) {                                                       \
        .u64s           = BKEY_U64s,                                    \
@@ -613,31 +624,17 @@ struct bch_extent_stripe_ptr {
 #endif
 };
 
-struct bch_extent_reservation {
-#if defined(__LITTLE_ENDIAN_BITFIELD)
-       __u64                   type:6,
-                               unused:22,
-                               replicas:4,
-                               generation:32;
-#elif defined (__BIG_ENDIAN_BITFIELD)
-       __u64                   generation:32,
-                               replicas:4,
-                               unused:22,
-                               type:6;
-#endif
-};
-
 struct bch_extent_rebalance {
 #if defined(__LITTLE_ENDIAN_BITFIELD)
-       __u64                   type:7,
-                               unused:33,
-                               compression:8,
+       __u64                   type:6,
+                               unused:34,
+                               compression:8, /* enum bch_compression_opt */
                                target:16;
 #elif defined (__BIG_ENDIAN_BITFIELD)
        __u64                   target:16,
                                compression:8,
-                               unused:33,
-                               type:7;
+                               unused:34,
+                               type:6;
 #endif
 };
 
@@ -838,34 +835,30 @@ enum inode_opt_id {
        Inode_opt_nr,
 };
 
-enum {
-       /*
-        * User flags (get/settable with FS_IOC_*FLAGS, correspond to FS_*_FL
-        * flags)
-        */
-       __BCH_INODE_SYNC                = 0,
-       __BCH_INODE_IMMUTABLE           = 1,
-       __BCH_INODE_APPEND              = 2,
-       __BCH_INODE_NODUMP              = 3,
-       __BCH_INODE_NOATIME             = 4,
-
-       __BCH_INODE_I_SIZE_DIRTY        = 5, /* obsolete */
-       __BCH_INODE_I_SECTORS_DIRTY     = 6, /* obsolete */
-       __BCH_INODE_UNLINKED            = 7,
-       __BCH_INODE_BACKPTR_UNTRUSTED   = 8,
-
-       /* bits 20+ reserved for packed fields below: */
-};
-
-#define BCH_INODE_SYNC         (1 << __BCH_INODE_SYNC)
-#define BCH_INODE_IMMUTABLE    (1 << __BCH_INODE_IMMUTABLE)
-#define BCH_INODE_APPEND       (1 << __BCH_INODE_APPEND)
-#define BCH_INODE_NODUMP       (1 << __BCH_INODE_NODUMP)
-#define BCH_INODE_NOATIME      (1 << __BCH_INODE_NOATIME)
-#define BCH_INODE_I_SIZE_DIRTY (1 << __BCH_INODE_I_SIZE_DIRTY)
-#define BCH_INODE_I_SECTORS_DIRTY (1 << __BCH_INODE_I_SECTORS_DIRTY)
-#define BCH_INODE_UNLINKED     (1 << __BCH_INODE_UNLINKED)
-#define BCH_INODE_BACKPTR_UNTRUSTED (1 << __BCH_INODE_BACKPTR_UNTRUSTED)
+#define BCH_INODE_FLAGS()                      \
+       x(sync,                         0)      \
+       x(immutable,                    1)      \
+       x(append,                       2)      \
+       x(nodump,                       3)      \
+       x(noatime,                      4)      \
+       x(i_size_dirty,                 5)      \
+       x(i_sectors_dirty,              6)      \
+       x(unlinked,                     7)      \
+       x(backptr_untrusted,            8)
+
+/* bits 20+ reserved for packed fields below: */
+
+enum bch_inode_flags {
+#define x(t, n)        BCH_INODE_##t = 1U << n,
+       BCH_INODE_FLAGS()
+#undef x
+};
+
+enum __bch_inode_flags {
+#define x(t, n)        __BCH_INODE_##t = n,
+       BCH_INODE_FLAGS()
+#undef x
+};
 
 LE32_BITMASK(INODE_STR_HASH,   struct bch_inode, bi_flags, 20, 24);
 LE32_BITMASK(INODE_NR_FIELDS,  struct bch_inode, bi_flags, 24, 31);
@@ -1232,7 +1225,8 @@ struct bch_sb_field {
        x(journal_seq_blacklist, 8)             \
        x(journal_v2,   9)                      \
        x(counters,     10)                     \
-       x(members_v2,   11)
+       x(members_v2,   11)                     \
+       x(errors,       12)
 
 enum bch_sb_field_type {
 #define x(f, nr)       BCH_SB_FIELD_##f = nr,
@@ -1282,6 +1276,18 @@ enum bch_iops_measurement {
        BCH_IOPS_NR
 };
 
+#define BCH_MEMBER_ERROR_TYPES()               \
+       x(read,         0)                      \
+       x(write,        1)                      \
+       x(checksum,     2)
+
+enum bch_member_error_type {
+#define x(t, n) BCH_MEMBER_ERROR_##t = n,
+       BCH_MEMBER_ERROR_TYPES()
+#undef x
+       BCH_MEMBER_ERROR_NR
+};
+
 struct bch_member {
        __uuid_t                uuid;
        __le64                  nbuckets;       /* device size */
@@ -1292,6 +1298,10 @@ struct bch_member {
 
        __le64                  flags;
        __le32                  iops[4];
+       __le64                  errors[BCH_MEMBER_ERROR_NR];
+       __le64                  errors_at_reset[BCH_MEMBER_ERROR_NR];
+       __le64                  errors_reset_time;
+       __le64                  seq;
 };
 
 #define BCH_MEMBER_V1_BYTES    56
@@ -1438,7 +1448,7 @@ struct bch_sb_field_replicas_v0 {
        struct bch_replicas_entry_v0 entries[];
 } __packed __aligned(8);
 
-struct bch_replicas_entry {
+struct bch_replicas_entry_v1 {
        __u8                    data_type;
        __u8                    nr_devs;
        __u8                    nr_required;
@@ -1450,7 +1460,7 @@ struct bch_replicas_entry {
 
 struct bch_sb_field_replicas {
        struct bch_sb_field     field;
-       struct bch_replicas_entry entries[];
+       struct bch_replicas_entry_v1 entries[];
 } __packed __aligned(8);
 
 /* BCH_SB_FIELD_quota: */
@@ -1530,7 +1540,7 @@ struct bch_sb_field_disk_groups {
        x(move_extent_write,                            36)     \
        x(move_extent_finish,                           37)     \
        x(move_extent_fail,                             38)     \
-       x(move_extent_alloc_mem_fail,                   39)     \
+       x(move_extent_start_fail,                       39)     \
        x(copygc,                                       40)     \
        x(copygc_wait,                                  41)     \
        x(gc_gens_end,                                  42)     \
@@ -1567,7 +1577,9 @@ struct bch_sb_field_disk_groups {
        x(write_super,                                  73)     \
        x(trans_restart_would_deadlock_recursion_limit, 74)     \
        x(trans_restart_write_buffer_flush,             75)     \
-       x(trans_restart_split_race,                     76)
+       x(trans_restart_split_race,                     76)     \
+       x(write_buffer_flush_slowpath,                  77)     \
+       x(write_buffer_flush_sync,                      78)
 
 enum bch_persistent_counters {
 #define x(t, n, ...) BCH_COUNTER_##t,
@@ -1615,11 +1627,20 @@ struct journal_seq_blacklist_entry {
 
 struct bch_sb_field_journal_seq_blacklist {
        struct bch_sb_field     field;
+       struct journal_seq_blacklist_entry start[];
+};
 
-       struct journal_seq_blacklist_entry start[0];
-       __u64                   _data[];
+struct bch_sb_field_errors {
+       struct bch_sb_field     field;
+       struct bch_sb_field_error_entry {
+               __le64          v;
+               __le64          last_error_time;
+       }                       entries[];
 };
 
+LE64_BITMASK(BCH_SB_ERROR_ENTRY_ID,    struct bch_sb_field_error_entry, v,  0, 16);
+LE64_BITMASK(BCH_SB_ERROR_ENTRY_NR,    struct bch_sb_field_error_entry, v, 16, 64);
+
 /* Superblock: */
 
 /*
@@ -1682,7 +1703,11 @@ struct bch_sb_field_journal_seq_blacklist {
        x(snapshot_skiplists,           BCH_VERSION(1,  1),             \
          BIT_ULL(BCH_RECOVERY_PASS_check_snapshots))                   \
        x(deleted_inodes,               BCH_VERSION(1,  2),             \
-         BIT_ULL(BCH_RECOVERY_PASS_check_inodes))
+         BIT_ULL(BCH_RECOVERY_PASS_check_inodes))                      \
+       x(rebalance_work,               BCH_VERSION(1,  3),             \
+         BIT_ULL(BCH_RECOVERY_PASS_set_fs_needs_rebalance))            \
+       x(member_seq,                   BCH_VERSION(1,  4),             \
+         0)
 
 enum bcachefs_metadata_version {
        bcachefs_metadata_version_min = 9,
@@ -1693,7 +1718,7 @@ enum bcachefs_metadata_version {
 };
 
 static const __maybe_unused
-unsigned bcachefs_metadata_required_upgrade_below = bcachefs_metadata_version_major_minor;
+unsigned bcachefs_metadata_required_upgrade_below = bcachefs_metadata_version_rebalance_work;
 
 #define bcachefs_metadata_version_current      (bcachefs_metadata_version_max - 1)
 
@@ -1748,7 +1773,8 @@ struct bch_sb {
        __le32                  time_base_hi;
        __le32                  time_precision;
 
-       __le64                  flags[8];
+       __le64                  flags[7];
+       __le64                  write_time;
        __le64                  features[2];
        __le64                  compat[2];
 
@@ -2115,7 +2141,8 @@ static inline __u64 __bset_magic(struct bch_sb *sb)
        x(clock,                7)              \
        x(dev_usage,            8)              \
        x(log,                  9)              \
-       x(overwrite,            10)
+       x(overwrite,            10)             \
+       x(write_buffer_keys,    11)
 
 enum {
 #define x(f, nr)       BCH_JSET_ENTRY_##f      = nr,
@@ -2124,6 +2151,19 @@ enum {
        BCH_JSET_ENTRY_NR
 };
 
+static inline bool jset_entry_is_key(struct jset_entry *e)
+{
+       switch (e->type) {
+       case BCH_JSET_ENTRY_btree_keys:
+       case BCH_JSET_ENTRY_btree_root:
+       case BCH_JSET_ENTRY_overwrite:
+       case BCH_JSET_ENTRY_write_buffer_keys:
+               return true;
+       }
+
+       return false;
+}
+
 /*
  * Journal sequence numbers can be blacklisted: bsets record the max sequence
  * number of all the journal entries they contain updates for, so that on
@@ -2165,7 +2205,7 @@ struct jset_entry_usage {
 struct jset_entry_data_usage {
        struct jset_entry       entry;
        __le64                  v;
-       struct bch_replicas_entry r;
+       struct bch_replicas_entry_v1 r;
 } __packed;
 
 struct jset_entry_clock {
@@ -2186,8 +2226,8 @@ struct jset_entry_dev_usage {
        __le32                  dev;
        __u32                   pad;
 
-       __le64                  buckets_ec;
-       __le64                  _buckets_unavailable; /* No longer used */
+       __le64                  _buckets_ec;            /* No longer used */
+       __le64                  _buckets_unavailable;   /* No longer used */
 
        struct jset_entry_dev_usage_type d[];
 };
@@ -2201,7 +2241,7 @@ static inline unsigned jset_entry_dev_usage_nr_types(struct jset_entry_dev_usage
 struct jset_entry_log {
        struct jset_entry       entry;
        u8                      d[];
-} __packed;
+} __packed __aligned(8);
 
 /*
  * On disk format for a journal entry:
@@ -2247,7 +2287,8 @@ LE32_BITMASK(JSET_NO_FLUSH,       struct jset, flags, 5, 6);
 enum btree_id_flags {
        BTREE_ID_EXTENTS        = BIT(0),
        BTREE_ID_SNAPSHOTS      = BIT(1),
-       BTREE_ID_DATA           = BIT(2),
+       BTREE_ID_SNAPSHOT_FIELD = BIT(2),
+       BTREE_ID_DATA           = BIT(3),
 };
 
 #define BCH_BTREE_IDS()                                                                \
@@ -2302,11 +2343,13 @@ enum btree_id_flags {
          BIT_ULL(KEY_TYPE_bucket_gens))                                        \
        x(snapshot_trees,       15,     0,                                      \
          BIT_ULL(KEY_TYPE_snapshot_tree))                                      \
-       x(deleted_inodes,       16,     BTREE_ID_SNAPSHOTS,                     \
+       x(deleted_inodes,       16,     BTREE_ID_SNAPSHOT_FIELD,                \
          BIT_ULL(KEY_TYPE_set))                                                \
        x(logged_ops,           17,     0,                                      \
          BIT_ULL(KEY_TYPE_logged_op_truncate)|                                 \
-         BIT_ULL(KEY_TYPE_logged_op_finsert))
+         BIT_ULL(KEY_TYPE_logged_op_finsert))                                  \
+       x(rebalance_work,       18,     BTREE_ID_SNAPSHOT_FIELD,                \
+         BIT_ULL(KEY_TYPE_set)|BIT_ULL(KEY_TYPE_cookie))
 
 enum btree_id {
 #define x(name, nr, ...) BTREE_ID_##name = nr,