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.33.2.4 2008/09/25 01:39:33 dillon Exp $
41 static void hammer_parsedevs(const char *blkdevs
);
42 static void sigalrm(int signo
);
43 static void usage(int exit_code
);
51 u_int64_t BandwidthOpt
;
52 const char *CyclePath
;
56 main(int ac
, char **av
)
63 while ((ch
= getopt(ac
, av
, "b:c:dhf:i:rs:t:v2")) != -1) {
69 BandwidthOpt
= strtoull(optarg
, &ptr
, 0);
97 DelayOpt
= strtol(optarg
, NULL
, 0);
109 TimeoutOpt
= strtol(optarg
, NULL
, 0);
126 signal(SIGALRM
, sigalrm
);
128 if (strcmp(av
[0], "synctid") == 0) {
129 hammer_cmd_synctid(av
+ 1, ac
- 1);
132 if (strcmp(av
[0], "namekey") == 0) {
137 key
= (int64_t)(crc32(av
[1], strlen(av
[1])) & 0x7FFFFFFF) << 32;
139 key
|= 0x100000000LL
;
140 printf("0x%016llx\n", key
);
143 if (strcmp(av
[0], "namekey32") == 0) {
148 key
= crc32(av
[1], strlen(av
[1])) & 0x7FFFFFFF;
151 printf("0x%08x\n", key
);
154 if (strcmp(av
[0], "pfs-status") == 0) {
155 hammer_cmd_pseudofs_status(av
+ 1, ac
- 1);
158 if (strcmp(av
[0], "pfs-master") == 0) {
159 hammer_cmd_pseudofs_create(av
+ 1, ac
- 1, 0);
162 if (strcmp(av
[0], "pfs-slave") == 0) {
163 hammer_cmd_pseudofs_create(av
+ 1, ac
- 1, 1);
166 if (strcmp(av
[0], "pfs-update") == 0) {
167 hammer_cmd_pseudofs_update(av
+ 1, ac
- 1);
170 if (strcmp(av
[0], "pfs-upgrade") == 0) {
171 hammer_cmd_pseudofs_upgrade(av
+ 1, ac
- 1);
174 if (strcmp(av
[0], "pfs-downgrade") == 0) {
175 hammer_cmd_pseudofs_downgrade(av
+ 1, ac
- 1);
178 if (strcmp(av
[0], "pfs-destroy") == 0) {
179 hammer_cmd_pseudofs_destroy(av
+ 1, ac
- 1);
182 if (strcmp(av
[0], "status") == 0) {
183 hammer_cmd_status(av
+ 1, ac
- 1);
186 if (strcmp(av
[0], "prune") == 0) {
187 hammer_cmd_softprune(av
+ 1, ac
- 1, 0);
190 if (strcmp(av
[0], "cleanup") == 0) {
191 hammer_cmd_cleanup(av
+ 1, ac
- 1);
194 if (strcmp(av
[0], "prune-everything") == 0) {
195 hammer_cmd_softprune(av
+ 1, ac
- 1, 1);
198 if (strcmp(av
[0], "snapshot") == 0) {
199 hammer_cmd_snapshot(av
+ 1, ac
- 1);
202 if (strcmp(av
[0], "bstats") == 0) {
203 hammer_cmd_bstats(av
+ 1, ac
- 1);
206 if (strcmp(av
[0], "iostats") == 0) {
207 hammer_cmd_iostats(av
+ 1, ac
- 1);
211 if (strncmp(av
[0], "history", 7) == 0) {
212 hammer_cmd_history(av
[0] + 7, av
+ 1, ac
- 1);
215 if (strncmp(av
[0], "reblock", 7) == 0) {
216 signal(SIGINT
, sigalrm
);
217 if (strcmp(av
[0], "reblock") == 0)
218 hammer_cmd_reblock(av
+ 1, ac
- 1, -1);
219 else if (strcmp(av
[0], "reblock-btree") == 0)
220 hammer_cmd_reblock(av
+ 1, ac
- 1, HAMMER_IOC_DO_BTREE
);
221 else if (strcmp(av
[0], "reblock-inodes") == 0)
222 hammer_cmd_reblock(av
+ 1, ac
- 1, HAMMER_IOC_DO_INODES
);
223 else if (strcmp(av
[0], "reblock-dirs") == 0)
224 hammer_cmd_reblock(av
+ 1, ac
- 1, HAMMER_IOC_DO_DIRS
);
225 else if (strcmp(av
[0], "reblock-data") == 0)
226 hammer_cmd_reblock(av
+ 1, ac
- 1, HAMMER_IOC_DO_DATA
);
231 if (strncmp(av
[0], "mirror", 6) == 0) {
232 if (strcmp(av
[0], "mirror-read") == 0)
233 hammer_cmd_mirror_read(av
+ 1, ac
- 1, 0);
234 else if (strcmp(av
[0], "mirror-read-stream") == 0)
235 hammer_cmd_mirror_read(av
+ 1, ac
- 1, 1);
236 else if (strcmp(av
[0], "mirror-write") == 0)
237 hammer_cmd_mirror_write(av
+ 1, ac
- 1);
238 else if (strcmp(av
[0], "mirror-copy") == 0)
239 hammer_cmd_mirror_copy(av
+ 1, ac
- 1, 0);
240 else if (strcmp(av
[0], "mirror-stream") == 0)
241 hammer_cmd_mirror_copy(av
+ 1, ac
- 1, 1);
242 else if (strcmp(av
[0], "mirror-dump") == 0)
243 hammer_cmd_mirror_dump();
249 uuid_name_lookup(&Hammer_FSType
, "DragonFly HAMMER", &status
);
250 if (status
!= uuid_s_ok
) {
251 errx(1, "uuids file does not have the DragonFly "
252 "HAMMER filesystem type");
255 if (strcmp(av
[0], "show") == 0) {
256 hammer_off_t node_offset
= (hammer_off_t
)-1;
258 hammer_parsedevs(blkdevs
);
260 sscanf(av
[1], "%llx", &node_offset
);
261 hammer_cmd_show(node_offset
, 0, NULL
, NULL
);
264 if (strcmp(av
[0], "blockmap") == 0) {
265 hammer_parsedevs(blkdevs
);
266 hammer_cmd_blockmap();
276 hammer_parsedevs(const char *blkdevs
)
281 if (blkdevs
== NULL
) {
282 errx(1, "A -f blkdev[:blkdev]* specification is required "
286 copy
= strdup(blkdevs
);
287 while ((volname
= copy
) != NULL
) {
288 if ((copy
= strchr(copy
, ':')) != NULL
)
290 setup_volume(-1, volname
, 0, O_RDONLY
);
296 sigalrm(int signo __unused
)
298 /* do nothing (interrupts HAMMER ioctl) */
307 "hammer [-v] [-t seconds] [-c cyclefile] command [argument ...]\n"
308 "hammer cleanup [<filesystem>]\n"
309 "hammer synctid <filesystem> [quick]\n"
310 "hammer namekey[32] <path>\n"
311 "hammer prune <softlink-dir>\n"
312 "hammer prune-everything <filesystem>\n"
313 "hammer snapshot [filesystem] <snapshot-dir>\n"
314 "hammer bstats [interval]\n"
315 "hammer iostats [interval]\n"
316 "hammer mirror-read <filesystem> [begin-tid]\n"
317 "hammer mirror-read-stream <filesystem> [begin-tid]\n"
318 "hammer mirror-write <filesystem>\n"
319 "hammer mirror-dump\n"
320 "hammer mirror-copy [[user@]host:]<filesystem>"
321 " [[user@]host:]<filesystem>\n"
322 "hammer mirror-stream [[user@]host:]<filesystem>"
323 " [[user@]host:]<filesystem>\n"
324 "hammer reblock[-btree/inodes/dirs/data] "
325 "<filesystem> [fill_percentage]\n"
326 "hammer pfs-status <dirpath> ...\n"
327 "hammer pfs-master <dirpath> [options]\n"
328 "hammer pfs-slave <dirpath> [options]\n"
329 "hammer pfs-update <dirpath> [options]\n"
330 "hammer pfs-upgrade <dirpath>\n"
331 "hammer pfs-downgrade <dirpath>\n"
332 "hammer pfs-destroy <dirpath>\n"
333 "hammer history[@offset[,len]] <file> ...\n"
334 "hammer -f blkdev[:blkdev]* [-r] show [offset]\n"
336 "hammer -f blkdev[:blkdev]* blockmap\n"