summaryrefslogtreecommitdiff
path: root/libbcachefs/bcachefs_format.h
diff options
context:
space:
mode:
Diffstat (limited to 'libbcachefs/bcachefs_format.h')
-rw-r--r--libbcachefs/bcachefs_format.h194
1 files changed, 80 insertions, 114 deletions
diff --git a/libbcachefs/bcachefs_format.h b/libbcachefs/bcachefs_format.h
index 2d64bcae..3f6d51ac 100644
--- a/libbcachefs/bcachefs_format.h
+++ b/libbcachefs/bcachefs_format.h
@@ -2,7 +2,7 @@
#define _BCACHEFS_FORMAT_H
/*
- * Bcache on disk data structures
+ * bcachefs on disk data structures
*/
#include <asm/types.h>
@@ -714,6 +714,25 @@ struct bch_xattr {
} __attribute__((packed, aligned(8)));
BKEY_VAL_TYPE(xattr, BCH_XATTR);
+/* Bucket/allocation information: */
+
+enum {
+ BCH_ALLOC = 128,
+};
+
+enum {
+ BCH_ALLOC_FIELD_READ_TIME = 0,
+ BCH_ALLOC_FIELD_WRITE_TIME = 1,
+};
+
+struct bch_alloc {
+ struct bch_val v;
+ __u8 fields;
+ __u8 gen;
+ __u8 data[];
+} __attribute__((packed, aligned(8)));
+BKEY_VAL_TYPE(alloc, BCH_ALLOC);
+
/* Superblock */
/* Version 0: Cache device
@@ -752,8 +771,7 @@ struct bch_member {
LE64_BITMASK(BCH_MEMBER_STATE, struct bch_member, flags[0], 0, 4)
LE64_BITMASK(BCH_MEMBER_TIER, struct bch_member, flags[0], 4, 8)
-LE64_BITMASK(BCH_MEMBER_HAS_METADATA, struct bch_member, flags[0], 8, 9)
-LE64_BITMASK(BCH_MEMBER_HAS_DATA, struct bch_member, flags[0], 9, 10)
+/* 8-10 unused, was HAS_(META)DATA */
LE64_BITMASK(BCH_MEMBER_REPLACEMENT, struct bch_member, flags[0], 10, 14)
LE64_BITMASK(BCH_MEMBER_DISCARD, struct bch_member, flags[0], 14, 15);
@@ -800,7 +818,8 @@ enum bch_sb_field_type {
BCH_SB_FIELD_journal = 0,
BCH_SB_FIELD_members = 1,
BCH_SB_FIELD_crypt = 2,
- BCH_SB_FIELD_NR = 3,
+ BCH_SB_FIELD_replicas = 3,
+ BCH_SB_FIELD_NR = 4,
};
struct bch_sb_field_journal {
@@ -861,8 +880,24 @@ LE64_BITMASK(BCH_KDF_SCRYPT_N, struct bch_sb_field_crypt, kdf_flags, 0, 16);
LE64_BITMASK(BCH_KDF_SCRYPT_R, struct bch_sb_field_crypt, kdf_flags, 16, 32);
LE64_BITMASK(BCH_KDF_SCRYPT_P, struct bch_sb_field_crypt, kdf_flags, 32, 48);
-struct bch_sb_field_replication {
+enum bch_data_types {
+ BCH_DATA_NONE = 0,
+ BCH_DATA_SB = 1,
+ BCH_DATA_JOURNAL = 2,
+ BCH_DATA_BTREE = 3,
+ BCH_DATA_USER = 4,
+ BCH_DATA_NR = 5,
+};
+
+struct bch_replicas_entry {
+ u8 data_type;
+ u8 nr;
+ u8 devs[0];
+};
+
+struct bch_sb_field_replicas {
struct bch_sb_field field;
+ struct bch_replicas_entry entries[0];
};
/*
@@ -937,8 +972,7 @@ LE64_BITMASK(BCH_SB_DATA_CSUM_TYPE, struct bch_sb, flags[0], 44, 48);
LE64_BITMASK(BCH_SB_META_REPLICAS_WANT, struct bch_sb, flags[0], 48, 52);
LE64_BITMASK(BCH_SB_DATA_REPLICAS_WANT, struct bch_sb, flags[0], 52, 56);
-LE64_BITMASK(BCH_SB_META_REPLICAS_HAVE, struct bch_sb, flags[0], 56, 60);
-LE64_BITMASK(BCH_SB_DATA_REPLICAS_HAVE, struct bch_sb, flags[0], 60, 64);
+/* 56-64 unused, was REPLICAS_HAVE */
LE64_BITMASK(BCH_SB_STR_HASH_TYPE, struct bch_sb, flags[1], 0, 4);
LE64_BITMASK(BCH_SB_COMPRESSION_TYPE, struct bch_sb, flags[1], 4, 8);
@@ -946,6 +980,7 @@ LE64_BITMASK(BCH_SB_INODE_32BIT, struct bch_sb, flags[1], 8, 9);
LE64_BITMASK(BCH_SB_128_BIT_MACS, struct bch_sb, flags[1], 9, 10);
LE64_BITMASK(BCH_SB_ENCRYPTION_TYPE, struct bch_sb, flags[1], 10, 14);
+
/* 14-20 unused, was JOURNAL_ENTRY_SIZE */
LE64_BITMASK(BCH_SB_META_REPLICAS_REQ, struct bch_sb, flags[1], 20, 24);
@@ -1003,77 +1038,6 @@ enum bch_compression_opts {
BCH_COMPRESSION_NR = 3,
};
-/* backing device specific stuff: */
-
-struct backingdev_sb {
- __le64 csum;
- __le64 offset; /* sector where this sb was written */
- __le64 version; /* of on disk format */
-
- uuid_le magic; /* bcachefs superblock UUID */
-
- uuid_le disk_uuid;
-
- /*
- * Internal cache set UUID - xored with various magic numbers and thus
- * must never change:
- */
- union {
- uuid_le set_uuid;
- __le64 set_magic;
- };
- __u8 label[BCH_SB_LABEL_SIZE];
-
- __le64 flags;
-
- /* Incremented each time superblock is written: */
- __le64 seq;
-
- /*
- * User visible UUID for identifying the cache set the user is allowed
- * to change:
- *
- * XXX hooked up?
- */
- uuid_le user_uuid;
- __le64 pad1[6];
-
- __le64 data_offset;
- __le16 block_size; /* sectors */
- __le16 pad2[3];
-
- __le32 last_mount; /* time_t */
- __le16 pad3;
- /* size of variable length portion - always 0 for backingdev superblock */
- __le16 u64s;
- __u64 _data[0];
-};
-
-LE64_BITMASK(BDEV_CACHE_MODE, struct backingdev_sb, flags, 0, 4);
-#define CACHE_MODE_WRITETHROUGH 0U
-#define CACHE_MODE_WRITEBACK 1U
-#define CACHE_MODE_WRITEAROUND 2U
-#define CACHE_MODE_NONE 3U
-
-LE64_BITMASK(BDEV_STATE, struct backingdev_sb, flags, 61, 63);
-#define BDEV_STATE_NONE 0U
-#define BDEV_STATE_CLEAN 1U
-#define BDEV_STATE_DIRTY 2U
-#define BDEV_STATE_STALE 3U
-
-#define BDEV_DATA_START_DEFAULT 16 /* sectors */
-
-static inline _Bool __SB_IS_BDEV(__u64 version)
-{
- return version == BCACHE_SB_VERSION_BDEV
- || version == BCACHE_SB_VERSION_BDEV_WITH_OFFSET;
-}
-
-static inline _Bool SB_IS_BDEV(const struct bch_sb *sb)
-{
- return __SB_IS_BDEV(sb->version);
-}
-
/*
* Magic numbers
*
@@ -1088,7 +1052,6 @@ static inline _Bool SB_IS_BDEV(const struct bch_sb *sb)
#define BCACHE_STATFS_MAGIC 0xca451a4e
#define JSET_MAGIC __cpu_to_le64(0x245235c1a3625032ULL)
-#define PSET_MAGIC __cpu_to_le64(0x6750e15f87337f91ULL)
#define BSET_MAGIC __cpu_to_le64(0x90135c78b99e07f5ULL)
static inline __le64 __bch2_sb_magic(struct bch_sb *sb)
@@ -1103,11 +1066,6 @@ static inline __u64 __jset_magic(struct bch_sb *sb)
return __le64_to_cpu(__bch2_sb_magic(sb) ^ JSET_MAGIC);
}
-static inline __u64 __pset_magic(struct bch_sb *sb)
-{
- return __le64_to_cpu(__bch2_sb_magic(sb) ^ PSET_MAGIC);
-}
-
static inline __u64 __bset_magic(struct bch_sb *sb)
{
return __le64_to_cpu(__bch2_sb_magic(sb) ^ BSET_MAGIC);
@@ -1136,9 +1094,9 @@ struct jset_entry {
LE32_BITMASK(JOURNAL_ENTRY_TYPE, struct jset_entry, flags, 0, 8);
enum {
- JOURNAL_ENTRY_BTREE_KEYS = 0,
- JOURNAL_ENTRY_BTREE_ROOT = 1,
- JOURNAL_ENTRY_PRIO_PTRS = 2,
+ JOURNAL_ENTRY_BTREE_KEYS = 0,
+ JOURNAL_ENTRY_BTREE_ROOT = 1,
+ JOURNAL_ENTRY_PRIO_PTRS = 2, /* Obsolete */
/*
* Journal sequence numbers can be blacklisted: bsets record the max
@@ -1150,7 +1108,7 @@ enum {
* and then record that we skipped it so that the next time we crash and
* recover we don't think there was a missing journal entry.
*/
- JOURNAL_ENTRY_JOURNAL_SEQ_BLACKLISTED = 3,
+ JOURNAL_ENTRY_JOURNAL_SEQ_BLACKLISTED = 3,
};
/*
@@ -1193,35 +1151,14 @@ LE32_BITMASK(JSET_BIG_ENDIAN, struct jset, flags, 4, 5);
#define BCH_JOURNAL_BUCKETS_MIN 20
-/* Bucket prios/gens */
-
-struct prio_set {
- struct bch_csum csum;
-
- __le64 magic;
- __le32 nonce[3];
- __le16 version;
- __le16 flags;
-
- __u8 encrypted_start[0];
-
- __le64 next_bucket;
-
- struct bucket_disk {
- __le16 prio[2];
- __u8 gen;
- } __attribute__((packed)) data[];
-} __attribute__((packed, aligned(8)));
-
-LE32_BITMASK(PSET_CSUM_TYPE, struct prio_set, flags, 0, 4);
-
/* Btree: */
#define DEFINE_BCH_BTREE_IDS() \
- DEF_BTREE_ID(EXTENTS, 0, "extents") \
- DEF_BTREE_ID(INODES, 1, "inodes") \
- DEF_BTREE_ID(DIRENTS, 2, "dirents") \
- DEF_BTREE_ID(XATTRS, 3, "xattrs")
+ DEF_BTREE_ID(EXTENTS, 0, "extents") \
+ DEF_BTREE_ID(INODES, 1, "inodes") \
+ DEF_BTREE_ID(DIRENTS, 2, "dirents") \
+ DEF_BTREE_ID(XATTRS, 3, "xattrs") \
+ DEF_BTREE_ID(ALLOC, 4, "alloc")
#define DEF_BTREE_ID(kwd, val, name) BTREE_ID_##kwd = val,
@@ -1318,4 +1255,33 @@ struct btree_node_entry {
};
} __attribute__((packed, aligned(8)));
+/* Obsolete: */
+
+struct prio_set {
+ struct bch_csum csum;
+
+ __le64 magic;
+ __le32 nonce[3];
+ __le16 version;
+ __le16 flags;
+
+ __u8 encrypted_start[0];
+
+ __le64 next_bucket;
+
+ struct bucket_disk {
+ __le16 prio[2];
+ __u8 gen;
+ } __attribute__((packed)) data[];
+} __attribute__((packed, aligned(8)));
+
+LE32_BITMASK(PSET_CSUM_TYPE, struct prio_set, flags, 0, 4);
+
+#define PSET_MAGIC __cpu_to_le64(0x6750e15f87337f91ULL)
+
+static inline __u64 __pset_magic(struct bch_sb *sb)
+{
+ return __le64_to_cpu(__bch2_sb_magic(sb) ^ PSET_MAGIC);
+}
+
#endif /* _BCACHEFS_FORMAT_H */