]> git.neil.brown.name Git - lafs-utils.git/commitdiff
Show seguage
authorNeilBrown <neilb@suse.de>
Mon, 2 May 2011 01:34:41 +0000 (11:34 +1000)
committerNeilBrown <neilb@suse.de>
Mon, 2 May 2011 01:34:41 +0000 (11:34 +1000)
Provide function to show segusage info, and fix some bugs exposed
by that new visibility.

Signed-off-by: NeilBrown <neilb@suse.de>
include/lafs/lafs.h
lib/lafs_checkpoint.c
lib/lafs_new.c
lib/lafs_new_segment.c
tools/lafs.c

index 9ad5a62559639dc56224dd41d55e536b705b7e68..6c90f4eb5eb58853ca64c56fc0eb1bcd9e18d95f 100644 (file)
@@ -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,
index 0e1a64a7bb23df213c546e2ea88049d491b0bfc0..fb0d19db1caacd72e23c1505632cf960cc454495 100644 (file)
@@ -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;
 }
index 9898e1514f0d886834532ef70d6c9852705711f9..db599bcdac1cabd19fca044e812133ddccc98b0a 100644 (file)
@@ -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;
 }
index 4efede2f572409b396adfa87eb50df02267a4489..43d5601d28c4ae450cfc3741b59725c9e0af3096 100644 (file)
@@ -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;
index 34d96d2613a28cb8d660ea0db3817fcdb0aa4c51..57c394154e62a678948a8b58c4def4d8b2869d58 100644 (file)
@@ -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) {