From 1c9a407059d0201983fa68ae02550505551beb9e Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Thu, 27 Apr 2017 12:33:52 -0700 Subject: [PATCH] scoutfs-utils: print extent items Signed-off-by: Zach Brown --- utils/src/format.h | 60 +++++++++++++++++++++++++++++++++++++++++----- utils/src/print.c | 55 +++++++++++++++++++++++++++++++++++------- 2 files changed, 100 insertions(+), 15 deletions(-) diff --git a/utils/src/format.h b/utils/src/format.h index 25cb3878..a58d12b6 100644 --- a/utils/src/format.h +++ b/utils/src/format.h @@ -156,9 +156,10 @@ struct scoutfs_segment_block { #define SCOUTFS_READDIR_KEY 6 #define SCOUTFS_LINK_BACKREF_KEY 7 #define SCOUTFS_SYMLINK_KEY 8 -#define SCOUTFS_EXTENT_KEY 9 +#define SCOUTFS_FILE_EXTENT_KEY 9 #define SCOUTFS_ORPHAN_KEY 10 -#define SCOUTFS_DATA_KEY 11 +#define SCOUTFS_FREE_EXTENT_BLKNO_KEY 11 +#define SCOUTFS_FREE_EXTENT_BLOCKS_KEY 12 /* not found in the fs */ #define SCOUTFS_MAX_UNUSED_KEY 253 #define SCOUTFS_NET_ADDR_KEY 254 @@ -198,11 +199,28 @@ struct scoutfs_orphan_key { __be64 ino; } __packed; -/* value is data payload bytes */ -struct scoutfs_data_key { +/* no value */ +struct scoutfs_file_extent_key { __u8 type; __be64 ino; - __be64 block; + __be64 last_blk_off; + __be64 last_blkno; + __be64 blocks; +} __packed; + +/* no value */ +struct scoutfs_free_extent_blkno_key { + __u8 type; + __be64 node_id; + __be64 last_blkno; + __be64 blocks; +} __packed; + +struct scoutfs_free_extent_blocks_key { + __u8 type; + __be64 node_id; + __be64 blocks; + __be64 last_blkno; } __packed; /* value is each item's part of the full xattr value for the off/len */ @@ -362,11 +380,41 @@ struct scoutfs_net_header { __u8 type; __u8 status; __u8 data[0]; -}; +} __packed; + +/* + * When there's no more free inodes this will be sent with ino = ~0 and + * nr = 0. + */ +struct scoutfs_net_inode_alloc { + __le64 ino; + __le64 nr; +} __packed; + +struct scoutfs_net_key_range { + __le16 start_len; + __le16 end_len; + __u8 key_bytes[0]; +} __packed; + +struct scoutfs_net_manifest_entries { + __le16 nr; + struct scoutfs_manifest_entry ments[0]; +} __packed; + +struct scoutfs_net_segnos { + __le16 nr; + __le64 segnos[0]; +} __packed; enum { /* sends and receives a struct scoutfs_timeval */ SCOUTFS_NET_TRADE_TIME = 0, + SCOUTFS_NET_ALLOC_INODES, + SCOUTFS_NET_MANIFEST_RANGE_ENTRIES, + SCOUTFS_NET_ALLOC_SEGNO, + SCOUTFS_NET_RECORD_SEGMENT, + SCOUTFS_NET_BULK_ALLOC, SCOUTFS_NET_UNKNOWN, }; diff --git a/utils/src/print.c b/utils/src/print.c index b6b84fc6..29fa2f82 100644 --- a/utils/src/print.c +++ b/utils/src/print.c @@ -160,14 +160,6 @@ static void print_readdir(void *key, int key_len, void *val, int val_len) name); } -static void print_data(void *key, int key_len, void *val, int val_len) -{ - struct scoutfs_data_key *dat = key; - - printf(" data: ino %llu block %llu\n", - be64_to_cpu(dat->ino), be64_to_cpu(dat->block)); -} - static void print_link_backref(void *key, int key_len, void *val, int val_len) { struct scoutfs_link_backref_key *lbkey = key; @@ -188,6 +180,49 @@ static void print_symlink(void *key, int key_len, void *val, int val_len) be64_to_cpu(skey->ino), name); } +/* + * Just print the calculated starting blk_off/blkno, we can add a flag + * to print the raw values before the math if needed. + */ +static void print_file_extent(void *key, int key_len, void *val, int val_len) +{ + struct scoutfs_file_extent_key *fext = key; + u64 blocks = be64_to_cpu(fext->blocks); + u64 blk_off = be64_to_cpu(fext->last_blk_off) - blocks + 1; + u64 blkno = be64_to_cpu(fext->last_blkno) - blocks + 1; + + printf(" extent: ino %llu blk_off %llu blkno %llu blocks %llu\n", + be64_to_cpu(fext->ino), blk_off, blkno, blocks); +} + +static void print_free_extent(void *key, int key_len, void *val, int val_len) +{ + struct scoutfs_free_extent_blkno_key *blk = key; + struct scoutfs_free_extent_blocks_key *bks = key; + u64 last_blkno; + u64 node_id; + u64 blocks; + u64 blkno; + char *str; + + if (blk->type == SCOUTFS_FREE_EXTENT_BLKNO_KEY) { + str = "free (blkno)"; + node_id = be64_to_cpu(blk->node_id); + last_blkno = be64_to_cpu(blk->last_blkno); + blocks = be64_to_cpu(blk->blocks); + } else { + str = "free (blocks)"; + node_id = be64_to_cpu(bks->node_id); + last_blkno = be64_to_cpu(bks->last_blkno); + blocks = be64_to_cpu(bks->blocks); + } + + blkno = last_blkno - blocks + 1; + + printf(" %s: node_id %llx blkno %llu blocks %llu\n", + str, node_id, blkno, blocks); +} + typedef void (*print_func_t)(void *key, int key_len, void *val, int val_len); static print_func_t printers[] = { @@ -198,7 +233,9 @@ static print_func_t printers[] = { [SCOUTFS_READDIR_KEY] = print_readdir, [SCOUTFS_SYMLINK_KEY] = print_symlink, [SCOUTFS_LINK_BACKREF_KEY] = print_link_backref, - [SCOUTFS_DATA_KEY] = print_data, + [SCOUTFS_FILE_EXTENT_KEY] = print_file_extent, + [SCOUTFS_FREE_EXTENT_BLKNO_KEY] = print_free_extent, + [SCOUTFS_FREE_EXTENT_BLOCKS_KEY] = print_free_extent, }; /* utils uses big contiguous allocations */