Deleted Added
full compact
nfs_serv.c (164436) nfs_serv.c (164585)
1/*-
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 19 unchanged lines hidden (view full) ---

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
30 * SUCH DAMAGE.
31 *
32 * @(#)nfs_serv.c 8.8 (Berkeley) 7/31/95
33 */
34
35#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 19 unchanged lines hidden (view full) ---

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
30 * SUCH DAMAGE.
31 *
32 * @(#)nfs_serv.c 8.8 (Berkeley) 7/31/95
33 */
34
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD: head/sys/nfsserver/nfs_serv.c 164436 2006-11-20 07:32:52Z pjd $");
36__FBSDID("$FreeBSD: head/sys/nfsserver/nfs_serv.c 164585 2006-11-24 11:53:16Z rwatson $");
37
38/*
39 * nfs version 2 and 3 server calls to vnode ops
40 * - these routines generally have 3 phases
41 * 1 - break down and validate rpc request in mbuf list
42 * 2 - do the vnode ops for the request
43 * (surprisingly ?? many are very similar to syscalls in vfs_syscalls.c)
44 * 3 - build the rpc reply in an mbuf list

--- 87 unchanged lines hidden (view full) ---

132SYSCTL_INT(_vfs_nfsrv, OID_AUTO, async, CTLFLAG_RW, &nfs_async, 0, "");
133SYSCTL_INT(_vfs_nfsrv, OID_AUTO, commit_blks, CTLFLAG_RW, &nfs_commit_blks, 0, "");
134SYSCTL_INT(_vfs_nfsrv, OID_AUTO, commit_miss, CTLFLAG_RW, &nfs_commit_miss, 0, "");
135
136struct nfsrvstats nfsrvstats;
137SYSCTL_STRUCT(_vfs_nfsrv, NFS_NFSRVSTATS, nfsrvstats, CTLFLAG_RD,
138 &nfsrvstats, nfsrvstats, "S,nfsrvstats");
139
37
38/*
39 * nfs version 2 and 3 server calls to vnode ops
40 * - these routines generally have 3 phases
41 * 1 - break down and validate rpc request in mbuf list
42 * 2 - do the vnode ops for the request
43 * (surprisingly ?? many are very similar to syscalls in vfs_syscalls.c)
44 * 3 - build the rpc reply in an mbuf list

--- 87 unchanged lines hidden (view full) ---

132SYSCTL_INT(_vfs_nfsrv, OID_AUTO, async, CTLFLAG_RW, &nfs_async, 0, "");
133SYSCTL_INT(_vfs_nfsrv, OID_AUTO, commit_blks, CTLFLAG_RW, &nfs_commit_blks, 0, "");
134SYSCTL_INT(_vfs_nfsrv, OID_AUTO, commit_miss, CTLFLAG_RW, &nfs_commit_miss, 0, "");
135
136struct nfsrvstats nfsrvstats;
137SYSCTL_STRUCT(_vfs_nfsrv, NFS_NFSRVSTATS, nfsrvstats, CTLFLAG_RD,
138 &nfsrvstats, nfsrvstats, "S,nfsrvstats");
139
140static int nfsrv_access_withgiant(struct vnode *vp, int flags,
141 struct ucred *cred, int rdonly, struct thread *td,
142 int override);
143static int nfsrv_access(struct vnode *, int, struct ucred *, int,
144 struct thread *, int);
140static int nfsrv_access(struct vnode *vp, int flags, struct ucred *cred,
141 int rdonly, struct thread *td, int override);
145static void nfsrvw_coalesce(struct nfsrv_descript *,
146 struct nfsrv_descript *);
147
148/*
149 * Clear nameidata fields that are tested in nsfmout cleanup code prior
150 * to using first nfsm macro (that might jump to the cleanup code).
151 */
152

--- 23 unchanged lines hidden (view full) ---

176 fhandle_t *fhp;
177 u_int32_t *tl;
178 caddr_t bpos;
179 int error = 0, rdonly, getret;
180 struct mbuf *mb, *mreq;
181 struct vattr vattr, *vap = &vattr;
182 u_long testmode, nfsmode;
183 int v3 = (nfsd->nd_flag & ND_NFSV3);
142static void nfsrvw_coalesce(struct nfsrv_descript *,
143 struct nfsrv_descript *);
144
145/*
146 * Clear nameidata fields that are tested in nsfmout cleanup code prior
147 * to using first nfsm macro (that might jump to the cleanup code).
148 */
149

--- 23 unchanged lines hidden (view full) ---

173 fhandle_t *fhp;
174 u_int32_t *tl;
175 caddr_t bpos;
176 int error = 0, rdonly, getret;
177 struct mbuf *mb, *mreq;
178 struct vattr vattr, *vap = &vattr;
179 u_long testmode, nfsmode;
180 int v3 = (nfsd->nd_flag & ND_NFSV3);
181 int vfslocked;
184
185 NFSD_LOCK_ASSERT();
186
187 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
188 if (!v3)
189 panic("nfsrv3_access: v3 proc called on a v2 connection");
190 fhp = &nfh.fh_generic;
191 nfsm_srvmtofh(fhp);
192 tl = nfsm_dissect_nonblock(u_int32_t *, NFSX_UNSIGNED);
182
183 NFSD_LOCK_ASSERT();
184
185 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
186 if (!v3)
187 panic("nfsrv3_access: v3 proc called on a v2 connection");
188 fhp = &nfh.fh_generic;
189 nfsm_srvmtofh(fhp);
190 tl = nfsm_dissect_nonblock(u_int32_t *, NFSX_UNSIGNED);
193 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
191 NFSD_UNLOCK();
192 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly,
193 TRUE);
194 if (error) {
194 if (error) {
195 NFSD_LOCK();
195 nfsm_reply(NFSX_UNSIGNED);
196 nfsm_srvpostop_attr(1, NULL);
197 error = 0;
198 goto nfsmout;
199 }
200 nfsmode = fxdr_unsigned(u_int32_t, *tl);
196 nfsm_reply(NFSX_UNSIGNED);
197 nfsm_srvpostop_attr(1, NULL);
198 error = 0;
199 goto nfsmout;
200 }
201 nfsmode = fxdr_unsigned(u_int32_t, *tl);
201 NFSD_UNLOCK();
202 mtx_lock(&Giant); /* VFS */
202 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
203 if ((nfsmode & NFSV3ACCESS_READ) &&
203 if ((nfsmode & NFSV3ACCESS_READ) &&
204 nfsrv_access_withgiant(vp, VREAD, cred, rdonly, td, 0))
204 nfsrv_access(vp, VREAD, cred, rdonly, td, 0))
205 nfsmode &= ~NFSV3ACCESS_READ;
206 if (vp->v_type == VDIR)
207 testmode = (NFSV3ACCESS_MODIFY | NFSV3ACCESS_EXTEND |
208 NFSV3ACCESS_DELETE);
209 else
210 testmode = (NFSV3ACCESS_MODIFY | NFSV3ACCESS_EXTEND);
211 if ((nfsmode & testmode) &&
205 nfsmode &= ~NFSV3ACCESS_READ;
206 if (vp->v_type == VDIR)
207 testmode = (NFSV3ACCESS_MODIFY | NFSV3ACCESS_EXTEND |
208 NFSV3ACCESS_DELETE);
209 else
210 testmode = (NFSV3ACCESS_MODIFY | NFSV3ACCESS_EXTEND);
211 if ((nfsmode & testmode) &&
212 nfsrv_access_withgiant(vp, VWRITE, cred, rdonly, td, 0))
212 nfsrv_access(vp, VWRITE, cred, rdonly, td, 0))
213 nfsmode &= ~testmode;
214 if (vp->v_type == VDIR)
215 testmode = NFSV3ACCESS_LOOKUP;
216 else
217 testmode = NFSV3ACCESS_EXECUTE;
218 if ((nfsmode & testmode) &&
213 nfsmode &= ~testmode;
214 if (vp->v_type == VDIR)
215 testmode = NFSV3ACCESS_LOOKUP;
216 else
217 testmode = NFSV3ACCESS_EXECUTE;
218 if ((nfsmode & testmode) &&
219 nfsrv_access_withgiant(vp, VEXEC, cred, rdonly, td, 0))
219 nfsrv_access(vp, VEXEC, cred, rdonly, td, 0))
220 nfsmode &= ~testmode;
221 getret = VOP_GETATTR(vp, vap, cred, td);
222 vput(vp);
220 nfsmode &= ~testmode;
221 getret = VOP_GETATTR(vp, vap, cred, td);
222 vput(vp);
223 mtx_unlock(&Giant); /* VFS */
223 VFS_UNLOCK_GIANT(vfslocked);
224 vp = NULL;
225 NFSD_LOCK();
226 nfsm_reply(NFSX_POSTOPATTR(1) + NFSX_UNSIGNED);
227 nfsm_srvpostop_attr(getret, vap);
228 tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED);
229 *tl = txdr_unsigned(nfsmode);
230nfsmout:
231 NFSD_LOCK_ASSERT();
232 if (vp) {
233 NFSD_UNLOCK();
224 vp = NULL;
225 NFSD_LOCK();
226 nfsm_reply(NFSX_POSTOPATTR(1) + NFSX_UNSIGNED);
227 nfsm_srvpostop_attr(getret, vap);
228 tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED);
229 *tl = txdr_unsigned(nfsmode);
230nfsmout:
231 NFSD_LOCK_ASSERT();
232 if (vp) {
233 NFSD_UNLOCK();
234 mtx_lock(&Giant); /* VFS */
234 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
235 vput(vp);
235 vput(vp);
236 mtx_unlock(&Giant); /* VFS */
236 VFS_UNLOCK_GIANT(vfslocked);
237 NFSD_LOCK();
238 }
239 return(error);
240}
241
242/*
243 * nfs getattr service
244 */

--- 9 unchanged lines hidden (view full) ---

254 struct vattr va;
255 struct vattr *vap = &va;
256 struct vnode *vp = NULL;
257 nfsfh_t nfh;
258 fhandle_t *fhp;
259 caddr_t bpos;
260 int error = 0, rdonly;
261 struct mbuf *mb, *mreq;
237 NFSD_LOCK();
238 }
239 return(error);
240}
241
242/*
243 * nfs getattr service
244 */

--- 9 unchanged lines hidden (view full) ---

254 struct vattr va;
255 struct vattr *vap = &va;
256 struct vnode *vp = NULL;
257 nfsfh_t nfh;
258 fhandle_t *fhp;
259 caddr_t bpos;
260 int error = 0, rdonly;
261 struct mbuf *mb, *mreq;
262 int vfslocked;
262
263 NFSD_LOCK_ASSERT();
264
265 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
266 fhp = &nfh.fh_generic;
267 nfsm_srvmtofh(fhp);
263
264 NFSD_LOCK_ASSERT();
265
266 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
267 fhp = &nfh.fh_generic;
268 nfsm_srvmtofh(fhp);
269 NFSD_UNLOCK();
268 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
269 if (error) {
270 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
271 if (error) {
272 NFSD_LOCK();
270 nfsm_reply(0);
271 error = 0;
272 goto nfsmout;
273 }
273 nfsm_reply(0);
274 error = 0;
275 goto nfsmout;
276 }
274 NFSD_UNLOCK();
275 mtx_lock(&Giant); /* VFS */
277 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
276 error = VOP_GETATTR(vp, vap, cred, td);
277 vput(vp);
278 error = VOP_GETATTR(vp, vap, cred, td);
279 vput(vp);
278 mtx_unlock(&Giant); /* VFS */
280 VFS_UNLOCK_GIANT(vfslocked);
279 vp = NULL;
280 NFSD_LOCK();
281 nfsm_reply(NFSX_FATTR(nfsd->nd_flag & ND_NFSV3));
282 if (error) {
283 error = 0;
284 goto nfsmout;
285 }
286 fp = nfsm_build(struct nfs_fattr *,
287 NFSX_FATTR(nfsd->nd_flag & ND_NFSV3));
288 nfsm_srvfillattr(vap, fp);
289 /* fall through */
290
291nfsmout:
292 NFSD_LOCK_ASSERT();
293 if (vp) {
294 NFSD_UNLOCK();
281 vp = NULL;
282 NFSD_LOCK();
283 nfsm_reply(NFSX_FATTR(nfsd->nd_flag & ND_NFSV3));
284 if (error) {
285 error = 0;
286 goto nfsmout;
287 }
288 fp = nfsm_build(struct nfs_fattr *,
289 NFSX_FATTR(nfsd->nd_flag & ND_NFSV3));
290 nfsm_srvfillattr(vap, fp);
291 /* fall through */
292
293nfsmout:
294 NFSD_LOCK_ASSERT();
295 if (vp) {
296 NFSD_UNLOCK();
295 mtx_lock(&Giant); /* VFS */
297 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
296 vput(vp);
298 vput(vp);
297 mtx_unlock(&Giant); /* VFS */
299 VFS_UNLOCK_GIANT(vfslocked);
298 NFSD_LOCK();
299 }
300 return(error);
301}
302
303/*
304 * nfs setattr service
305 */

--- 14 unchanged lines hidden (view full) ---

320 fhandle_t *fhp;
321 u_int32_t *tl;
322 caddr_t bpos;
323 int error = 0, rdonly, preat_ret = 1, postat_ret = 1;
324 int v3 = (nfsd->nd_flag & ND_NFSV3), gcheck = 0;
325 struct mbuf *mb, *mreq;
326 struct timespec guard;
327 struct mount *mp = NULL;
300 NFSD_LOCK();
301 }
302 return(error);
303}
304
305/*
306 * nfs setattr service
307 */

--- 14 unchanged lines hidden (view full) ---

322 fhandle_t *fhp;
323 u_int32_t *tl;
324 caddr_t bpos;
325 int error = 0, rdonly, preat_ret = 1, postat_ret = 1;
326 int v3 = (nfsd->nd_flag & ND_NFSV3), gcheck = 0;
327 struct mbuf *mb, *mreq;
328 struct timespec guard;
329 struct mount *mp = NULL;
330 int vfslocked;
328
329 NFSD_LOCK_ASSERT();
330
331 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
332 fhp = &nfh.fh_generic;
333 nfsm_srvmtofh(fhp);
331
332 NFSD_LOCK_ASSERT();
333
334 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
335 fhp = &nfh.fh_generic;
336 nfsm_srvmtofh(fhp);
337 NFSD_UNLOCK();
334 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
335 error = ESTALE;
336 goto out;
337 }
338 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
339 error = ESTALE;
340 goto out;
341 }
338 NFSD_UNLOCK();
339 mtx_lock(&Giant); /* VFS */
342 vfslocked = VFS_LOCK_GIANT(mp);
340 (void) vn_start_write(NULL, &mp, V_WAIT);
341 vfs_rel(mp); /* The write holds a ref. */
343 (void) vn_start_write(NULL, &mp, V_WAIT);
344 vfs_rel(mp); /* The write holds a ref. */
342 mtx_unlock(&Giant); /* VFS */
343 NFSD_LOCK();
345 VFS_UNLOCK_GIANT(vfslocked);
344 VATTR_NULL(vap);
346 VATTR_NULL(vap);
347 NFSD_LOCK();
345 if (v3) {
346 nfsm_srvsattr(vap);
347 tl = nfsm_dissect_nonblock(u_int32_t *, NFSX_UNSIGNED);
348 gcheck = fxdr_unsigned(int, *tl);
349 if (gcheck) {
350 tl = nfsm_dissect_nonblock(u_int32_t *, 2 * NFSX_UNSIGNED);
351 fxdr_nfsv3time(tl, &guard);
352 }

--- 22 unchanged lines hidden (view full) ---

375 fxdr_unsigned(int32_t, sp->sa_atime.nfsv2_sec);
376 vap->va_atime.tv_nsec = 0;
377#endif
378 }
379 if (sp->sa_mtime.nfsv2_sec != nfsrv_nfs_xdrneg1)
380 fxdr_nfsv2time(&sp->sa_mtime, &vap->va_mtime);
381
382 }
348 if (v3) {
349 nfsm_srvsattr(vap);
350 tl = nfsm_dissect_nonblock(u_int32_t *, NFSX_UNSIGNED);
351 gcheck = fxdr_unsigned(int, *tl);
352 if (gcheck) {
353 tl = nfsm_dissect_nonblock(u_int32_t *, 2 * NFSX_UNSIGNED);
354 fxdr_nfsv3time(tl, &guard);
355 }

--- 22 unchanged lines hidden (view full) ---

378 fxdr_unsigned(int32_t, sp->sa_atime.nfsv2_sec);
379 vap->va_atime.tv_nsec = 0;
380#endif
381 }
382 if (sp->sa_mtime.nfsv2_sec != nfsrv_nfs_xdrneg1)
383 fxdr_nfsv2time(&sp->sa_mtime, &vap->va_mtime);
384
385 }
386 NFSD_UNLOCK();
383
384 /*
385 * Now that we have all the fields, lets do it.
386 */
387 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
388 if (error) {
387
388 /*
389 * Now that we have all the fields, lets do it.
390 */
391 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
392 if (error) {
393 NFSD_LOCK();
389 nfsm_reply(2 * NFSX_UNSIGNED);
390 if (v3)
391 nfsm_srvwcc_data(preat_ret, &preat, postat_ret, vap);
392 error = 0;
393 goto nfsmout;
394 }
395
396 /*
397 * vp now an active resource, pay careful attention to cleanup
398 */
399 if (v3) {
394 nfsm_reply(2 * NFSX_UNSIGNED);
395 if (v3)
396 nfsm_srvwcc_data(preat_ret, &preat, postat_ret, vap);
397 error = 0;
398 goto nfsmout;
399 }
400
401 /*
402 * vp now an active resource, pay careful attention to cleanup
403 */
404 if (v3) {
400 NFSD_UNLOCK();
401 mtx_lock(&Giant); /* VFS */
405 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
402 error = preat_ret = VOP_GETATTR(vp, &preat, cred, td);
403 if (!error && gcheck &&
404 (preat.va_ctime.tv_sec != guard.tv_sec ||
405 preat.va_ctime.tv_nsec != guard.tv_nsec))
406 error = NFSERR_NOT_SYNC;
407 if (error) {
408 vput(vp);
406 error = preat_ret = VOP_GETATTR(vp, &preat, cred, td);
407 if (!error && gcheck &&
408 (preat.va_ctime.tv_sec != guard.tv_sec ||
409 preat.va_ctime.tv_nsec != guard.tv_nsec))
410 error = NFSERR_NOT_SYNC;
411 if (error) {
412 vput(vp);
409 mtx_unlock(&Giant); /* VFS */
413 VFS_UNLOCK_GIANT(vfslocked);
410 vp = NULL;
411 NFSD_LOCK();
412 nfsm_reply(NFSX_WCCDATA(v3));
413 if (v3)
414 nfsm_srvwcc_data(preat_ret, &preat, postat_ret, vap);
415 error = 0;
416 goto nfsmout;
417 }
414 vp = NULL;
415 NFSD_LOCK();
416 nfsm_reply(NFSX_WCCDATA(v3));
417 if (v3)
418 nfsm_srvwcc_data(preat_ret, &preat, postat_ret, vap);
419 error = 0;
420 goto nfsmout;
421 }
418 mtx_unlock(&Giant); /* VFS */
419 NFSD_LOCK();
422 VFS_UNLOCK_GIANT(vfslocked);
420 }
423 }
421 NFSD_LOCK_ASSERT();
422
423 /*
424 * If the size is being changed write acces is required, otherwise
425 * just check for a read only filesystem.
426 */
427 if (vap->va_size == ((u_quad_t)((quad_t) -1))) {
428 if (rdonly || (vp->v_mount->mnt_flag & MNT_RDONLY)) {
429 error = EROFS;
430 goto out;
431 }
432 } else {
433 if (vp->v_type == VDIR) {
434 error = EISDIR;
435 goto out;
436 } else if ((error = nfsrv_access(vp, VWRITE, cred, rdonly,
424
425 /*
426 * If the size is being changed write acces is required, otherwise
427 * just check for a read only filesystem.
428 */
429 if (vap->va_size == ((u_quad_t)((quad_t) -1))) {
430 if (rdonly || (vp->v_mount->mnt_flag & MNT_RDONLY)) {
431 error = EROFS;
432 goto out;
433 }
434 } else {
435 if (vp->v_type == VDIR) {
436 error = EISDIR;
437 goto out;
438 } else if ((error = nfsrv_access(vp, VWRITE, cred, rdonly,
437 td, 0)) != 0)
439 td, 0)) != 0)
438 goto out;
439 }
440 goto out;
441 }
440 NFSD_UNLOCK();
441 mtx_lock(&Giant); /* VFS */
442 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
442 error = VOP_SETATTR(vp, vap, cred, td);
443 postat_ret = VOP_GETATTR(vp, vap, cred, td);
443 error = VOP_SETATTR(vp, vap, cred, td);
444 postat_ret = VOP_GETATTR(vp, vap, cred, td);
444 mtx_unlock(&Giant); /* VFS */
445 NFSD_LOCK();
445 VFS_UNLOCK_GIANT(vfslocked);
446 if (!error)
447 error = postat_ret;
448out:
446 if (!error)
447 error = postat_ret;
448out:
449 NFSD_LOCK_ASSERT();
449 NFSD_UNLOCK_ASSERT();
450 if (vp != NULL) {
450 if (vp != NULL) {
451 NFSD_UNLOCK();
452 mtx_lock(&Giant); /* VFS */
451 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
453 vput(vp);
452 vput(vp);
454 mtx_unlock(&Giant); /* VFS */
455 NFSD_LOCK();
453 VFS_UNLOCK_GIANT(vfslocked);
456 }
457
458 vp = NULL;
454 }
455
456 vp = NULL;
457 NFSD_LOCK();
459 nfsm_reply(NFSX_WCCORFATTR(v3));
460 if (v3) {
461 nfsm_srvwcc_data(preat_ret, &preat, postat_ret, vap);
462 } else if (!error) {
463 /* v2 non-error case. */
464 fp = nfsm_build(struct nfs_fattr *, NFSX_V2FATTR);
465 nfsm_srvfillattr(vap, fp);
466 }
467 error = 0;
468 /* fall through */
469
470nfsmout:
471 NFSD_LOCK_ASSERT();
472 NFSD_UNLOCK();
458 nfsm_reply(NFSX_WCCORFATTR(v3));
459 if (v3) {
460 nfsm_srvwcc_data(preat_ret, &preat, postat_ret, vap);
461 } else if (!error) {
462 /* v2 non-error case. */
463 fp = nfsm_build(struct nfs_fattr *, NFSX_V2FATTR);
464 nfsm_srvfillattr(vap, fp);
465 }
466 error = 0;
467 /* fall through */
468
469nfsmout:
470 NFSD_LOCK_ASSERT();
471 NFSD_UNLOCK();
473 mtx_lock(&Giant); /* VFS */
472 vfslocked = VFS_LOCK_GIANT(mp);
474 if (vp)
475 vput(vp);
476 vn_finished_write(mp);
473 if (vp)
474 vput(vp);
475 vn_finished_write(mp);
477 mtx_unlock(&Giant); /* VFS */
476 VFS_UNLOCK_GIANT(vfslocked);
478 NFSD_LOCK();
479 return(error);
480}
481
482/*
483 * nfs lookup rpc
484 */
485int

