2 * Copyright (c) 1989, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * from nfs_vfsops.c 8.12 (Berkeley) 5/20/95
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
39 #include "opt_bootp.h"
40 #include "opt_nfsroot.h"
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/kernel.h>
47 #include <sys/clock.h>
50 #include <sys/malloc.h>
52 #include <sys/module.h>
53 #include <sys/mount.h>
55 #include <sys/socket.h>
56 #include <sys/socketvar.h>
57 #include <sys/sockio.h>
58 #include <sys/sysctl.h>
59 #include <sys/vnode.h>
60 #include <sys/signalvar.h>
63 #include <vm/vm_extern.h>
67 #include <net/route.h>
68 #include <netinet/in.h>
70 #include <fs/nfs/nfsport.h>
71 #include <fs/nfsclient/nfsnode.h>
72 #include <fs/nfsclient/nfsmount.h>
73 #include <fs/nfsclient/nfs.h>
74 #include <fs/nfsclient/nfsdiskless.h>
76 extern int nfscl_ticks;
77 extern struct timeval nfsboottime;
78 extern struct nfsstats newnfsstats;
80 MALLOC_DEFINE(M_NEWNFSREQ, "newnfsclient_req", "New NFS request header");
81 MALLOC_DEFINE(M_NEWNFSMNT, "newnfsmnt", "New NFS mount struct");
83 SYSCTL_DECL(_vfs_newnfs);
84 SYSCTL_STRUCT(_vfs_newnfs, NFS_NFSSTATS, nfsstats, CTLFLAG_RW,
85 &newnfsstats, nfsstats, "S,nfsstats");
86 static int nfs_ip_paranoia = 1;
87 SYSCTL_INT(_vfs_newnfs, OID_AUTO, nfs_ip_paranoia, CTLFLAG_RW,
88 &nfs_ip_paranoia, 0, "");
89 static int nfs_tprintf_initial_delay = NFS_TPRINTF_INITIAL_DELAY;
90 SYSCTL_INT(_vfs_newnfs, NFS_TPRINTF_INITIAL_DELAY,
91 downdelayinitial, CTLFLAG_RW, &nfs_tprintf_initial_delay, 0, "");
92 /* how long between console messages "nfs server foo not responding" */
93 static int nfs_tprintf_delay = NFS_TPRINTF_DELAY;
94 SYSCTL_INT(_vfs_newnfs, NFS_TPRINTF_DELAY,
95 downdelayinterval, CTLFLAG_RW, &nfs_tprintf_delay, 0, "");
97 static void nfs_sec_name(char *, int *);
98 static void nfs_decode_args(struct mount *mp, struct nfsmount *nmp,
99 struct nfs_args *argp, struct ucred *, struct thread *);
100 static int mountnfs(struct nfs_args *, struct mount *,
101 struct sockaddr *, char *, u_char *, u_char *, u_char *,
102 struct vnode **, struct ucred *, struct thread *);
103 static vfs_mount_t nfs_mount;
104 static vfs_cmount_t nfs_cmount;
105 static vfs_unmount_t nfs_unmount;
106 static vfs_root_t nfs_root;
107 static vfs_statfs_t nfs_statfs;
108 static vfs_sync_t nfs_sync;
109 static vfs_sysctl_t nfs_sysctl;
112 * nfs vfs operations.
114 static struct vfsops nfs_vfsops = {
115 .vfs_init = ncl_init,
116 .vfs_mount = nfs_mount,
117 .vfs_cmount = nfs_cmount,
118 .vfs_root = nfs_root,
119 .vfs_statfs = nfs_statfs,
120 .vfs_sync = nfs_sync,
121 .vfs_uninit = ncl_uninit,
122 .vfs_unmount = nfs_unmount,
123 .vfs_sysctl = nfs_sysctl,
125 VFS_SET(nfs_vfsops, newnfs, VFCF_NETWORK);
127 /* So that loader and kldload(2) can find us, wherever we are.. */
128 MODULE_VERSION(newnfs, 1);
131 * This structure must be filled in by a primary bootstrap or bootstrap
132 * server for a diskless/dataless machine. It is initialized below just
133 * to ensure that it is allocated to initialized data (.data not .bss).
135 struct nfs_diskless newnfs_diskless = { { { 0 } } };
136 struct nfsv3_diskless newnfsv3_diskless = { { { 0 } } };
137 int newnfs_diskless_valid = 0;
139 SYSCTL_INT(_vfs_newnfs, OID_AUTO, diskless_valid, CTLFLAG_RD,
140 &newnfs_diskless_valid, 0,
141 "Has the diskless struct been filled correctly");
143 SYSCTL_STRING(_vfs_newnfs, OID_AUTO, diskless_rootpath, CTLFLAG_RD,
144 newnfsv3_diskless.root_hostnam, 0, "Path to nfs root");
146 SYSCTL_OPAQUE(_vfs_newnfs, OID_AUTO, diskless_rootaddr, CTLFLAG_RD,
147 &newnfsv3_diskless.root_saddr, sizeof newnfsv3_diskless.root_saddr,
148 "%Ssockaddr_in", "Diskless root nfs address");
151 void newnfsargs_ntoh(struct nfs_args *);
152 static int nfs_mountdiskless(char *,
153 struct sockaddr_in *, struct nfs_args *,
154 struct thread *, struct vnode **, struct mount *);
155 static void nfs_convert_diskless(void);
156 static void nfs_convert_oargs(struct nfs_args *args,
157 struct onfs_args *oargs);
160 newnfs_iosize(struct nfsmount *nmp)
164 /* First, set the upper limit for iosize */
165 if (nmp->nm_flag & NFSMNT_NFSV4) {
166 maxio = NFS_MAXBSIZE;
167 } else if (nmp->nm_flag & NFSMNT_NFSV3) {
168 if (nmp->nm_sotype == SOCK_DGRAM)
169 maxio = NFS_MAXDGRAMDATA;
171 maxio = NFS_MAXBSIZE;
173 maxio = NFS_V2MAXDATA;
175 if (nmp->nm_rsize > maxio || nmp->nm_rsize == 0)
176 nmp->nm_rsize = maxio;
177 if (nmp->nm_rsize > MAXBSIZE)
178 nmp->nm_rsize = MAXBSIZE;
179 if (nmp->nm_readdirsize > maxio || nmp->nm_readdirsize == 0)
180 nmp->nm_readdirsize = maxio;
181 if (nmp->nm_readdirsize > nmp->nm_rsize)
182 nmp->nm_readdirsize = nmp->nm_rsize;
183 if (nmp->nm_wsize > maxio || nmp->nm_wsize == 0)
184 nmp->nm_wsize = maxio;
185 if (nmp->nm_wsize > MAXBSIZE)
186 nmp->nm_wsize = MAXBSIZE;
189 * Calculate the size used for io buffers. Use the larger
190 * of the two sizes to minimise nfs requests but make sure
191 * that it is at least one VM page to avoid wasting buffer
194 iosize = imax(nmp->nm_rsize, nmp->nm_wsize);
195 iosize = imax(iosize, PAGE_SIZE);
196 nmp->nm_mountp->mnt_stat.f_iosize = iosize;
201 nfs_convert_oargs(struct nfs_args *args, struct onfs_args *oargs)
204 args->version = NFS_ARGSVERSION;
205 args->addr = oargs->addr;
206 args->addrlen = oargs->addrlen;
207 args->sotype = oargs->sotype;
208 args->proto = oargs->proto;
209 args->fh = oargs->fh;
210 args->fhsize = oargs->fhsize;
211 args->flags = oargs->flags;
212 args->wsize = oargs->wsize;
213 args->rsize = oargs->rsize;
214 args->readdirsize = oargs->readdirsize;
215 args->timeo = oargs->timeo;
216 args->retrans = oargs->retrans;
217 args->readahead = oargs->readahead;
218 args->hostname = oargs->hostname;
222 nfs_convert_diskless(void)
225 bcopy(&newnfs_diskless.myif, &newnfsv3_diskless.myif,
226 sizeof (struct ifaliasreq));
227 bcopy(&newnfs_diskless.mygateway, &newnfsv3_diskless.mygateway,
228 sizeof (struct sockaddr_in));
229 nfs_convert_oargs(&newnfsv3_diskless.root_args,
230 &newnfs_diskless.root_args);
231 if (newnfsv3_diskless.root_args.flags & NFSMNT_NFSV3) {
232 newnfsv3_diskless.root_fhsize = NFSX_MYFH;
233 bcopy(newnfs_diskless.root_fh, newnfsv3_diskless.root_fh,
236 newnfsv3_diskless.root_fhsize = NFSX_V2FH;
237 bcopy(newnfs_diskless.root_fh, newnfsv3_diskless.root_fh,
240 bcopy(&newnfs_diskless.root_saddr,&newnfsv3_diskless.root_saddr,
241 sizeof(struct sockaddr_in));
242 bcopy(newnfs_diskless.root_hostnam, newnfsv3_diskless.root_hostnam,
244 newnfsv3_diskless.root_time = newnfs_diskless.root_time;
245 bcopy(newnfs_diskless.my_hostnam, newnfsv3_diskless.my_hostnam,
247 newnfs_diskless_valid = 3;
254 nfs_statfs(struct mount *mp, struct statfs *sbp)
258 struct nfsmount *nmp = VFSTONFS(mp);
259 struct nfsvattr nfsva;
262 int error = 0, attrflag, gotfsinfo = 0, ret;
267 error = vfs_busy(mp, MBF_NOWAIT);
270 error = ncl_nget(mp, nmp->nm_fh, nmp->nm_fhsize, &np);
276 mtx_lock(&nmp->nm_mtx);
277 if (NFSHASNFSV3(nmp) && !NFSHASGOTFSINFO(nmp)) {
278 mtx_unlock(&nmp->nm_mtx);
279 error = nfsrpc_fsinfo(vp, &fs, td->td_ucred, td, &nfsva,
284 mtx_unlock(&nmp->nm_mtx);
286 error = nfsrpc_statfs(vp, &sb, &fs, td->td_ucred, td, &nfsva,
289 ret = nfsrpc_getattrnovp(nmp, nmp->nm_fh, nmp->nm_fhsize, 1,
290 td->td_ucred, td, &nfsva, NULL);
293 * Just set default values to get things going.
295 NFSBZERO((caddr_t)&nfsva, sizeof (struct nfsvattr));
296 nfsva.na_vattr.va_type = VDIR;
297 nfsva.na_vattr.va_mode = 0777;
298 nfsva.na_vattr.va_nlink = 100;
299 nfsva.na_vattr.va_uid = (uid_t)0;
300 nfsva.na_vattr.va_gid = (gid_t)0;
301 nfsva.na_vattr.va_fileid = 2;
302 nfsva.na_vattr.va_gen = 1;
303 nfsva.na_vattr.va_blocksize = NFS_FABLKSIZE;
304 nfsva.na_vattr.va_size = 512 * 1024;
307 (void) nfscl_loadattrcache(&vp, &nfsva, NULL, NULL, 0, 1);
309 mtx_lock(&nmp->nm_mtx);
310 if (gotfsinfo || (nmp->nm_flag & NFSMNT_NFSV4))
311 nfscl_loadfsinfo(nmp, &fs);
312 nfscl_loadsbinfo(nmp, &sb, sbp);
313 sbp->f_flags = nmp->nm_flag;
314 sbp->f_iosize = newnfs_iosize(nmp);
315 mtx_unlock(&nmp->nm_mtx);
316 if (sbp != &mp->mnt_stat) {
317 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
318 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
320 strncpy(&sbp->f_fstypename[0], mp->mnt_vfc->vfc_name, MFSNAMELEN);
321 } else if (NFS_ISV4(vp)) {
322 error = nfscl_maperr(td, error, (uid_t)0, (gid_t)0);
330 * nfs version 3 fsinfo rpc call
333 ncl_fsinfo(struct nfsmount *nmp, struct vnode *vp, struct ucred *cred,
337 struct nfsvattr nfsva;
340 error = nfsrpc_fsinfo(vp, &fs, cred, td, &nfsva, &attrflag, NULL);
343 (void) nfscl_loadattrcache(&vp, &nfsva, NULL, NULL, 0,
345 mtx_lock(&nmp->nm_mtx);
346 nfscl_loadfsinfo(nmp, &fs);
347 mtx_unlock(&nmp->nm_mtx);
353 * Mount a remote root fs via. nfs. This depends on the info in the
354 * newnfs_diskless structure that has been filled in properly by some primary
356 * It goes something like this:
357 * - do enough of "ifconfig" by calling ifioctl() so that the system
358 * can talk to the server
359 * - If newnfs_diskless.mygateway is filled in, use that address as
361 * - build the rootfs mount point and call mountnfs() to do the rest.
363 * It is assumed to be safe to read, modify, and write the nfsv3_diskless
364 * structure, as well as other global NFS client variables here, as
365 * nfs_mountroot() will be called once in the boot before any other NFS
366 * client activity occurs.
369 ncl_mountroot(struct mount *mp)
371 struct thread *td = curthread;
372 struct nfsv3_diskless *nd = &newnfsv3_diskless;
381 #if defined(BOOTP_NFSROOT) && defined(BOOTP)
382 bootpc_init(); /* use bootp to get nfs_diskless filled in */
383 #elif defined(NFS_ROOT)
384 nfs_setup_diskless();
387 if (newnfs_diskless_valid == 0)
389 if (newnfs_diskless_valid == 1)
390 nfs_convert_diskless();
393 * XXX splnet, so networks will receive...
398 * Do enough of ifconfig(8) so that the critical net interface can
399 * talk to the server.
401 error = socreate(nd->myif.ifra_addr.sa_family, &so, nd->root_args.sotype, 0,
404 panic("nfs_mountroot: socreate(%04x): %d",
405 nd->myif.ifra_addr.sa_family, error);
407 #if 0 /* XXX Bad idea */
409 * We might not have been told the right interface, so we pass
410 * over the first ten interfaces of the same kind, until we get
411 * one of them configured.
414 for (i = strlen(nd->myif.ifra_name) - 1;
415 nd->myif.ifra_name[i] >= '0' &&
416 nd->myif.ifra_name[i] <= '9';
417 nd->myif.ifra_name[i] ++) {
418 error = ifioctl(so, SIOCAIFADDR, (caddr_t)&nd->myif, td);
423 error = ifioctl(so, SIOCAIFADDR, (caddr_t)&nd->myif, td);
425 panic("nfs_mountroot: SIOCAIFADDR: %d", error);
426 if ((cp = getenv("boot.netif.mtu")) != NULL) {
427 ir.ifr_mtu = strtol(cp, NULL, 10);
428 bcopy(nd->myif.ifra_name, ir.ifr_name, IFNAMSIZ);
430 error = ifioctl(so, SIOCSIFMTU, (caddr_t)&ir, td);
432 printf("nfs_mountroot: SIOCSIFMTU: %d", error);
437 * If the gateway field is filled in, set it as the default route.
438 * Note that pxeboot will set a default route of 0 if the route
439 * is not set by the DHCP server. Check also for a value of 0
440 * to avoid panicking inappropriately in that situation.
442 if (nd->mygateway.sin_len != 0 &&
443 nd->mygateway.sin_addr.s_addr != 0) {
444 struct sockaddr_in mask, sin;
446 bzero((caddr_t)&mask, sizeof(mask));
448 sin.sin_family = AF_INET;
449 sin.sin_len = sizeof(sin);
450 /* XXX MRT use table 0 for this sort of thing */
451 error = rtrequest(RTM_ADD, (struct sockaddr *)&sin,
452 (struct sockaddr *)&nd->mygateway,
453 (struct sockaddr *)&mask,
454 RTF_UP | RTF_GATEWAY, NULL);
456 panic("nfs_mountroot: RTM_ADD: %d", error);
460 * Create the rootfs mount point.
462 nd->root_args.fh = nd->root_fh;
463 nd->root_args.fhsize = nd->root_fhsize;
464 l = ntohl(nd->root_saddr.sin_addr.s_addr);
465 snprintf(buf, sizeof(buf), "%ld.%ld.%ld.%ld:%s",
466 (l >> 24) & 0xff, (l >> 16) & 0xff,
467 (l >> 8) & 0xff, (l >> 0) & 0xff, nd->root_hostnam);
468 printf("NFS ROOT: %s\n", buf);
469 nd->root_args.hostname = buf;
470 if ((error = nfs_mountdiskless(buf,
471 &nd->root_saddr, &nd->root_args, td, &vp, mp)) != 0) {
476 * This is not really an nfs issue, but it is much easier to
477 * set hostname here and then let the "/etc/rc.xxx" files
478 * mount the right /var based upon its preset value.
480 mtx_lock(&prison0.pr_mtx);
481 strlcpy(prison0.pr_hostname, nd->my_hostnam,
482 sizeof(prison0.pr_hostname));
483 mtx_unlock(&prison0.pr_mtx);
484 inittodr(ntohl(nd->root_time));
489 * Internal version of mount system call for diskless setup.
492 nfs_mountdiskless(char *path,
493 struct sockaddr_in *sin, struct nfs_args *args, struct thread *td,
494 struct vnode **vpp, struct mount *mp)
496 struct sockaddr *nam;
499 nam = sodupsockaddr((struct sockaddr *)sin, M_WAITOK);
500 if ((error = mountnfs(args, mp, nam, path, NULL, NULL, NULL, vpp,
501 td->td_ucred, td)) != 0) {
502 printf("nfs_mountroot: mount %s on /: %d\n", path, error);
509 nfs_sec_name(char *sec, int *flagsp)
511 if (!strcmp(sec, "krb5"))
512 *flagsp |= NFSMNT_KERB;
513 else if (!strcmp(sec, "krb5i"))
514 *flagsp |= (NFSMNT_KERB | NFSMNT_INTEGRITY);
515 else if (!strcmp(sec, "krb5p"))
516 *flagsp |= (NFSMNT_KERB | NFSMNT_PRIVACY);
520 nfs_decode_args(struct mount *mp, struct nfsmount *nmp, struct nfs_args *argp,
521 struct ucred *cred, struct thread *td)
529 * Set read-only flag if requested; otherwise, clear it if this is
530 * an update. If this is not an update, then either the read-only
531 * flag is already clear, or this is a root mount and it was set
532 * intentionally at some previous point.
534 if (vfs_getopt(mp->mnt_optnew, "ro", NULL, NULL) == 0) {
536 mp->mnt_flag |= MNT_RDONLY;
538 } else if (mp->mnt_flag & MNT_UPDATE) {
540 mp->mnt_flag &= ~MNT_RDONLY;
545 * Silently clear NFSMNT_NOCONN if it's a TCP mount, it makes
546 * no sense in that context. Also, set up appropriate retransmit
547 * and soft timeout behavior.
549 if (argp->sotype == SOCK_STREAM) {
550 nmp->nm_flag &= ~NFSMNT_NOCONN;
551 nmp->nm_timeo = NFS_MAXTIMEO;
554 /* Also clear RDIRPLUS if not NFSv3, it crashes some servers */
555 if ((argp->flags & NFSMNT_NFSV3) == 0)
556 nmp->nm_flag &= ~NFSMNT_RDIRPLUS;
558 /* Also re-bind if we're switching to/from a connected UDP socket */
559 adjsock = ((nmp->nm_flag & NFSMNT_NOCONN) !=
560 (argp->flags & NFSMNT_NOCONN));
562 /* Update flags atomically. Don't change the lock bits. */
563 nmp->nm_flag = argp->flags | nmp->nm_flag;
566 if ((argp->flags & NFSMNT_TIMEO) && argp->timeo > 0) {
567 nmp->nm_timeo = (argp->timeo * NFS_HZ + 5) / 10;
568 if (nmp->nm_timeo < NFS_MINTIMEO)
569 nmp->nm_timeo = NFS_MINTIMEO;
570 else if (nmp->nm_timeo > NFS_MAXTIMEO)
571 nmp->nm_timeo = NFS_MAXTIMEO;
574 if ((argp->flags & NFSMNT_RETRANS) && argp->retrans > 1) {
575 nmp->nm_retry = argp->retrans;
576 if (nmp->nm_retry > NFS_MAXREXMIT)
577 nmp->nm_retry = NFS_MAXREXMIT;
580 if ((argp->flags & NFSMNT_WSIZE) && argp->wsize > 0) {
581 nmp->nm_wsize = argp->wsize;
582 /* Round down to multiple of blocksize */
583 nmp->nm_wsize &= ~(NFS_FABLKSIZE - 1);
584 if (nmp->nm_wsize <= 0)
585 nmp->nm_wsize = NFS_FABLKSIZE;
588 if ((argp->flags & NFSMNT_RSIZE) && argp->rsize > 0) {
589 nmp->nm_rsize = argp->rsize;
590 /* Round down to multiple of blocksize */
591 nmp->nm_rsize &= ~(NFS_FABLKSIZE - 1);
592 if (nmp->nm_rsize <= 0)
593 nmp->nm_rsize = NFS_FABLKSIZE;
596 if ((argp->flags & NFSMNT_READDIRSIZE) && argp->readdirsize > 0) {
597 nmp->nm_readdirsize = argp->readdirsize;
600 if ((argp->flags & NFSMNT_ACREGMIN) && argp->acregmin >= 0)
601 nmp->nm_acregmin = argp->acregmin;
603 nmp->nm_acregmin = NFS_MINATTRTIMO;
604 if ((argp->flags & NFSMNT_ACREGMAX) && argp->acregmax >= 0)
605 nmp->nm_acregmax = argp->acregmax;
607 nmp->nm_acregmax = NFS_MAXATTRTIMO;
608 if ((argp->flags & NFSMNT_ACDIRMIN) && argp->acdirmin >= 0)
609 nmp->nm_acdirmin = argp->acdirmin;
611 nmp->nm_acdirmin = NFS_MINDIRATTRTIMO;
612 if ((argp->flags & NFSMNT_ACDIRMAX) && argp->acdirmax >= 0)
613 nmp->nm_acdirmax = argp->acdirmax;
615 nmp->nm_acdirmax = NFS_MAXDIRATTRTIMO;
616 if (nmp->nm_acdirmin > nmp->nm_acdirmax)
617 nmp->nm_acdirmin = nmp->nm_acdirmax;
618 if (nmp->nm_acregmin > nmp->nm_acregmax)
619 nmp->nm_acregmin = nmp->nm_acregmax;
621 if ((argp->flags & NFSMNT_READAHEAD) && argp->readahead >= 0) {
622 if (argp->readahead <= NFS_MAXRAHEAD)
623 nmp->nm_readahead = argp->readahead;
625 nmp->nm_readahead = NFS_MAXRAHEAD;
627 if ((argp->flags & NFSMNT_WCOMMITSIZE) && argp->wcommitsize >= 0) {
628 if (argp->wcommitsize < nmp->nm_wsize)
629 nmp->nm_wcommitsize = nmp->nm_wsize;
631 nmp->nm_wcommitsize = argp->wcommitsize;
634 adjsock |= ((nmp->nm_sotype != argp->sotype) ||
635 (nmp->nm_soproto != argp->proto));
637 if (nmp->nm_client != NULL && adjsock) {
638 int haslock = 0, error = 0;
640 if (nmp->nm_sotype == SOCK_STREAM) {
641 error = newnfs_sndlock(&nmp->nm_sockreq.nr_lock);
646 newnfs_disconnect(&nmp->nm_sockreq);
648 newnfs_sndunlock(&nmp->nm_sockreq.nr_lock);
649 nmp->nm_sotype = argp->sotype;
650 nmp->nm_soproto = argp->proto;
651 if (nmp->nm_sotype == SOCK_DGRAM)
652 while (newnfs_connect(nmp, &nmp->nm_sockreq,
654 printf("newnfs_args: retrying connect\n");
655 (void) nfs_catnap(PSOCK, "newnfscon");
659 nmp->nm_sotype = argp->sotype;
660 nmp->nm_soproto = argp->proto;
664 static const char *nfs_opts[] = { "from",
665 "noatime", "noexec", "suiddir", "nosuid", "nosymfollow", "union",
666 "noclusterr", "noclusterw", "multilabel", "acls", "force", "update",
667 "async", "noconn", "nolockd", "conn", "lockd", "intr", "rdirplus",
668 "readdirsize", "soft", "hard", "mntudp", "tcp", "udp", "wsize", "rsize",
669 "retrans", "acregmin", "acregmax", "acdirmin", "acdirmax", "resvport",
670 "readahead", "hostname", "timeout", "addr", "fh", "nfsv3", "sec",
671 "principal", "nfsv4", "gssname", "allgssname", "dirpath",
678 * It seems a bit dumb to copyinstr() the host and path here and then
679 * bcopy() them in mountnfs(), but I wanted to detect errors before
680 * doing the sockargs() call because sockargs() allocates an mbuf and
681 * an error after that means that I have to release the mbuf.
685 nfs_mount(struct mount *mp)
687 struct nfs_args args = {
688 .version = NFS_ARGSVERSION,
690 .addrlen = sizeof (struct sockaddr_in),
691 .sotype = SOCK_STREAM,
698 .readdirsize = NFS_READDIRSIZE,
700 .retrans = NFS_RETRANS,
701 .readahead = NFS_DEFRAHEAD,
702 .wcommitsize = 0, /* was: NQ_DEFLEASE */
705 .acregmin = NFS_MINATTRTIMO,
706 .acregmax = NFS_MAXATTRTIMO,
707 .acdirmin = NFS_MINDIRATTRTIMO,
708 .acdirmax = NFS_MAXDIRATTRTIMO,
713 int error = 0, ret, len;
714 struct sockaddr *nam = NULL;
718 u_char nfh[NFSX_FHMAX], krbname[100], dirpath[100], srvkrbname[100];
719 char *opt, *name, *secname;
721 if (vfs_filteropt(mp->mnt_optnew, nfs_opts)) {
727 if ((mp->mnt_flag & (MNT_ROOTFS | MNT_UPDATE)) == MNT_ROOTFS) {
728 error = ncl_mountroot(mp);
734 /* Handle the new style options. */
735 if (vfs_getopt(mp->mnt_optnew, "noconn", NULL, NULL) == 0)
736 args.flags |= NFSMNT_NOCONN;
737 if (vfs_getopt(mp->mnt_optnew, "conn", NULL, NULL) == 0)
738 args.flags |= NFSMNT_NOCONN;
739 if (vfs_getopt(mp->mnt_optnew, "nolockd", NULL, NULL) == 0)
740 args.flags |= NFSMNT_NOLOCKD;
741 if (vfs_getopt(mp->mnt_optnew, "lockd", NULL, NULL) == 0)
742 args.flags &= ~NFSMNT_NOLOCKD;
743 if (vfs_getopt(mp->mnt_optnew, "intr", NULL, NULL) == 0)
744 args.flags |= NFSMNT_INT;
745 if (vfs_getopt(mp->mnt_optnew, "rdirplus", NULL, NULL) == 0)
746 args.flags |= NFSMNT_RDIRPLUS;
747 if (vfs_getopt(mp->mnt_optnew, "resvport", NULL, NULL) == 0)
748 args.flags |= NFSMNT_RESVPORT;
749 if (vfs_getopt(mp->mnt_optnew, "noresvport", NULL, NULL) == 0)
750 args.flags &= ~NFSMNT_RESVPORT;
751 if (vfs_getopt(mp->mnt_optnew, "soft", NULL, NULL) == 0)
752 args.flags |= NFSMNT_SOFT;
753 if (vfs_getopt(mp->mnt_optnew, "hard", NULL, NULL) == 0)
754 args.flags &= ~NFSMNT_SOFT;
755 if (vfs_getopt(mp->mnt_optnew, "mntudp", NULL, NULL) == 0)
756 args.sotype = SOCK_DGRAM;
757 if (vfs_getopt(mp->mnt_optnew, "udp", NULL, NULL) == 0)
758 args.sotype = SOCK_DGRAM;
759 if (vfs_getopt(mp->mnt_optnew, "tcp", NULL, NULL) == 0)
760 args.sotype = SOCK_STREAM;
761 if (vfs_getopt(mp->mnt_optnew, "nfsv3", NULL, NULL) == 0)
762 args.flags |= NFSMNT_NFSV3;
763 if (vfs_getopt(mp->mnt_optnew, "nfsv4", NULL, NULL) == 0) {
764 args.flags |= NFSMNT_NFSV4;
765 args.sotype = SOCK_STREAM;
767 if (vfs_getopt(mp->mnt_optnew, "allgssname", NULL, NULL) == 0)
768 args.flags |= NFSMNT_ALLGSSNAME;
769 if (vfs_getopt(mp->mnt_optnew, "readdirsize", (void **)&opt, NULL) == 0) {
771 vfs_mount_error(mp, "illegal readdirsize");
775 ret = sscanf(opt, "%d", &args.readdirsize);
776 if (ret != 1 || args.readdirsize <= 0) {
777 vfs_mount_error(mp, "illegal readdirsize: %s",
782 args.flags |= NFSMNT_READDIRSIZE;
784 if (vfs_getopt(mp->mnt_optnew, "readahead", (void **)&opt, NULL) == 0) {
786 vfs_mount_error(mp, "illegal readahead");
790 ret = sscanf(opt, "%d", &args.readahead);
791 if (ret != 1 || args.readahead <= 0) {
792 vfs_mount_error(mp, "illegal readahead: %s",
797 args.flags |= NFSMNT_READAHEAD;
799 if (vfs_getopt(mp->mnt_optnew, "wsize", (void **)&opt, NULL) == 0) {
801 vfs_mount_error(mp, "illegal wsize");
805 ret = sscanf(opt, "%d", &args.wsize);
806 if (ret != 1 || args.wsize <= 0) {
807 vfs_mount_error(mp, "illegal wsize: %s",
812 args.flags |= NFSMNT_WSIZE;
814 if (vfs_getopt(mp->mnt_optnew, "rsize", (void **)&opt, NULL) == 0) {
816 vfs_mount_error(mp, "illegal rsize");
820 ret = sscanf(opt, "%d", &args.rsize);
821 if (ret != 1 || args.rsize <= 0) {
822 vfs_mount_error(mp, "illegal wsize: %s",
827 args.flags |= NFSMNT_RSIZE;
829 if (vfs_getopt(mp->mnt_optnew, "retrans", (void **)&opt, NULL) == 0) {
831 vfs_mount_error(mp, "illegal retrans");
835 ret = sscanf(opt, "%d", &args.retrans);
836 if (ret != 1 || args.retrans <= 0) {
837 vfs_mount_error(mp, "illegal retrans: %s",
842 args.flags |= NFSMNT_RETRANS;
844 if (vfs_getopt(mp->mnt_optnew, "acregmin", (void **)&opt, NULL) == 0) {
845 ret = sscanf(opt, "%d", &args.acregmin);
846 if (ret != 1 || args.acregmin < 0) {
847 vfs_mount_error(mp, "illegal acregmin: %s",
852 args.flags |= NFSMNT_ACREGMIN;
854 if (vfs_getopt(mp->mnt_optnew, "acregmax", (void **)&opt, NULL) == 0) {
855 ret = sscanf(opt, "%d", &args.acregmax);
856 if (ret != 1 || args.acregmax < 0) {
857 vfs_mount_error(mp, "illegal acregmax: %s",
862 args.flags |= NFSMNT_ACREGMAX;
864 if (vfs_getopt(mp->mnt_optnew, "acdirmin", (void **)&opt, NULL) == 0) {
865 ret = sscanf(opt, "%d", &args.acdirmin);
866 if (ret != 1 || args.acdirmin < 0) {
867 vfs_mount_error(mp, "illegal acdirmin: %s",
872 args.flags |= NFSMNT_ACDIRMIN;
874 if (vfs_getopt(mp->mnt_optnew, "acdirmax", (void **)&opt, NULL) == 0) {
875 ret = sscanf(opt, "%d", &args.acdirmax);
876 if (ret != 1 || args.acdirmax < 0) {
877 vfs_mount_error(mp, "illegal acdirmax: %s",
882 args.flags |= NFSMNT_ACDIRMAX;
884 if (vfs_getopt(mp->mnt_optnew, "timeout", (void **)&opt, NULL) == 0) {
885 ret = sscanf(opt, "%d", &args.timeo);
886 if (ret != 1 || args.timeo <= 0) {
887 vfs_mount_error(mp, "illegal timeout: %s",
892 args.flags |= NFSMNT_TIMEO;
894 if (vfs_getopt(mp->mnt_optnew, "sec",
895 (void **) &secname, NULL) == 0)
896 nfs_sec_name(secname, &args.flags);
898 if (mp->mnt_flag & MNT_UPDATE) {
899 struct nfsmount *nmp = VFSTONFS(mp);
906 * When doing an update, we can't change version,
907 * security, switch lockd strategies or change cookie
910 args.flags = (args.flags &
916 NFSMNT_NOLOCKD /*|NFSMNT_XLATECOOKIE*/)) |
923 NFSMNT_NOLOCKD /*|NFSMNT_XLATECOOKIE*/));
924 nfs_decode_args(mp, nmp, &args, td->td_ucred, td);
929 * Make the nfs_ip_paranoia sysctl serve as the default connection
930 * or no-connection mode for those protocols that support
931 * no-connection mode (the flag will be cleared later for protocols
932 * that do not support no-connection mode). This will allow a client
933 * to receive replies from a different IP then the request was
934 * sent to. Note: default value for nfs_ip_paranoia is 1 (paranoid),
937 if (nfs_ip_paranoia == 0)
938 args.flags |= NFSMNT_NOCONN;
940 if (vfs_getopt(mp->mnt_optnew, "fh", (void **)&args.fh,
941 &args.fhsize) == 0) {
942 if (args.fhsize > NFSX_FHMAX) {
943 vfs_mount_error(mp, "Bad file handle");
947 bcopy(args.fh, nfh, args.fhsize);
952 (void) vfs_getopt(mp->mnt_optnew, "hostname", (void **)&args.hostname,
954 if (args.hostname == NULL) {
955 vfs_mount_error(mp, "Invalid hostname");
959 bcopy(args.hostname, hst, MNAMELEN);
960 hst[MNAMELEN - 1] = '\0';
962 if (vfs_getopt(mp->mnt_optnew, "principal", (void **)&name, NULL) == 0)
963 strlcpy(srvkrbname, name, sizeof (srvkrbname));
965 snprintf(srvkrbname, sizeof (srvkrbname), "nfs@%s", hst);
966 args.srvkrbnamelen = strlen(srvkrbname);
968 if (vfs_getopt(mp->mnt_optnew, "gssname", (void **)&name, NULL) == 0)
969 strlcpy(krbname, name, sizeof (krbname));
972 args.krbnamelen = strlen(krbname);
974 if (vfs_getopt(mp->mnt_optnew, "dirpath", (void **)&name, NULL) == 0)
975 strlcpy(dirpath, name, sizeof (dirpath));
978 args.dirlen = strlen(dirpath);
980 if (vfs_getopt(mp->mnt_optnew, "addr", (void **)&args.addr,
981 &args.addrlen) == 0) {
982 if (args.addrlen > SOCK_MAXADDRLEN) {
983 error = ENAMETOOLONG;
986 nam = malloc(args.addrlen, M_SONAME, M_WAITOK);
987 bcopy(args.addr, nam, args.addrlen);
988 nam->sa_len = args.addrlen;
992 error = mountnfs(&args, mp, nam, hst, krbname, dirpath, srvkrbname,
993 &vp, td->td_ucred, td);
997 mp->mnt_kern_flag |= (MNTK_MPSAFE|MNTK_LOOKUP_SHARED);
1008 * It seems a bit dumb to copyinstr() the host and path here and then
1009 * bcopy() them in mountnfs(), but I wanted to detect errors before
1010 * doing the sockargs() call because sockargs() allocates an mbuf and
1011 * an error after that means that I have to release the mbuf.
1015 nfs_cmount(struct mntarg *ma, void *data, int flags)
1018 struct nfs_args args;
1020 error = copyin(data, &args, sizeof (struct nfs_args));
1024 ma = mount_arg(ma, "nfs_args", &args, sizeof args);
1026 error = kernel_mount(ma, flags);
1031 * Common code for mount and mountroot
1034 mountnfs(struct nfs_args *argp, struct mount *mp, struct sockaddr *nam,
1035 char *hst, u_char *krbname, u_char *dirpath, u_char *srvkrbname,
1036 struct vnode **vpp, struct ucred *cred, struct thread *td)
1038 struct nfsmount *nmp;
1040 int error, trycnt, ret, clearintr;
1041 struct nfsvattr nfsva;
1042 static u_int64_t clval = 0;
1044 if (mp->mnt_flag & MNT_UPDATE) {
1046 printf("%s: MNT_UPDATE is no longer handled here\n", __func__);
1047 FREE(nam, M_SONAME);
1050 MALLOC(nmp, struct nfsmount *, sizeof (struct nfsmount) +
1051 argp->krbnamelen + argp->dirlen + argp->srvkrbnamelen + 2,
1052 M_NEWNFSMNT, M_WAITOK);
1053 bzero((caddr_t)nmp, sizeof (struct nfsmount) +
1054 argp->krbnamelen + argp->dirlen + argp->srvkrbnamelen + 2);
1055 TAILQ_INIT(&nmp->nm_bufq);
1057 clval = (u_int64_t)nfsboottime.tv_sec;
1058 nmp->nm_clval = clval++;
1059 nmp->nm_krbnamelen = argp->krbnamelen;
1060 nmp->nm_dirpathlen = argp->dirlen;
1061 nmp->nm_srvkrbnamelen = argp->srvkrbnamelen;
1062 if (td->td_ucred->cr_uid != (uid_t)0) {
1064 * nm_uid is used to get KerberosV credentials for
1065 * the nfsv4 state handling operations if there is
1066 * no host based principal set. Use the uid of
1067 * this user if not root, since they are doing the
1068 * mount. I don't think setting this for root will
1069 * work, since root normally does not have user
1070 * credentials in a credentials cache.
1072 nmp->nm_uid = td->td_ucred->cr_uid;
1075 * Just set to -1, so it won't be used.
1077 nmp->nm_uid = (uid_t)-1;
1080 /* Copy and null terminate all the names */
1081 if (nmp->nm_krbnamelen > 0) {
1082 bcopy(krbname, nmp->nm_krbname, nmp->nm_krbnamelen);
1083 nmp->nm_name[nmp->nm_krbnamelen] = '\0';
1085 if (nmp->nm_dirpathlen > 0) {
1086 bcopy(dirpath, NFSMNT_DIRPATH(nmp),
1087 nmp->nm_dirpathlen);
1088 nmp->nm_name[nmp->nm_krbnamelen + nmp->nm_dirpathlen
1091 if (nmp->nm_srvkrbnamelen > 0) {
1092 bcopy(srvkrbname, NFSMNT_SRVKRBNAME(nmp),
1093 nmp->nm_srvkrbnamelen);
1094 nmp->nm_name[nmp->nm_krbnamelen + nmp->nm_dirpathlen
1095 + nmp->nm_srvkrbnamelen + 2] = '\0';
1097 nmp->nm_sockreq.nr_cred = crhold(cred);
1098 mtx_init(&nmp->nm_sockreq.nr_mtx, "nfssock", NULL, MTX_DEF);
1102 nmp->nm_mountp = mp;
1103 mtx_init(&nmp->nm_mtx, "NFSmount lock", NULL, MTX_DEF | MTX_DUPOK);
1105 nfs_decode_args(mp, nmp, argp, cred, td);
1108 * V2 can only handle 32 bit filesizes. A 4GB-1 limit may be too
1109 * high, depending on whether we end up with negative offsets in
1110 * the client or server somewhere. 2GB-1 may be safer.
1112 * For V3, ncl_fsinfo will adjust this as necessary. Assume maximum
1113 * that we can handle until we find out otherwise.
1114 * XXX Our "safe" limit on the client is what we can store in our
1115 * buffer cache using signed(!) block numbers.
1117 if ((argp->flags & (NFSMNT_NFSV3 | NFSMNT_NFSV4)) == 0)
1118 nmp->nm_maxfilesize = 0xffffffffLL;
1120 nmp->nm_maxfilesize = (u_int64_t)0x80000000 * DEV_BSIZE - 1;
1122 nmp->nm_timeo = NFS_TIMEO;
1123 nmp->nm_retry = NFS_RETRANS;
1124 if ((argp->flags & (NFSMNT_NFSV3 | NFSMNT_NFSV4)) == 0) {
1125 nmp->nm_wsize = NFS_WSIZE;
1126 nmp->nm_rsize = NFS_RSIZE;
1127 nmp->nm_readdirsize = NFS_READDIRSIZE;
1129 nmp->nm_wcommitsize = hibufspace / (desiredvnodes / 1000);
1130 nmp->nm_numgrps = NFS_MAXGRPS;
1131 nmp->nm_readahead = NFS_DEFRAHEAD;
1132 nmp->nm_tprintf_delay = nfs_tprintf_delay;
1133 if (nmp->nm_tprintf_delay < 0)
1134 nmp->nm_tprintf_delay = 0;
1135 nmp->nm_tprintf_initial_delay = nfs_tprintf_initial_delay;
1136 if (nmp->nm_tprintf_initial_delay < 0)
1137 nmp->nm_tprintf_initial_delay = 0;
1138 nmp->nm_fhsize = argp->fhsize;
1139 if (nmp->nm_fhsize > 0)
1140 bcopy((caddr_t)argp->fh, (caddr_t)nmp->nm_fh, argp->fhsize);
1141 bcopy(hst, mp->mnt_stat.f_mntfromname, MNAMELEN);
1143 /* Set up the sockets and per-host congestion */
1144 nmp->nm_sotype = argp->sotype;
1145 nmp->nm_soproto = argp->proto;
1146 nmp->nm_sockreq.nr_prog = NFS_PROG;
1147 if ((argp->flags & NFSMNT_NFSV4))
1148 nmp->nm_sockreq.nr_vers = NFS_VER4;
1149 else if ((argp->flags & NFSMNT_NFSV3))
1150 nmp->nm_sockreq.nr_vers = NFS_VER3;
1152 nmp->nm_sockreq.nr_vers = NFS_VER2;
1156 * For Connection based sockets (TCP,...) do the connect here,
1157 * but make it interruptible, even for non-interuptible mounts.
1159 if ((nmp->nm_flag & NFSMNT_INT) == 0) {
1160 nmp->nm_flag |= NFSMNT_INT;
1165 if ((error = newnfs_connect(nmp, &nmp->nm_sockreq, cred, td, 0)))
1168 nmp->nm_flag &= ~NFSMNT_INT;
1171 * A reference count is needed on the nfsnode representing the
1172 * remote root. If this object is not persistent, then backward
1173 * traversals of the mount point (i.e. "..") will not work if
1174 * the nfsnode gets flushed out of the cache. Ufs does not have
1175 * this problem, because one can identify root inodes by their
1176 * number == ROOTINO (2).
1178 if (nmp->nm_fhsize == 0 && (nmp->nm_flag & NFSMNT_NFSV4) &&
1179 nmp->nm_dirpathlen > 0) {
1181 * If the fhsize on the mount point == 0 for V4, the mount
1182 * path needs to be looked up.
1186 error = nfsrpc_getdirpath(nmp, NFSMNT_DIRPATH(nmp),
1189 (void) nfs_catnap(PZERO, "nfsgetdirp");
1190 } while (error && --trycnt > 0);
1192 error = nfscl_maperr(td, error, (uid_t)0, (gid_t)0);
1196 if (nmp->nm_fhsize > 0) {
1197 error = ncl_nget(mp, nmp->nm_fh, nmp->nm_fhsize, &np);
1203 * Get file attributes and transfer parameters for the
1204 * mountpoint. This has the side effect of filling in
1205 * (*vpp)->v_type with the correct value.
1207 ret = nfsrpc_getattrnovp(nmp, nmp->nm_fh, nmp->nm_fhsize, 1,
1208 cred, td, &nfsva, NULL);
1211 * Just set default values to get things going.
1213 NFSBZERO((caddr_t)&nfsva, sizeof (struct nfsvattr));
1214 nfsva.na_vattr.va_type = VDIR;
1215 nfsva.na_vattr.va_mode = 0777;
1216 nfsva.na_vattr.va_nlink = 100;
1217 nfsva.na_vattr.va_uid = (uid_t)0;
1218 nfsva.na_vattr.va_gid = (gid_t)0;
1219 nfsva.na_vattr.va_fileid = 2;
1220 nfsva.na_vattr.va_gen = 1;
1221 nfsva.na_vattr.va_blocksize = NFS_FABLKSIZE;
1222 nfsva.na_vattr.va_size = 512 * 1024;
1224 (void) nfscl_loadattrcache(vpp, &nfsva, NULL, NULL, 0, 1);
1225 if (argp->flags & NFSMNT_NFSV3)
1226 ncl_fsinfo(nmp, *vpp, cred, td);
1229 * Lose the lock but keep the ref.
1231 VOP_UNLOCK(*vpp, 0);
1237 newnfs_disconnect(&nmp->nm_sockreq);
1238 crfree(nmp->nm_sockreq.nr_cred);
1239 mtx_destroy(&nmp->nm_sockreq.nr_mtx);
1240 mtx_destroy(&nmp->nm_mtx);
1241 FREE(nmp, M_NEWNFSMNT);
1242 FREE(nam, M_SONAME);
1247 * unmount system call
1250 nfs_unmount(struct mount *mp, int mntflags)
1253 struct nfsmount *nmp;
1254 int error, flags = 0, trycnt = 0;
1258 if (mntflags & MNT_FORCE)
1259 flags |= FORCECLOSE;
1262 * Goes something like this..
1263 * - Call vflush() to clear out vnodes for this filesystem
1264 * - Close the socket
1265 * - Free up the data structures
1267 /* In the forced case, cancel any outstanding requests. */
1268 if (mntflags & MNT_FORCE) {
1269 error = newnfs_nmcancelreqs(nmp);
1272 /* For a forced close, get rid of the renew thread now */
1273 nfscl_umount(nmp, td);
1275 /* We hold 1 extra ref on the root vnode; see comment in mountnfs(). */
1277 error = vflush(mp, 1, flags, td);
1278 if ((mntflags & MNT_FORCE) && error != 0 && ++trycnt < 30)
1279 (void) nfs_catnap(PSOCK, "newndm");
1280 } while ((mntflags & MNT_FORCE) && error != 0 && trycnt < 30);
1285 * We are now committed to the unmount.
1287 if ((mntflags & MNT_FORCE) == 0)
1288 nfscl_umount(nmp, td);
1289 newnfs_disconnect(&nmp->nm_sockreq);
1290 crfree(nmp->nm_sockreq.nr_cred);
1291 FREE(nmp->nm_nam, M_SONAME);
1293 mtx_destroy(&nmp->nm_sockreq.nr_mtx);
1294 mtx_destroy(&nmp->nm_mtx);
1295 FREE(nmp, M_NEWNFSMNT);
1301 * Return root of a filesystem
1304 nfs_root(struct mount *mp, int flags, struct vnode **vpp)
1307 struct nfsmount *nmp;
1312 error = ncl_nget(mp, nmp->nm_fh, nmp->nm_fhsize, &np);
1317 * Get transfer parameters and attributes for root vnode once.
1319 mtx_lock(&nmp->nm_mtx);
1320 if (NFSHASNFSV3(nmp) && !NFSHASGOTFSINFO(nmp)) {
1321 mtx_unlock(&nmp->nm_mtx);
1322 ncl_fsinfo(nmp, vp, curthread->td_ucred, curthread);
1324 mtx_unlock(&nmp->nm_mtx);
1325 if (vp->v_type == VNON)
1327 vp->v_vflag |= VV_ROOT;
1333 * Flush out the buffer cache
1337 nfs_sync(struct mount *mp, int waitfor)
1339 struct vnode *vp, *mvp;
1341 int error, allerror = 0;
1346 * Force stale buffer cache information to be flushed.
1350 MNT_VNODE_FOREACH(vp, mp, mvp) {
1353 /* XXX Racy bv_cnt check. */
1354 if (VOP_ISLOCKED(vp) || vp->v_bufobj.bo_dirty.bv_cnt == 0 ||
1355 waitfor == MNT_LAZY) {
1360 if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, td)) {
1362 MNT_VNODE_FOREACH_ABORT_ILOCKED(mp, mvp);
1365 error = VOP_FSYNC(vp, waitfor, td);
1378 nfs_sysctl(struct mount *mp, fsctlop_t op, struct sysctl_req *req)
1380 struct nfsmount *nmp = VFSTONFS(mp);
1384 bzero(&vq, sizeof(vq));
1387 case VFS_CTL_NOLOCKS:
1388 val = (nmp->nm_flag & NFSMNT_NOLOCKS) ? 1 : 0;
1389 if (req->oldptr != NULL) {
1390 error = SYSCTL_OUT(req, &val, sizeof(val));
1394 if (req->newptr != NULL) {
1395 error = SYSCTL_IN(req, &val, sizeof(val));
1399 nmp->nm_flag |= NFSMNT_NOLOCKS;
1401 nmp->nm_flag &= ~NFSMNT_NOLOCKS;
1406 mtx_lock(&nmp->nm_mtx);
1407 if (nmp->nm_state & NFSSTA_TIMEO)
1408 vq.vq_flags |= VQ_NOTRESP;
1409 mtx_unlock(&nmp->nm_mtx);
1411 if (!(nmp->nm_flag & NFSMNT_NOLOCKS) &&
1412 (nmp->nm_state & NFSSTA_LOCKTIMEO))
1413 vq.vq_flags |= VQ_NOTRESPLOCK;
1415 error = SYSCTL_OUT(req, &vq, sizeof(vq));
1418 if (req->oldptr != NULL) {
1419 error = SYSCTL_OUT(req, &nmp->nm_tprintf_initial_delay,
1420 sizeof(nmp->nm_tprintf_initial_delay));
1424 if (req->newptr != NULL) {
1425 error = vfs_suser(mp, req->td);
1428 error = SYSCTL_IN(req, &nmp->nm_tprintf_initial_delay,
1429 sizeof(nmp->nm_tprintf_initial_delay));
1432 if (nmp->nm_tprintf_initial_delay < 0)
1433 nmp->nm_tprintf_initial_delay = 0;