scoutfs: put magic value in block header

The super block had a magic value that was used to identify that the
block should contain our data structure.  But it was called an 'id'
which was confused with the header fsid in the past.  Also, the btree
blocks aren't using a similar magic value at all.

This moves the magic value in to the header and creates values for the
super block and btree blocks.  Both are written but the btree block
reads don't check the value.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2018-11-20 15:15:55 -08:00
committed by Zach Brown
parent 675275fbf1
commit 20f4e1c338
3 changed files with 12 additions and 10 deletions

View File

@@ -781,6 +781,7 @@ retry:
bt->free_end = cpu_to_le16(SCOUTFS_BLOCK_SIZE);
}
bt->hdr.magic = cpu_to_le32(SCOUTFS_BLOCK_MAGIC_BTREE);
bt->hdr.blkno = cpu_to_le64(blkno);
bt->hdr.seq = cpu_to_le64(seq);
if (ref) {
@@ -1646,7 +1647,6 @@ int scoutfs_btree_write_dirty(struct super_block *sb)
/* checksum everything to reduce time between io submission merging */
for_each_dirty_bh(bti, bh, tmp) {
bt = (void *)bh->b_data;
bt->hdr._pad = 0;
bt->hdr.crc = scoutfs_block_calc_crc(&bt->hdr);
}

View File

@@ -3,8 +3,10 @@
/* statfs(2) f_type */
#define SCOUTFS_SUPER_MAGIC 0x554f4353 /* "SCOU" */
/* super block id */
#define SCOUTFS_SUPER_ID 0x2e736674756f6373ULL /* "scoutfs." */
/* block header magic values, chosen at random */
#define SCOUTFS_BLOCK_MAGIC_SUPER 0x103c428b
#define SCOUTFS_BLOCK_MAGIC_BTREE 0xe597f96d
/*
* The super block and btree blocks are fixed 4k.
@@ -67,12 +69,12 @@ struct scoutfs_inet_addr {
/*
* This header is stored at the start of btree blocks and the super
* block for verification. The crc is calculated by zeroing the crc and
* padding so the buffer is large and aligned.
* block for verification. The crc field is not included in the
* calculation of the crc.
*/
struct scoutfs_block_header {
__le32 crc;
__le32 _pad;
__le32 magic;
__le64 fsid;
__le64 seq;
__le64 blkno;

View File

@@ -191,7 +191,7 @@ int scoutfs_write_dirty_super(struct super_block *sb)
super = page_address(page);
memcpy(super, &sbi->super, sizeof(*super));
super->hdr._pad = 0;
super->hdr.magic = cpu_to_le32(SCOUTFS_BLOCK_MAGIC_SUPER);
super->hdr.crc = scoutfs_block_calc_crc(&super->hdr);
ret = scoutfs_bio_write(sb, &page, le64_to_cpu(super->hdr.blkno), 1);
@@ -226,9 +226,9 @@ int scoutfs_read_super(struct super_block *sb,
super = scoutfs_page_block_address(&page, 0);
if (super->id != cpu_to_le64(SCOUTFS_SUPER_ID)) {
scoutfs_err(sb, "super block has invalid id %llx",
le64_to_cpu(super->id));
if (super->hdr.magic != cpu_to_le32(SCOUTFS_BLOCK_MAGIC_SUPER)) {
scoutfs_err(sb, "super block has invalid magic value 0x%08x",
le32_to_cpu(super->hdr.magic));
ret = -EINVAL;
goto out;
}