Skip to content

Commit 6321bef

Browse files
Christoph Hellwigaxboe
authored andcommitted
bcache: use read_cache_page_gfp to read the superblock
Avoid a pointless dependency on buffer heads in bcache by simply open coding reading a single page. Also add a SB_OFFSET define for the byte offset of the superblock instead of using magic numbers. 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 475389a commit 6321bef

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

‎drivers/md/bcache/super.c‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "writeback.h"
1616

1717
#include <linux/blkdev.h>
18-
#include <linux/buffer_head.h>
1918
#include <linux/debugfs.h>
2019
#include <linux/genhd.h>
2120
#include <linux/idr.h>
@@ -64,13 +63,14 @@ static const char *read_super(struct cache_sb *sb, struct block_device *bdev,
6463
{
6564
const char *err;
6665
struct cache_sb_disk *s;
67-
struct buffer_head *bh = __bread(bdev, 1, SB_SIZE);
66+
struct page *page;
6867
unsigned int i;
6968

70-
if (!bh)
69+
page = read_cache_page_gfp(bdev->bd_inode->i_mapping,
70+
SB_OFFSET >> PAGE_SHIFT, GFP_KERNEL);
71+
if (IS_ERR(page))
7172
return "IO error";
72-
73-
s = (struct cache_sb_disk *)bh->b_data;
73+
s = page_address(page) + offset_in_page(SB_OFFSET);
7474

7575
sb->offset = le64_to_cpu(s->offset);
7676
sb->version = le64_to_cpu(s->version);
@@ -188,12 +188,10 @@ static const char *read_super(struct cache_sb *sb, struct block_device *bdev,
188188
}
189189

190190
sb->last_mount = (u32)ktime_get_real_seconds();
191-
err = NULL;
192-
193-
get_page(bh->b_page);
194191
*res = s;
192+
return NULL;
195193
err:
196-
put_bh(bh);
194+
put_page(page);
197195
return err;
198196
}
199197

‎include/uapi/linux/bcache.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ static inline struct bkey *bkey_idx(const struct bkey *k, unsigned int nr_keys)
148148
#define BCACHE_SB_MAX_VERSION 4
149149

150150
#define SB_SECTOR 8
151+
#define SB_OFFSET (SB_SECTOR << SECTOR_SHIFT)
151152
#define SB_SIZE 4096
152153
#define SB_LABEL_SIZE 32
153154
#define SB_JOURNAL_BUCKETS 256U

0 commit comments

Comments
 (0)