Deleted Added
full compact
nfsiod.c (1559) nfsiod.c (2999)
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#ifndef lint
38static char copyright[] =
39"@(#) Copyright (c) 1989, 1993\n\
40 The Regents of the University of California. All rights reserved.\n";
41#endif not lint
42
43#ifndef lint
44static char sccsid[] = "@(#)nfsiod.c 8.3 (Berkeley) 2/22/94";
45#endif not lint
46
47#include <sys/param.h>
48#include <sys/ioctl.h>
49#include <sys/syslog.h>
50#include <sys/ucred.h>
51#include <sys/wait.h>
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#ifndef lint
38static char copyright[] =
39"@(#) Copyright (c) 1989, 1993\n\
40 The Regents of the University of California. All rights reserved.\n";
41#endif not lint
42
43#ifndef lint
44static char sccsid[] = "@(#)nfsiod.c 8.3 (Berkeley) 2/22/94";
45#endif not lint
46
47#include <sys/param.h>
48#include <sys/ioctl.h>
49#include <sys/syslog.h>
50#include <sys/ucred.h>
51#include <sys/wait.h>
52#include <sys/mount.h>
52
53#include <nfs/nfsv2.h>
54#include <nfs/nfs.h>
55
56#include <err.h>
57#include <errno.h>
58#include <fcntl.h>
59#include <signal.h>
60#include <stdio.h>
61#include <stdlib.h>
62#include <unistd.h>
63
64/* Global defs */
65#ifdef DEBUG
66int debug = 1;
67#else
68int debug = 0;
69#endif
70
71void nonfs __P((int));
72void reapchild __P((int));
73void usage __P((void));
74
75/*
76 * Nfsiod does asynchronous buffered I/O on behalf of the NFS client.
77 * It does not have to be running for correct operation, but will
78 * improve throughput.
79 */
80int
81main(argc, argv)
82 int argc;
83 char *argv[];
84{
85 int ch, num_servers;
53
54#include <nfs/nfsv2.h>
55#include <nfs/nfs.h>
56
57#include <err.h>
58#include <errno.h>
59#include <fcntl.h>
60#include <signal.h>
61#include <stdio.h>
62#include <stdlib.h>
63#include <unistd.h>
64
65/* Global defs */
66#ifdef DEBUG
67int debug = 1;
68#else
69int debug = 0;
70#endif
71
72void nonfs __P((int));
73void reapchild __P((int));
74void usage __P((void));
75
76/*
77 * Nfsiod does asynchronous buffered I/O on behalf of the NFS client.
78 * It does not have to be running for correct operation, but will
79 * improve throughput.
80 */
81int
82main(argc, argv)
83 int argc;
84 char *argv[];
85{
86 int ch, num_servers;
87 struct vfsconf *vfc;
86
88
89 vfc = getvfsbyname("nfs");
90 if(!vfc && vfsisloadable("nfs")) {
91 if(vfsload("nfs"))
92 err(1, "vfsload(nfs)");
93 endvfsent(); /* flush cache */
94 vfc = getvfsbyname("nfs");
95 }
96
97 if(!vfc) {
98 errx(1, "NFS support is not available in the running kernel");
99 }
100
87#define MAXNFSDCNT 20
88#define DEFNFSDCNT 1
89 num_servers = DEFNFSDCNT;
90 while ((ch = getopt(argc, argv, "n:")) != EOF)
91 switch (ch) {
92 case 'n':
93 num_servers = atoi(optarg);
94 if (num_servers < 1 || num_servers > MAXNFSDCNT) {
95 warnx("nfsiod count %d; reset to %d",
96 DEFNFSDCNT);
97 num_servers = DEFNFSDCNT;
98 }
99 break;
100 case '?':
101 default:
102 usage();
103 }
104 argc -= optind;
105 argv += optind;
106
107 /*
108 * XXX
109 * Backward compatibility, trailing number is the count of daemons.
110 */
111 if (argc > 1)
112 usage();
113 if (argc == 1) {
114 num_servers = atoi(argv[0]);
115 if (num_servers < 1 || num_servers > MAXNFSDCNT) {
116 warnx("nfsiod count %d; reset to %d", DEFNFSDCNT);
117 num_servers = DEFNFSDCNT;
118 }
119 }
120
121 if (debug == 0) {
122 daemon(0, 0);
123 (void)signal(SIGHUP, SIG_IGN);
124 (void)signal(SIGINT, SIG_IGN);
125 (void)signal(SIGQUIT, SIG_IGN);
126 (void)signal(SIGSYS, nonfs);
127 }
128 (void)signal(SIGCHLD, reapchild);
129
130 openlog("nfsiod:", LOG_PID, LOG_DAEMON);
131
132 while (num_servers--)
133 switch (fork()) {
134 case -1:
135 syslog(LOG_ERR, "fork: %m");
136 exit (1);
137 case 0:
138 if (nfssvc(NFSSVC_BIOD, NULL) < 0) {
139 syslog(LOG_ERR, "nfssvc: %m");
140 exit (1);
141 }
142 exit(0);
143 }
144 exit (0);
145}
146
147void
148nonfs(signo)
149 int signo;
150{
151 syslog(LOG_ERR, "missing system call: NFS not available.");
152}
153
154void
155reapchild(signo)
156 int signo;
157{
158
159 while (wait3(NULL, WNOHANG, NULL));
160}
161
162void
163usage()
164{
165 (void)fprintf(stderr, "usage: nfsiod [-n num_servers]\n");
166 exit(1);
167}
101#define MAXNFSDCNT 20
102#define DEFNFSDCNT 1
103 num_servers = DEFNFSDCNT;
104 while ((ch = getopt(argc, argv, "n:")) != EOF)
105 switch (ch) {
106 case 'n':
107 num_servers = atoi(optarg);
108 if (num_servers < 1 || num_servers > MAXNFSDCNT) {
109 warnx("nfsiod count %d; reset to %d",
110 DEFNFSDCNT);
111 num_servers = DEFNFSDCNT;
112 }
113 break;
114 case '?':
115 default:
116 usage();
117 }
118 argc -= optind;
119 argv += optind;
120
121 /*
122 * XXX
123 * Backward compatibility, trailing number is the count of daemons.
124 */
125 if (argc > 1)
126 usage();
127 if (argc == 1) {
128 num_servers = atoi(argv[0]);
129 if (num_servers < 1 || num_servers > MAXNFSDCNT) {
130 warnx("nfsiod count %d; reset to %d", DEFNFSDCNT);
131 num_servers = DEFNFSDCNT;
132 }
133 }
134
135 if (debug == 0) {
136 daemon(0, 0);
137 (void)signal(SIGHUP, SIG_IGN);
138 (void)signal(SIGINT, SIG_IGN);
139 (void)signal(SIGQUIT, SIG_IGN);
140 (void)signal(SIGSYS, nonfs);
141 }
142 (void)signal(SIGCHLD, reapchild);
143
144 openlog("nfsiod:", LOG_PID, LOG_DAEMON);
145
146 while (num_servers--)
147 switch (fork()) {
148 case -1:
149 syslog(LOG_ERR, "fork: %m");
150 exit (1);
151 case 0:
152 if (nfssvc(NFSSVC_BIOD, NULL) < 0) {
153 syslog(LOG_ERR, "nfssvc: %m");
154 exit (1);
155 }
156 exit(0);
157 }
158 exit (0);
159}
160
161void
162nonfs(signo)
163 int signo;
164{
165 syslog(LOG_ERR, "missing system call: NFS not available.");
166}
167
168void
169reapchild(signo)
170 int signo;
171{
172
173 while (wait3(NULL, WNOHANG, NULL));
174}
175
176void
177usage()
178{
179 (void)fprintf(stderr, "usage: nfsiod [-n num_servers]\n");
180 exit(1);
181}