From: NeilBrown Date: Mon, 2 May 2011 01:34:41 +0000 (+1000) Subject: Show seguage X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=5414603f35d4a9465c2fa399fec8ec0e5a13bb6c;p=lafs-utils.git Show seguage Provide function to show segusage info, and fix some bugs exposed by that new visibility. Signed-off-by: NeilBrown --- diff --git a/include/lafs/lafs.h b/include/lafs/lafs.h index 9ad5a62..6c90f4e 100644 --- a/include/lafs/lafs.h +++ b/include/lafs/lafs.h @@ -72,6 +72,7 @@ void lafs_summary_update(struct lafs_ino *ino, loff_t oldaddr, loff_t newaddr, int is_index); void lafs_segment_count(struct lafs *fs, loff_t addr, int diff); +void lafs_segment_apply_delayed(struct lafs *fs); void lafs_print_device(struct lafs_device *dev); void lafs_print_devblock(struct lafs_dev *dev); @@ -81,6 +82,7 @@ void lafs_print_lafs(struct lafs *fs); void lafs_print_inode(struct lafs_ino *ino); void lafs_print_cluster(struct cluster_head *head, int blocksize, int groups, int verbose); +void lafs_print_segusage(char *buf, int blocksize, int start, int max); u32 lafs_find_next(struct lafs_ino *ino, u32 bnum); int lafs_hash_name(u32 seed, int len, const char *name); void lafs_dir_init_block(char *block, int psz, const char *name, int len, diff --git a/lib/lafs_checkpoint.c b/lib/lafs_checkpoint.c index 0e1a64a..fb0d19d 100644 --- a/lib/lafs_checkpoint.c +++ b/lib/lafs_checkpoint.c @@ -92,5 +92,6 @@ int lafs_checkpoint(struct lafs *fs) fs->flags &= ~LAFS_DELAY_UPDATES; lafs_write_state(fs); + lafs_segment_apply_delayed(fs); return 0; } diff --git a/lib/lafs_new.c b/lib/lafs_new.c index 9898e15..db599bc 100644 --- a/lib/lafs_new.c +++ b/lib/lafs_new.c @@ -39,7 +39,7 @@ int lafs_new(struct lafs *fs, int blockbytes) fs->wc[0].seq = 1; fs->wc[1].seq = 1; - fs->youth_next = 1; + fs->youth_next = 0x8000; return 0; } diff --git a/lib/lafs_new_segment.c b/lib/lafs_new_segment.c index 4efede2..43d5601 100644 --- a/lib/lafs_new_segment.c +++ b/lib/lafs_new_segment.c @@ -12,7 +12,7 @@ static void cluster_reset(struct lafs *fs, struct lafs_cluster *wc) wc->chead_size = sizeof(struct cluster_head); } -void set_youth(struct lafs *fs, int dev, loff_t seg, int youth) +static void set_youth(struct lafs *fs, int dev, loff_t seg, int youth) { struct lafs_device *dv; struct lafs_dblk *db; diff --git a/tools/lafs.c b/tools/lafs.c index 34d96d2..57c3941 100644 --- a/tools/lafs.c +++ b/tools/lafs.c @@ -1598,7 +1598,7 @@ static void c_show_dirblock(struct state *st, void **args) char *bstr = args[2]; if (!bstr) { - printf("show dirblock: now block number given\n"); + printf("show dirblock: no block number given\n"); return; } if (get_int(bstr, &bnum) < 0) { @@ -1638,6 +1638,42 @@ static void c_show_dirblock(struct state *st, void **args) free(buf); } +/****** SHOW SEGUSAGE ******/ +static char help_show_segusage[] = "Show counts in segusage block"; +static struct args args_show_segusage[] = { + { "BLOCK", opaque, -1, {NULL}, "Block number in file or LaFS"}, + TERMINAL_ARG +}; +static void c_show_segusage(struct state *st, void **args) +{ + int bnum; + char *buf; + char *bstr = args[2]; + + if (!bstr) { + printf("show segusage: no block number given\n"); + return; + } + if (get_int(bstr, &bnum) < 0) { + printf("show segusage: %s is not a valid address\n", bstr); + return; + } + if (!st->lafs->blocksize) { + printf("show segusage: LaFS not ready to show blocks\n"); + return; + } + + buf = malloc(st->lafs->blocksize); + if (lafs_read_virtual(st->lafs, buf, bnum)) { + printf("show segusage: cannot read block at %d\n", bnum); + free(buf); + return; + } + + lafs_print_segusage(buf, st->lafs->blocksize, 0, st->lafs->blocksize); + if (!args[3]) + free(buf); +} #define SCMD(x) {#x, c_show_##x, args_show_##x, help_show_##x} static struct cmd show_cmds[] = { @@ -1645,6 +1681,7 @@ static struct cmd show_cmds[] = { SCMD(device), SCMD(dirblock), SCMD(inode), + SCMD(segusage), SCMD(state), { NULL, NULL, NULL, NULL} }; @@ -1707,6 +1744,8 @@ static void c_store(struct state *st, void **args) inum = lafs_imap_alloc(imfile); inode = lafs_add_inode(fs, inum, TypeFile); lafs_dir_add(dir, tail, inum, lafs_dt_type(inode)); + inode->md.file.linkcount = 1; + lafs_dirty_inode(inode); bnum = 0; while(1) {