--- 26 unchanged lines hidden (view full) ---

512
513 pubflag = nfs_ispublicfh(fhp);
514
515 nd.ni_cnd.cn_cred = cred;
516 nd.ni_cnd.cn_nameiop = LOOKUP;
517 nd.ni_cnd.cn_flags = LOCKLEAF | SAVESTART;
518 error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
519 &dirp, v3, &dirattr, &dirattr_ret, td, pubflag);
477 NFSD_LOCK();
478 return(error);
479}
480
481/*
482 * nfs lookup rpc
483 */
484int

--- 26 unchanged lines hidden (view full) ---

511
512 pubflag = nfs_ispublicfh(fhp);
513
514 nd.ni_cnd.cn_cred = cred;
515 nd.ni_cnd.cn_nameiop = LOOKUP;
516 nd.ni_cnd.cn_flags = LOCKLEAF | SAVESTART;
517 error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
518 &dirp, v3, &dirattr, &dirattr_ret, td, pubflag);
519 NFSD_UNLOCK();
520
521 /*
522 * namei failure, only dirp to cleanup. Clear out garbarge from
523 * structure in case macros jump to nfsmout.
520
521 /*
522 * namei failure, only dirp to cleanup. Clear out garbarge from
523 * structure in case macros jump to nfsmout.
524 *
525 * XXXRW: For now, use Giant unconditionally during name lookup,
526 * rather than deal with complexity of conditional Giant acqusition
527 * as moving across the name space.
524 */
528 */
525
526 NFSD_UNLOCK();
527 mtx_lock(&Giant); /* VFS */
528 if (error) {
529 if (dirp) {
530 vrele(dirp);
531 dirp = NULL;
532 }
533 mtx_unlock(&Giant); /* VFS */
534 NFSD_LOCK();

--- 156 unchanged lines hidden (view full) ---

691 int error = 0, rdonly, i, tlen, len, getret;
692 int v3 = (nfsd->nd_flag & ND_NFSV3);
693 struct mbuf *mb, *mp3, *nmp, *mreq;
694 struct vnode *vp = NULL;
695 struct vattr attr;
696 nfsfh_t nfh;
697 fhandle_t *fhp;
698 struct uio io, *uiop = &io;
529 mtx_lock(&Giant); /* VFS */
530 if (error) {
531 if (dirp) {
532 vrele(dirp);
533 dirp = NULL;
534 }
535 mtx_unlock(&Giant); /* VFS */
536 NFSD_LOCK();

--- 156 unchanged lines hidden (view full) ---

693 int error = 0, rdonly, i, tlen, len, getret;
694 int v3 = (nfsd->nd_flag & ND_NFSV3);
695 struct mbuf *mb, *mp3, *nmp, *mreq;
696 struct vnode *vp = NULL;
697 struct vattr attr;
698 nfsfh_t nfh;
699 fhandle_t *fhp;
700 struct uio io, *uiop = &io;
701 int vfslocked;
699
700 NFSD_LOCK_ASSERT();
701
702 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
703#ifndef nolint
704 mp = NULL;
705#endif
706 mp3 = NULL;
707 fhp = &nfh.fh_generic;
708 nfsm_srvmtofh(fhp);
702
703 NFSD_LOCK_ASSERT();
704
705 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
706#ifndef nolint
707 mp = NULL;
708#endif
709 mp3 = NULL;
710 fhp = &nfh.fh_generic;
711 nfsm_srvmtofh(fhp);
712 NFSD_UNLOCK();
709 len = 0;
710 i = 0;
713 len = 0;
714 i = 0;
711 NFSD_UNLOCK();
712 while (len < NFS_MAXPATHLEN) {
713 MGET(nmp, M_TRYWAIT, MT_DATA);
714 MCLGET(nmp, M_TRYWAIT);
715 nmp->m_len = NFSMSIZ(nmp);
716 if (len == 0)
717 mp3 = mp = nmp;
718 else {
719 mp->m_next = nmp;

--- 11 unchanged lines hidden (view full) ---

731 }
732 uiop->uio_iov = iv;
733 uiop->uio_iovcnt = i;
734 uiop->uio_offset = 0;
735 uiop->uio_resid = len;
736 uiop->uio_rw = UIO_READ;
737 uiop->uio_segflg = UIO_SYSSPACE;
738 uiop->uio_td = NULL;
715 while (len < NFS_MAXPATHLEN) {
716 MGET(nmp, M_TRYWAIT, MT_DATA);
717 MCLGET(nmp, M_TRYWAIT);
718 nmp->m_len = NFSMSIZ(nmp);
719 if (len == 0)
720 mp3 = mp = nmp;
721 else {
722 mp->m_next = nmp;

--- 11 unchanged lines hidden (view full) ---

734 }
735 uiop->uio_iov = iv;
736 uiop->uio_iovcnt = i;
737 uiop->uio_offset = 0;
738 uiop->uio_resid = len;
739 uiop->uio_rw = UIO_READ;
740 uiop->uio_segflg = UIO_SYSSPACE;
741 uiop->uio_td = NULL;
739 NFSD_LOCK();
740 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
741 if (error) {
742 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
743 if (error) {
744 NFSD_LOCK();
742 nfsm_reply(2 * NFSX_UNSIGNED);
743 if (v3)
744 nfsm_srvpostop_attr(1, NULL);
745 error = 0;
746 goto nfsmout;
747 }
745 nfsm_reply(2 * NFSX_UNSIGNED);
746 if (v3)
747 nfsm_srvpostop_attr(1, NULL);
748 error = 0;
749 goto nfsmout;
750 }
748 NFSD_UNLOCK();
749 mtx_lock(&Giant); /* VFS */
751 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
750 if (vp->v_type != VLNK) {
751 if (v3)
752 error = EINVAL;
753 else
754 error = ENXIO;
755 } else
756 error = VOP_READLINK(vp, uiop, cred);
757 getret = VOP_GETATTR(vp, &attr, cred, td);
758 vput(vp);
752 if (vp->v_type != VLNK) {
753 if (v3)
754 error = EINVAL;
755 else
756 error = ENXIO;
757 } else
758 error = VOP_READLINK(vp, uiop, cred);
759 getret = VOP_GETATTR(vp, &attr, cred, td);
760 vput(vp);
759 mtx_unlock(&Giant); /* VFS */
761 VFS_UNLOCK_GIANT(vfslocked);
760 vp = NULL;
761 NFSD_LOCK();
762 nfsm_reply(NFSX_POSTOPATTR(v3) + NFSX_UNSIGNED);
763 if (v3)
764 nfsm_srvpostop_attr(getret, &attr);
765 if (error) {
766 error = 0;
767 goto nfsmout;

--- 8 unchanged lines hidden (view full) ---

776 mb->m_next = mp3;
777 mp3 = NULL;
778nfsmout:
779 NFSD_LOCK_ASSERT();
780 if (mp3)
781 m_freem(mp3);
782 if (vp) {
783 NFSD_UNLOCK();
762 vp = NULL;
763 NFSD_LOCK();
764 nfsm_reply(NFSX_POSTOPATTR(v3) + NFSX_UNSIGNED);
765 if (v3)
766 nfsm_srvpostop_attr(getret, &attr);
767 if (error) {
768 error = 0;
769 goto nfsmout;

--- 8 unchanged lines hidden (view full) ---

778 mb->m_next = mp3;
779 mp3 = NULL;
780nfsmout:
781 NFSD_LOCK_ASSERT();
782 if (mp3)
783 m_freem(mp3);
784 if (vp) {
785 NFSD_UNLOCK();
784 mtx_lock(&Giant); /* VFS */
786 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
785 vput(vp);
787 vput(vp);
786 mtx_unlock(&Giant); /* VFS */
788 VFS_UNLOCK_GIANT(vfslocked);
787 NFSD_LOCK();
788 }
789 return(error);
790}
791
792/*
793 * nfs read service
794 */

--- 19 unchanged lines hidden (view full) ---

814 struct vnode *vp = NULL;
815 nfsfh_t nfh;
816 fhandle_t *fhp;
817 struct uio io, *uiop = &io;
818 struct vattr va, *vap = &va;
819 struct nfsheur *nh;
820 off_t off;
821 int ioflag = 0;
789 NFSD_LOCK();
790 }
791 return(error);
792}
793
794/*
795 * nfs read service
796 */

--- 19 unchanged lines hidden (view full) ---

816 struct vnode *vp = NULL;
817 nfsfh_t nfh;
818 fhandle_t *fhp;
819 struct uio io, *uiop = &io;
820 struct vattr va, *vap = &va;
821 struct nfsheur *nh;
822 off_t off;
823 int ioflag = 0;
824 int vfslocked;
822
823 NFSD_LOCK_ASSERT();
824
825 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
826 fhp = &nfh.fh_generic;
827 nfsm_srvmtofh(fhp);
828 if (v3) {
829 tl = nfsm_dissect_nonblock(u_int32_t *, 2 * NFSX_UNSIGNED);
830 off = fxdr_hyper(tl);
831 } else {
832 tl = nfsm_dissect_nonblock(u_int32_t *, NFSX_UNSIGNED);
833 off = (off_t)fxdr_unsigned(u_int32_t, *tl);
834 }
835 nfsm_srvstrsiz(reqlen, NFS_SRVMAXDATA(nfsd));
825
826 NFSD_LOCK_ASSERT();
827
828 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
829 fhp = &nfh.fh_generic;
830 nfsm_srvmtofh(fhp);
831 if (v3) {
832 tl = nfsm_dissect_nonblock(u_int32_t *, 2 * NFSX_UNSIGNED);
833 off = fxdr_hyper(tl);
834 } else {
835 tl = nfsm_dissect_nonblock(u_int32_t *, NFSX_UNSIGNED);
836 off = (off_t)fxdr_unsigned(u_int32_t, *tl);
837 }
838 nfsm_srvstrsiz(reqlen, NFS_SRVMAXDATA(nfsd));
839 NFSD_UNLOCK();
836
837 /*
838 * Reference vp. If an error occurs, vp will be invalid, but we
839 * have to NULL it just in case. The macros might goto nfsmout
840 * as well.
841 */
840
841 /*
842 * Reference vp. If an error occurs, vp will be invalid, but we
843 * have to NULL it just in case. The macros might goto nfsmout
844 * as well.
845 */
842
843 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
846 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly,
847 TRUE);
844 if (error) {
845 vp = NULL;
848 if (error) {
849 vp = NULL;
850 NFSD_LOCK();
846 nfsm_reply(2 * NFSX_UNSIGNED);
847 if (v3)
848 nfsm_srvpostop_attr(1, NULL);
849 error = 0;
850 goto nfsmout;
851 }
852
853 if (vp->v_type != VREG) {
854 if (v3)
855 error = EINVAL;
856 else
857 error = (vp->v_type == VDIR) ? EISDIR : EACCES;
858 }
851 nfsm_reply(2 * NFSX_UNSIGNED);
852 if (v3)
853 nfsm_srvpostop_attr(1, NULL);
854 error = 0;
855 goto nfsmout;
856 }
857
858 if (vp->v_type != VREG) {
859 if (v3)
860 error = EINVAL;
861 else
862 error = (vp->v_type == VDIR) ? EISDIR : EACCES;
863 }
859 NFSD_UNLOCK();
860 mtx_lock(&Giant); /* VFS */
864 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
861 if (!error) {
865 if (!error) {
862 if ((error = nfsrv_access_withgiant(vp, VREAD, cred, rdonly,
863 td, 1)) != 0)
864 error = nfsrv_access_withgiant(vp, VEXEC, cred,
865 rdonly, td, 1);
866 if ((error = nfsrv_access(vp, VREAD, cred, rdonly, td, 1))
867 != 0)
868 error = nfsrv_access(vp, VEXEC, cred, rdonly, td, 1);
866 }
867 getret = VOP_GETATTR(vp, vap, cred, td);
868 if (!error)
869 error = getret;
870 if (error) {
871 vput(vp);
869 }
870 getret = VOP_GETATTR(vp, vap, cred, td);
871 if (!error)
872 error = getret;
873 if (error) {
874 vput(vp);
872 mtx_unlock(&Giant); /* VFS */
875 VFS_UNLOCK_GIANT(vfslocked);
873 vp = NULL;
874 NFSD_LOCK();
875 nfsm_reply(NFSX_POSTOPATTR(v3));
876 if (v3)
877 nfsm_srvpostop_attr(getret, vap);
878 error = 0;
879 goto nfsmout;
880 }
876 vp = NULL;
877 NFSD_LOCK();
878 nfsm_reply(NFSX_POSTOPATTR(v3));
879 if (v3)
880 nfsm_srvpostop_attr(getret, vap);
881 error = 0;
882 goto nfsmout;
883 }
881 mtx_unlock(&Giant); /* VFS */
882 NFSD_LOCK();
884 VFS_UNLOCK_GIANT(vfslocked);
883
884 /*
885 * Calculate byte count to read
886 */
887
888 if (off >= vap->va_size)
889 cnt = 0;
890 else if ((off + reqlen) > vap->va_size)
891 cnt = vap->va_size - off;
892 else
893 cnt = reqlen;
894
885
886 /*
887 * Calculate byte count to read
888 */
889
890 if (off >= vap->va_size)
891 cnt = 0;
892 else if ((off + reqlen) > vap->va_size)
893 cnt = vap->va_size - off;
894 else
895 cnt = reqlen;
896
897 NFSD_LOCK();
895 /*
896 * Calculate seqcount for heuristic
897 */
898
899 {
900 int hi;
901 int try = 32;
902

--- 50 unchanged lines hidden (view full) ---

953 *tl++ = nfsrv_nfs_true;
954 fp = (struct nfs_fattr *)tl;
955 tl += (NFSX_V3FATTR / sizeof (u_int32_t));
956 } else {
957 tl = nfsm_build(u_int32_t *, NFSX_V2FATTR + NFSX_UNSIGNED);
958 fp = (struct nfs_fattr *)tl;
959 tl += (NFSX_V2FATTR / sizeof (u_int32_t));
960 }
898 /*
899 * Calculate seqcount for heuristic
900 */
901
902 {
903 int hi;
904 int try = 32;
905

--- 50 unchanged lines hidden (view full) ---

956 *tl++ = nfsrv_nfs_true;
957 fp = (struct nfs_fattr *)tl;
958 tl += (NFSX_V3FATTR / sizeof (u_int32_t));
959 } else {
960 tl = nfsm_build(u_int32_t *, NFSX_V2FATTR + NFSX_UNSIGNED);
961 fp = (struct nfs_fattr *)tl;
962 tl += (NFSX_V2FATTR / sizeof (u_int32_t));
963 }
961 len = left = nfsm_rndup(cnt);
962 NFSD_UNLOCK();
964 NFSD_UNLOCK();
965 len = left = nfsm_rndup(cnt);
963 if (cnt > 0) {
964 /*
965 * Generate the mbuf list with the uio_iov ref. to it.
966 */
967 i = 0;
968 m = m2 = mb;
969 while (left > 0) {
970 siz = min(M_TRAILINGSPACE(m), left);

--- 29 unchanged lines hidden (view full) ---

1000 }
1001 m = m->m_next;
1002 }
1003 uiop->uio_iovcnt = i;
1004 uiop->uio_offset = off;
1005 uiop->uio_resid = len;
1006 uiop->uio_rw = UIO_READ;
1007 uiop->uio_segflg = UIO_SYSSPACE;
966 if (cnt > 0) {
967 /*
968 * Generate the mbuf list with the uio_iov ref. to it.
969 */
970 i = 0;
971 m = m2 = mb;
972 while (left > 0) {
973 siz = min(M_TRAILINGSPACE(m), left);

--- 29 unchanged lines hidden (view full) ---

1003 }
1004 m = m->m_next;
1005 }
1006 uiop->uio_iovcnt = i;
1007 uiop->uio_offset = off;
1008 uiop->uio_resid = len;
1009 uiop->uio_rw = UIO_READ;
1010 uiop->uio_segflg = UIO_SYSSPACE;
1008 mtx_lock(&Giant); /* VFS */
1011 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1009 error = VOP_READ(vp, uiop, IO_NODELOCKED | ioflag, cred);
1010 off = uiop->uio_offset;
1011 nh->nh_nextr = off;
1012 FREE((caddr_t)iv2, M_TEMP);
1013 if (error || (getret = VOP_GETATTR(vp, vap, cred, td))) {
1014 if (!error)
1015 error = getret;
1016 m_freem(mreq);
1017 vput(vp);
1012 error = VOP_READ(vp, uiop, IO_NODELOCKED | ioflag, cred);
1013 off = uiop->uio_offset;
1014 nh->nh_nextr = off;
1015 FREE((caddr_t)iv2, M_TEMP);
1016 if (error || (getret = VOP_GETATTR(vp, vap, cred, td))) {
1017 if (!error)
1018 error = getret;
1019 m_freem(mreq);
1020 vput(vp);
1018 mtx_unlock(&Giant); /* VFS */
1021 VFS_UNLOCK_GIANT(vfslocked);
1019 NFSD_LOCK();
1020 vp = NULL;
1021 nfsm_reply(NFSX_POSTOPATTR(v3));
1022 if (v3)
1023 nfsm_srvpostop_attr(getret, vap);
1024 error = 0;
1025 goto nfsmout;
1026 }
1027 } else {
1028 uiop->uio_resid = 0;
1022 NFSD_LOCK();
1023 vp = NULL;
1024 nfsm_reply(NFSX_POSTOPATTR(v3));
1025 if (v3)
1026 nfsm_srvpostop_attr(getret, vap);
1027 error = 0;
1028 goto nfsmout;
1029 }
1030 } else {
1031 uiop->uio_resid = 0;
1029 mtx_lock(&Giant); /* VFS */
1032 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1030 }
1033 }
1031 mtx_assert(&Giant, MA_OWNED); /* VFS */
1034 VFS_ASSERT_GIANT(vp->v_mount);
1032 vput(vp);
1035 vput(vp);
1033 mtx_unlock(&Giant); /* VFS */
1036 VFS_UNLOCK_GIANT(vfslocked);
1034 vp = NULL;
1035 NFSD_LOCK();
1036 nfsm_srvfillattr(vap, fp);
1037 tlen = len - uiop->uio_resid;
1038 cnt = cnt < tlen ? cnt : tlen;
1039 tlen = nfsm_rndup(cnt);
1040 if (len != tlen || tlen != cnt)
1041 nfsm_adj(mb, len - tlen, tlen - cnt);

--- 4 unchanged lines hidden (view full) ---

1046 else
1047 *tl++ = nfsrv_nfs_false;
1048 }
1049 *tl = txdr_unsigned(cnt);
1050nfsmout:
1051 NFSD_LOCK_ASSERT();
1052 if (vp) {
1053 NFSD_UNLOCK();
1037 vp = NULL;
1038 NFSD_LOCK();
1039 nfsm_srvfillattr(vap, fp);
1040 tlen = len - uiop->uio_resid;
1041 cnt = cnt < tlen ? cnt : tlen;
1042 tlen = nfsm_rndup(cnt);
1043 if (len != tlen || tlen != cnt)
1044 nfsm_adj(mb, len - tlen, tlen - cnt);

--- 4 unchanged lines hidden (view full) ---

1049 else
1050 *tl++ = nfsrv_nfs_false;
1051 }
1052 *tl = txdr_unsigned(cnt);
1053nfsmout:
1054 NFSD_LOCK_ASSERT();
1055 if (vp) {
1056 NFSD_UNLOCK();
1054 mtx_lock(&Giant); /* VFS */
1057 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1055 vput(vp);
1058 vput(vp);
1056 mtx_unlock(&Giant); /* VFS */
1059 VFS_UNLOCK_GIANT(vfslocked);
1057 NFSD_LOCK();
1058 }
1059 return(error);
1060}
1061
1062/*
1063 * nfs write service
1064 */

