Print this page
4953763 Need way to configure NFS window sizes without changing system wide defaults
6216670 NFS server needs a bigger transmit buffer
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/cmd/fs.d/nfs/nfs4cbd/nfs4cbd.c
+++ new/usr/src/cmd/fs.d/nfs/nfs4cbd/nfs4cbd.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
|
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 - * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22 + * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 27 /* All Rights Reserved */
28 28
29 29 /*
30 30 * Portions of this source code were derived from Berkeley 4.3 BSD
31 31 * under license from the Regents of the University of California.
32 32 */
33 33
34 -#pragma ident "%Z%%M% %I% %E% SMI"
35 -
36 34 /*
37 35 * This module provides the user level support for the NFSv4
38 36 * callback program. It is modeled after nfsd. When a nfsv4
39 37 * mount occurs, the mount command forks and the child runs
40 38 * start_nfs4_callback. If this is the first mount, then the
41 39 * process will hang around listening for incoming connection
42 40 * requests from the nfsv4 server.
43 41 *
44 42 * For connection-less protocols, the krpc is started immediately.
45 43 * For connection oriented protocols, the kernel module is informed
46 44 * of netid and universal address that it can give this
47 45 * information to the server during setclientid.
48 46 */
49 47
50 48 #include <sys/param.h>
51 49 #include <sys/types.h>
52 50 #include <syslog.h>
53 51 #include <tiuser.h>
54 52 #include <rpc/rpc.h>
55 53 #include <errno.h>
56 54 #include <thread.h>
57 55 #include <sys/resource.h>
58 56 #include <sys/file.h>
59 57 #include <nfs/nfs.h>
60 58 #include <nfs/nfssys.h>
61 59 #include <stdio.h>
62 60 #include <stdlib.h>
63 61 #include <netconfig.h>
64 62 #include <netdir.h>
65 63 #include <string.h>
66 64 #include <unistd.h>
67 65 #include <stropts.h>
68 66 #include <sys/tihdr.h>
69 67 #include <netinet/tcp.h>
70 68 #include "nfs_tbind.h"
71 69 #include "thrpool.h"
72 70 #include <rpcsvc/nfs4_prot.h>
73 71 #include <netdb.h>
74 72 #include <signal.h>
75 73 #include <strings.h>
76 74 #include <priv_utils.h>
77 75 #include <rpcsvc/daemon_utils.h>
78 76
79 77 static int nfs4svc(int, struct netbuf *, struct netconfig *, int,
80 78 struct netbuf *);
81 79 extern int _nfssys(int, void *);
82 80
83 81 static char *MyName;
84 82
85 83 /*
86 84 * The following are all globals used by routines in nfs_tbind.c.
87 85 */
88 86 size_t end_listen_fds; /* used by conn_close_oldest() */
89 87 size_t num_fds = 0; /* used by multiple routines */
90 88 int listen_backlog = 32; /* used by bind_to_{provider,proto}() */
91 89 int num_servers; /* used by cots_listen_event() */
92 90 int (*Mysvc)(int, struct netbuf, struct netconfig *) = NULL;
93 91 /* used by cots_listen_event() */
94 92 int max_conns_allowed = -1; /* used by cots_listen_event() */
95 93
96 94 int
97 95 main(int argc, char *argv[])
98 96 {
99 97 int pid;
100 98 int i;
101 99 struct protob *protobp;
102 100 struct flock f;
103 101 pid_t pi;
104 102 struct svcpool_args cb_svcpool;
105 103
106 104 MyName = "nfs4cbd";
107 105 Mysvc4 = nfs4svc;
108 106
109 107 #ifndef DEBUG
110 108 /*
111 109 * Close existing file descriptors, open "/dev/null" as
112 110 * standard input, output, and error, and detach from
113 111 * controlling terminal.
114 112 */
115 113 closefrom(0);
116 114 (void) open("/dev/null", O_RDONLY);
117 115 (void) open("/dev/null", O_WRONLY);
118 116 (void) dup(1);
119 117 (void) setsid();
120 118 #endif
121 119
|
↓ open down ↓ |
76 lines elided |
↑ open up ↑ |
122 120 /*
123 121 * create a child to continue our work
124 122 * Parent's exit will tell mount command we're ready to go
125 123 */
126 124 if ((pi = fork()) > 0) {
127 125 exit(0);
128 126 }
129 127
130 128 if (pi == -1) {
131 129 (void) syslog(LOG_ERR,
132 - "Could not start NFS4_CALLBACK service");
130 + "Could not start NFS4_CALLBACK service");
133 131 exit(1);
134 132 }
135 133
136 134 (void) _create_daemon_lock(NFS4CBD, DAEMON_UID, DAEMON_GID);
137 135
138 136 svcsetprio();
139 137
140 138 if (__init_daemon_priv(PU_RESETGROUPS|PU_CLEARLIMITSET,
141 139 DAEMON_UID, DAEMON_GID, PRIV_SYS_NFS, (char *)NULL) == -1) {
142 140 (void) fprintf(stderr, "%s must be run with sufficient"
143 - " privileges\n", argv[0]);
141 + " privileges\n", argv[0]);
144 142 exit(1);
145 143 }
146 144 /* Basic privileges we don't need, remove from E/P. */
147 145 __fini_daemon_priv(PRIV_PROC_EXEC, PRIV_PROC_FORK, PRIV_FILE_LINK_ANY,
148 146 PRIV_PROC_SESSION, PRIV_PROC_INFO, (char *)NULL);
149 147
150 148 /*
151 149 * establish our lock on the lock file and write our pid to it.
152 150 * exit if some other process holds the lock, or if there's any
153 151 * error in writing/locking the file.
154 152 */
155 153 pid = _enter_daemon_lock(NFS4CBD);
156 154 switch (pid) {
157 155 case 0:
158 156 break;
159 157 case -1:
160 158 syslog(LOG_ERR, "error locking for %s: %s", NFS4CBD,
161 159 strerror(errno));
162 160 exit(2);
163 161 default:
164 162 /* daemon was already running */
165 163 exit(0);
166 164 }
167 165
168 166 openlog(MyName, LOG_PID | LOG_NDELAY, LOG_DAEMON);
169 167
170 168 cb_svcpool.id = NFS_CB_SVCPOOL_ID;
171 169 cb_svcpool.maxthreads = 0;
172 170 cb_svcpool.redline = 0;
173 171 cb_svcpool.qsize = 0;
174 172 cb_svcpool.timeout = 0;
175 173 cb_svcpool.stksize = 0;
176 174 cb_svcpool.max_same_xprt = 0;
177 175
178 176 /* create a SVC_POOL for the nfsv4 callback deamon */
179 177 if (_nfssys(SVCPOOL_CREATE, &cb_svcpool)) {
180 178 (void) syslog(LOG_ERR, "can't setup NFS_CB SVCPOOL: Exiting");
181 179 exit(1);
182 180 }
183 181
184 182 /*
185 183 * Set up blocked thread to do LWP creation on behalf of the kernel.
186 184 */
187 185 if (svcwait(NFS_CB_SVCPOOL_ID)) {
188 186 (void) syslog(LOG_ERR,
189 187 "Can't set up NFS_CB LWP creator: Exiting");
190 188 exit(1);
191 189 }
192 190
193 191
194 192 /*
195 193 * Build a protocol block list for registration.
196 194 */
197 195 protobp = (struct protob *)malloc(sizeof (struct protob));
198 196 protobp->serv = "NFS4_CALLBACK";
199 197 protobp->versmin = NFS_CB;
200 198 protobp->versmax = NFS_CB;
201 199 protobp->program = NFS4_CALLBACK;
202 200 protobp->next = NULL;
203 201
204 202 if (do_all(protobp, NULL, 0) == -1) {
205 203 exit(1);
206 204 }
207 205
208 206 free(protobp);
209 207
210 208 if (num_fds == 0) {
211 209 (void) syslog(LOG_ERR,
212 210 "Could not start NFS4_CALLBACK service for any protocol");
213 211 exit(1);
214 212 }
215 213
216 214 end_listen_fds = num_fds;
217 215 /*
218 216 * Poll for non-data control events on the transport descriptors.
219 217 */
220 218 poll_for_action();
221 219
222 220 /*
223 221 * If we get here, something failed in poll_for_action().
224 222 */
225 223 return (1);
226 224 }
227 225
228 226 char *
229 227 get_uaddr(int fd, struct netconfig *nconf, struct netbuf *nb)
230 228 {
231 229 struct nfs_svc_args nsa;
232 230 char *ua, *ua2, *mua = NULL;
|
↓ open down ↓ |
79 lines elided |
↑ open up ↑ |
233 231 char me[MAXHOSTNAMELEN];
234 232 struct nd_addrlist *nas;
235 233 struct nd_hostserv hs;
236 234 struct nd_mergearg ma;
237 235
238 236 ua = taddr2uaddr(nconf, nb);
239 237
240 238 if (ua == NULL) {
241 239 #ifdef DEBUG
242 240 fprintf(stderr, "taddr2uaddr failed for netid %s\n",
243 - nconf->nc_netid);
241 + nconf->nc_netid);
244 242 #endif
245 243 return (NULL);
246 244 }
247 245
248 246 gethostname(me, MAXHOSTNAMELEN);
249 247
250 248 hs.h_host = me;
251 249 hs.h_serv = "nfs";
252 250 if (netdir_getbyname(nconf, &hs, &nas)) {
253 251 #ifdef DEBUG
254 252 netdir_perror("netdir_getbyname");
255 253 #endif
256 254 return (NULL);
257 255 }
258 256
259 257 ua2 = taddr2uaddr(nconf, nas->n_addrs);
260 258
261 259 if (ua2 == NULL) {
262 260 #ifdef DEBUG
263 261 fprintf(stderr, "taddr2uaddr failed for netid %s.\n",
264 - nconf->nc_netid);
262 + nconf->nc_netid);
265 263 #endif
266 264 return (NULL);
267 265 }
268 266
269 267 ma.s_uaddr = ua;
270 268 ma.c_uaddr = ua2;
271 269 ma.m_uaddr = NULL;
272 270
273 271 if (netdir_options(nconf, ND_MERGEADDR, 0, (char *)&ma)) {
274 272 #ifdef DEBUG
275 273 netdir_perror("netdir_options");
276 274 #endif
277 275 return (NULL);
278 276 }
279 277
280 278 mua = ma.m_uaddr;
281 279 return (mua);
282 280 }
283 281
284 282 /*
285 283 * Establish NFS4 callback service thread.
286 284 */
287 285 static int
288 286 nfs4svc(int fd, struct netbuf *addrmask, struct netconfig *nconf,
|
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
289 287 int cmd, struct netbuf *addr)
290 288 {
291 289 struct nfs4_svc_args nsa;
292 290 char *ua;
293 291 int error;
294 292
295 293 ua = get_uaddr(fd, nconf, addr);
296 294
297 295 if (ua == NULL) {
298 296 syslog(LOG_NOTICE, "nfsv4 cannot determine local hostname "
299 - "binding for transport %s - delegations will not be "
300 - "available on this transport\n", nconf->nc_netid);
297 + "binding for transport %s - delegations will not be "
298 + "available on this transport\n", nconf->nc_netid);
301 299 return (0);
302 300 }
303 301
304 302 #ifdef DEBUG
305 303 if (cmd & NFS4_KRPC_START)
306 304 fprintf(stderr, "nfs4cbd: starting callback rpc on %s %s\n",
307 - nconf->nc_netid, ua);
305 + nconf->nc_netid, ua);
308 306 else
309 307 fprintf(stderr, "nfs4cbd: listening on %s %s\n",
310 - nconf->nc_netid, ua);
308 + nconf->nc_netid, ua);
311 309 #endif
312 310
313 311 nsa.fd = fd;
314 312 nsa.cmd = cmd;
315 313 nsa.netid = nconf->nc_netid;
316 314 if (addrmask)
317 315 nsa.addrmask = *addrmask;
318 316 else
319 317 bzero(&nsa.addrmask, sizeof (struct netbuf));
320 318 nsa.addr = ua;
321 319 nsa.protofmly = nconf->nc_protofmly;
322 320 nsa.proto = nconf->nc_proto;
323 321 if ((error = _nfssys(NFS4_SVC, &nsa)) != 0)
324 322 syslog(LOG_ERR, "nfssys NFS4_SVC failed\n");
325 323
326 324 return (error);
327 325 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX