scoutfs-utils: move super id to block hdr magic

Move the magic value that identifies the super block into the block
header and use it for btree blocks as well.

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2019-04-12 10:54:20 -07:00
committed by Zach Brown
parent dd117593da
commit 64bdda717c
3 changed files with 16 additions and 15 deletions
+7 -5
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;
+3 -3
View File
@@ -229,8 +229,8 @@ static int write_new_fs(char *path, int fd, struct scoutfs_quorum_config *conf)
/* partially initialize the super so we can use it to init others */
memset(super, 0, SCOUTFS_BLOCK_SIZE);
pseudo_random_bytes(&super->hdr.fsid, sizeof(super->hdr.fsid));
super->hdr.magic = cpu_to_le32(SCOUTFS_BLOCK_MAGIC_SUPER);
super->hdr.seq = cpu_to_le64(1);
super->id = cpu_to_le64(SCOUTFS_SUPER_ID);
super->format_hash = cpu_to_le64(SCOUTFS_FORMAT_HASH);
uuid_generate(super->uuid);
super->next_ino = cpu_to_le64(SCOUTFS_ROOT_INO + 1);
@@ -293,7 +293,7 @@ static int write_new_fs(char *path, int fd, struct scoutfs_quorum_config *conf)
ebk->major = cpu_to_be64(free_len);
ebk->minor = cpu_to_be64(free_start + free_len - 1);
bt->hdr._pad = 0;
bt->hdr.magic = cpu_to_le32(SCOUTFS_BLOCK_MAGIC_BTREE);
bt->hdr.crc = cpu_to_le32(crc_block(&bt->hdr));
ret = write_raw_block(fd, blkno, bt);
@@ -338,7 +338,7 @@ static int write_new_fs(char *path, int fd, struct scoutfs_quorum_config *conf)
ino_key->ski_ino = cpu_to_le64(SCOUTFS_ROOT_INO);
ino_key->sk_type = SCOUTFS_INODE_TYPE;
bt->hdr._pad = 0;
bt->hdr.magic = cpu_to_le32(SCOUTFS_BLOCK_MAGIC_BTREE);
bt->hdr.crc = cpu_to_le32(crc_block(&bt->hdr));
ret = write_raw_block(fd, blkno, bt);
+6 -7
View File
@@ -72,9 +72,10 @@ static void print_block_header(struct scoutfs_block_header *hdr)
else
valid_str[0] = '\0';
printf(" hdr: crc %08x %sfsid %llx seq %llu blkno %llu\n",
le32_to_cpu(hdr->crc), valid_str, le64_to_cpu(hdr->fsid),
le64_to_cpu(hdr->seq), le64_to_cpu(hdr->blkno));
printf(" hdr: crc %08x %smagic %08x fsid %llx seq %llu blkno %llu\n",
le32_to_cpu(hdr->crc), valid_str, le32_to_cpu(hdr->magic),
le64_to_cpu(hdr->fsid), le64_to_cpu(hdr->blkno),
le64_to_cpu(hdr->seq));
}
static void print_inode(struct scoutfs_key *key, void *val, int val_len)
@@ -512,10 +513,8 @@ static void print_super_block(struct scoutfs_super_block *super, u64 blkno)
printf("super blkno %llu\n", blkno);
print_block_header(&super->hdr);
printf(" id %llx format_hash %llx\n"
" uuid %s\n",
le64_to_cpu(super->id), le64_to_cpu(super->format_hash),
uuid_str);
printf(" format_hash %llx uuid %s\n",
le64_to_cpu(super->format_hash), uuid_str);
/* XXX these are all in a crazy order */
printf(" next_ino %llu next_seq %llu next_seg_seq %llu\n"