From acda5a3bf108d48b5c3297b1c77a8ef5adce838b Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Wed, 1 Feb 2017 13:30:44 -0800 Subject: [PATCH] Add support for free_segs in super The allocator records the total number of free segments in the super block. Signed-off-by: Zach Brown --- utils/src/format.h | 3 +++ utils/src/mkfs.c | 1 + utils/src/print.c | 5 +++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/utils/src/format.h b/utils/src/format.h index 2ba9cbd8..4a6b15bf 100644 --- a/utils/src/format.h +++ b/utils/src/format.h @@ -23,6 +23,8 @@ #define SCOUTFS_SEGMENT_MASK (SCOUTFS_SEGMENT_SIZE - 1) #define SCOUTFS_SEGMENT_PAGES (SCOUTFS_SEGMENT_SIZE / PAGE_SIZE) #define SCOUTFS_SEGMENT_BLOCKS (SCOUTFS_SEGMENT_SIZE / SCOUTFS_BLOCK_SIZE) +#define SCOUTFS_SEGMENT_BLOCK_SHIFT \ + (SCOUTFS_SEGMENT_SHIFT - SCOUTFS_BLOCK_SHIFT) #define SCOUTFS_PAGES_PER_BLOCK (SCOUTFS_BLOCK_SIZE / PAGE_SIZE) #define SCOUTFS_BLOCK_PAGE_ORDER (SCOUTFS_BLOCK_SHIFT - PAGE_SHIFT) @@ -350,6 +352,7 @@ struct scoutfs_super_block { __le64 next_ino; __le64 alloc_uninit; __le64 total_segs; + __le64 free_segs; __le64 total_blocks; __le64 free_blocks; __le64 ring_blkno; diff --git a/utils/src/mkfs.c b/utils/src/mkfs.c index 57174c9f..26f58ea3 100644 --- a/utils/src/mkfs.c +++ b/utils/src/mkfs.c @@ -159,6 +159,7 @@ static int write_new_fs(char *path, int fd) /* alloc from uninit, don't need regions yet */ super->alloc_uninit = cpu_to_le64(first_segno + 1); + super->free_segs = cpu_to_le64(total_segs - (first_segno + 1)); /* write seg with root inode */ sblk->segno = cpu_to_le64(first_segno); diff --git a/utils/src/print.c b/utils/src/print.c index 9f486ccc..27243ca8 100644 --- a/utils/src/print.c +++ b/utils/src/print.c @@ -408,7 +408,7 @@ static int print_super_blocks(int fd) printf(" next_ino %llu total_blocks %llu free_blocks %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\n", + " next_seg_seq %llu free_segs %llu\n", le64_to_cpu(super->next_ino), le64_to_cpu(super->total_blocks), le64_to_cpu(super->free_blocks), @@ -418,7 +418,8 @@ static int print_super_blocks(int fd) le64_to_cpu(super->ring_gen), le64_to_cpu(super->alloc_uninit), le64_to_cpu(super->total_segs), - le64_to_cpu(super->next_seg_seq)); + le64_to_cpu(super->next_seg_seq), + le64_to_cpu(super->free_segs)); printf(" alloc root:"); print_treap_ref(&super->alloc_treap_root.ref); printf("\n");