From 228c5d8b4b84c6939495fd124d35d42e808831cc Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Fri, 19 May 2017 08:56:40 -0700 Subject: [PATCH] scoutfs-utils: support meta and data seqs Signed-off-by: Zach Brown --- utils/src/format.h | 19 ++++++++++++++++--- utils/src/ioctl.h | 4 ++++ utils/src/mkfs.c | 13 +++++++------ utils/src/print.c | 9 +++++++-- utils/src/stat.c | 4 +++- utils/src/walk_inodes.c | 4 ++++ 6 files changed, 41 insertions(+), 12 deletions(-) diff --git a/utils/src/format.h b/utils/src/format.h index 7e91afa1..dd991c2d 100644 --- a/utils/src/format.h +++ b/utils/src/format.h @@ -163,6 +163,8 @@ struct scoutfs_segment_block { #define SCOUTFS_INODE_INDEX_CTIME_KEY 13 #define SCOUTFS_INODE_INDEX_MTIME_KEY 14 #define SCOUTFS_INODE_INDEX_SIZE_KEY 15 +#define SCOUTFS_INODE_INDEX_META_SEQ_KEY 16 +#define SCOUTFS_INODE_INDEX_DATA_SEQ_KEY 17 /* not found in the fs */ #define SCOUTFS_MAX_UNUSED_KEY 253 #define SCOUTFS_NET_ADDR_KEY 254 @@ -280,6 +282,7 @@ struct scoutfs_super_block { __le64 id; __u8 uuid[SCOUTFS_UUID_BYTES]; __le64 next_ino; + __le64 next_seq; __le64 alloc_uninit; __le64 total_segs; __le64 free_segs; @@ -300,6 +303,14 @@ struct scoutfs_timespec { } __packed; /* + * @meta_seq: advanced the first time an inode is updated in a given + * transaction. It can only advance again after the inode is written + * and a new transaction opens. + * + * @data_seq: advanced the first time a file's data (or size) is + * modified in a given transaction. It can only advance again after the + * file is written and a new transaction opens. + * * @data_version: incremented every time the contents of a file could * have changed. It is exposed via an ioctl and is then provided as an * argument to data functions to protect racing modification. @@ -314,6 +325,8 @@ struct scoutfs_timespec { struct scoutfs_inode { __le64 size; __le64 blocks; + __le64 meta_seq; + __le64 data_seq; __le64 data_version; __le64 next_readdir_pos; __le32 nlink; @@ -426,13 +439,13 @@ struct scoutfs_net_segnos { } __packed; enum { - /* sends and receives a struct scoutfs_timeval */ - SCOUTFS_NET_TRADE_TIME = 0, - SCOUTFS_NET_ALLOC_INODES, + SCOUTFS_NET_ALLOC_INODES = 0, SCOUTFS_NET_MANIFEST_RANGE_ENTRIES, SCOUTFS_NET_ALLOC_SEGNO, SCOUTFS_NET_RECORD_SEGMENT, SCOUTFS_NET_BULK_ALLOC, + SCOUTFS_NET_ADVANCE_SEQ, + SCOUTFS_NET_GET_LAST_SEQ, SCOUTFS_NET_UNKNOWN, }; diff --git a/utils/src/ioctl.h b/utils/src/ioctl.h index 822147d3..64fd525d 100644 --- a/utils/src/ioctl.h +++ b/utils/src/ioctl.h @@ -43,6 +43,8 @@ enum { SCOUTFS_IOC_WALK_INODES_CTIME = 0, SCOUTFS_IOC_WALK_INODES_MTIME, SCOUTFS_IOC_WALK_INODES_SIZE, + SCOUTFS_IOC_WALK_INODES_META_SEQ, + SCOUTFS_IOC_WALK_INODES_DATA_SEQ, SCOUTFS_IOC_WALK_INODES_UNKNOWN, }; @@ -143,6 +145,8 @@ struct scoutfs_ioctl_stage { */ struct scoutfs_ioctl_stat_more { __u64 valid_bytes; + __u64 meta_seq; + __u64 data_seq; __u64 data_version; } __packed; diff --git a/utils/src/mkfs.c b/utils/src/mkfs.c index 005723d8..31d719ae 100644 --- a/utils/src/mkfs.c +++ b/utils/src/mkfs.c @@ -131,6 +131,7 @@ static int write_new_fs(char *path, int fd) super->id = cpu_to_le64(SCOUTFS_SUPER_ID); uuid_generate(super->uuid); super->next_ino = cpu_to_le64(SCOUTFS_ROOT_INO + 1); + super->next_seq = cpu_to_le64(1); super->total_segs = cpu_to_le64(total_segs); super->next_seg_seq = cpu_to_le64(2); @@ -193,7 +194,7 @@ static int write_new_fs(char *path, int fd) ikey->type = SCOUTFS_INODE_KEY; ikey->ino = cpu_to_be64(SCOUTFS_ROOT_INO); idx_key = (void *)(ikey + 1); - idx_key->type = SCOUTFS_INODE_INDEX_SIZE_KEY; + idx_key->type = SCOUTFS_INODE_INDEX_META_SEQ_KEY; idx_key->major = cpu_to_be64(0); idx_key->minor = 0; idx_key->ino = cpu_to_be64(SCOUTFS_ROOT_INO); @@ -212,12 +213,12 @@ static int write_new_fs(char *path, int fd) /* write seg with root inode */ sblk->segno = cpu_to_le64(first_segno); sblk->seq = cpu_to_le64(1); - sblk->nr_items = cpu_to_le32(4); + sblk->nr_items = cpu_to_le32(5); item = &sblk->items[0]; - ikey = (void *)&sblk->items[4]; + ikey = (void *)&sblk->items[5]; inode = (void *)(ikey + 1) + - (3 * sizeof(struct scoutfs_inode_index_key)); + (4 * sizeof(struct scoutfs_inode_index_key)); item->seq = cpu_to_le64(1); item->key_off = cpu_to_le32((long)ikey - (long)sblk); @@ -243,7 +244,7 @@ static int write_new_fs(char *path, int fd) /* write the root inode index keys */ for (i = SCOUTFS_INODE_INDEX_CTIME_KEY; - i <= SCOUTFS_INODE_INDEX_SIZE_KEY; i++) { + i <= SCOUTFS_INODE_INDEX_META_SEQ_KEY; i++) { item->seq = cpu_to_le64(1); item->key_off = cpu_to_le32((long)idx_key - (long)sblk); @@ -260,7 +261,7 @@ static int write_new_fs(char *path, int fd) idx_key->major = cpu_to_be64(tv.tv_sec); idx_key->minor = cpu_to_be32(tv.tv_usec * 1000); break; - case SCOUTFS_INODE_INDEX_SIZE_KEY: + default: idx_key->major = cpu_to_be64(0); idx_key->minor = 0; break; diff --git a/utils/src/print.c b/utils/src/print.c index 9dd03192..3fb5a313 100644 --- a/utils/src/print.c +++ b/utils/src/print.c @@ -80,7 +80,7 @@ static void print_inode(void *key, int key_len, void *val, int val_len) printf(" inode: ino %llu size %llu blocks %llu nlink %u\n" " uid %u gid %u mode 0%o rdev 0x%x\n" - " next_readdir_pos %llu data_version %llu\n" + " next_readdir_pos %llu meta_seq %llu data_seq %llu data_version %llu\n" " atime %llu.%08u ctime %llu.%08u\n" " mtime %llu.%08u\n", be64_to_cpu(ikey->ino), @@ -89,6 +89,8 @@ static void print_inode(void *key, int key_len, void *val, int val_len) le32_to_cpu(inode->gid), le32_to_cpu(inode->mode), le32_to_cpu(inode->rdev), le64_to_cpu(inode->next_readdir_pos), + le64_to_cpu(inode->meta_seq), + le64_to_cpu(inode->data_seq), le64_to_cpu(inode->data_version), le64_to_cpu(inode->atime.sec), le32_to_cpu(inode->atime.nsec), @@ -250,6 +252,8 @@ static print_func_t printers[] = { [SCOUTFS_INODE_INDEX_CTIME_KEY] = print_inode_index, [SCOUTFS_INODE_INDEX_MTIME_KEY] = print_inode_index, [SCOUTFS_INODE_INDEX_SIZE_KEY] = print_inode_index, + [SCOUTFS_INODE_INDEX_META_SEQ_KEY] = print_inode_index, + [SCOUTFS_INODE_INDEX_DATA_SEQ_KEY] = print_inode_index, }; /* utils uses big contiguous allocations */ @@ -443,11 +447,12 @@ static void print_super_block(struct scoutfs_super_block *super, u64 blkno) printf(" id %llx uuid %s\n", le64_to_cpu(super->id), uuid_str); /* XXX these are all in a crazy order */ - printf(" next_ino %llu\n" + printf(" next_ino %llu next_seq %llu\n" " ring_blkno %llu ring_blocks %llu ring_tail_block %llu\n" " ring_gen %llu alloc_uninit %llu total_segs %llu\n" " next_seg_seq %llu free_segs %llu\n", le64_to_cpu(super->next_ino), + le64_to_cpu(super->next_seq), le64_to_cpu(super->ring_blkno), le64_to_cpu(super->ring_blocks), le64_to_cpu(super->ring_tail_block), diff --git a/utils/src/stat.c b/utils/src/stat.c index 11d0972e..b584441b 100644 --- a/utils/src/stat.c +++ b/utils/src/stat.c @@ -48,8 +48,10 @@ static int stat_more_cmd(int argc, char **argv) "%s (%d)\n", path, strerror(errno), errno); } else { printf(" File: '%s'\n" + " meta_seq: %-20llu data_seq %-20llu" " data_version: %-20llu\n", - path, stm.data_version); + path, stm.meta_seq, stm.data_seq, + stm.data_version); } close(fd); diff --git a/utils/src/walk_inodes.c b/utils/src/walk_inodes.c index 80ef6d6c..5d06c4cd 100644 --- a/utils/src/walk_inodes.c +++ b/utils/src/walk_inodes.c @@ -86,6 +86,10 @@ static int walk_inodes_cmd(int argc, char **argv) walk.index = SCOUTFS_IOC_WALK_INODES_CTIME; else if (!strcasecmp(argv[0], "mtime")) walk.index = SCOUTFS_IOC_WALK_INODES_MTIME; + else if (!strcasecmp(argv[0], "meta_seq")) + walk.index = SCOUTFS_IOC_WALK_INODES_META_SEQ; + else if (!strcasecmp(argv[0], "data_seq")) + walk.index = SCOUTFS_IOC_WALK_INODES_DATA_SEQ; else { fprintf(stderr, "unknown index '%s', try 'size', 'ctime, or " "mtime'\n", argv[0]);