--- 20 unchanged lines hidden (view full) ---

1085 int v3 = (nfsd->nd_flag & ND_NFSV3);
1086 struct mbuf *mb, *mreq;
1087 struct vnode *vp = NULL;
1088 nfsfh_t nfh;
1089 fhandle_t *fhp;
1090 struct uio io, *uiop = &io;
1091 off_t off;
1092 struct mount *mntp = NULL;
1060 NFSD_LOCK();
1061 }
1062 return(error);
1063}
1064
1065/*
1066 * nfs write service
1067 */

--- 20 unchanged lines hidden (view full) ---

1088 int v3 = (nfsd->nd_flag & ND_NFSV3);
1089 struct mbuf *mb, *mreq;
1090 struct vnode *vp = NULL;
1091 nfsfh_t nfh;
1092 fhandle_t *fhp;
1093 struct uio io, *uiop = &io;
1094 off_t off;
1095 struct mount *mntp = NULL;
1096 int vfslocked;
1093
1094 NFSD_LOCK_ASSERT();
1095
1096 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
1097 if (mrep == NULL) {
1098 *mrq = NULL;
1099 error = 0;
1100 goto nfsmout;
1101 }
1102 fhp = &nfh.fh_generic;
1103 nfsm_srvmtofh(fhp);
1097
1098 NFSD_LOCK_ASSERT();
1099
1100 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
1101 if (mrep == NULL) {
1102 *mrq = NULL;
1103 error = 0;
1104 goto nfsmout;
1105 }
1106 fhp = &nfh.fh_generic;
1107 nfsm_srvmtofh(fhp);
1108 NFSD_UNLOCK();
1104 if ((mntp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
1105 error = ESTALE;
1109 if ((mntp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
1110 error = ESTALE;
1111 NFSD_LOCK();
1106 goto ereply;
1107 }
1112 goto ereply;
1113 }
1108 NFSD_UNLOCK();
1109 mtx_lock(&Giant); /* VFS */
1114 vfslocked = VFS_LOCK_GIANT(mntp);
1110 (void) vn_start_write(NULL, &mntp, V_WAIT);
1111 vfs_rel(mntp); /* The write holds a ref. */
1115 (void) vn_start_write(NULL, &mntp, V_WAIT);
1116 vfs_rel(mntp); /* The write holds a ref. */
1112 mtx_unlock(&Giant); /* VFS */
1113 NFSD_LOCK();
1117 VFS_UNLOCK_GIANT(vfslocked);
1114 if (v3) {
1118 if (v3) {
1119 NFSD_LOCK();
1115 tl = nfsm_dissect_nonblock(u_int32_t *, 5 * NFSX_UNSIGNED);
1120 tl = nfsm_dissect_nonblock(u_int32_t *, 5 * NFSX_UNSIGNED);
1121 NFSD_UNLOCK();
1116 off = fxdr_hyper(tl);
1117 tl += 3;
1118 stable = fxdr_unsigned(int, *tl++);
1119 } else {
1122 off = fxdr_hyper(tl);
1123 tl += 3;
1124 stable = fxdr_unsigned(int, *tl++);
1125 } else {
1126 NFSD_LOCK();
1120 tl = nfsm_dissect_nonblock(u_int32_t *, 4 * NFSX_UNSIGNED);
1127 tl = nfsm_dissect_nonblock(u_int32_t *, 4 * NFSX_UNSIGNED);
1128 NFSD_UNLOCK();
1121 off = (off_t)fxdr_unsigned(u_int32_t, *++tl);
1122 tl += 2;
1123 if (nfs_async)
1124 stable = NFSV3WRITE_UNSTABLE;
1125 }
1126 retlen = len = fxdr_unsigned(int32_t, *tl);
1127 cnt = i = 0;
1128

--- 24 unchanged lines hidden (view full) ---

1153 if (mp->m_len > 0)
1154 cnt++;
1155 }
1156 mp = mp->m_next;
1157 }
1158 }
1159 if (len > NFS_MAXDATA || len < 0 || i < len) {
1160 error = EIO;
1129 off = (off_t)fxdr_unsigned(u_int32_t, *++tl);
1130 tl += 2;
1131 if (nfs_async)
1132 stable = NFSV3WRITE_UNSTABLE;
1133 }
1134 retlen = len = fxdr_unsigned(int32_t, *tl);
1135 cnt = i = 0;
1136

--- 24 unchanged lines hidden (view full) ---

