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.44 2008/11/13 02:04:27 dillon Exp $
41 static void hammer_parsedevs(const char *blkdevs);
42 static void sigalrm(int signo);
43 static void sigintr(int signo);
44 static void usage(int exit_code);
56 u_int64_t BandwidthOpt;
57 const char *CyclePath;
61 main(int ac, char **av)
69 while ((ch = getopt(ac, av, "b:c:dhf:i:qrs:t:v2yC:")) != -1) {
78 BandwidthOpt = strtoull(optarg, &ptr, 0);
93 /* bytes per second if no suffix */
109 DelayOpt = strtol(optarg, NULL, 0);
121 TimeoutOpt = strtol(optarg, NULL, 0);
136 cacheSize = strtol(optarg, &ptr, 0);
149 /* bytes if no suffix */
155 UseReadAhead = strtol(ptr + 1, NULL, 0);
156 UseReadBehind = -UseReadAhead;
158 if (cacheSize < 1024 * 1024)
159 cacheSize = 1024 * 1024;
160 if (UseReadAhead < 0)
162 if (UseReadAhead * HAMMER_BUFSIZE / cacheSize / 16) {
163 UseReadAhead = cacheSize / 16 / HAMMER_BUFSIZE;
164 UseReadBehind = -UseReadAhead;
166 hammer_cache_set(cacheSize);
180 signal(SIGALRM, sigalrm);
181 signal(SIGINT, sigintr);
183 if (strcmp(av[0], "synctid") == 0) {
184 hammer_cmd_synctid(av + 1, ac - 1);
187 if (strcmp(av[0], "namekey2") == 0) {
191 const char *aname = av[1];
196 key = (u_int32_t)crc32(aname, len) & 0xFFFFFFFEU;
200 crcx = crc32(aname + 3, len - 5);
201 crcx = crcx ^ (crcx >> 6) ^ (crcx >> 12);
202 key |= (int64_t)(crcx & 0x3F) << 42;
208 key |= ((int64_t)(aname[2] & 0x1F) << 48);
211 key |= ((int64_t)(aname[1] & 0x1F) << 53) |
212 ((int64_t)(aname[len-2] & 0x1F) << 37);
215 key |= ((int64_t)(aname[0] & 0x1F) << 58) |
216 ((int64_t)(aname[len-1] & 0x1F) << 32);
222 key |= 0x100000000LL;
223 printf("0x%016llx\n", key);
226 if (strcmp(av[0], "namekey1") == 0) {
231 key = (int64_t)(crc32(av[1], strlen(av[1])) & 0x7FFFFFFF) << 32;
233 key |= 0x100000000LL;
234 printf("0x%016llx\n", key);
237 if (strcmp(av[0], "namekey32") == 0) {
242 key = crc32(av[1], strlen(av[1])) & 0x7FFFFFFF;
245 printf("0x%08x\n", key);
248 if (strcmp(av[0], "pfs-status") == 0) {
249 hammer_cmd_pseudofs_status(av + 1, ac - 1);
252 if (strcmp(av[0], "pfs-master") == 0) {
253 hammer_cmd_pseudofs_create(av + 1, ac - 1, 0);
256 if (strcmp(av[0], "pfs-slave") == 0) {
257 hammer_cmd_pseudofs_create(av + 1, ac - 1, 1);
260 if (strcmp(av[0], "pfs-update") == 0) {
261 hammer_cmd_pseudofs_update(av + 1, ac - 1);
264 if (strcmp(av[0], "pfs-upgrade") == 0) {
265 hammer_cmd_pseudofs_upgrade(av + 1, ac - 1);
268 if (strcmp(av[0], "pfs-downgrade") == 0) {
269 hammer_cmd_pseudofs_downgrade(av + 1, ac - 1);
272 if (strcmp(av[0], "pfs-destroy") == 0) {
273 hammer_cmd_pseudofs_destroy(av + 1, ac - 1);
276 if (strcmp(av[0], "status") == 0) {
277 hammer_cmd_status(av + 1, ac - 1);
280 if (strcmp(av[0], "prune") == 0) {
281 hammer_cmd_softprune(av + 1, ac - 1, 0);
284 if (strcmp(av[0], "cleanup") == 0) {
285 hammer_cmd_cleanup(av + 1, ac - 1);
288 if (strcmp(av[0], "info") == 0) {
289 hammer_cmd_info(ac - 1);
292 if (strcmp(av[0], "prune-everything") == 0) {
293 hammer_cmd_softprune(av + 1, ac - 1, 1);
296 if (strcmp(av[0], "snapshot") == 0) {
297 hammer_cmd_snapshot(av + 1, ac - 1);
300 if (strcmp(av[0], "bstats") == 0) {
301 hammer_cmd_bstats(av + 1, ac - 1);
304 if (strcmp(av[0], "iostats") == 0) {
305 hammer_cmd_iostats(av + 1, ac - 1);
309 if (strncmp(av[0], "history", 7) == 0) {
310 hammer_cmd_history(av[0] + 7, av + 1, ac - 1);
313 if (strcmp(av[0], "rebalance") == 0) {
314 signal(SIGINT, sigalrm);
315 hammer_cmd_rebalance(av + 1, ac - 1);
318 if (strncmp(av[0], "reblock", 7) == 0) {
319 signal(SIGINT, sigalrm);
320 if (strcmp(av[0], "reblock") == 0)
321 hammer_cmd_reblock(av + 1, ac - 1, -1);
322 else if (strcmp(av[0], "reblock-btree") == 0)
323 hammer_cmd_reblock(av + 1, ac - 1, HAMMER_IOC_DO_BTREE);
324 else if (strcmp(av[0], "reblock-inodes") == 0)
325 hammer_cmd_reblock(av + 1, ac - 1, HAMMER_IOC_DO_INODES);
326 else if (strcmp(av[0], "reblock-dirs") == 0)
327 hammer_cmd_reblock(av + 1, ac - 1, HAMMER_IOC_DO_DIRS);
328 else if (strcmp(av[0], "reblock-data") == 0)
329 hammer_cmd_reblock(av + 1, ac - 1, HAMMER_IOC_DO_DATA);
334 if (strncmp(av[0], "mirror", 6) == 0) {
335 if (strcmp(av[0], "mirror-read") == 0)
336 hammer_cmd_mirror_read(av + 1, ac - 1, 0);
337 else if (strcmp(av[0], "mirror-read-stream") == 0)
338 hammer_cmd_mirror_read(av + 1, ac - 1, 1);
339 else if (strcmp(av[0], "mirror-write") == 0)
340 hammer_cmd_mirror_write(av + 1, ac - 1);
341 else if (strcmp(av[0], "mirror-copy") == 0)
342 hammer_cmd_mirror_copy(av + 1, ac - 1, 0);
343 else if (strcmp(av[0], "mirror-stream") == 0)
344 hammer_cmd_mirror_copy(av + 1, ac - 1, 1);
345 else if (strcmp(av[0], "mirror-dump") == 0)
346 hammer_cmd_mirror_dump();
351 if (strcmp(av[0], "version") == 0) {
352 hammer_cmd_get_version(av + 1, ac - 1);
355 if (strcmp(av[0], "version-upgrade") == 0) {
356 hammer_cmd_set_version(av + 1, ac - 1);
360 uuid_name_lookup(&Hammer_FSType, "DragonFly HAMMER", &status);
361 if (status != uuid_s_ok) {
362 errx(1, "uuids file does not have the DragonFly "
363 "HAMMER filesystem type");
366 if (strcmp(av[0], "show") == 0) {
367 hammer_off_t node_offset = (hammer_off_t)-1;
369 hammer_parsedevs(blkdevs);
371 sscanf(av[1], "%llx", &node_offset);
372 hammer_cmd_show(node_offset, 0, NULL, NULL);
375 if (strcmp(av[0], "blockmap") == 0) {
376 hammer_parsedevs(blkdevs);
377 hammer_cmd_blockmap();
387 hammer_parsedevs(const char *blkdevs)
392 if (blkdevs == NULL) {
393 errx(1, "A -f blkdev[:blkdev]* specification is required "
397 copy = strdup(blkdevs);
398 while ((volname = copy) != NULL) {
399 if ((copy = strchr(copy, ':')) != NULL)
401 setup_volume(-1, volname, 0, O_RDONLY);
407 sigalrm(int signo __unused)
409 /* do nothing (interrupts HAMMER ioctl) */
414 sigintr(int signo __unused)
416 if (RunningIoctl == 0)
419 /* do nothing (interrupts HAMMER ioctl) */
428 "hammer [-2qrvy] [-b bandwidth] [-c cyclefile] [-f blkdev[:blkdev]*]\n"
429 " [-i delay ] [-t seconds] command [argument ...]\n"
430 "hammer synctid <filesystem> [quick]\n"
431 "hammer -f blkdev[:blkdev]* blockmap\n"
432 "hammer bstats [interval]\n"
433 "hammer iostats [interval]\n"
434 "hammer history[@offset[,len]] <file> ...\n"
435 "hammer -f blkdev[:blkdev]* [-r] [-vvv] show [offset]\n"
437 "hammer -f blkdev[:blkdev]* blockmap\n"
439 "hammer namekey1 <path>\n"
440 "hammer namekey2 <path>\n"
441 "hammer cleanup [<filesystem> ...]\n"
443 "hammer snapshot [<filesystem>] <snapshot-dir>\n"
444 "hammer prune <softlink-dir>\n"
445 "hammer prune-everything <filesystem>\n"
446 "hammer rebalance <filesystem> [saturation_percentage]\n"
447 "hammer reblock[-btree/inodes/dirs/data] "
448 "<filesystem> [fill_percentage]\n"
449 "hammer pfs-status <dirpath> ...\n"
450 "hammer pfs-master <dirpath> [options]\n"
451 "hammer pfs-slave <dirpath> [options]\n"
452 "hammer pfs-update <dirpath> [options]\n"
453 "hammer pfs-upgrade <dirpath>\n"
454 "hammer pfs-downgrade <dirpath>\n"
455 "hammer pfs-destroy <dirpath>\n"
456 "hammer mirror-read <filesystem> [begin-tid]\n"
457 "hammer mirror-read-stream <filesystem> [begin-tid]\n"
458 "hammer mirror-write <filesystem>\n"
459 "hammer mirror-dump\n"
460 "hammer mirror-copy [[user@]host:]<filesystem>"
461 " [[user@]host:]<filesystem>\n"
462 "hammer mirror-stream [[user@]host:]<filesystem>"
463 " [[user@]host:]<filesystem>\n"
464 "hammer version <filesystem>\n"
465 "hammer version-upgrade <filesystem> version# [force]\n"