nfs_vfsops.c revision 1.38 1 /* $NetBSD: nfs_vfsops.c,v 1.38 1995/08/13 00:00:08 mycroft Exp $ */
2
3 /*
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Rick Macklem at The University of Guelph.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)nfs_vfsops.c 8.3 (Berkeley) 1/4/94
39 */
40
41 #include <sys/param.h>
42 #include <sys/conf.h>
43 #include <sys/ioctl.h>
44 #include <sys/signal.h>
45 #include <sys/proc.h>
46 #include <sys/namei.h>
47 #include <sys/vnode.h>
48 #include <sys/kernel.h>
49 #include <sys/mount.h>
50 #include <sys/buf.h>
51 #include <sys/mbuf.h>
52 #include <sys/socket.h>
53 #include <sys/systm.h>
54
55 #include <net/if.h>
56 #include <net/route.h>
57 #include <netinet/in.h>
58
59 #include <nfs/rpcv2.h>
60 #include <nfs/nfsv2.h>
61 #include <nfs/nfsnode.h>
62 #include <nfs/nfsmount.h>
63 #include <nfs/nfs.h>
64 #include <nfs/xdr_subs.h>
65 #include <nfs/nfsm_subs.h>
66 #include <nfs/nfsdiskless.h>
67 #include <nfs/nqnfs.h>
68
69 /*
70 * nfs vfs operations.
71 */
72 struct vfsops nfs_vfsops = {
73 MOUNT_NFS,
74 nfs_mount,
75 nfs_start,
76 nfs_unmount,
77 nfs_root,
78 nfs_quotactl,
79 nfs_statfs,
80 nfs_sync,
81 nfs_vget,
82 nfs_fhtovp,
83 nfs_vptofh,
84 nfs_init,
85 };
86
87 extern u_long nfs_procids[NFS_NPROCS];
88 extern u_long nfs_prog, nfs_vers;
89 void nfs_disconnect __P((struct nfsmount *));
90
91 static struct mount *
92 nfs_mount_diskless __P((struct nfs_dlmount *, char *, int, struct vnode **));
93
94 #define TRUE 1
95 #define FALSE 0
96
97 /*
98 * nfs statfs call
99 */
100 int
101 nfs_statfs(mp, sbp, p)
102 struct mount *mp;
103 register struct statfs *sbp;
104 struct proc *p;
105 {
106 register struct vnode *vp;
107 register struct nfsv2_statfs *sfp;
108 register caddr_t cp;
109 register long t1;
110 caddr_t bpos, dpos, cp2;
111 int error = 0, isnq;
112 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
113 struct nfsmount *nmp;
114 struct ucred *cred;
115 struct nfsnode *np;
116
117 nmp = VFSTONFS(mp);
118 isnq = (nmp->nm_flag & NFSMNT_NQNFS);
119 if (error = nfs_nget(mp, &nmp->nm_fh, &np))
120 return (error);
121 vp = NFSTOV(np);
122 nfsstats.rpccnt[NFSPROC_STATFS]++;
123 cred = crget();
124 cred->cr_ngroups = 0;
125 nfsm_reqhead(vp, NFSPROC_STATFS, NFSX_FH);
126 nfsm_fhtom(vp);
127 nfsm_request(vp, NFSPROC_STATFS, p, cred);
128 nfsm_dissect(sfp, struct nfsv2_statfs *, NFSX_STATFS(isnq));
129 #ifdef COMPAT_09
130 sbp->f_type = 2;
131 #else
132 sbp->f_type = 0;
133 #endif
134 sbp->f_flags = nmp->nm_flag;
135 sbp->f_iosize = NFS_MAXDGRAMDATA;
136 sbp->f_bsize = fxdr_unsigned(long, sfp->sf_bsize);
137 sbp->f_blocks = fxdr_unsigned(long, sfp->sf_blocks);
138 sbp->f_bfree = fxdr_unsigned(long, sfp->sf_bfree);
139 sbp->f_bavail = fxdr_unsigned(long, sfp->sf_bavail);
140 if (isnq) {
141 sbp->f_files = fxdr_unsigned(long, sfp->sf_files);
142 sbp->f_ffree = fxdr_unsigned(long, sfp->sf_ffree);
143 } else {
144 sbp->f_files = 0;
145 sbp->f_ffree = 0;
146 }
147 if (sbp != &mp->mnt_stat) {
148 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
149 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
150 }
151 strncpy(&sbp->f_fstypename[0], mp->mnt_op->vfs_name, MFSNAMELEN);
152 nfsm_reqdone;
153 vrele(vp);
154 crfree(cred);
155 return (error);
156 }
157
158 /*
159 * Mount a remote root fs via. NFS. It goes like this:
160 * - Call nfs_boot_init() to fill in the nfs_diskless struct
161 * (using RARP, bootparam RPC, mountd RPC)
162 * - hand craft the swap nfs vnode hanging off a fake mount point
163 * if swdevt[0].sw_dev == NODEV
164 * - build the rootfs mount point and call mountnfs() to do the rest.
165 */
166 int
167 nfs_mountroot()
168 {
169 struct nfs_diskless nd;
170 struct vattr attr;
171 struct mount *mp;
172 struct vnode *vp;
173 struct proc *procp;
174 struct ucred *cred;
175 long n;
176 int error;
177
178 procp = curproc; /* XXX */
179
180 /*
181 * XXX time must be non-zero when we init the interface or else
182 * the arp code will wedge. [Fixed now in if_ether.c]
183 * However, the NFS attribute cache gives false "hits" when
184 * time.tv_sec < NFS_ATTRTIMEO(np) so keep this in for now.
185 */
186 if (time.tv_sec < NFS_MAXATTRTIMO)
187 time.tv_sec = NFS_MAXATTRTIMO;
188
189 /*
190 * Call nfs_boot_init() to fill in the nfs_diskless struct.
191 * Side effect: Finds and configures a network interface.
192 */
193 bzero((caddr_t) &nd, sizeof(nd));
194 nfs_boot_init(&nd, procp);
195
196 /*
197 * Create the root mount point.
198 */
199 mp = nfs_mount_diskless(&nd.nd_root, "/", 0, &vp);
200 printf("root on %s\n", &nd.nd_root.ndm_host);
201
202 /*
203 * Link it into the mount list.
204 */
205 if (vfs_lock(mp))
206 panic("nfs_mountroot: vfs_lock");
207 CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
208 mp->mnt_vnodecovered = NULLVP;
209 vfs_unlock(mp);
210 rootvp = vp;
211
212 /* Get root attributes (for the time). */
213 error = VOP_GETATTR(vp, &attr, procp->p_ucred, procp);
214 if (error) panic("nfs_mountroot: getattr for root");
215 n = attr.va_mtime.ts_sec;
216 #ifdef DEBUG
217 printf("root time: 0x%x\n", n);
218 #endif
219 inittodr(n);
220
221 #ifdef notyet
222 /* Set up swap credentials. */
223 proc0.p_ucred->cr_uid = ntohl(nd.swap_ucred.cr_uid);
224 proc0.p_ucred->cr_gid = ntohl(nd.swap_ucred.cr_gid);
225 if ((proc0.p_ucred->cr_ngroups = ntohs(nd.swap_ucred.cr_ngroups)) >
226 NGROUPS)
227 proc0.p_ucred->cr_ngroups = NGROUPS;
228 for (i = 0; i < proc0.p_ucred->cr_ngroups; i++)
229 proc0.p_ucred->cr_groups[i] = ntohl(nd.swap_ucred.cr_groups[i]);
230 #endif
231
232 /*
233 * "Mount" the swap device.
234 *
235 * On a "dataless" configuration (swap on disk) we will have:
236 * (swdevt[0].sw_dev != NODEV) identifying the swap device.
237 */
238 if (bdevvp(swapdev, &swapdev_vp))
239 panic("nfs_mountroot: can't setup swap vp");
240 if (swdevt[0].sw_dev != NODEV) {
241 printf("swap on device 0x%x\n", swdevt[0].sw_dev);
242 return (0);
243 }
244
245 /*
246 * If swapping to an nfs node: (swdevt[0].sw_dev == NODEV)
247 * Create a fake mount point just for the swap vnode so that the
248 * swap file can be on a different server from the rootfs.
249 */
250 mp = nfs_mount_diskless(&nd.nd_swap, "/swap", 0, &vp);
251 printf("swap on %s\n", &nd.nd_swap.ndm_host);
252
253 /*
254 * Since the swap file is not the root dir of a file system,
255 * hack it to a regular file.
256 */
257 vp->v_type = VREG;
258 vp->v_flag = 0;
259 swdevt[0].sw_vp = vp;
260
261 /*
262 * Find out how large the swap file is.
263 */
264 error = VOP_GETATTR(vp, &attr, procp->p_ucred, procp);
265 if (error)
266 panic("nfs_mountroot: getattr for swap");
267 n = (long) (attr.va_size >> DEV_BSHIFT);
268 #ifdef DEBUG
269 printf("swap size: 0x%x (blocks)\n", n);
270 #endif
271 swdevt[0].sw_nblks = n;
272
273 return (0);
274 }
275
276 /*
277 * Internal version of mount system call for diskless setup.
278 */
279 static struct mount *
280 nfs_mount_diskless(ndmntp, mntname, mntflag, vpp)
281 struct nfs_dlmount *ndmntp;
282 char *mntname;
283 int mntflag;
284 struct vnode **vpp;
285 {
286 struct nfs_args args;
287 struct mount *mp;
288 struct mbuf *m;
289 int error;
290
291 /* Create the mount point. */
292 mp = (struct mount *)malloc((u_long)sizeof(struct mount),
293 M_MOUNT, M_NOWAIT);
294 if (mp == NULL)
295 panic("nfs_mountroot: malloc mount for %s", mntname);
296 bzero((char *)mp, (u_long)sizeof(struct mount));
297 mp->mnt_op = &nfs_vfsops;
298 mp->mnt_flag = mntflag;
299
300 /* Initialize mount args. */
301 bzero((caddr_t) &args, sizeof(args));
302 args.addr = (struct sockaddr *)&ndmntp->ndm_saddr;
303 args.addrlen = args.addr->sa_len;
304 args.sotype = SOCK_DGRAM;
305 args.fh = (nfsv2fh_t *)ndmntp->ndm_fh;
306 args.hostname = ndmntp->ndm_host;
307 args.flags = NFSMNT_RESVPORT;
308
309 #ifdef NFS_BOOT_OPTIONS
310 args.flags |= NFS_BOOT_OPTIONS;
311 #endif
312 #ifdef NFS_BOOT_RWSIZE
313 /*
314 * Reduce rsize,wsize for interfaces that consistently
315 * drop fragments of long UDP messages. (i.e. wd8003).
316 * You can always change these later via remount.
317 */
318 args.flags |= NFSMNT_WSIZE | NFSMNT_RSIZE;
319 args.wsize = NFS_BOOT_RWSIZE;
320 args.rsize = NFS_BOOT_RWSIZE;
321 #endif
322
323 /* Get mbuf for server sockaddr. */
324 m = m_get(M_WAIT, MT_SONAME);
325 if (m == NULL)
326 panic("nfs_mountroot: mget soname for %s", mntname);
327 bcopy((caddr_t)args.addr, mtod(m, caddr_t),
328 (m->m_len = args.addr->sa_len));
329
330 if (error = mountnfs(&args, mp, m, mntname, args.hostname, vpp))
331 panic("nfs_mountroot: mount %s failed: %d", mntname);
332
333 return (mp);
334 }
335
336 void
337 nfs_decode_args(nmp, argp)
338 struct nfsmount *nmp;
339 struct nfs_args *argp;
340 {
341 int s;
342 int adjsock;
343
344 s = splsoftnet();
345
346 /* Re-bind if rsrvd port requested and wasn't on one */
347 adjsock = !(nmp->nm_flag & NFSMNT_RESVPORT)
348 && (argp->flags & NFSMNT_RESVPORT);
349
350 /* Update flags atomically. Don't change the lock bits. */
351 nmp->nm_flag =
352 (argp->flags & ~NFSMNT_INTERNAL) | (nmp->nm_flag & NFSMNT_INTERNAL);
353 splx(s);
354
355 if ((argp->flags & NFSMNT_TIMEO) && argp->timeo > 0) {
356 nmp->nm_timeo = (argp->timeo * NFS_HZ + 5) / 10;
357 if (nmp->nm_timeo < NFS_MINTIMEO)
358 nmp->nm_timeo = NFS_MINTIMEO;
359 else if (nmp->nm_timeo > NFS_MAXTIMEO)
360 nmp->nm_timeo = NFS_MAXTIMEO;
361 }
362
363 if ((argp->flags & NFSMNT_RETRANS) && argp->retrans > 1) {
364 nmp->nm_retry = argp->retrans;
365 if (nmp->nm_retry > NFS_MAXREXMIT)
366 nmp->nm_retry = NFS_MAXREXMIT;
367 }
368
369 if ((argp->flags & NFSMNT_WSIZE) && argp->wsize > 0) {
370 int osize = nmp->nm_wsize;
371 nmp->nm_wsize = argp->wsize;
372 /* Round down to multiple of blocksize */
373 nmp->nm_wsize &= ~0x1ff;
374 if (nmp->nm_wsize <= 0)
375 nmp->nm_wsize = 512;
376 else if (nmp->nm_wsize > NFS_MAXDATA)
377 nmp->nm_wsize = NFS_MAXDATA;
378 adjsock |= (nmp->nm_wsize != osize);
379 }
380 if (nmp->nm_wsize > MAXBSIZE)
381 nmp->nm_wsize = MAXBSIZE;
382
383 if ((argp->flags & NFSMNT_RSIZE) && argp->rsize > 0) {
384 int osize = nmp->nm_rsize;
385 nmp->nm_rsize = argp->rsize;
386 /* Round down to multiple of blocksize */
387 nmp->nm_rsize &= ~0x1ff;
388 if (nmp->nm_rsize <= 0)
389 nmp->nm_rsize = 512;
390 else if (nmp->nm_rsize > NFS_MAXDATA)
391 nmp->nm_rsize = NFS_MAXDATA;
392 adjsock |= (nmp->nm_rsize != osize);
393 }
394 if (nmp->nm_rsize > MAXBSIZE)
395 nmp->nm_rsize = MAXBSIZE;
396
397 if ((argp->flags & NFSMNT_MAXGRPS) && argp->maxgrouplist >= 0 &&
398 argp->maxgrouplist <= NFS_MAXGRPS)
399 nmp->nm_numgrps = argp->maxgrouplist;
400 if ((argp->flags & NFSMNT_READAHEAD) && argp->readahead >= 0 &&
401 argp->readahead <= NFS_MAXRAHEAD)
402 nmp->nm_readahead = argp->readahead;
403 if ((argp->flags & NFSMNT_LEASETERM) && argp->leaseterm >= 2 &&
404 argp->leaseterm <= NQ_MAXLEASE)
405 nmp->nm_leaseterm = argp->leaseterm;
406 if ((argp->flags & NFSMNT_DEADTHRESH) && argp->deadthresh >= 1 &&
407 argp->deadthresh <= NQ_NEVERDEAD)
408 nmp->nm_deadthresh = argp->deadthresh;
409
410 if (nmp->nm_so && adjsock) {
411 nfs_disconnect(nmp);
412 if (nmp->nm_sotype == SOCK_DGRAM)
413 while (nfs_connect(nmp, (struct nfsreq *)0)) {
414 printf("nfs_args: retrying connect\n");
415 (void) tsleep((caddr_t)&lbolt,
416 PSOCK, "nfscon", 0);
417 }
418 }
419 }
420
421 /*
422 * VFS Operations.
423 *
424 * mount system call
425 * It seems a bit dumb to copyinstr() the host and path here and then
426 * bcopy() them in mountnfs(), but I wanted to detect errors before
427 * doing the sockargs() call because sockargs() allocates an mbuf and
428 * an error after that means that I have to release the mbuf.
429 */
430 /* ARGSUSED */
431 int
432 nfs_mount(mp, path, data, ndp, p)
433 struct mount *mp;
434 char *path;
435 caddr_t data;
436 struct nameidata *ndp;
437 struct proc *p;
438 {
439 int error;
440 struct nfs_args args;
441 struct mbuf *nam;
442 struct vnode *vp;
443 char pth[MNAMELEN], hst[MNAMELEN];
444 size_t len;
445 nfsv2fh_t nfh;
446
447 if (error = copyin(data, (caddr_t)&args, sizeof (struct nfs_args)))
448 return (error);
449 if (mp->mnt_flag & MNT_UPDATE) {
450 register struct nfsmount *nmp = VFSTONFS(mp);
451
452 if (nmp == NULL)
453 return (EIO);
454 nfs_decode_args(nmp, &args);
455 return (0);
456 }
457 if (error = copyin((caddr_t)args.fh, (caddr_t)&nfh, sizeof (nfsv2fh_t)))
458 return (error);
459 if (error = copyinstr(path, pth, MNAMELEN-1, &len))
460 return (error);
461 bzero(&pth[len], MNAMELEN - len);
462 if (error = copyinstr(args.hostname, hst, MNAMELEN-1, &len))
463 return (error);
464 bzero(&hst[len], MNAMELEN - len);
465 /* sockargs() call must be after above copyin() calls */
466 if (error = sockargs(&nam, (caddr_t)args.addr,
467 args.addrlen, MT_SONAME))
468 return (error);
469 args.fh = &nfh;
470 error = mountnfs(&args, mp, nam, pth, hst, &vp);
471 return (error);
472 }
473
474 /*
475 * Common code for mount and mountroot
476 */
477 int
478 mountnfs(argp, mp, nam, pth, hst, vpp)
479 register struct nfs_args *argp;
480 register struct mount *mp;
481 struct mbuf *nam;
482 char *pth, *hst;
483 struct vnode **vpp;
484 {
485 register struct nfsmount *nmp;
486 struct nfsnode *np;
487 int error;
488
489 if (mp->mnt_flag & MNT_UPDATE) {
490 nmp = VFSTONFS(mp);
491 /* update paths, file handles, etc, here XXX */
492 m_freem(nam);
493 return (0);
494 } else {
495 MALLOC(nmp, struct nfsmount *, sizeof (struct nfsmount),
496 M_NFSMNT, M_WAITOK);
497 bzero((caddr_t)nmp, sizeof (struct nfsmount));
498 mp->mnt_data = (qaddr_t)nmp;
499 }
500 getnewfsid(mp, makefstype(MOUNT_NFS));
501 nmp->nm_mountp = mp;
502 if ((argp->flags & (NFSMNT_NQNFS | NFSMNT_MYWRITE)) ==
503 (NFSMNT_NQNFS | NFSMNT_MYWRITE)) {
504 error = EPERM;
505 goto bad;
506 }
507 if (argp->flags & NFSMNT_NQNFS)
508 /*
509 * We have to set mnt_maxsymlink to a non-zero value so
510 * that COMPAT_43 routines will know that we are setting
511 * the d_type field in directories (and can zero it for
512 * unsuspecting binaries).
513 */
514 mp->mnt_maxsymlinklen = 1;
515 nmp->nm_timeo = NFS_TIMEO;
516 nmp->nm_retry = NFS_RETRANS;
517 nmp->nm_wsize = NFS_WSIZE;
518 nmp->nm_rsize = NFS_RSIZE;
519 nmp->nm_numgrps = NFS_MAXGRPS;
520 nmp->nm_readahead = NFS_DEFRAHEAD;
521 nmp->nm_leaseterm = NQ_DEFLEASE;
522 nmp->nm_deadthresh = NQ_DEADTHRESH;
523 CIRCLEQ_INIT(&nmp->nm_timerhead);
524 nmp->nm_inprog = NULLVP;
525 bcopy((caddr_t)argp->fh, (caddr_t)&nmp->nm_fh, sizeof(nfsv2fh_t));
526 #ifdef COMPAT_09
527 mp->mnt_stat.f_type = 2;
528 #else
529 mp->mnt_stat.f_type = 0;
530 #endif
531 strncpy(&mp->mnt_stat.f_fstypename[0], mp->mnt_op->vfs_name, MFSNAMELEN);
532 bcopy(hst, mp->mnt_stat.f_mntfromname, MNAMELEN);
533 bcopy(pth, mp->mnt_stat.f_mntonname, MNAMELEN);
534 nmp->nm_nam = nam;
535 nfs_decode_args(nmp, argp);
536
537 /* Set up the sockets and per-host congestion */
538 nmp->nm_sotype = argp->sotype;
539 nmp->nm_soproto = argp->proto;
540
541 /*
542 * For Connection based sockets (TCP,...) defer the connect until
543 * the first request, in case the server is not responding.
544 */
545 if (nmp->nm_sotype == SOCK_DGRAM &&
546 (error = nfs_connect(nmp, (struct nfsreq *)0)))
547 goto bad;
548
549 /*
550 * This is silly, but it has to be set so that vinifod() works.
551 * We do not want to do an nfs_statfs() here since we can get
552 * stuck on a dead server and we are holding a lock on the mount
553 * point.
554 */
555 mp->mnt_stat.f_iosize = NFS_MAXDGRAMDATA;
556 /*
557 * A reference count is needed on the nfsnode representing the
558 * remote root. If this object is not persistent, then backward
559 * traversals of the mount point (i.e. "..") will not work if
560 * the nfsnode gets flushed out of the cache. Ufs does not have
561 * this problem, because one can identify root inodes by their
562 * number == ROOTINO (2).
563 */
564 if (error = nfs_nget(mp, &nmp->nm_fh, &np))
565 goto bad;
566 *vpp = NFSTOV(np);
567
568 return (0);
569 bad:
570 nfs_disconnect(nmp);
571 free((caddr_t)nmp, M_NFSMNT);
572 m_freem(nam);
573 return (error);
574 }
575
576 /*
577 * unmount system call
578 */
579 int
580 nfs_unmount(mp, mntflags, p)
581 struct mount *mp;
582 int mntflags;
583 struct proc *p;
584 {
585 register struct nfsmount *nmp;
586 struct nfsnode *np;
587 struct vnode *vp;
588 int error, flags = 0;
589 extern int doforce;
590
591 if (mntflags & MNT_FORCE)
592 flags |= FORCECLOSE;
593 nmp = VFSTONFS(mp);
594 /*
595 * Goes something like this..
596 * - Check for activity on the root vnode (other than ourselves).
597 * - Call vflush() to clear out vnodes for this file system,
598 * except for the root vnode.
599 * - Decrement reference on the vnode representing remote root.
600 * - Close the socket
601 * - Free up the data structures
602 */
603 /*
604 * We need to decrement the ref. count on the nfsnode representing
605 * the remote root. See comment in mountnfs(). The VFS unmount()
606 * has done vput on this vnode, otherwise we would get deadlock!
607 */
608 if (error = nfs_nget(mp, &nmp->nm_fh, &np))
609 return(error);
610 vp = NFSTOV(np);
611 if (vp->v_usecount > 2) {
612 vput(vp);
613 return (EBUSY);
614 }
615
616 /*
617 * Must handshake with nqnfs_clientd() if it is active.
618 */
619 nmp->nm_flag |= NFSMNT_DISMINPROG;
620 while (nmp->nm_inprog != NULLVP)
621 (void) tsleep((caddr_t)&lbolt, PSOCK, "nfsdism", 0);
622 if (error = vflush(mp, vp, flags)) {
623 vput(vp);
624 nmp->nm_flag &= ~NFSMNT_DISMINPROG;
625 return (error);
626 }
627
628 /*
629 * We are now committed to the unmount.
630 * For NQNFS, let the server daemon free the nfsmount structure.
631 */
632 if (nmp->nm_flag & (NFSMNT_NQNFS | NFSMNT_KERB))
633 nmp->nm_flag |= NFSMNT_DISMNT;
634
635 /*
636 * There are two reference counts to get rid of here.
637 */
638 vrele(vp);
639 vrele(vp);
640 vgone(vp);
641 nfs_disconnect(nmp);
642 m_freem(nmp->nm_nam);
643
644 if ((nmp->nm_flag & (NFSMNT_NQNFS | NFSMNT_KERB)) == 0)
645 free((caddr_t)nmp, M_NFSMNT);
646 return (0);
647 }
648
649 /*
650 * Return root of a filesystem
651 */
652 int
653 nfs_root(mp, vpp)
654 struct mount *mp;
655 struct vnode **vpp;
656 {
657 register struct vnode *vp;
658 struct nfsmount *nmp;
659 struct nfsnode *np;
660 int error;
661
662 nmp = VFSTONFS(mp);
663 if (error = nfs_nget(mp, &nmp->nm_fh, &np))
664 return (error);
665 vp = NFSTOV(np);
666 vp->v_type = VDIR;
667 vp->v_flag = VROOT;
668 *vpp = vp;
669 return (0);
670 }
671
672 extern int syncprt;
673
674 /*
675 * Flush out the buffer cache
676 */
677 /* ARGSUSED */
678 int
679 nfs_sync(mp, waitfor, cred, p)
680 struct mount *mp;
681 int waitfor;
682 struct ucred *cred;
683 struct proc *p;
684 {
685 register struct vnode *vp;
686 int error, allerror = 0;
687
688 /*
689 * Force stale buffer cache information to be flushed.
690 */
691 loop:
692 for (vp = mp->mnt_vnodelist.lh_first;
693 vp != NULL;
694 vp = vp->v_mntvnodes.le_next) {
695 /*
696 * If the vnode that we are about to sync is no longer
697 * associated with this mount point, start over.
698 */
699 if (vp->v_mount != mp)
700 goto loop;
701 if (VOP_ISLOCKED(vp) || vp->v_dirtyblkhd.lh_first == NULL)
702 continue;
703 if (vget(vp, 1))
704 goto loop;
705 if (error = VOP_FSYNC(vp, cred, waitfor, p))
706 allerror = error;
707 vput(vp);
708 }
709 return (allerror);
710 }
711
712 /*
713 * NFS flat namespace lookup.
714 * Currently unsupported.
715 */
716 /* ARGSUSED */
717 int
718 nfs_vget(mp, ino, vpp)
719 struct mount *mp;
720 ino_t ino;
721 struct vnode **vpp;
722 {
723
724 return (EOPNOTSUPP);
725 }
726
727 /*
728 * At this point, this should never happen
729 */
730 /* ARGSUSED */
731 int
732 nfs_fhtovp(mp, fhp, nam, vpp, exflagsp, credanonp)
733 register struct mount *mp;
734 struct fid *fhp;
735 struct mbuf *nam;
736 struct vnode **vpp;
737 int *exflagsp;
738 struct ucred **credanonp;
739 {
740
741 return (EINVAL);
742 }
743
744 /*
745 * Vnode pointer to File handle, should never happen either
746 */
747 /* ARGSUSED */
748 int
749 nfs_vptofh(vp, fhp)
750 struct vnode *vp;
751 struct fid *fhp;
752 {
753
754 return (EINVAL);
755 }
756
757 /*
758 * Vfs start routine, a no-op.
759 */
760 /* ARGSUSED */
761 int
762 nfs_start(mp, flags, p)
763 struct mount *mp;
764 int flags;
765 struct proc *p;
766 {
767
768 return (0);
769 }
770
771 /*
772 * Do operations associated with quotas, not supported
773 */
774 /* ARGSUSED */
775 int
776 nfs_quotactl(mp, cmd, uid, arg, p)
777 struct mount *mp;
778 int cmd;
779 uid_t uid;
780 caddr_t arg;
781 struct proc *p;
782 {
783
784 return (EOPNOTSUPP);
785 }
786