1161 if (mp->m_len > 0)
1162 cnt++;
1163 }
1164 mp = mp->m_next;
1165 }
1166 }
1167 if (len > NFS_MAXDATA || len < 0 || i < len) {
1168 error = EIO;
1169 NFSD_LOCK();
1161 nfsm_reply(2 * NFSX_UNSIGNED);
1162 if (v3)
1163 nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, vap);
1164 error = 0;
1165 goto nfsmout;
1166 }
1170 nfsm_reply(2 * NFSX_UNSIGNED);
1171 if (v3)
1172 nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, vap);
1173 error = 0;
1174 goto nfsmout;
1175 }
1167 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
1176 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly,
1177 TRUE);
1168 if (error) {
1169 vp = NULL;
1178 if (error) {
1179 vp = NULL;
1180 NFSD_LOCK();
1170 nfsm_reply(2 * NFSX_UNSIGNED);
1171 if (v3)
1172 nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, vap);
1173 error = 0;
1174 goto nfsmout;
1175 }
1176 if (v3) {
1181 nfsm_reply(2 * NFSX_UNSIGNED);
1182 if (v3)
1183 nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, vap);
1184 error = 0;
1185 goto nfsmout;
1186 }
1187 if (v3) {
1177 NFSD_UNLOCK();
1178 mtx_lock(&Giant); /* VFS */
1188 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1179 forat_ret = VOP_GETATTR(vp, &forat, cred, td);
1189 forat_ret = VOP_GETATTR(vp, &forat, cred, td);
1180 mtx_unlock(&Giant); /* VFS */
1181 NFSD_LOCK();
1190 VFS_UNLOCK_GIANT(vfslocked);
1182 }
1183 if (vp->v_type != VREG) {
1184 if (v3)
1185 error = EINVAL;
1186 else
1187 error = (vp->v_type == VDIR) ? EISDIR : EACCES;
1188 }
1191 }
1192 if (vp->v_type != VREG) {
1193 if (v3)
1194 error = EINVAL;
1195 else
1196 error = (vp->v_type == VDIR) ? EISDIR : EACCES;
1197 }
1189 if (!error)
1198 if (!error) {
1199 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1190 error = nfsrv_access(vp, VWRITE, cred, rdonly, td, 1);
1200 error = nfsrv_access(vp, VWRITE, cred, rdonly, td, 1);
1201 VFS_UNLOCK_GIANT(vfslocked);
1202 }
1191 if (error) {
1203 if (error) {
1192 NFSD_UNLOCK();
1193 mtx_lock(&Giant); /* VFS */
1204 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1194 vput(vp);
1205 vput(vp);
1195 mtx_unlock(&Giant); /* VFS */
1196 NFSD_LOCK();
1206 VFS_UNLOCK_GIANT(vfslocked);
1197 vp = NULL;
1207 vp = NULL;
1208 NFSD_LOCK();
1198 nfsm_reply(NFSX_WCCDATA(v3));
1199 if (v3)
1200 nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, vap);
1201 error = 0;
1202 goto nfsmout;
1203 }
1204
1209 nfsm_reply(NFSX_WCCDATA(v3));
1210 if (v3)
1211 nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, vap);
1212 error = 0;
1213 goto nfsmout;
1214 }
1215
1205 NFSD_UNLOCK();
1206 if (len > 0) {
1207 MALLOC(ivp, struct iovec *, cnt * sizeof (struct iovec), M_TEMP,
1208 M_WAITOK);
1209 uiop->uio_iov = iv = ivp;
1210 uiop->uio_iovcnt = cnt;
1211 mp = mrep;
1212 while (mp) {
1213 if (mp->m_len > 0) {

--- 17 unchanged lines hidden (view full) ---

1231 ioflags = (IO_SYNC | IO_NODELOCKED);
1232 else
1233 ioflags = (IO_METASYNC | IO_SYNC | IO_NODELOCKED);
1234 uiop->uio_resid = len;
1235 uiop->uio_rw = UIO_WRITE;
1236 uiop->uio_segflg = UIO_SYSSPACE;
1237 uiop->uio_td = NULL;
1238 uiop->uio_offset = off;
1216 if (len > 0) {
1217 MALLOC(ivp, struct iovec *, cnt * sizeof (struct iovec), M_TEMP,
1218 M_WAITOK);
1219 uiop->uio_iov = iv = ivp;
1220 uiop->uio_iovcnt = cnt;
1221 mp = mrep;
1222 while (mp) {
1223 if (mp->m_len > 0) {

--- 17 unchanged lines hidden (view full) ---

1241 ioflags = (IO_SYNC | IO_NODELOCKED);
1242 else
1243 ioflags = (IO_METASYNC | IO_SYNC | IO_NODELOCKED);
1244 uiop->uio_resid = len;
1245 uiop->uio_rw = UIO_WRITE;
1246 uiop->uio_segflg = UIO_SYSSPACE;
1247 uiop->uio_td = NULL;
1248 uiop->uio_offset = off;
1239 mtx_lock(&Giant); /* VFS */
1249 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1240 error = VOP_WRITE(vp, uiop, ioflags, cred);
1241 /* XXXRW: unlocked write. */
1242 nfsrvstats.srvvop_writes++;
1243 FREE((caddr_t)iv, M_TEMP);
1244 } else
1250 error = VOP_WRITE(vp, uiop, ioflags, cred);
1251 /* XXXRW: unlocked write. */
1252 nfsrvstats.srvvop_writes++;
1253 FREE((caddr_t)iv, M_TEMP);
1254 } else
1245 mtx_lock(&Giant); /* VFS */
1246 mtx_assert(&Giant, MA_OWNED); /* VFS */
1255 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1256 VFS_ASSERT_GIANT(vp->v_mount);
1247 aftat_ret = VOP_GETATTR(vp, vap, cred, td);
1248 vput(vp);
1257 aftat_ret = VOP_GETATTR(vp, vap, cred, td);
1258 vput(vp);
1249 mtx_unlock(&Giant); /* VFS */
1250 NFSD_LOCK();
1259 VFS_UNLOCK_GIANT(vfslocked);
1251 vp = NULL;
1252 if (!error)
1253 error = aftat_ret;
1260 vp = NULL;
1261 if (!error)
1262 error = aftat_ret;
1263 NFSD_LOCK();
1254ereply:
1255 NFSD_LOCK_ASSERT();
1256 nfsm_reply(NFSX_PREOPATTR(v3) + NFSX_POSTOPORFATTR(v3) +
1257 2 * NFSX_UNSIGNED + NFSX_WRITEVERF(v3));
1258 if (v3) {
1259 nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, vap);
1260 if (error) {
1261 error = 0;

--- 21 unchanged lines hidden (view full) ---

1283 /* v2 non-error case. */
1284 fp = nfsm_build(struct nfs_fattr *, NFSX_V2FATTR);
1285 nfsm_srvfillattr(vap, fp);
1286 }
1287 error = 0;
1288nfsmout:
1289 NFSD_LOCK_ASSERT();
1290 NFSD_UNLOCK();
1264ereply:
1265 NFSD_LOCK_ASSERT();
1266 nfsm_reply(NFSX_PREOPATTR(v3) + NFSX_POSTOPORFATTR(v3) +
1267 2 * NFSX_UNSIGNED + NFSX_WRITEVERF(v3));
1268 if (v3) {
1269 nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, vap);
1270 if (error) {
1271 error = 0;

--- 21 unchanged lines hidden (view full) ---

1293 /* v2 non-error case. */
1294 fp = nfsm_build(struct nfs_fattr *, NFSX_V2FATTR);
1295 nfsm_srvfillattr(vap, fp);
1296 }
1297 error = 0;
1298nfsmout:
1299 NFSD_LOCK_ASSERT();
1300 NFSD_UNLOCK();
1291 mtx_lock(&Giant); /* VFS */
1301 vfslocked = VFS_LOCK_GIANT(mntp);
1292 if (vp)
1293 vput(vp);
1294 vn_finished_write(mntp);
1302 if (vp)
1303 vput(vp);
1304 vn_finished_write(mntp);
1295 mtx_unlock(&Giant); /* VFS */
1305 VFS_UNLOCK_GIANT(vfslocked);
1296 NFSD_LOCK();
1297 return(error);
1298}
1299
1300/*
1301 * For the purposes of write gathering, we must decide if the credential
1302 * associated with two pending requests have equivilent privileges. Since
1303 * NFS only uses a subset of the BSD ucred -- the effective uid and group
1304 * IDs -- we have a compare routine that checks only the relevant fields.
1305 */
1306static int
1307nfsrv_samecred(struct ucred *cr1, struct ucred *cr2)
1308{
1309 int i;
1310
1306 NFSD_LOCK();
1307 return(error);
1308}
1309
1310/*
1311 * For the purposes of write gathering, we must decide if the credential
1312 * associated with two pending requests have equivilent privileges. Since
1313 * NFS only uses a subset of the BSD ucred -- the effective uid and group
1314 * IDs -- we have a compare routine that checks only the relevant fields.
1315 */
1316static int
1317nfsrv_samecred(struct ucred *cr1, struct ucred *cr2)
1318{
1319 int i;
1320
1321 NFSD_LOCK_DONTCARE();
1322
1311 if (cr1->cr_uid != cr2->cr_uid)
1312 return (0);
1313 if (cr1->cr_ngroups != cr2->cr_ngroups)
1314 return (0);
1315 for (i = 0; i < cr1->cr_ngroups; i++) {
1316 if (cr1->cr_groups[i] != cr2->cr_groups[i])
1317 return (0);
1318 }

--- 24 unchanged lines hidden (view full) ---

1343 caddr_t bpos, dpos;
1344 int error = 0, rdonly, len, forat_ret = 1;
1345 int ioflags, aftat_ret = 1, s, adjust, v3, zeroing;
1346 struct mbuf *mb, *mreq, *mrep, *md;
1347 struct vnode *vp = NULL;
1348 struct uio io, *uiop = &io;
1349 u_quad_t cur_usec;
1350 struct mount *mntp = NULL;
1323 if (cr1->cr_uid != cr2->cr_uid)
1324 return (0);
1325 if (cr1->cr_ngroups != cr2->cr_ngroups)
1326 return (0);
1327 for (i = 0; i < cr1->cr_ngroups; i++) {
1328 if (cr1->cr_groups[i] != cr2->cr_groups[i])
1329 return (0);
1330 }

--- 24 unchanged lines hidden (view full) ---

1355 caddr_t bpos, dpos;
1356 int error = 0, rdonly, len, forat_ret = 1;
1357 int ioflags, aftat_ret = 1, s, adjust, v3, zeroing;
1358 struct mbuf *mb, *mreq, *mrep, *md;
1359 struct vnode *vp = NULL;
1360 struct uio io, *uiop = &io;
1361 u_quad_t cur_usec;
1362 struct mount *mntp = NULL;
1363 int vfslocked;
1351
1352 NFSD_LOCK_ASSERT();
1353
1354 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
1355#ifndef nolint
1356 i = 0;
1357 len = 0;
1358#endif

--- 137 unchanged lines hidden (view full) ---

1496 NFS_DPF(WG, ("P%03x", nfsd->nd_retxid & 0xfff));
1497 LIST_REMOVE(nfsd, nd_tq);
1498 LIST_REMOVE(nfsd, nd_hash);
1499 splx(s);
1500 mrep = nfsd->nd_mrep;
1501 nfsd->nd_mrep = NULL;
1502 cred = nfsd->nd_cr;
1503 v3 = (nfsd->nd_flag & ND_NFSV3);
1364
1365 NFSD_LOCK_ASSERT();
1366
1367 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
1368#ifndef nolint
1369 i = 0;
1370 len = 0;
1371#endif

--- 137 unchanged lines hidden (view full) ---

1509 NFS_DPF(WG, ("P%03x", nfsd->nd_retxid & 0xfff));
1510 LIST_REMOVE(nfsd, nd_tq);
1511 LIST_REMOVE(nfsd, nd_hash);
1512 splx(s);
1513 mrep = nfsd->nd_mrep;
1514 nfsd->nd_mrep = NULL;
1515 cred = nfsd->nd_cr;
1516 v3 = (nfsd->nd_flag & ND_NFSV3);
1517 NFSD_UNLOCK();
1504 forat_ret = aftat_ret = 1;
1505 error = nfsrv_fhtovp(&nfsd->nd_fh, 1, &vp, cred, slp,
1506 nfsd->nd_nam, &rdonly, TRUE);
1507 if (!error) {
1508 if (v3) {
1518 forat_ret = aftat_ret = 1;
1519 error = nfsrv_fhtovp(&nfsd->nd_fh, 1, &vp, cred, slp,
1520 nfsd->nd_nam, &rdonly, TRUE);
1521 if (!error) {
1522 if (v3) {
1509 NFSD_UNLOCK();
1510 mtx_lock(&Giant); /* VFS */
1523 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1511 forat_ret = VOP_GETATTR(vp, &forat, cred, td);
1524 forat_ret = VOP_GETATTR(vp, &forat, cred, td);
1512 mtx_unlock(&Giant); /* VFS */
1513 NFSD_LOCK();
1525 VFS_UNLOCK_GIANT(vfslocked);
1514 }
1515 if (vp->v_type != VREG) {
1516 if (v3)
1517 error = EINVAL;
1518 else
1519 error = (vp->v_type == VDIR) ? EISDIR : EACCES;
1520 }
1521 } else {
1522 vp = NULL;
1523 }
1526 }
1527 if (vp->v_type != VREG) {
1528 if (v3)
1529 error = EINVAL;
1530 else
1531 error = (vp->v_type == VDIR) ? EISDIR : EACCES;
1532 }
1533 } else {
1534 vp = NULL;
1535 }
1524 NFSD_UNLOCK();
1525 mtx_lock(&Giant); /* VFS */
1536 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1526 if (!error)
1537 if (!error)
1527 error = nfsrv_access_withgiant(vp, VWRITE, cred, rdonly,
1528 td, 1);
1538 error = nfsrv_access(vp, VWRITE, cred, rdonly, td, 1);
1529 if (nfsd->nd_stable == NFSV3WRITE_UNSTABLE)
1530 ioflags = IO_NODELOCKED;
1531 else if (nfsd->nd_stable == NFSV3WRITE_DATASYNC)
1532 ioflags = (IO_SYNC | IO_NODELOCKED);
1533 else
1534 ioflags = (IO_METASYNC | IO_SYNC | IO_NODELOCKED);
1535 uiop->uio_rw = UIO_WRITE;
1536 uiop->uio_segflg = UIO_SYSSPACE;

--- 37 unchanged lines hidden (view full) ---

1574 FREE((caddr_t)iov, M_TEMP);
1575 }
1576 m_freem(mrep);
1577 if (vp) {
1578 aftat_ret = VOP_GETATTR(vp, &va, cred, td);
1579 vput(vp);
1580 vp = NULL;
1581 }
1539 if (nfsd->nd_stable == NFSV3WRITE_UNSTABLE)
1540 ioflags = IO_NODELOCKED;
1541 else if (nfsd->nd_stable == NFSV3WRITE_DATASYNC)
1542 ioflags = (IO_SYNC | IO_NODELOCKED);
1543 else
1544 ioflags = (IO_METASYNC | IO_SYNC | IO_NODELOCKED);
1545 uiop->uio_rw = UIO_WRITE;
1546 uiop->uio_segflg = UIO_SYSSPACE;

--- 37 unchanged lines hidden (view full) ---

1584 FREE((caddr_t)iov, M_TEMP);
1585 }
1586 m_freem(mrep);
1587 if (vp) {
1588 aftat_ret = VOP_GETATTR(vp, &va, cred, td);
1589 vput(vp);
1590 vp = NULL;
1591 }
1582 mtx_unlock(&Giant); /* VFS */
1583 NFSD_LOCK();
1592 VFS_UNLOCK_GIANT(vfslocked);
1584
1585 /*
1586 * Loop around generating replies for all write rpcs that have
1587 * now been completed.
1588 */
1593
1594 /*
1595 * Loop around generating replies for all write rpcs that have
1596 * now been completed.
1597 */
1598 NFSD_LOCK();
1589 swp = nfsd;
1590 do {
1591 NFS_DPF(WG, ("R%03x", nfsd->nd_retxid & 0xfff));
1592 if (error) {
1593 nfsm_writereply(NFSX_WCCDATA(v3));
1594 if (v3) {
1595 nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, &va);
1596 }

--- 46 unchanged lines hidden (view full) ---

1643 goto loop1;
1644 }
1645 splx(s);
1646
1647 /*
1648 * Search for a reply to return.
1649 */
1650 s = splsoftclock();
1599 swp = nfsd;
1600 do {
1601 NFS_DPF(WG, ("R%03x", nfsd->nd_retxid & 0xfff));
1602 if (error) {
1603 nfsm_writereply(NFSX_WCCDATA(v3));
1604 if (v3) {
1605 nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, &va);
1606 }

--- 46 unchanged lines hidden (view full) ---

1653 goto loop1;
1654 }
1655 splx(s);
1656
1657 /*
1658 * Search for a reply to return.
1659 */
1660 s = splsoftclock();
1661 NFSD_LOCK_ASSERT();
1651 LIST_FOREACH(nfsd, &slp->ns_tq, nd_tq)
1652 if (nfsd->nd_mreq) {
1653 NFS_DPF(WG, ("X%03x", nfsd->nd_retxid & 0xfff));
1654 LIST_REMOVE(nfsd, nd_tq);
1655 *mrq = nfsd->nd_mreq;
1656 *ndp = nfsd;
1657 break;
1658 }

--- 78 unchanged lines hidden (view full) ---

1737 caddr_t cp;
1738 struct mbuf *mb, *mreq;
1739 struct vnode *dirp = NULL;
1740 nfsfh_t nfh;
1741 fhandle_t *fhp;
1742 u_quad_t tempsize;
1743 u_char cverf[NFSX_V3CREATEVERF];
1744 struct mount *mp = NULL;
1662 LIST_FOREACH(nfsd, &slp->ns_tq, nd_tq)
1663 if (nfsd->nd_mreq) {
1664 NFS_DPF(WG, ("X%03x", nfsd->nd_retxid & 0xfff));
1665 LIST_REMOVE(nfsd, nd_tq);
1666 *mrq = nfsd->nd_mreq;
1667 *ndp = nfsd;
1668 break;
1669 }

--- 78 unchanged lines hidden (view full) ---

1748 caddr_t cp;
1749 struct mbuf *mb, *mreq;
1750 struct vnode *dirp = NULL;
1751 nfsfh_t nfh;
1752 fhandle_t *fhp;
1753 u_quad_t tempsize;
1754 u_char cverf[NFSX_V3CREATEVERF];
1755 struct mount *mp = NULL;
1756 int vfslocked;
1745
1746 NFSD_LOCK_ASSERT();
1747
1748 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
1749#ifndef nolint
1750 rdev = 0;
1751#endif
1752 ndclear(&nd);
1753
1754 fhp = &nfh.fh_generic;
1755 nfsm_srvmtofh(fhp);
1757
1758 NFSD_LOCK_ASSERT();
1759
1760 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
1761#ifndef nolint
1762 rdev = 0;
1763#endif
1764 ndclear(&nd);
1765
1766 fhp = &nfh.fh_generic;
1767 nfsm_srvmtofh(fhp);
1768 NFSD_UNLOCK();
1756 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
1757 error = ESTALE;
1769 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
1770 error = ESTALE;
1771 NFSD_LOCK();
1758 goto ereply_locked;
1759 }
1772 goto ereply_locked;
1773 }
1760 NFSD_UNLOCK();
1761 mtx_lock(&Giant); /* VFS */
1774 vfslocked = VFS_LOCK_GIANT(mp);
1762 (void) vn_start_write(NULL, &mp, V_WAIT);
1763 vfs_rel(mp); /* The write holds a ref. */
1775 (void) vn_start_write(NULL, &mp, V_WAIT);
1776 vfs_rel(mp); /* The write holds a ref. */
1764 mtx_unlock(&Giant); /* VFS */
1777 VFS_UNLOCK_GIANT(vfslocked);
1765 NFSD_LOCK();
1766 nfsm_srvnamesiz(len);
1767
1768 nd.ni_cnd.cn_cred = cred;
1769 nd.ni_cnd.cn_nameiop = CREATE;
1770 nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | SAVESTART;
1771
1772 /*

--- 4 unchanged lines hidden (view full) ---

1777 * set even if an error occurs, but the nd structure will not
1778 * be valid at all if an error occurs so we have to invalidate it
1779 * prior to calling nfsm_reply ( which might goto nfsmout ).
1780 */
1781 error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
1782 &dirp, v3, &dirfor, &dirfor_ret, td, FALSE);
1783 if (dirp && !v3) {
1784 NFSD_UNLOCK();
1778 NFSD_LOCK();
1779 nfsm_srvnamesiz(len);
1780
1781 nd.ni_cnd.cn_cred = cred;
1782 nd.ni_cnd.cn_nameiop = CREATE;
1783 nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | SAVESTART;
1784
1785 /*

--- 4 unchanged lines hidden (view full) ---

1790 * set even if an error occurs, but the nd structure will not
1791 * be valid at all if an error occurs so we have to invalidate it
1792 * prior to calling nfsm_reply ( which might goto nfsmout ).
1793 */
1794 error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
1795 &dirp, v3, &dirfor, &dirfor_ret, td, FALSE);
1796 if (dirp && !v3) {
1797 NFSD_UNLOCK();
1785 mtx_lock(&Giant); /* VFS */
1798 vfslocked = VFS_LOCK_GIANT(dirp->v_mount);
1786 vrele(dirp);
1799 vrele(dirp);
1787 mtx_unlock(&Giant); /* VFS */
1800 VFS_UNLOCK_GIANT(vfslocked);
1788 NFSD_LOCK();
1789 dirp = NULL;
1790 }
1791 if (error) {
1792 nfsm_reply(NFSX_WCCDATA(v3));
1793 if (v3)
1794 nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
1795 error = 0;

--- 28 unchanged lines hidden (view full) ---

1824 nfsm_srvsattr(vap);
1825 break;
1826 case NFSV3CREATE_EXCLUSIVE:
1827 cp = nfsm_dissect_nonblock(caddr_t, NFSX_V3CREATEVERF);
1828 bcopy(cp, cverf, NFSX_V3CREATEVERF);
1829 exclusive_flag = 1;
1830 break;
1831 };
1801 NFSD_LOCK();
1802 dirp = NULL;
1803 }
1804 if (error) {
1805 nfsm_reply(NFSX_WCCDATA(v3));
1806 if (v3)
1807 nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
1808 error = 0;

--- 28 unchanged lines hidden (view full) ---

1837 nfsm_srvsattr(vap);
1838 break;
1839 case NFSV3CREATE_EXCLUSIVE:
1840 cp = nfsm_dissect_nonblock(caddr_t, NFSX_V3CREATEVERF);
1841 bcopy(cp, cverf, NFSX_V3CREATEVERF);
1842 exclusive_flag = 1;
1843 break;
1844 };
1845 NFSD_UNLOCK();
1832 vap->va_type = VREG;
1833 } else {
1834 sp = nfsm_dissect_nonblock(struct nfsv2_sattr *, NFSX_V2SATTR);
1835 vap->va_type = IFTOVT(fxdr_unsigned(u_int32_t, sp->sa_mode));
1846 vap->va_type = VREG;
1847 } else {
1848 sp = nfsm_dissect_nonblock(struct nfsv2_sattr *, NFSX_V2SATTR);
1849 vap->va_type = IFTOVT(fxdr_unsigned(u_int32_t, sp->sa_mode));
1850 NFSD_UNLOCK();
1836 if (vap->va_type == VNON)
1837 vap->va_type = VREG;
1838 vap->va_mode = nfstov_mode(sp->sa_mode);
1839 switch (vap->va_type) {
1840 case VREG:
1841 tsize = fxdr_unsigned(int32_t, sp->sa_size);
1842 if (tsize != -1)
1843 vap->va_size = (u_quad_t)tsize;

--- 10 unchanged lines hidden (view full) ---

1854
1855 /*
1856 * Iff doesn't exist, create it
1857 * otherwise just truncate to 0 length
1858 * should I set the mode too ?
1859 *
1860 * The only possible error we can have at this point is EEXIST.
1861 * nd.ni_vp will also be non-NULL in that case.
1851 if (vap->va_type == VNON)
1852 vap->va_type = VREG;
1853 vap->va_mode = nfstov_mode(sp->sa_mode);
1854 switch (vap->va_type) {
1855 case VREG:
1856 tsize = fxdr_unsigned(int32_t, sp->sa_size);
1857 if (tsize != -1)
1858 vap->va_size = (u_quad_t)tsize;

--- 10 unchanged lines hidden (view full) ---

1869
1870 /*
1871 * Iff doesn't exist, create it
1872 * otherwise just truncate to 0 length
1873 * should I set the mode too ?
1874 *
1875 * The only possible error we can have at this point is EEXIST.
1876 * nd.ni_vp will also be non-NULL in that case.
1877 *
1878 * XXXRW: For now acquire Giant unconditionally during create to
1879 * avoid interactions between Giant for ndvp and Giant for vp if it
1880 * already exists.
1862 */
1881 */
1863 NFSD_UNLOCK();
1864 mtx_lock(&Giant); /* VFS */
1865 if (nd.ni_vp == NULL) {
1866 if (vap->va_mode == (mode_t)VNOVAL)
1867 vap->va_mode = 0;
1868 if (vap->va_type == VREG || vap->va_type == VSOCK) {
1869 error = VOP_CREATE(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, vap);
1870 if (error)
1871 NDFREE(&nd, NDF_ONLY_PNBUF);

--- 61 unchanged lines hidden (view full) ---

1933 error = EINVAL;
1934 goto ereply;
1935 }
1936 } else {
1937 error = ENXIO;
1938 }
1939 } else {
1940 if (vap->va_size != -1) {
1882 mtx_lock(&Giant); /* VFS */
1883 if (nd.ni_vp == NULL) {
1884 if (vap->va_mode == (mode_t)VNOVAL)
1885 vap->va_mode = 0;
1886 if (vap->va_type == VREG || vap->va_type == VSOCK) {
1887 error = VOP_CREATE(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, vap);
1888 if (error)
1889 NDFREE(&nd, NDF_ONLY_PNBUF);

--- 61 unchanged lines hidden (view full) ---

1951 error = EINVAL;
1952 goto ereply;
1953 }
1954 } else {
1955 error = ENXIO;
1956 }
1957 } else {
1958 if (vap->va_size != -1) {
1941 error = nfsrv_access_withgiant(nd.ni_vp, VWRITE,
1942 cred, (nd.ni_cnd.cn_flags & RDONLY), td, 0);
1959 error = nfsrv_access(nd.ni_vp, VWRITE, cred,
1960 (nd.ni_cnd.cn_flags & RDONLY), td, 0);
1943 if (!error) {
1944 tempsize = vap->va_size;
1945 VATTR_NULL(vap);
1946 vap->va_size = tempsize;
1947 error = VOP_SETATTR(nd.ni_vp, vap, cred,
1948 td);
1949 }
1950 }

--- 96 unchanged lines hidden (view full) ---

2047 u_int32_t major, minor;
2048 enum vtype vtyp;
2049 struct mbuf *mb, *mreq;
2050 struct vnode *vp, *dirp = NULL;
2051 nfsfh_t nfh;
2052 fhandle_t *fhp;
2053 struct mount *mp = NULL;
2054 int v3 = (nfsd->nd_flag & ND_NFSV3);
1961 if (!error) {
1962 tempsize = vap->va_size;
1963 VATTR_NULL(vap);
1964 vap->va_size = tempsize;
1965 error = VOP_SETATTR(nd.ni_vp, vap, cred,
1966 td);
1967 }
1968 }

--- 96 unchanged lines hidden (view full) ---

2065 u_int32_t major, minor;
2066 enum vtype vtyp;
2067 struct mbuf *mb, *mreq;
2068 struct vnode *vp, *dirp = NULL;
2069 nfsfh_t nfh;
2070 fhandle_t *fhp;
2071 struct mount *mp = NULL;
2072 int v3 = (nfsd->nd_flag & ND_NFSV3);
2073 int vfslocked;
2055
2056 NFSD_LOCK_ASSERT();
2057
2058 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
2059 if (!v3)
2060 panic("nfsrv_mknod: v3 proc called on a v2 connection");
2061 ndclear(&nd);
2062
2063 fhp = &nfh.fh_generic;
2064 nfsm_srvmtofh(fhp);
2074
2075 NFSD_LOCK_ASSERT();
2076
2077 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
2078 if (!v3)
2079 panic("nfsrv_mknod: v3 proc called on a v2 connection");
2080 ndclear(&nd);
2081
2082 fhp = &nfh.fh_generic;
2083 nfsm_srvmtofh(fhp);
2084 NFSD_UNLOCK();
2065 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
2066 error = ESTALE;
2085 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
2086 error = ESTALE;
2087 NFSD_LOCK();
2067 goto ereply;
2068 }
2088 goto ereply;
2089 }
2069 NFSD_UNLOCK();
2070 mtx_lock(&Giant); /* VFS */
2090 vfslocked = VFS_LOCK_GIANT(mp);
2071 (void) vn_start_write(NULL, &mp, V_WAIT);
2072 vfs_rel(mp); /* The write holds a ref. */
2091 (void) vn_start_write(NULL, &mp, V_WAIT);
2092 vfs_rel(mp); /* The write holds a ref. */
2073 mtx_unlock(&Giant); /* VFS */
2093 VFS_UNLOCK_GIANT(vfslocked);
2074 NFSD_LOCK();
2075 nfsm_srvnamesiz(len);
2076
2077 nd.ni_cnd.cn_cred = cred;
2078 nd.ni_cnd.cn_nameiop = CREATE;
2079 nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | SAVESTART;
2080
2081 /*

--- 5 unchanged lines hidden (view full) ---

2087 error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
2088 &dirp, v3, &dirfor, &dirfor_ret, td, FALSE);
2089 if (error) {
2090 nfsm_reply(NFSX_WCCDATA(1));
2091 nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
2092 error = 0;
2093 goto nfsmout;
2094 }
2094 NFSD_LOCK();
2095 nfsm_srvnamesiz(len);
2096
2097 nd.ni_cnd.cn_cred = cred;
2098 nd.ni_cnd.cn_nameiop = CREATE;
2099 nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | SAVESTART;
2100
2101 /*

--- 5 unchanged lines hidden (view full) ---

2107 error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
2108 &dirp, v3, &dirfor, &dirfor_ret, td, FALSE);
2109 if (error) {
2110 nfsm_reply(NFSX_WCCDATA(1));
2111 nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
2112 error = 0;
2113 goto nfsmout;
2114 }
2115
2116 /*
2117 * XXXRW: For now, acquire Giant unconditionally to avoid complexity
2118 * of dealing with Giant separately for dvp and vp.
2119 */
2095 tl = nfsm_dissect_nonblock(u_int32_t *, NFSX_UNSIGNED);
2096 vtyp = nfsv3tov_type(*tl);
2097 if (vtyp != VCHR && vtyp != VBLK && vtyp != VSOCK && vtyp != VFIFO) {
2098 NFSD_UNLOCK();
2120 tl = nfsm_dissect_nonblock(u_int32_t *, NFSX_UNSIGNED);
2121 vtyp = nfsv3tov_type(*tl);
2122 if (vtyp != VCHR && vtyp != VBLK && vtyp != VSOCK && vtyp != VFIFO) {
2123 NFSD_UNLOCK();
2099 mtx_lock(&Giant); /* VFS */
2100 error = NFSERR_BADTYPE;
2124 error = NFSERR_BADTYPE;
2125 mtx_lock(&Giant); /* VFS */
2101 goto out;
2102 }
2103 VATTR_NULL(vap);
2104 nfsm_srvsattr(vap);
2105 if (vtyp == VCHR || vtyp == VBLK) {
2106 tl = nfsm_dissect_nonblock(u_int32_t *, 2 * NFSX_UNSIGNED);
2107 major = fxdr_unsigned(u_int32_t, *tl++);
2108 minor = fxdr_unsigned(u_int32_t, *tl);
2109 vap->va_rdev = makedev(major, minor);
2110 }
2111
2112 /*
2113 * Iff doesn't exist, create it.
2114 */
2115 if (nd.ni_vp) {
2116 NFSD_UNLOCK();
2126 goto out;
2127 }
2128 VATTR_NULL(vap);
2129 nfsm_srvsattr(vap);
2130 if (vtyp == VCHR || vtyp == VBLK) {
2131 tl = nfsm_dissect_nonblock(u_int32_t *, 2 * NFSX_UNSIGNED);
2132 major = fxdr_unsigned(u_int32_t, *tl++);
2133 minor = fxdr_unsigned(u_int32_t, *tl);
2134 vap->va_rdev = makedev(major, minor);
2135 }
2136
2137 /*
2138 * Iff doesn't exist, create it.
2139 */
2140 if (nd.ni_vp) {
2141 NFSD_UNLOCK();
2117 mtx_lock(&Giant); /* VFS */
2118 error = EEXIST;
2142 error = EEXIST;
2143 mtx_lock(&Giant); /* VFS */
2119 goto out;
2120 }
2121 vap->va_type = vtyp;
2122 if (vap->va_mode == (mode_t)VNOVAL)
2123 vap->va_mode = 0;
2124 NFSD_UNLOCK();
2125 mtx_lock(&Giant); /* VFS */
2126 if (vtyp == VSOCK) {

--- 36 unchanged lines hidden (view full) ---

2163 if (nd.ni_cnd.cn_flags & ISSYMLINK)
2164 error = EINVAL;
2165 }
2166
2167 /*
2168 * send response, cleanup, return.
2169 */
2170out:
2144 goto out;
2145 }
2146 vap->va_type = vtyp;
2147 if (vap->va_mode == (mode_t)VNOVAL)
2148 vap->va_mode = 0;
2149 NFSD_UNLOCK();
2150 mtx_lock(&Giant); /* VFS */
2151 if (vtyp == VSOCK) {

--- 36 unchanged lines hidden (view full) ---

2188 if (nd.ni_cnd.cn_flags & ISSYMLINK)
2189 error = EINVAL;
2190 }
2191
2192 /*
2193 * send response, cleanup, return.
2194 */
2195out:
2196 GIANT_REQUIRED;
2171 NFSD_UNLOCK_ASSERT();
2172 vp = nd.ni_vp;
2173 if (!error) {
2174 bzero((caddr_t)fhp, sizeof(nfh));
2175 fhp->fh_fsid = vp->v_mount->mnt_stat.f_fsid;
2176 error = VFS_VPTOFH(vp, &fhp->fh_fid);
2177 if (!error)
2178 error = VOP_GETATTR(vp, vap, cred, td);

--- 28 unchanged lines hidden (view full) ---

2207 if (v3) {
2208 if (!error) {
2209 nfsm_srvpostop_fh(fhp);
2210 nfsm_srvpostop_attr(0, vap);
2211 }
2212 nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
2213 }
2214 NFSD_UNLOCK();
2197 NFSD_UNLOCK_ASSERT();
2198 vp = nd.ni_vp;
2199 if (!error) {
2200 bzero((caddr_t)fhp, sizeof(nfh));
2201 fhp->fh_fsid = vp->v_mount->mnt_stat.f_fsid;
2202 error = VFS_VPTOFH(vp, &fhp->fh_fid);
2203 if (!error)
2204 error = VOP_GETATTR(vp, vap, cred, td);

--- 28 unchanged lines hidden (view full) ---

2233 if (v3) {
2234 if (!error) {
2235 nfsm_srvpostop_fh(fhp);
2236 nfsm_srvpostop_attr(0, vap);
2237 }
2238 nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
2239 }
2240 NFSD_UNLOCK();
2215 mtx_lock(&Giant); /* VFS */
2241 vfslocked = VFS_LOCK_GIANT(mp);
2216 vn_finished_write(mp);
2242 vn_finished_write(mp);
2217 mtx_unlock(&Giant); /* VFS */
2243 VFS_UNLOCK_GIANT(vfslocked);
2218 NFSD_LOCK();
2219 return (0);
2220nfsmout:
2221 NFSD_LOCK_ASSERT();
2222 NFSD_UNLOCK();
2223 mtx_lock(&Giant); /* VFS */
2224 if (nd.ni_dvp) {
2225 if (nd.ni_dvp == nd.ni_vp)

--- 30 unchanged lines hidden (view full) ---

2256 int error = 0, len, dirfor_ret = 1, diraft_ret = 1;
2257 int v3 = (nfsd->nd_flag & ND_NFSV3);
2258 struct mbuf *mb, *mreq;
2259 struct vnode *dirp;
2260 struct vattr dirfor, diraft;
2261 nfsfh_t nfh;
2262 fhandle_t *fhp;
2263 struct mount *mp = NULL;
2244 NFSD_LOCK();
2245 return (0);
2246nfsmout:
2247 NFSD_LOCK_ASSERT();
2248 NFSD_UNLOCK();
2249 mtx_lock(&Giant); /* VFS */
2250 if (nd.ni_dvp) {
2251 if (nd.ni_dvp == nd.ni_vp)

--- 30 unchanged lines hidden (view full) ---

2282 int error = 0, len, dirfor_ret = 1, diraft_ret = 1;
2283 int v3 = (nfsd->nd_flag & ND_NFSV3);
2284 struct mbuf *mb, *mreq;
2285 struct vnode *dirp;
2286 struct vattr dirfor, diraft;
2287 nfsfh_t nfh;
2288 fhandle_t *fhp;
2289 struct mount *mp = NULL;
2290 int vfslocked;
2264
2265 NFSD_LOCK_ASSERT();
2266
2267 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
2268 ndclear(&nd);
2269
2270 fhp = &nfh.fh_generic;
2271 nfsm_srvmtofh(fhp);
2291
2292 NFSD_LOCK_ASSERT();
2293
2294 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
2295 ndclear(&nd);
2296
2297 fhp = &nfh.fh_generic;
2298 nfsm_srvmtofh(fhp);
2299 NFSD_UNLOCK();
2272 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
2273 error = ESTALE;
2300 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
2301 error = ESTALE;
2302 NFSD_LOCK();
2274 goto ereply;
2275 }
2303 goto ereply;
2304 }
2276 NFSD_UNLOCK();
2277 mtx_lock(&Giant); /* VFS */
2305 vfslocked = VFS_LOCK_GIANT(mp);
2278 (void) vn_start_write(NULL, &mp, V_WAIT);
2279 vfs_rel(mp); /* The write holds a ref. */
2306 (void) vn_start_write(NULL, &mp, V_WAIT);
2307 vfs_rel(mp); /* The write holds a ref. */
2280 mtx_unlock(&Giant); /* VFS */
2308 VFS_UNLOCK_GIANT(vfslocked);
2281 NFSD_LOCK();
2282 nfsm_srvnamesiz(len);
2283
2284 nd.ni_cnd.cn_cred = cred;
2285 nd.ni_cnd.cn_nameiop = DELETE;
2286 nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF;
2287 error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
2288 &dirp, v3, &dirfor, &dirfor_ret, td, FALSE);

--- 92 unchanged lines hidden (view full) ---

2381 struct nameidata fromnd, tond;
2382 struct vnode *fvp, *tvp, *tdvp, *fdirp = NULL;
2383 struct vnode *tdirp = NULL;
2384 struct vattr fdirfor, fdiraft, tdirfor, tdiraft;
2385 nfsfh_t fnfh, tnfh;
2386 fhandle_t *ffhp, *tfhp;
2387 uid_t saved_uid;
2388 struct mount *mp = NULL;
2309 NFSD_LOCK();
2310 nfsm_srvnamesiz(len);
2311
2312 nd.ni_cnd.cn_cred = cred;
2313 nd.ni_cnd.cn_nameiop = DELETE;
2314 nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF;
2315 error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
2316 &dirp, v3, &dirfor, &dirfor_ret, td, FALSE);

