Skip to content

Commit

Permalink
HAMMER Utilities: Sync with 60E
Browse files Browse the repository at this point in the history
* Change the cycle file to hold an entire B-Tree base key, plus an optional
  TID (used by the mirroring code).

* Flesh out the mirroring code.  Add timeout (-t) support.  Add cycle file
  support.

* When mirror-copy is used have the target sync the filesystem
  and acknowledge completion and store the completed TID in the cycle
  file.

* Incremental mirroring now works when using mirror-copy with a cycle file.

* Add mirror-dump, aka hammer mirror-read ... | hammer mirror-dump, for
  debugging.
  • Loading branch information
Matthew Dillon committed Jul 7, 2008
1 parent adf0174 commit 243ca32
Show file tree
Hide file tree
Showing 9 changed files with 445 additions and 120 deletions.
446 changes: 360 additions & 86 deletions sbin/hammer/cmd_mirror.c

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion sbin/hammer/cmd_pseudofs.c
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_pseudofs.c,v 1.3 2008/07/02 22:05:59 dillon Exp $
* $DragonFly: src/sbin/hammer/cmd_pseudofs.c,v 1.4 2008/07/07 00:27:22 dillon Exp $
*/

#include "hammer.h"
Expand Down Expand Up @@ -79,6 +79,12 @@ hammer_cmd_pseudofs_create(char **av, int ac)
hammer_cmd_pseudofs_update(av, ac, 1);
}

void
hammer_cmd_pseudofs_destroy(char **av, int ac)
{
fprintf(stderr, "pfs-destroy not implemented yet\n");
}

