Skip to content

Commit a702a69

Browse files
Christoph Hellwigaxboe
authored andcommitted
bcache: use a separate data structure for the on-disk super block
Split out an on-disk version struct cache_sb with the proper endianness annotations. This fixes a fair chunk of sparse warnings, but there are some left due to the way the checksum is defined. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Coly Li <colyli@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e8547d4 commit a702a69

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

‎drivers/md/bcache/super.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ static const char *read_super(struct cache_sb *sb, struct block_device *bdev,
6363
struct page **res)
6464
{
6565
const char *err;
66-
struct cache_sb *s;
66+
struct cache_sb_disk *s;
6767
struct buffer_head *bh = __bread(bdev, 1, SB_SIZE);
6868
unsigned int i;
6969

7070
if (!bh)
7171
return "IO error";
7272

73-
s = (struct cache_sb *) bh->b_data;
73+
s = (struct cache_sb_disk *)bh->b_data;
7474

7575
sb->offset = le64_to_cpu(s->offset);
7676
sb->version = le64_to_cpu(s->version);
@@ -209,7 +209,7 @@ static void write_bdev_super_endio(struct bio *bio)
209209

210210
static void __write_super(struct cache_sb *sb, struct bio *bio)
211211
{
212-
struct cache_sb *out = page_address(bio_first_page_all(bio));
212+
struct cache_sb_disk *out = page_address(bio_first_page_all(bio));
213213
unsigned int i;
214214

215215
bio->bi_iter.bi_sector = SB_SECTOR;

‎include/uapi/linux/bcache.h‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,57 @@ static inline struct bkey *bkey_idx(const struct bkey *k, unsigned int nr_keys)
156156

157157
#define BDEV_DATA_START_DEFAULT 16 /* sectors */
158158

159+
struct cache_sb_disk {
160+
__le64 csum;
161+
__le64 offset; /* sector where this sb was written */
162+
__le64 version;
163+
164+
__u8 magic[16];
165+
166+
__u8 uuid[16];
167+
union {
168+
__u8 set_uuid[16];
169+
__le64 set_magic;
170+
};
171+
__u8 label[SB_LABEL_SIZE];
172+
173+
__le64 flags;
174+
__le64 seq;
175+
__le64 pad[8];
176+
177+
union {
178+
struct {
179+
/* Cache devices */
180+
__le64 nbuckets; /* device size */
181+
182+
__le16 block_size; /* sectors */
183+
__le16 bucket_size; /* sectors */
184+
185+
__le16 nr_in_set;
186+
__le16 nr_this_dev;
187+
};
188+
struct {
189+
/* Backing devices */
190+
__le64 data_offset;
191+
192+
/*
193+
* block_size from the cache device section is still used by
194+
* backing devices, so don't add anything here until we fix
195+
* things to not need it for backing devices anymore
196+
*/
197+
};
198+
};
199+
200+
__le32 last_mount; /* time overflow in y2106 */
201+
202+
__le16 first_bucket;
203+
union {
204+
__le16 njournal_buckets;
205+
__le16 keys;
206+
};
207+
__le64 d[SB_JOURNAL_BUCKETS]; /* journal buckets */
208+
};
209+
159210
struct cache_sb {
160211
__u64 csum;
161212
__u64 offset; /* sector where this sb was written */

0 commit comments

Comments
 (0)