--- 92 unchanged lines hidden (view full) ---

2409 struct nameidata fromnd, tond;
2410 struct vnode *fvp, *tvp, *tdvp, *fdirp = NULL;
2411 struct vnode *tdirp = NULL;
2412 struct vattr fdirfor, fdiraft, tdirfor, tdiraft;
2413 nfsfh_t fnfh, tnfh;
2414 fhandle_t *ffhp, *tfhp;
2415 uid_t saved_uid;
2416 struct mount *mp = NULL;
2417 int vfslocked;
2389
2390 NFSD_LOCK_ASSERT();
2391
2392 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
2393#ifndef nolint
2394 fvp = NULL;
2395#endif
2396 ffhp = &fnfh.fh_generic;
2397 tfhp = &tnfh.fh_generic;
2398
2399 /*
2400 * Clear fields incase goto nfsmout occurs from macro.
2401 */
2402
2403 ndclear(&fromnd);
2404 ndclear(&tond);
2405
2406 nfsm_srvmtofh(ffhp);
2418
2419 NFSD_LOCK_ASSERT();
2420
2421 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
2422#ifndef nolint
2423 fvp = NULL;
2424#endif
2425 ffhp = &fnfh.fh_generic;
2426 tfhp = &tnfh.fh_generic;
2427
2428 /*
2429 * Clear fields incase goto nfsmout occurs from macro.
2430 */
2431
2432 ndclear(&fromnd);
2433 ndclear(&tond);
2434
2435 nfsm_srvmtofh(ffhp);
2436 NFSD_UNLOCK();
2407 if ((mp = vfs_getvfs(&ffhp->fh_fsid)) == NULL) {
2408 error = ESTALE;
2437 if ((mp = vfs_getvfs(&ffhp->fh_fsid)) == NULL) {
2438 error = ESTALE;
2439 NFSD_LOCK();
2409 goto out1;
2410 }
2440 goto out1;
2441 }
2411 NFSD_UNLOCK();
2412 mtx_lock(&Giant);
2442 vfslocked = VFS_LOCK_GIANT(mp);
2413 (void) vn_start_write(NULL, &mp, V_WAIT);
2414 vfs_rel(mp); /* The write holds a ref. */
2443 (void) vn_start_write(NULL, &mp, V_WAIT);
2444 vfs_rel(mp); /* The write holds a ref. */
2415 mtx_unlock(&Giant);
2445 VFS_UNLOCK_GIANT(vfslocked);
2416 NFSD_LOCK();
2417 nfsm_srvnamesiz(len);
2418 /*
2419 * Remember our original uid so that we can reset cr_uid before
2420 * the second nfs_namei() call, in case it is remapped.
2421 */
2422 saved_uid = cred->cr_uid;
2423 fromnd.ni_cnd.cn_cred = cred;
2424 fromnd.ni_cnd.cn_nameiop = DELETE;
2425 fromnd.ni_cnd.cn_flags = WANTPARENT | SAVESTART;
2426 error = nfs_namei(&fromnd, ffhp, len, slp, nam, &md,
2427 &dpos, &fdirp, v3, &fdirfor, &fdirfor_ret, td, FALSE);
2428 if (fdirp && !v3) {
2429 NFSD_UNLOCK();
2446 NFSD_LOCK();
2447 nfsm_srvnamesiz(len);
2448 /*
2449 * Remember our original uid so that we can reset cr_uid before
2450 * the second nfs_namei() call, in case it is remapped.
2451 */
2452 saved_uid = cred->cr_uid;
2453 fromnd.ni_cnd.cn_cred = cred;
2454 fromnd.ni_cnd.cn_nameiop = DELETE;
2455 fromnd.ni_cnd.cn_flags = WANTPARENT | SAVESTART;
2456 error = nfs_namei(&fromnd, ffhp, len, slp, nam, &md,
2457 &dpos, &fdirp, v3, &fdirfor, &fdirfor_ret, td, FALSE);
2458 if (fdirp && !v3) {
2459 NFSD_UNLOCK();
2430 mtx_lock(&Giant); /* VFS */
2460 vfslocked = VFS_LOCK_GIANT(fdirp->v_mount);
2431 vrele(fdirp);
2461 vrele(fdirp);
2432 mtx_unlock(&Giant); /* VFS */
2462 VFS_UNLOCK_GIANT(vfslocked);
2433 NFSD_LOCK();
2434 fdirp = NULL;
2435 }
2436 if (error) {
2437 nfsm_reply(2 * NFSX_WCCDATA(v3));
2438 if (v3) {
2439 nfsm_srvwcc_data(fdirfor_ret, &fdirfor, fdiraft_ret, &fdiraft);
2440 nfsm_srvwcc_data(tdirfor_ret, &tdirfor, tdiraft_ret, &tdiraft);

--- 72 unchanged lines hidden (view full) ---

2513 * then there is nothing to do.
2514 */
2515 if (fvp == tvp && fromnd.ni_dvp == tdvp &&
2516 fromnd.ni_cnd.cn_namelen == tond.ni_cnd.cn_namelen &&
2517 !bcmp(fromnd.ni_cnd.cn_nameptr, tond.ni_cnd.cn_nameptr,
2518 fromnd.ni_cnd.cn_namelen))
2519 error = -1;
2520out:
2463 NFSD_LOCK();
2464 fdirp = NULL;
2465 }
2466 if (error) {
2467 nfsm_reply(2 * NFSX_WCCDATA(v3));
2468 if (v3) {
2469 nfsm_srvwcc_data(fdirfor_ret, &fdirfor, fdiraft_ret, &fdiraft);
2470 nfsm_srvwcc_data(tdirfor_ret, &tdirfor, tdiraft_ret, &tdiraft);

--- 72 unchanged lines hidden (view full) ---

2543 * then there is nothing to do.
2544 */
2545 if (fvp == tvp && fromnd.ni_dvp == tdvp &&
2546 fromnd.ni_cnd.cn_namelen == tond.ni_cnd.cn_namelen &&
2547 !bcmp(fromnd.ni_cnd.cn_nameptr, tond.ni_cnd.cn_nameptr,
2548 fromnd.ni_cnd.cn_namelen))
2549 error = -1;
2550out:
2551 GIANT_REQUIRED;
2521 NFSD_UNLOCK_ASSERT();
2522 if (!error) {
2523 /*
2524 * The VOP_RENAME function releases all vnode references &
2525 * locks prior to returning so we need to clear the pointers
2526 * to bypass cleanup code later on.
2527 */
2528 error = VOP_RENAME(fromnd.ni_dvp, fromnd.ni_vp, &fromnd.ni_cnd,

--- 105 unchanged lines hidden (view full) ---

2634 int error = 0, rdonly, len, dirfor_ret = 1, diraft_ret = 1;
2635 int getret = 1, v3 = (nfsd->nd_flag & ND_NFSV3);
2636 struct mbuf *mb, *mreq;
2637 struct vnode *vp = NULL, *xp, *dirp = NULL;
2638 struct vattr dirfor, diraft, at;
2639 nfsfh_t nfh, dnfh;
2640 fhandle_t *fhp, *dfhp;
2641 struct mount *mp = NULL;
2552 NFSD_UNLOCK_ASSERT();
2553 if (!error) {
2554 /*
2555 * The VOP_RENAME function releases all vnode references &
2556 * locks prior to returning so we need to clear the pointers
2557 * to bypass cleanup code later on.
2558 */
2559 error = VOP_RENAME(fromnd.ni_dvp, fromnd.ni_vp, &fromnd.ni_cnd,

--- 105 unchanged lines hidden (view full) ---

2665 int error = 0, rdonly, len, dirfor_ret = 1, diraft_ret = 1;
2666 int getret = 1, v3 = (nfsd->nd_flag & ND_NFSV3);
2667 struct mbuf *mb, *mreq;
2668 struct vnode *vp = NULL, *xp, *dirp = NULL;
2669 struct vattr dirfor, diraft, at;
2670 nfsfh_t nfh, dnfh;
2671 fhandle_t *fhp, *dfhp;
2672 struct mount *mp = NULL;
2673 int vfslocked;
2642
2643 NFSD_LOCK_ASSERT();
2644
2645 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
2646 ndclear(&nd);
2647
2648 fhp = &nfh.fh_generic;
2649 dfhp = &dnfh.fh_generic;
2650 nfsm_srvmtofh(fhp);
2651 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
2652 error = ESTALE;
2653 goto ereply;
2654 }
2655 NFSD_UNLOCK();
2674
2675 NFSD_LOCK_ASSERT();
2676
2677 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
2678 ndclear(&nd);
2679
2680 fhp = &nfh.fh_generic;
2681 dfhp = &dnfh.fh_generic;
2682 nfsm_srvmtofh(fhp);
2683 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
2684 error = ESTALE;
2685 goto ereply;
2686 }
2687 NFSD_UNLOCK();
2656 mtx_lock(&Giant); /* VFS */
2688 vfslocked = VFS_LOCK_GIANT(mp);
2657 (void) vn_start_write(NULL, &mp, V_WAIT);
2658 vfs_rel(mp); /* The write holds a ref. */
2689 (void) vn_start_write(NULL, &mp, V_WAIT);
2690 vfs_rel(mp); /* The write holds a ref. */
2659 mtx_unlock(&Giant); /* VFS */
2691 VFS_UNLOCK_GIANT(vfslocked);
2660 NFSD_LOCK();
2661 nfsm_srvmtofh(dfhp);
2662 nfsm_srvnamesiz(len);
2663
2692 NFSD_LOCK();
2693 nfsm_srvmtofh(dfhp);
2694 nfsm_srvnamesiz(len);
2695
2664 error = nfsrv_fhtovp(fhp, TRUE, &vp, cred, slp, nam, &rdonly, TRUE);
2696 error = nfsrv_fhtovp_locked(fhp, TRUE, &vp, cred, slp, nam, &rdonly,
2697 TRUE);
2665 if (error) {
2666 nfsm_reply(NFSX_POSTOPATTR(v3) + NFSX_WCCDATA(v3));
2667 if (v3) {
2668 nfsm_srvpostop_attr(getret, &at);
2669 nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
2670 }
2671 vp = NULL;
2672 error = 0;

--- 125 unchanged lines hidden (view full) ---

2798 struct iovec iv;
2799 int error = 0, len, len2, dirfor_ret = 1, diraft_ret = 1;
2800 int v3 = (nfsd->nd_flag & ND_NFSV3);
2801 struct mbuf *mb, *mreq;
2802 struct vnode *dirp = NULL;
2803 nfsfh_t nfh;
2804 fhandle_t *fhp;
2805 struct mount *mp = NULL;
2698 if (error) {
2699 nfsm_reply(NFSX_POSTOPATTR(v3) + NFSX_WCCDATA(v3));
2700 if (v3) {
2701 nfsm_srvpostop_attr(getret, &at);
2702 nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
2703 }
2704 vp = NULL;
2705 error = 0;

--- 125 unchanged lines hidden (view full) ---

2831 struct iovec iv;
2832 int error = 0, len, len2, dirfor_ret = 1, diraft_ret = 1;
2833 int v3 = (nfsd->nd_flag & ND_NFSV3);
2834 struct mbuf *mb, *mreq;
2835 struct vnode *dirp = NULL;
2836 nfsfh_t nfh;
2837 fhandle_t *fhp;
2838 struct mount *mp = NULL;
2839 int vfslocked;
2806
2807 NFSD_LOCK_ASSERT();
2808
2809 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
2810 ndclear(&nd);
2811
2840
2841 NFSD_LOCK_ASSERT();
2842
2843 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
2844 ndclear(&nd);
2845
2846 /*
2847 * XXXRW: For now, unconditionally acquire Giant in several places to
2848 * avoid complexity of unwinding separately when several vnodes are
2849 * in flight.
2850 */
2812 fhp = &nfh.fh_generic;
2813 nfsm_srvmtofh(fhp);
2814 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
2815 NFSD_UNLOCK();
2816 mtx_lock(&Giant); /* VFS */
2817 error = ESTALE;
2818 goto out;
2819 }
2820 NFSD_UNLOCK();
2851 fhp = &nfh.fh_generic;
2852 nfsm_srvmtofh(fhp);
2853 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
2854 NFSD_UNLOCK();
2855 mtx_lock(&Giant); /* VFS */
2856 error = ESTALE;
2857 goto out;
2858 }
2859 NFSD_UNLOCK();
2821 mtx_lock(&Giant); /* VFS */
2860 vfslocked = VFS_LOCK_GIANT(mp);
2822 (void) vn_start_write(NULL, &mp, V_WAIT);
2823 vfs_rel(mp); /* The write holds a ref. */
2861 (void) vn_start_write(NULL, &mp, V_WAIT);
2862 vfs_rel(mp); /* The write holds a ref. */
2824 mtx_unlock(&Giant); /* VFS */
2863 VFS_UNLOCK_GIANT(vfslocked);
2825 NFSD_LOCK();
2826 nfsm_srvnamesiz(len);
2827 nd.ni_cnd.cn_cred = cred;
2828 nd.ni_cnd.cn_nameiop = CREATE;
2829 nd.ni_cnd.cn_flags = LOCKPARENT | SAVESTART;
2830 error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
2831 &dirp, v3, &dirfor, &dirfor_ret, td, FALSE);
2832 if (error == 0) {

--- 161 unchanged lines hidden (view full) ---

2994 int error = 0, len, dirfor_ret = 1, diraft_ret = 1;
2995 int v3 = (nfsd->nd_flag & ND_NFSV3);
2996 struct mbuf *mb, *mreq;
2997 struct vnode *dirp = NULL;
2998 int vpexcl = 0;
2999 nfsfh_t nfh;
3000 fhandle_t *fhp;
3001 struct mount *mp = NULL;
2864 NFSD_LOCK();
2865 nfsm_srvnamesiz(len);
2866 nd.ni_cnd.cn_cred = cred;
2867 nd.ni_cnd.cn_nameiop = CREATE;
2868 nd.ni_cnd.cn_flags = LOCKPARENT | SAVESTART;
2869 error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
2870 &dirp, v3, &dirfor, &dirfor_ret, td, FALSE);
2871 if (error == 0) {

--- 161 unchanged lines hidden (view full) ---

3033 int error = 0, len, dirfor_ret = 1, diraft_ret = 1;
3034 int v3 = (nfsd->nd_flag & ND_NFSV3);
3035 struct mbuf *mb, *mreq;
3036 struct vnode *dirp = NULL;
3037 int vpexcl = 0;
3038 nfsfh_t nfh;
3039 fhandle_t *fhp;
3040 struct mount *mp = NULL;
3041 int vfslocked;
3002
3003 NFSD_LOCK_ASSERT();
3004
3005 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
3006 ndclear(&nd);
3007
3042
3043 NFSD_LOCK_ASSERT();
3044
3045 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
3046 ndclear(&nd);
3047
3048 /*
3049 * XXXRW: For now, unconditionally acquire Giant so as to avoid the
3050 * complexity of tracking it for several in-flight vnodes.
3051 */
3008 fhp = &nfh.fh_generic;
3009 nfsm_srvmtofh(fhp);
3010 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
3011 NFSD_UNLOCK();
3012 mtx_lock(&Giant); /* VFS */
3013 error = ESTALE;
3014 goto out;
3015 }
3016 NFSD_UNLOCK();
3052 fhp = &nfh.fh_generic;
3053 nfsm_srvmtofh(fhp);
3054 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
3055 NFSD_UNLOCK();
3056 mtx_lock(&Giant); /* VFS */
3057 error = ESTALE;
3058 goto out;
3059 }
3060 NFSD_UNLOCK();
3017 mtx_lock(&Giant); /* VFS */
3061 vfslocked = VFS_LOCK_GIANT(mp);
3018 (void) vn_start_write(NULL, &mp, V_WAIT);
3019 vfs_rel(mp); /* The write holds a ref. */
3062 (void) vn_start_write(NULL, &mp, V_WAIT);
3063 vfs_rel(mp); /* The write holds a ref. */
3020 mtx_unlock(&Giant); /* VFS */
3064 VFS_UNLOCK_GIANT(vfslocked);
3021 NFSD_LOCK();
3022 nfsm_srvnamesiz(len);
3023 nd.ni_cnd.cn_cred = cred;
3024 nd.ni_cnd.cn_nameiop = CREATE;
3025 nd.ni_cnd.cn_flags = LOCKPARENT;
3026
3027 error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
3028 &dirp, v3, &dirfor, &dirfor_ret, td, FALSE);
3029 if (dirp && !v3) {
3030 NFSD_UNLOCK();
3065 NFSD_LOCK();
3066 nfsm_srvnamesiz(len);
3067 nd.ni_cnd.cn_cred = cred;
3068 nd.ni_cnd.cn_nameiop = CREATE;
3069 nd.ni_cnd.cn_flags = LOCKPARENT;
3070
3071 error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
3072 &dirp, v3, &dirfor, &dirfor_ret, td, FALSE);
3073 if (dirp && !v3) {
3074 NFSD_UNLOCK();
3031 mtx_lock(&Giant); /* VFS */
3075 vfslocked = VFS_LOCK_GIANT(dirp->v_mount);
3032 vrele(dirp);
3076 vrele(dirp);
3033 mtx_unlock(&Giant); /* VFS */
3077 VFS_UNLOCK_GIANT(vfslocked);
3034 NFSD_LOCK();
3035 dirp = NULL;
3036 }
3037 if (error) {
3038 nfsm_reply(NFSX_WCCDATA(v3));
3039 if (v3)
3040 nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
3041 error = 0;

--- 128 unchanged lines hidden (view full) ---

3170 int v3 = (nfsd->nd_flag & ND_NFSV3);
3171 struct mbuf *mb, *mreq;
3172 struct vnode *vp, *dirp = NULL;
3173 struct vattr dirfor, diraft;
3174 nfsfh_t nfh;
3175 fhandle_t *fhp;
3176 struct nameidata nd;
3177 struct mount *mp = NULL;
3078 NFSD_LOCK();
3079 dirp = NULL;
3080 }
3081 if (error) {
3082 nfsm_reply(NFSX_WCCDATA(v3));
3083 if (v3)
3084 nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
3085 error = 0;

--- 128 unchanged lines hidden (view full) ---

3214 int v3 = (nfsd->nd_flag & ND_NFSV3);
3215 struct mbuf *mb, *mreq;
3216 struct vnode *vp, *dirp = NULL;
3217 struct vattr dirfor, diraft;
3218 nfsfh_t nfh;
3219 fhandle_t *fhp;
3220 struct nameidata nd;
3221 struct mount *mp = NULL;
3222 int vfslocked;
3178
3179 NFSD_LOCK_ASSERT();
3180
3181 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
3182 ndclear(&nd);
3183
3184 fhp = &nfh.fh_generic;
3185 nfsm_srvmtofh(fhp);
3186 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
3187 error = ESTALE;
3188 goto out;
3189 }
3190 NFSD_UNLOCK();
3223
3224 NFSD_LOCK_ASSERT();
3225
3226 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
3227 ndclear(&nd);
3228
3229 fhp = &nfh.fh_generic;
3230 nfsm_srvmtofh(fhp);
3231 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
3232 error = ESTALE;
3233 goto out;
3234 }
3235 NFSD_UNLOCK();
3191 mtx_lock(&Giant); /* VFS */
3236 vfslocked = VFS_LOCK_GIANT(mp);
3192 (void) vn_start_write(NULL, &mp, V_WAIT);
3193 vfs_rel(mp); /* The write holds a ref. */
3237 (void) vn_start_write(NULL, &mp, V_WAIT);
3238 vfs_rel(mp); /* The write holds a ref. */
3194 mtx_unlock(&Giant); /* VFS */
3239 VFS_UNLOCK_GIANT(vfslocked);
3195 NFSD_LOCK();
3196 nfsm_srvnamesiz(len);
3197 nd.ni_cnd.cn_cred = cred;
3198 nd.ni_cnd.cn_nameiop = DELETE;
3199 nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF;
3200 error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
3201 &dirp, v3, &dirfor, &dirfor_ret, td, FALSE);
3202 if (dirp && !v3) {
3203 NFSD_UNLOCK();
3240 NFSD_LOCK();
3241 nfsm_srvnamesiz(len);
3242 nd.ni_cnd.cn_cred = cred;
3243 nd.ni_cnd.cn_nameiop = DELETE;
3244 nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF;
3245 error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
3246 &dirp, v3, &dirfor, &dirfor_ret, td, FALSE);
3247 if (dirp && !v3) {
3248 NFSD_UNLOCK();
3204 mtx_lock(&Giant); /* VFS */
3249 vfslocked = VFS_LOCK_GIANT(dirp->v_mount);
3205 vrele(dirp);
3250 vrele(dirp);
3206 mtx_unlock(&Giant); /* VFS */
3251 VFS_UNLOCK_GIANT(vfslocked);
3207 NFSD_LOCK();
3208 dirp = NULL;
3209 }
3210 if (error) {
3211 nfsm_reply(NFSX_WCCDATA(v3));
3212 if (v3)
3213 nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
3214 error = 0;

--- 15 unchanged lines hidden (view full) ---

3230 * The root of a mounted filesystem cannot be deleted.
3231 */
3232 if (vp->v_vflag & VV_ROOT)
3233 error = EBUSY;
3234out:
3235 /*
3236 * Issue or abort op. Since SAVESTART is not set, path name
3237 * component is freed by the VOP after either.
3252 NFSD_LOCK();
3253 dirp = NULL;
3254 }
3255 if (error) {
3256 nfsm_reply(NFSX_WCCDATA(v3));
3257 if (v3)
3258 nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
3259 error = 0;

--- 15 unchanged lines hidden (view full) ---

3275 * The root of a mounted filesystem cannot be deleted.
3276 */
3277 if (vp->v_vflag & VV_ROOT)
3278 error = EBUSY;
3279out:
3280 /*
3281 * Issue or abort op. Since SAVESTART is not set, path name
3282 * component is freed by the VOP after either.
3283 *
3284 * XXXRW: For now, acquire Giant unconditionally to avoid the
3285 * complexity of unwinding Giant for several vnodes in flight.
3238 */
3239 NFSD_LOCK_ASSERT();
3240 NFSD_UNLOCK();
3241 mtx_lock(&Giant); /* VFS */
3242 if (!error)
3243 error = VOP_RMDIR(nd.ni_dvp, nd.ni_vp, &nd.ni_cnd);
3244 NDFREE(&nd, NDF_ONLY_PNBUF);
3245

--- 107 unchanged lines hidden (view full) ---

3353 fhandle_t *fhp;
3354 struct uio io;
3355 struct iovec iv;
3356 int len, nlen, rem, xfer, tsiz, i, error = 0, getret = 1;
3357 int siz, cnt, fullsiz, eofflag, rdonly, ncookies;
3358 int v3 = (nfsd->nd_flag & ND_NFSV3);
3359 u_quad_t off, toff, verf;
3360 u_long *cookies = NULL, *cookiep; /* needs to be int64_t or off_t */
3286 */
3287 NFSD_LOCK_ASSERT();
3288 NFSD_UNLOCK();
3289 mtx_lock(&Giant); /* VFS */
3290 if (!error)
3291 error = VOP_RMDIR(nd.ni_dvp, nd.ni_vp, &nd.ni_cnd);
3292 NDFREE(&nd, NDF_ONLY_PNBUF);
3293

--- 107 unchanged lines hidden (view full) ---

3401 fhandle_t *fhp;
3402 struct uio io;
3403 struct iovec iv;
3404 int len, nlen, rem, xfer, tsiz, i, error = 0, getret = 1;
3405 int siz, cnt, fullsiz, eofflag, rdonly, ncookies;
3406 int v3 = (nfsd->nd_flag & ND_NFSV3);
3407 u_quad_t off, toff, verf;
3408 u_long *cookies = NULL, *cookiep; /* needs to be int64_t or off_t */
3409 int vfslocked;
3361
3362 NFSD_LOCK_ASSERT();
3363
3364 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
3365 fhp = &nfh.fh_generic;
3366 nfsm_srvmtofh(fhp);
3367 if (v3) {
3368 tl = nfsm_dissect_nonblock(u_int32_t *, 5 * NFSX_UNSIGNED);
3369 toff = fxdr_hyper(tl);
3370 tl += 2;
3371 verf = fxdr_hyper(tl);
3372 tl += 2;
3373 } else {
3374 tl = nfsm_dissect_nonblock(u_int32_t *, 2 * NFSX_UNSIGNED);
3375 toff = fxdr_unsigned(u_quad_t, *tl++);
3376 verf = 0; /* shut up gcc */
3377 }
3410
3411 NFSD_LOCK_ASSERT();
3412
3413 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
3414 fhp = &nfh.fh_generic;
3415 nfsm_srvmtofh(fhp);
3416 if (v3) {
3417 tl = nfsm_dissect_nonblock(u_int32_t *, 5 * NFSX_UNSIGNED);
3418 toff = fxdr_hyper(tl);
3419 tl += 2;
3420 verf = fxdr_hyper(tl);
3421 tl += 2;
3422 } else {
3423 tl = nfsm_dissect_nonblock(u_int32_t *, 2 * NFSX_UNSIGNED);
3424 toff = fxdr_unsigned(u_quad_t, *tl++);
3425 verf = 0; /* shut up gcc */
3426 }
3427 NFSD_UNLOCK();
3378 off = toff;
3379 cnt = fxdr_unsigned(int, *tl);
3380 siz = ((cnt + DIRBLKSIZ - 1) & ~(DIRBLKSIZ - 1));
3381 xfer = NFS_SRVMAXDATA(nfsd);
3382 if (cnt > xfer)
3383 cnt = xfer;
3384 if (siz > xfer)
3385 siz = xfer;
3386 fullsiz = siz;
3387 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
3388 if (!error && vp->v_type != VDIR) {
3389 error = ENOTDIR;
3428 off = toff;
3429 cnt = fxdr_unsigned(int, *tl);
3430 siz = ((cnt + DIRBLKSIZ - 1) & ~(DIRBLKSIZ - 1));
3431 xfer = NFS_SRVMAXDATA(nfsd);
3432 if (cnt > xfer)
3433 cnt = xfer;
3434 if (siz > xfer)
3435 siz = xfer;
3436 fullsiz = siz;
3437 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
3438 if (!error && vp->v_type != VDIR) {
3439 error = ENOTDIR;
3390 NFSD_UNLOCK();
3391 mtx_lock(&Giant); /* VFS */
3440 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
3392 vput(vp);
3441 vput(vp);
3393 mtx_unlock(&Giant); /* VFS */
3394 NFSD_LOCK();
3442 VFS_UNLOCK_GIANT(vfslocked);
3395 vp = NULL;
3396 }
3397 if (error) {
3443 vp = NULL;
3444 }
3445 if (error) {
3446 NFSD_LOCK();
3398 nfsm_reply(NFSX_UNSIGNED);
3399 if (v3)
3400 nfsm_srvpostop_attr(getret, &at);
3401 error = 0;
3402 goto nfsmout;
3403 }
3404
3405 /*
3406 * Obtain lock on vnode for this section of the code
3407 */
3447 nfsm_reply(NFSX_UNSIGNED);
3448 if (v3)
3449 nfsm_srvpostop_attr(getret, &at);
3450 error = 0;
3451 goto nfsmout;
3452 }
3453
3454 /*
3455 * Obtain lock on vnode for this section of the code
3456 */
3408 NFSD_UNLOCK();
3409 mtx_lock(&Giant); /* VFS */
3457 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
3410 if (v3) {
3411 error = getret = VOP_GETATTR(vp, &at, cred, td);
3412#if 0
3413 /*
3414 * XXX This check may be too strict for Solaris 2.5 clients.
3415 */
3416 if (!error && toff && verf && verf != at.va_filerev)
3417 error = NFSERR_BAD_COOKIE;
3418#endif
3419 }
3420 if (!error)
3458 if (v3) {
3459 error = getret = VOP_GETATTR(vp, &at, cred, td);
3460#if 0
3461 /*
3462 * XXX This check may be too strict for Solaris 2.5 clients.
3463 */
3464 if (!error && toff && verf && verf != at.va_filerev)
3465 error = NFSERR_BAD_COOKIE;
3466#endif
3467 }
3468 if (!error)
3421 error = nfsrv_access_withgiant(vp, VEXEC, cred, rdonly, td, 0);
3469 error = nfsrv_access(vp, VEXEC, cred, rdonly, td, 0);
3422 if (error) {
3423 vput(vp);
3470 if (error) {
3471 vput(vp);
3424 mtx_unlock(&Giant); /* VFS */
3472 VFS_UNLOCK_GIANT(vfslocked);
3425 NFSD_LOCK();
3426 vp = NULL;
3427 nfsm_reply(NFSX_POSTOPATTR(v3));
3428 if (v3)
3429 nfsm_srvpostop_attr(getret, &at);
3430 error = 0;
3431 goto nfsmout;
3432 }

--- 27 unchanged lines hidden (view full) ---

3460 if (v3) {
3461 getret = VOP_GETATTR(vp, &at, cred, td);
3462 if (!error)
3463 error = getret;
3464 }
3465 VOP_UNLOCK(vp, 0, td);
3466 if (error) {
3467 vrele(vp);
3473 NFSD_LOCK();
3474 vp = NULL;
3475 nfsm_reply(NFSX_POSTOPATTR(v3));
3476 if (v3)
3477 nfsm_srvpostop_attr(getret, &at);
3478 error = 0;
3479 goto nfsmout;
3480 }

--- 27 unchanged lines hidden (view full) ---

3508 if (v3) {
3509 getret = VOP_GETATTR(vp, &at, cred, td);
3510 if (!error)
3511 error = getret;
3512 }
3513 VOP_UNLOCK(vp, 0, td);
3514 if (error) {
3515 vrele(vp);
3468 mtx_unlock(&Giant); /* VFS */
3516 VFS_UNLOCK_GIANT(vfslocked);
3469 vp = NULL;
3470 free((caddr_t)rbuf, M_TEMP);
3471 if (cookies)
3472 free((caddr_t)cookies, M_TEMP);
3473 NFSD_LOCK();
3474 nfsm_reply(NFSX_POSTOPATTR(v3));
3475 if (v3)
3476 nfsm_srvpostop_attr(getret, &at);

--- 4 unchanged lines hidden (view full) ---

3481 siz -= io.uio_resid;
3482
3483 /*
3484 * If nothing read, return eof
3485 * rpc reply
3486 */
3487 if (siz == 0) {
3488 vrele(vp);
3517 vp = NULL;
3518 free((caddr_t)rbuf, M_TEMP);
3519 if (cookies)
3520 free((caddr_t)cookies, M_TEMP);
3521 NFSD_LOCK();
3522 nfsm_reply(NFSX_POSTOPATTR(v3));
3523 if (v3)
3524 nfsm_srvpostop_attr(getret, &at);

--- 4 unchanged lines hidden (view full) ---

3529 siz -= io.uio_resid;
3530
3531 /*
3532 * If nothing read, return eof
3533 * rpc reply
3534 */
3535 if (siz == 0) {
3536 vrele(vp);
3489 mtx_unlock(&Giant); /* VFS */
3537 VFS_UNLOCK_GIANT(vfslocked);
3490 vp = NULL;
3491 NFSD_LOCK();
3492 nfsm_reply(NFSX_POSTOPATTR(v3) + NFSX_COOKIEVERF(v3) +
3493 2 * NFSX_UNSIGNED);
3494 if (v3) {
3495 nfsm_srvpostop_attr(getret, &at);
3496 tl = nfsm_build(u_int32_t *, 4 * NFSX_UNSIGNED);
3497 txdr_hyper(at.va_filerev, tl);

--- 33 unchanged lines hidden (view full) ---

3531 ncookies--;
3532 }
3533 if (cpos >= cend || ncookies == 0) {
3534 toff = off;
3535 siz = fullsiz;
3536 goto again;
3537 }
3538
3538 vp = NULL;
3539 NFSD_LOCK();
3540 nfsm_reply(NFSX_POSTOPATTR(v3) + NFSX_COOKIEVERF(v3) +
3541 2 * NFSX_UNSIGNED);
3542 if (v3) {
3543 nfsm_srvpostop_attr(getret, &at);
3544 tl = nfsm_build(u_int32_t *, 4 * NFSX_UNSIGNED);
3545 txdr_hyper(at.va_filerev, tl);

--- 33 unchanged lines hidden (view full) ---

3579 ncookies--;
3580 }
3581 if (cpos >= cend || ncookies == 0) {
3582 toff = off;
3583 siz = fullsiz;
3584 goto again;
3585 }
3586
3539 mtx_unlock(&Giant); /* VFS */
3587 VFS_UNLOCK_GIANT(vfslocked);
3540 NFSD_LOCK();
3541 len = 3 * NFSX_UNSIGNED; /* paranoia, probably can be 0 */
3542 nfsm_reply(NFSX_POSTOPATTR(v3) + NFSX_COOKIEVERF(v3) + siz);
3543 if (v3) {
3544 nfsm_srvpostop_attr(getret, &at);
3545 tl = nfsm_build(u_int32_t *, 2 * NFSX_UNSIGNED);
3546 txdr_hyper(at.va_filerev, tl);
3547 }

--- 62 unchanged lines hidden (view full) ---

3610 bp += NFSX_UNSIGNED;
3611 }
3612 cpos += dp->d_reclen;
3613 dp = (struct dirent *)cpos;
3614 cookiep++;
3615 ncookies--;
3616 }
3617 NFSD_UNLOCK();
3588 NFSD_LOCK();
3589 len = 3 * NFSX_UNSIGNED; /* paranoia, probably can be 0 */
3590 nfsm_reply(NFSX_POSTOPATTR(v3) + NFSX_COOKIEVERF(v3) + siz);
3591 if (v3) {
3592 nfsm_srvpostop_attr(getret, &at);
3593 tl = nfsm_build(u_int32_t *, 2 * NFSX_UNSIGNED);
3594 txdr_hyper(at.va_filerev, tl);
3595 }

--- 62 unchanged lines hidden (view full) ---

3658 bp += NFSX_UNSIGNED;
3659 }
3660 cpos += dp->d_reclen;
3661 dp = (struct dirent *)cpos;
3662 cookiep++;
3663 ncookies--;
3664 }
3665 NFSD_UNLOCK();
3618 mtx_lock(&Giant); /* VFS */
3666 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
3619 vrele(vp);
3667 vrele(vp);
3620 mtx_unlock(&Giant); /* VFS */
3668 VFS_UNLOCK_GIANT(vfslocked);
3621 NFSD_LOCK();
3622 vp = NULL;
3623 nfsm_clget;
3624 *tl = nfsrv_nfs_false;
3625 bp += NFSX_UNSIGNED;
3626 nfsm_clget;
3627 if (eofflag)
3628 *tl = nfsrv_nfs_true;

--- 7 unchanged lines hidden (view full) ---

3636 mp->m_len += bp - bpos;
3637 FREE((caddr_t)rbuf, M_TEMP);
3638 FREE((caddr_t)cookies, M_TEMP);
3639
3640nfsmout:
3641 NFSD_LOCK_ASSERT();
3642 if (vp) {
3643 NFSD_UNLOCK();
3669 NFSD_LOCK();
3670 vp = NULL;
3671 nfsm_clget;
3672 *tl = nfsrv_nfs_false;
3673 bp += NFSX_UNSIGNED;
3674 nfsm_clget;
3675 if (eofflag)
3676 *tl = nfsrv_nfs_true;

--- 7 unchanged lines hidden (view full) ---

3684 mp->m_len += bp - bpos;
3685 FREE((caddr_t)rbuf, M_TEMP);
3686 FREE((caddr_t)cookies, M_TEMP);
3687
3688nfsmout:
3689 NFSD_LOCK_ASSERT();
3690 if (vp) {
3691 NFSD_UNLOCK();
3644 mtx_lock(&Giant); /* VFS */
3692 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
3645 vrele(vp);
3693 vrele(vp);
3646 mtx_unlock(&Giant); /* VFS */
3694 VFS_UNLOCK_GIANT(vfslocked);
3647 NFSD_LOCK();
3648 }
3649 return(error);
3650}
3651
3652int
3653nfsrv_readdirplus(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
3654 struct thread *td, struct mbuf **mrq)

--- 18 unchanged lines hidden (view full) ---

3673 struct iovec iv;
3674 struct vattr va, at, *vap = &va;
3675 struct nfs_fattr *fp;
3676 int len, nlen, rem, xfer, tsiz, i, error = 0, getret = 1;
3677 int siz, cnt, fullsiz, eofflag, rdonly, dirlen, ncookies;
3678 u_quad_t off, toff, verf;
3679 u_long *cookies = NULL, *cookiep; /* needs to be int64_t or off_t */
3680 int v3 = (nfsd->nd_flag & ND_NFSV3);
3695 NFSD_LOCK();
3696 }
3697 return(error);
3698}
3699
3700int
3701nfsrv_readdirplus(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
3702 struct thread *td, struct mbuf **mrq)

