diff mbox series

[07/15] btrfs-progs: add snapshot_id to the btrfs_header

Message ID 7e34f77485b09a60857761b92ddcce4fe1ef892a.1646691255.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: initial snapshot_id support | expand

Commit Message

Josef Bacik March 7, 2022, 10:17 p.m. UTC
Add a new btrfs_header_v2 which has the original header and an
additional snapshot_id field for tracking the snapshot the block was
created in.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 kernel-shared/ctree.h | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h
index f3343840..7d4fd491 100644
--- a/kernel-shared/ctree.h
+++ b/kernel-shared/ctree.h
@@ -328,6 +328,7 @@  static inline unsigned long btrfs_chunk_item_size(int num_stripes)
 
 #define BTRFS_HEADER_FLAG_WRITTEN		(1ULL << 0)
 #define BTRFS_HEADER_FLAG_RELOC			(1ULL << 1)
+#define BTRFS_HEADER_FLAG_V2			(1ULL << 2)
 #define BTRFS_SUPER_FLAG_SEEDING		(1ULL << 32)
 #define BTRFS_SUPER_FLAG_METADUMP		(1ULL << 33)
 #define BTRFS_SUPER_FLAG_METADUMP_V2		(1ULL << 34)
@@ -361,6 +362,11 @@  struct btrfs_header {
 	u8 level;
 } __attribute__ ((__packed__));
 
+struct btrfs_header_v2 {
+	struct btrfs_header header_v1;
+	__le64 snapshot_id;
+} __attribute__ ((__packed__));
+
 static inline u32 __BTRFS_LEAF_DATA_SIZE(u32 nodesize)
 {
 	return nodesize - sizeof(struct btrfs_header);
@@ -1569,13 +1575,13 @@  static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)
 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits)		\
 static inline u##bits btrfs_##name(const struct extent_buffer *eb)	\
 {									\
-	const struct btrfs_header *h = (struct btrfs_header *)eb->data;	\
+	const type *h = (type *)eb->data;				\
 	return le##bits##_to_cpu(h->member);				\
 }									\
 static inline void btrfs_set_##name(struct extent_buffer *eb,		\
 				    u##bits val)			\
 {									\
-	struct btrfs_header *h = (struct btrfs_header *)eb->data;	\
+	type *h = (type *)eb->data;					\
 	h->member = cpu_to_le##bits(val);				\
 }
 
@@ -2142,12 +2148,16 @@  BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
 BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
 BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
 BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
+BTRFS_SETGET_HEADER_FUNCS(header_snapshot_id, struct btrfs_header_v2,
+			  snapshot_id, 64);
 BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64);
 BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header, nritems,
 			 32);
 BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64);
 BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header,
 			 generation, 64);
+BTRFS_SETGET_STACK_FUNCS(stack_header_snapshot_id, struct btrfs_header_v2,
+			 snapshot_id, 64);
 
 static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag)
 {