2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $DragonFly: src/sbin/hammer/hammer.c,v 1.32 2008/07/09 18:32:19 swildner Exp $
41 static void hammer_parsedevs(const char *blkdevs
);
42 static void sigalrm(int signo
);
43 static void usage(int exit_code
);
50 const char *CyclePath
;
54 main(int ac
, char **av
)
60 while ((ch
= getopt(ac
, av
, "c:dhf:rs:t:v2")) != -1) {
84 TimeoutOpt
= strtol(optarg
, NULL
, 0);
101 signal(SIGALRM
, sigalrm
);
103 if (strcmp(av
[0], "synctid") == 0) {
104 hammer_cmd_synctid(av
+ 1, ac
- 1);
107 if (strcmp(av
[0], "namekey") == 0) {
112 key
= (int64_t)(crc32(av
[1], strlen(av
[1])) & 0x7FFFFFFF) << 32;
114 key
|= 0x100000000LL
;
115 printf("0x%016llx\n", key
);
118 if (strcmp(av
[0], "namekey32") == 0) {
123 key
= crc32(av
[1], strlen(av
[1])) & 0x7FFFFFFF;
126 printf("0x%08x\n", key
);
129 if (strcmp(av
[0], "pfs-status") == 0) {
130 hammer_cmd_pseudofs_status(av
+ 1, ac
- 1);
133 if (strcmp(av
[0], "pfs-master") == 0) {
134 hammer_cmd_pseudofs_create(av
+ 1, ac
- 1, 0);
137 if (strcmp(av
[0], "pfs-slave") == 0) {
138 hammer_cmd_pseudofs_create(av
+ 1, ac
- 1, 1);
141 if (strcmp(av
[0], "pfs-update") == 0) {
142 hammer_cmd_pseudofs_update(av
+ 1, ac
- 1);
145 if (strcmp(av
[0], "pfs-destroy") == 0) {
146 hammer_cmd_pseudofs_destroy(av
+ 1, ac
- 1);
149 if (strcmp(av
[0], "status") == 0) {
150 hammer_cmd_status(av
+ 1, ac
- 1);
153 if (strcmp(av
[0], "prune") == 0) {
154 hammer_cmd_softprune(av
+ 1, ac
- 1, 0);
157 if (strcmp(av
[0], "prune-everything") == 0) {
158 hammer_cmd_softprune(av
+ 1, ac
- 1, 1);
161 if (strcmp(av
[0], "snapshot") == 0) {
162 hammer_cmd_snapshot(av
+ 1, ac
- 1);
165 if (strcmp(av
[0], "bstats") == 0) {
166 hammer_cmd_bstats(av
+ 1, ac
- 1);
169 if (strcmp(av
[0], "iostats") == 0) {
170 hammer_cmd_iostats(av
+ 1, ac
- 1);
174 if (strncmp(av
[0], "history", 7) == 0) {
175 hammer_cmd_history(av
[0] + 7, av
+ 1, ac
- 1);
178 if (strncmp(av
[0], "reblock", 7) == 0) {
179 if (strcmp(av
[0], "reblock") == 0)
180 hammer_cmd_reblock(av
+ 1, ac
- 1, -1);
181 else if (strcmp(av
[0], "reblock-btree") == 0)
182 hammer_cmd_reblock(av
+ 1, ac
- 1, HAMMER_IOC_DO_BTREE
);
183 else if (strcmp(av
[0], "reblock-inodes") == 0)
184 hammer_cmd_reblock(av
+ 1, ac
- 1, HAMMER_IOC_DO_INODES
);
185 else if (strcmp(av
[0], "reblock-dirs") == 0)
186 hammer_cmd_reblock(av
+ 1, ac
- 1, HAMMER_IOC_DO_DIRS
);
187 else if (strcmp(av
[0], "reblock-data") == 0)
188 hammer_cmd_reblock(av
+ 1, ac
- 1, HAMMER_IOC_DO_DATA
);
193 if (strncmp(av
[0], "mirror", 6) == 0) {
194 if (strcmp(av
[0], "mirror-read") == 0)
195 hammer_cmd_mirror_read(av
+ 1, ac
- 1);
196 else if (strcmp(av
[0], "mirror-write") == 0)
197 hammer_cmd_mirror_write(av
+ 1, ac
- 1);
198 else if (strcmp(av
[0], "mirror-copy") == 0)
199 hammer_cmd_mirror_copy(av
+ 1, ac
- 1);
200 else if (strcmp(av
[0], "mirror-dump") == 0)
201 hammer_cmd_mirror_dump();
207 uuid_name_lookup(&Hammer_FSType
, "DragonFly HAMMER", &status
);
208 if (status
!= uuid_s_ok
) {
209 errx(1, "uuids file does not have the DragonFly "
210 "HAMMER filesystem type");
213 if (strcmp(av
[0], "show") == 0) {
214 hammer_off_t node_offset
= (hammer_off_t
)-1;
216 hammer_parsedevs(blkdevs
);
218 sscanf(av
[1], "%llx", &node_offset
);
219 hammer_cmd_show(node_offset
, 0, NULL
, NULL
);
222 if (strcmp(av
[0], "blockmap") == 0) {
223 hammer_parsedevs(blkdevs
);
224 hammer_cmd_blockmap();
234 hammer_parsedevs(const char *blkdevs
)
239 if (blkdevs
== NULL
) {
240 errx(1, "A -f blkdevs specification is required "
244 copy
= strdup(blkdevs
);
245 while ((volname
= copy
) != NULL
) {
246 if ((copy
= strchr(copy
, ':')) != NULL
)
248 setup_volume(-1, volname
, 0, O_RDONLY
);
254 sigalrm(int signo __unused
)
256 /* do nothing (interrupts HAMMER ioctl) */
265 "hammer [-t seconds] [-c cyclefile] ....\n"
266 "hammer prune <dir-holding-softlinks>\n"
267 "hammer prune-everything <filesystem>\n"
268 "hammer snapshot <softlink-dir> [<filesystem>]\n"
269 "hammer bstats <interval>\n"
270 "hammer iostats <interval>\n"
271 "hammer mirror-read <filesystem>\n"
272 "hammer mirror-write <filesystem>\n"
273 "hammer mirror-dump\n"
274 "hammer mirror-copy [[user@]host:]<filesystem>"
275 " [[user@]host:]<filesystem>\n"
276 "hammer reblock[-btree/inodes/dirs/data] "
277 "<filesystem> [pack%%]\n"
278 "hammer pfs-status <dirpath>\n"
279 "hammer pfs-master <dirpath> [options]\n"
280 "hammer pfs-slave <dirpath> [options]\n"
281 "hammer pfs-update <dirpath> [options]\n"
282 "hammer history[@offset[,len]] <file-1>...<file-N>\n"
283 "hammer -f blkdevs [-r] show\n"
284 "hammer -f blkdevs blockmap\n"