--- 18 unchanged lines hidden (view full) ---

3721 struct iovec iv;
3722 struct vattr va, at, *vap = &va;
3723 struct nfs_fattr *fp;
3724 int len, nlen, rem, xfer, tsiz, i, error = 0, getret = 1;
3725 int siz, cnt, fullsiz, eofflag, rdonly, dirlen, ncookies;
3726 u_quad_t off, toff, verf;
3727 u_long *cookies = NULL, *cookiep; /* needs to be int64_t or off_t */
3728 int v3 = (nfsd->nd_flag & ND_NFSV3);
3729 int vfslocked;
3681
3682 NFSD_LOCK_ASSERT();
3683
3684 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
3685 if (!v3)
3686 panic("nfsrv_readdirplus: v3 proc called on a v2 connection");
3687 fhp = &nfh.fh_generic;
3688 nfsm_srvmtofh(fhp);
3689 tl = nfsm_dissect_nonblock(u_int32_t *, 6 * NFSX_UNSIGNED);
3690 toff = fxdr_hyper(tl);
3691 tl += 2;
3692 verf = fxdr_hyper(tl);
3693 tl += 2;
3694 siz = fxdr_unsigned(int, *tl++);
3695 cnt = fxdr_unsigned(int, *tl);
3696 off = toff;
3697 siz = ((siz + DIRBLKSIZ - 1) & ~(DIRBLKSIZ - 1));
3698 xfer = NFS_SRVMAXDATA(nfsd);
3730
3731 NFSD_LOCK_ASSERT();
3732
3733 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
3734 if (!v3)
3735 panic("nfsrv_readdirplus: v3 proc called on a v2 connection");
3736 fhp = &nfh.fh_generic;
3737 nfsm_srvmtofh(fhp);
3738 tl = nfsm_dissect_nonblock(u_int32_t *, 6 * NFSX_UNSIGNED);
3739 toff = fxdr_hyper(tl);
3740 tl += 2;
3741 verf = fxdr_hyper(tl);
3742 tl += 2;
3743 siz = fxdr_unsigned(int, *tl++);
3744 cnt = fxdr_unsigned(int, *tl);
3745 off = toff;
3746 siz = ((siz + DIRBLKSIZ - 1) & ~(DIRBLKSIZ - 1));
3747 xfer = NFS_SRVMAXDATA(nfsd);
3748 NFSD_UNLOCK();
3699 if (cnt > xfer)
3700 cnt = xfer;
3701 if (siz > xfer)
3702 siz = xfer;
3703 fullsiz = siz;
3704 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
3705 if (!error && vp->v_type != VDIR) {
3706 error = ENOTDIR;
3749 if (cnt > xfer)
3750 cnt = xfer;
3751 if (siz > xfer)
3752 siz = xfer;
3753 fullsiz = siz;
3754 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
3755 if (!error && vp->v_type != VDIR) {
3756 error = ENOTDIR;
3707 NFSD_UNLOCK();
3708 mtx_lock(&Giant); /* VFS */
3757 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
3709 vput(vp);
3758 vput(vp);
3710 mtx_unlock(&Giant); /* VFS */
3759 VFS_UNLOCK_GIANT(vfslocked);
3711 vp = NULL;
3760 vp = NULL;
3712 NFSD_LOCK();
3713 }
3714 if (error) {
3761 }
3762 if (error) {
3763 NFSD_LOCK();
3715 nfsm_reply(NFSX_UNSIGNED);
3716 nfsm_srvpostop_attr(getret, &at);
3717 error = 0;
3718 goto nfsmout;
3719 }
3764 nfsm_reply(NFSX_UNSIGNED);
3765 nfsm_srvpostop_attr(getret, &at);
3766 error = 0;
3767 goto nfsmout;
3768 }
3720 NFSD_UNLOCK();
3721 mtx_lock(&Giant); /* VFS */
3769 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
3722 error = getret = VOP_GETATTR(vp, &at, cred, td);
3723#if 0
3724 /*
3725 * XXX This check may be too strict for Solaris 2.5 clients.
3726 */
3727 if (!error && toff && verf && verf != at.va_filerev)
3728 error = NFSERR_BAD_COOKIE;
3729#endif
3730 if (!error)
3770 error = getret = VOP_GETATTR(vp, &at, cred, td);
3771#if 0
3772 /*
3773 * XXX This check may be too strict for Solaris 2.5 clients.
3774 */
3775 if (!error && toff && verf && verf != at.va_filerev)
3776 error = NFSERR_BAD_COOKIE;
3777#endif
3778 if (!error)
3731 error = nfsrv_access_withgiant(vp, VEXEC, cred, rdonly, td, 0);
3779 error = nfsrv_access(vp, VEXEC, cred, rdonly, td, 0);
3732 if (error) {
3733 vput(vp);
3780 if (error) {
3781 vput(vp);
3734 mtx_unlock(&Giant); /* VFS */
3782 VFS_UNLOCK_GIANT(vfslocked);
3735 NFSD_LOCK();
3736 vp = NULL;
3737 nfsm_reply(NFSX_V3POSTOPATTR);
3738 nfsm_srvpostop_attr(getret, &at);
3739 error = 0;
3740 goto nfsmout;
3741 }
3742 VOP_UNLOCK(vp, 0, td);

--- 20 unchanged lines hidden (view full) ---

3763 getret = VOP_GETATTR(vp, &at, cred, td);
3764 VOP_UNLOCK(vp, 0, td);
3765 if (!cookies && !error)
3766 error = NFSERR_PERM;
3767 if (!error)
3768 error = getret;
3769 if (error) {
3770 vrele(vp);
3783 NFSD_LOCK();
3784 vp = NULL;
3785 nfsm_reply(NFSX_V3POSTOPATTR);
3786 nfsm_srvpostop_attr(getret, &at);
3787 error = 0;
3788 goto nfsmout;
3789 }
3790 VOP_UNLOCK(vp, 0, td);

--- 20 unchanged lines hidden (view full) ---

3811 getret = VOP_GETATTR(vp, &at, cred, td);
3812 VOP_UNLOCK(vp, 0, td);
3813 if (!cookies && !error)
3814 error = NFSERR_PERM;
3815 if (!error)
3816 error = getret;
3817 if (error) {
3818 vrele(vp);
3771 mtx_unlock(&Giant); /* VFS */
3819 VFS_UNLOCK_GIANT(vfslocked);
3772 vp = NULL;
3773 if (cookies)
3774 free((caddr_t)cookies, M_TEMP);
3775 free((caddr_t)rbuf, M_TEMP);
3776 NFSD_LOCK();
3777 nfsm_reply(NFSX_V3POSTOPATTR);
3778 nfsm_srvpostop_attr(getret, &at);
3779 error = 0;
3780 goto nfsmout;
3781 }
3782 if (io.uio_resid) {
3783 siz -= io.uio_resid;
3784
3785 /*
3786 * If nothing read, return eof
3787 * rpc reply
3788 */
3789 if (siz == 0) {
3790 vrele(vp);
3820 vp = NULL;
3821 if (cookies)
3822 free((caddr_t)cookies, M_TEMP);
3823 free((caddr_t)rbuf, M_TEMP);
3824 NFSD_LOCK();
3825 nfsm_reply(NFSX_V3POSTOPATTR);
3826 nfsm_srvpostop_attr(getret, &at);
3827 error = 0;
3828 goto nfsmout;
3829 }
3830 if (io.uio_resid) {
3831 siz -= io.uio_resid;
3832
3833 /*
3834 * If nothing read, return eof
3835 * rpc reply
3836 */
3837 if (siz == 0) {
3838 vrele(vp);
3791 mtx_unlock(&Giant); /* VFS */
3839 VFS_UNLOCK_GIANT(vfslocked);
3792 NFSD_LOCK();
3793 vp = NULL;
3794 nfsm_reply(NFSX_V3POSTOPATTR + NFSX_V3COOKIEVERF +
3795 2 * NFSX_UNSIGNED);
3796 nfsm_srvpostop_attr(getret, &at);
3797 tl = nfsm_build(u_int32_t *, 4 * NFSX_UNSIGNED);
3798 txdr_hyper(at.va_filerev, tl);
3799 tl += 2;

--- 38 unchanged lines hidden (view full) ---

3838 /*
3839 * Probe one of the directory entries to see if the filesystem
3840 * supports VGET.
3841 */
3842 if (VFS_VGET(vp->v_mount, dp->d_fileno, LK_EXCLUSIVE, &nvp) ==
3843 EOPNOTSUPP) {
3844 error = NFSERR_NOTSUPP;
3845 vrele(vp);
3840 NFSD_LOCK();
3841 vp = NULL;
3842 nfsm_reply(NFSX_V3POSTOPATTR + NFSX_V3COOKIEVERF +
3843 2 * NFSX_UNSIGNED);
3844 nfsm_srvpostop_attr(getret, &at);
3845 tl = nfsm_build(u_int32_t *, 4 * NFSX_UNSIGNED);
3846 txdr_hyper(at.va_filerev, tl);
3847 tl += 2;

--- 38 unchanged lines hidden (view full) ---

3886 /*
3887 * Probe one of the directory entries to see if the filesystem
3888 * supports VGET.
3889 */
3890 if (VFS_VGET(vp->v_mount, dp->d_fileno, LK_EXCLUSIVE, &nvp) ==
3891 EOPNOTSUPP) {
3892 error = NFSERR_NOTSUPP;
3893 vrele(vp);
3846 mtx_unlock(&Giant); /* VFS */
3894 VFS_UNLOCK_GIANT(vfslocked);
3847 vp = NULL;
3848 free((caddr_t)cookies, M_TEMP);
3849 free((caddr_t)rbuf, M_TEMP);
3850 NFSD_LOCK();
3851 nfsm_reply(NFSX_V3POSTOPATTR);
3852 nfsm_srvpostop_attr(getret, &at);
3853 error = 0;
3854 goto nfsmout;
3855 }
3856 vput(nvp);
3895 vp = NULL;
3896 free((caddr_t)cookies, M_TEMP);
3897 free((caddr_t)rbuf, M_TEMP);
3898 NFSD_LOCK();
3899 nfsm_reply(NFSX_V3POSTOPATTR);
3900 nfsm_srvpostop_attr(getret, &at);
3901 error = 0;
3902 goto nfsmout;
3903 }
3904 vput(nvp);
3857 mtx_unlock(&Giant); /* VFS */
3905 VFS_UNLOCK_GIANT(vfslocked);
3858 nvp = NULL;
3859
3860 dirlen = len = NFSX_V3POSTOPATTR + NFSX_V3COOKIEVERF +
3861 2 * NFSX_UNSIGNED;
3862 NFSD_LOCK();
3863 nfsm_reply(cnt);
3864 nfsm_srvpostop_attr(getret, &at);
3865 tl = nfsm_build(u_int32_t *, 2 * NFSX_UNSIGNED);
3866 txdr_hyper(at.va_filerev, tl);
3867 mp = mb;
3868 bp = bpos;
3869 be = bp + M_TRAILINGSPACE(mp);
3870
3871 NFSD_UNLOCK();
3906 nvp = NULL;
3907
3908 dirlen = len = NFSX_V3POSTOPATTR + NFSX_V3COOKIEVERF +
3909 2 * NFSX_UNSIGNED;
3910 NFSD_LOCK();
3911 nfsm_reply(cnt);
3912 nfsm_srvpostop_attr(getret, &at);
3913 tl = nfsm_build(u_int32_t *, 2 * NFSX_UNSIGNED);
3914 txdr_hyper(at.va_filerev, tl);
3915 mp = mb;
3916 bp = bpos;
3917 be = bp + M_TRAILINGSPACE(mp);
3918
3919 NFSD_UNLOCK();
3872 mtx_lock(&Giant); /* VFS */
3920 VFS_LOCK_GIANT(vp->v_mount);
3873 /* Loop through the records and build reply */
3874 while (cpos < cend && ncookies > 0) {
3875 if (dp->d_fileno != 0 && dp->d_type != DT_WHT) {
3876 nlen = dp->d_namlen;
3877 rem = nfsm_rndup(nlen)-nlen;
3878
3879 /*
3880 * For readdir_and_lookup get the vnode using
3881 * the file number.
3882 */
3883 if (VFS_VGET(vp->v_mount, dp->d_fileno, LK_EXCLUSIVE,
3884 &nvp))
3885 goto invalid;
3886 bzero((caddr_t)nfhp, NFSX_V3FH);
3887 nfhp->fh_fsid =
3888 nvp->v_mount->mnt_stat.f_fsid;
3921 /* Loop through the records and build reply */
3922 while (cpos < cend && ncookies > 0) {
3923 if (dp->d_fileno != 0 && dp->d_type != DT_WHT) {
3924 nlen = dp->d_namlen;
3925 rem = nfsm_rndup(nlen)-nlen;
3926
3927 /*
3928 * For readdir_and_lookup get the vnode using
3929 * the file number.
3930 */
3931 if (VFS_VGET(vp->v_mount, dp->d_fileno, LK_EXCLUSIVE,
3932 &nvp))
3933 goto invalid;
3934 bzero((caddr_t)nfhp, NFSX_V3FH);
3935 nfhp->fh_fsid =
3936 nvp->v_mount->mnt_stat.f_fsid;
3937 /*
3938 * XXXRW: Assert the mountpoints are the same so that
3939 * we know that acquiring Giant based on the
3940 * directory is the right thing for the child.
3941 */
3942 KASSERT(nvp->v_mount == vp->v_mount,
3943 ("nfsrv_readdirplus: nvp mount != vp mount"));
3889 if (VFS_VPTOFH(nvp, &nfhp->fh_fid)) {
3890 vput(nvp);
3891 nvp = NULL;
3892 goto invalid;
3893 }
3894 if (VOP_GETATTR(nvp, vap, cred, td)) {
3895 vput(nvp);
3896 nvp = NULL;

--- 81 unchanged lines hidden (view full) ---

3978invalid:
3979 NFSD_UNLOCK_ASSERT();
3980 cpos += dp->d_reclen;
3981 dp = (struct dirent *)cpos;
3982 cookiep++;
3983 ncookies--;
3984 }
3985 vrele(vp);
3944 if (VFS_VPTOFH(nvp, &nfhp->fh_fid)) {
3945 vput(nvp);
3946 nvp = NULL;
3947 goto invalid;
3948 }
3949 if (VOP_GETATTR(nvp, vap, cred, td)) {
3950 vput(nvp);
3951 nvp = NULL;

--- 81 unchanged lines hidden (view full) ---

4033invalid:
4034 NFSD_UNLOCK_ASSERT();
4035 cpos += dp->d_reclen;
4036 dp = (struct dirent *)cpos;
4037 cookiep++;
4038 ncookies--;
4039 }
4040 vrele(vp);
3986 mtx_unlock(&Giant); /* VFS */
4041 VFS_UNLOCK_GIANT(vfslocked);
3987 vp = NULL;
3988 nfsm_clget_nolock;
3989 *tl = nfsrv_nfs_false;
3990 bp += NFSX_UNSIGNED;
3991 NFSD_LOCK();
3992 nfsm_clget;
3993 if (eofflag)
3994 *tl = nfsrv_nfs_true;

--- 6 unchanged lines hidden (view full) ---

4001 } else
4002 mp->m_len += bp - bpos;
4003 FREE((caddr_t)cookies, M_TEMP);
4004 FREE((caddr_t)rbuf, M_TEMP);
4005nfsmout:
4006 NFSD_LOCK_ASSERT();
4007 if (vp) {
4008 NFSD_UNLOCK();
4042 vp = NULL;
4043 nfsm_clget_nolock;
4044 *tl = nfsrv_nfs_false;
4045 bp += NFSX_UNSIGNED;
4046 NFSD_LOCK();
4047 nfsm_clget;
4048 if (eofflag)
4049 *tl = nfsrv_nfs_true;

--- 6 unchanged lines hidden (view full) ---

4056 } else
4057 mp->m_len += bp - bpos;
4058 FREE((caddr_t)cookies, M_TEMP);
4059 FREE((caddr_t)rbuf, M_TEMP);
4060nfsmout:
4061 NFSD_LOCK_ASSERT();
4062 if (vp) {
4063 NFSD_UNLOCK();
4009 mtx_lock(&Giant); /* VFS */
4064 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
4010 vrele(vp);
4065 vrele(vp);
4011 mtx_unlock(&Giant); /* VFS */
4066 VFS_UNLOCK_GIANT(vfslocked);
4012 NFSD_LOCK();
4013 }
4014 return(error);
4015}
4016
4017/*
4018 * nfs commit service
4019 */

--- 11 unchanged lines hidden (view full) ---

4031 fhandle_t *fhp;
4032 u_int32_t *tl;
4033 caddr_t bpos;
4034 int error = 0, rdonly, for_ret = 1, aft_ret = 1, cnt;
4035 struct mbuf *mb, *mreq;
4036 u_quad_t off;
4037 struct mount *mp = NULL;
4038 int v3 = (nfsd->nd_flag & ND_NFSV3);
4067 NFSD_LOCK();
4068 }
4069 return(error);
4070}
4071
4072/*
4073 * nfs commit service
4074 */

--- 11 unchanged lines hidden (view full) ---

4086 fhandle_t *fhp;
4087 u_int32_t *tl;
4088 caddr_t bpos;
4089 int error = 0, rdonly, for_ret = 1, aft_ret = 1, cnt;
4090 struct mbuf *mb, *mreq;
4091 u_quad_t off;
4092 struct mount *mp = NULL;
4093 int v3 = (nfsd->nd_flag & ND_NFSV3);
4094 int vfslocked;
4039
4040 NFSD_LOCK_ASSERT();
4041
4042 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
4043 if (!v3)
4044 panic("nfsrv_commit: v3 proc called on a v2 connection");
4045 fhp = &nfh.fh_generic;
4046 nfsm_srvmtofh(fhp);
4047 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
4048 error = ESTALE;
4049 goto ereply;
4050 }
4051 NFSD_UNLOCK();
4095
4096 NFSD_LOCK_ASSERT();
4097
4098 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
4099 if (!v3)
4100 panic("nfsrv_commit: v3 proc called on a v2 connection");
4101 fhp = &nfh.fh_generic;
4102 nfsm_srvmtofh(fhp);
4103 if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
4104 error = ESTALE;
4105 goto ereply;
4106 }
4107 NFSD_UNLOCK();
4052 mtx_lock(&Giant); /* VFS */
4108 vfslocked = VFS_LOCK_GIANT(mp);
4053 (void) vn_start_write(NULL, &mp, V_WAIT);
4054 vfs_rel(mp); /* The write holds a ref. */
4109 (void) vn_start_write(NULL, &mp, V_WAIT);
4110 vfs_rel(mp); /* The write holds a ref. */
4055 mtx_unlock(&Giant); /* VFS */
4056 NFSD_LOCK();
4111 VFS_UNLOCK_GIANT(vfslocked);
4057 tl = nfsm_dissect_nonblock(u_int32_t *, 3 * NFSX_UNSIGNED);
4058
4059 /*
4060 * XXX At this time VOP_FSYNC() does not accept offset and byte
4061 * count parameters, so these arguments are useless (someday maybe).
4062 */
4063 off = fxdr_hyper(tl);
4064 tl += 2;
4065 cnt = fxdr_unsigned(int, *tl);
4066 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
4067 if (error) {
4112 tl = nfsm_dissect_nonblock(u_int32_t *, 3 * NFSX_UNSIGNED);
4113
4114 /*
4115 * XXX At this time VOP_FSYNC() does not accept offset and byte
4116 * count parameters, so these arguments are useless (someday maybe).
4117 */
4118 off = fxdr_hyper(tl);
4119 tl += 2;
4120 cnt = fxdr_unsigned(int, *tl);
4121 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
4122 if (error) {
4123 NFSD_LOCK();
4068 nfsm_reply(2 * NFSX_UNSIGNED);
4069 nfsm_srvwcc_data(for_ret, &bfor, aft_ret, &aft);
4070 error = 0;
4071 goto nfsmout;
4072 }
4124 nfsm_reply(2 * NFSX_UNSIGNED);
4125 nfsm_srvwcc_data(for_ret, &bfor, aft_ret, &aft);
4126 error = 0;
4127 goto nfsmout;
4128 }
4073 NFSD_UNLOCK();
4074 mtx_lock(&Giant); /* VFS */
4129 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
4075 for_ret = VOP_GETATTR(vp, &bfor, cred, td);
4076
4077 if (cnt > MAX_COMMIT_COUNT) {
4078 /*
4079 * Give up and do the whole thing
4080 */
4081 if (vp->v_object &&
4082 (vp->v_object->flags & OBJ_MIGHTBEDIRTY)) {

--- 71 unchanged lines hidden (view full) ---

4154 ++lblkno;
4155 }
4156 VI_UNLOCK(vp);
4157 splx(s);
4158 }
4159
4160 aft_ret = VOP_GETATTR(vp, &aft, cred, td);
4161 vput(vp);
4130 for_ret = VOP_GETATTR(vp, &bfor, cred, td);
4131
4132 if (cnt > MAX_COMMIT_COUNT) {
4133 /*
4134 * Give up and do the whole thing
4135 */
4136 if (vp->v_object &&
4137 (vp->v_object->flags & OBJ_MIGHTBEDIRTY)) {

--- 71 unchanged lines hidden (view full) ---

4209 ++lblkno;
4210 }
4211 VI_UNLOCK(vp);
4212 splx(s);
4213 }
4214
4215 aft_ret = VOP_GETATTR(vp, &aft, cred, td);
4216 vput(vp);
4162 mtx_unlock(&Giant); /* VFS */
4217 VFS_UNLOCK_GIANT(vfslocked);
4163 vp = NULL;
4164 NFSD_LOCK();
4165ereply:
4166 NFSD_LOCK_ASSERT();
4167 nfsm_reply(NFSX_V3WCCDATA + NFSX_V3WRITEVERF);
4168 nfsm_srvwcc_data(for_ret, &bfor, aft_ret, &aft);
4169 if (!error) {
4170 tl = nfsm_build(u_int32_t *, NFSX_V3WRITEVERF);
4171 if (nfsver.tv_sec == 0)
4172 nfsver = boottime;
4173 *tl++ = txdr_unsigned(nfsver.tv_sec);
4174 *tl = txdr_unsigned(nfsver.tv_usec);
4175 } else {
4176 error = 0;
4177 }
4178nfsmout:
4179 NFSD_LOCK_ASSERT();
4180 NFSD_UNLOCK();
4218 vp = NULL;
4219 NFSD_LOCK();
4220ereply:
4221 NFSD_LOCK_ASSERT();
4222 nfsm_reply(NFSX_V3WCCDATA + NFSX_V3WRITEVERF);
4223 nfsm_srvwcc_data(for_ret, &bfor, aft_ret, &aft);
4224 if (!error) {
4225 tl = nfsm_build(u_int32_t *, NFSX_V3WRITEVERF);
4226 if (nfsver.tv_sec == 0)
4227 nfsver = boottime;
4228 *tl++ = txdr_unsigned(nfsver.tv_sec);
4229 *tl = txdr_unsigned(nfsver.tv_usec);
4230 } else {
4231 error = 0;
4232 }
4233nfsmout:
4234 NFSD_LOCK_ASSERT();
4235 NFSD_UNLOCK();
4181 mtx_lock(&Giant); /* VFS */
4236 vfslocked = VFS_LOCK_GIANT(mp);
4182 if (vp)
4183 vput(vp);
4184 vn_finished_write(mp);
4237 if (vp)
4238 vput(vp);
4239 vn_finished_write(mp);
4185 mtx_unlock(&Giant); /* VFS */
4240 VFS_UNLOCK_GIANT(vfslocked);
4186 NFSD_LOCK();
4187 return(error);
4188}
4189
4190/*
4191 * nfs statfs service
4192 */
4193int

--- 11 unchanged lines hidden (view full) ---

4205 int v3 = (nfsd->nd_flag & ND_NFSV3);
4206 struct mbuf *mb, *mreq;
4207 struct vnode *vp = NULL;
4208 struct vattr at;
4209 nfsfh_t nfh;
4210 fhandle_t *fhp;
4211 struct statfs statfs;
4212 u_quad_t tval;
4241 NFSD_LOCK();
4242 return(error);
4243}
4244
4245/*
4246 * nfs statfs service
4247 */
4248int

