nfs_commonport.c revision 1.1.1.1.10.2 1 1.1.1.1.10.2 tls /* $NetBSD: nfs_commonport.c,v 1.1.1.1.10.2 2014/08/20 00:04:27 tls Exp $ */
2 1.1.1.1.10.2 tls /*-
3 1.1.1.1.10.2 tls * Copyright (c) 1989, 1993
4 1.1.1.1.10.2 tls * The Regents of the University of California. All rights reserved.
5 1.1.1.1.10.2 tls *
6 1.1.1.1.10.2 tls * This code is derived from software contributed to Berkeley by
7 1.1.1.1.10.2 tls * Rick Macklem at The University of Guelph.
8 1.1.1.1.10.2 tls *
9 1.1.1.1.10.2 tls * Redistribution and use in source and binary forms, with or without
10 1.1.1.1.10.2 tls * modification, are permitted provided that the following conditions
11 1.1.1.1.10.2 tls * are met:
12 1.1.1.1.10.2 tls * 1. Redistributions of source code must retain the above copyright
13 1.1.1.1.10.2 tls * notice, this list of conditions and the following disclaimer.
14 1.1.1.1.10.2 tls * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.1.1.10.2 tls * notice, this list of conditions and the following disclaimer in the
16 1.1.1.1.10.2 tls * documentation and/or other materials provided with the distribution.
17 1.1.1.1.10.2 tls * 4. Neither the name of the University nor the names of its contributors
18 1.1.1.1.10.2 tls * may be used to endorse or promote products derived from this software
19 1.1.1.1.10.2 tls * without specific prior written permission.
20 1.1.1.1.10.2 tls *
21 1.1.1.1.10.2 tls * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1.1.1.10.2 tls * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1.1.1.10.2 tls * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1.1.1.10.2 tls * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1.1.1.10.2 tls * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1.1.1.10.2 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1.1.1.10.2 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1.1.1.10.2 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1.1.1.10.2 tls * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1.1.1.10.2 tls * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1.1.1.10.2 tls * SUCH DAMAGE.
32 1.1.1.1.10.2 tls *
33 1.1.1.1.10.2 tls */
34 1.1.1.1.10.2 tls
35 1.1.1.1.10.2 tls #include <sys/cdefs.h>
36 1.1.1.1.10.2 tls /* __FBSDID("FreeBSD: head/sys/fs/nfs/nfs_commonport.c 249592 2013-04-17 21:00:22Z ken "); */
37 1.1.1.1.10.2 tls __RCSID("$NetBSD: nfs_commonport.c,v 1.1.1.1.10.2 2014/08/20 00:04:27 tls Exp $");
38 1.1.1.1.10.2 tls
39 1.1.1.1.10.2 tls /*
40 1.1.1.1.10.2 tls * Functions that need to be different for different versions of BSD
41 1.1.1.1.10.2 tls * kernel should be kept here, along with any global storage specific
42 1.1.1.1.10.2 tls * to this BSD variant.
43 1.1.1.1.10.2 tls */
44 1.1.1.1.10.2 tls #include <fs/nfs/nfsport.h>
45 1.1.1.1.10.2 tls #include <sys/sysctl.h>
46 1.1.1.1.10.2 tls #include <vm/vm.h>
47 1.1.1.1.10.2 tls #include <vm/vm_object.h>
48 1.1.1.1.10.2 tls #include <vm/vm_page.h>
49 1.1.1.1.10.2 tls #include <vm/vm_param.h>
50 1.1.1.1.10.2 tls #include <vm/vm_map.h>
51 1.1.1.1.10.2 tls #include <vm/vm_kern.h>
52 1.1.1.1.10.2 tls #include <vm/vm_extern.h>
53 1.1.1.1.10.2 tls #include <vm/uma.h>
54 1.1.1.1.10.2 tls
55 1.1.1.1.10.2 tls extern int nfscl_ticks;
56 1.1.1.1.10.2 tls extern int nfsrv_nfsuserd;
57 1.1.1.1.10.2 tls extern struct nfssockreq nfsrv_nfsuserdsock;
58 1.1.1.1.10.2 tls extern void (*nfsd_call_recall)(struct vnode *, int, struct ucred *,
59 1.1.1.1.10.2 tls struct thread *);
60 1.1.1.1.10.2 tls extern int nfsrv_useacl;
61 1.1.1.1.10.2 tls struct mount nfsv4root_mnt;
62 1.1.1.1.10.2 tls int newnfs_numnfsd = 0;
63 1.1.1.1.10.2 tls struct nfsstats newnfsstats;
64 1.1.1.1.10.2 tls int nfs_numnfscbd = 0;
65 1.1.1.1.10.2 tls int nfscl_debuglevel = 0;
66 1.1.1.1.10.2 tls char nfsv4_callbackaddr[INET6_ADDRSTRLEN];
67 1.1.1.1.10.2 tls struct callout newnfsd_callout;
68 1.1.1.1.10.2 tls void (*nfsd_call_servertimer)(void) = NULL;
69 1.1.1.1.10.2 tls void (*ncl_call_invalcaches)(struct vnode *) = NULL;
70 1.1.1.1.10.2 tls
71 1.1.1.1.10.2 tls static int nfs_realign_test;
72 1.1.1.1.10.2 tls static int nfs_realign_count;
73 1.1.1.1.10.2 tls
74 1.1.1.1.10.2 tls SYSCTL_NODE(_vfs, OID_AUTO, nfs, CTLFLAG_RW, 0, "New NFS filesystem");
75 1.1.1.1.10.2 tls SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_test, CTLFLAG_RW, &nfs_realign_test,
76 1.1.1.1.10.2 tls 0, "Number of realign tests done");
77 1.1.1.1.10.2 tls SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_count, CTLFLAG_RW, &nfs_realign_count,
78 1.1.1.1.10.2 tls 0, "Number of mbuf realignments done");
79 1.1.1.1.10.2 tls SYSCTL_STRING(_vfs_nfs, OID_AUTO, callback_addr, CTLFLAG_RW,
80 1.1.1.1.10.2 tls nfsv4_callbackaddr, sizeof(nfsv4_callbackaddr),
81 1.1.1.1.10.2 tls "NFSv4 callback addr for server to use");
82 1.1.1.1.10.2 tls SYSCTL_INT(_vfs_nfs, OID_AUTO, debuglevel, CTLFLAG_RW, &nfscl_debuglevel,
83 1.1.1.1.10.2 tls 0, "Debug level for new nfs client");
84 1.1.1.1.10.2 tls
85 1.1.1.1.10.2 tls /*
86 1.1.1.1.10.2 tls * Defines for malloc
87 1.1.1.1.10.2 tls * (Here for FreeBSD, since they allocate storage.)
88 1.1.1.1.10.2 tls */
89 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSRVCACHE, "NFSD srvcache", "NFSD Server Request Cache");
90 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSDCLIENT, "NFSD V4client", "NFSD V4 Client Id");
91 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSDSTATE, "NFSD V4state",
92 1.1.1.1.10.2 tls "NFSD V4 State (Openowner, Open, Lockowner, Delegation");
93 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSDLOCK, "NFSD V4lock", "NFSD V4 byte range lock");
94 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSDLOCKFILE, "NFSD lckfile", "NFSD Open/Lock file");
95 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSSTRING, "NFSD string", "NFSD V4 long string");
96 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSUSERGROUP, "NFSD usrgroup", "NFSD V4 User/group map");
97 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSDREQ, "NFS req", "NFS request header");
98 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSFH, "NFS fh", "NFS file handle");
99 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSCLOWNER, "NFSCL owner", "NFSCL Open Owner");
100 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSCLOPEN, "NFSCL open", "NFSCL Open");
101 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSCLDELEG, "NFSCL deleg", "NFSCL Delegation");
102 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSCLCLIENT, "NFSCL client", "NFSCL Client");
103 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSCLLOCKOWNER, "NFSCL lckown", "NFSCL Lock Owner");
104 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSCLLOCK, "NFSCL lck", "NFSCL Lock");
105 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSV4NODE, "NEWNFSnode", "New nfs vnode");
106 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSDIRECTIO, "NEWdirectio", "New nfs Direct IO buffer");
107 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSDIROFF, "NFSCL diroffdiroff",
108 1.1.1.1.10.2 tls "New NFS directory offset data");
109 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSDROLLBACK, "NFSD rollback",
110 1.1.1.1.10.2 tls "New NFS local lock rollback");
111 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSLAYOUT, "NFSCL layout", "NFSv4.1 Layout");
112 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSFLAYOUT, "NFSCL flayout", "NFSv4.1 File Layout");
113 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSDEVINFO, "NFSCL devinfo", "NFSv4.1 Device Info");
114 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSSOCKREQ, "NFSCL sockreq", "NFS Sock Req");
115 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSCLDS, "NFSCL session", "NFSv4.1 Session");
116 1.1.1.1.10.2 tls MALLOC_DEFINE(M_NEWNFSLAYRECALL, "NFSCL layrecall", "NFSv4.1 Layout Recall");
117 1.1.1.1.10.2 tls
118 1.1.1.1.10.2 tls /*
119 1.1.1.1.10.2 tls * Definition of mutex locks.
120 1.1.1.1.10.2 tls * newnfsd_mtx is used in nfsrvd_nfsd() to protect the nfs socket list
121 1.1.1.1.10.2 tls * and assorted other nfsd structures.
122 1.1.1.1.10.2 tls */
123 1.1.1.1.10.2 tls struct mtx newnfsd_mtx;
124 1.1.1.1.10.2 tls struct mtx nfs_sockl_mutex;
125 1.1.1.1.10.2 tls struct mtx nfs_state_mutex;
126 1.1.1.1.10.2 tls struct mtx nfs_nameid_mutex;
127 1.1.1.1.10.2 tls struct mtx nfs_req_mutex;
128 1.1.1.1.10.2 tls struct mtx nfs_slock_mutex;
129 1.1.1.1.10.2 tls
130 1.1.1.1.10.2 tls /* local functions */
131 1.1.1.1.10.2 tls static int nfssvc_call(struct thread *, struct nfssvc_args *, struct ucred *);
132 1.1.1.1.10.2 tls
133 1.1.1.1.10.2 tls #ifdef __NO_STRICT_ALIGNMENT
134 1.1.1.1.10.2 tls /*
135 1.1.1.1.10.2 tls * These architectures don't need re-alignment, so just return.
136 1.1.1.1.10.2 tls */
137 1.1.1.1.10.2 tls int
138 1.1.1.1.10.2 tls newnfs_realign(struct mbuf **pm, int how)
139 1.1.1.1.10.2 tls {
140 1.1.1.1.10.2 tls
141 1.1.1.1.10.2 tls return (0);
142 1.1.1.1.10.2 tls }
143 1.1.1.1.10.2 tls #else /* !__NO_STRICT_ALIGNMENT */
144 1.1.1.1.10.2 tls /*
145 1.1.1.1.10.2 tls * newnfs_realign:
146 1.1.1.1.10.2 tls *
147 1.1.1.1.10.2 tls * Check for badly aligned mbuf data and realign by copying the unaligned
148 1.1.1.1.10.2 tls * portion of the data into a new mbuf chain and freeing the portions
149 1.1.1.1.10.2 tls * of the old chain that were replaced.
150 1.1.1.1.10.2 tls *
151 1.1.1.1.10.2 tls * We cannot simply realign the data within the existing mbuf chain
152 1.1.1.1.10.2 tls * because the underlying buffers may contain other rpc commands and
153 1.1.1.1.10.2 tls * we cannot afford to overwrite them.
154 1.1.1.1.10.2 tls *
155 1.1.1.1.10.2 tls * We would prefer to avoid this situation entirely. The situation does
156 1.1.1.1.10.2 tls * not occur with NFS/UDP and is supposed to only occassionally occur
157 1.1.1.1.10.2 tls * with TCP. Use vfs.nfs.realign_count and realign_test to check this.
158 1.1.1.1.10.2 tls *
159 1.1.1.1.10.2 tls */
160 1.1.1.1.10.2 tls int
161 1.1.1.1.10.2 tls newnfs_realign(struct mbuf **pm, int how)
162 1.1.1.1.10.2 tls {
163 1.1.1.1.10.2 tls struct mbuf *m, *n;
164 1.1.1.1.10.2 tls int off, space;
165 1.1.1.1.10.2 tls
166 1.1.1.1.10.2 tls ++nfs_realign_test;
167 1.1.1.1.10.2 tls while ((m = *pm) != NULL) {
168 1.1.1.1.10.2 tls if ((m->m_len & 0x3) || (mtod(m, intptr_t) & 0x3)) {
169 1.1.1.1.10.2 tls /*
170 1.1.1.1.10.2 tls * NB: we can't depend on m_pkthdr.len to help us
171 1.1.1.1.10.2 tls * decide what to do here. May not be worth doing
172 1.1.1.1.10.2 tls * the m_length calculation as m_copyback will
173 1.1.1.1.10.2 tls * expand the mbuf chain below as needed.
174 1.1.1.1.10.2 tls */
175 1.1.1.1.10.2 tls space = m_length(m, NULL);
176 1.1.1.1.10.2 tls if (space >= MINCLSIZE) {
177 1.1.1.1.10.2 tls /* NB: m_copyback handles space > MCLBYTES */
178 1.1.1.1.10.2 tls n = m_getcl(how, MT_DATA, 0);
179 1.1.1.1.10.2 tls } else
180 1.1.1.1.10.2 tls n = m_get(how, MT_DATA);
181 1.1.1.1.10.2 tls if (n == NULL)
182 1.1.1.1.10.2 tls return (ENOMEM);
183 1.1.1.1.10.2 tls /*
184 1.1.1.1.10.2 tls * Align the remainder of the mbuf chain.
185 1.1.1.1.10.2 tls */
186 1.1.1.1.10.2 tls n->m_len = 0;
187 1.1.1.1.10.2 tls off = 0;
188 1.1.1.1.10.2 tls while (m != NULL) {
189 1.1.1.1.10.2 tls m_copyback(n, off, m->m_len, mtod(m, caddr_t));
190 1.1.1.1.10.2 tls off += m->m_len;
191 1.1.1.1.10.2 tls m = m->m_next;
192 1.1.1.1.10.2 tls }
193 1.1.1.1.10.2 tls m_freem(*pm);
194 1.1.1.1.10.2 tls *pm = n;
195 1.1.1.1.10.2 tls ++nfs_realign_count;
196 1.1.1.1.10.2 tls break;
197 1.1.1.1.10.2 tls }
198 1.1.1.1.10.2 tls pm = &m->m_next;
199 1.1.1.1.10.2 tls }
200 1.1.1.1.10.2 tls
201 1.1.1.1.10.2 tls return (0);
202 1.1.1.1.10.2 tls }
203 1.1.1.1.10.2 tls #endif /* __NO_STRICT_ALIGNMENT */
204 1.1.1.1.10.2 tls
205 1.1.1.1.10.2 tls #ifdef notdef
206 1.1.1.1.10.2 tls static void
207 1.1.1.1.10.2 tls nfsrv_object_create(struct vnode *vp, struct thread *td)
208 1.1.1.1.10.2 tls {
209 1.1.1.1.10.2 tls
210 1.1.1.1.10.2 tls if (vp == NULL || vp->v_type != VREG)
211 1.1.1.1.10.2 tls return;
212 1.1.1.1.10.2 tls (void) vfs_object_create(vp, td, td->td_ucred);
213 1.1.1.1.10.2 tls }
214 1.1.1.1.10.2 tls #endif
215 1.1.1.1.10.2 tls
216 1.1.1.1.10.2 tls /*
217 1.1.1.1.10.2 tls * Look up a file name. Basically just initialize stuff and call namei().
218 1.1.1.1.10.2 tls */
219 1.1.1.1.10.2 tls int
220 1.1.1.1.10.2 tls nfsrv_lookupfilename(struct nameidata *ndp, char *fname, NFSPROC_T *p)
221 1.1.1.1.10.2 tls {
222 1.1.1.1.10.2 tls int error;
223 1.1.1.1.10.2 tls
224 1.1.1.1.10.2 tls NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, fname,
225 1.1.1.1.10.2 tls p);
226 1.1.1.1.10.2 tls error = namei(ndp);
227 1.1.1.1.10.2 tls if (!error) {
228 1.1.1.1.10.2 tls NDFREE(ndp, NDF_ONLY_PNBUF);
229 1.1.1.1.10.2 tls }
230 1.1.1.1.10.2 tls return (error);
231 1.1.1.1.10.2 tls }
232 1.1.1.1.10.2 tls
233 1.1.1.1.10.2 tls /*
234 1.1.1.1.10.2 tls * Copy NFS uid, gids to the cred structure.
235 1.1.1.1.10.2 tls */
236 1.1.1.1.10.2 tls void
237 1.1.1.1.10.2 tls newnfs_copycred(struct nfscred *nfscr, struct ucred *cr)
238 1.1.1.1.10.2 tls {
239 1.1.1.1.10.2 tls
240 1.1.1.1.10.2 tls KASSERT(nfscr->nfsc_ngroups >= 0,
241 1.1.1.1.10.2 tls ("newnfs_copycred: negative nfsc_ngroups"));
242 1.1.1.1.10.2 tls cr->cr_uid = nfscr->nfsc_uid;
243 1.1.1.1.10.2 tls crsetgroups(cr, nfscr->nfsc_ngroups, nfscr->nfsc_groups);
244 1.1.1.1.10.2 tls }
245 1.1.1.1.10.2 tls
246 1.1.1.1.10.2 tls /*
247 1.1.1.1.10.2 tls * Map args from nfsmsleep() to msleep().
248 1.1.1.1.10.2 tls */
249 1.1.1.1.10.2 tls int
250 1.1.1.1.10.2 tls nfsmsleep(void *chan, void *mutex, int prio, const char *wmesg,
251 1.1.1.1.10.2 tls struct timespec *ts)
252 1.1.1.1.10.2 tls {
253 1.1.1.1.10.2 tls u_int64_t nsecval;
254 1.1.1.1.10.2 tls int error, timeo;
255 1.1.1.1.10.2 tls
256 1.1.1.1.10.2 tls if (ts) {
257 1.1.1.1.10.2 tls timeo = hz * ts->tv_sec;
258 1.1.1.1.10.2 tls nsecval = (u_int64_t)ts->tv_nsec;
259 1.1.1.1.10.2 tls nsecval = ((nsecval * ((u_int64_t)hz)) + 500000000) /
260 1.1.1.1.10.2 tls 1000000000;
261 1.1.1.1.10.2 tls timeo += (int)nsecval;
262 1.1.1.1.10.2 tls } else {
263 1.1.1.1.10.2 tls timeo = 0;
264 1.1.1.1.10.2 tls }
265 1.1.1.1.10.2 tls error = msleep(chan, (struct mtx *)mutex, prio, wmesg, timeo);
266 1.1.1.1.10.2 tls return (error);
267 1.1.1.1.10.2 tls }
268 1.1.1.1.10.2 tls
269 1.1.1.1.10.2 tls /*
270 1.1.1.1.10.2 tls * Get the file system info for the server. For now, just assume FFS.
271 1.1.1.1.10.2 tls */
272 1.1.1.1.10.2 tls void
273 1.1.1.1.10.2 tls nfsvno_getfs(struct nfsfsinfo *sip, int isdgram)
274 1.1.1.1.10.2 tls {
275 1.1.1.1.10.2 tls int pref;
276 1.1.1.1.10.2 tls
277 1.1.1.1.10.2 tls /*
278 1.1.1.1.10.2 tls * XXX
279 1.1.1.1.10.2 tls * There should be file system VFS OP(s) to get this information.
280 1.1.1.1.10.2 tls * For now, assume ufs.
281 1.1.1.1.10.2 tls */
282 1.1.1.1.10.2 tls if (isdgram)
283 1.1.1.1.10.2 tls pref = NFS_MAXDGRAMDATA;
284 1.1.1.1.10.2 tls else
285 1.1.1.1.10.2 tls pref = NFS_MAXDATA;
286 1.1.1.1.10.2 tls sip->fs_rtmax = NFS_MAXDATA;
287 1.1.1.1.10.2 tls sip->fs_rtpref = pref;
288 1.1.1.1.10.2 tls sip->fs_rtmult = NFS_FABLKSIZE;
289 1.1.1.1.10.2 tls sip->fs_wtmax = NFS_MAXDATA;
290 1.1.1.1.10.2 tls sip->fs_wtpref = pref;
291 1.1.1.1.10.2 tls sip->fs_wtmult = NFS_FABLKSIZE;
292 1.1.1.1.10.2 tls sip->fs_dtpref = pref;
293 1.1.1.1.10.2 tls sip->fs_maxfilesize = 0xffffffffffffffffull;
294 1.1.1.1.10.2 tls sip->fs_timedelta.tv_sec = 0;
295 1.1.1.1.10.2 tls sip->fs_timedelta.tv_nsec = 1;
296 1.1.1.1.10.2 tls sip->fs_properties = (NFSV3FSINFO_LINK |
297 1.1.1.1.10.2 tls NFSV3FSINFO_SYMLINK | NFSV3FSINFO_HOMOGENEOUS |
298 1.1.1.1.10.2 tls NFSV3FSINFO_CANSETTIME);
299 1.1.1.1.10.2 tls }
300 1.1.1.1.10.2 tls
301 1.1.1.1.10.2 tls /*
302 1.1.1.1.10.2 tls * Do the pathconf vnode op.
303 1.1.1.1.10.2 tls */
304 1.1.1.1.10.2 tls int
305 1.1.1.1.10.2 tls nfsvno_pathconf(struct vnode *vp, int flag, register_t *retf,
306 1.1.1.1.10.2 tls struct ucred *cred, struct thread *p)
307 1.1.1.1.10.2 tls {
308 1.1.1.1.10.2 tls int error;
309 1.1.1.1.10.2 tls
310 1.1.1.1.10.2 tls error = VOP_PATHCONF(vp, flag, retf);
311 1.1.1.1.10.2 tls if (error == EOPNOTSUPP || error == EINVAL) {
312 1.1.1.1.10.2 tls /*
313 1.1.1.1.10.2 tls * Some file systems return EINVAL for name arguments not
314 1.1.1.1.10.2 tls * supported and some return EOPNOTSUPP for this case.
315 1.1.1.1.10.2 tls * So the NFSv3 Pathconf RPC doesn't fail for these cases,
316 1.1.1.1.10.2 tls * just fake them.
317 1.1.1.1.10.2 tls */
318 1.1.1.1.10.2 tls switch (flag) {
319 1.1.1.1.10.2 tls case _PC_LINK_MAX:
320 1.1.1.1.10.2 tls *retf = LINK_MAX;
321 1.1.1.1.10.2 tls break;
322 1.1.1.1.10.2 tls case _PC_NAME_MAX:
323 1.1.1.1.10.2 tls *retf = NAME_MAX;
324 1.1.1.1.10.2 tls break;
325 1.1.1.1.10.2 tls case _PC_CHOWN_RESTRICTED:
326 1.1.1.1.10.2 tls *retf = 1;
327 1.1.1.1.10.2 tls break;
328 1.1.1.1.10.2 tls case _PC_NO_TRUNC:
329 1.1.1.1.10.2 tls *retf = 1;
330 1.1.1.1.10.2 tls break;
331 1.1.1.1.10.2 tls default:
332 1.1.1.1.10.2 tls /*
333 1.1.1.1.10.2 tls * Only happens if a _PC_xxx is added to the server,
334 1.1.1.1.10.2 tls * but this isn't updated.
335 1.1.1.1.10.2 tls */
336 1.1.1.1.10.2 tls *retf = 0;
337 1.1.1.1.10.2 tls printf("nfsrvd pathconf flag=%d not supp\n", flag);
338 1.1.1.1.10.2 tls };
339 1.1.1.1.10.2 tls error = 0;
340 1.1.1.1.10.2 tls }
341 1.1.1.1.10.2 tls NFSEXITCODE(error);
342 1.1.1.1.10.2 tls return (error);
343 1.1.1.1.10.2 tls }
344 1.1.1.1.10.2 tls
345 1.1.1.1.10.2 tls /* Fake nfsrv_atroot. Just return 0 */
346 1.1.1.1.10.2 tls int
347 1.1.1.1.10.2 tls nfsrv_atroot(struct vnode *vp, long *retp)
348 1.1.1.1.10.2 tls {
349 1.1.1.1.10.2 tls
350 1.1.1.1.10.2 tls return (0);
351 1.1.1.1.10.2 tls }
352 1.1.1.1.10.2 tls
353 1.1.1.1.10.2 tls /*
354 1.1.1.1.10.2 tls * Set the credentials to refer to root.
355 1.1.1.1.10.2 tls * If only the various BSDen could agree on whether cr_gid is a separate
356 1.1.1.1.10.2 tls * field or cr_groups[0]...
357 1.1.1.1.10.2 tls */
358 1.1.1.1.10.2 tls void
359 1.1.1.1.10.2 tls newnfs_setroot(struct ucred *cred)
360 1.1.1.1.10.2 tls {
361 1.1.1.1.10.2 tls
362 1.1.1.1.10.2 tls cred->cr_uid = 0;
363 1.1.1.1.10.2 tls cred->cr_groups[0] = 0;
364 1.1.1.1.10.2 tls cred->cr_ngroups = 1;
365 1.1.1.1.10.2 tls }
366 1.1.1.1.10.2 tls
367 1.1.1.1.10.2 tls /*
368 1.1.1.1.10.2 tls * Get the client credential. Used for Renew and recovery.
369 1.1.1.1.10.2 tls */
370 1.1.1.1.10.2 tls struct ucred *
371 1.1.1.1.10.2 tls newnfs_getcred(void)
372 1.1.1.1.10.2 tls {
373 1.1.1.1.10.2 tls struct ucred *cred;
374 1.1.1.1.10.2 tls struct thread *td = curthread;
375 1.1.1.1.10.2 tls
376 1.1.1.1.10.2 tls cred = crdup(td->td_ucred);
377 1.1.1.1.10.2 tls newnfs_setroot(cred);
378 1.1.1.1.10.2 tls return (cred);
379 1.1.1.1.10.2 tls }
380 1.1.1.1.10.2 tls
381 1.1.1.1.10.2 tls /*
382 1.1.1.1.10.2 tls * Nfs timer routine
383 1.1.1.1.10.2 tls * Call the nfsd's timer function once/sec.
384 1.1.1.1.10.2 tls */
385 1.1.1.1.10.2 tls void
386 1.1.1.1.10.2 tls newnfs_timer(void *arg)
387 1.1.1.1.10.2 tls {
388 1.1.1.1.10.2 tls static time_t lasttime = 0;
389 1.1.1.1.10.2 tls /*
390 1.1.1.1.10.2 tls * Call the server timer, if set up.
391 1.1.1.1.10.2 tls * The argument indicates if it is the next second and therefore
392 1.1.1.1.10.2 tls * leases should be checked.
393 1.1.1.1.10.2 tls */
394 1.1.1.1.10.2 tls if (lasttime != NFSD_MONOSEC) {
395 1.1.1.1.10.2 tls lasttime = NFSD_MONOSEC;
396 1.1.1.1.10.2 tls if (nfsd_call_servertimer != NULL)
397 1.1.1.1.10.2 tls (*nfsd_call_servertimer)();
398 1.1.1.1.10.2 tls }
399 1.1.1.1.10.2 tls callout_reset(&newnfsd_callout, nfscl_ticks, newnfs_timer, NULL);
400 1.1.1.1.10.2 tls }
401 1.1.1.1.10.2 tls
402 1.1.1.1.10.2 tls
403 1.1.1.1.10.2 tls /*
404 1.1.1.1.10.2 tls * Sleep for a short period of time unless errval == NFSERR_GRACE, where
405 1.1.1.1.10.2 tls * the sleep should be for 5 seconds.
406 1.1.1.1.10.2 tls * Since lbolt doesn't exist in FreeBSD-CURRENT, just use a timeout on
407 1.1.1.1.10.2 tls * an event that never gets a wakeup. Only return EINTR or 0.
408 1.1.1.1.10.2 tls */
409 1.1.1.1.10.2 tls int
410 1.1.1.1.10.2 tls nfs_catnap(int prio, int errval, const char *wmesg)
411 1.1.1.1.10.2 tls {
412 1.1.1.1.10.2 tls static int non_event;
413 1.1.1.1.10.2 tls int ret;
414 1.1.1.1.10.2 tls
415 1.1.1.1.10.2 tls if (errval == NFSERR_GRACE)
416 1.1.1.1.10.2 tls ret = tsleep(&non_event, prio, wmesg, 5 * hz);
417 1.1.1.1.10.2 tls else
418 1.1.1.1.10.2 tls ret = tsleep(&non_event, prio, wmesg, 1);
419 1.1.1.1.10.2 tls if (ret != EINTR)
420 1.1.1.1.10.2 tls ret = 0;
421 1.1.1.1.10.2 tls return (ret);
422 1.1.1.1.10.2 tls }
423 1.1.1.1.10.2 tls
424 1.1.1.1.10.2 tls /*
425 1.1.1.1.10.2 tls * Get referral. For now, just fail.
426 1.1.1.1.10.2 tls */
427 1.1.1.1.10.2 tls struct nfsreferral *
428 1.1.1.1.10.2 tls nfsv4root_getreferral(struct vnode *vp, struct vnode *dvp, u_int32_t fileno)
429 1.1.1.1.10.2 tls {
430 1.1.1.1.10.2 tls
431 1.1.1.1.10.2 tls return (NULL);
432 1.1.1.1.10.2 tls }
433 1.1.1.1.10.2 tls
434 1.1.1.1.10.2 tls static int
435 1.1.1.1.10.2 tls nfssvc_nfscommon(struct thread *td, struct nfssvc_args *uap)
436 1.1.1.1.10.2 tls {
437 1.1.1.1.10.2 tls int error;
438 1.1.1.1.10.2 tls
439 1.1.1.1.10.2 tls error = nfssvc_call(td, uap, td->td_ucred);
440 1.1.1.1.10.2 tls NFSEXITCODE(error);
441 1.1.1.1.10.2 tls return (error);
442 1.1.1.1.10.2 tls }
443 1.1.1.1.10.2 tls
444 1.1.1.1.10.2 tls static int
445 1.1.1.1.10.2 tls nfssvc_call(struct thread *p, struct nfssvc_args *uap, struct ucred *cred)
446 1.1.1.1.10.2 tls {
447 1.1.1.1.10.2 tls int error = EINVAL;
448 1.1.1.1.10.2 tls struct nfsd_idargs nid;
449 1.1.1.1.10.2 tls
450 1.1.1.1.10.2 tls if (uap->flag & NFSSVC_IDNAME) {
451 1.1.1.1.10.2 tls error = copyin(uap->argp, (caddr_t)&nid, sizeof (nid));
452 1.1.1.1.10.2 tls if (error)
453 1.1.1.1.10.2 tls goto out;
454 1.1.1.1.10.2 tls error = nfssvc_idname(&nid);
455 1.1.1.1.10.2 tls goto out;
456 1.1.1.1.10.2 tls } else if (uap->flag & NFSSVC_GETSTATS) {
457 1.1.1.1.10.2 tls error = copyout(&newnfsstats,
458 1.1.1.1.10.2 tls CAST_USER_ADDR_T(uap->argp), sizeof (newnfsstats));
459 1.1.1.1.10.2 tls if (error == 0) {
460 1.1.1.1.10.2 tls if ((uap->flag & NFSSVC_ZEROCLTSTATS) != 0) {
461 1.1.1.1.10.2 tls newnfsstats.attrcache_hits = 0;
462 1.1.1.1.10.2 tls newnfsstats.attrcache_misses = 0;
463 1.1.1.1.10.2 tls newnfsstats.lookupcache_hits = 0;
464 1.1.1.1.10.2 tls newnfsstats.lookupcache_misses = 0;
465 1.1.1.1.10.2 tls newnfsstats.direofcache_hits = 0;
466 1.1.1.1.10.2 tls newnfsstats.direofcache_misses = 0;
467 1.1.1.1.10.2 tls newnfsstats.accesscache_hits = 0;
468 1.1.1.1.10.2 tls newnfsstats.accesscache_misses = 0;
469 1.1.1.1.10.2 tls newnfsstats.biocache_reads = 0;
470 1.1.1.1.10.2 tls newnfsstats.read_bios = 0;
471 1.1.1.1.10.2 tls newnfsstats.read_physios = 0;
472 1.1.1.1.10.2 tls newnfsstats.biocache_writes = 0;
473 1.1.1.1.10.2 tls newnfsstats.write_bios = 0;
474 1.1.1.1.10.2 tls newnfsstats.write_physios = 0;
475 1.1.1.1.10.2 tls newnfsstats.biocache_readlinks = 0;
476 1.1.1.1.10.2 tls newnfsstats.readlink_bios = 0;
477 1.1.1.1.10.2 tls newnfsstats.biocache_readdirs = 0;
478 1.1.1.1.10.2 tls newnfsstats.readdir_bios = 0;
479 1.1.1.1.10.2 tls newnfsstats.rpcretries = 0;
480 1.1.1.1.10.2 tls newnfsstats.rpcrequests = 0;
481 1.1.1.1.10.2 tls newnfsstats.rpctimeouts = 0;
482 1.1.1.1.10.2 tls newnfsstats.rpcunexpected = 0;
483 1.1.1.1.10.2 tls newnfsstats.rpcinvalid = 0;
484 1.1.1.1.10.2 tls bzero(newnfsstats.rpccnt,
485 1.1.1.1.10.2 tls sizeof(newnfsstats.rpccnt));
486 1.1.1.1.10.2 tls }
487 1.1.1.1.10.2 tls if ((uap->flag & NFSSVC_ZEROSRVSTATS) != 0) {
488 1.1.1.1.10.2 tls newnfsstats.srvrpc_errs = 0;
489 1.1.1.1.10.2 tls newnfsstats.srv_errs = 0;
490 1.1.1.1.10.2 tls newnfsstats.srvcache_inproghits = 0;
491 1.1.1.1.10.2 tls newnfsstats.srvcache_idemdonehits = 0;
492 1.1.1.1.10.2 tls newnfsstats.srvcache_nonidemdonehits = 0;
493 1.1.1.1.10.2 tls newnfsstats.srvcache_misses = 0;
494 1.1.1.1.10.2 tls newnfsstats.srvcache_tcppeak = 0;
495 1.1.1.1.10.2 tls newnfsstats.srvclients = 0;
496 1.1.1.1.10.2 tls newnfsstats.srvopenowners = 0;
497 1.1.1.1.10.2 tls newnfsstats.srvopens = 0;
498 1.1.1.1.10.2 tls newnfsstats.srvlockowners = 0;
499 1.1.1.1.10.2 tls newnfsstats.srvlocks = 0;
500 1.1.1.1.10.2 tls newnfsstats.srvdelegates = 0;
501 1.1.1.1.10.2 tls newnfsstats.clopenowners = 0;
502 1.1.1.1.10.2 tls newnfsstats.clopens = 0;
503 1.1.1.1.10.2 tls newnfsstats.cllockowners = 0;
504 1.1.1.1.10.2 tls newnfsstats.cllocks = 0;
505 1.1.1.1.10.2 tls newnfsstats.cldelegates = 0;
506 1.1.1.1.10.2 tls newnfsstats.cllocalopenowners = 0;
507 1.1.1.1.10.2 tls newnfsstats.cllocalopens = 0;
508 1.1.1.1.10.2 tls newnfsstats.cllocallockowners = 0;
509 1.1.1.1.10.2 tls newnfsstats.cllocallocks = 0;
510 1.1.1.1.10.2 tls bzero(newnfsstats.srvrpccnt,
511 1.1.1.1.10.2 tls sizeof(newnfsstats.srvrpccnt));
512 1.1.1.1.10.2 tls bzero(newnfsstats.cbrpccnt,
513 1.1.1.1.10.2 tls sizeof(newnfsstats.cbrpccnt));
514 1.1.1.1.10.2 tls }
515 1.1.1.1.10.2 tls }
516 1.1.1.1.10.2 tls goto out;
517 1.1.1.1.10.2 tls } else if (uap->flag & NFSSVC_NFSUSERDPORT) {
518 1.1.1.1.10.2 tls u_short sockport;
519 1.1.1.1.10.2 tls
520 1.1.1.1.10.2 tls error = copyin(uap->argp, (caddr_t)&sockport,
521 1.1.1.1.10.2 tls sizeof (u_short));
522 1.1.1.1.10.2 tls if (!error)
523 1.1.1.1.10.2 tls error = nfsrv_nfsuserdport(sockport, p);
524 1.1.1.1.10.2 tls } else if (uap->flag & NFSSVC_NFSUSERDDELPORT) {
525 1.1.1.1.10.2 tls nfsrv_nfsuserddelport();
526 1.1.1.1.10.2 tls error = 0;
527 1.1.1.1.10.2 tls }
528 1.1.1.1.10.2 tls
529 1.1.1.1.10.2 tls out:
530 1.1.1.1.10.2 tls NFSEXITCODE(error);
531 1.1.1.1.10.2 tls return (error);
532 1.1.1.1.10.2 tls }
533 1.1.1.1.10.2 tls
534 1.1.1.1.10.2 tls /*
535 1.1.1.1.10.2 tls * called by all three modevent routines, so that it gets things
536 1.1.1.1.10.2 tls * initialized soon enough.
537 1.1.1.1.10.2 tls */
538 1.1.1.1.10.2 tls void
539 1.1.1.1.10.2 tls newnfs_portinit(void)
540 1.1.1.1.10.2 tls {
541 1.1.1.1.10.2 tls static int inited = 0;
542 1.1.1.1.10.2 tls
543 1.1.1.1.10.2 tls if (inited)
544 1.1.1.1.10.2 tls return;
545 1.1.1.1.10.2 tls inited = 1;
546 1.1.1.1.10.2 tls /* Initialize SMP locks used by both client and server. */
547 1.1.1.1.10.2 tls mtx_init(&newnfsd_mtx, "newnfsd_mtx", NULL, MTX_DEF);
548 1.1.1.1.10.2 tls mtx_init(&nfs_state_mutex, "nfs_state_mutex", NULL, MTX_DEF);
549 1.1.1.1.10.2 tls }
550 1.1.1.1.10.2 tls
551 1.1.1.1.10.2 tls /*
552 1.1.1.1.10.2 tls * Determine if the file system supports NFSv4 ACLs.
553 1.1.1.1.10.2 tls * Return 1 if it does, 0 otherwise.
554 1.1.1.1.10.2 tls */
555 1.1.1.1.10.2 tls int
556 1.1.1.1.10.2 tls nfs_supportsnfsv4acls(struct vnode *vp)
557 1.1.1.1.10.2 tls {
558 1.1.1.1.10.2 tls int error;
559 1.1.1.1.10.2 tls register_t retval;
560 1.1.1.1.10.2 tls
561 1.1.1.1.10.2 tls ASSERT_VOP_LOCKED(vp, "nfs supports nfsv4acls");
562 1.1.1.1.10.2 tls
563 1.1.1.1.10.2 tls if (nfsrv_useacl == 0)
564 1.1.1.1.10.2 tls return (0);
565 1.1.1.1.10.2 tls error = VOP_PATHCONF(vp, _PC_ACL_NFS4, &retval);
566 1.1.1.1.10.2 tls if (error == 0 && retval != 0)
567 1.1.1.1.10.2 tls return (1);
568 1.1.1.1.10.2 tls return (0);
569 1.1.1.1.10.2 tls }
570 1.1.1.1.10.2 tls
571 1.1.1.1.10.2 tls extern int (*nfsd_call_nfscommon)(struct thread *, struct nfssvc_args *);
572 1.1.1.1.10.2 tls
573 1.1.1.1.10.2 tls /*
574 1.1.1.1.10.2 tls * Called once to initialize data structures...
575 1.1.1.1.10.2 tls */
576 1.1.1.1.10.2 tls static int
577 1.1.1.1.10.2 tls nfscommon_modevent(module_t mod, int type, void *data)
578 1.1.1.1.10.2 tls {
579 1.1.1.1.10.2 tls int error = 0;
580 1.1.1.1.10.2 tls static int loaded = 0;
581 1.1.1.1.10.2 tls
582 1.1.1.1.10.2 tls switch (type) {
583 1.1.1.1.10.2 tls case MOD_LOAD:
584 1.1.1.1.10.2 tls if (loaded)
585 1.1.1.1.10.2 tls goto out;
586 1.1.1.1.10.2 tls newnfs_portinit();
587 1.1.1.1.10.2 tls mtx_init(&nfs_nameid_mutex, "nfs_nameid_mutex", NULL, MTX_DEF);
588 1.1.1.1.10.2 tls mtx_init(&nfs_sockl_mutex, "nfs_sockl_mutex", NULL, MTX_DEF);
589 1.1.1.1.10.2 tls mtx_init(&nfs_slock_mutex, "nfs_slock_mutex", NULL, MTX_DEF);
590 1.1.1.1.10.2 tls mtx_init(&nfs_req_mutex, "nfs_req_mutex", NULL, MTX_DEF);
591 1.1.1.1.10.2 tls mtx_init(&nfsrv_nfsuserdsock.nr_mtx, "nfsuserd", NULL,
592 1.1.1.1.10.2 tls MTX_DEF);
593 1.1.1.1.10.2 tls callout_init(&newnfsd_callout, CALLOUT_MPSAFE);
594 1.1.1.1.10.2 tls newnfs_init();
595 1.1.1.1.10.2 tls nfsd_call_nfscommon = nfssvc_nfscommon;
596 1.1.1.1.10.2 tls loaded = 1;
597 1.1.1.1.10.2 tls break;
598 1.1.1.1.10.2 tls
599 1.1.1.1.10.2 tls case MOD_UNLOAD:
600 1.1.1.1.10.2 tls if (newnfs_numnfsd != 0 || nfsrv_nfsuserd != 0 ||
601 1.1.1.1.10.2 tls nfs_numnfscbd != 0) {
602 1.1.1.1.10.2 tls error = EBUSY;
603 1.1.1.1.10.2 tls break;
604 1.1.1.1.10.2 tls }
605 1.1.1.1.10.2 tls
606 1.1.1.1.10.2 tls nfsd_call_nfscommon = NULL;
607 1.1.1.1.10.2 tls callout_drain(&newnfsd_callout);
608 1.1.1.1.10.2 tls /* and get rid of the mutexes */
609 1.1.1.1.10.2 tls mtx_destroy(&nfs_nameid_mutex);
610 1.1.1.1.10.2 tls mtx_destroy(&newnfsd_mtx);
611 1.1.1.1.10.2 tls mtx_destroy(&nfs_state_mutex);
612 1.1.1.1.10.2 tls mtx_destroy(&nfs_sockl_mutex);
613 1.1.1.1.10.2 tls mtx_destroy(&nfs_slock_mutex);
614 1.1.1.1.10.2 tls mtx_destroy(&nfs_req_mutex);
615 1.1.1.1.10.2 tls mtx_destroy(&nfsrv_nfsuserdsock.nr_mtx);
616 1.1.1.1.10.2 tls loaded = 0;
617 1.1.1.1.10.2 tls break;
618 1.1.1.1.10.2 tls default:
619 1.1.1.1.10.2 tls error = EOPNOTSUPP;
620 1.1.1.1.10.2 tls break;
621 1.1.1.1.10.2 tls }
622 1.1.1.1.10.2 tls
623 1.1.1.1.10.2 tls out:
624 1.1.1.1.10.2 tls NFSEXITCODE(error);
625 1.1.1.1.10.2 tls return error;
626 1.1.1.1.10.2 tls }
627 1.1.1.1.10.2 tls static moduledata_t nfscommon_mod = {
628 1.1.1.1.10.2 tls "nfscommon",
629 1.1.1.1.10.2 tls nfscommon_modevent,
630 1.1.1.1.10.2 tls NULL,
631 1.1.1.1.10.2 tls };
632 1.1.1.1.10.2 tls DECLARE_MODULE(nfscommon, nfscommon_mod, SI_SUB_VFS, SI_ORDER_ANY);
633 1.1.1.1.10.2 tls
634 1.1.1.1.10.2 tls /* So that loader and kldload(2) can find us, wherever we are.. */
635 1.1.1.1.10.2 tls MODULE_VERSION(nfscommon, 1);
636 1.1.1.1.10.2 tls MODULE_DEPEND(nfscommon, nfssvc, 1, 1, 1);
637 1.1.1.1.10.2 tls MODULE_DEPEND(nfscommon, krpc, 1, 1, 1);
638 1.1.1.1.10.2 tls
639