nfs_vfsops.c revision 1.1 1 1.1 cgd /*
2 1.1 cgd * Copyright (c) 1989 The Regents of the University of California.
3 1.1 cgd * All rights reserved.
4 1.1 cgd *
5 1.1 cgd * This code is derived from software contributed to Berkeley by
6 1.1 cgd * Rick Macklem at The University of Guelph.
7 1.1 cgd *
8 1.1 cgd * Redistribution and use in source and binary forms, with or without
9 1.1 cgd * modification, are permitted provided that the following conditions
10 1.1 cgd * are met:
11 1.1 cgd * 1. Redistributions of source code must retain the above copyright
12 1.1 cgd * notice, this list of conditions and the following disclaimer.
13 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer in the
15 1.1 cgd * documentation and/or other materials provided with the distribution.
16 1.1 cgd * 3. All advertising materials mentioning features or use of this software
17 1.1 cgd * must display the following acknowledgement:
18 1.1 cgd * This product includes software developed by the University of
19 1.1 cgd * California, Berkeley and its contributors.
20 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
21 1.1 cgd * may be used to endorse or promote products derived from this software
22 1.1 cgd * without specific prior written permission.
23 1.1 cgd *
24 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.1 cgd * SUCH DAMAGE.
35 1.1 cgd *
36 1.1 cgd * @(#)nfs_vfsops.c 7.31 (Berkeley) 5/6/91
37 1.1 cgd */
38 1.1 cgd
39 1.1 cgd #include "param.h"
40 1.1 cgd #include "conf.h"
41 1.1 cgd #include "ioctl.h"
42 1.1 cgd #include "signal.h"
43 1.1 cgd #include "proc.h"
44 1.1 cgd #include "namei.h"
45 1.1 cgd #include "vnode.h"
46 1.1 cgd #include "mount.h"
47 1.1 cgd #include "buf.h"
48 1.1 cgd #include "mbuf.h"
49 1.1 cgd #include "socket.h"
50 1.1 cgd #include "systm.h"
51 1.1 cgd
52 1.1 cgd #include "../net/if.h"
53 1.1 cgd #include "../net/route.h"
54 1.1 cgd #include "../netinet/in.h"
55 1.1 cgd
56 1.1 cgd #include "nfsv2.h"
57 1.1 cgd #include "nfsnode.h"
58 1.1 cgd #include "nfsmount.h"
59 1.1 cgd #include "nfs.h"
60 1.1 cgd #include "xdr_subs.h"
61 1.1 cgd #include "nfsm_subs.h"
62 1.1 cgd #include "nfsdiskless.h"
63 1.1 cgd
64 1.1 cgd /*
65 1.1 cgd * nfs vfs operations.
66 1.1 cgd */
67 1.1 cgd struct vfsops nfs_vfsops = {
68 1.1 cgd nfs_mount,
69 1.1 cgd nfs_start,
70 1.1 cgd nfs_unmount,
71 1.1 cgd nfs_root,
72 1.1 cgd nfs_quotactl,
73 1.1 cgd nfs_statfs,
74 1.1 cgd nfs_sync,
75 1.1 cgd nfs_fhtovp,
76 1.1 cgd nfs_vptofh,
77 1.1 cgd nfs_init,
78 1.1 cgd };
79 1.1 cgd
80 1.1 cgd static u_char nfs_mntid;
81 1.1 cgd extern u_long nfs_procids[NFS_NPROCS];
82 1.1 cgd extern u_long nfs_prog, nfs_vers;
83 1.1 cgd struct nfs_diskless nfs_diskless;
84 1.1 cgd void nfs_disconnect();
85 1.1 cgd
86 1.1 cgd #define TRUE 1
87 1.1 cgd #define FALSE 0
88 1.1 cgd
89 1.1 cgd /*
90 1.1 cgd * nfs statfs call
91 1.1 cgd */
92 1.1 cgd nfs_statfs(mp, sbp, p)
93 1.1 cgd struct mount *mp;
94 1.1 cgd register struct statfs *sbp;
95 1.1 cgd struct proc *p;
96 1.1 cgd {
97 1.1 cgd register struct vnode *vp;
98 1.1 cgd register struct nfsv2_statfs *sfp;
99 1.1 cgd register caddr_t cp;
100 1.1 cgd register long t1;
101 1.1 cgd caddr_t bpos, dpos, cp2;
102 1.1 cgd u_long xid;
103 1.1 cgd int error = 0;
104 1.1 cgd struct mbuf *mreq, *mrep, *md, *mb, *mb2;
105 1.1 cgd struct nfsmount *nmp;
106 1.1 cgd struct ucred *cred;
107 1.1 cgd struct nfsnode *np;
108 1.1 cgd
109 1.1 cgd nmp = VFSTONFS(mp);
110 1.1 cgd if (error = nfs_nget(mp, &nmp->nm_fh, &np))
111 1.1 cgd return (error);
112 1.1 cgd vp = NFSTOV(np);
113 1.1 cgd nfsstats.rpccnt[NFSPROC_STATFS]++;
114 1.1 cgd cred = crget();
115 1.1 cgd cred->cr_ngroups = 1;
116 1.1 cgd nfsm_reqhead(nfs_procids[NFSPROC_STATFS], cred, NFSX_FH);
117 1.1 cgd nfsm_fhtom(vp);
118 1.1 cgd nfsm_request(vp, NFSPROC_STATFS, p, 0);
119 1.1 cgd nfsm_disect(sfp, struct nfsv2_statfs *, NFSX_STATFS);
120 1.1 cgd sbp->f_type = MOUNT_NFS;
121 1.1 cgd sbp->f_flags = nmp->nm_flag;
122 1.1 cgd sbp->f_bsize = fxdr_unsigned(long, sfp->sf_tsize);
123 1.1 cgd sbp->f_fsize = fxdr_unsigned(long, sfp->sf_bsize);
124 1.1 cgd sbp->f_blocks = fxdr_unsigned(long, sfp->sf_blocks);
125 1.1 cgd sbp->f_bfree = fxdr_unsigned(long, sfp->sf_bfree);
126 1.1 cgd sbp->f_bavail = fxdr_unsigned(long, sfp->sf_bavail);
127 1.1 cgd sbp->f_files = 0;
128 1.1 cgd sbp->f_ffree = 0;
129 1.1 cgd if (sbp != &mp->mnt_stat) {
130 1.1 cgd bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
131 1.1 cgd bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
132 1.1 cgd }
133 1.1 cgd nfsm_reqdone;
134 1.1 cgd nfs_nput(vp);
135 1.1 cgd crfree(cred);
136 1.1 cgd return (error);
137 1.1 cgd }
138 1.1 cgd
139 1.1 cgd /*
140 1.1 cgd * Mount a remote root fs via. nfs. This depends on the info in the
141 1.1 cgd * nfs_diskless structure that has been filled in properly by some primary
142 1.1 cgd * bootstrap.
143 1.1 cgd * It goes something like this:
144 1.1 cgd * - do enough of "ifconfig" by calling ifioctl() so that the system
145 1.1 cgd * can talk to the server
146 1.1 cgd * - If nfs_diskless.mygateway is filled in, use that address as
147 1.1 cgd * a default gateway.
148 1.1 cgd * (This is done the 4.3 way with rtioctl() and should be changed)
149 1.1 cgd * - hand craft the swap nfs vnode hanging off a fake mount point
150 1.1 cgd * - build the rootfs mount point and call mountnfs() to do the rest.
151 1.1 cgd */
152 1.1 cgd nfs_mountroot()
153 1.1 cgd {
154 1.1 cgd register struct mount *mp;
155 1.1 cgd register struct mbuf *m;
156 1.1 cgd struct socket *so;
157 1.1 cgd struct vnode *vp;
158 1.1 cgd int error;
159 1.1 cgd
160 1.1 cgd /*
161 1.1 cgd * Do enough of ifconfig(8) so that critical net interface can
162 1.1 cgd * talk to the server.
163 1.1 cgd */
164 1.1 cgd if (socreate(nfs_diskless.myif.ifra_addr.sa_family, &so, SOCK_DGRAM, 0))
165 1.1 cgd panic("nfs ifconf");
166 1.1 cgd if (ifioctl(so, SIOCAIFADDR, &nfs_diskless.myif))
167 1.1 cgd panic("nfs ifconf2");
168 1.1 cgd soclose(so);
169 1.1 cgd
170 1.1 cgd /*
171 1.1 cgd * If the gateway field is filled in, set it as the default route.
172 1.1 cgd */
173 1.1 cgd #ifdef COMPAT_43
174 1.1 cgd if (nfs_diskless.mygateway.sa_family == AF_INET) {
175 1.1 cgd struct ortentry rt;
176 1.1 cgd struct sockaddr_in *sin;
177 1.1 cgd
178 1.1 cgd sin = (struct sockaddr_in *) &rt.rt_dst;
179 1.1 cgd sin->sin_len = sizeof (struct sockaddr_in);
180 1.1 cgd sin->sin_family = AF_INET;
181 1.1 cgd sin->sin_addr.s_addr = 0; /* default */
182 1.1 cgd bcopy((caddr_t)&nfs_diskless.mygateway, (caddr_t)&rt.rt_gateway,
183 1.1 cgd sizeof (struct sockaddr_in));
184 1.1 cgd rt.rt_flags = (RTF_UP | RTF_GATEWAY);
185 1.1 cgd if (rtioctl(SIOCADDRT, (caddr_t)&rt))
186 1.1 cgd panic("nfs root route");
187 1.1 cgd }
188 1.1 cgd #endif /* COMPAT_43 */
189 1.1 cgd
190 1.1 cgd /*
191 1.1 cgd * If swapping to an nfs node (indicated by swdevt[0].sw_dev == NODEV):
192 1.1 cgd * Create a fake mount point just for the swap vnode so that the
193 1.1 cgd * swap file can be on a different server from the rootfs.
194 1.1 cgd */
195 1.1 cgd if (swdevt[0].sw_dev == NODEV) {
196 1.1 cgd mp = (struct mount *)malloc((u_long)sizeof(struct mount),
197 1.1 cgd M_MOUNT, M_NOWAIT);
198 1.1 cgd if (mp == NULL)
199 1.1 cgd panic("nfs root mount");
200 1.1 cgd mp->mnt_op = &nfs_vfsops;
201 1.1 cgd mp->mnt_flag = 0;
202 1.1 cgd mp->mnt_exroot = 0;
203 1.1 cgd mp->mnt_mounth = NULLVP;
204 1.1 cgd
205 1.1 cgd /*
206 1.1 cgd * Set up the diskless nfs_args for the swap mount point
207 1.1 cgd * and then call mountnfs() to mount it.
208 1.1 cgd * Since the swap file is not the root dir of a file system,
209 1.1 cgd * hack it to a regular file.
210 1.1 cgd */
211 1.1 cgd nfs_diskless.swap_args.fh = (nfsv2fh_t *)nfs_diskless.swap_fh;
212 1.1 cgd MGET(m, MT_SONAME, M_DONTWAIT);
213 1.1 cgd if (m == NULL)
214 1.1 cgd panic("nfs root mbuf");
215 1.1 cgd bcopy((caddr_t)&nfs_diskless.swap_saddr, mtod(m, caddr_t),
216 1.1 cgd nfs_diskless.swap_saddr.sa_len);
217 1.1 cgd m->m_len = nfs_diskless.swap_saddr.sa_len;
218 1.1 cgd if (mountnfs(&nfs_diskless.swap_args, mp, m, "/swap",
219 1.1 cgd nfs_diskless.swap_hostnam, &vp))
220 1.1 cgd panic("nfs swap");
221 1.1 cgd vp->v_type = VREG;
222 1.1 cgd vp->v_flag = 0;
223 1.1 cgd swapdev_vp = vp;
224 1.1 cgd VREF(vp);
225 1.1 cgd swdevt[0].sw_vp = vp;
226 1.1 cgd }
227 1.1 cgd
228 1.1 cgd /*
229 1.1 cgd * Create the rootfs mount point.
230 1.1 cgd */
231 1.1 cgd mp = (struct mount *)malloc((u_long)sizeof(struct mount),
232 1.1 cgd M_MOUNT, M_NOWAIT);
233 1.1 cgd if (mp == NULL)
234 1.1 cgd panic("nfs root mount2");
235 1.1 cgd mp->mnt_op = &nfs_vfsops;
236 1.1 cgd mp->mnt_flag = MNT_RDONLY;
237 1.1 cgd mp->mnt_exroot = 0;
238 1.1 cgd mp->mnt_mounth = NULLVP;
239 1.1 cgd
240 1.1 cgd /*
241 1.1 cgd * Set up the root fs args and call mountnfs() to do the rest.
242 1.1 cgd */
243 1.1 cgd nfs_diskless.root_args.fh = (nfsv2fh_t *)nfs_diskless.root_fh;
244 1.1 cgd MGET(m, MT_SONAME, M_DONTWAIT);
245 1.1 cgd if (m == NULL)
246 1.1 cgd panic("nfs root mbuf2");
247 1.1 cgd bcopy((caddr_t)&nfs_diskless.root_saddr, mtod(m, caddr_t),
248 1.1 cgd nfs_diskless.root_saddr.sa_len);
249 1.1 cgd m->m_len = nfs_diskless.root_saddr.sa_len;
250 1.1 cgd if (mountnfs(&nfs_diskless.root_args, mp, m, "/",
251 1.1 cgd nfs_diskless.root_hostnam, &vp))
252 1.1 cgd panic("nfs root");
253 1.1 cgd if (vfs_lock(mp))
254 1.1 cgd panic("nfs root2");
255 1.1 cgd rootfs = mp;
256 1.1 cgd mp->mnt_next = mp;
257 1.1 cgd mp->mnt_prev = mp;
258 1.1 cgd mp->mnt_vnodecovered = NULLVP;
259 1.1 cgd vfs_unlock(mp);
260 1.1 cgd rootvp = vp;
261 1.1 cgd inittodr((time_t)0); /* There is no time in the nfs fsstat so ?? */
262 1.1 cgd return (0);
263 1.1 cgd }
264 1.1 cgd
265 1.1 cgd /*
266 1.1 cgd * VFS Operations.
267 1.1 cgd *
268 1.1 cgd * mount system call
269 1.1 cgd * It seems a bit dumb to copyinstr() the host and path here and then
270 1.1 cgd * bcopy() them in mountnfs(), but I wanted to detect errors before
271 1.1 cgd * doing the sockargs() call because sockargs() allocates an mbuf and
272 1.1 cgd * an error after that means that I have to release the mbuf.
273 1.1 cgd */
274 1.1 cgd /* ARGSUSED */
275 1.1 cgd nfs_mount(mp, path, data, ndp, p)
276 1.1 cgd struct mount *mp;
277 1.1 cgd char *path;
278 1.1 cgd caddr_t data;
279 1.1 cgd struct nameidata *ndp;
280 1.1 cgd struct proc *p;
281 1.1 cgd {
282 1.1 cgd int error;
283 1.1 cgd struct nfs_args args;
284 1.1 cgd struct mbuf *nam;
285 1.1 cgd struct vnode *vp;
286 1.1 cgd char pth[MNAMELEN], hst[MNAMELEN];
287 1.1 cgd u_int len;
288 1.1 cgd nfsv2fh_t nfh;
289 1.1 cgd
290 1.1 cgd if (mp->mnt_flag & MNT_UPDATE)
291 1.1 cgd return (0);
292 1.1 cgd if (error = copyin(data, (caddr_t)&args, sizeof (struct nfs_args)))
293 1.1 cgd return (error);
294 1.1 cgd if (error = copyin((caddr_t)args.fh, (caddr_t)&nfh, sizeof (nfsv2fh_t)))
295 1.1 cgd return (error);
296 1.1 cgd if (error = copyinstr(path, pth, MNAMELEN-1, &len))
297 1.1 cgd return (error);
298 1.1 cgd bzero(&pth[len], MNAMELEN - len);
299 1.1 cgd if (error = copyinstr(args.hostname, hst, MNAMELEN-1, &len))
300 1.1 cgd return (error);
301 1.1 cgd bzero(&hst[len], MNAMELEN - len);
302 1.1 cgd /* sockargs() call must be after above copyin() calls */
303 1.1 cgd if (error = sockargs(&nam, (caddr_t)args.addr,
304 1.1 cgd sizeof (struct sockaddr), MT_SONAME))
305 1.1 cgd return (error);
306 1.1 cgd args.fh = &nfh;
307 1.1 cgd error = mountnfs(&args, mp, nam, pth, hst, &vp);
308 1.1 cgd return (error);
309 1.1 cgd }
310 1.1 cgd
311 1.1 cgd /*
312 1.1 cgd * Common code for mount and mountroot
313 1.1 cgd */
314 1.1 cgd mountnfs(argp, mp, nam, pth, hst, vpp)
315 1.1 cgd register struct nfs_args *argp;
316 1.1 cgd register struct mount *mp;
317 1.1 cgd struct mbuf *nam;
318 1.1 cgd char *pth, *hst;
319 1.1 cgd struct vnode **vpp;
320 1.1 cgd {
321 1.1 cgd register struct nfsmount *nmp;
322 1.1 cgd struct proc *p = curproc; /* XXX */
323 1.1 cgd struct nfsnode *np;
324 1.1 cgd int error;
325 1.1 cgd fsid_t tfsid;
326 1.1 cgd
327 1.1 cgd MALLOC(nmp, struct nfsmount *, sizeof *nmp, M_NFSMNT, M_WAITOK);
328 1.1 cgd bzero((caddr_t)nmp, sizeof *nmp);
329 1.1 cgd mp->mnt_data = (qaddr_t)nmp;
330 1.1 cgd /*
331 1.1 cgd * Generate a unique nfs mount id. The problem is that a dev number
332 1.1 cgd * is not unique across multiple systems. The techique is as follows:
333 1.1 cgd * 1) Set to nblkdev,0 which will never be used otherwise
334 1.1 cgd * 2) Generate a first guess as nblkdev,nfs_mntid where nfs_mntid is
335 1.1 cgd * NOT 0
336 1.1 cgd * 3) Loop searching the mount list for another one with same id
337 1.1 cgd * If a match, increment val[0] and try again
338 1.1 cgd * NB: I increment val[0] { a long } instead of nfs_mntid { a u_char }
339 1.1 cgd * so that nfs is not limited to 255 mount points
340 1.1 cgd * Incrementing the high order bits does no real harm, since it
341 1.1 cgd * simply makes the major dev number tick up. The upper bound is
342 1.1 cgd * set to major dev 127 to avoid any sign extention problems
343 1.1 cgd */
344 1.1 cgd mp->mnt_stat.f_fsid.val[0] = makedev(nblkdev, 0);
345 1.1 cgd mp->mnt_stat.f_fsid.val[1] = MOUNT_NFS;
346 1.1 cgd if (++nfs_mntid == 0)
347 1.1 cgd ++nfs_mntid;
348 1.1 cgd tfsid.val[0] = makedev(nblkdev, nfs_mntid);
349 1.1 cgd tfsid.val[1] = MOUNT_NFS;
350 1.1 cgd while (rootfs && getvfs(&tfsid)) {
351 1.1 cgd tfsid.val[0]++;
352 1.1 cgd nfs_mntid++;
353 1.1 cgd }
354 1.1 cgd if (major(tfsid.val[0]) > 127) {
355 1.1 cgd error = ENOENT;
356 1.1 cgd goto bad;
357 1.1 cgd }
358 1.1 cgd mp->mnt_stat.f_fsid.val[0] = tfsid.val[0];
359 1.1 cgd nmp->nm_mountp = mp;
360 1.1 cgd nmp->nm_flag = argp->flags;
361 1.1 cgd nmp->nm_rto = NFS_TIMEO;
362 1.1 cgd nmp->nm_rtt = -1;
363 1.1 cgd nmp->nm_rttvar = nmp->nm_rto << 1;
364 1.1 cgd nmp->nm_retry = NFS_RETRANS;
365 1.1 cgd nmp->nm_wsize = NFS_WSIZE;
366 1.1 cgd nmp->nm_rsize = NFS_RSIZE;
367 1.1 cgd bcopy((caddr_t)argp->fh, (caddr_t)&nmp->nm_fh, sizeof(nfsv2fh_t));
368 1.1 cgd bcopy(hst, mp->mnt_stat.f_mntfromname, MNAMELEN);
369 1.1 cgd bcopy(pth, mp->mnt_stat.f_mntonname, MNAMELEN);
370 1.1 cgd nmp->nm_nam = nam;
371 1.1 cgd
372 1.1 cgd if ((argp->flags & NFSMNT_TIMEO) && argp->timeo > 0) {
373 1.1 cgd nmp->nm_rto = argp->timeo;
374 1.1 cgd /* NFS timeouts are specified in 1/10 sec. */
375 1.1 cgd nmp->nm_rto = (nmp->nm_rto * 10) / NFS_HZ;
376 1.1 cgd if (nmp->nm_rto < NFS_MINTIMEO)
377 1.1 cgd nmp->nm_rto = NFS_MINTIMEO;
378 1.1 cgd else if (nmp->nm_rto > NFS_MAXTIMEO)
379 1.1 cgd nmp->nm_rto = NFS_MAXTIMEO;
380 1.1 cgd nmp->nm_rttvar = nmp->nm_rto << 1;
381 1.1 cgd }
382 1.1 cgd
383 1.1 cgd if ((argp->flags & NFSMNT_RETRANS) && argp->retrans > 1) {
384 1.1 cgd nmp->nm_retry = argp->retrans;
385 1.1 cgd if (nmp->nm_retry > NFS_MAXREXMIT)
386 1.1 cgd nmp->nm_retry = NFS_MAXREXMIT;
387 1.1 cgd }
388 1.1 cgd
389 1.1 cgd if ((argp->flags & NFSMNT_WSIZE) && argp->wsize > 0) {
390 1.1 cgd nmp->nm_wsize = argp->wsize;
391 1.1 cgd /* Round down to multiple of blocksize */
392 1.1 cgd nmp->nm_wsize &= ~0x1ff;
393 1.1 cgd if (nmp->nm_wsize <= 0)
394 1.1 cgd nmp->nm_wsize = 512;
395 1.1 cgd else if (nmp->nm_wsize > NFS_MAXDATA)
396 1.1 cgd nmp->nm_wsize = NFS_MAXDATA;
397 1.1 cgd }
398 1.1 cgd if (nmp->nm_wsize > MAXBSIZE)
399 1.1 cgd nmp->nm_wsize = MAXBSIZE;
400 1.1 cgd
401 1.1 cgd if ((argp->flags & NFSMNT_RSIZE) && argp->rsize > 0) {
402 1.1 cgd nmp->nm_rsize = argp->rsize;
403 1.1 cgd /* Round down to multiple of blocksize */
404 1.1 cgd nmp->nm_rsize &= ~0x1ff;
405 1.1 cgd if (nmp->nm_rsize <= 0)
406 1.1 cgd nmp->nm_rsize = 512;
407 1.1 cgd else if (nmp->nm_rsize > NFS_MAXDATA)
408 1.1 cgd nmp->nm_rsize = NFS_MAXDATA;
409 1.1 cgd }
410 1.1 cgd if (nmp->nm_rsize > MAXBSIZE)
411 1.1 cgd nmp->nm_rsize = MAXBSIZE;
412 1.1 cgd /* Set up the sockets and per-host congestion */
413 1.1 cgd nmp->nm_sotype = argp->sotype;
414 1.1 cgd nmp->nm_soproto = argp->proto;
415 1.1 cgd if (error = nfs_connect(nmp))
416 1.1 cgd goto bad;
417 1.1 cgd
418 1.1 cgd if (error = nfs_statfs(mp, &mp->mnt_stat, p))
419 1.1 cgd goto bad;
420 1.1 cgd /*
421 1.1 cgd * A reference count is needed on the nfsnode representing the
422 1.1 cgd * remote root. If this object is not persistent, then backward
423 1.1 cgd * traversals of the mount point (i.e. "..") will not work if
424 1.1 cgd * the nfsnode gets flushed out of the cache. Ufs does not have
425 1.1 cgd * this problem, because one can identify root inodes by their
426 1.1 cgd * number == ROOTINO (2).
427 1.1 cgd */
428 1.1 cgd if (error = nfs_nget(mp, &nmp->nm_fh, &np))
429 1.1 cgd goto bad;
430 1.1 cgd /*
431 1.1 cgd * Unlock it, but keep the reference count.
432 1.1 cgd */
433 1.1 cgd nfs_unlock(NFSTOV(np));
434 1.1 cgd *vpp = NFSTOV(np);
435 1.1 cgd
436 1.1 cgd return (0);
437 1.1 cgd bad:
438 1.1 cgd nfs_disconnect(nmp);
439 1.1 cgd FREE(nmp, M_NFSMNT);
440 1.1 cgd m_freem(nam);
441 1.1 cgd return (error);
442 1.1 cgd }
443 1.1 cgd
444 1.1 cgd /*
445 1.1 cgd * unmount system call
446 1.1 cgd */
447 1.1 cgd nfs_unmount(mp, mntflags, p)
448 1.1 cgd struct mount *mp;
449 1.1 cgd int mntflags;
450 1.1 cgd struct proc *p;
451 1.1 cgd {
452 1.1 cgd register struct nfsmount *nmp;
453 1.1 cgd struct nfsnode *np;
454 1.1 cgd struct vnode *vp;
455 1.1 cgd int error, flags = 0;
456 1.1 cgd extern int doforce;
457 1.1 cgd
458 1.1 cgd if (mntflags & MNT_FORCE) {
459 1.1 cgd if (!doforce || mp == rootfs)
460 1.1 cgd return (EINVAL);
461 1.1 cgd flags |= FORCECLOSE;
462 1.1 cgd }
463 1.1 cgd nmp = VFSTONFS(mp);
464 1.1 cgd /*
465 1.1 cgd * Clear out the buffer cache
466 1.1 cgd */
467 1.1 cgd mntflushbuf(mp, 0);
468 1.1 cgd if (mntinvalbuf(mp))
469 1.1 cgd return (EBUSY);
470 1.1 cgd /*
471 1.1 cgd * Goes something like this..
472 1.1 cgd * - Check for activity on the root vnode (other than ourselves).
473 1.1 cgd * - Call vflush() to clear out vnodes for this file system,
474 1.1 cgd * except for the root vnode.
475 1.1 cgd * - Decrement reference on the vnode representing remote root.
476 1.1 cgd * - Close the socket
477 1.1 cgd * - Free up the data structures
478 1.1 cgd */
479 1.1 cgd /*
480 1.1 cgd * We need to decrement the ref. count on the nfsnode representing
481 1.1 cgd * the remote root. See comment in mountnfs(). The VFS unmount()
482 1.1 cgd * has done vput on this vnode, otherwise we would get deadlock!
483 1.1 cgd */
484 1.1 cgd if (error = nfs_nget(mp, &nmp->nm_fh, &np))
485 1.1 cgd return(error);
486 1.1 cgd vp = NFSTOV(np);
487 1.1 cgd if (vp->v_usecount > 2) {
488 1.1 cgd vput(vp);
489 1.1 cgd return (EBUSY);
490 1.1 cgd }
491 1.1 cgd if (error = vflush(mp, vp, flags)) {
492 1.1 cgd vput(vp);
493 1.1 cgd return (error);
494 1.1 cgd }
495 1.1 cgd /*
496 1.1 cgd * Get rid of two reference counts, and unlock it on the second.
497 1.1 cgd */
498 1.1 cgd vrele(vp);
499 1.1 cgd vput(vp);
500 1.1 cgd nfs_disconnect(nmp);
501 1.1 cgd m_freem(nmp->nm_nam);
502 1.1 cgd free((caddr_t)nmp, M_NFSMNT);
503 1.1 cgd return (0);
504 1.1 cgd }
505 1.1 cgd
506 1.1 cgd /*
507 1.1 cgd * Return root of a filesystem
508 1.1 cgd */
509 1.1 cgd nfs_root(mp, vpp)
510 1.1 cgd struct mount *mp;
511 1.1 cgd struct vnode **vpp;
512 1.1 cgd {
513 1.1 cgd register struct vnode *vp;
514 1.1 cgd struct nfsmount *nmp;
515 1.1 cgd struct nfsnode *np;
516 1.1 cgd int error;
517 1.1 cgd
518 1.1 cgd nmp = VFSTONFS(mp);
519 1.1 cgd if (error = nfs_nget(mp, &nmp->nm_fh, &np))
520 1.1 cgd return (error);
521 1.1 cgd vp = NFSTOV(np);
522 1.1 cgd vp->v_type = VDIR;
523 1.1 cgd vp->v_flag = VROOT;
524 1.1 cgd *vpp = vp;
525 1.1 cgd return (0);
526 1.1 cgd }
527 1.1 cgd
528 1.1 cgd extern int syncprt;
529 1.1 cgd
530 1.1 cgd /*
531 1.1 cgd * Flush out the buffer cache
532 1.1 cgd */
533 1.1 cgd /* ARGSUSED */
534 1.1 cgd nfs_sync(mp, waitfor)
535 1.1 cgd struct mount *mp;
536 1.1 cgd int waitfor;
537 1.1 cgd {
538 1.1 cgd if (syncprt)
539 1.1 cgd bufstats();
540 1.1 cgd /*
541 1.1 cgd * Force stale buffer cache information to be flushed.
542 1.1 cgd */
543 1.1 cgd mntflushbuf(mp, waitfor == MNT_WAIT ? B_SYNC : 0);
544 1.1 cgd return (0);
545 1.1 cgd }
546 1.1 cgd
547 1.1 cgd /*
548 1.1 cgd * At this point, this should never happen
549 1.1 cgd */
550 1.1 cgd /* ARGSUSED */
551 1.1 cgd nfs_fhtovp(mp, fhp, vpp)
552 1.1 cgd struct mount *mp;
553 1.1 cgd struct fid *fhp;
554 1.1 cgd struct vnode **vpp;
555 1.1 cgd {
556 1.1 cgd
557 1.1 cgd return (EINVAL);
558 1.1 cgd }
559 1.1 cgd
560 1.1 cgd /*
561 1.1 cgd * Vnode pointer to File handle, should never happen either
562 1.1 cgd */
563 1.1 cgd /* ARGSUSED */
564 1.1 cgd nfs_vptofh(vp, fhp)
565 1.1 cgd struct vnode *vp;
566 1.1 cgd struct fid *fhp;
567 1.1 cgd {
568 1.1 cgd
569 1.1 cgd return (EINVAL);
570 1.1 cgd }
571 1.1 cgd
572 1.1 cgd /*
573 1.1 cgd * Vfs start routine, a no-op.
574 1.1 cgd */
575 1.1 cgd /* ARGSUSED */
576 1.1 cgd nfs_start(mp, flags, p)
577 1.1 cgd struct mount *mp;
578 1.1 cgd int flags;
579 1.1 cgd struct proc *p;
580 1.1 cgd {
581 1.1 cgd
582 1.1 cgd return (0);
583 1.1 cgd }
584 1.1 cgd
585 1.1 cgd /*
586 1.1 cgd * Do operations associated with quotas, not supported
587 1.1 cgd */
588 1.1 cgd nfs_quotactl(mp, cmd, uid, arg, p)
589 1.1 cgd struct mount *mp;
590 1.1 cgd int cmd;
591 1.1 cgd uid_t uid;
592 1.1 cgd caddr_t arg;
593 1.1 cgd struct proc *p;
594 1.1 cgd {
595 1.1 cgd #ifdef lint
596 1.1 cgd mp = mp; cmd = cmd; uid = uid; arg = arg;
597 1.1 cgd #endif /* lint */
598 1.1 cgd return (EOPNOTSUPP);
599 1.1 cgd }
600