xref: /freebsd/usr.sbin/pnfsdskill/pnfsdskill.c (revision f1ed5c000c688cf9781b486134baf4ba25415efd)
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 <stdio.h>
34 #include <stdlib.h>
35 #include <unistd.h>
36 #include <netdb.h>
37 #include <arpa/inet.h>
38 #include <netinet/in.h>
39 #include <nfs/nfssvc.h>
40 
41 #include <fs/nfs/nfsproto.h>
42 #include <fs/nfs/nfskpiport.h>
43 #include <fs/nfs/nfs.h>
44 
45 static void usage(void);
46 
47 /*
48  * This program disables use of a DS mirror.  The "dspath" command line
49  * argument must be an exact match for the mounted-on path of the DS.
50  * It should be done before any forced dismount is performed on the path
51  * and should work even when the mount point is hung.
52  */
53 int
54 main(int argc, char *argv[])
55 {
56 	struct nfsd_pnfsd_args pnfsdarg;
57 
58 	if (argc != 2)
59 		usage();
60 	if (geteuid() != 0)
61 		errx(1, "Must be run as root/su");
62 
63 	pnfsdarg.op = PNFSDOP_DELDSSERVER;
64 	pnfsdarg.dspath = argv[1];
65 	if (nfssvc(NFSSVC_PNFSDS, &pnfsdarg) < 0)
66 		err(1, "Can't kill %s", argv[1]);
67 }
68 
69 static void
70 usage(void)
71 {
72 
73 	fprintf(stderr, "pnfsdsfile [filepath]\n");
74 	exit(1);
75 }
76 
77