From d7ae405ca092ffbbb6202a3ff68313bd12c8ce6d Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 11 May 2008 20:44:44 +0000 Subject: [PATCH] HAMMER Utilities: Features * Add a new option '-c cyclefile' which when coupled with '-t timeout' allows successive invocations of a pruning or reblocking operation to pick up where it left off. --- sbin/hammer/Makefile | 4 +-- sbin/hammer/cmd_prune.c | 10 ++++-- sbin/hammer/cmd_reblock.c | 19 +++++------ sbin/hammer/{hammer.h => cycle.c} | 67 +++++++++++++++++++++------------------ sbin/hammer/hammer.8 | 10 +++++- sbin/hammer/hammer.c | 13 +++++--- sbin/hammer/hammer.h | 6 +++- 7 files changed, 80 insertions(+), 49 deletions(-) copy sbin/hammer/{hammer.h => cycle.c} (64%) diff --git a/sbin/hammer/Makefile b/sbin/hammer/Makefile index 6ab8a9e40c..88b14ee00c 100644 --- a/sbin/hammer/Makefile +++ b/sbin/hammer/Makefile @@ -1,8 +1,8 @@ # -# $DragonFly: src/sbin/hammer/Makefile,v 1.9 2008/03/25 03:58:21 dillon Exp $ +# $DragonFly: src/sbin/hammer/Makefile,v 1.10 2008/05/11 20:44:44 dillon Exp $ PROG= hammer -SRCS= hammer.c ondisk.c blockmap.c cache.c misc.c \ +SRCS= hammer.c ondisk.c blockmap.c cache.c misc.c cycle.c \ cmd_show.c cmd_prune.c cmd_history.c cmd_blockmap.c \ cmd_reblock.c MAN= hammer.8 diff --git a/sbin/hammer/cmd_prune.c b/sbin/hammer/cmd_prune.c index bf05abd927..9b8fea40ce 100644 --- a/sbin/hammer/cmd_prune.c +++ b/sbin/hammer/cmd_prune.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sbin/hammer/Attic/cmd_prune.c,v 1.8 2008/05/10 22:56:37 dillon Exp $ + * $DragonFly: src/sbin/hammer/Attic/cmd_prune.c,v 1.9 2008/05/11 20:44:44 dillon Exp $ */ #include "hammer.h" @@ -71,7 +71,8 @@ hammer_cmd_prune(char **av, int ac) bzero(&prune, sizeof(prune)); prune.nelms = 0; prune.beg_obj_id = HAMMER_MIN_OBJID; - prune.end_obj_id = HAMMER_MAX_OBJID; + prune.end_obj_id = hammer_get_cycle(HAMMER_MAX_OBJID); + prune.cur_obj_id = prune.end_obj_id; /* remove me */ prune.cur_key = HAMMER_MAX_KEY; /* remove me */ prune.stat_oldest_tid = HAMMER_MAX_TID; @@ -105,7 +106,12 @@ hammer_cmd_prune(char **av, int ac) } else if (prune.head.flags & HAMMER_IOC_HEAD_INTR) { printf("Prune %s interrupted by timer at %016llx\n", filesystem, prune.cur_obj_id); + if (CyclePath) + hammer_set_cycle(prune.cur_obj_id); + } else { + if (CyclePath) + hammer_reset_cycle(); printf("Prune %s succeeded\n", filesystem); } close(fd); diff --git a/sbin/hammer/cmd_reblock.c b/sbin/hammer/cmd_reblock.c index 42eb2de122..2ff03baae9 100644 --- a/sbin/hammer/cmd_reblock.c +++ b/sbin/hammer/cmd_reblock.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sbin/hammer/cmd_reblock.c,v 1.3 2008/05/05 20:34:52 dillon Exp $ + * $DragonFly: src/sbin/hammer/cmd_reblock.c,v 1.4 2008/05/11 20:44:44 dillon Exp $ */ #include "hammer.h" @@ -50,7 +50,7 @@ hammer_cmd_reblock(char **av, int ac) int perc; bzero(&reblock, sizeof(reblock)); - reblock.beg_obj_id = HAMMER_MIN_OBJID; + reblock.beg_obj_id = hammer_get_cycle(HAMMER_MIN_OBJID); reblock.end_obj_id = HAMMER_MAX_OBJID; if (ac == 0) @@ -73,14 +73,15 @@ hammer_cmd_reblock(char **av, int ac) if (fd < 0) err(1, "Unable to open %s", filesystem); if (ioctl(fd, HAMMERIOC_REBLOCK, &reblock) < 0) { - if (errno == EINTR) { - printf("Reblock %s interrupted by timer at %016llx\n", - filesystem, reblock.cur_obj_id); - } else { - printf("Reblock %s failed: %s\n", - filesystem, strerror(errno)); - } + 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\n", + filesystem, reblock.cur_obj_id); + if (CyclePath) + hammer_set_cycle(reblock.cur_obj_id); } else { + if (CyclePath) + hammer_reset_cycle(); printf("Reblock %s succeeded\n", filesystem); } close(fd); diff --git a/sbin/hammer/hammer.h b/sbin/hammer/cycle.c similarity index 64% copy from sbin/hammer/hammer.h copy to sbin/hammer/cycle.c index 59984d1b48..fcd4fd9e31 100644 --- a/sbin/hammer/hammer.h +++ b/sbin/hammer/cycle.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007 The DragonFly Project. All rights reserved. + * Copyright (c) 2008 The DragonFly Project. All rights reserved. * * This code is derived from software contributed to The DragonFly Project * by Matthew Dillon @@ -31,40 +31,47 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sbin/hammer/hammer.h,v 1.9 2008/03/20 04:03:03 dillon Exp $ + * $DragonFly: src/sbin/hammer/cycle.c,v 1.1 2008/05/11 20:44:44 dillon Exp $ */ -#include -#include -#include -#include -#include +#include "hammer.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +int64_t +hammer_get_cycle(int64_t default_obj_id) +{ + int64_t obj_id; + FILE *fp; -#include "hammer_util.h" -#include + if ((fp = fopen(CyclePath, "r")) != NULL) { + if (fscanf(fp, "%llx\n", &obj_id) != 1) { + obj_id = default_obj_id; + fprintf(stderr, "Warning: malformed obj_id in %s\n", + CyclePath); + } + fclose(fp); + } else { + obj_id = default_obj_id; + } + return(obj_id); +} -extern int RecurseOpt; -extern int VerboseOpt; -extern const char *LinkPath; +void +hammer_set_cycle(int64_t obj_id) +{ + FILE *fp; -void hammer_cmd_show(hammer_tid_t node_offset, int depth, - hammer_base_elm_t left_bound, hammer_base_elm_t right_bound); -void hammer_cmd_prune(char **av, int ac); -void hammer_cmd_history(const char *offset_str, char **av, int ac); -void hammer_cmd_blockmap(void); -void hammer_cmd_reblock(char **av, int ac); + if ((fp = fopen(CyclePath, "w")) != NULL) { + fprintf(fp, "%016llx\n", obj_id); + fclose(fp); + } else { + fprintf(stderr, "Warning: Unable to write to %s: %s\n", + CyclePath, strerror(errno)); + } +} +void +hammer_reset_cycle(void) +{ + remove(CyclePath); +} diff --git a/sbin/hammer/hammer.8 b/sbin/hammer/hammer.8 index 1be85891a1..d7db7930e5 100644 --- a/sbin/hammer/hammer.8 +++ b/sbin/hammer/hammer.8 @@ -30,7 +30,7 @@ .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $DragonFly: src/sbin/hammer/hammer.8,v 1.13 2008/05/10 17:54:59 dillon Exp $ +.\" $DragonFly: src/sbin/hammer/hammer.8,v 1.14 2008/05/11 20:44:44 dillon Exp $ .Dd December 31, 2007 .Dt HAMMER 8 .Os @@ -40,6 +40,7 @@ .Sh SYNOPSIS .Nm .Op Fl hrx +.Op Fl c Ar cyclefile .Op Fl f Ar blkdev[:blkdev]* .Op Fl s Ar linkpath .Op Fl t Ar timeout @@ -57,6 +58,13 @@ The options are as follows: Get help .It Fl r Specify recursion for those commands which support it. +.It Fl c Ar cyclefile +When pruning and reblocking you can instruction HAMMER to start at the +object id stored in the specified file. If the file does not exist +HAMMER will start at the beginning. If HAMMER is told to run for a +specific period of time and is unable to complete the operation it will +write out the current obj_id so the next run can pick up where it left +off. If HAMMER runs to completion it will delete the cyclefile.. .It Fl f Ar blkdev[:blkdev]* Specify the volumes making up a HAMMER filesystem. .It Fl s Ar linkpath diff --git a/sbin/hammer/hammer.c b/sbin/hammer/hammer.c index c528bfa1be..732370b399 100644 --- a/sbin/hammer/hammer.c +++ b/sbin/hammer/hammer.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sbin/hammer/hammer.c,v 1.15 2008/05/10 17:54:59 dillon Exp $ + * $DragonFly: src/sbin/hammer/hammer.c,v 1.16 2008/05/11 20:44:44 dillon Exp $ */ #include "hammer.h" @@ -47,6 +47,7 @@ static void usage(int exit_code); int RecurseOpt; int VerboseOpt; int NoSyncOpt; +const char *CyclePath; const char *LinkPath; int @@ -59,8 +60,11 @@ main(int ac, char **av) u_int32_t status; char *blkdevs = NULL; - while ((ch = getopt(ac, av, "hf:rs:t:vx")) != -1) { + while ((ch = getopt(ac, av, "c:hf:rs:t:vx")) != -1) { switch(ch) { + case 'c': + CyclePath = optarg; + break; case 'h': usage(0); /* not reached */ @@ -315,9 +319,10 @@ usage(int exit_code) fprintf(stderr, "hammer -h\n" "hammer [-x] now[64]\n" + "hammer [-t timeout] [-c cyclefile] ....\n" "hammer stamp[64]