History

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.

Christoph Hellwig committed 6 years ago

Commit a702a691 parent e8547d42 files · +54 −3Browse files

Unified · Split

2 files
  1. drivers/md/bcache/super.c +3 −3
  2. include/uapi/linux/bcache.h +51 −0
drivers/md/bcache/super.c+3−3
@@ -63,14 +63,14 @@ static const char *read_super(struct cache_sb *sb, struct block_device *bdev, · 62 unmodified lines
63 struct page **res)63 struct page **res)
64{64{
65 const char *err;65 const char *err;
66 struct cache_sb *s;66 struct cache_sb_disk *s;
67 struct buffer_head *bh = __bread(bdev, 1, SB_SIZE);67 struct buffer_head *bh = __bread(bdev, 1, SB_SIZE);
68 unsigned int i;68 unsigned int i;
69 69
70 if (!bh)70 if (!bh)
71 return "IO error";71 return "IO error";
72 72
73 s = (struct cache_sb *) bh->b_data;73 s = (struct cache_sb_disk *)bh->b_data;
74 74
75 sb->offset = le64_to_cpu(s->offset);75 sb->offset = le64_to_cpu(s->offset);
76 sb->version = le64_to_cpu(s->version);76 sb->version = le64_to_cpu(s->version);
@@ -209,7 +209,7 @@ static void write_bdev_super_endio(struct bio *bio) · 132 unmodified lines
209 209
210static void __write_super(struct cache_sb *sb, struct bio *bio)210static void __write_super(struct cache_sb *sb, struct bio *bio)
211{211{
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));
213 unsigned int i;213 unsigned int i;
214 214
215 bio->bi_iter.bi_sector = SB_SECTOR;215 bio->bi_iter.bi_sector = SB_SECTOR;
include/uapi/linux/bcache.h+51−0
@@ -156,6 +156,57 @@ static inline struct bkey *bkey_idx(const struct bkey *k, unsigned int nr_keys) · 155 unmodified lines
156 156
157#define BDEV_DATA_START_DEFAULT 16 /* sectors */157#define BDEV_DATA_START_DEFAULT 16 /* sectors */
158 158
159struct 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
159struct cache_sb {210struct cache_sb {
160 __u64 csum;211 __u64 csum;
161 __u64 offset; /* sector where this sb was written */212 __u64 offset; /* sector where this sb was written */