HAMMER utility - Add ^C support, improve verbosity.
authorMatthew Dillon <dillon@apollo.backplane.com>
Tue, 20 Jan 2009 01:06:53 +0000 (17:06 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Tue, 20 Jan 2009 01:06:53 +0000 (17:06 -0800)
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.

sbin/hammer/cmd_cleanup.c
sbin/hammer/cmd_reblock.c
sbin/hammer/cmd_softprune.c
sbin/hammer/hammer.c
sbin/hammer/hammer.h

index 8cc13f9..07014e0 100644 (file)
@@ -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);
index f4040de..75b1a3b 100644 (file)
@@ -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"
index 9b86466..ef0707a 100644 (file)
@@ -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)
index 14ee858..fc5eb5b 100644 (file)
@@ -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);
@@ -357,6 +361,16 @@ sigalrm(int signo __unused)
 
 static
 void
+sigintr(int signo __unused)
+{
+       if (RunningIoctl == 0)
+               _exit(1);
+       DidInterrupt = 1;
+       /* do nothing (interrupts HAMMER ioctl) */
+}
+
+static
+void
 usage(int exit_code)
 {
        fprintf(stderr, 
index ed8f5b3..ec7d7d7 100644 (file)
@@ -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;