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);
42 int NormalExit = 1; /* if set to 0 main() has to pthread_exit() */
45 main(int ac, char **av)
47 const char *sel_path = NULL;
48 const char *uuid_str = NULL;
50 int pfs_type = HAMMER2_PFSTYPE_NONE;
61 while ((ch = getopt(ac, av, "adqs:t:u:v")) != -1) {
71 * Quick mode - do not block verifying certain
72 * operations such as (connect).
81 * set node type for mkpfs
83 if (strcasecmp(optarg, "ADMIN") == 0) {
84 pfs_type = HAMMER2_PFSTYPE_ADMIN;
85 } else if (strcasecmp(optarg, "CACHE") == 0) {
86 pfs_type = HAMMER2_PFSTYPE_CACHE;
87 } else if (strcasecmp(optarg, "COPY") == 0) {
88 pfs_type = HAMMER2_PFSTYPE_COPY;
89 } else if (strcasecmp(optarg, "SLAVE") == 0) {
90 pfs_type = HAMMER2_PFSTYPE_SLAVE;
91 } else if (strcasecmp(optarg, "SOFT_SLAVE") == 0) {
92 pfs_type = HAMMER2_PFSTYPE_SOFT_SLAVE;
93 } else if (strcasecmp(optarg, "SOFT_MASTER") == 0) {
94 pfs_type = HAMMER2_PFSTYPE_SOFT_MASTER;
95 } else if (strcasecmp(optarg, "MASTER") == 0) {
96 pfs_type = HAMMER2_PFSTYPE_MASTER;
98 fprintf(stderr, "-t: Unrecognized node type\n");
104 * set uuid for mkpfs, else one will be generated
105 * (required for all except the MASTER node_type)
113 fprintf(stderr, "Unknown option: %c\n", ch);
121 * Adjust, then process the command
126 fprintf(stderr, "Missing command\n");
131 if (strcmp(av[0], "connect") == 0) {
133 * Add cluster connection
136 fprintf(stderr, "connect: missing argument\n");
139 ecode = cmd_remote_connect(sel_path, av[1]);
140 } else if (strcmp(av[0], "disconnect") == 0) {
142 * Remove cluster connection
145 fprintf(stderr, "disconnect: missing argument\n");
148 ecode = cmd_remote_disconnect(sel_path, av[1]);
149 } else if (strcmp(av[0], "status") == 0) {
151 * Get status of PFS and its connections (-a for all PFSs)
153 ecode = cmd_remote_status(sel_path, all_opt);
154 } else if (strcmp(av[0], "pfs-list") == 0) {
158 ecode = cmd_pfs_list(sel_path);
159 } else if (strcmp(av[0], "pfs-create") == 0) {
161 * Create new PFS using pfs_type
164 fprintf(stderr, "pfs-create: requires name\n");
167 ecode = cmd_pfs_create(sel_path, av[1], pfs_type, uuid_str);
168 } else if (strcmp(av[0], "pfs-delete") == 0) {
170 * Delete a PFS by name
173 fprintf(stderr, "pfs-delete: requires name\n");
176 ecode = cmd_pfs_delete(sel_path, av[1]);
177 } else if (strcmp(av[0], "snapshot") == 0) {
179 * Create snapshot with optional pfs-type and optional
182 } else if (strcmp(av[0], "service") == 0) {
184 * Start the service daemon. This daemon accepts
185 * connections from local and remote clients, handles
186 * the security handshake, and manages the core messaging
189 ecode = cmd_service();
190 } else if (strcmp(av[0], "leaf") == 0) {
192 * Start the management daemon for a specific PFS.
194 * This will typically connect to the local master node
195 * daemon, register the PFS, and then pass its side of
196 * the socket descriptor to the kernel HAMMER2 VFS via an
197 * ioctl(). The process and/or thread context remains in the
198 * kernel until the PFS is unmounted or the connection is
199 * lost, then returns from the ioctl.
201 * It is possible to connect directly to a remote master node
202 * instead of the local master node in situations where
203 * encryption is not desired or no local master node is
204 * desired. This is not recommended because it represents
205 * a single point of failure for the PFS's communications.
207 * Direct kernel<->kernel communication between HAMMER2 VFSs
208 * is theoretically possible for directly-connected
209 * registrations (i.e. where the spanning tree is degenerate),
210 * but not recommended. We specifically try to reduce the
211 * complexity of the HAMMER2 VFS kernel code.
213 ecode = cmd_leaf(sel_path);
214 } else if (strcmp(av[0], "shell") == 0) {
216 * Connect to the command line monitor in the hammer2 master
217 * node for the machine using HAMMER2_DBG_SHELL messages.
219 ecode = cmd_shell((ac < 2) ? NULL : av[1]);
220 } else if (strcmp(av[0], "rsainit") == 0) {
222 * Initialize a RSA keypair. If no target directory is
223 * specified we default to "/etc/hammer2".
225 arg = (ac < 2) ? HAMMER2_DEFAULT_DIR : av[1];
226 ecode = cmd_rsainit(arg);
227 } else if (strcmp(av[0], "rsaenc") == 0) {
229 * Encrypt the input symmetrically by running it through
230 * the specified public and/or private key files.
232 * If no key files are specified data is encoded using
233 * "/etc/hammer2/rsa.pub".
235 * WARNING: no padding is added, data stream must contain
236 * random padding for this to be secure.
238 * Used for debugging only
241 const char *rsapath = HAMMER2_DEFAULT_DIR "/rsa.pub";
242 ecode = cmd_rsaenc(&rsapath, 1);
244 ecode = cmd_rsaenc((const char **)&av[1], ac - 1);
246 } else if (strcmp(av[0], "rsadec") == 0) {
248 * Decrypt the input symmetrically by running it through
249 * the specified public and/or private key files.
251 * If no key files are specified data is decoded using
252 * "/etc/hammer2/rsa.prv".
254 * WARNING: no padding is added, data stream must contain
255 * random padding for this to be secure.
257 * Used for debugging only
260 const char *rsapath = HAMMER2_DEFAULT_DIR "/rsa.prv";
261 ecode = cmd_rsadec(&rsapath, 1);
263 ecode = cmd_rsadec((const char **)&av[1], ac - 1);
265 } else if (strcmp(av[0], "show") == 0) {
267 * Raw dump of filesystem. Use -v to check all crc's, and
268 * -vv to dump bulk file data.
271 fprintf(stderr, "show: requires device path\n");
277 fprintf(stderr, "Unrecognized command: %s\n", av[0]);
282 * In DebugMode we may wind up starting several pthreads in the
283 * original process, in which case we have to let them run and
290 _exit(2); /* NOT REACHED */
299 "hammer2 [-s path] command...\n"
300 " -s path Select filesystem\n"
301 " -t type PFS type for pfs-create\n"
302 " -u uuid uuid for pfs-create\n"
304 " connect <target> Add cluster link\n"
305 " disconnect <target> Del cluster link\n"
306 " status Report cluster status\n"
307 " pfs-list List PFSs\n"
308 " pfs-create <label> Create a PFS\n"
309 " pfs-delete <label> Destroy a PFS\n"
310 " snapshot Snapshot a PFS\n"
311 " service Start service daemon\n"
312 " leaf Start pfs leaf daemon\n"
313 " shell [<host>] Connect to debug shell\n"
314 " rsainit Initialize rsa fields\n"
315 " show devpath Raw hammer2 media dump\n"