scoutfs-utils: support meta and data seqs

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2017-05-19 08:56:40 -07:00
parent 08aaa5b430
commit 228c5d8b4b
6 changed files with 41 additions and 12 deletions

View File

@@ -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,
};

View File

@@ -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;

View File

@@ -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;

View File

@@ -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),

View File

@@ -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);

View File

@@ -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]);