--- 11 unchanged lines hidden (view full) ---

4260 int v3 = (nfsd->nd_flag & ND_NFSV3);
4261 struct mbuf *mb, *mreq;
4262 struct vnode *vp = NULL;
4263 struct vattr at;
4264 nfsfh_t nfh;
4265 fhandle_t *fhp;
4266 struct statfs statfs;
4267 u_quad_t tval;
4268 int vfslocked;
4213
4214 NFSD_LOCK_ASSERT();
4269
4270 NFSD_LOCK_ASSERT();
4271 NFSD_UNLOCK();
4215
4216 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
4217 fhp = &nfh.fh_generic;
4218 nfsm_srvmtofh(fhp);
4219 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
4220 if (error) {
4272
4273 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
4274 fhp = &nfh.fh_generic;
4275 nfsm_srvmtofh(fhp);
4276 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
4277 if (error) {
4278 NFSD_LOCK();
4221 nfsm_reply(NFSX_UNSIGNED);
4222 if (v3)
4223 nfsm_srvpostop_attr(getret, &at);
4224 error = 0;
4225 goto nfsmout;
4226 }
4227 sf = &statfs;
4279 nfsm_reply(NFSX_UNSIGNED);
4280 if (v3)
4281 nfsm_srvpostop_attr(getret, &at);
4282 error = 0;
4283 goto nfsmout;
4284 }
4285 sf = &statfs;
4228 NFSD_UNLOCK();
4229 mtx_lock(&Giant); /* VFS */
4286 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
4230 error = VFS_STATFS(vp->v_mount, sf, td);
4231 getret = VOP_GETATTR(vp, &at, cred, td);
4232 vput(vp);
4287 error = VFS_STATFS(vp->v_mount, sf, td);
4288 getret = VOP_GETATTR(vp, &at, cred, td);
4289 vput(vp);
4233 mtx_unlock(&Giant); /* VFS */
4290 VFS_UNLOCK_GIANT(vfslocked);
4234 vp = NULL;
4235 NFSD_LOCK();
4236 nfsm_reply(NFSX_POSTOPATTR(v3) + NFSX_STATFS(v3));
4237 if (v3)
4238 nfsm_srvpostop_attr(getret, &at);
4239 if (error) {
4240 error = 0;
4241 goto nfsmout;

--- 34 unchanged lines hidden (view full) ---

4276 sfp->sf_bavail = 0;
4277 else
4278 sfp->sf_bavail = txdr_unsigned(sf->f_bavail);
4279 }
4280nfsmout:
4281 NFSD_LOCK_ASSERT();
4282 if (vp) {
4283 NFSD_UNLOCK();
4291 vp = NULL;
4292 NFSD_LOCK();
4293 nfsm_reply(NFSX_POSTOPATTR(v3) + NFSX_STATFS(v3));
4294 if (v3)
4295 nfsm_srvpostop_attr(getret, &at);
4296 if (error) {
4297 error = 0;
4298 goto nfsmout;

--- 34 unchanged lines hidden (view full) ---

4333 sfp->sf_bavail = 0;
4334 else
4335 sfp->sf_bavail = txdr_unsigned(sf->f_bavail);
4336 }
4337nfsmout:
4338 NFSD_LOCK_ASSERT();
4339 if (vp) {
4340 NFSD_UNLOCK();
4284 mtx_lock(&Giant); /* VFS */
4341 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
4285 vput(vp);
4342 vput(vp);
4286 mtx_unlock(&Giant); /* VFS */
4343 VFS_UNLOCK_GIANT(vfslocked);
4287 NFSD_LOCK();
4288 }
4289 return(error);
4290}
4291
4292/*
4293 * nfs fsinfo service
4294 */

