From 7c4bc528c61187f340213562fe14cd776564271d Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Wed, 14 Dec 2016 13:53:46 -0800 Subject: [PATCH] Make sure manifests cover all keys Make sure that the manifest entries for a given level fully cover the possible key space. This helps item reading describe cached key ranges that extend around items. Signed-off-by: Zach Brown --- utils/src/format.h | 6 ++++-- utils/src/mkfs.c | 18 +++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/utils/src/format.h b/utils/src/format.h index 002ceaac..71027e90 100644 --- a/utils/src/format.h +++ b/utils/src/format.h @@ -37,8 +37,6 @@ #define SCOUTFS_MAX_TRANS_BLOCKS (128 * 1024 * 1024 / SCOUTFS_BLOCK_SIZE) -#define SCOUTFS_MAX_KEY_BYTES 255 - /* * This header is found at the start of every block so that we can * verify that it's what we were looking for. The crc and padding @@ -215,6 +213,7 @@ struct scoutfs_key { #define SCOUTFS_SYMLINK_KEY 8 #define SCOUTFS_EXTENT_KEY 9 #define SCOUTFS_ORPHAN_KEY 10 +#define SCOUTFS_MAX_UNUSED_KEY 255 #define SCOUTFS_MAX_ITEM_LEN 512 @@ -443,4 +442,7 @@ struct scoutfs_link_backref { __le64 offset; } __packed; +#define SCOUTFS_MAX_KEY_SIZE \ + offsetof(struct scoutfs_dirent_key, name[SCOUTFS_NAME_LEN]) + #endif diff --git a/utils/src/mkfs.c b/utils/src/mkfs.c index b477a7e2..1efc8a05 100644 --- a/utils/src/mkfs.c +++ b/utils/src/mkfs.c @@ -66,7 +66,7 @@ static u64 calc_ring_blocks(u64 size) segs = size >> SCOUTFS_SEGMENT_SHIFT; max_entry_bytes = sizeof(struct scoutfs_ring_add_manifest) + - (2 * SCOUTFS_MAX_KEY_BYTES); + (2 * SCOUTFS_MAX_KEY_SIZE); total_bytes = (segs * max_entry_bytes) * 4; blocks = DIV_ROUND_UP(total_bytes, SCOUTFS_BLOCK_SIZE); @@ -101,6 +101,7 @@ static int write_new_fs(char *path, int fd) u64 ring_blocks; u64 total_segs; u64 first_segno; + __u8 *type; int ret; gettimeofday(&tv, NULL); @@ -190,19 +191,14 @@ static int write_new_fs(char *path, int fd) /* a single manifest entry points to the single segment */ am = (void *)ring->entries; am->eh.type = SCOUTFS_RING_ADD_MANIFEST; - am->eh.len = cpu_to_le16(sizeof(struct scoutfs_ring_add_manifest) + - (2 * sizeof(struct scoutfs_inode_key))); + am->eh.len = cpu_to_le16(sizeof(struct scoutfs_ring_add_manifest) + 1); am->segno = sblk->segno; am->seq = cpu_to_le64(1); - am->first_key_len = cpu_to_le16(sizeof(struct scoutfs_inode_key)); - am->last_key_len = cpu_to_le16(sizeof(struct scoutfs_inode_key)); + am->first_key_len = 0; + am->last_key_len = cpu_to_le16(1); am->level = 1; - ikey = (void *)(am + 1); - ikey->type = SCOUTFS_INODE_KEY; - ikey->ino = cpu_to_be64(SCOUTFS_ROOT_INO); - ikey = (void *)(ikey + 1); - ikey->type = SCOUTFS_INODE_KEY; - ikey->ino = cpu_to_be64(SCOUTFS_ROOT_INO); + type = (void *)(am + 1); + *type = SCOUTFS_MAX_UNUSED_KEY; /* a single alloc region records the first two segs as allocated */ reg = (void *)am + le16_to_cpu(am->eh.len);