Skip to content

Commit

Permalink
HAMMER Utilities: Features
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Matthew Dillon committed May 11, 2008
1 parent c695044 commit d7ae405
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 19 deletions.
4 changes: 2 additions & 2 deletions sbin/hammer/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 8 additions & 2 deletions sbin/hammer/cmd_prune.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 10 additions & 9 deletions sbin/hammer/cmd_reblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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);
Expand Down
77 changes: 77 additions & 0 deletions sbin/hammer/cycle.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2008 The DragonFly Project. All rights reserved.
*
* This code is derived from software contributed to The DragonFly Project
* by Matthew Dillon <dillon@backplane.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of The DragonFly Project nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific, prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $DragonFly: src/sbin/hammer/cycle.c,v 1.1 2008/05/11 20:44:44 dillon Exp $
*/

#include "hammer.h"

int64_t
hammer_get_cycle(int64_t default_obj_id)
{
int64_t obj_id;
FILE *fp;

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);
}

void
hammer_set_cycle(int64_t obj_id)
{
FILE *fp;

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);
}

10 changes: 9 additions & 1 deletion sbin/hammer/hammer.8
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions sbin/hammer/hammer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -47,6 +47,7 @@ static void usage(int exit_code);
int RecurseOpt;
int VerboseOpt;
int NoSyncOpt;
const char *CyclePath;
const char *LinkPath;

int
Expand All @@ -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 */
Expand Down Expand Up @@ -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] <time>\n"
"hammer [-s linkpath] prune <filesystem> [using <configfile>]\n"
"hammer [-s linkpath] prune <filesystem> from <modulo_time> to "
"hammer prune <filesystem> [using <configfile>]\n"
"hammer prune <filesystem> from <modulo_time> to "
"<modulo_time> every <modulo_time>\n"
"hammer prune <filesystem> from <modulo_time> everything\n"
"hammer prune <filesystem> everything\n"
Expand Down
6 changes: 5 additions & 1 deletion sbin/hammer/hammer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* 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/hammer.h,v 1.10 2008/05/11 20:44:44 dillon Exp $
*/

#include <sys/types.h>
Expand Down Expand Up @@ -59,6 +59,7 @@
extern int RecurseOpt;
extern int VerboseOpt;
extern const char *LinkPath;
extern const char *CyclePath;

void hammer_cmd_show(hammer_tid_t node_offset, int depth,
hammer_base_elm_t left_bound, hammer_base_elm_t right_bound);
Expand All @@ -67,4 +68,7 @@ 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);

int64_t hammer_get_cycle(int64_t default_obj_id);
void hammer_set_cycle(int64_t obj_id);
void hammer_reset_cycle(void);

0 comments on commit d7ae405

Please sign in to comment.