Commit | Line | Data |
---|---|---|
a2907882 KM |
1 | /* |
2 | * Copyright (c) 1989 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * Rick Macklem at The University of Guelph. | |
7 | * | |
dbf0c423 | 8 | * %sccs.include.redist.c% |
a2907882 | 9 | * |
c33e9e8b | 10 | * @(#)nfs_vfsops.c 7.49 (Berkeley) %G% |
a2907882 KM |
11 | */ |
12 | ||
5548a02f KB |
13 | #include <sys/param.h> |
14 | #include <sys/conf.h> | |
15 | #include <sys/ioctl.h> | |
16 | #include <sys/signal.h> | |
17 | #include <sys/proc.h> | |
18 | #include <sys/namei.h> | |
19 | #include <sys/vnode.h> | |
20 | #include <sys/kernel.h> | |
21 | #include <sys/mount.h> | |
22 | #include <sys/buf.h> | |
23 | #include <sys/mbuf.h> | |
24 | #include <sys/socket.h> | |
25 | #include <sys/systm.h> | |
058dee65 | 26 | |
5548a02f KB |
27 | #include <net/if.h> |
28 | #include <net/route.h> | |
29 | #include <netinet/in.h> | |
058dee65 | 30 | |
5548a02f KB |
31 | #include <nfs/rpcv2.h> |
32 | #include <nfs/nfsv2.h> | |
33 | #include <nfs/nfsnode.h> | |
34 | #include <nfs/nfsmount.h> | |
35 | #include <nfs/nfs.h> | |
36 | #include <nfs/xdr_subs.h> | |
37 | #include <nfs/nfsm_subs.h> | |
38 | #include <nfs/nfsdiskless.h> | |
39 | #include <nfs/nqnfs.h> | |
a2907882 | 40 | |
a2907882 KM |
41 | /* |
42 | * nfs vfs operations. | |
43 | */ | |
a2907882 KM |
44 | struct vfsops nfs_vfsops = { |
45 | nfs_mount, | |
b3226026 | 46 | nfs_start, |
a2907882 KM |
47 | nfs_unmount, |
48 | nfs_root, | |
56cf2c46 | 49 | nfs_quotactl, |
a2907882 KM |
50 | nfs_statfs, |
51 | nfs_sync, | |
2cd82738 | 52 | nfs_vget, |
a2907882 KM |
53 | nfs_fhtovp, |
54 | nfs_vptofh, | |
363ac00e | 55 | nfs_init, |
a2907882 KM |
56 | }; |
57 | ||
2c5b44a2 KM |
58 | /* |
59 | * This structure must be filled in by a primary bootstrap or bootstrap | |
60 | * server for a diskless/dataless machine. It is initialized below just | |
61 | * to ensure that it is allocated to initialized data (.data not .bss). | |
62 | */ | |
63 | struct nfs_diskless nfs_diskless = { 0 }; | |
64 | ||
e8540f59 | 65 | static u_char nfs_mntid; |
f0f1cbaa KM |
66 | extern u_long nfs_procids[NFS_NPROCS]; |
67 | extern u_long nfs_prog, nfs_vers; | |
c465e0e7 CT |
68 | void nfs_disconnect __P((struct nfsmount *)); |
69 | void nfsargs_ntoh __P((struct nfs_args *)); | |
70 | static struct mount *nfs_mountdiskless __P((char *, char *, int, | |
71 | struct sockaddr_in *, struct nfs_args *, register struct vnode **)); | |
f0f1cbaa KM |
72 | |
73 | #define TRUE 1 | |
74 | #define FALSE 0 | |
75 | ||
76 | /* | |
77 | * nfs statfs call | |
78 | */ | |
c465e0e7 | 79 | int |
4ebfcce2 | 80 | nfs_statfs(mp, sbp, p) |
f0f1cbaa KM |
81 | struct mount *mp; |
82 | register struct statfs *sbp; | |
4ebfcce2 | 83 | struct proc *p; |
f0f1cbaa KM |
84 | { |
85 | register struct vnode *vp; | |
86 | register struct nfsv2_statfs *sfp; | |
87 | register caddr_t cp; | |
88 | register long t1; | |
89 | caddr_t bpos, dpos, cp2; | |
41f343df | 90 | int error = 0, isnq; |
f0f1cbaa KM |
91 | struct mbuf *mreq, *mrep, *md, *mb, *mb2; |
92 | struct nfsmount *nmp; | |
93 | struct ucred *cred; | |
94 | struct nfsnode *np; | |
95 | ||
96 | nmp = VFSTONFS(mp); | |
41f343df | 97 | isnq = (nmp->nm_flag & NFSMNT_NQNFS); |
f0f1cbaa KM |
98 | if (error = nfs_nget(mp, &nmp->nm_fh, &np)) |
99 | return (error); | |
100 | vp = NFSTOV(np); | |
101 | nfsstats.rpccnt[NFSPROC_STATFS]++; | |
102 | cred = crget(); | |
103 | cred->cr_ngroups = 1; | |
2c5b44a2 | 104 | nfsm_reqhead(vp, NFSPROC_STATFS, NFSX_FH); |
f0f1cbaa | 105 | nfsm_fhtom(vp); |
2c5b44a2 | 106 | nfsm_request(vp, NFSPROC_STATFS, p, cred); |
41f343df | 107 | nfsm_dissect(sfp, struct nfsv2_statfs *, NFSX_STATFS(isnq)); |
f0f1cbaa KM |
108 | sbp->f_type = MOUNT_NFS; |
109 | sbp->f_flags = nmp->nm_flag; | |
2c5b44a2 | 110 | sbp->f_iosize = NFS_MAXDGRAMDATA; |
a22e809c | 111 | sbp->f_bsize = fxdr_unsigned(long, sfp->sf_bsize); |
f0f1cbaa KM |
112 | sbp->f_blocks = fxdr_unsigned(long, sfp->sf_blocks); |
113 | sbp->f_bfree = fxdr_unsigned(long, sfp->sf_bfree); | |
114 | sbp->f_bavail = fxdr_unsigned(long, sfp->sf_bavail); | |
41f343df KM |
115 | if (isnq) { |
116 | sbp->f_files = fxdr_unsigned(long, sfp->sf_files); | |
117 | sbp->f_ffree = fxdr_unsigned(long, sfp->sf_ffree); | |
118 | } else { | |
119 | sbp->f_files = 0; | |
120 | sbp->f_ffree = 0; | |
121 | } | |
f0f1cbaa KM |
122 | if (sbp != &mp->mnt_stat) { |
123 | bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN); | |
124 | bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN); | |
125 | } | |
126 | nfsm_reqdone; | |
2c5b44a2 | 127 | vrele(vp); |
f0f1cbaa KM |
128 | crfree(cred); |
129 | return (error); | |
130 | } | |
a2907882 KM |
131 | |
132 | /* | |
1c89915d KM |
133 | * Mount a remote root fs via. nfs. This depends on the info in the |
134 | * nfs_diskless structure that has been filled in properly by some primary | |
135 | * bootstrap. | |
136 | * It goes something like this: | |
137 | * - do enough of "ifconfig" by calling ifioctl() so that the system | |
138 | * can talk to the server | |
139 | * - If nfs_diskless.mygateway is filled in, use that address as | |
140 | * a default gateway. | |
1c89915d | 141 | * - hand craft the swap nfs vnode hanging off a fake mount point |
2c5b44a2 | 142 | * if swdevt[0].sw_dev == NODEV |
1c89915d | 143 | * - build the rootfs mount point and call mountnfs() to do the rest. |
a2907882 | 144 | */ |
c465e0e7 | 145 | int |
a2907882 KM |
146 | nfs_mountroot() |
147 | { | |
1c89915d | 148 | register struct mount *mp; |
c465e0e7 | 149 | register struct nfs_diskless *nd = &nfs_diskless; |
1c89915d KM |
150 | struct socket *so; |
151 | struct vnode *vp; | |
c465e0e7 | 152 | struct proc *p = curproc; /* XXX */ |
26e1e7cf | 153 | int error, i; |
1c89915d | 154 | |
c465e0e7 CT |
155 | /* |
156 | * XXX time must be non-zero when we init the interface or else | |
157 | * the arp code will wedge... | |
158 | */ | |
159 | if (time.tv_sec == 0) | |
160 | time.tv_sec = 1; | |
161 | ||
162 | #ifdef notyet | |
163 | /* Set up swap credentials. */ | |
c33e9e8b KM |
164 | proc0.p_ucred->cr_uid = ntohl(nd->swap_ucred.cr_uid); |
165 | proc0.p_ucred->cr_gid = ntohl(nd->swap_ucred.cr_gid); | |
166 | if ((proc0.p_ucred->cr_ngroups = ntohs(nd->swap_ucred.cr_ngroups)) > | |
167 | NGROUPS) | |
168 | proc0.p_ucred->cr_ngroups = NGROUPS; | |
169 | for (i = 0; i < proc0.p_ucred->cr_ngroups; i++) | |
170 | proc0.p_ucred->cr_groups[i] = ntohl(nd->swap_ucred.cr_groups[i]); | |
c465e0e7 CT |
171 | #endif |
172 | ||
1c89915d | 173 | /* |
2c5b44a2 | 174 | * Do enough of ifconfig(8) so that the critical net interface can |
1c89915d KM |
175 | * talk to the server. |
176 | */ | |
c465e0e7 CT |
177 | if (error = socreate(nd->myif.ifra_addr.sa_family, &so, SOCK_DGRAM, 0)) |
178 | panic("nfs_mountroot: socreate: %d", error); | |
179 | if (error = ifioctl(so, SIOCAIFADDR, (caddr_t)&nd->myif, p)) | |
180 | panic("nfs_mountroot: SIOCAIFADDR: %d", error); | |
1c89915d KM |
181 | soclose(so); |
182 | ||
183 | /* | |
184 | * If the gateway field is filled in, set it as the default route. | |
185 | */ | |
c465e0e7 | 186 | if (nd->mygateway.sin_len != 0) { |
2c5b44a2 KM |
187 | struct sockaddr_in sin; |
188 | extern struct sockaddr_in icmpmask; | |
189 | ||
190 | sin.sin_len = sizeof (struct sockaddr_in); | |
191 | sin.sin_family = AF_INET; | |
192 | sin.sin_addr.s_addr = 0; /* default */ | |
193 | in_sockmaskof(sin.sin_addr, &icmpmask); | |
c465e0e7 CT |
194 | if (error = rtrequest(RTM_ADD, (struct sockaddr *)&sin, |
195 | (struct sockaddr *)&nd->mygateway, | |
196 | (struct sockaddr *)&icmpmask, | |
197 | RTF_UP | RTF_GATEWAY, (struct rtentry **)0)) | |
198 | panic("nfs_mountroot: RTM_ADD: %d", error); | |
1c89915d | 199 | } |
1c89915d KM |
200 | |
201 | /* | |
202 | * If swapping to an nfs node (indicated by swdevt[0].sw_dev == NODEV): | |
203 | * Create a fake mount point just for the swap vnode so that the | |
204 | * swap file can be on a different server from the rootfs. | |
205 | */ | |
206 | if (swdevt[0].sw_dev == NODEV) { | |
c465e0e7 CT |
207 | nd->swap_args.fh = (nfsv2fh_t *)nd->swap_fh; |
208 | (void) nfs_mountdiskless(nd->swap_hostnam, "/swap", 0, | |
209 | &nd->swap_saddr, &nd->swap_args, &vp); | |
1c89915d KM |
210 | |
211 | /* | |
1c89915d KM |
212 | * Since the swap file is not the root dir of a file system, |
213 | * hack it to a regular file. | |
214 | */ | |
1c89915d KM |
215 | vp->v_type = VREG; |
216 | vp->v_flag = 0; | |
217 | swapdev_vp = vp; | |
218 | VREF(vp); | |
219 | swdevt[0].sw_vp = vp; | |
c465e0e7 | 220 | swdevt[0].sw_nblks = ntohl(nd->swap_nblks); |
751df505 KM |
221 | } else if (bdevvp(swapdev, &swapdev_vp)) |
222 | panic("nfs_mountroot: can't setup swapdev_vp"); | |
1c89915d KM |
223 | |
224 | /* | |
225 | * Create the rootfs mount point. | |
226 | */ | |
c465e0e7 CT |
227 | nd->root_args.fh = (nfsv2fh_t *)nd->root_fh; |
228 | mp = nfs_mountdiskless(nd->root_hostnam, "/", MNT_RDONLY, | |
229 | &nd->root_saddr, &nd->root_args, &vp); | |
1c89915d | 230 | |
1c89915d | 231 | if (vfs_lock(mp)) |
c465e0e7 | 232 | panic("nfs_mountroot: vfs_lock"); |
1c89915d KM |
233 | rootfs = mp; |
234 | mp->mnt_next = mp; | |
235 | mp->mnt_prev = mp; | |
236 | mp->mnt_vnodecovered = NULLVP; | |
237 | vfs_unlock(mp); | |
238 | rootvp = vp; | |
26e1e7cf KM |
239 | |
240 | /* | |
241 | * This is not really an nfs issue, but it is much easier to | |
242 | * set hostname here and then let the "/etc/rc.xxx" files | |
243 | * mount the right /var based upon its preset value. | |
244 | */ | |
c465e0e7 | 245 | bcopy(nd->my_hostnam, hostname, MAXHOSTNAMELEN); |
26e1e7cf KM |
246 | hostname[MAXHOSTNAMELEN - 1] = '\0'; |
247 | for (i = 0; i < MAXHOSTNAMELEN; i++) | |
248 | if (hostname[i] == '\0') | |
249 | break; | |
250 | hostnamelen = i; | |
c33e9e8b | 251 | inittodr(ntohl(nd->root_time)); |
1c89915d | 252 | return (0); |
a2907882 KM |
253 | } |
254 | ||
c465e0e7 CT |
255 | /* |
256 | * Internal version of mount system call for diskless setup. | |
257 | */ | |
258 | static struct mount * | |
259 | nfs_mountdiskless(path, which, mountflag, sin, args, vpp) | |
260 | char *path; | |
261 | char *which; | |
262 | int mountflag; | |
263 | struct sockaddr_in *sin; | |
264 | struct nfs_args *args; | |
265 | register struct vnode **vpp; | |
266 | { | |
267 | register struct mount *mp; | |
268 | register struct mbuf *m; | |
269 | register int error; | |
270 | ||
271 | mp = (struct mount *)malloc((u_long)sizeof(struct mount), | |
272 | M_MOUNT, M_NOWAIT); | |
273 | if (mp == NULL) | |
274 | panic("nfs_mountroot: %s mount malloc", which); | |
275 | mp->mnt_op = &nfs_vfsops; | |
276 | mp->mnt_flag = mountflag; | |
277 | mp->mnt_mounth = NULLVP; | |
278 | ||
279 | MGET(m, MT_SONAME, M_DONTWAIT); | |
280 | if (m == NULL) | |
281 | panic("nfs_mountroot: %s mount mbuf", which); | |
282 | bcopy((caddr_t)sin, mtod(m, caddr_t), sin->sin_len); | |
283 | m->m_len = sin->sin_len; | |
284 | nfsargs_ntoh(args); | |
285 | if (error = mountnfs(args, mp, m, which, path, vpp)) | |
286 | panic("nfs_mountroot: mount %s on %s: %d", path, which, error); | |
287 | ||
288 | return (mp); | |
289 | } | |
290 | ||
2c5b44a2 KM |
291 | /* |
292 | * Convert the integer fields of the nfs_args structure from net byte order | |
293 | * to host byte order. Called by nfs_mountroot() above. | |
294 | */ | |
295 | void | |
296 | nfsargs_ntoh(nfsp) | |
297 | register struct nfs_args *nfsp; | |
298 | { | |
299 | ||
300 | NTOHL(nfsp->sotype); | |
301 | NTOHL(nfsp->proto); | |
302 | NTOHL(nfsp->flags); | |
303 | NTOHL(nfsp->wsize); | |
304 | NTOHL(nfsp->rsize); | |
305 | NTOHL(nfsp->timeo); | |
306 | NTOHL(nfsp->retrans); | |
307 | NTOHL(nfsp->maxgrouplist); | |
308 | NTOHL(nfsp->readahead); | |
309 | NTOHL(nfsp->leaseterm); | |
310 | NTOHL(nfsp->deadthresh); | |
311 | } | |
312 | ||
a2907882 KM |
313 | /* |
314 | * VFS Operations. | |
315 | * | |
316 | * mount system call | |
317 | * It seems a bit dumb to copyinstr() the host and path here and then | |
318 | * bcopy() them in mountnfs(), but I wanted to detect errors before | |
319 | * doing the sockargs() call because sockargs() allocates an mbuf and | |
320 | * an error after that means that I have to release the mbuf. | |
321 | */ | |
0bd503ad | 322 | /* ARGSUSED */ |
c465e0e7 | 323 | int |
4ebfcce2 | 324 | nfs_mount(mp, path, data, ndp, p) |
a2907882 KM |
325 | struct mount *mp; |
326 | char *path; | |
327 | caddr_t data; | |
328 | struct nameidata *ndp; | |
4ebfcce2 | 329 | struct proc *p; |
a2907882 KM |
330 | { |
331 | int error; | |
332 | struct nfs_args args; | |
f0f1cbaa | 333 | struct mbuf *nam; |
1c89915d | 334 | struct vnode *vp; |
a2907882 | 335 | char pth[MNAMELEN], hst[MNAMELEN]; |
4f76a9f0 | 336 | u_int len; |
a2907882 KM |
337 | nfsv2fh_t nfh; |
338 | ||
339 | if (error = copyin(data, (caddr_t)&args, sizeof (struct nfs_args))) | |
340 | return (error); | |
4f76a9f0 | 341 | if (error = copyin((caddr_t)args.fh, (caddr_t)&nfh, sizeof (nfsv2fh_t))) |
a2907882 KM |
342 | return (error); |
343 | if (error = copyinstr(path, pth, MNAMELEN-1, &len)) | |
344 | return (error); | |
4f76a9f0 | 345 | bzero(&pth[len], MNAMELEN - len); |
a2907882 KM |
346 | if (error = copyinstr(args.hostname, hst, MNAMELEN-1, &len)) |
347 | return (error); | |
4f76a9f0 | 348 | bzero(&hst[len], MNAMELEN - len); |
a2907882 | 349 | /* sockargs() call must be after above copyin() calls */ |
f0f1cbaa | 350 | if (error = sockargs(&nam, (caddr_t)args.addr, |
2c5b44a2 | 351 | args.addrlen, MT_SONAME)) |
a2907882 KM |
352 | return (error); |
353 | args.fh = &nfh; | |
1c89915d | 354 | error = mountnfs(&args, mp, nam, pth, hst, &vp); |
a2907882 KM |
355 | return (error); |
356 | } | |
357 | ||
358 | /* | |
359 | * Common code for mount and mountroot | |
360 | */ | |
c465e0e7 | 361 | int |
1c89915d | 362 | mountnfs(argp, mp, nam, pth, hst, vpp) |
a2907882 KM |
363 | register struct nfs_args *argp; |
364 | register struct mount *mp; | |
f0f1cbaa | 365 | struct mbuf *nam; |
a2907882 | 366 | char *pth, *hst; |
1c89915d | 367 | struct vnode **vpp; |
a2907882 KM |
368 | { |
369 | register struct nfsmount *nmp; | |
9fa46e39 | 370 | struct nfsnode *np; |
a2907882 | 371 | int error; |
98fb8dd3 | 372 | fsid_t tfsid; |
a2907882 | 373 | |
c465e0e7 CT |
374 | if (mp->mnt_flag & MNT_UPDATE) { |
375 | nmp = VFSTONFS(mp); | |
376 | /* update paths, file handles, etc, here XXX */ | |
377 | m_freem(nam); | |
378 | return (0); | |
379 | } else { | |
380 | MALLOC(nmp, struct nfsmount *, sizeof (struct nfsmount), | |
381 | M_NFSMNT, M_WAITOK); | |
382 | bzero((caddr_t)nmp, sizeof (struct nfsmount)); | |
383 | mp->mnt_data = (qaddr_t)nmp; | |
384 | } | |
6b9617ff | 385 | getnewfsid(mp, MOUNT_NFS); |
a2907882 KM |
386 | nmp->nm_mountp = mp; |
387 | nmp->nm_flag = argp->flags; | |
2c5b44a2 KM |
388 | if ((nmp->nm_flag & (NFSMNT_NQNFS | NFSMNT_MYWRITE)) == |
389 | (NFSMNT_NQNFS | NFSMNT_MYWRITE)) { | |
390 | error = EPERM; | |
391 | goto bad; | |
392 | } | |
460cf449 KM |
393 | if (nmp->nm_flag & (NFSMNT_RDIRALOOK | NFSMNT_LEASETERM)) { |
394 | if ((nmp->nm_flag & NFSMNT_NQNFS) == 0) { | |
395 | error = EPERM; | |
396 | goto bad; | |
397 | } | |
398 | /* | |
399 | * We have to set mnt_maxsymlink to a non-zero value so | |
400 | * that COMPAT_43 routines will know that we are setting | |
401 | * the d_type field in directories (and can zero it for | |
402 | * unsuspecting binaries). | |
403 | */ | |
404 | mp->mnt_maxsymlinklen = 1; | |
2c5b44a2 KM |
405 | } |
406 | nmp->nm_timeo = NFS_TIMEO; | |
98fb8dd3 KM |
407 | nmp->nm_retry = NFS_RETRANS; |
408 | nmp->nm_wsize = NFS_WSIZE; | |
409 | nmp->nm_rsize = NFS_RSIZE; | |
2c5b44a2 KM |
410 | nmp->nm_numgrps = NFS_MAXGRPS; |
411 | nmp->nm_readahead = NFS_DEFRAHEAD; | |
412 | nmp->nm_leaseterm = NQ_DEFLEASE; | |
413 | nmp->nm_deadthresh = NQ_DEADTHRESH; | |
414 | nmp->nm_tnext = (struct nfsnode *)nmp; | |
415 | nmp->nm_tprev = (struct nfsnode *)nmp; | |
416 | nmp->nm_inprog = NULLVP; | |
98fb8dd3 | 417 | bcopy((caddr_t)argp->fh, (caddr_t)&nmp->nm_fh, sizeof(nfsv2fh_t)); |
54fb9dc2 KM |
418 | mp->mnt_stat.f_type = MOUNT_NFS; |
419 | bcopy(hst, mp->mnt_stat.f_mntfromname, MNAMELEN); | |
420 | bcopy(pth, mp->mnt_stat.f_mntonname, MNAMELEN); | |
f0f1cbaa | 421 | nmp->nm_nam = nam; |
98fb8dd3 KM |
422 | |
423 | if ((argp->flags & NFSMNT_TIMEO) && argp->timeo > 0) { | |
2c5b44a2 KM |
424 | nmp->nm_timeo = (argp->timeo * NFS_HZ + 5) / 10; |
425 | if (nmp->nm_timeo < NFS_MINTIMEO) | |
426 | nmp->nm_timeo = NFS_MINTIMEO; | |
427 | else if (nmp->nm_timeo > NFS_MAXTIMEO) | |
428 | nmp->nm_timeo = NFS_MAXTIMEO; | |
98fb8dd3 KM |
429 | } |
430 | ||
d8792713 | 431 | if ((argp->flags & NFSMNT_RETRANS) && argp->retrans > 1) { |
98fb8dd3 KM |
432 | nmp->nm_retry = argp->retrans; |
433 | if (nmp->nm_retry > NFS_MAXREXMIT) | |
434 | nmp->nm_retry = NFS_MAXREXMIT; | |
435 | } | |
436 | ||
437 | if ((argp->flags & NFSMNT_WSIZE) && argp->wsize > 0) { | |
a2907882 | 438 | nmp->nm_wsize = argp->wsize; |
98fb8dd3 KM |
439 | /* Round down to multiple of blocksize */ |
440 | nmp->nm_wsize &= ~0x1ff; | |
441 | if (nmp->nm_wsize <= 0) | |
442 | nmp->nm_wsize = 512; | |
443 | else if (nmp->nm_wsize > NFS_MAXDATA) | |
444 | nmp->nm_wsize = NFS_MAXDATA; | |
445 | } | |
d8792713 KM |
446 | if (nmp->nm_wsize > MAXBSIZE) |
447 | nmp->nm_wsize = MAXBSIZE; | |
98fb8dd3 KM |
448 | |
449 | if ((argp->flags & NFSMNT_RSIZE) && argp->rsize > 0) { | |
a2907882 | 450 | nmp->nm_rsize = argp->rsize; |
98fb8dd3 KM |
451 | /* Round down to multiple of blocksize */ |
452 | nmp->nm_rsize &= ~0x1ff; | |
453 | if (nmp->nm_rsize <= 0) | |
454 | nmp->nm_rsize = 512; | |
455 | else if (nmp->nm_rsize > NFS_MAXDATA) | |
456 | nmp->nm_rsize = NFS_MAXDATA; | |
457 | } | |
d8792713 KM |
458 | if (nmp->nm_rsize > MAXBSIZE) |
459 | nmp->nm_rsize = MAXBSIZE; | |
2c5b44a2 KM |
460 | if ((argp->flags & NFSMNT_MAXGRPS) && argp->maxgrouplist >= 0 && |
461 | argp->maxgrouplist <= NFS_MAXGRPS) | |
462 | nmp->nm_numgrps = argp->maxgrouplist; | |
463 | if ((argp->flags & NFSMNT_READAHEAD) && argp->readahead >= 0 && | |
464 | argp->readahead <= NFS_MAXRAHEAD) | |
465 | nmp->nm_readahead = argp->readahead; | |
466 | if ((argp->flags & NFSMNT_LEASETERM) && argp->leaseterm >= 2 && | |
467 | argp->leaseterm <= NQ_MAXLEASE) | |
468 | nmp->nm_leaseterm = argp->leaseterm; | |
469 | if ((argp->flags & NFSMNT_DEADTHRESH) && argp->deadthresh >= 1 && | |
470 | argp->deadthresh <= NQ_NEVERDEAD) | |
471 | nmp->nm_deadthresh = argp->deadthresh; | |
98fb8dd3 | 472 | /* Set up the sockets and per-host congestion */ |
f0f1cbaa KM |
473 | nmp->nm_sotype = argp->sotype; |
474 | nmp->nm_soproto = argp->proto; | |
98fb8dd3 | 475 | |
2c5b44a2 KM |
476 | /* |
477 | * For Connection based sockets (TCP,...) defer the connect until | |
478 | * the first request, in case the server is not responding. | |
479 | */ | |
480 | if (nmp->nm_sotype == SOCK_DGRAM && | |
481 | (error = nfs_connect(nmp, (struct nfsreq *)0))) | |
efaa4294 | 482 | goto bad; |
2c5b44a2 KM |
483 | |
484 | /* | |
485 | * This is silly, but it has to be set so that vinifod() works. | |
486 | * We do not want to do an nfs_statfs() here since we can get | |
487 | * stuck on a dead server and we are holding a lock on the mount | |
488 | * point. | |
489 | */ | |
490 | mp->mnt_stat.f_iosize = NFS_MAXDGRAMDATA; | |
9fa46e39 KM |
491 | /* |
492 | * A reference count is needed on the nfsnode representing the | |
493 | * remote root. If this object is not persistent, then backward | |
494 | * traversals of the mount point (i.e. "..") will not work if | |
495 | * the nfsnode gets flushed out of the cache. Ufs does not have | |
496 | * this problem, because one can identify root inodes by their | |
497 | * number == ROOTINO (2). | |
498 | */ | |
499 | if (error = nfs_nget(mp, &nmp->nm_fh, &np)) | |
500 | goto bad; | |
1c89915d | 501 | *vpp = NFSTOV(np); |
efaa4294 | 502 | |
f0f1cbaa | 503 | return (0); |
a2907882 | 504 | bad: |
98fb8dd3 | 505 | nfs_disconnect(nmp); |
2c5b44a2 | 506 | free((caddr_t)nmp, M_NFSMNT); |
f0f1cbaa | 507 | m_freem(nam); |
a2907882 KM |
508 | return (error); |
509 | } | |
510 | ||
511 | /* | |
512 | * unmount system call | |
513 | */ | |
c465e0e7 | 514 | int |
4ebfcce2 | 515 | nfs_unmount(mp, mntflags, p) |
a2907882 | 516 | struct mount *mp; |
56cf2c46 | 517 | int mntflags; |
4ebfcce2 | 518 | struct proc *p; |
a2907882 KM |
519 | { |
520 | register struct nfsmount *nmp; | |
9fa46e39 | 521 | struct nfsnode *np; |
98fb8dd3 | 522 | struct vnode *vp; |
6556ebbd KM |
523 | int error, flags = 0; |
524 | extern int doforce; | |
a2907882 | 525 | |
87be6db2 | 526 | if (mntflags & MNT_FORCE) { |
6556ebbd | 527 | if (!doforce || mp == rootfs) |
87be6db2 | 528 | return (EINVAL); |
56cf2c46 | 529 | flags |= FORCECLOSE; |
87be6db2 | 530 | } |
54fb9dc2 | 531 | nmp = VFSTONFS(mp); |
a2907882 KM |
532 | /* |
533 | * Goes something like this.. | |
98fb8dd3 KM |
534 | * - Check for activity on the root vnode (other than ourselves). |
535 | * - Call vflush() to clear out vnodes for this file system, | |
536 | * except for the root vnode. | |
537 | * - Decrement reference on the vnode representing remote root. | |
a2907882 KM |
538 | * - Close the socket |
539 | * - Free up the data structures | |
540 | */ | |
9fa46e39 KM |
541 | /* |
542 | * We need to decrement the ref. count on the nfsnode representing | |
543 | * the remote root. See comment in mountnfs(). The VFS unmount() | |
544 | * has done vput on this vnode, otherwise we would get deadlock! | |
545 | */ | |
546 | if (error = nfs_nget(mp, &nmp->nm_fh, &np)) | |
547 | return(error); | |
98fb8dd3 KM |
548 | vp = NFSTOV(np); |
549 | if (vp->v_usecount > 2) { | |
550 | vput(vp); | |
551 | return (EBUSY); | |
552 | } | |
2c5b44a2 KM |
553 | |
554 | /* | |
555 | * Must handshake with nqnfs_clientd() if it is active. | |
556 | */ | |
557 | nmp->nm_flag |= NFSMNT_DISMINPROG; | |
558 | while (nmp->nm_inprog != NULLVP) | |
559 | (void) tsleep((caddr_t)&lbolt, PSOCK, "nfsdism", 0); | |
98fb8dd3 KM |
560 | if (error = vflush(mp, vp, flags)) { |
561 | vput(vp); | |
2c5b44a2 | 562 | nmp->nm_flag &= ~NFSMNT_DISMINPROG; |
a2907882 | 563 | return (error); |
98fb8dd3 | 564 | } |
2c5b44a2 KM |
565 | |
566 | /* | |
567 | * We are now committed to the unmount. | |
568 | * For NQNFS, let the server daemon free the nfsmount structure. | |
569 | */ | |
570 | if (nmp->nm_flag & (NFSMNT_NQNFS | NFSMNT_KERB)) | |
571 | nmp->nm_flag |= NFSMNT_DISMNT; | |
572 | ||
a2907882 | 573 | /* |
2c5b44a2 | 574 | * There are two reference counts to get rid of here. |
a2907882 | 575 | */ |
98fb8dd3 | 576 | vrele(vp); |
2c5b44a2 | 577 | vrele(vp); |
8473f8d7 | 578 | vgone(vp); |
98fb8dd3 | 579 | nfs_disconnect(nmp); |
f0f1cbaa | 580 | m_freem(nmp->nm_nam); |
2c5b44a2 KM |
581 | |
582 | if ((nmp->nm_flag & (NFSMNT_NQNFS | NFSMNT_KERB)) == 0) | |
583 | free((caddr_t)nmp, M_NFSMNT); | |
a2907882 KM |
584 | return (0); |
585 | } | |
586 | ||
587 | /* | |
588 | * Return root of a filesystem | |
589 | */ | |
c465e0e7 | 590 | int |
a2907882 KM |
591 | nfs_root(mp, vpp) |
592 | struct mount *mp; | |
593 | struct vnode **vpp; | |
594 | { | |
595 | register struct vnode *vp; | |
596 | struct nfsmount *nmp; | |
597 | struct nfsnode *np; | |
598 | int error; | |
599 | ||
54fb9dc2 | 600 | nmp = VFSTONFS(mp); |
a2907882 KM |
601 | if (error = nfs_nget(mp, &nmp->nm_fh, &np)) |
602 | return (error); | |
603 | vp = NFSTOV(np); | |
604 | vp->v_type = VDIR; | |
605 | vp->v_flag = VROOT; | |
606 | *vpp = vp; | |
607 | return (0); | |
608 | } | |
609 | ||
9238aa59 RM |
610 | extern int syncprt; |
611 | ||
a2907882 | 612 | /* |
9238aa59 | 613 | * Flush out the buffer cache |
a2907882 | 614 | */ |
0bd503ad | 615 | /* ARGSUSED */ |
c465e0e7 | 616 | int |
050651c3 | 617 | nfs_sync(mp, waitfor, cred, p) |
a2907882 KM |
618 | struct mount *mp; |
619 | int waitfor; | |
050651c3 KM |
620 | struct ucred *cred; |
621 | struct proc *p; | |
a2907882 | 622 | { |
050651c3 KM |
623 | register struct vnode *vp; |
624 | int error, allerror = 0; | |
625 | ||
9238aa59 RM |
626 | /* |
627 | * Force stale buffer cache information to be flushed. | |
628 | */ | |
050651c3 KM |
629 | loop: |
630 | for (vp = mp->mnt_mounth; vp; vp = vp->v_mountf) { | |
631 | /* | |
632 | * If the vnode that we are about to sync is no longer | |
633 | * associated with this mount point, start over. | |
634 | */ | |
635 | if (vp->v_mount != mp) | |
636 | goto loop; | |
bd60d0f0 | 637 | if (VOP_ISLOCKED(vp) || vp->v_dirtyblkhd.le_next == NULL) |
050651c3 KM |
638 | continue; |
639 | if (vget(vp)) | |
640 | goto loop; | |
641 | if (error = VOP_FSYNC(vp, cred, waitfor, p)) | |
642 | allerror = error; | |
643 | vput(vp); | |
644 | } | |
645 | return (allerror); | |
a2907882 KM |
646 | } |
647 | ||
2cd82738 KM |
648 | /* |
649 | * NFS flat namespace lookup. | |
650 | * Currently unsupported. | |
651 | */ | |
652 | /* ARGSUSED */ | |
653 | int | |
654 | nfs_vget(mp, ino, vpp) | |
655 | struct mount *mp; | |
656 | ino_t ino; | |
657 | struct vnode **vpp; | |
658 | { | |
659 | ||
660 | return (EOPNOTSUPP); | |
661 | } | |
662 | ||
a2907882 KM |
663 | /* |
664 | * At this point, this should never happen | |
665 | */ | |
0bd503ad | 666 | /* ARGSUSED */ |
c465e0e7 | 667 | int |
9580c523 KM |
668 | nfs_fhtovp(mp, fhp, nam, vpp, exflagsp, credanonp) |
669 | register struct mount *mp; | |
a2907882 | 670 | struct fid *fhp; |
9580c523 | 671 | struct mbuf *nam; |
a2907882 | 672 | struct vnode **vpp; |
9580c523 KM |
673 | int *exflagsp; |
674 | struct ucred **credanonp; | |
a2907882 | 675 | { |
0bd503ad | 676 | |
a2907882 KM |
677 | return (EINVAL); |
678 | } | |
679 | ||
680 | /* | |
681 | * Vnode pointer to File handle, should never happen either | |
682 | */ | |
0bd503ad | 683 | /* ARGSUSED */ |
c465e0e7 | 684 | int |
4ebfcce2 KM |
685 | nfs_vptofh(vp, fhp) |
686 | struct vnode *vp; | |
a2907882 | 687 | struct fid *fhp; |
a2907882 | 688 | { |
0bd503ad | 689 | |
a2907882 KM |
690 | return (EINVAL); |
691 | } | |
9238aa59 RM |
692 | |
693 | /* | |
694 | * Vfs start routine, a no-op. | |
695 | */ | |
0bd503ad | 696 | /* ARGSUSED */ |
c465e0e7 | 697 | int |
4ebfcce2 | 698 | nfs_start(mp, flags, p) |
9238aa59 RM |
699 | struct mount *mp; |
700 | int flags; | |
4ebfcce2 | 701 | struct proc *p; |
9238aa59 | 702 | { |
0bd503ad | 703 | |
9238aa59 RM |
704 | return (0); |
705 | } | |
56cf2c46 KM |
706 | |
707 | /* | |
708 | * Do operations associated with quotas, not supported | |
709 | */ | |
e0f6df7b | 710 | /* ARGSUSED */ |
c465e0e7 | 711 | int |
4ebfcce2 | 712 | nfs_quotactl(mp, cmd, uid, arg, p) |
56cf2c46 KM |
713 | struct mount *mp; |
714 | int cmd; | |
050651c3 | 715 | uid_t uid; |
56cf2c46 | 716 | caddr_t arg; |
4ebfcce2 | 717 | struct proc *p; |
56cf2c46 | 718 | { |
e0f6df7b | 719 | |
56cf2c46 KM |
720 | return (EOPNOTSUPP); |
721 | } |