From: Matthew Dillon Date: Tue, 20 Jan 2009 01:06:53 +0000 (-0800) Subject: HAMMER utility - Add ^C support, improve verbosity. X-Git-Tag: v2.3.0~25 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/445faa6982b6614e5beb87c4673dc042e8bf7114 HAMMER utility - Add ^C support, improve verbosity. The hammer utility will now write-out the cycle file when pruning or reblocking is interrupted with ^C. The hammer cleanup directive will now wait for children to exit before exiting itself. The hammer reblocking and pruning directives now generate more verbose printf output. --- diff --git a/sbin/hammer/cmd_cleanup.c b/sbin/hammer/cmd_cleanup.c index 8cc13f968b..07014e06ea 100644 --- a/sbin/hammer/cmd_cleanup.c +++ b/sbin/hammer/cmd_cleanup.c @@ -715,6 +715,7 @@ runcmd(int *resp, const char *ctl, ...) /* * Run the command. */ + RunningIoctl = 1; if ((pid = fork()) == 0) { if (VerboseOpt < 2) { int fd = open("/dev/null", O_RDWR); @@ -727,10 +728,14 @@ runcmd(int *resp, const char *ctl, ...) res = 127; } else { int status; + while (waitpid(pid, &status, 0) != pid) ; res = WEXITSTATUS(status); } + RunningIoctl = 0; + if (DidInterrupt) + _exit(1); free(cmd); free(av); diff --git a/sbin/hammer/cmd_reblock.c b/sbin/hammer/cmd_reblock.c index f4040de769..75b1a3b485 100644 --- a/sbin/hammer/cmd_reblock.c +++ b/sbin/hammer/cmd_reblock.c @@ -94,15 +94,19 @@ hammer_cmd_reblock(char **av, int ac, int flags) reblock.free_level = HAMMER_LARGEBLOCK_SIZE - reblock.free_level; if (reblock.free_level < 0) reblock.free_level = 0; - printf("reblock free level %d\n", reblock.free_level); + printf("reblock start %016llx:%04x free level %d\n", + reblock.key_beg.obj_id, + reblock.key_beg.localization, + reblock.free_level); fd = open(filesystem, O_RDONLY); if (fd < 0) err(1, "Unable to open %s", filesystem); + RunningIoctl = 1; if (ioctl(fd, HAMMERIOC_REBLOCK, &reblock) < 0) { printf("Reblock %s failed: %s\n", filesystem, strerror(errno)); } else if (reblock.head.flags & HAMMER_IOC_HEAD_INTR) { - printf("Reblock %s interrupted by timer at %016llx %04x\n", + printf("Reblock %s interrupted by timer at %016llx:%04x\n", filesystem, reblock.key_cur.obj_id, reblock.key_cur.localization); @@ -114,6 +118,7 @@ hammer_cmd_reblock(char **av, int ac, int flags) hammer_reset_cycle(); printf("Reblock %s succeeded\n", filesystem); } + RunningIoctl = 0; close(fd); printf("Reblocked:\n" " %lld/%lld btree nodes\n" diff --git a/sbin/hammer/cmd_softprune.c b/sbin/hammer/cmd_softprune.c index 9b8646635c..ef0707a1b3 100644 --- a/sbin/hammer/cmd_softprune.c +++ b/sbin/hammer/cmd_softprune.c @@ -145,10 +145,13 @@ hammer_cmd_softprune(char **av, int ac, int everything_opt) rcode = 1; continue; } - printf("objspace %016llx %016llx\n", + printf("objspace %016llx:%04x %016llx:%04x\n", scan->prune.key_beg.obj_id, - scan->prune.key_end.obj_id); + scan->prune.key_beg.localization, + scan->prune.key_end.obj_id, + scan->prune.key_end.localization); + RunningIoctl = 1; if (ioctl(fd, HAMMERIOC_PRUNE, &scan->prune) < 0) { printf("Prune %s failed: %s\n", scan->filesystem, strerror(errno)); @@ -174,6 +177,7 @@ hammer_cmd_softprune(char **av, int ac, int everything_opt) scan->prune.stat_dirrecords, scan->prune.stat_bytes ); + RunningIoctl = 0; close(fd); } if (rcode) diff --git a/sbin/hammer/hammer.c b/sbin/hammer/hammer.c index 14ee858faa..fc5eb5ba9a 100644 --- a/sbin/hammer/hammer.c +++ b/sbin/hammer/hammer.c @@ -40,6 +40,7 @@ static void hammer_parsedevs(const char *blkdevs); static void sigalrm(int signo); +static void sigintr(int signo); static void usage(int exit_code); int RecurseOpt; @@ -49,6 +50,8 @@ int NoSyncOpt; int TwoWayPipeOpt; int TimeoutOpt; int DelayOpt = 5; +int RunningIoctl; +int DidInterrupt; u_int64_t BandwidthOpt; const char *CyclePath; const char *LinkPath; @@ -134,6 +137,7 @@ main(int ac, char **av) } signal(SIGALRM, sigalrm); + signal(SIGINT, sigintr); if (strcmp(av[0], "synctid") == 0) { hammer_cmd_synctid(av + 1, ac - 1); @@ -355,6 +359,16 @@ sigalrm(int signo __unused) /* do nothing (interrupts HAMMER ioctl) */ } +static +void +sigintr(int signo __unused) +{ + if (RunningIoctl == 0) + _exit(1); + DidInterrupt = 1; + /* do nothing (interrupts HAMMER ioctl) */ +} + static void usage(int exit_code) diff --git a/sbin/hammer/hammer.h b/sbin/hammer/hammer.h index ed8f5b37d9..ec7d7d7b55 100644 --- a/sbin/hammer/hammer.h +++ b/sbin/hammer/hammer.h @@ -66,6 +66,8 @@ extern int QuietOpt; extern int TwoWayPipeOpt; extern int TimeoutOpt; extern int DelayOpt; +extern int RunningIoctl; +extern int DidInterrupt; extern u_int64_t BandwidthOpt; extern const char *LinkPath; extern const char *CyclePath;