HAMMER - Implement volume-list command
[dragonfly.git] / sbin / hammer / hammer.c
index 6d7ab5a..88b51c4 100644 (file)
@@ -51,11 +51,15 @@ int NoSyncOpt;
 int TwoWayPipeOpt;
 int TimeoutOpt;
 int DelayOpt = 5;
+char *SshPort;
 int ForceYesOpt = 0;
+int CompressOpt;
 int ForceOpt;
 int RunningIoctl;
 int DidInterrupt;
+int BulkOpt;
 u_int64_t BandwidthOpt;
+u_int64_t SplitupOpt = 4ULL * 1024ULL * 1024ULL * 1024ULL;
 const char *CyclePath;
 const char *LinkPath;
 
@@ -68,7 +72,7 @@ main(int ac, char **av)
        int ch;
        int cacheSize = 0;
 
-       while ((ch = getopt(ac, av, "b:c:dhf:i:qrs:t:v2yC:F")) != -1) {
+       while ((ch = getopt(ac, av, "b:c:dhf:i:p:qrs:t:v2yBC:FS:X")) != -1) {
                switch(ch) {
                case '2':
                        TwoWayPipeOpt = 1;
@@ -98,6 +102,28 @@ main(int ac, char **av)
                                usage(1);
                        }
                        break;
+               case 'S':
+                       SplitupOpt = strtoull(optarg, &ptr, 0);
+                       switch(*ptr) {
+                       case 'g':
+                       case 'G':
+                               SplitupOpt *= 1024;
+                               /* fall through */
+                       case 'm':
+                       case 'M':
+                               SplitupOpt *= 1024;
+                               /* fall through */
+                       case 'k':
+                       case 'K':
+                               SplitupOpt *= 1024;
+                               break;
+                       case '\0':
+                               /* bytes per second if no suffix */
+                               break;
+                       default:
+                               usage(1);
+                       }
+                       break;
                case 'c':
                        CyclePath = optarg;
                        break;
@@ -110,6 +136,9 @@ main(int ac, char **av)
                case 'i':
                        DelayOpt = strtol(optarg, NULL, 0);
                        break;
+               case 'p':
+                       SshPort = optarg;
+                       break;
                case 'r':
                        RecurseOpt = 1;
                        break;
@@ -134,6 +163,9 @@ main(int ac, char **av)
                        else
                                ++QuietOpt;
                        break;
+               case 'B':
+                       BulkOpt = 1;
+                       break;
                case 'C':
                        cacheSize = strtol(optarg, &ptr, 0);
                        switch(*ptr) {
@@ -170,6 +202,9 @@ main(int ac, char **av)
                case 'F':
                        ForceOpt = 1;
                        break;
+               case 'X':
+                       CompressOpt = 1;
+                       break;
                default:
                        usage(1);
                        /* not reached */
@@ -225,7 +260,7 @@ main(int ac, char **av)
                }
                if (key == 0)
                        key |= 0x100000000LL;
-               printf("0x%016llx\n", key);
+               printf("0x%016jx\n", (uintmax_t)key);
                exit(0);
        }
        if (strcmp(av[0], "namekey1") == 0) {
@@ -236,7 +271,7 @@ main(int ac, char **av)
                key = (int64_t)(crc32(av[1], strlen(av[1])) & 0x7FFFFFFF) << 32;
                if (key == 0)
                        key |= 0x100000000LL;
-               printf("0x%016llx\n", key);
+               printf("0x%016jx\n", (uintmax_t)key);
                exit(0);
        }
        if (strcmp(av[0], "namekey32") == 0) {
@@ -286,18 +321,46 @@ main(int ac, char **av)
                hammer_cmd_softprune(av + 1, ac - 1, 0);
                exit(0);
        }
+       if (strcmp(av[0], "config") == 0) {
+               hammer_cmd_config(av + 1, ac - 1);
+               exit(0);
+       }
+       if (strcmp(av[0], "viconfig") == 0) {
+               hammer_cmd_viconfig(av + 1, ac - 1);
+               exit(0);
+       }
        if (strcmp(av[0], "cleanup") == 0) {
                hammer_cmd_cleanup(av + 1, ac - 1);
                exit(0);
        }
        if (strcmp(av[0], "info") == 0) {
-               hammer_cmd_info(ac - 1);
+               hammer_cmd_info();
                exit(0);
        }
        if (strcmp(av[0], "prune-everything") == 0) {
                hammer_cmd_softprune(av + 1, ac - 1, 1);
                exit(0);
        }
+       if (strcmp(av[0], "snap") == 0) {
+               hammer_cmd_snap(av + 1, ac - 1, 0, 1);
+               exit(0);
+       }
+       if (strcmp(av[0], "snaplo") == 0) {
+               hammer_cmd_snap(av + 1, ac - 1, 0, 0);
+               exit(0);
+       }
+       if (strcmp(av[0], "snapq") == 0) {
+               hammer_cmd_snap(av + 1, ac - 1, 1, 0);
+               exit(0);
+       }
+       if (strcmp(av[0], "snapls") == 0) {
+               hammer_cmd_snapls(av + 1, ac - 1);
+               exit(0);
+       }
+       if (strcmp(av[0], "snaprm") == 0) {
+               hammer_cmd_snaprm(av + 1, ac - 1);
+               exit(0);
+       }
        if (strcmp(av[0], "snapshot") == 0) {
                hammer_cmd_snapshot(av + 1, ac - 1);
                exit(0);
@@ -353,6 +416,14 @@ main(int ac, char **av)
                        usage(1);
                exit(0);
        }
+       if (strcmp(av[0], "dedup-simulate") == 0) {
+               hammer_cmd_dedup_simulate(av + 1, ac - 1);
+               exit(0);
+       }
+       if (strcmp(av[0], "dedup") == 0) {
+               hammer_cmd_dedup(av + 1, ac - 1);
+               exit(0);
+       }
        if (strcmp(av[0], "version") == 0) {
                hammer_cmd_get_version(av + 1, ac - 1);
                exit(0);
@@ -361,8 +432,16 @@ main(int ac, char **av)
                hammer_cmd_set_version(av + 1, ac - 1);
                exit(0);
        }
-       if (strcmp(av[0], "expand") == 0) {
-               hammer_cmd_expand(av + 1, ac - 1);
+       if (strcmp(av[0], "volume-add") == 0) {
+               hammer_cmd_volume_add(av + 1, ac - 1);
+               exit(0);
+       }
+       if (strcmp(av[0], "volume-del") == 0) {
+               hammer_cmd_volume_del(av + 1, ac - 1);
+               exit(0);
+       }
+       if (strcmp(av[0], "volume-list") == 0) {
+               hammer_cmd_volume_list(av + 1, ac - 1);
                exit(0);
        }
 
@@ -374,12 +453,24 @@ main(int ac, char **av)
 
        if (strcmp(av[0], "show") == 0) {
                u_int32_t lo = 0;
-               int64_t obj_id = (int64_t)HAMMER_MIN_OBJID;
+               intmax_t obj_id = (int64_t)HAMMER_MIN_OBJID;
 
                hammer_parsedevs(blkdevs);
                if (ac > 1)
-                       sscanf(av[1], "%08x:%llx", &lo, &obj_id);
-               hammer_cmd_show(-1, lo, obj_id, 0, NULL, NULL);
+                       sscanf(av[1], "%08x:%jx", &lo, &obj_id);
+               hammer_cmd_show(-1, lo, (int64_t)obj_id, 0, NULL, NULL);
+               exit(0);
+       }
+       if (strcmp(av[0], "show-undo") == 0) {
+               hammer_parsedevs(blkdevs);
+               hammer_cmd_show_undo();
+               exit(0);
+       }
+       if (strcmp(av[0], "recover") == 0) {
+               hammer_parsedevs(blkdevs);
+               if (ac <= 1)
+                       errx(1, "hammer recover required target directory");
+               hammer_cmd_recover(av[1]);
                exit(0);
        }
        if (strcmp(av[0], "blockmap") == 0) {
@@ -387,6 +478,11 @@ main(int ac, char **av)
                hammer_cmd_blockmap();
                exit(0);
        }
+       if (strcmp(av[0], "checkmap") == 0) {
+               hammer_parsedevs(blkdevs);
+               hammer_cmd_checkmap();
+               exit(0);
+       }
        usage(1);
        /* not reached */
        return(0);
@@ -408,7 +504,7 @@ hammer_parsedevs(const char *blkdevs)
        char *volname;
 
        if (blkdevs == NULL) {
-               errx(1, "A -f blkdev[:blkdev]* specification is required "
+               errx(1, "A -f blkdevs specification is required "
                        "for this command");
        }
 
@@ -447,26 +543,24 @@ usage(int exit_code)
 {
        fprintf(stderr, 
                "hammer -h\n"
-               "hammer [-2qrvy] [-b bandwidth] [-c cyclefile] [-f blkdev[:blkdev]*]\n"
-               "       [-i delay ] [-t seconds] command [argument ...]\n"
+               "hammer [-2BqrvXy] [-b bandwidth] [-C cachesize[:readahead]] [-c cyclefile]\n"
+               "       [-f blkdevs] [-i delay] [-t seconds] [-S splitup]\n"
+               "       command [argument ...]\n"
                "hammer synctid <filesystem> [quick]\n"
-               "hammer -f blkdev[:blkdev]* blockmap\n"
                "hammer bstats [interval]\n"
                "hammer iostats [interval]\n"
                "hammer history[@offset[,len]] <file> ...\n"
-               "hammer -f blkdev[:blkdev]* [-r] [-vvv] show [offset]\n"
-#if 0
-               "hammer -f blkdev[:blkdev]* blockmap\n"
-#endif
                "hammer namekey1 <path>\n"
                "hammer namekey2 <path>\n"
+               "hammer namekey32 <path>\n"
                "hammer cleanup [<filesystem> ...]\n"
                "hammer info\n"
                "hammer snapshot [<filesystem>] <snapshot-dir>\n"
+               "hammer snapshot <filesystem> <snapshot-dir> [<note>]\n"
                "hammer prune <softlink-dir>\n"
                "hammer prune-everything <filesystem>\n"
                "hammer rebalance <filesystem> [saturation_percentage]\n"
-               "hammer reblock[-btree/inodes/dirs/data] "
+               "hammer reblock[-btree|-inodes|-dirs|-data] "
                        "<filesystem> [fill_percentage]\n"
                "hammer pfs-status <dirpath> ...\n"
                "hammer pfs-master <dirpath> [options]\n"
@@ -484,9 +578,43 @@ usage(int exit_code)
                "hammer mirror-stream [[user@]host:]<filesystem>"
                                    " [[user@]host:]<filesystem>\n"
                "hammer version <filesystem>\n"
-               "hammer version-upgrade <filesystem> version# [force]\n"
-               "hammer expand <filesystem> <device>\n"
+               "hammer version-upgrade <filesystem> <version> [force]\n"
+               "hammer volume-add <device> <filesystem>\n"
+               "hammer volume-del <device> <filesystem>\n"
+               "hammer volume-list <filesystem>\n"
+       );
+
+       fprintf(stderr, "\nHAMMER utility version 3+ commands:\n");
+
+       fprintf(stderr,
+               "hammer config [<filesystem> [<configfile>]]\n"
+               "hammer viconfig [<filesystem>]\n"
+               "hammer snap <path> [<note>]\n"
+               "hammer snaplo <path> [<note>]\n"
+               "hammer snapq <dir> [<note>]\n"
+               "hammer snaprm <path> ...\n"
+               "hammer snaprm <transid> ...\n"
+               "hammer snaprm <filesystem> <transid> ...\n"
+               "hammer snapls [<path> ...]\n"
        );
+
+       fprintf(stderr, "\nHAMMER utility version 4+ commands:\n");
+
+       fprintf(stderr,
+               "hammer -f blkdevs blockmap\n"
+               "hammer -f blkdevs checkmap\n"
+               "hammer -f blkdevs [-qqq] show [lo:objid]\n"
+               "hammer -f blkdevs show-undo\n"
+               "hammer -f blkdevs recover <target_dir>\n"
+       );
+
+       fprintf(stderr, "\nHAMMER utility version 5+ commands:\n");
+
+       fprintf(stderr,
+               "hammer dedup-simulate <filesystem>\n"
+               "hammer dedup <filesystem>\n"
+       );
+
        exit(exit_code);
 }