2 * Copyright (c) 2011-2012 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@dragonflybsd.org>
6 * by Venkatesh Srinivas <vsrinivas@dragonflybsd.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static void usage(int code);
41 int NormalExit = 1; /* if set to 0 main() has to pthread_exit() */
44 main(int ac, char **av)
46 const char *sel_path = NULL;
47 const char *uuid_str = NULL;
48 int pfs_type = HAMMER2_PFSTYPE_NONE;
57 while ((ch = getopt(ac, av, "aqs:t:u:")) != -1) {
64 * Quick mode - do not block verifying certain
65 * operations such as (connect).
74 * set node type for mkpfs
76 if (strcasecmp(optarg, "ADMIN") == 0) {
77 pfs_type = HAMMER2_PFSTYPE_ADMIN;
78 } else if (strcasecmp(optarg, "CACHE") == 0) {
79 pfs_type = HAMMER2_PFSTYPE_CACHE;
80 } else if (strcasecmp(optarg, "COPY") == 0) {
81 pfs_type = HAMMER2_PFSTYPE_COPY;
82 } else if (strcasecmp(optarg, "SLAVE") == 0) {
83 pfs_type = HAMMER2_PFSTYPE_SLAVE;
84 } else if (strcasecmp(optarg, "SOFT_SLAVE") == 0) {
85 pfs_type = HAMMER2_PFSTYPE_SOFT_SLAVE;
86 } else if (strcasecmp(optarg, "SOFT_MASTER") == 0) {
87 pfs_type = HAMMER2_PFSTYPE_SOFT_MASTER;
88 } else if (strcasecmp(optarg, "MASTER") == 0) {
89 pfs_type = HAMMER2_PFSTYPE_MASTER;
91 fprintf(stderr, "-t: Unrecognized node type\n");
97 * set uuid for mkpfs, else one will be generated
98 * (required for all except the MASTER node_type)
106 fprintf(stderr, "Unknown option: %c\n", ch);
114 * Adjust, then process the command
119 fprintf(stderr, "Missing command\n");
124 if (strcmp(av[0], "connect") == 0) {
126 * Add cluster connection
129 fprintf(stderr, "connect: missing argument\n");
132 ecode = cmd_remote_connect(sel_path, av[1]);
133 } else if (strcmp(av[0], "disconnect") == 0) {
135 * Remove cluster connection
138 fprintf(stderr, "disconnect: missing argument\n");
141 ecode = cmd_remote_disconnect(sel_path, av[1]);
142 } else if (strcmp(av[0], "status") == 0) {
144 * Get status of PFS and its connections (-a for all PFSs)
146 ecode = cmd_remote_status(sel_path, all_opt);
147 } else if (strcmp(av[0], "mkpfs") == 0) {
149 * Create new PFS using pfs_type
151 } else if (strcmp(av[0], "snapshot") == 0) {
153 * Create snapshot with optional pfs_type and optional
156 } else if (strcmp(av[0], "helper") == 0) {
158 * Typically run as a daemon, this multi-threaded helper
159 * subsystem manages socket communications for the
162 ecode = cmd_helper(sel_path);
164 fprintf(stderr, "Unrecognized command: %s\n", av[0]);
169 * In DebugMode we may wind up starting several pthreads in the
170 * original process, in which case we have to let them run and
177 _exit(2); /* NOT REACHED */
186 "hammer2 [-s path] command...\n"
187 " -s path Select filesystem\n"