1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2004 Pawel Jakub Dawidek <pjd@FreeBSD.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <stdint.h>
32 #include <fcntl.h>
33 #include <unistd.h>
34 #include <string.h>
35 #include <ctype.h>
36 #include <inttypes.h>
37 #include <libgen.h>
38 #include <pthread.h>
39 #include <signal.h>
40 #include <err.h>
41 #include <errno.h>
42 #include <assert.h>
43
44 #include <sys/param.h>
45 #include <sys/ioctl.h>
46 #include <sys/socket.h>
47 #include <sys/sysctl.h>
48 #include <sys/syslog.h>
49 #include <sys/time.h>
50 #include <sys/bio.h>
51 #include <netinet/in.h>
52 #include <netinet/tcp.h>
53 #include <arpa/inet.h>
54
55 #include "ggate.h"
56
57
58 static enum { UNSET, CREATE, DESTROY, LIST, RESCUE } action = UNSET;
59
60 static const char *path = NULL;
61 static const char *host = NULL;
62 static int unit = G_GATE_UNIT_AUTO;
63 static unsigned flags = 0;
64 static int direct_flag = 0;
65 static int force = 0;
66 static unsigned queue_size = G_GATE_QUEUE_SIZE;
67 static unsigned port = G_GATE_PORT;
68 static off_t mediasize;
69 static unsigned sectorsize = 0;
70 static unsigned timeout = G_GATE_TIMEOUT;
71 static int sendfd, recvfd;
72 static uint32_t token;
73 static pthread_t sendtd, recvtd;
74 static int reconnect;
75 static int initialbuffersize = 131072;
76
77 static void
usage(void)78 usage(void)
79 {
80
81 fprintf(stderr, "usage: %s create [-nv] [-o <ro|wo|rw>] "
82 "[-o <direct>] [-p port] "
83 "[-q queue_size] [-R rcvbuf] [-S sndbuf] [-s sectorsize] "
84 "[-t timeout] [-u unit] <host> <path>\n", getprogname());
85 fprintf(stderr, " %s rescue [-nv] [-o <ro|wo|rw>] "
86 "[-o <direct>] [-p port] "
87 "[-R rcvbuf] [-S sndbuf] <-u unit> <host> <path>\n", getprogname());
88 fprintf(stderr, " %s destroy [-f] <-u unit>\n", getprogname());
89 fprintf(stderr, " %s list [-v] [-u unit]\n", getprogname());
90 exit(EXIT_FAILURE);
91 }
92
93 static void *
send_thread(void * arg __unused)94 send_thread(void *arg __unused)
95 {
96 struct g_gate_ctl_io ggio;
97 struct g_gate_hdr hdr;
98 size_t buf_capacity;
99 ssize_t numbytesprocd;
100 int error;
101 char *newbuf;
102
103 g_gate_log(LOG_NOTICE, "%s: started!", __func__);
104
105 buf_capacity = initialbuffersize;
106
107 ggio.gctl_version = G_GATE_VERSION;
108 ggio.gctl_unit = unit;
109 ggio.gctl_data = malloc(buf_capacity);
110 if (ggio.gctl_data == NULL) {
111 g_gate_log(LOG_ERR, "%s: Cannot alloc buffer.", __func__);
112 pthread_exit(NULL);
113 }
114
115 for (;;) {
116 ggio.gctl_length = buf_capacity;
117 ggio.gctl_error = 0;
118 g_gate_ioctl(G_GATE_CMD_START, &ggio);
119 error = ggio.gctl_error;
120 switch (error) {
121 case 0:
122 break;
123 case ECANCELED:
124 if (reconnect)
125 break;
126 /* Exit gracefully. */
127 g_gate_close_device();
128 exit(EXIT_SUCCESS);
129
130 case ENOMEM:
131 {
132 /* Buffer too small. */
133 g_gate_log(LOG_DEBUG, "buffer too small. new size: %u",
134 ggio.gctl_length);
135 newbuf = malloc(ggio.gctl_length);
136 if (newbuf != NULL) {
137 free(ggio.gctl_data);
138 ggio.gctl_data = newbuf;
139 buf_capacity = ggio.gctl_length;
140 continue;
141 }
142 /* FALLTHROUGH */
143 }
144
145 case ENXIO:
146 default:
147 g_gate_xlog("ioctl(/dev/%s): %s.", G_GATE_CTL_NAME,
148 strerror(error));
149 }
150
151 if (reconnect)
152 break;
153
154 switch (ggio.gctl_cmd) {
155 case BIO_READ:
156 hdr.gh_cmd = GGATE_CMD_READ;
157 break;
158 case BIO_WRITE:
159 hdr.gh_cmd = GGATE_CMD_WRITE;
160 break;
161 case BIO_FLUSH:
162 hdr.gh_cmd = GGATE_CMD_FLUSH;
163 break;
164 default:
165 g_gate_log(LOG_NOTICE, "Unknown gctl_cmd: %i",
166 ggio.gctl_cmd);
167 ggio.gctl_error = EOPNOTSUPP;
168 g_gate_ioctl(G_GATE_CMD_DONE, &ggio);
169 continue;
170 }
171
172 hdr.gh_seq = ggio.gctl_seq;
173 hdr.gh_offset = ggio.gctl_offset;
174 hdr.gh_length = ggio.gctl_length;
175 hdr.gh_error = 0;
176 g_gate_swap2n_hdr(&hdr);
177
178 numbytesprocd = g_gate_send(sendfd, &hdr, sizeof(hdr), MSG_NOSIGNAL);
179 g_gate_log(LOG_DEBUG, "Sent hdr packet.");
180 g_gate_swap2h_hdr(&hdr);
181 if (reconnect)
182 break;
183 if (numbytesprocd != sizeof(hdr)) {
184 g_gate_log(LOG_ERR, "Lost connection 1.");
185 reconnect = 1;
186 pthread_kill(recvtd, SIGUSR1);
187 break;
188 }
189
190 if (hdr.gh_cmd == GGATE_CMD_WRITE) {
191 numbytesprocd = g_gate_send(sendfd, ggio.gctl_data,
192 ggio.gctl_length, MSG_NOSIGNAL);
193 if (reconnect)
194 break;
195 if (numbytesprocd != ggio.gctl_length) {
196 g_gate_log(LOG_ERR, "Lost connection 2 (%zd != %zd).",
197 numbytesprocd, (ssize_t)ggio.gctl_length);
198 reconnect = 1;
199 pthread_kill(recvtd, SIGUSR1);
200 break;
201 }
202 g_gate_log(LOG_DEBUG, "Sent %zd bytes (offset=%"
203 PRIu64 ", length=%" PRIu32 ").", numbytesprocd,
204 hdr.gh_offset, hdr.gh_length);
205 }
206 }
207 g_gate_log(LOG_DEBUG, "%s: Died.", __func__);
208 return (NULL);
209 }
210
211 static void *
recv_thread(void * arg __unused)212 recv_thread(void *arg __unused)
213 {
214 struct g_gate_ctl_io ggio;
215 struct g_gate_hdr hdr;
216 ssize_t buf_capacity;
217 ssize_t numbytesprocd;
218 char *newbuf;
219
220 g_gate_log(LOG_NOTICE, "%s: started!", __func__);
221
222 buf_capacity = initialbuffersize;
223
224 ggio.gctl_version = G_GATE_VERSION;
225 ggio.gctl_unit = unit;
226 ggio.gctl_data = malloc(buf_capacity);
227 if (ggio.gctl_data == NULL) {
228 g_gate_log(LOG_ERR, "%s: Cannot alloc buffer.", __func__);
229 pthread_exit(NULL);
230 }
231
232 for (;;) {
233 numbytesprocd = g_gate_recv(recvfd, &hdr, sizeof(hdr), MSG_WAITALL);
234 if (reconnect)
235 break;
236 g_gate_swap2h_hdr(&hdr);
237 if (numbytesprocd != sizeof(hdr)) {
238 if (numbytesprocd == -1 && errno == EAGAIN)
239 continue;
240 g_gate_log(LOG_ERR, "Lost connection 3.");
241 reconnect = 1;
242 pthread_kill(sendtd, SIGUSR1);
243 break;
244 }
245 g_gate_log(LOG_DEBUG, "Received hdr packet.");
246
247 ggio.gctl_seq = hdr.gh_seq;
248 ggio.gctl_cmd = hdr.gh_cmd;
249 ggio.gctl_offset = hdr.gh_offset;
250 ggio.gctl_length = hdr.gh_length;
251 ggio.gctl_error = hdr.gh_error;
252
253 if (ggio.gctl_length > buf_capacity) {
254 newbuf = malloc(ggio.gctl_length);
255 if (newbuf != NULL) {
256 free(ggio.gctl_data);
257 ggio.gctl_data = newbuf;
258 buf_capacity = ggio.gctl_length;
259 } else {
260 g_gate_log(LOG_ERR, "Received too big response: %zd",
261 ggio.gctl_length);
262 break;
263 }
264 }
265
266 if (ggio.gctl_error == 0 && ggio.gctl_cmd == GGATE_CMD_READ) {
267 numbytesprocd = g_gate_recv(recvfd, ggio.gctl_data,
268 ggio.gctl_length, MSG_WAITALL);
269 if (reconnect)
270 break;
271 g_gate_log(LOG_DEBUG, "Received data packet.");
272 if (numbytesprocd != ggio.gctl_length) {
273 g_gate_log(LOG_ERR, "Lost connection 4.");
274 reconnect = 1;
275 pthread_kill(sendtd, SIGUSR1);
276 break;
277 }
278 g_gate_log(LOG_DEBUG, "Received %d bytes (offset=%"
279 PRIu64 ", length=%" PRIu32 ").", numbytesprocd,
280 hdr.gh_offset, hdr.gh_length);
281 }
282
283 g_gate_ioctl(G_GATE_CMD_DONE, &ggio);
284 }
285 g_gate_log(LOG_DEBUG, "%s: Died.", __func__);
286 pthread_exit(NULL);
287 }
288
289 static int
handshake(int dir)290 handshake(int dir)
291 {
292 struct g_gate_version ver;
293 struct g_gate_cinit cinit;
294 struct g_gate_sinit sinit;
295 struct sockaddr_in serv;
296 int sfd;
297
298 /*
299 * Do the network stuff.
300 */
301 bzero(&serv, sizeof(serv));
302 serv.sin_family = AF_INET;
303 serv.sin_addr.s_addr = g_gate_str2ip(host);
304 if (serv.sin_addr.s_addr == INADDR_NONE) {
305 g_gate_log(LOG_DEBUG, "Invalid IP/host name: %s.", host);
306 return (-1);
307 }
308 serv.sin_port = htons(port);
309 sfd = socket(AF_INET, SOCK_STREAM, 0);
310 if (sfd == -1) {
311 g_gate_log(LOG_DEBUG, "Cannot open socket: %s.",
312 strerror(errno));
313 return (-1);
314 }
315
316 g_gate_socket_settings(sfd);
317
318 if (connect(sfd, (struct sockaddr *)&serv, sizeof(serv)) == -1) {
319 g_gate_log(LOG_DEBUG, "Cannot connect to server: %s.",
320 strerror(errno));
321 close(sfd);
322 return (-1);
323 }
324
325 g_gate_log(LOG_INFO, "Connected to the server: %s:%d.", host, port);
326
327 /*
328 * Create and send version packet.
329 */
330 g_gate_log(LOG_DEBUG, "Sending version packet.");
331 assert(strlen(GGATE_MAGIC) == sizeof(ver.gv_magic));
332 bcopy(GGATE_MAGIC, ver.gv_magic, sizeof(ver.gv_magic));
333 ver.gv_version = GGATE_VERSION;
334 ver.gv_error = 0;
335 g_gate_swap2n_version(&ver);
336 if (g_gate_send(sfd, &ver, sizeof(ver), MSG_NOSIGNAL) == -1) {
337 g_gate_log(LOG_DEBUG, "Error while sending version packet: %s.",
338 strerror(errno));
339 close(sfd);
340 return (-1);
341 }
342 bzero(&ver, sizeof(ver));
343 if (g_gate_recv(sfd, &ver, sizeof(ver), MSG_WAITALL) == -1) {
344 g_gate_log(LOG_DEBUG, "Error while receiving data: %s.",
345 strerror(errno));
346 close(sfd);
347 return (-1);
348 }
349 if (ver.gv_error != 0) {
350 g_gate_log(LOG_DEBUG, "Version verification problem: %s.",
351 strerror(errno));
352 close(sfd);
353 return (-1);
354 }
355
356 /*
357 * Create and send initial packet.
358 */
359 g_gate_log(LOG_DEBUG, "Sending initial packet.");
360 if (strlcpy(cinit.gc_path, path, sizeof(cinit.gc_path)) >=
361 sizeof(cinit.gc_path)) {
362 g_gate_log(LOG_DEBUG, "Path name too long.");
363 close(sfd);
364 return (-1);
365 }
366 cinit.gc_flags = flags | direct_flag | dir;
367 cinit.gc_token = token;
368 cinit.gc_nconn = 2;
369 g_gate_swap2n_cinit(&cinit);
370 if (g_gate_send(sfd, &cinit, sizeof(cinit), MSG_NOSIGNAL) == -1) {
371 g_gate_log(LOG_DEBUG, "Error while sending initial packet: %s.",
372 strerror(errno));
373 close(sfd);
374 return (-1);
375 }
376 g_gate_swap2h_cinit(&cinit);
377
378 /*
379 * Receiving initial packet from server.
380 */
381 g_gate_log(LOG_DEBUG, "Receiving initial packet.");
382 if (g_gate_recv(sfd, &sinit, sizeof(sinit), MSG_WAITALL) == -1) {
383 g_gate_log(LOG_DEBUG, "Error while receiving data: %s.",
384 strerror(errno));
385 close(sfd);
386 return (-1);
387 }
388 g_gate_swap2h_sinit(&sinit);
389 if (sinit.gs_error != 0) {
390 g_gate_log(LOG_DEBUG, "Error from server: %s.",
391 strerror(sinit.gs_error));
392 close(sfd);
393 return (-1);
394 }
395 g_gate_log(LOG_DEBUG, "Received initial packet.");
396
397 mediasize = sinit.gs_mediasize;
398 if (sectorsize == 0)
399 sectorsize = sinit.gs_sectorsize;
400
401 return (sfd);
402 }
403
404 static void
mydaemon(void)405 mydaemon(void)
406 {
407
408 if (g_gate_verbose > 0)
409 return;
410 if (daemon(0, 0) == 0)
411 return;
412 if (action == CREATE)
413 g_gate_destroy(unit, 1);
414 err(EXIT_FAILURE, "Cannot daemonize");
415 }
416
417 static int
g_gatec_connect(void)418 g_gatec_connect(void)
419 {
420
421 token = arc4random();
422 /*
423 * Our receive descriptor is connected to the send descriptor on the
424 * server side.
425 */
426 recvfd = handshake(GGATE_FLAG_SEND);
427 if (recvfd == -1)
428 return (0);
429 /*
430 * Our send descriptor is connected to the receive descriptor on the
431 * server side.
432 */
433 sendfd = handshake(GGATE_FLAG_RECV);
434 if (sendfd == -1)
435 return (0);
436 return (1);
437 }
438
439 static void
g_gatec_start(void)440 g_gatec_start(void)
441 {
442 int error;
443
444 reconnect = 0;
445 error = pthread_create(&recvtd, NULL, recv_thread, NULL);
446 if (error != 0) {
447 g_gate_destroy(unit, 1);
448 g_gate_xlog("pthread_create(recv_thread): %s.",
449 strerror(error));
450 }
451 sendtd = pthread_self();
452 send_thread(NULL);
453 /* Disconnected. */
454 close(sendfd);
455 close(recvfd);
456 }
457
458 static void
signop(int sig __unused)459 signop(int sig __unused)
460 {
461
462 /* Do nothing. */
463 }
464
465 static void
g_gatec_loop(void)466 g_gatec_loop(void)
467 {
468 struct g_gate_ctl_cancel ggioc;
469
470 signal(SIGUSR1, signop);
471 for (;;) {
472 g_gatec_start();
473 g_gate_log(LOG_NOTICE, "Disconnected [%s %s]. Connecting...",
474 host, path);
475 while (!g_gatec_connect()) {
476 sleep(2);
477 g_gate_log(LOG_NOTICE, "Connecting [%s %s]...", host,
478 path);
479 }
480 ggioc.gctl_version = G_GATE_VERSION;
481 ggioc.gctl_unit = unit;
482 ggioc.gctl_seq = 0;
483 g_gate_ioctl(G_GATE_CMD_CANCEL, &ggioc);
484 }
485 }
486
487 static void
g_gatec_create(void)488 g_gatec_create(void)
489 {
490 struct g_gate_ctl_create ggioc;
491
492 if (!g_gatec_connect())
493 g_gate_xlog("Cannot connect: %s.", strerror(errno));
494
495 /*
496 * Ok, got both sockets, time to create provider.
497 */
498 memset(&ggioc, 0, sizeof(ggioc));
499 ggioc.gctl_version = G_GATE_VERSION;
500 ggioc.gctl_mediasize = mediasize;
501 ggioc.gctl_sectorsize = sectorsize;
502 ggioc.gctl_flags = flags;
503 ggioc.gctl_maxcount = queue_size;
504 ggioc.gctl_timeout = timeout;
505 ggioc.gctl_unit = unit;
506 snprintf(ggioc.gctl_info, sizeof(ggioc.gctl_info), "%s:%u %s", host,
507 port, path);
508 g_gate_ioctl(G_GATE_CMD_CREATE, &ggioc);
509 if (unit == -1) {
510 printf("%s%u\n", G_GATE_PROVIDER_NAME, ggioc.gctl_unit);
511 fflush(stdout);
512 }
513 unit = ggioc.gctl_unit;
514
515 mydaemon();
516 g_gatec_loop();
517 }
518
519 static void
g_gatec_rescue(void)520 g_gatec_rescue(void)
521 {
522 struct g_gate_ctl_cancel ggioc;
523
524 if (!g_gatec_connect())
525 g_gate_xlog("Cannot connect: %s.", strerror(errno));
526
527 ggioc.gctl_version = G_GATE_VERSION;
528 ggioc.gctl_unit = unit;
529 ggioc.gctl_seq = 0;
530 g_gate_ioctl(G_GATE_CMD_CANCEL, &ggioc);
531
532 mydaemon();
533 g_gatec_loop();
534 }
535
536 static void
init_initial_buffer_size(void)537 init_initial_buffer_size(void)
538 {
539 int value;
540 size_t intsize;
541 intsize = sizeof(initialbuffersize);
542 if (sysctlbyname("kern.maxphys", &value, &intsize, NULL, 0) == 0)
543 initialbuffersize = value;
544 }
545
546 int
main(int argc,char * argv[])547 main(int argc, char *argv[])
548 {
549
550 if (argc < 2)
551 usage();
552 if (strcasecmp(argv[1], "create") == 0)
553 action = CREATE;
554 else if (strcasecmp(argv[1], "destroy") == 0)
555 action = DESTROY;
556 else if (strcasecmp(argv[1], "list") == 0)
557 action = LIST;
558 else if (strcasecmp(argv[1], "rescue") == 0)
559 action = RESCUE;
560 else
561 usage();
562 argc -= 1;
563 argv += 1;
564 for (;;) {
565 int ch;
566
567 ch = getopt(argc, argv, "fno:p:q:R:S:s:t:u:v");
568 if (ch == -1)
569 break;
570 switch (ch) {
571 case 'f':
572 if (action != DESTROY)
573 usage();
574 force = 1;
575 break;
576 case 'n':
577 if (action != CREATE && action != RESCUE)
578 usage();
579 nagle = 0;
580 break;
581 case 'o':
582 if (action != CREATE && action != RESCUE)
583 usage();
584 if (strcasecmp("ro", optarg) == 0)
585 flags = G_GATE_FLAG_READONLY;
586 else if (strcasecmp("wo", optarg) == 0)
587 flags = G_GATE_FLAG_WRITEONLY;
588 else if (strcasecmp("rw", optarg) == 0)
589 flags = 0;
590 else if (strcasecmp("direct", optarg) == 0)
591 direct_flag = GGATE_FLAG_DIRECT;
592 else {
593 errx(EXIT_FAILURE,
594 "Invalid argument for '-o' option.");
595 }
596 break;
597 case 'p':
598 if (action != CREATE && action != RESCUE)
599 usage();
600 errno = 0;
601 port = strtoul(optarg, NULL, 10);
602 if (port == 0 && errno != 0)
603 errx(EXIT_FAILURE, "Invalid port.");
604 break;
605 case 'q':
606 if (action != CREATE)
607 usage();
608 errno = 0;
609 queue_size = strtoul(optarg, NULL, 10);
610 if (queue_size == 0 && errno != 0)
611 errx(EXIT_FAILURE, "Invalid queue_size.");
612 break;
613 case 'R':
614 if (action != CREATE && action != RESCUE)
615 usage();
616 errno = 0;
617 rcvbuf = strtoul(optarg, NULL, 10);
618 if (rcvbuf == 0 && errno != 0)
619 errx(EXIT_FAILURE, "Invalid rcvbuf.");
620 break;
621 case 'S':
622 if (action != CREATE && action != RESCUE)
623 usage();
624 errno = 0;
625 sndbuf = strtoul(optarg, NULL, 10);
626 if (sndbuf == 0 && errno != 0)
627 errx(EXIT_FAILURE, "Invalid sndbuf.");
628 break;
629 case 's':
630 if (action != CREATE)
631 usage();
632 errno = 0;
633 sectorsize = strtoul(optarg, NULL, 10);
634 if (sectorsize == 0 && errno != 0)
635 errx(EXIT_FAILURE, "Invalid sectorsize.");
636 break;
637 case 't':
638 if (action != CREATE)
639 usage();
640 errno = 0;
641 timeout = strtoul(optarg, NULL, 10);
642 if (timeout == 0 && errno != 0)
643 errx(EXIT_FAILURE, "Invalid timeout.");
644 break;
645 case 'u':
646 errno = 0;
647 unit = strtol(optarg, NULL, 10);
648 if (unit == 0 && errno != 0)
649 errx(EXIT_FAILURE, "Invalid unit number.");
650 break;
651 case 'v':
652 if (action == DESTROY)
653 usage();
654 g_gate_verbose++;
655 break;
656 default:
657 usage();
658 }
659 }
660 argc -= optind;
661 argv += optind;
662
663 init_initial_buffer_size();
664
665 switch (action) {
666 case CREATE:
667 if (argc != 2)
668 usage();
669 g_gate_load_module();
670 g_gate_open_device();
671 host = argv[0];
672 path = argv[1];
673 g_gatec_create();
674 break;
675 case DESTROY:
676 if (unit == -1) {
677 fprintf(stderr, "Required unit number.\n");
678 usage();
679 }
680 g_gate_verbose = 1;
681 g_gate_open_device();
682 g_gate_destroy(unit, force);
683 break;
684 case LIST:
685 g_gate_list(unit, g_gate_verbose);
686 break;
687 case RESCUE:
688 if (argc != 2)
689 usage();
690 if (unit == -1) {
691 fprintf(stderr, "Required unit number.\n");
692 usage();
693 }
694 g_gate_open_device();
695 host = argv[0];
696 path = argv[1];
697 g_gatec_rescue();
698 break;
699 case UNSET:
700 default:
701 usage();
702 }
703 g_gate_close_device();
704 exit(EXIT_SUCCESS);
705 }
706