1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2017 Rick Macklem 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 */ 28 29 #include <sys/cdefs.h> 30 __FBSDID("$FreeBSD$"); 31 32 #include <err.h> 33 #include <getopt.h> 34 #include <stdio.h> 35 #include <stdlib.h> 36 #include <unistd.h> 37 #include <netdb.h> 38 #include <arpa/inet.h> 39 #include <netinet/in.h> 40 #include <nfs/nfssvc.h> 41 42 #include <fs/nfs/nfsproto.h> 43 #include <fs/nfs/nfskpiport.h> 44 #include <fs/nfs/nfs.h> 45 46 static void usage(void); 47 48 static struct option longopts[] = { 49 { "force", no_argument, NULL, 'f' }, 50 { NULL, 0, NULL, 0 } 51 }; 52 53 /* 54 * This program disables use of a DS mirror. The "dspath" command line 55 * argument must be an exact match for the mounted-on path of the DS. 56 * It should be done before any forced dismount is performed on the path 57 * and should work even when the mount point is hung. 58 */ 59 int 60 main(int argc, char *argv[]) 61 { 62 struct nfsd_pnfsd_args pnfsdarg; 63 int ch, force; 64 65 if (geteuid() != 0) 66 errx(1, "Must be run as root/su"); 67 force = 0; 68 while ((ch = getopt_long(argc, argv, "f", longopts, NULL)) != -1) { 69 switch (ch) { 70 case 'f': 71 force = 1; 72 break; 73 default: 74 usage(); 75 } 76 } 77 argc -= optind; 78 argv += optind; 79 if (argc != 1) 80 usage(); 81 82 if (force != 0) 83 pnfsdarg.op = PNFSDOP_FORCEDELDS; 84 else 85 pnfsdarg.op = PNFSDOP_DELDSSERVER; 86 pnfsdarg.dspath = *argv; 87 if (nfssvc(NFSSVC_PNFSDS, &pnfsdarg) < 0) 88 err(1, "Can't kill %s", *argv); 89 } 90 91 static void 92 usage(void) 93 { 94 95 fprintf(stderr, "pnfsdsfile [-f] mounted-on-DS-dir\n"); 96 exit(1); 97 } 98 99