Introduce checks for FREE_SPACE_INFO item, which include: - Key alignment check The objectid is the logical bytenr of the chunk/bg, and offset is the length of the chunk/bg, thus they should all be aligned to the fs block size. - Item size check The FREE_SPACE_INFO should a fix size. - Flags check The flags member should have no other flags than BTRFS_FREE_SPACE_USING_BITMAPS. For future expansion, introduce a new macro BTRFS_FREE_SPACE_FLAGS_MASK for such checks. And since we're here, the BTRFS_FREE_SPACE_USING_BITMAPS should not use unsigned long long, as the flags is only 32 bits wide. So fix that to use unsigned long. - Extent count check That member shows how many free space bitmap/extent items there are inside the chunk/bg. We know the chunk size (from key->offset), thus there should be at most (key->offset >> sectorsize_bits) blocks inside the chunk. Use that value as the upper limit and if that counter is larger than that, there is a high chance it's a bitflip in high bits.
Showing the changes to include/uapi (1 of 2 files). Show all
Unified · Split
| @@ -1245,7 +1245,8 @@ struct btrfs_free_space_info { · 1244 unmodified lines | |||
| 1245 | __le32 flags; | 1245 | __le32 flags; |
| 1246 | } __attribute__ ((__packed__)); | 1246 | } __attribute__ ((__packed__)); |
| 1247 | 1247 | ||
| 1248 | #define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0) | 1248 | #define BTRFS_FREE_SPACE_USING_BITMAPS (1UL << 0) |
| 1249 | #define BTRFS_FREE_SPACE_FLAGS_MASK (BTRFS_FREE_SPACE_USING_BITMAPS) | ||
| 1249 | 1250 | ||
| 1250 | #define BTRFS_QGROUP_LEVEL_SHIFT 48 | 1251 | #define BTRFS_QGROUP_LEVEL_SHIFT 48 |
| 1251 | static inline __u16 btrfs_qgroup_level(__u64 qgroupid) | 1252 | static inline __u16 btrfs_qgroup_level(__u64 qgroupid) |