From be4a137479ce9a8e1136e7fa41cece20ff49fc2e Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Fri, 5 Aug 2016 14:53:42 -0700 Subject: [PATCH] Add support for printing block map items Signed-off-by: Zach Brown --- utils/src/format.h | 20 +++++++++++++++++++- utils/src/print.c | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/utils/src/format.h b/utils/src/format.h index 2a3605c4..fbd09ddd 100644 --- a/utils/src/format.h +++ b/utils/src/format.h @@ -100,7 +100,7 @@ struct scoutfs_key { #define SCOUTFS_INODE_KEY 1 #define SCOUTFS_XATTR_KEY 2 #define SCOUTFS_DIRENT_KEY 3 -#define SCOUTFS_DATA_KEY 4 +#define SCOUTFS_BMAP_KEY 4 #define SCOUTFS_MAX_ITEM_LEN 512 @@ -244,4 +244,22 @@ struct scoutfs_xattr { __u8 name[0]; } __packed; +/* + * We use simple block map items to map a aligned fixed group of logical + * block offsets to physical blocks. We make them a decent size to + * reduce the item storage overhead per block referenced, but we don't + * want them so large that they start to take up an extraordinary amount + * of space for small files. 8 block items ranges from around 3% to .3% + * overhead for files that use only one or all of the blocks in the + * mapping item. + */ +#define SCOUTFS_BLOCK_MAP_SHIFT 3 +#define SCOUTFS_BLOCK_MAP_COUNT (1 << SCOUTFS_BLOCK_MAP_SHIFT) +#define SCOUTFS_BLOCK_MAP_MASK (SCOUTFS_BLOCK_MAP_COUNT - 1) + +struct scoutfs_block_map { + __le32 crc[SCOUTFS_BLOCK_MAP_COUNT]; + __le64 blkno[SCOUTFS_BLOCK_MAP_COUNT]; +}; + #endif diff --git a/utils/src/print.c b/utils/src/print.c index 1530d3e1..fca5837e 100644 --- a/utils/src/print.c +++ b/utils/src/print.c @@ -89,6 +89,17 @@ static void print_dirent(struct scoutfs_dirent *dent, unsigned int val_len) le64_to_cpu(dent->ino), dent->type, i, name); } +static void print_block_map(struct scoutfs_block_map *map) +{ + int i; + + printf(" bmap:"); + for (i = 0; i < SCOUTFS_BLOCK_MAP_COUNT; i++) + printf(" [%u] %llu", + i, le64_to_cpu(map->blkno[i])); + printf("\n"); +} + static void print_block_ref(struct scoutfs_block_ref *ref) { printf(" ref: blkno %llu seq %llu\n", @@ -110,6 +121,9 @@ static void print_btree_val(struct scoutfs_btree_item *item, u8 level) case SCOUTFS_DIRENT_KEY: print_dirent((void *)item->val, le16_to_cpu(item->val_len)); break; + case SCOUTFS_BMAP_KEY: + print_block_map((void *)item->val); + break; } }