void
hammer_cmd_pseudofs_update(char **av, int ac, int doinit)
{
Expand Down
9 changes: 6 additions & 3 deletions sbin/hammer/cmd_reblock.c
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.9 2008/06/26 04:07:57 dillon Exp $
* $DragonFly: src/sbin/hammer/cmd_reblock.c,v 1.10 2008/07/07 00:27:22 dillon Exp $
*/

#include "hammer.h"
Expand All @@ -49,11 +49,14 @@ hammer_cmd_reblock(char **av, int ac, int flags)
int fd;
int perc;

if (TimeoutOpt > 0)
alarm(TimeoutOpt);

bzero(&reblock, sizeof(reblock));

reblock.key_beg.localization = HAMMER_MIN_LOCALIZATION;
reblock.key_beg.obj_id = HAMMER_MIN_OBJID;
hammer_get_cycle(&reblock.key_beg);
hammer_get_cycle(&reblock.key_beg, NULL);

reblock.key_end.localization = HAMMER_MAX_LOCALIZATION;
reblock.key_end.obj_id = HAMMER_MAX_OBJID;
Expand Down Expand Up @@ -104,7 +107,7 @@ hammer_cmd_reblock(char **av, int ac, int flags)
reblock.key_cur.obj_id,
reblock.key_cur.localization);
if (CyclePath) {
hammer_set_cycle(&reblock.key_cur);
hammer_set_cycle(&reblock.key_cur, 0);
}
} else {
if (CyclePath)
Expand Down
7 changes: 4 additions & 3 deletions sbin/hammer/cmd_show.c
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_show.c,v 1.14 2008/07/02 22:05:59 dillon Exp $
* $DragonFly: src/sbin/hammer/cmd_show.c,v 1.15 2008/07/07 00:27:22 dillon Exp $
*/

#include "hammer.h"
Expand Down Expand Up @@ -63,8 +63,9 @@ hammer_cmd_show(hammer_off_t node_offset, int depth,
volume = get_volume(RootVolNo);
node_offset = volume->ondisk->vol0_btree_root;
if (VerboseOpt) {
printf("\trecords=%lld\n",
volume->ondisk->vol0_stat_records);
printf("Volume header\trecords=%lld next_tid=%016llx\n",
volume->ondisk->vol0_stat_records,
volume->ondisk->vol0_next_tid);
}
rel_volume(volume);
}
Expand Down
8 changes: 5 additions & 3 deletions sbin/hammer/cmd_softprune.c
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_softprune.c,v 1.5 2008/06/26 04:07:57 dillon Exp $
* $DragonFly: src/sbin/hammer/cmd_softprune.c,v 1.6 2008/07/07 00:27:22 dillon Exp $
*/

#include "hammer.h"
Expand Down Expand Up @@ -68,6 +68,8 @@ hammer_cmd_softprune(char **av, int ac, int everything_opt)

base = NULL;
rcode = 0;
if (TimeoutOpt > 0)
alarm(TimeoutOpt);

/*
* NOTE: To restrict to a single file XXX we have to set
Expand All @@ -81,7 +83,7 @@ hammer_cmd_softprune(char **av, int ac, int everything_opt)
template.key_beg.obj_id = HAMMER_MIN_OBJID;
template.key_end.localization = HAMMER_MAX_LOCALIZATION;
template.key_end.obj_id = HAMMER_MAX_OBJID;
hammer_get_cycle(&template.key_end);
hammer_get_cycle(&template.key_end, NULL);
template.stat_oldest_tid = HAMMER_MAX_TID;

/*
Expand Down Expand Up @@ -158,7 +160,7 @@ hammer_cmd_softprune(char **av, int ac, int everything_opt)
scan->prune.key_cur.obj_id,
scan->prune.key_cur.localization);
if (CyclePath)
hammer_set_cycle(&scan->prune.key_cur);
hammer_set_cycle(&scan->prune.key_cur, 0);
rcode = 0;
} else {
if (CyclePath)
Expand Down
47 changes: 35 additions & 12 deletions sbin/hammer/cycle.c
Expand Up @@ -31,33 +31,56 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $DragonFly: src/sbin/hammer/cycle.c,v 1.4 2008/06/26 04:07:57 dillon Exp $
* $DragonFly: src/sbin/hammer/cycle.c,v 1.5 2008/07/07 00:27:22 dillon Exp $
*/

#include "hammer.h"

void
hammer_get_cycle(hammer_base_elm_t base)
hammer_get_cycle(hammer_base_elm_t base, hammer_tid_t *extra)
{
FILE *fp;
struct stat st;
int fd;

if (CyclePath && (fp = fopen(CyclePath, "r")) != NULL) {
if (fscanf(fp, "%llx %x\n", &base->obj_id, &base->localization) != 2) {
fprintf(stderr, "Warning: malformed cycle in %s\n",
if (CyclePath && (fd = open(CyclePath, O_RDONLY)) >= 0) {
if (fstat(fd, &st) < 0) {
fprintf(stderr, "cycle-file %s: cannot stat\n",
CyclePath);
close(fd);
return;
}
fclose(fp);
if (st.st_size < sizeof(*base)) {
fprintf(stderr, "cycle-file %s: clearing old version\n",
CyclePath);
close(fd);
remove(CyclePath);
return;
}
if (read(fd, base, sizeof(*base)) != sizeof(*base)) {
fprintf(stderr, "cycle-file %s: read failed %s\n",
CyclePath, strerror(errno));
return;
}
if (extra) {
if (read(fd, extra, sizeof(*extra)) != sizeof(*extra)) {
fprintf(stderr, "cycle-file %s: Warning, malformed\n",
CyclePath);
}
}
close(fd);
}
/* ok if the file does not exist */
}

void
hammer_set_cycle(hammer_base_elm_t base)
hammer_set_cycle(hammer_base_elm_t base, hammer_tid_t extra)
{
FILE *fp;
int fd;

if ((fp = fopen(CyclePath, "w")) != NULL) {
fprintf(fp, "%016llx %08x\n", base->obj_id, base->localization);
fclose(fp);
if ((fd = open(CyclePath, O_RDWR|O_CREAT|O_TRUNC, 0666)) >= 0) {
write(fd, base, sizeof(*base));
write(fd, &extra, sizeof(extra));
close(fd);
} else {
fprintf(stderr, "Warning: Unable to write to %s: %s\n",
CyclePath, strerror(errno));
Expand Down
5 changes: 4 additions & 1 deletion sbin/hammer/hammer.8
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.30 2008/07/02 22:05:59 dillon Exp $
.\" $DragonFly: src/sbin/hammer/hammer.8,v 1.31 2008/07/07 00:27:22 dillon Exp $
.Dd June 26, 2008
.Dt HAMMER 8
.Os
Expand Down Expand Up @@ -311,6 +311,9 @@ Take a mirroring stream on stdin and output it to stdout.
This command will fail if the
.Ar shared_uuid
configuration field for the two filesystems do not match.
.It Ar mirror-dump
A mirror-read can be piped into a mirror-dump to dump an ascii
representation of the mirroring stream.
.It Ar mirror-copy Ar [[user@]host:]filesystem Ar [[user@]host:]filesystem
This is a shortcut which pipes a mirror-read command to a mirror-write
command. If a remote host specification is made the program forks an
Expand Down
24 changes: 16 additions & 8 deletions sbin/hammer/hammer.c
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.29 2008/07/02 22:05:59 dillon Exp $
* $DragonFly: src/sbin/hammer/hammer.c,v 1.30 2008/07/07 00:27:22 dillon Exp $
*/

#include "hammer.h"
Expand All @@ -45,19 +45,23 @@ static void usage(int exit_code);
int RecurseOpt;
int VerboseOpt;
int NoSyncOpt;
int TwoWayPipeOpt;
int TimeoutOpt;
const char *CyclePath;
const char *LinkPath;

int
main(int ac, char **av)
{
int ch;
int timeout = 0;
u_int32_t status;
char *blkdevs = NULL;

while ((ch = getopt(ac, av, "c:dhf:rs:t:v")) != -1) {
while ((ch = getopt(ac, av, "c:dhf:rs:t:v2")) != -1) {
switch(ch) {
case '2':
TwoWayPipeOpt = 1;
break;
case 'c':
CyclePath = optarg;
break;
Expand All @@ -77,7 +81,7 @@ main(int ac, char **av)
LinkPath = optarg;
break;
case 't':
timeout = strtol(optarg, NULL, 0);
TimeoutOpt = strtol(optarg, NULL, 0);
break;
case 'v':
++VerboseOpt;
Expand All @@ -94,10 +98,7 @@ main(int ac, char **av)
/* not reached */
}

if (timeout > 0) {
signal(SIGALRM, sigalrm);
alarm(timeout);
}
signal(SIGALRM, sigalrm);

if (strcmp(av[0], "synctid") == 0) {
hammer_cmd_synctid(av + 1, ac - 1);
Expand Down Expand Up @@ -137,6 +138,10 @@ main(int ac, char **av)
hammer_cmd_pseudofs_update(av + 1, ac - 1, 0);
exit(0);
}
if (strcmp(av[0], "pfs-destroy") == 0) {
hammer_cmd_pseudofs_destroy(av + 1, ac - 1);
exit(0);
}
if (strcmp(av[0], "status") == 0) {
hammer_cmd_status(av + 1, ac - 1);
exit(0);
Expand Down Expand Up @@ -188,6 +193,8 @@ main(int ac, char **av)
hammer_cmd_mirror_write(av + 1, ac - 1);
else if (strcmp(av[0], "mirror-copy") == 0)
hammer_cmd_mirror_copy(av + 1, ac - 1);
else if (strcmp(av[0], "mirror-dump") == 0)
hammer_cmd_mirror_dump();
else
usage(1);
exit(0);
Expand Down Expand Up @@ -259,6 +266,7 @@ usage(int exit_code)
"hammer iostats <interval>\n"
"hammer mirror-read <filesystem>\n"
"hammer mirror-write <filesystem>\n"
"hammer mirror-dump\n"
"hammer mirror-copy [[user@]host:]<filesystem>"
" [[user@]host:]<filesystem>\n"
"hammer reblock[-btree/inodes/dirs/data] "
Expand Down
11 changes: 8 additions & 3 deletions sbin/hammer/hammer.h
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.20 2008/07/02 22:05:59 dillon Exp $
* $DragonFly: src/sbin/hammer/hammer.h,v 1.21 2008/07/07 00:27:22 dillon Exp $
*/

#include <sys/types.h>
Expand All @@ -53,6 +53,7 @@
#include <assert.h>
#include <err.h>
#include <ctype.h>
#include <signal.h>
#include <dirent.h>
#include <uuid.h>

Expand All @@ -61,6 +62,8 @@

extern int RecurseOpt;
extern int VerboseOpt;
extern int TwoWayPipeOpt;
extern int TimeoutOpt;
extern const char *LinkPath;
extern const char *CyclePath;

Expand All @@ -74,16 +77,18 @@ void hammer_cmd_synctid(char **av, int ac);
void hammer_cmd_mirror_read(char **av, int ac);
void hammer_cmd_mirror_write(char **av, int ac);
void hammer_cmd_mirror_copy(char **av, int ac);
void hammer_cmd_mirror_dump(void);
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, int flags);
void hammer_cmd_pseudofs_status(char **av, int ac);
void hammer_cmd_pseudofs_create(char **av, int ac);
void hammer_cmd_pseudofs_update(char **av, int ac, int doinit);
void hammer_cmd_pseudofs_destroy(char **av, int ac);
void hammer_cmd_status(char **av, int ac);
void hammer_cmd_snapshot(char **av, int ac);

void hammer_get_cycle(hammer_base_elm_t base);
void hammer_set_cycle(hammer_base_elm_t base);
void hammer_get_cycle(hammer_base_elm_t base, hammer_tid_t *tidp);
void hammer_set_cycle(hammer_base_elm_t base, hammer_tid_t tid);
void hammer_reset_cycle(void);

0 comments on commit 243ca32

Please sign in to comment.