--- 11 unchanged lines hidden (view full) ---

4306 struct mbuf *mb, *mreq;
4307 struct vnode *vp = NULL;
4308 struct vattr at;
4309 nfsfh_t nfh;
4310 fhandle_t *fhp;
4311 u_quad_t maxfsize;
4312 struct statfs sb;
4313 int v3 = (nfsd->nd_flag & ND_NFSV3);
4344 NFSD_LOCK();
4345 }
4346 return(error);
4347}
4348
4349/*
4350 * nfs fsinfo service
4351 */

--- 11 unchanged lines hidden (view full) ---

4363 struct mbuf *mb, *mreq;
4364 struct vnode *vp = NULL;
4365 struct vattr at;
4366 nfsfh_t nfh;
4367 fhandle_t *fhp;
4368 u_quad_t maxfsize;
4369 struct statfs sb;
4370 int v3 = (nfsd->nd_flag & ND_NFSV3);
4371 int vfslocked;
4314
4315 NFSD_LOCK_ASSERT();
4372
4373 NFSD_LOCK_ASSERT();
4374 NFSD_UNLOCK();
4316
4317 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
4318 if (!v3)
4319 panic("nfsrv_fsinfo: v3 proc called on a v2 connection");
4320 fhp = &nfh.fh_generic;
4321 nfsm_srvmtofh(fhp);
4322 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
4323 if (error) {
4375
4376 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
4377 if (!v3)
4378 panic("nfsrv_fsinfo: v3 proc called on a v2 connection");
4379 fhp = &nfh.fh_generic;
4380 nfsm_srvmtofh(fhp);
4381 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
4382 if (error) {
4383 NFSD_LOCK();
4324 nfsm_reply(NFSX_UNSIGNED);
4325 nfsm_srvpostop_attr(getret, &at);
4326 error = 0;
4327 goto nfsmout;
4328 }
4329
4384 nfsm_reply(NFSX_UNSIGNED);
4385 nfsm_srvpostop_attr(getret, &at);
4386 error = 0;
4387 goto nfsmout;
4388 }
4389
4330 NFSD_UNLOCK();
4331 mtx_lock(&Giant); /* VFS */
4390 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
4332 /* XXX Try to make a guess on the max file size. */
4333 VFS_STATFS(vp->v_mount, &sb, td);
4334 maxfsize = (u_quad_t)0x80000000 * sb.f_bsize - 1;
4335
4336 getret = VOP_GETATTR(vp, &at, cred, td);
4337 vput(vp);
4391 /* XXX Try to make a guess on the max file size. */
4392 VFS_STATFS(vp->v_mount, &sb, td);
4393 maxfsize = (u_quad_t)0x80000000 * sb.f_bsize - 1;
4394
4395 getret = VOP_GETATTR(vp, &at, cred, td);
4396 vput(vp);
4338 mtx_unlock(&Giant); /* VFS */
4397 VFS_UNLOCK_GIANT(vfslocked);
4339 vp = NULL;
4340 NFSD_LOCK();
4341 nfsm_reply(NFSX_V3POSTOPATTR + NFSX_V3FSINFO);
4342 nfsm_srvpostop_attr(getret, &at);
4343 sip = nfsm_build(struct nfsv3_fsinfo *, NFSX_V3FSINFO);
4344
4345 /*
4346 * XXX

--- 16 unchanged lines hidden (view full) ---

4363 sip->fs_timedelta.nfsv3_nsec = txdr_unsigned(1);
4364 sip->fs_properties = txdr_unsigned(NFSV3FSINFO_LINK |
4365 NFSV3FSINFO_SYMLINK | NFSV3FSINFO_HOMOGENEOUS |
4366 NFSV3FSINFO_CANSETTIME);
4367nfsmout:
4368 NFSD_LOCK_ASSERT();
4369 if (vp) {
4370 NFSD_UNLOCK();
4398 vp = NULL;
4399 NFSD_LOCK();
4400 nfsm_reply(NFSX_V3POSTOPATTR + NFSX_V3FSINFO);
4401 nfsm_srvpostop_attr(getret, &at);
4402 sip = nfsm_build(struct nfsv3_fsinfo *, NFSX_V3FSINFO);
4403
4404 /*
4405 * XXX

--- 16 unchanged lines hidden (view full) ---

4422 sip->fs_timedelta.nfsv3_nsec = txdr_unsigned(1);
4423 sip->fs_properties = txdr_unsigned(NFSV3FSINFO_LINK |
4424 NFSV3FSINFO_SYMLINK | NFSV3FSINFO_HOMOGENEOUS |
4425 NFSV3FSINFO_CANSETTIME);
4426nfsmout:
4427 NFSD_LOCK_ASSERT();
4428 if (vp) {
4429 NFSD_UNLOCK();
4371 mtx_lock(&Giant); /* VFS */
4430 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
4372 vput(vp);
4431 vput(vp);
4373 mtx_unlock(&Giant); /* VFS */
4432 VFS_UNLOCK_GIANT(vfslocked);
4374 NFSD_LOCK();
4375 }
4376 return(error);
4377}
4378
4379/*
4380 * nfs pathconf service
4381 */

--- 10 unchanged lines hidden (view full) ---

4392 int error = 0, rdonly, getret = 1;
4393 register_t linkmax, namemax, chownres, notrunc;
4394 struct mbuf *mb, *mreq;
4395 struct vnode *vp = NULL;
4396 struct vattr at;
4397 nfsfh_t nfh;
4398 fhandle_t *fhp;
4399 int v3 = (nfsd->nd_flag & ND_NFSV3);
4433 NFSD_LOCK();
4434 }
4435 return(error);
4436}
4437
4438/*
4439 * nfs pathconf service
4440 */

--- 10 unchanged lines hidden (view full) ---

4451 int error = 0, rdonly, getret = 1;
4452 register_t linkmax, namemax, chownres, notrunc;
4453 struct mbuf *mb, *mreq;
4454 struct vnode *vp = NULL;
4455 struct vattr at;
4456 nfsfh_t nfh;
4457 fhandle_t *fhp;
4458 int v3 = (nfsd->nd_flag & ND_NFSV3);
4459 int vfslocked;
4400
4401 NFSD_LOCK_ASSERT();
4460
4461 NFSD_LOCK_ASSERT();
4462 NFSD_UNLOCK();
4402
4403 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
4404 if (!v3)
4405 panic("nfsrv_pathconf: v3 proc called on a v2 connection");
4406 fhp = &nfh.fh_generic;
4407 nfsm_srvmtofh(fhp);
4408 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
4409 if (error) {
4463
4464 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
4465 if (!v3)
4466 panic("nfsrv_pathconf: v3 proc called on a v2 connection");
4467 fhp = &nfh.fh_generic;
4468 nfsm_srvmtofh(fhp);
4469 error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
4470 if (error) {
4471 NFSD_LOCK();
4410 nfsm_reply(NFSX_UNSIGNED);
4411 nfsm_srvpostop_attr(getret, &at);
4412 error = 0;
4413 goto nfsmout;
4414 }
4472 nfsm_reply(NFSX_UNSIGNED);
4473 nfsm_srvpostop_attr(getret, &at);
4474 error = 0;
4475 goto nfsmout;
4476 }
4415 NFSD_UNLOCK();
4416 mtx_lock(&Giant); /* VFS */
4477 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
4417 error = VOP_PATHCONF(vp, _PC_LINK_MAX, &linkmax);
4418 if (!error)
4419 error = VOP_PATHCONF(vp, _PC_NAME_MAX, &namemax);
4420 if (!error)
4421 error = VOP_PATHCONF(vp, _PC_CHOWN_RESTRICTED, &chownres);
4422 if (!error)
4423 error = VOP_PATHCONF(vp, _PC_NO_TRUNC, &notrunc);
4424 getret = VOP_GETATTR(vp, &at, cred, td);
4425 vput(vp);
4478 error = VOP_PATHCONF(vp, _PC_LINK_MAX, &linkmax);
4479 if (!error)
4480 error = VOP_PATHCONF(vp, _PC_NAME_MAX, &namemax);
4481 if (!error)
4482 error = VOP_PATHCONF(vp, _PC_CHOWN_RESTRICTED, &chownres);
4483 if (!error)
4484 error = VOP_PATHCONF(vp, _PC_NO_TRUNC, &notrunc);
4485 getret = VOP_GETATTR(vp, &at, cred, td);
4486 vput(vp);
4426 mtx_unlock(&Giant); /* VFS */
4487 VFS_UNLOCK_GIANT(vfslocked);
4427 vp = NULL;
4428 NFSD_LOCK();
4429 nfsm_reply(NFSX_V3POSTOPATTR + NFSX_V3PATHCONF);
4430 nfsm_srvpostop_attr(getret, &at);
4431 if (error) {
4432 error = 0;
4433 goto nfsmout;
4434 }

--- 10 unchanged lines hidden (view full) ---

4445 * Unix defaults should be ok.
4446 */
4447 pc->pc_caseinsensitive = nfsrv_nfs_false;
4448 pc->pc_casepreserving = nfsrv_nfs_true;
4449nfsmout:
4450 NFSD_LOCK_ASSERT();
4451 if (vp) {
4452 NFSD_UNLOCK();
4488 vp = NULL;
4489 NFSD_LOCK();
4490 nfsm_reply(NFSX_V3POSTOPATTR + NFSX_V3PATHCONF);
4491 nfsm_srvpostop_attr(getret, &at);
4492 if (error) {
4493 error = 0;
4494 goto nfsmout;
4495 }

--- 10 unchanged lines hidden (view full) ---

4506 * Unix defaults should be ok.
4507 */
4508 pc->pc_caseinsensitive = nfsrv_nfs_false;
4509 pc->pc_casepreserving = nfsrv_nfs_true;
4510nfsmout:
4511 NFSD_LOCK_ASSERT();
4512 if (vp) {
4513 NFSD_UNLOCK();
4453 mtx_lock(&Giant); /* VFS */
4514 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
4454 vput(vp);
4515 vput(vp);
4455 mtx_unlock(&Giant); /* VFS */
4516 VFS_UNLOCK_GIANT(vfslocked);
4456 NFSD_LOCK();
4457 }
4458 return(error);
4459}
4460
4461/*
4462 * Null operation, used by clients to ping server
4463 */

--- 53 unchanged lines hidden (view full) ---

4517 * operations, so that processes that chmod after opening a file don't
4518 * break. I don't like this because it opens a security hole, but since
4519 * the nfs server opens a security hole the size of a barn door anyhow,
4520 * what the heck.
4521 *
4522 * The exception to rule 2 is EPERM. If a file is IMMUTABLE, VOP_ACCESS()
4523 * will return EPERM instead of EACCESS. EPERM is always an error.
4524 *
4517 NFSD_LOCK();
4518 }
4519 return(error);
4520}
4521
4522/*
4523 * Null operation, used by clients to ping server
4524 */

--- 53 unchanged lines hidden (view full) ---

4578 * operations, so that processes that chmod after opening a file don't
4579 * break. I don't like this because it opens a security hole, but since
4580 * the nfs server opens a security hole the size of a barn door anyhow,
4581 * what the heck.
4582 *
4583 * The exception to rule 2 is EPERM. If a file is IMMUTABLE, VOP_ACCESS()
4584 * will return EPERM instead of EACCESS. EPERM is always an error.
4585 *
4525 * There are two versions: one to be called while holding Giant (which is
4526 * needed due to use of VFS), and the other called with the NFS server lock
4527 * (which will be dropped and reacquired). This is necessary because
4528 * nfsrv_access checks are required from both classes of contexts.
4586 * There are two versions: one called while holding the NFS server lock,
4587 * which will be dropped and re-acquired, and one called without it.
4588 *
4589 * nfsrv_access() assumes that the NFS server lock is not held, but that if
4590 * Giant is required for the vnode it will already be acquired.
4591 *
4592 * nfsrv_access_locked() assumes that the NFS server lock is held, but that
4593 * it will need to acquire Giant for the vnode.
4529 */
4530static int
4594 */
4595static int
4531nfsrv_access_withgiant(struct vnode *vp, int flags, struct ucred *cred,
4596nfsrv_access(struct vnode *vp, int flags, struct ucred *cred,
4532 int rdonly, struct thread *td, int override)
4533{
4534 struct vattr vattr;
4535 int error;
4536
4597 int rdonly, struct thread *td, int override)
4598{
4599 struct vattr vattr;
4600 int error;
4601
4537 GIANT_REQUIRED;
4602 NFSD_UNLOCK_ASSERT();
4603 VFS_ASSERT_GIANT(vp->v_mount);
4538
4539 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
4540
4541 if (flags & VWRITE) {
4542 /* Just vn_writechk() changed to check rdonly */
4543 /*
4544 * Disallow write attempts on read-only filesystems;
4545 * unless the file is a socket or a block or character

--- 24 unchanged lines hidden (view full) ---

4570 /*
4571 * Allow certain operations for the owner (reads and writes
4572 * on files that are already open).
4573 */
4574 if (override && error == EACCES && cred->cr_uid == vattr.va_uid)
4575 error = 0;
4576 return (error);
4577}
4604
4605 nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
4606
4607 if (flags & VWRITE) {
4608 /* Just vn_writechk() changed to check rdonly */
4609 /*
4610 * Disallow write attempts on read-only filesystems;
4611 * unless the file is a socket or a block or character

--- 24 unchanged lines hidden (view full) ---

4636 /*
4637 * Allow certain operations for the owner (reads and writes
4638 * on files that are already open).
4639 */
4640 if (override && error == EACCES && cred->cr_uid == vattr.va_uid)
4641 error = 0;
4642 return (error);
4643}
4578
4579static int
4580nfsrv_access(struct vnode *vp, int flags, struct ucred *cred, int rdonly,
4581 struct thread *td, int override)
4582{
4583 int error;
4584
4585 NFSD_LOCK_ASSERT();
4586
4587 NFSD_UNLOCK();
4588 mtx_lock(&Giant); /* VFS */
4589 error = nfsrv_access_withgiant(vp, flags, cred, rdonly, td, override);
4590 mtx_unlock(&Giant); /* VFS */
4591 NFSD_LOCK();
4592 return (error);
4593}