4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T.
25 * All rights reserved.
29 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
30 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
33 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/systm.h>
38 #include <sys/vnode.h>
41 #include <sys/filio.h>
45 #include <sys/pathname.h>
46 #include <sys/dirent.h>
47 #include <sys/debug.h>
48 #include <sys/vmsystm.h>
49 #include <sys/fcntl.h>
50 #include <sys/flock.h>
52 #include <sys/errno.h>
53 #include <sys/strsubr.h>
54 #include <sys/sysmacros.h>
56 #include <sys/cmn_err.h>
57 #include <sys/pathconf.h>
58 #include <sys/utsname.h>
61 #include <sys/atomic.h>
62 #include <sys/policy.h>
65 #include <rpc/types.h>
70 #include <nfs/nfs_clnt.h>
71 #include <nfs/rnode.h>
72 #include <nfs/nfs_acl.h>
80 #include <vm/seg_map.h>
81 #include <vm/seg_kpm.h>
82 #include <vm/seg_vn.h>
84 #include <sys/fs_subr.h>
88 static int nfs_rdwrlbn(vnode_t
*, page_t
*, uoff_t
, size_t, int,
90 static int nfswrite(vnode_t
*, caddr_t
, uint_t
, int, cred_t
*);
91 static int nfsread(vnode_t
*, caddr_t
, uint_t
, int, size_t *, cred_t
*);
92 static int nfssetattr(vnode_t
*, struct vattr
*, int, cred_t
*);
93 static int nfslookup_dnlc(vnode_t
*, char *, vnode_t
**, cred_t
*);
94 static int nfslookup_otw(vnode_t
*, char *, vnode_t
**, cred_t
*, int);
95 static int nfsrename(vnode_t
*, char *, vnode_t
*, char *, cred_t
*,
97 static int nfsreaddir(vnode_t
*, rddir_cache
*, cred_t
*);
98 static int nfs_bio(struct buf
*, cred_t
*);
99 static int nfs_getapage(vnode_t
*, uoff_t
, size_t, uint_t
*,
100 page_t
*[], size_t, struct seg
*, caddr_t
,
101 enum seg_rw
, cred_t
*);
102 static void nfs_readahead(vnode_t
*, uoff_t
, caddr_t
, struct seg
*,
104 static int nfs_sync_putapage(vnode_t
*, page_t
*, uoff_t
, size_t,
106 static int nfs_sync_pageio(vnode_t
*, page_t
*, uoff_t
, size_t,
108 static void nfs_delmap_callback(struct as
*, void *, uint_t
);
111 * Error flags used to pass information about certain special errors
112 * which need to be handled specially.
117 * These are the vnode ops routines which implement the vnode interface to
118 * the networked file system. These routines just take their parameters,
119 * make them look networkish by putting the right info into interface structs,
120 * and then calling the appropriate remote routine(s) to do the work.
122 * Note on directory name lookup cacheing: If we detect a stale fhandle,
123 * we purge the directory cache relative to that vnode. This way, the
124 * user won't get burned by the cache repeatedly. See <nfs/rnode.h> for
125 * more details on rnode locking.
128 static int nfs_open(vnode_t
**, int, cred_t
*, caller_context_t
*);
129 static int nfs_close(vnode_t
*, int, int, offset_t
, cred_t
*,
131 static int nfs_read(vnode_t
*, struct uio
*, int, cred_t
*,
133 static int nfs_write(vnode_t
*, struct uio
*, int, cred_t
*,
135 static int nfs_ioctl(vnode_t
*, int, intptr_t, int, cred_t
*, int *,
137 static int nfs_getattr(vnode_t
*, struct vattr
*, int, cred_t
*,
139 static int nfs_setattr(vnode_t
*, struct vattr
*, int, cred_t
*,
141 static int nfs_access(vnode_t
*, int, int, cred_t
*, caller_context_t
*);
142 static int nfs_accessx(void *, int, cred_t
*);
143 static int nfs_readlink(vnode_t
*, struct uio
*, cred_t
*,
145 static int nfs_fsync(vnode_t
*, int, cred_t
*, caller_context_t
*);
146 static void nfs_inactive(vnode_t
*, cred_t
*, caller_context_t
*);
147 static int nfs_lookup(vnode_t
*, char *, vnode_t
**, struct pathname
*,
148 int, vnode_t
*, cred_t
*, caller_context_t
*,
149 int *, pathname_t
*);
150 static int nfs_create(vnode_t
*, char *, struct vattr
*, enum vcexcl
,
151 int, vnode_t
**, cred_t
*, int, caller_context_t
*,
153 static int nfs_remove(vnode_t
*, char *, cred_t
*, caller_context_t
*,
155 static int nfs_link(vnode_t
*, vnode_t
*, char *, cred_t
*,
156 caller_context_t
*, int);
157 static int nfs_rename(vnode_t
*, char *, vnode_t
*, char *, cred_t
*,
158 caller_context_t
*, int);
159 static int nfs_mkdir(vnode_t
*, char *, struct vattr
*, vnode_t
**,
160 cred_t
*, caller_context_t
*, int, vsecattr_t
*);
161 static int nfs_rmdir(vnode_t
*, char *, vnode_t
*, cred_t
*,
162 caller_context_t
*, int);
163 static int nfs_symlink(vnode_t
*, char *, struct vattr
*, char *,
164 cred_t
*, caller_context_t
*, int);
165 static int nfs_readdir(vnode_t
*, struct uio
*, cred_t
*, int *,
166 caller_context_t
*, int);
167 static int nfs_fid(vnode_t
*, fid_t
*, caller_context_t
*);
168 static int nfs_rwlock(vnode_t
*, int, caller_context_t
*);
169 static void nfs_rwunlock(vnode_t
*, int, caller_context_t
*);
170 static int nfs_seek(vnode_t
*, offset_t
, offset_t
*, caller_context_t
*);
171 static int nfs_getpage(vnode_t
*, offset_t
, size_t, uint_t
*,
172 page_t
*[], size_t, struct seg
*, caddr_t
,
173 enum seg_rw
, cred_t
*, caller_context_t
*);
174 static int nfs_putpage(vnode_t
*, offset_t
, size_t, int, cred_t
*,
176 static int nfs_map(vnode_t
*, offset_t
, struct as
*, caddr_t
*, size_t,
177 uchar_t
, uchar_t
, uint_t
, cred_t
*, caller_context_t
*);
178 static int nfs_addmap(vnode_t
*, offset_t
, struct as
*, caddr_t
, size_t,
179 uchar_t
, uchar_t
, uint_t
, cred_t
*, caller_context_t
*);
180 static int nfs_frlock(vnode_t
*, int, struct flock64
*, int, offset_t
,
181 struct flk_callback
*, cred_t
*, caller_context_t
*);
182 static int nfs_space(vnode_t
*, int, struct flock64
*, int, offset_t
,
183 cred_t
*, caller_context_t
*);
184 static int nfs_realvp(vnode_t
*, vnode_t
**, caller_context_t
*);
185 static int nfs_delmap(vnode_t
*, offset_t
, struct as
*, caddr_t
, size_t,
186 uint_t
, uint_t
, uint_t
, cred_t
*, caller_context_t
*);
187 static int nfs_pathconf(vnode_t
*, int, ulong_t
*, cred_t
*,
189 static int nfs_pageio(vnode_t
*, page_t
*, uoff_t
, size_t, int,
190 cred_t
*, caller_context_t
*);
191 static int nfs_setsecattr(vnode_t
*, vsecattr_t
*, int, cred_t
*,
193 static int nfs_getsecattr(vnode_t
*, vsecattr_t
*, int, cred_t
*,
195 static int nfs_shrlock(vnode_t
*, int, struct shrlock
*, int, cred_t
*,
198 const struct vnodeops nfs_vnodeops
= {
200 .vop_open
= nfs_open
,
201 .vop_close
= nfs_close
,
202 .vop_read
= nfs_read
,
203 .vop_write
= nfs_write
,
204 .vop_ioctl
= nfs_ioctl
,
205 .vop_getattr
= nfs_getattr
,
206 .vop_setattr
= nfs_setattr
,
207 .vop_access
= nfs_access
,
208 .vop_lookup
= nfs_lookup
,
209 .vop_create
= nfs_create
,
210 .vop_remove
= nfs_remove
,
211 .vop_link
= nfs_link
,
212 .vop_rename
= nfs_rename
,
213 .vop_mkdir
= nfs_mkdir
,
214 .vop_rmdir
= nfs_rmdir
,
215 .vop_readdir
= nfs_readdir
,
216 .vop_symlink
= nfs_symlink
,
217 .vop_readlink
= nfs_readlink
,
218 .vop_fsync
= nfs_fsync
,
219 .vop_inactive
= nfs_inactive
,
221 .vop_rwlock
= nfs_rwlock
,
222 .vop_rwunlock
= nfs_rwunlock
,
223 .vop_seek
= nfs_seek
,
224 .vop_frlock
= nfs_frlock
,
225 .vop_space
= nfs_space
,
226 .vop_realvp
= nfs_realvp
,
227 .vop_getpage
= nfs_getpage
,
228 .vop_putpage
= nfs_putpage
,
230 .vop_addmap
= nfs_addmap
,
231 .vop_delmap
= nfs_delmap
,
232 .vop_dump
= nfs_dump
,
233 .vop_pathconf
= nfs_pathconf
,
234 .vop_pageio
= nfs_pageio
,
235 .vop_setsecattr
= nfs_setsecattr
,
236 .vop_getsecattr
= nfs_getsecattr
,
237 .vop_shrlock
= nfs_shrlock
,
238 .vop_vnevent
= fs_vnevent_support
,
242 * XXX: This is referenced in modstubs.s
244 const struct vnodeops
*
245 nfs_getvnodeops(void)
247 return (&nfs_vnodeops
);
252 nfs_open(vnode_t
**vpp
, int flag
, cred_t
*cr
, caller_context_t
*ct
)
261 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
263 mutex_enter(&rp
->r_statelock
);
264 if (rp
->r_cred
== NULL
) {
268 mutex_exit(&rp
->r_statelock
);
271 * If there is no cached data or if close-to-open
272 * consistency checking is turned off, we can avoid
273 * the over the wire getattr. Otherwise, if the
274 * file system is mounted readonly, then just verify
275 * the caches are up to date using the normal mechanism.
276 * Else, if the file is not mmap'd, then just mark
277 * the attributes as timed out. They will be refreshed
278 * and the caches validated prior to being used.
279 * Else, the file system is mounted writeable so
280 * force an over the wire GETATTR in order to ensure
281 * that all cached data is valid.
283 if (vp
->v_count
> 1 ||
284 ((vn_has_cached_data(vp
) || HAVE_RDDIR_CACHE(rp
)) &&
285 !(VTOMI(vp
)->mi_flags
& MI_NOCTO
))) {
286 if (vn_is_readonly(vp
))
287 error
= nfs_validate_caches(vp
, cr
);
288 else if (rp
->r_mapcnt
== 0 && vp
->v_count
== 1) {
293 error
= nfs_getattr_otw(vp
, &va
, cr
);
303 nfs_close(vnode_t
*vp
, int flag
, int count
, offset_t offset
, cred_t
*cr
,
304 caller_context_t
*ct
)
311 * zone_enter(2) prevents processes from changing zones with NFS files
312 * open; if we happen to get here from the wrong zone we can't do
313 * anything over the wire.
315 if (VTOMI(vp
)->mi_zone
!= nfs_zone()) {
317 * We could attempt to clean up locks, except we're sure
318 * that the current process didn't acquire any locks on
319 * the file: any attempt to lock a file belong to another zone
320 * will fail, and one can't lock an NFS file and then change
321 * zones, as that fails too.
323 * Returning an error here is the sane thing to do. A
324 * subsequent call to VN_RELE() which translates to a
325 * nfs_inactive() will clean up state: if the zone of the
326 * vnode's origin is still alive and kicking, an async worker
327 * thread will handle the request (from the correct zone), and
328 * everything (minus the final nfs_getattr_otw() call) should
329 * be OK. If the zone is going away nfs_async_inactive() will
330 * throw away cached pages inline.
336 * If we are using local locking for this filesystem, then
337 * release all of the SYSV style record locks. Otherwise,
338 * we are doing network locking and we need to release all
339 * of the network locks. All of the locks held by this
340 * process on this file are released no matter what the
341 * incoming reference count is.
343 if (VTOMI(vp
)->mi_flags
& MI_LLOCK
) {
344 cleanlocks(vp
, ttoproc(curthread
)->p_pid
, 0);
345 cleanshares(vp
, ttoproc(curthread
)->p_pid
);
347 nfs_lockrelease(vp
, flag
, offset
, cr
);
353 * If the file has been `unlinked', then purge the
354 * DNLC so that this vnode will get reycled quicker
355 * and the .nfs* file on the server will get removed.
358 if (rp
->r_unldvp
!= NULL
)
362 * If the file was open for write and there are pages,
363 * then if the file system was mounted using the "no-close-
364 * to-open" semantics, then start an asynchronous flush
365 * of the all of the pages in the file.
366 * else the file system was not mounted using the "no-close-
367 * to-open" semantics, then do a synchronous flush and
368 * commit of all of the dirty and uncommitted pages.
370 * The asynchronous flush of the pages in the "nocto" path
371 * mostly just associates a cred pointer with the rnode so
372 * writes which happen later will have a better chance of
373 * working. It also starts the data being written to the
374 * server, but without unnecessarily delaying the application.
376 if ((flag
& FWRITE
) && vn_has_cached_data(vp
)) {
377 if ((VTOMI(vp
)->mi_flags
& MI_NOCTO
)) {
378 error
= nfs_putpage(vp
, 0, 0, B_ASYNC
,
383 error
= nfs_putpage(vp
, 0, 0, 0, cr
, ct
);
385 mutex_enter(&rp
->r_statelock
);
388 mutex_exit(&rp
->r_statelock
);
391 mutex_enter(&rp
->r_statelock
);
394 mutex_exit(&rp
->r_statelock
);
398 * If RWRITEATTR is set, then issue an over the wire GETATTR to
399 * refresh the attribute cache with a set of attributes which
400 * weren't returned from a WRITE. This will enable the close-
401 * to-open processing to work.
403 if (rp
->r_flags
& RWRITEATTR
)
404 (void) nfs_getattr_otw(vp
, &va
, cr
);
411 nfs_read(vnode_t
*vp
, struct uio
*uiop
, int ioflag
, cred_t
*cr
,
412 caller_context_t
*ct
)
427 if (nfs_zone() != mi
->mi_zone
)
430 ASSERT(nfs_rw_lock_held(&rp
->r_rwlock
, RW_READER
));
432 if (vp
->v_type
!= VREG
)
435 if (uiop
->uio_resid
== 0)
438 if (uiop
->uio_loffset
> MAXOFF32_T
)
441 if (uiop
->uio_loffset
< 0 ||
442 uiop
->uio_loffset
+ uiop
->uio_resid
> MAXOFF32_T
)
446 * Bypass VM if caching has been disabled (e.g., locking) or if
447 * using client-side direct I/O and the file is not mmap'd and
448 * there are no cached pages.
450 if ((vp
->v_flag
& VNOCACHE
) ||
451 (((rp
->r_flags
& RDIRECTIO
) || (mi
->mi_flags
& MI_DIRECTIO
)) &&
452 rp
->r_mapcnt
== 0 && rp
->r_inmap
== 0 &&
453 !vn_has_cached_data(vp
))) {
458 * Let's try to do read in as large a chunk as we can
459 * (Filesystem (NFS client) bsize if possible/needed).
460 * For V3, this is 32K and for V2, this is 8K.
462 bufsize
= MIN(uiop
->uio_resid
, VTOMI(vp
)->mi_curread
);
463 base
= kmem_alloc(bufsize
, KM_SLEEP
);
465 n
= MIN(uiop
->uio_resid
, bufsize
);
466 error
= nfsread(vp
, base
, uiop
->uio_offset
, n
,
470 error
= uiomove(base
, n
, UIO_READ
, uiop
);
472 } while (!error
&& uiop
->uio_resid
> 0 && n
> 0);
473 kmem_free(base
, bufsize
);
480 off
= uiop
->uio_loffset
& MAXBMASK
; /* mapping offset */
481 on
= uiop
->uio_loffset
& MAXBOFFSET
; /* Relative offset */
482 n
= MIN(MAXBSIZE
- on
, uiop
->uio_resid
);
484 error
= nfs_validate_caches(vp
, cr
);
488 mutex_enter(&rp
->r_statelock
);
489 while (rp
->r_flags
& RINCACHEPURGE
) {
490 if (!cv_wait_sig(&rp
->r_cv
, &rp
->r_statelock
)) {
491 mutex_exit(&rp
->r_statelock
);
495 diff
= rp
->r_size
- uiop
->uio_loffset
;
496 mutex_exit(&rp
->r_statelock
);
506 error
= vpm_data_copy(vp
, off
+ on
, n
, uiop
,
509 base
= segmap_getmapflt(segkmap
, vp
, off
+ on
, n
,
511 error
= uiomove(base
+ on
, n
, UIO_READ
, uiop
);
516 * If read a whole block or read to eof,
517 * won't need this buffer again soon.
519 mutex_enter(&rp
->r_statelock
);
520 if (n
+ on
== MAXBSIZE
||
521 uiop
->uio_loffset
== rp
->r_size
)
525 mutex_exit(&rp
->r_statelock
);
527 error
= vpm_sync_pages(vp
, off
, n
, flags
);
529 error
= segmap_release(segkmap
, base
, flags
);
533 (void) vpm_sync_pages(vp
, off
, n
, 0);
535 (void) segmap_release(segkmap
, base
, 0);
538 } while (!error
&& uiop
->uio_resid
> 0);
545 nfs_write(vnode_t
*vp
, struct uio
*uiop
, int ioflag
, cred_t
*cr
,
546 caller_context_t
*ct
)
564 if (nfs_zone() != mi
->mi_zone
)
566 if (vp
->v_type
!= VREG
)
569 if (uiop
->uio_resid
== 0)
572 if (ioflag
& FAPPEND
) {
576 * Must serialize if appending.
578 if (nfs_rw_lock_held(&rp
->r_rwlock
, RW_READER
)) {
579 nfs_rw_exit(&rp
->r_rwlock
);
580 if (nfs_rw_enter_sig(&rp
->r_rwlock
, RW_WRITER
,
585 va
.va_mask
= AT_SIZE
;
586 error
= nfsgetattr(vp
, &va
, cr
);
589 uiop
->uio_loffset
= va
.va_size
;
592 if (uiop
->uio_loffset
> MAXOFF32_T
)
595 offset
= uiop
->uio_loffset
+ uiop
->uio_resid
;
597 if (uiop
->uio_loffset
< 0 || offset
> MAXOFF32_T
)
600 if (uiop
->uio_llimit
> (rlim64_t
)MAXOFF32_T
) {
603 limit
= (rlim_t
)uiop
->uio_llimit
;
607 * Check to make sure that the process will not exceed
608 * its limit on file size. It is okay to write up to
609 * the limit, but not beyond. Thus, the write which
610 * reaches the limit will be short and the next write
611 * will return an error.
614 if (offset
> limit
) {
615 remainder
= offset
- limit
;
616 uiop
->uio_resid
= limit
- uiop
->uio_offset
;
617 if (uiop
->uio_resid
<= 0) {
618 proc_t
*p
= ttoproc(curthread
);
620 uiop
->uio_resid
+= remainder
;
621 mutex_enter(&p
->p_lock
);
622 (void) rctl_action(rctlproc_legacy
[RLIMIT_FSIZE
],
623 p
->p_rctls
, p
, RCA_UNSAFE_SIGINFO
);
624 mutex_exit(&p
->p_lock
);
629 if (nfs_rw_enter_sig(&rp
->r_lkserlock
, RW_READER
, INTR(vp
)))
633 * Bypass VM if caching has been disabled (e.g., locking) or if
634 * using client-side direct I/O and the file is not mmap'd and
635 * there are no cached pages.
637 if ((vp
->v_flag
& VNOCACHE
) ||
638 (((rp
->r_flags
& RDIRECTIO
) || (mi
->mi_flags
& MI_DIRECTIO
)) &&
639 rp
->r_mapcnt
== 0 && rp
->r_inmap
== 0 &&
640 !vn_has_cached_data(vp
))) {
646 if (rp
->r_flags
& RSTALE
) {
647 resid
= uiop
->uio_resid
;
648 offset
= uiop
->uio_loffset
;
651 * A close may have cleared r_error, if so,
652 * propagate ESTALE error return properly
658 bufsize
= MIN(uiop
->uio_resid
, mi
->mi_curwrite
);
659 base
= kmem_alloc(bufsize
, KM_SLEEP
);
661 resid
= uiop
->uio_resid
;
662 offset
= uiop
->uio_loffset
;
663 count
= MIN(uiop
->uio_resid
, bufsize
);
664 org_offset
= uiop
->uio_offset
;
665 error
= uiomove(base
, count
, UIO_WRITE
, uiop
);
667 error
= nfswrite(vp
, base
, org_offset
,
670 } while (!error
&& uiop
->uio_resid
> 0);
671 kmem_free(base
, bufsize
);
676 off
= uiop
->uio_loffset
& MAXBMASK
; /* mapping offset */
677 on
= uiop
->uio_loffset
& MAXBOFFSET
; /* Relative offset */
678 n
= MIN(MAXBSIZE
- on
, uiop
->uio_resid
);
680 resid
= uiop
->uio_resid
;
681 offset
= uiop
->uio_loffset
;
683 if (rp
->r_flags
& RSTALE
) {
686 * A close may have cleared r_error, if so,
687 * propagate ESTALE error return properly
695 * Don't create dirty pages faster than they
696 * can be cleaned so that the system doesn't
697 * get imbalanced. If the async queue is
698 * maxed out, then wait for it to drain before
699 * creating more dirty pages. Also, wait for
700 * any threads doing pagewalks in the vop_getattr
701 * entry points so that they don't block for
704 mutex_enter(&rp
->r_statelock
);
705 while ((mi
->mi_max_threads
!= 0 &&
706 rp
->r_awcount
> 2 * mi
->mi_max_threads
) ||
709 klwp_t
*lwp
= ttolwp(curthread
);
713 if (!cv_wait_sig(&rp
->r_cv
, &rp
->r_statelock
)) {
714 mutex_exit(&rp
->r_statelock
);
723 cv_wait(&rp
->r_cv
, &rp
->r_statelock
);
725 mutex_exit(&rp
->r_statelock
);
728 * Touch the page and fault it in if it is not in core
729 * before segmap_getmapflt or vpm_data_copy can lock it.
730 * This is to avoid the deadlock if the buffer is mapped
731 * to the same file through mmap which we want to write.
733 uio_prefaultpages((long)n
, uiop
);
737 * It will use kpm mappings, so no need to
740 error
= writerp(rp
, NULL
, n
, uiop
, 0);
743 int pon
= uiop
->uio_loffset
& PAGEOFFSET
;
744 size_t pn
= MIN(PAGESIZE
- pon
,
748 mutex_enter(&rp
->r_statelock
);
749 pagecreate
= (pon
== 0) && (pn
== PAGESIZE
||
750 uiop
->uio_loffset
+ pn
>= rp
->r_size
);
751 mutex_exit(&rp
->r_statelock
);
753 base
= segmap_getmapflt(segkmap
, vp
, off
+ on
,
754 pn
, !pagecreate
, S_WRITE
);
756 error
= writerp(rp
, base
+ pon
, n
, uiop
,
760 base
= segmap_getmapflt(segkmap
, vp
, off
+ on
,
762 error
= writerp(rp
, base
+ on
, n
, uiop
, 0);
767 if (mi
->mi_flags
& MI_NOAC
)
769 else if (n
+ on
== MAXBSIZE
|| IS_SWAPVP(vp
)) {
771 * Have written a whole block.
772 * Start an asynchronous write
773 * and mark the buffer to
774 * indicate that it won't be
777 flags
= SM_WRITE
| SM_ASYNC
| SM_DONTNEED
;
780 if ((ioflag
& (FSYNC
|FDSYNC
)) ||
781 (rp
->r_flags
& ROUTOFSPACE
)) {
786 error
= vpm_sync_pages(vp
, off
, n
, flags
);
788 error
= segmap_release(segkmap
, base
, flags
);
792 (void) vpm_sync_pages(vp
, off
, n
, 0);
794 (void) segmap_release(segkmap
, base
, 0);
797 * In the event that we got an access error while
798 * faulting in a page for a write-only file just
804 } while (!error
&& uiop
->uio_resid
> 0);
808 uiop
->uio_resid
= resid
+ remainder
;
809 uiop
->uio_loffset
= offset
;
811 uiop
->uio_resid
+= remainder
;
813 nfs_rw_exit(&rp
->r_lkserlock
);
819 * Flags are composed of {B_ASYNC, B_INVAL, B_FREE, B_DONTNEED}
822 nfs_rdwrlbn(vnode_t
*vp
, page_t
*pp
, uoff_t off
, size_t len
,
823 int flags
, cred_t
*cr
)
828 ASSERT(nfs_zone() == VTOMI(vp
)->mi_zone
);
829 bp
= pageio_setup(pp
, len
, vp
, flags
);
833 * pageio_setup should have set b_addr to 0. This
834 * is correct since we want to do I/O on a page
835 * boundary. bp_mapin will use this addr to calculate
836 * an offset, and then set b_addr to the kernel virtual
837 * address it allocated for us.
839 ASSERT(bp
->b_un
.b_addr
== 0);
843 bp
->b_lblkno
= lbtodb(off
);
845 bp
->b_offset
= (offset_t
)off
;
848 error
= nfs_bio(bp
, cr
);
857 * Write to file. Writes to remote server in largest size
858 * chunks that the server can handle. Write is synchronous.
861 nfswrite(vnode_t
*vp
, caddr_t base
, uint_t offset
, int count
, cred_t
*cr
)
865 struct nfswriteargs wa
;
866 struct nfsattrstat ns
;
876 ASSERT(nfs_zone() == mi
->mi_zone
);
878 wa
.wa_args
= &wa
.wa_args_buf
;
879 wa
.wa_fhandle
= *VTOFH(vp
);
882 tsize
= MIN(mi
->mi_curwrite
, count
);
884 wa
.wa_begoff
= offset
;
885 wa
.wa_totcount
= tsize
;
887 wa
.wa_offset
= offset
;
889 if (mi
->mi_io_kstats
) {
890 mutex_enter(&mi
->mi_lock
);
891 kstat_runq_enter(KSTAT_IO_PTR(mi
->mi_io_kstats
));
892 mutex_exit(&mi
->mi_lock
);
896 error
= rfs2call(mi
, RFS_WRITE
,
897 xdr_writeargs
, (caddr_t
)&wa
,
898 xdr_attrstat
, (caddr_t
)&ns
, cr
,
899 &douprintf
, &ns
.ns_status
, 0, NULL
);
900 } while (error
== ENFS_TRYAGAIN
);
901 if (mi
->mi_io_kstats
) {
902 mutex_enter(&mi
->mi_lock
);
903 kstat_runq_exit(KSTAT_IO_PTR(mi
->mi_io_kstats
));
904 mutex_exit(&mi
->mi_lock
);
908 error
= geterrno(ns
.ns_status
);
910 * Can't check for stale fhandle and purge caches
911 * here because pages are held by nfs_getpage.
912 * Just mark the attribute cache as timed out
913 * and set RWRITEATTR to indicate that the file
914 * was modified with a WRITE operation.
920 if (mi
->mi_io_kstats
) {
921 mutex_enter(&mi
->mi_lock
);
922 KSTAT_IO_PTR(mi
->mi_io_kstats
)->
924 KSTAT_IO_PTR(mi
->mi_io_kstats
)->
926 mutex_exit(&mi
->mi_lock
);
928 lwp_stat_update(LWP_STAT_OUBLK
, 1);
929 mutex_enter(&rp
->r_statelock
);
930 PURGE_ATTRCACHE_LOCKED(rp
);
931 rp
->r_flags
|= RWRITEATTR
;
932 mutex_exit(&rp
->r_statelock
);
935 } while (!error
&& count
);
941 * Read from a file. Reads data in largest chunks our interface can handle.
944 nfsread(vnode_t
*vp
, caddr_t base
, uint_t offset
,
945 int count
, size_t *residp
, cred_t
*cr
)
948 struct nfsreadargs ra
;
949 struct nfsrdresult rr
;
961 ASSERT(nfs_zone() == mi
->mi_zone
);
965 ra
.ra_fhandle
= *VTOFH(vp
);
968 fi
.fhp
= (caddr_t
)&ra
.ra_fhandle
;
969 fi
.copyproc
= nfscopyfh
;
970 fi
.lookupproc
= nfslookup
;
971 fi
.xattrdirproc
= acl_getxattrdir2
;
974 if (mi
->mi_io_kstats
) {
975 mutex_enter(&mi
->mi_lock
);
976 kstat_runq_enter(KSTAT_IO_PTR(mi
->mi_io_kstats
));
977 mutex_exit(&mi
->mi_lock
);
981 tsize
= MIN(mi
->mi_curread
, count
);
983 ra
.ra_offset
= offset
;
984 ra
.ra_totcount
= tsize
;
988 error
= rfs2call(mi
, RFS_READ
,
989 xdr_readargs
, (caddr_t
)&ra
,
990 xdr_rdresult
, (caddr_t
)&rr
, cr
,
991 &douprintf
, &rr
.rr_status
, 0, &fi
);
992 } while (error
== ENFS_TRYAGAIN
);
994 if (mi
->mi_io_kstats
) {
995 mutex_enter(&mi
->mi_lock
);
996 kstat_runq_exit(KSTAT_IO_PTR(mi
->mi_io_kstats
));
997 mutex_exit(&mi
->mi_lock
);
1001 error
= geterrno(rr
.rr_status
);
1003 count
-= rr
.rr_count
;
1004 base
+= rr
.rr_count
;
1005 offset
+= rr
.rr_count
;
1006 if (mi
->mi_io_kstats
) {
1007 mutex_enter(&mi
->mi_lock
);
1008 KSTAT_IO_PTR(mi
->mi_io_kstats
)->reads
++;
1009 KSTAT_IO_PTR(mi
->mi_io_kstats
)->nread
+=
1011 mutex_exit(&mi
->mi_lock
);
1013 lwp_stat_update(LWP_STAT_INBLK
, 1);
1016 } while (!error
&& count
&& rr
.rr_count
== tsize
);
1022 * Since no error occurred, we have the current
1023 * attributes and we need to do a cache check and then
1024 * potentially update the cached attributes. We can't
1025 * use the normal attribute check and cache mechanisms
1026 * because they might cause a cache flush which would
1027 * deadlock. Instead, we just check the cache to see
1028 * if the attributes have changed. If it is, then we
1029 * just mark the attributes as out of date. The next
1030 * time that the attributes are checked, they will be
1031 * out of date, new attributes will be fetched, and
1032 * the page cache will be flushed. If the attributes
1033 * weren't changed, then we just update the cached
1034 * attributes with these attributes.
1037 * If NFS_ACL is supported on the server, then the
1038 * attributes returned by server may have minimal
1039 * permissions sometimes denying access to users having
1040 * proper access. To get the proper attributes, mark
1041 * the attributes as expired so that they will be
1042 * regotten via the NFS_ACL GETATTR2 procedure.
1044 error
= nattr_to_vattr(vp
, &rr
.rr_attr
, &va
);
1045 mutex_enter(&rp
->r_statelock
);
1046 if (error
|| !CACHE_VALID(rp
, va
.va_mtime
, va
.va_size
) ||
1047 (mi
->mi_flags
& MI_ACL
)) {
1048 mutex_exit(&rp
->r_statelock
);
1049 PURGE_ATTRCACHE(vp
);
1051 if (rp
->r_mtime
<= t
) {
1052 nfs_attrcache_va(vp
, &va
);
1054 mutex_exit(&rp
->r_statelock
);
1063 nfs_ioctl(vnode_t
*vp
, int cmd
, intptr_t arg
, int flag
, cred_t
*cr
, int *rvalp
,
1064 caller_context_t
*ct
)
1067 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
1071 return (nfs_directio(vp
, (int)arg
, cr
));
1079 nfs_getattr(vnode_t
*vp
, struct vattr
*vap
, int flags
, cred_t
*cr
,
1080 caller_context_t
*ct
)
1085 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
1088 * If it has been specified that the return value will
1089 * just be used as a hint, and we are only being asked
1090 * for size, fsid or rdevid, then return the client's
1091 * notion of these values without checking to make sure
1092 * that the attribute cache is up to date.
1093 * The whole point is to avoid an over the wire GETATTR
1097 if (flags
& ATTR_HINT
) {
1099 (vap
->va_mask
& (AT_SIZE
| AT_FSID
| AT_RDEV
))) {
1100 mutex_enter(&rp
->r_statelock
);
1101 if (vap
->va_mask
| AT_SIZE
)
1102 vap
->va_size
= rp
->r_size
;
1103 if (vap
->va_mask
| AT_FSID
)
1104 vap
->va_fsid
= rp
->r_attr
.va_fsid
;
1105 if (vap
->va_mask
| AT_RDEV
)
1106 vap
->va_rdev
= rp
->r_attr
.va_rdev
;
1107 mutex_exit(&rp
->r_statelock
);
1113 * Only need to flush pages if asking for the mtime
1114 * and if there any dirty pages or any outstanding
1115 * asynchronous (write) requests for this file.
1117 if (vap
->va_mask
& AT_MTIME
) {
1118 if (vn_has_cached_data(vp
) &&
1119 ((rp
->r_flags
& RDIRTY
) || rp
->r_awcount
> 0)) {
1120 mutex_enter(&rp
->r_statelock
);
1122 mutex_exit(&rp
->r_statelock
);
1123 error
= nfs_putpage(vp
, 0, 0, 0, cr
, ct
);
1124 mutex_enter(&rp
->r_statelock
);
1125 if (error
&& (error
== ENOSPC
|| error
== EDQUOT
)) {
1127 rp
->r_error
= error
;
1129 if (--rp
->r_gcount
== 0)
1130 cv_broadcast(&rp
->r_cv
);
1131 mutex_exit(&rp
->r_statelock
);
1135 return (nfsgetattr(vp
, vap
, cr
));
1140 nfs_setattr(vnode_t
*vp
, struct vattr
*vap
, int flags
, cred_t
*cr
,
1141 caller_context_t
*ct
)
1147 mask
= vap
->va_mask
;
1149 if (mask
& AT_NOSET
)
1152 if ((mask
& AT_SIZE
) &&
1153 vap
->va_type
== VREG
&&
1154 vap
->va_size
> MAXOFF32_T
)
1157 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
1160 va
.va_mask
= AT_UID
| AT_MODE
;
1162 error
= nfsgetattr(vp
, &va
, cr
);
1166 error
= secpolicy_vnode_setattr(cr
, vp
, vap
, &va
, flags
, nfs_accessx
,
1172 error
= nfssetattr(vp
, vap
, flags
, cr
);
1174 if (error
== 0 && (mask
& AT_SIZE
) && vap
->va_size
== 0)
1175 vnevent_truncate(vp
, ct
);
1181 nfssetattr(vnode_t
*vp
, struct vattr
*vap
, int flags
, cred_t
*cr
)
1185 struct nfssaargs args
;
1186 struct nfsattrstat ns
;
1195 mask
= vap
->va_mask
;
1197 ASSERT(nfs_zone() == VTOMI(vp
)->mi_zone
);
1202 * Only need to flush pages if there are any pages and
1203 * if the file is marked as dirty in some fashion. The
1204 * file must be flushed so that we can accurately
1205 * determine the size of the file and the cached data
1206 * after the SETATTR returns. A file is considered to
1207 * be dirty if it is either marked with RDIRTY, has
1208 * outstanding i/o's active, or is mmap'd. In this
1209 * last case, we can't tell whether there are dirty
1210 * pages, so we flush just to be sure.
1212 if (vn_has_cached_data(vp
) &&
1213 ((rp
->r_flags
& RDIRTY
) ||
1215 rp
->r_mapcnt
> 0)) {
1216 ASSERT(vp
->v_type
!= VCHR
);
1217 error
= nfs_putpage(vp
, 0, 0, 0, cr
, NULL
);
1218 if (error
&& (error
== ENOSPC
|| error
== EDQUOT
)) {
1219 mutex_enter(&rp
->r_statelock
);
1221 rp
->r_error
= error
;
1222 mutex_exit(&rp
->r_statelock
);
1227 * If the system call was utime(2) or utimes(2) and the
1228 * application did not specify the times, then set the
1229 * mtime nanosecond field to 1 billion. This will get
1230 * translated from 1 billion nanoseconds to 1 million
1231 * microseconds in the over the wire request. The
1232 * server will use 1 million in the microsecond field
1233 * to tell whether both the mtime and atime should be
1234 * set to the server's current time.
1236 * This is an overload of the protocol and should be
1237 * documented in the NFS Version 2 protocol specification.
1239 if ((mask
& AT_MTIME
) && !(flags
& ATTR_UTIME
)) {
1240 vap
->va_mtime
.tv_nsec
= 1000000000;
1241 if (NFS_TIME_T_OK(vap
->va_mtime
.tv_sec
) &&
1242 NFS_TIME_T_OK(vap
->va_atime
.tv_sec
)) {
1243 error
= vattr_to_sattr(vap
, &args
.saa_sa
);
1246 * Use server times. vap time values will not be used.
1247 * To ensure no time overflow, make sure vap has
1248 * valid values, but retain the original values.
1250 timestruc_t mtime
= vap
->va_mtime
;
1251 timestruc_t atime
= vap
->va_atime
;
1254 now
= gethrestime_sec();
1255 if (NFS_TIME_T_OK(now
)) {
1256 /* Just in case server does not know of this */
1257 vap
->va_mtime
.tv_sec
= now
;
1258 vap
->va_atime
.tv_sec
= now
;
1260 vap
->va_mtime
.tv_sec
= 0;
1261 vap
->va_atime
.tv_sec
= 0;
1263 error
= vattr_to_sattr(vap
, &args
.saa_sa
);
1264 /* set vap times back on */
1265 vap
->va_mtime
= mtime
;
1266 vap
->va_atime
= atime
;
1269 /* Either do not set times or use the client specified times */
1270 error
= vattr_to_sattr(vap
, &args
.saa_sa
);
1273 /* req time field(s) overflow - return immediately */
1276 args
.saa_fh
= *VTOFH(vp
);
1278 va
.va_mask
= AT_MODE
;
1279 error
= nfsgetattr(vp
, &va
, cr
);
1290 error
= rfs2call(mi
, RFS_SETATTR
,
1291 xdr_saargs
, (caddr_t
)&args
,
1292 xdr_attrstat
, (caddr_t
)&ns
, cr
,
1293 &douprintf
, &ns
.ns_status
, 0, NULL
);
1296 * Purge the access cache and ACL cache if changing either the
1297 * owner of the file, the group owner, or the mode. These may
1298 * change the access permissions of the file, so purge old
1299 * information and start over again.
1301 if ((mask
& (AT_UID
| AT_GID
| AT_MODE
)) && (mi
->mi_flags
& MI_ACL
)) {
1302 (void) nfs_access_purge_rp(rp
);
1303 if (rp
->r_secattr
!= NULL
) {
1304 mutex_enter(&rp
->r_statelock
);
1305 vsp
= rp
->r_secattr
;
1306 rp
->r_secattr
= NULL
;
1307 mutex_exit(&rp
->r_statelock
);
1314 error
= geterrno(ns
.ns_status
);
1317 * If changing the size of the file, invalidate
1318 * any local cached data which is no longer part
1319 * of the file. We also possibly invalidate the
1320 * last page in the file. We could use
1321 * pvn_vpzero(), but this would mark the page as
1322 * modified and require it to be written back to
1323 * the server for no particularly good reason.
1324 * This way, if we access it, then we bring it
1325 * back in. A read should be cheaper than a
1328 if (mask
& AT_SIZE
) {
1329 nfs_invalidate_pages(vp
,
1330 (vap
->va_size
& PAGEMASK
), cr
);
1332 (void) nfs_cache_fattr(vp
, &ns
.ns_attr
, &va
, t
, cr
);
1334 * If NFS_ACL is supported on the server, then the
1335 * attributes returned by server may have minimal
1336 * permissions sometimes denying access to users having
1337 * proper access. To get the proper attributes, mark
1338 * the attributes as expired so that they will be
1339 * regotten via the NFS_ACL GETATTR2 procedure.
1341 if (mi
->mi_flags
& MI_ACL
) {
1342 PURGE_ATTRCACHE(vp
);
1345 * This next check attempts to deal with NFS
1346 * servers which can not handle increasing
1347 * the size of the file via setattr. Most
1348 * of these servers do not return an error,
1349 * but do not change the size of the file.
1350 * Hence, this check and then attempt to set
1351 * the file size by writing 1 byte at the
1352 * offset of the end of the file that we need.
1354 if ((mask
& AT_SIZE
) &&
1355 ns
.ns_attr
.na_size
< (uint32_t)vap
->va_size
) {
1358 error
= nfswrite(vp
, &zb
,
1359 vap
->va_size
- sizeof (zb
),
1363 * Some servers will change the mode to clear the setuid
1364 * and setgid bits when changing the uid or gid. The
1365 * client needs to compensate appropriately.
1367 if (mask
& (AT_UID
| AT_GID
)) {
1370 va
.va_mask
= AT_MODE
;
1371 terror
= nfsgetattr(vp
, &va
, cr
);
1373 (((mask
& AT_MODE
) &&
1374 va
.va_mode
!= vap
->va_mode
) ||
1375 (!(mask
& AT_MODE
) &&
1376 va
.va_mode
!= omode
))) {
1377 va
.va_mask
= AT_MODE
;
1379 va
.va_mode
= vap
->va_mode
;
1382 (void) nfssetattr(vp
, &va
, 0, cr
);
1386 PURGE_ATTRCACHE(vp
);
1387 PURGE_STALE_FH(error
, vp
, cr
);
1390 PURGE_ATTRCACHE(vp
);
1397 nfs_accessx(void *vp
, int mode
, cred_t
*cr
)
1399 ASSERT(nfs_zone() == VTOMI((vnode_t
*)vp
)->mi_zone
);
1400 return (nfs_access(vp
, mode
, 0, cr
, NULL
));
1405 nfs_access(vnode_t
*vp
, int mode
, int flags
, cred_t
*cr
, caller_context_t
*ct
)
1414 if (nfs_zone() != mi
->mi_zone
)
1416 if (mi
->mi_flags
& MI_ACL
) {
1417 error
= acl_access2(vp
, mode
, flags
, cr
);
1418 if (mi
->mi_flags
& MI_ACL
)
1422 va
.va_mask
= AT_MODE
| AT_UID
| AT_GID
;
1423 error
= nfsgetattr(vp
, &va
, cr
);
1428 * Disallow write attempts on read-only
1429 * file systems, unless the file is a
1432 if ((mode
& VWRITE
) && vn_is_readonly(vp
) && !IS_DEVVP(vp
))
1436 * Disallow attempts to access mandatory lock files.
1438 if ((mode
& (VWRITE
| VREAD
| VEXEC
)) &&
1439 MANDLOCK(vp
, va
.va_mode
))
1443 * Access check is based on only
1444 * one of owner, group, public.
1445 * If not owner, then check group.
1446 * If not a member of the group,
1447 * then check public access.
1449 if (crgetuid(cr
) != va
.va_uid
) {
1451 if (!groupmember(va
.va_gid
, cr
))
1455 return (secpolicy_vnode_access2(cr
, vp
, va
.va_uid
,
1456 va
.va_mode
<< shift
, mode
));
1459 static int nfs_do_symlink_cache
= 1;
1463 nfs_readlink(vnode_t
*vp
, struct uio
*uiop
, cred_t
*cr
, caller_context_t
*ct
)
1466 struct nfsrdlnres rl
;
1472 * We want to be consistent with UFS semantics so we will return
1473 * EINVAL instead of ENXIO. This violates the XNFS spec and
1474 * the RFC 1094, which are wrong any way. BUGID 1138002.
1476 if (vp
->v_type
!= VLNK
)
1479 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
1483 if (nfs_do_symlink_cache
&& rp
->r_symlink
.contents
!= NULL
) {
1484 error
= nfs_validate_caches(vp
, cr
);
1487 mutex_enter(&rp
->r_statelock
);
1488 if (rp
->r_symlink
.contents
!= NULL
) {
1489 error
= uiomove(rp
->r_symlink
.contents
,
1490 rp
->r_symlink
.len
, UIO_READ
, uiop
);
1491 mutex_exit(&rp
->r_statelock
);
1494 mutex_exit(&rp
->r_statelock
);
1498 rl
.rl_data
= kmem_alloc(NFS_MAXPATHLEN
, KM_SLEEP
);
1501 fi
.fhp
= NULL
; /* no need to update, filehandle not copied */
1502 fi
.copyproc
= nfscopyfh
;
1503 fi
.lookupproc
= nfslookup
;
1504 fi
.xattrdirproc
= acl_getxattrdir2
;
1508 error
= rfs2call(VTOMI(vp
), RFS_READLINK
,
1509 xdr_readlink
, (caddr_t
)VTOFH(vp
),
1510 xdr_rdlnres
, (caddr_t
)&rl
, cr
,
1511 &douprintf
, &rl
.rl_status
, 0, &fi
);
1515 kmem_free((void *)rl
.rl_data
, NFS_MAXPATHLEN
);
1519 error
= geterrno(rl
.rl_status
);
1521 error
= uiomove(rl
.rl_data
, (int)rl
.rl_count
, UIO_READ
, uiop
);
1522 if (nfs_do_symlink_cache
&& rp
->r_symlink
.contents
== NULL
) {
1523 mutex_enter(&rp
->r_statelock
);
1524 if (rp
->r_symlink
.contents
== NULL
) {
1525 rp
->r_symlink
.contents
= rl
.rl_data
;
1526 rp
->r_symlink
.len
= (int)rl
.rl_count
;
1527 rp
->r_symlink
.size
= NFS_MAXPATHLEN
;
1528 mutex_exit(&rp
->r_statelock
);
1530 mutex_exit(&rp
->r_statelock
);
1532 kmem_free((void *)rl
.rl_data
,
1537 kmem_free((void *)rl
.rl_data
, NFS_MAXPATHLEN
);
1540 PURGE_STALE_FH(error
, vp
, cr
);
1542 kmem_free((void *)rl
.rl_data
, NFS_MAXPATHLEN
);
1546 * Conform to UFS semantics (see comment above)
1548 return (error
== ENXIO
? EINVAL
: error
);
1552 * Flush local dirty pages to stable storage on the server.
1554 * If FNODSYNC is specified, then there is nothing to do because
1555 * metadata changes are not cached on the client before being
1556 * sent to the server.
1560 nfs_fsync(vnode_t
*vp
, int syncflag
, cred_t
*cr
, caller_context_t
*ct
)
1564 if ((syncflag
& FNODSYNC
) || IS_SWAPVP(vp
))
1567 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
1570 error
= nfs_putpage(vp
, 0, 0, 0, cr
, ct
);
1572 error
= VTOR(vp
)->r_error
;
1578 * Weirdness: if the file was removed or the target of a rename
1579 * operation while it was open, it got renamed instead. Here we
1580 * remove the renamed file.
1584 nfs_inactive(vnode_t
*vp
, cred_t
*cr
, caller_context_t
*ct
)
1588 ASSERT(vp
!= DNLC_NO_VNODE
);
1591 * If this is coming from the wrong zone, we let someone in the right
1592 * zone take care of it asynchronously. We can get here due to
1593 * VN_RELE() being called from pageout() or fsflush(). This call may
1594 * potentially turn into an expensive no-op if, for instance, v_count
1595 * gets incremented in the meantime, but it's still correct.
1597 if (nfs_zone() != VTOMI(vp
)->mi_zone
) {
1598 nfs_async_inactive(vp
, cr
, nfs_inactive
);
1604 if (rp
->r_unldvp
!= NULL
) {
1606 * Save the vnode pointer for the directory where the
1607 * unlinked-open file got renamed, then set it to NULL
1608 * to prevent another thread from getting here before
1609 * we're done with the remove. While we have the
1610 * statelock, make local copies of the pertinent rnode
1611 * fields. If we weren't to do this in an atomic way, the
1612 * the unl* fields could become inconsistent with respect
1613 * to each other due to a race condition between this
1614 * code and nfs_remove(). See bug report 1034328.
1616 mutex_enter(&rp
->r_statelock
);
1617 if (rp
->r_unldvp
!= NULL
) {
1621 struct nfsdiropargs da
;
1622 enum nfsstat status
;
1626 unldvp
= rp
->r_unldvp
;
1627 rp
->r_unldvp
= NULL
;
1628 unlname
= rp
->r_unlname
;
1629 rp
->r_unlname
= NULL
;
1630 unlcred
= rp
->r_unlcred
;
1631 rp
->r_unlcred
= NULL
;
1632 mutex_exit(&rp
->r_statelock
);
1635 * If there are any dirty pages left, then flush
1636 * them. This is unfortunate because they just
1637 * may get thrown away during the remove operation,
1638 * but we have to do this for correctness.
1640 if (vn_has_cached_data(vp
) &&
1641 ((rp
->r_flags
& RDIRTY
) || rp
->r_count
> 0)) {
1642 ASSERT(vp
->v_type
!= VCHR
);
1643 error
= nfs_putpage(vp
, 0, 0, 0,
1646 mutex_enter(&rp
->r_statelock
);
1648 rp
->r_error
= error
;
1649 mutex_exit(&rp
->r_statelock
);
1654 * Do the remove operation on the renamed file
1656 setdiropargs(&da
, unlname
, unldvp
);
1660 (void) rfs2call(VTOMI(unldvp
), RFS_REMOVE
,
1661 xdr_diropargs
, (caddr_t
)&da
,
1662 xdr_enum
, (caddr_t
)&status
, unlcred
,
1663 &douprintf
, &status
, 0, NULL
);
1665 if (HAVE_RDDIR_CACHE(VTOR(unldvp
)))
1666 nfs_purge_rddir_cache(unldvp
);
1667 PURGE_ATTRCACHE(unldvp
);
1670 * Release stuff held for the remove
1673 kmem_free(unlname
, MAXNAMELEN
);
1677 mutex_exit(&rp
->r_statelock
);
1684 * Remote file system operations having to do with directory manipulation.
1689 nfs_lookup(vnode_t
*dvp
, char *nm
, vnode_t
**vpp
, struct pathname
*pnp
,
1690 int flags
, vnode_t
*rdir
, cred_t
*cr
, caller_context_t
*ct
,
1691 int *direntflags
, pathname_t
*realpnp
)
1695 vnode_t
*avp
= NULL
;
1698 if (nfs_zone() != VTOMI(dvp
)->mi_zone
)
1704 * Are we looking up extended attributes? If so, "dvp" is
1705 * the file or directory for which we want attributes, and
1706 * we need a lookup of the hidden attribute directory
1707 * before we lookup the rest of the path.
1709 if (flags
& LOOKUP_XATTR
) {
1710 bool_t cflag
= ((flags
& CREATE_XATTR_DIR
) != 0);
1714 if (!(mi
->mi_flags
& MI_EXTATTR
))
1717 if (nfs_rw_enter_sig(&drp
->r_rwlock
, RW_READER
, INTR(dvp
)))
1720 (void) nfslookup_dnlc(dvp
, XATTR_DIR_NAME
, &avp
, cr
);
1722 error
= acl_getxattrdir2(dvp
, &avp
, cflag
, cr
, 0);
1726 nfs_rw_exit(&drp
->r_rwlock
);
1729 if (mi
->mi_flags
& MI_EXTATTR
)
1737 if (nfs_rw_enter_sig(&drp
->r_rwlock
, RW_READER
, INTR(dvp
))) {
1742 error
= nfslookup(dvp
, nm
, vpp
, pnp
, flags
, rdir
, cr
, 0);
1744 nfs_rw_exit(&drp
->r_rwlock
);
1747 * If vnode is a device, create special vnode.
1749 if (!error
&& IS_DEVVP(*vpp
)) {
1751 *vpp
= specvp(vp
, vp
->v_rdev
, vp
->v_type
, cr
);
1762 static int nfs_lookup_neg_cache
= 1;
1765 static int nfs_lookup_dnlc_hits
= 0;
1766 static int nfs_lookup_dnlc_misses
= 0;
1767 static int nfs_lookup_dnlc_neg_hits
= 0;
1768 static int nfs_lookup_dnlc_disappears
= 0;
1769 static int nfs_lookup_dnlc_lookups
= 0;
1774 nfslookup(vnode_t
*dvp
, char *nm
, vnode_t
**vpp
, struct pathname
*pnp
,
1775 int flags
, vnode_t
*rdir
, cred_t
*cr
, int rfscall_flags
)
1779 ASSERT(nfs_zone() == VTOMI(dvp
)->mi_zone
);
1782 * If lookup is for "", just return dvp. Don't need
1783 * to send it over the wire, look it up in the dnlc,
1784 * or perform any access checks.
1793 * Can't do lookups in non-directories.
1795 if (dvp
->v_type
!= VDIR
)
1799 * If we're called with RFSCALL_SOFT, it's important that
1800 * the only rfscall is one we make directly; if we permit
1801 * an access call because we're looking up "." or validating
1802 * a dnlc hit, we'll deadlock because that rfscall will not
1803 * have the RFSCALL_SOFT set.
1805 if (rfscall_flags
& RFSCALL_SOFT
)
1809 * If lookup is for ".", just return dvp. Don't need
1810 * to send it over the wire or look it up in the dnlc,
1811 * just need to check access.
1813 if (strcmp(nm
, ".") == 0) {
1814 error
= nfs_access(dvp
, VEXEC
, 0, cr
, NULL
);
1823 * Lookup this name in the DNLC. If there was a valid entry,
1824 * then return the results of the lookup.
1826 error
= nfslookup_dnlc(dvp
, nm
, vpp
, cr
);
1827 if (error
|| *vpp
!= NULL
)
1831 error
= nfslookup_otw(dvp
, nm
, vpp
, cr
, rfscall_flags
);
1837 nfslookup_dnlc(vnode_t
*dvp
, char *nm
, vnode_t
**vpp
, cred_t
*cr
)
1842 ASSERT(*nm
!= '\0');
1843 ASSERT(nfs_zone() == VTOMI(dvp
)->mi_zone
);
1846 * Lookup this name in the DNLC. If successful, then validate
1847 * the caches and then recheck the DNLC. The DNLC is rechecked
1848 * just in case this entry got invalidated during the call
1849 * to nfs_validate_caches.
1851 * An assumption is being made that it is safe to say that a
1852 * file exists which may not on the server. Any operations to
1853 * the server will fail with ESTALE.
1856 nfs_lookup_dnlc_lookups
++;
1858 vp
= dnlc_lookup(dvp
, nm
);
1861 if (vp
== DNLC_NO_VNODE
&& !vn_is_readonly(dvp
)) {
1862 PURGE_ATTRCACHE(dvp
);
1864 error
= nfs_validate_caches(dvp
, cr
);
1867 vp
= dnlc_lookup(dvp
, nm
);
1869 error
= nfs_access(dvp
, VEXEC
, 0, cr
, NULL
);
1874 if (vp
== DNLC_NO_VNODE
) {
1877 nfs_lookup_dnlc_neg_hits
++;
1883 nfs_lookup_dnlc_hits
++;
1888 nfs_lookup_dnlc_disappears
++;
1893 nfs_lookup_dnlc_misses
++;
1902 nfslookup_otw(vnode_t
*dvp
, char *nm
, vnode_t
**vpp
, cred_t
*cr
,
1906 struct nfsdiropargs da
;
1907 struct nfsdiropres dr
;
1912 ASSERT(*nm
!= '\0');
1913 ASSERT(dvp
->v_type
== VDIR
);
1914 ASSERT(nfs_zone() == VTOMI(dvp
)->mi_zone
);
1916 setdiropargs(&da
, nm
, dvp
);
1919 fi
.fhp
= NULL
; /* no need to update, filehandle not copied */
1920 fi
.copyproc
= nfscopyfh
;
1921 fi
.lookupproc
= nfslookup
;
1922 fi
.xattrdirproc
= acl_getxattrdir2
;
1928 error
= rfs2call(VTOMI(dvp
), RFS_LOOKUP
,
1929 xdr_diropargs
, (caddr_t
)&da
,
1930 xdr_diropres
, (caddr_t
)&dr
, cr
,
1931 &douprintf
, &dr
.dr_status
, rfscall_flags
, &fi
);
1934 error
= geterrno(dr
.dr_status
);
1936 *vpp
= makenfsnode(&dr
.dr_fhandle
, &dr
.dr_attr
,
1937 dvp
->v_vfsp
, t
, cr
, VTOR(dvp
)->r_path
, nm
);
1939 * If NFS_ACL is supported on the server, then the
1940 * attributes returned by server may have minimal
1941 * permissions sometimes denying access to users having
1942 * proper access. To get the proper attributes, mark
1943 * the attributes as expired so that they will be
1944 * regotten via the NFS_ACL GETATTR2 procedure.
1946 if (VTOMI(*vpp
)->mi_flags
& MI_ACL
) {
1947 PURGE_ATTRCACHE(*vpp
);
1949 if (!(rfscall_flags
& RFSCALL_SOFT
))
1950 dnlc_update(dvp
, nm
, *vpp
);
1952 PURGE_STALE_FH(error
, dvp
, cr
);
1953 if (error
== ENOENT
&& nfs_lookup_neg_cache
)
1954 dnlc_enter(dvp
, nm
, DNLC_NO_VNODE
);
1963 nfs_create(vnode_t
*dvp
, char *nm
, struct vattr
*va
, enum vcexcl exclusive
,
1964 int mode
, vnode_t
**vpp
, cred_t
*cr
, int lfaware
, caller_context_t
*ct
,
1968 struct nfscreatargs args
;
1969 struct nfsdiropres dr
;
1980 if (nfs_zone() != VTOMI(dvp
)->mi_zone
)
1982 if (nfs_rw_enter_sig(&drp
->r_rwlock
, RW_WRITER
, INTR(dvp
)))
1986 * We make a copy of the attributes because the caller does not
1987 * expect us to change what va points to.
1992 * If the pathname is "", just use dvp. Don't need
1993 * to send it over the wire, look it up in the dnlc,
1994 * or perform any access checks.
2001 * If the pathname is ".", just use dvp. Don't need
2002 * to send it over the wire or look it up in the dnlc,
2003 * just need to check access.
2005 } else if (strcmp(nm
, ".") == 0) {
2006 error
= nfs_access(dvp
, VEXEC
, 0, cr
, ct
);
2008 nfs_rw_exit(&drp
->r_rwlock
);
2014 * We need to go over the wire, just to be sure whether the
2015 * file exists or not. Using the DNLC can be dangerous in
2016 * this case when making a decision regarding existence.
2019 error
= nfslookup_otw(dvp
, nm
, &vp
, cr
, 0);
2022 if (exclusive
== EXCL
)
2024 else if (vp
->v_type
== VDIR
&& (mode
& VWRITE
))
2028 * If vnode is a device, create special vnode.
2032 vp
= specvp(vp
, vp
->v_rdev
, vp
->v_type
, cr
);
2035 if (!(error
= fop_access(vp
, mode
, 0, cr
, ct
))) {
2036 if ((vattr
.va_mask
& AT_SIZE
) &&
2037 vp
->v_type
== VREG
) {
2038 vattr
.va_mask
= AT_SIZE
;
2039 error
= nfssetattr(vp
, &vattr
, 0, cr
);
2043 * Existing file was truncated;
2044 * emit a create event.
2046 vnevent_create(vp
, ct
);
2051 nfs_rw_exit(&drp
->r_rwlock
);
2060 ASSERT(vattr
.va_mask
& AT_TYPE
);
2061 if (vattr
.va_type
== VREG
) {
2062 ASSERT(vattr
.va_mask
& AT_MODE
);
2063 if (MANDMODE(vattr
.va_mode
)) {
2064 nfs_rw_exit(&drp
->r_rwlock
);
2069 dnlc_remove(dvp
, nm
);
2071 setdiropargs(&args
.ca_da
, nm
, dvp
);
2074 * Decide what the group-id of the created file should be.
2075 * Set it in attribute list as advisory...then do a setattr
2076 * if the server didn't get it right the first time.
2078 error
= setdirgid(dvp
, &vattr
.va_gid
, cr
);
2080 nfs_rw_exit(&drp
->r_rwlock
);
2083 vattr
.va_mask
|= AT_GID
;
2086 * This is a completely gross hack to make mknod
2087 * work over the wire until we can wack the protocol
2089 #define IFCHR 0020000 /* character special */
2090 #define IFBLK 0060000 /* block special */
2091 #define IFSOCK 0140000 /* socket */
2094 * dev_t is uint_t in 5.x and short in 4.x. Both 4.x
2095 * supports 8 bit majors. 5.x supports 14 bit majors. 5.x supports 18
2096 * bits in the minor number where 4.x supports 8 bits. If the 5.x
2097 * minor/major numbers <= 8 bits long, compress the device
2098 * number before sending it. Otherwise, the 4.x server will not
2099 * create the device with the correct device number and nothing can be
2102 if (vattr
.va_type
== VCHR
|| vattr
.va_type
== VBLK
) {
2103 dev_t d
= vattr
.va_rdev
;
2106 if (vattr
.va_type
== VCHR
)
2107 vattr
.va_mode
|= IFCHR
;
2109 vattr
.va_mode
|= IFBLK
;
2111 (void) cmpldev(&dev32
, d
);
2112 if (dev32
& ~((SO4_MAXMAJ
<< L_BITSMINOR32
) | SO4_MAXMIN
))
2113 vattr
.va_size
= (uoff_t
)dev32
;
2115 vattr
.va_size
= (uoff_t
)nfsv2_cmpdev(d
);
2117 vattr
.va_mask
|= AT_MODE
|AT_SIZE
;
2118 } else if (vattr
.va_type
== VFIFO
) {
2119 vattr
.va_mode
|= IFCHR
; /* xtra kludge for namedpipe */
2120 vattr
.va_size
= (uoff_t
)NFS_FIFO_DEV
; /* blech */
2121 vattr
.va_mask
|= AT_MODE
|AT_SIZE
;
2122 } else if (vattr
.va_type
== VSOCK
) {
2123 vattr
.va_mode
|= IFSOCK
;
2125 * To avoid triggering bugs in the servers set AT_SIZE
2126 * (all other RFS_CREATE calls set this).
2129 vattr
.va_mask
|= AT_MODE
|AT_SIZE
;
2132 args
.ca_sa
= &args
.ca_sa_buf
;
2133 error
= vattr_to_sattr(&vattr
, args
.ca_sa
);
2135 /* req time field(s) overflow - return immediately */
2136 nfs_rw_exit(&drp
->r_rwlock
);
2144 error
= rfs2call(VTOMI(dvp
), RFS_CREATE
,
2145 xdr_creatargs
, (caddr_t
)&args
,
2146 xdr_diropres
, (caddr_t
)&dr
, cr
,
2147 &douprintf
, &dr
.dr_status
, 0, NULL
);
2149 PURGE_ATTRCACHE(dvp
); /* mod time changed */
2152 error
= geterrno(dr
.dr_status
);
2154 if (HAVE_RDDIR_CACHE(drp
))
2155 nfs_purge_rddir_cache(dvp
);
2156 vp
= makenfsnode(&dr
.dr_fhandle
, &dr
.dr_attr
,
2157 dvp
->v_vfsp
, t
, cr
, NULL
, NULL
);
2159 * If NFS_ACL is supported on the server, then the
2160 * attributes returned by server may have minimal
2161 * permissions sometimes denying access to users having
2162 * proper access. To get the proper attributes, mark
2163 * the attributes as expired so that they will be
2164 * regotten via the NFS_ACL GETATTR2 procedure.
2166 if (VTOMI(vp
)->mi_flags
& MI_ACL
) {
2167 PURGE_ATTRCACHE(vp
);
2169 dnlc_update(dvp
, nm
, vp
);
2171 if (vattr
.va_size
== 0) {
2172 mutex_enter(&rp
->r_statelock
);
2174 mutex_exit(&rp
->r_statelock
);
2175 if (vn_has_cached_data(vp
)) {
2176 ASSERT(vp
->v_type
!= VCHR
);
2177 nfs_invalidate_pages(vp
,
2183 * Make sure the gid was set correctly.
2184 * If not, try to set it (but don't lose
2185 * any sleep over it).
2187 if (vattr
.va_gid
!= rp
->r_attr
.va_gid
) {
2188 vattr
.va_mask
= AT_GID
;
2189 (void) nfssetattr(vp
, &vattr
, 0, cr
);
2193 * If vnode is a device create special vnode
2196 *vpp
= specvp(vp
, vp
->v_rdev
, vp
->v_type
, cr
);
2201 PURGE_STALE_FH(error
, dvp
, cr
);
2205 nfs_rw_exit(&drp
->r_rwlock
);
2211 * Weirdness: if the vnode to be removed is open
2212 * we rename it instead of removing it and nfs_inactive
2213 * will remove the new name.
2217 nfs_remove(vnode_t
*dvp
, char *nm
, cred_t
*cr
, caller_context_t
*ct
, int flags
)
2220 struct nfsdiropargs da
;
2221 enum nfsstat status
;
2228 if (nfs_zone() != VTOMI(dvp
)->mi_zone
)
2231 if (nfs_rw_enter_sig(&drp
->r_rwlock
, RW_WRITER
, INTR(dvp
)))
2234 error
= nfslookup(dvp
, nm
, &vp
, NULL
, 0, NULL
, cr
, 0);
2236 nfs_rw_exit(&drp
->r_rwlock
);
2240 if (vp
->v_type
== VDIR
&& secpolicy_fs_linkdir(cr
, dvp
->v_vfsp
)) {
2242 nfs_rw_exit(&drp
->r_rwlock
);
2247 * First just remove the entry from the name cache, as it
2248 * is most likely the only entry for this vp.
2250 dnlc_remove(dvp
, nm
);
2253 * If the file has a v_count > 1 then there may be more than one
2254 * entry in the name cache due multiple links or an open file,
2255 * but we don't have the real reference count so flush all
2258 if (vp
->v_count
> 1)
2262 * Now we have the real reference count on the vnode
2265 mutex_enter(&rp
->r_statelock
);
2266 if (vp
->v_count
> 1 &&
2267 (rp
->r_unldvp
== NULL
|| strcmp(nm
, rp
->r_unlname
) == 0)) {
2268 mutex_exit(&rp
->r_statelock
);
2269 tmpname
= newname();
2270 error
= nfsrename(dvp
, nm
, dvp
, tmpname
, cr
, ct
);
2272 kmem_free(tmpname
, MAXNAMELEN
);
2274 mutex_enter(&rp
->r_statelock
);
2275 if (rp
->r_unldvp
== NULL
) {
2278 if (rp
->r_unlcred
!= NULL
)
2279 crfree(rp
->r_unlcred
);
2282 rp
->r_unlname
= tmpname
;
2284 kmem_free(rp
->r_unlname
, MAXNAMELEN
);
2285 rp
->r_unlname
= tmpname
;
2287 mutex_exit(&rp
->r_statelock
);
2290 mutex_exit(&rp
->r_statelock
);
2292 * We need to flush any dirty pages which happen to
2293 * be hanging around before removing the file. This
2294 * shouldn't happen very often and mostly on file
2295 * systems mounted "nocto".
2297 if (vn_has_cached_data(vp
) &&
2298 ((rp
->r_flags
& RDIRTY
) || rp
->r_count
> 0)) {
2299 error
= nfs_putpage(vp
, 0, 0, 0, cr
, ct
);
2300 if (error
&& (error
== ENOSPC
|| error
== EDQUOT
)) {
2301 mutex_enter(&rp
->r_statelock
);
2303 rp
->r_error
= error
;
2304 mutex_exit(&rp
->r_statelock
);
2308 setdiropargs(&da
, nm
, dvp
);
2312 error
= rfs2call(VTOMI(dvp
), RFS_REMOVE
,
2313 xdr_diropargs
, (caddr_t
)&da
,
2314 xdr_enum
, (caddr_t
)&status
, cr
,
2315 &douprintf
, &status
, 0, NULL
);
2318 * The xattr dir may be gone after last attr is removed,
2319 * so flush it from dnlc.
2321 if (dvp
->v_flag
& V_XATTRDIR
)
2324 PURGE_ATTRCACHE(dvp
); /* mod time changed */
2325 PURGE_ATTRCACHE(vp
); /* link count changed */
2328 error
= geterrno(status
);
2330 if (HAVE_RDDIR_CACHE(drp
))
2331 nfs_purge_rddir_cache(dvp
);
2333 PURGE_STALE_FH(error
, dvp
, cr
);
2339 vnevent_remove(vp
, dvp
, nm
, ct
);
2343 nfs_rw_exit(&drp
->r_rwlock
);
2350 nfs_link(vnode_t
*tdvp
, vnode_t
*svp
, char *tnm
, cred_t
*cr
,
2351 caller_context_t
*ct
, int flags
)
2354 struct nfslinkargs args
;
2355 enum nfsstat status
;
2360 if (nfs_zone() != VTOMI(tdvp
)->mi_zone
)
2362 if (fop_realvp(svp
, &realvp
, ct
) == 0)
2365 args
.la_from
= VTOFH(svp
);
2366 setdiropargs(&args
.la_to
, tnm
, tdvp
);
2369 if (nfs_rw_enter_sig(&tdrp
->r_rwlock
, RW_WRITER
, INTR(tdvp
)))
2372 dnlc_remove(tdvp
, tnm
);
2376 error
= rfs2call(VTOMI(svp
), RFS_LINK
,
2377 xdr_linkargs
, (caddr_t
)&args
,
2378 xdr_enum
, (caddr_t
)&status
, cr
,
2379 &douprintf
, &status
, 0, NULL
);
2381 PURGE_ATTRCACHE(tdvp
); /* mod time changed */
2382 PURGE_ATTRCACHE(svp
); /* link count changed */
2385 error
= geterrno(status
);
2387 if (HAVE_RDDIR_CACHE(tdrp
))
2388 nfs_purge_rddir_cache(tdvp
);
2392 nfs_rw_exit(&tdrp
->r_rwlock
);
2396 * Notify the source file of this link operation.
2398 vnevent_link(svp
, ct
);
2405 nfs_rename(vnode_t
*odvp
, char *onm
, vnode_t
*ndvp
, char *nnm
, cred_t
*cr
,
2406 caller_context_t
*ct
, int flags
)
2410 if (nfs_zone() != VTOMI(odvp
)->mi_zone
)
2412 if (fop_realvp(ndvp
, &realvp
, ct
) == 0)
2415 return (nfsrename(odvp
, onm
, ndvp
, nnm
, cr
, ct
));
2419 * nfsrename does the real work of renaming in NFS Version 2.
2422 nfsrename(vnode_t
*odvp
, char *onm
, vnode_t
*ndvp
, char *nnm
, cred_t
*cr
,
2423 caller_context_t
*ct
)
2426 enum nfsstat status
;
2427 struct nfsrnmargs args
;
2429 vnode_t
*nvp
= NULL
;
2430 vnode_t
*ovp
= NULL
;
2436 ASSERT(nfs_zone() == VTOMI(odvp
)->mi_zone
);
2437 if (strcmp(onm
, ".") == 0 || strcmp(onm
, "..") == 0 ||
2438 strcmp(nnm
, ".") == 0 || strcmp(nnm
, "..") == 0)
2443 if ((intptr_t)odrp
< (intptr_t)ndrp
) {
2444 if (nfs_rw_enter_sig(&odrp
->r_rwlock
, RW_WRITER
, INTR(odvp
)))
2446 if (nfs_rw_enter_sig(&ndrp
->r_rwlock
, RW_WRITER
, INTR(ndvp
))) {
2447 nfs_rw_exit(&odrp
->r_rwlock
);
2451 if (nfs_rw_enter_sig(&ndrp
->r_rwlock
, RW_WRITER
, INTR(ndvp
)))
2453 if (nfs_rw_enter_sig(&odrp
->r_rwlock
, RW_WRITER
, INTR(odvp
))) {
2454 nfs_rw_exit(&ndrp
->r_rwlock
);
2460 * Lookup the target file. If it exists, it needs to be
2461 * checked to see whether it is a mount point and whether
2462 * it is active (open).
2464 error
= nfslookup(ndvp
, nnm
, &nvp
, NULL
, 0, NULL
, cr
, 0);
2467 * If this file has been mounted on, then just
2468 * return busy because renaming to it would remove
2469 * the mounted file system from the name space.
2471 if (vn_mountedvfs(nvp
) != NULL
) {
2473 nfs_rw_exit(&odrp
->r_rwlock
);
2474 nfs_rw_exit(&ndrp
->r_rwlock
);
2479 * Purge the name cache of all references to this vnode
2480 * so that we can check the reference count to infer
2481 * whether it is active or not.
2484 * First just remove the entry from the name cache, as it
2485 * is most likely the only entry for this vp.
2487 dnlc_remove(ndvp
, nnm
);
2489 * If the file has a v_count > 1 then there may be more
2490 * than one entry in the name cache due multiple links
2491 * or an open file, but we don't have the real reference
2492 * count so flush all possible entries.
2494 if (nvp
->v_count
> 1)
2498 * If the vnode is active and is not a directory,
2499 * arrange to rename it to a
2500 * temporary file so that it will continue to be
2501 * accessible. This implements the "unlink-open-file"
2502 * semantics for the target of a rename operation.
2503 * Before doing this though, make sure that the
2504 * source and target files are not already the same.
2506 if (nvp
->v_count
> 1 && nvp
->v_type
!= VDIR
) {
2508 * Lookup the source name.
2510 error
= nfslookup(odvp
, onm
, &ovp
, NULL
, 0, NULL
,
2514 * The source name *should* already exist.
2518 nfs_rw_exit(&odrp
->r_rwlock
);
2519 nfs_rw_exit(&ndrp
->r_rwlock
);
2524 * Compare the two vnodes. If they are the same,
2525 * just release all held vnodes and return success.
2530 nfs_rw_exit(&odrp
->r_rwlock
);
2531 nfs_rw_exit(&ndrp
->r_rwlock
);
2536 * Can't mix and match directories and non-
2537 * directories in rename operations. We already
2538 * know that the target is not a directory. If
2539 * the source is a directory, return an error.
2541 if (ovp
->v_type
== VDIR
) {
2544 nfs_rw_exit(&odrp
->r_rwlock
);
2545 nfs_rw_exit(&ndrp
->r_rwlock
);
2550 * The target file exists, is not the same as
2551 * the source file, and is active. Link it
2552 * to a temporary filename to avoid having
2553 * the server removing the file completely.
2555 tmpname
= newname();
2556 error
= nfs_link(ndvp
, nvp
, tmpname
, cr
, NULL
, 0);
2557 if (error
== EOPNOTSUPP
) {
2558 error
= nfs_rename(ndvp
, nnm
, ndvp
, tmpname
,
2562 kmem_free(tmpname
, MAXNAMELEN
);
2565 nfs_rw_exit(&odrp
->r_rwlock
);
2566 nfs_rw_exit(&ndrp
->r_rwlock
);
2570 mutex_enter(&rp
->r_statelock
);
2571 if (rp
->r_unldvp
== NULL
) {
2573 rp
->r_unldvp
= ndvp
;
2574 if (rp
->r_unlcred
!= NULL
)
2575 crfree(rp
->r_unlcred
);
2578 rp
->r_unlname
= tmpname
;
2580 kmem_free(rp
->r_unlname
, MAXNAMELEN
);
2581 rp
->r_unlname
= tmpname
;
2583 mutex_exit(&rp
->r_statelock
);
2589 * When renaming directories to be a subdirectory of a
2590 * different parent, the dnlc entry for ".." will no
2591 * longer be valid, so it must be removed.
2593 * We do a lookup here to determine whether we are renaming
2594 * a directory and we need to check if we are renaming
2595 * an unlinked file. This might have already been done
2596 * in previous code, so we check ovp == NULL to avoid
2600 error
= nfslookup(odvp
, onm
, &ovp
, NULL
, 0, NULL
, cr
, 0);
2603 * The source name *should* already exist.
2606 nfs_rw_exit(&odrp
->r_rwlock
);
2607 nfs_rw_exit(&ndrp
->r_rwlock
);
2613 ASSERT(ovp
!= NULL
);
2616 dnlc_remove(odvp
, onm
);
2617 dnlc_remove(ndvp
, nnm
);
2619 setdiropargs(&args
.rna_from
, onm
, odvp
);
2620 setdiropargs(&args
.rna_to
, nnm
, ndvp
);
2624 error
= rfs2call(VTOMI(odvp
), RFS_RENAME
,
2625 xdr_rnmargs
, (caddr_t
)&args
,
2626 xdr_enum
, (caddr_t
)&status
, cr
,
2627 &douprintf
, &status
, 0, NULL
);
2629 PURGE_ATTRCACHE(odvp
); /* mod time changed */
2630 PURGE_ATTRCACHE(ndvp
); /* mod time changed */
2633 error
= geterrno(status
);
2635 if (HAVE_RDDIR_CACHE(odrp
))
2636 nfs_purge_rddir_cache(odvp
);
2637 if (HAVE_RDDIR_CACHE(ndrp
))
2638 nfs_purge_rddir_cache(ndvp
);
2640 * when renaming directories to be a subdirectory of a
2641 * different parent, the dnlc entry for ".." will no
2642 * longer be valid, so it must be removed
2646 if (ovp
->v_type
== VDIR
) {
2647 dnlc_remove(ovp
, "..");
2648 if (HAVE_RDDIR_CACHE(rp
))
2649 nfs_purge_rddir_cache(ovp
);
2654 * If we are renaming the unlinked file, update the
2655 * r_unldvp and r_unlname as needed.
2657 mutex_enter(&rp
->r_statelock
);
2658 if (rp
->r_unldvp
!= NULL
) {
2659 if (strcmp(rp
->r_unlname
, onm
) == 0) {
2660 (void) strncpy(rp
->r_unlname
,
2662 rp
->r_unlname
[MAXNAMELEN
- 1] = '\0';
2664 if (ndvp
!= rp
->r_unldvp
) {
2665 VN_RELE(rp
->r_unldvp
);
2666 rp
->r_unldvp
= ndvp
;
2671 mutex_exit(&rp
->r_statelock
);
2674 * System V defines rename to return EEXIST, not
2675 * ENOTEMPTY if the target directory is not empty.
2676 * Over the wire, the error is NFSERR_ENOTEMPTY
2677 * which geterrno maps to ENOTEMPTY.
2679 if (error
== ENOTEMPTY
)
2686 vnevent_rename_dest(nvp
, ndvp
, nnm
, ct
);
2689 vnevent_rename_dest_dir(ndvp
, ct
);
2691 ASSERT(ovp
!= NULL
);
2692 vnevent_rename_src(ovp
, odvp
, onm
, ct
);
2700 nfs_rw_exit(&odrp
->r_rwlock
);
2701 nfs_rw_exit(&ndrp
->r_rwlock
);
2708 nfs_mkdir(vnode_t
*dvp
, char *nm
, struct vattr
*va
, vnode_t
**vpp
, cred_t
*cr
,
2709 caller_context_t
*ct
, int flags
, vsecattr_t
*vsecp
)
2712 struct nfscreatargs args
;
2713 struct nfsdiropres dr
;
2718 if (nfs_zone() != VTOMI(dvp
)->mi_zone
)
2721 setdiropargs(&args
.ca_da
, nm
, dvp
);
2724 * Decide what the group-id and set-gid bit of the created directory
2725 * should be. May have to do a setattr to get the gid right.
2727 error
= setdirgid(dvp
, &va
->va_gid
, cr
);
2730 error
= setdirmode(dvp
, &va
->va_mode
, cr
);
2733 va
->va_mask
|= AT_MODE
|AT_GID
;
2735 args
.ca_sa
= &args
.ca_sa_buf
;
2736 error
= vattr_to_sattr(va
, args
.ca_sa
);
2738 /* req time field(s) overflow - return immediately */
2743 if (nfs_rw_enter_sig(&drp
->r_rwlock
, RW_WRITER
, INTR(dvp
)))
2746 dnlc_remove(dvp
, nm
);
2752 error
= rfs2call(VTOMI(dvp
), RFS_MKDIR
,
2753 xdr_creatargs
, (caddr_t
)&args
,
2754 xdr_diropres
, (caddr_t
)&dr
, cr
,
2755 &douprintf
, &dr
.dr_status
, 0, NULL
);
2757 PURGE_ATTRCACHE(dvp
); /* mod time changed */
2760 error
= geterrno(dr
.dr_status
);
2762 if (HAVE_RDDIR_CACHE(drp
))
2763 nfs_purge_rddir_cache(dvp
);
2765 * The attributes returned by RFS_MKDIR can not
2766 * be depended upon, so mark the attribute cache
2767 * as purged. A subsequent GETATTR will get the
2768 * correct attributes from the server.
2770 *vpp
= makenfsnode(&dr
.dr_fhandle
, &dr
.dr_attr
,
2771 dvp
->v_vfsp
, t
, cr
, NULL
, NULL
);
2772 PURGE_ATTRCACHE(*vpp
);
2773 dnlc_update(dvp
, nm
, *vpp
);
2776 * Make sure the gid was set correctly.
2777 * If not, try to set it (but don't lose
2778 * any sleep over it).
2780 if (va
->va_gid
!= VTOR(*vpp
)->r_attr
.va_gid
) {
2781 va
->va_mask
= AT_GID
;
2782 (void) nfssetattr(*vpp
, va
, 0, cr
);
2785 PURGE_STALE_FH(error
, dvp
, cr
);
2789 nfs_rw_exit(&drp
->r_rwlock
);
2796 nfs_rmdir(vnode_t
*dvp
, char *nm
, vnode_t
*cdir
, cred_t
*cr
,
2797 caller_context_t
*ct
, int flags
)
2800 enum nfsstat status
;
2801 struct nfsdiropargs da
;
2806 if (nfs_zone() != VTOMI(dvp
)->mi_zone
)
2809 if (nfs_rw_enter_sig(&drp
->r_rwlock
, RW_WRITER
, INTR(dvp
)))
2813 * Attempt to prevent a rmdir(".") from succeeding.
2815 error
= nfslookup(dvp
, nm
, &vp
, NULL
, 0, NULL
, cr
, 0);
2817 nfs_rw_exit(&drp
->r_rwlock
);
2823 nfs_rw_exit(&drp
->r_rwlock
);
2827 setdiropargs(&da
, nm
, dvp
);
2830 * First just remove the entry from the name cache, as it
2831 * is most likely an entry for this vp.
2833 dnlc_remove(dvp
, nm
);
2836 * If there vnode reference count is greater than one, then
2837 * there may be additional references in the DNLC which will
2838 * need to be purged. First, trying removing the entry for
2839 * the parent directory and see if that removes the additional
2840 * reference(s). If that doesn't do it, then use dnlc_purge_vp
2841 * to completely remove any references to the directory which
2842 * might still exist in the DNLC.
2844 if (vp
->v_count
> 1) {
2845 dnlc_remove(vp
, "..");
2846 if (vp
->v_count
> 1)
2852 error
= rfs2call(VTOMI(dvp
), RFS_RMDIR
,
2853 xdr_diropargs
, (caddr_t
)&da
,
2854 xdr_enum
, (caddr_t
)&status
, cr
,
2855 &douprintf
, &status
, 0, NULL
);
2857 PURGE_ATTRCACHE(dvp
); /* mod time changed */
2861 nfs_rw_exit(&drp
->r_rwlock
);
2865 error
= geterrno(status
);
2867 if (HAVE_RDDIR_CACHE(drp
))
2868 nfs_purge_rddir_cache(dvp
);
2869 if (HAVE_RDDIR_CACHE(VTOR(vp
)))
2870 nfs_purge_rddir_cache(vp
);
2872 PURGE_STALE_FH(error
, dvp
, cr
);
2874 * System V defines rmdir to return EEXIST, not
2875 * ENOTEMPTY if the directory is not empty. Over
2876 * the wire, the error is NFSERR_ENOTEMPTY which
2877 * geterrno maps to ENOTEMPTY.
2879 if (error
== ENOTEMPTY
)
2884 vnevent_rmdir(vp
, dvp
, nm
, ct
);
2888 nfs_rw_exit(&drp
->r_rwlock
);
2895 nfs_symlink(vnode_t
*dvp
, char *lnm
, struct vattr
*tva
, char *tnm
, cred_t
*cr
,
2896 caller_context_t
*ct
, int flags
)
2899 struct nfsslargs args
;
2900 enum nfsstat status
;
2904 if (nfs_zone() != VTOMI(dvp
)->mi_zone
)
2906 setdiropargs(&args
.sla_from
, lnm
, dvp
);
2907 args
.sla_sa
= &args
.sla_sa_buf
;
2908 error
= vattr_to_sattr(tva
, args
.sla_sa
);
2910 /* req time field(s) overflow - return immediately */
2916 if (nfs_rw_enter_sig(&drp
->r_rwlock
, RW_WRITER
, INTR(dvp
)))
2919 dnlc_remove(dvp
, lnm
);
2923 error
= rfs2call(VTOMI(dvp
), RFS_SYMLINK
,
2924 xdr_slargs
, (caddr_t
)&args
,
2925 xdr_enum
, (caddr_t
)&status
, cr
,
2926 &douprintf
, &status
, 0, NULL
);
2928 PURGE_ATTRCACHE(dvp
); /* mod time changed */
2931 error
= geterrno(status
);
2933 if (HAVE_RDDIR_CACHE(drp
))
2934 nfs_purge_rddir_cache(dvp
);
2936 PURGE_STALE_FH(error
, dvp
, cr
);
2940 nfs_rw_exit(&drp
->r_rwlock
);
2946 static int nfs_readdir_cache_hits
= 0;
2947 static int nfs_readdir_cache_shorts
= 0;
2948 static int nfs_readdir_cache_waits
= 0;
2949 static int nfs_readdir_cache_misses
= 0;
2950 static int nfs_readdir_readahead
= 0;
2953 static int nfs_shrinkreaddir
= 0;
2956 * Read directory entries.
2957 * There are some weird things to look out for here. The uio_offset
2958 * field is either 0 or it is the offset returned from a previous
2959 * readdir. It is an opaque value used by the server to find the
2960 * correct directory block to read. The count field is the number
2961 * of blocks to read on the server. This is advisory only, the server
2962 * may return only one block's worth of entries. Entries may be compressed
2967 nfs_readdir(vnode_t
*vp
, struct uio
*uiop
, cred_t
*cr
, int *eofp
,
2968 caller_context_t
*ct
, int flags
)
2984 ASSERT(nfs_rw_lock_held(&rp
->r_rwlock
, RW_READER
));
2985 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
2988 * Make sure that the directory cache is valid.
2990 if (HAVE_RDDIR_CACHE(rp
)) {
2991 if (nfs_disable_rddir_cache
) {
2993 * Setting nfs_disable_rddir_cache in /etc/system
2994 * allows interoperability with servers that do not
2995 * properly update the attributes of directories.
2996 * Any cached information gets purged before an
2997 * access is made to it.
2999 nfs_purge_rddir_cache(vp
);
3001 error
= nfs_validate_caches(vp
, cr
);
3008 * UGLINESS: SunOS 3.2 servers apparently cannot always handle an
3009 * RFS_READDIR request with rda_count set to more than 0x400. So
3010 * we reduce the request size here purely for compatibility.
3012 * In general, this is no longer required. However, if a server
3013 * is discovered which can not handle requests larger than 1024,
3014 * nfs_shrinkreaddir can be set to 1 to enable this backwards
3017 * In any case, the request size is limited to NFS_MAXDATA bytes.
3019 count
= MIN(uiop
->uio_iov
->iov_len
,
3020 nfs_shrinkreaddir
? 0x400 : NFS_MAXDATA
);
3028 * Short circuit last readdir which always returns 0 bytes.
3029 * This can be done after the directory has been read through
3030 * completely at least once. This will set r_direof which
3031 * can be used to find the value of the last cookie.
3033 mutex_enter(&rp
->r_statelock
);
3034 if (rp
->r_direof
!= NULL
&&
3035 uiop
->uio_offset
== rp
->r_direof
->nfs_ncookie
) {
3036 mutex_exit(&rp
->r_statelock
);
3038 nfs_readdir_cache_shorts
++;
3043 rddir_cache_rele(nrdc
);
3047 * Look for a cache entry. Cache entries are identified
3048 * by the NFS cookie value and the byte count requested.
3050 srdc
.nfs_cookie
= uiop
->uio_offset
;
3051 srdc
.buflen
= count
;
3052 rdc
= avl_find(&rp
->r_dir
, &srdc
, &where
);
3054 rddir_cache_hold(rdc
);
3056 * If the cache entry is in the process of being
3057 * filled in, wait until this completes. The
3058 * RDDIRWAIT bit is set to indicate that someone
3059 * is waiting and then the thread currently
3060 * filling the entry is done, it should do a
3061 * cv_broadcast to wakeup all of the threads
3062 * waiting for it to finish.
3064 if (rdc
->flags
& RDDIR
) {
3065 nfs_rw_exit(&rp
->r_rwlock
);
3066 rdc
->flags
|= RDDIRWAIT
;
3068 nfs_readdir_cache_waits
++;
3070 if (!cv_wait_sig(&rdc
->cv
, &rp
->r_statelock
)) {
3072 * We got interrupted, probably
3073 * the user typed ^C or an alarm
3074 * fired. We free the new entry
3075 * if we allocated one.
3077 mutex_exit(&rp
->r_statelock
);
3078 (void) nfs_rw_enter_sig(&rp
->r_rwlock
,
3080 rddir_cache_rele(rdc
);
3082 rddir_cache_rele(nrdc
);
3085 mutex_exit(&rp
->r_statelock
);
3086 (void) nfs_rw_enter_sig(&rp
->r_rwlock
,
3088 rddir_cache_rele(rdc
);
3092 * Check to see if a readdir is required to
3093 * fill the entry. If so, mark this entry
3094 * as being filled, remove our reference,
3095 * and branch to the code to fill the entry.
3097 if (rdc
->flags
& RDDIRREQ
) {
3098 rdc
->flags
&= ~RDDIRREQ
;
3099 rdc
->flags
|= RDDIR
;
3101 rddir_cache_rele(nrdc
);
3103 mutex_exit(&rp
->r_statelock
);
3108 nfs_readdir_cache_hits
++;
3111 * If an error occurred while attempting
3112 * to fill the cache entry, just return it.
3116 mutex_exit(&rp
->r_statelock
);
3117 rddir_cache_rele(rdc
);
3119 rddir_cache_rele(nrdc
);
3124 * The cache entry is complete and good,
3125 * copyout the dirent structs to the calling
3128 error
= uiomove(rdc
->entries
, rdc
->entlen
, UIO_READ
, uiop
);
3131 * If no error occurred during the copyout,
3132 * update the offset in the uio struct to
3133 * contain the value of the next cookie
3134 * and set the eof value appropriately.
3137 uiop
->uio_offset
= rdc
->nfs_ncookie
;
3143 * Decide whether to do readahead. Don't if
3144 * have already read to the end of directory.
3148 mutex_exit(&rp
->r_statelock
);
3149 rddir_cache_rele(rdc
);
3151 rddir_cache_rele(nrdc
);
3156 * Check to see whether we found an entry
3157 * for the readahead. If so, we don't need
3158 * to do anything further, so free the new
3159 * entry if one was allocated. Otherwise,
3160 * allocate a new entry, add it to the cache,
3161 * and then initiate an asynchronous readdir
3162 * operation to fill it.
3164 srdc
.nfs_cookie
= rdc
->nfs_ncookie
;
3165 srdc
.buflen
= count
;
3166 rrdc
= avl_find(&rp
->r_dir
, &srdc
, &where
);
3169 rddir_cache_rele(nrdc
);
3174 rrdc
= rddir_cache_alloc(KM_NOSLEEP
);
3177 rrdc
->nfs_cookie
= rdc
->nfs_ncookie
;
3178 rrdc
->buflen
= count
;
3179 avl_insert(&rp
->r_dir
, rrdc
, where
);
3180 rddir_cache_hold(rrdc
);
3181 mutex_exit(&rp
->r_statelock
);
3182 rddir_cache_rele(rdc
);
3184 nfs_readdir_readahead
++;
3186 nfs_async_readdir(vp
, rrdc
, cr
, nfsreaddir
);
3191 mutex_exit(&rp
->r_statelock
);
3192 rddir_cache_rele(rdc
);
3197 * Didn't find an entry in the cache. Construct a new empty
3198 * entry and link it into the cache. Other processes attempting
3199 * to access this entry will need to wait until it is filled in.
3201 * Since kmem_alloc may block, another pass through the cache
3202 * will need to be taken to make sure that another process
3203 * hasn't already added an entry to the cache for this request.
3206 mutex_exit(&rp
->r_statelock
);
3207 nrdc
= rddir_cache_alloc(KM_SLEEP
);
3208 nrdc
->nfs_cookie
= uiop
->uio_offset
;
3209 nrdc
->buflen
= count
;
3214 * Add this entry to the cache.
3216 avl_insert(&rp
->r_dir
, nrdc
, where
);
3217 rddir_cache_hold(nrdc
);
3218 mutex_exit(&rp
->r_statelock
);
3223 nfs_readdir_cache_misses
++;
3228 error
= nfsreaddir(vp
, nrdc
, cr
);
3231 * If this operation failed, just return the error which occurred.
3237 * Since the RPC operation will have taken sometime and blocked
3238 * this process, another pass through the cache will need to be
3239 * taken to find the correct cache entry. It is possible that
3240 * the correct cache entry will not be there (although one was
3241 * added) because the directory changed during the RPC operation
3242 * and the readdir cache was flushed. In this case, just start
3243 * over. It is hoped that this will not happen too often... :-)
3251 nfsreaddir(vnode_t
*vp
, rddir_cache
*rdc
, cred_t
*cr
)
3254 struct nfsrddirargs rda
;
3255 struct nfsrddirres rd
;
3260 failinfo_t fi
, *fip
;
3262 ASSERT(nfs_zone() == VTOMI(vp
)->mi_zone
);
3263 count
= rdc
->buflen
;
3268 rda
.rda_fh
= *VTOFH(vp
);
3269 rda
.rda_offset
= rdc
->nfs_cookie
;
3272 * NFS client failover support
3273 * suppress failover unless we have a zero cookie
3275 if (rdc
->nfs_cookie
== (off_t
)0) {
3277 fi
.fhp
= (caddr_t
)&rda
.rda_fh
;
3278 fi
.copyproc
= nfscopyfh
;
3279 fi
.lookupproc
= nfslookup
;
3280 fi
.xattrdirproc
= acl_getxattrdir2
;
3286 rd
.rd_entries
= kmem_alloc(rdc
->buflen
, KM_SLEEP
);
3288 rd
.rd_offset
= rda
.rda_offset
;
3292 if (mi
->mi_io_kstats
) {
3293 mutex_enter(&mi
->mi_lock
);
3294 kstat_runq_enter(KSTAT_IO_PTR(mi
->mi_io_kstats
));
3295 mutex_exit(&mi
->mi_lock
);
3299 rda
.rda_count
= MIN(count
, mi
->mi_curread
);
3300 error
= rfs2call(mi
, RFS_READDIR
,
3301 xdr_rddirargs
, (caddr_t
)&rda
,
3302 xdr_getrddirres
, (caddr_t
)&rd
, cr
,
3303 &douprintf
, &rd
.rd_status
, 0, fip
);
3304 } while (error
== ENFS_TRYAGAIN
);
3306 if (mi
->mi_io_kstats
) {
3307 mutex_enter(&mi
->mi_lock
);
3308 kstat_runq_exit(KSTAT_IO_PTR(mi
->mi_io_kstats
));
3309 mutex_exit(&mi
->mi_lock
);
3313 * Since we are actually doing a READDIR RPC, we must have
3314 * exclusive access to the cache entry being filled. Thus,
3315 * it is safe to update all fields except for the flags
3316 * field. The r_statelock in the rnode must be held to
3317 * prevent two different threads from simultaneously
3318 * attempting to update the flags field. This can happen
3319 * if we are turning off RDDIR and the other thread is
3320 * trying to set RDDIRWAIT.
3322 ASSERT(rdc
->flags
& RDDIR
);
3324 error
= geterrno(rd
.rd_status
);
3326 rdc
->nfs_ncookie
= rd
.rd_offset
;
3327 rdc
->eof
= rd
.rd_eof
? 1 : 0;
3328 rdc
->entlen
= rd
.rd_size
;
3329 ASSERT(rdc
->entlen
<= rdc
->buflen
);
3331 rdc
->entries
= rddir_cache_buf_alloc(rdc
->buflen
,
3334 rdc
->entries
= kmem_alloc(rdc
->buflen
, KM_SLEEP
);
3336 bcopy(rd
.rd_entries
, rdc
->entries
, rdc
->entlen
);
3338 if (mi
->mi_io_kstats
) {
3339 mutex_enter(&mi
->mi_lock
);
3340 KSTAT_IO_PTR(mi
->mi_io_kstats
)->reads
++;
3341 KSTAT_IO_PTR(mi
->mi_io_kstats
)->nread
+=
3343 mutex_exit(&mi
->mi_lock
);
3346 PURGE_STALE_FH(error
, vp
, cr
);
3350 rdc
->entries
= NULL
;
3353 kmem_free(rd
.rd_entries
, rdc
->buflen
);
3355 mutex_enter(&rp
->r_statelock
);
3356 rdc
->flags
&= ~RDDIR
;
3357 if (rdc
->flags
& RDDIRWAIT
) {
3358 rdc
->flags
&= ~RDDIRWAIT
;
3359 cv_broadcast(&rdc
->cv
);
3362 rdc
->flags
|= RDDIRREQ
;
3363 mutex_exit(&rp
->r_statelock
);
3365 rddir_cache_rele(rdc
);
3371 static int nfs_bio_do_stop
= 0;
3375 nfs_bio(struct buf
*bp
, cred_t
*cr
)
3377 rnode_t
*rp
= VTOR(bp
->b_vp
);
3383 DTRACE_IO1(start
, struct buf
*, bp
);
3385 ASSERT(nfs_zone() == VTOMI(bp
->b_vp
)->mi_zone
);
3386 offset
= dbtob(bp
->b_blkno
);
3388 if (bp
->b_flags
& B_READ
) {
3389 mutex_enter(&rp
->r_statelock
);
3390 if (rp
->r_cred
!= NULL
) {
3399 mutex_exit(&rp
->r_statelock
);
3401 error
= bp
->b_error
= nfsread(bp
->b_vp
, bp
->b_un
.b_addr
,
3402 offset
, bp
->b_bcount
, &bp
->b_resid
, cred
);
3408 * Didn't get it all because we hit EOF,
3409 * zero all the memory beyond the EOF.
3411 /* bzero(rdaddr + */
3412 bzero(bp
->b_un
.b_addr
+
3413 bp
->b_bcount
- bp
->b_resid
, bp
->b_resid
);
3415 mutex_enter(&rp
->r_statelock
);
3416 if (bp
->b_resid
== bp
->b_bcount
&&
3417 offset
>= rp
->r_size
) {
3419 * We didn't read anything at all as we are
3420 * past EOF. Return an error indicator back
3421 * but don't destroy the pages (yet).
3425 mutex_exit(&rp
->r_statelock
);
3426 } else if (error
== EACCES
) {
3427 mutex_enter(&rp
->r_statelock
);
3429 if (rp
->r_cred
!= NULL
)
3435 mutex_exit(&rp
->r_statelock
);
3438 mutex_exit(&rp
->r_statelock
);
3441 if (!(rp
->r_flags
& RSTALE
)) {
3442 mutex_enter(&rp
->r_statelock
);
3443 if (rp
->r_cred
!= NULL
) {
3452 mutex_exit(&rp
->r_statelock
);
3454 mutex_enter(&rp
->r_statelock
);
3455 count
= MIN(bp
->b_bcount
, rp
->r_size
- offset
);
3456 mutex_exit(&rp
->r_statelock
);
3458 cmn_err(CE_PANIC
, "nfs_bio: write count < 0");
3461 zcmn_err(getzoneid(), CE_WARN
,
3462 "nfs_bio: zero length write at %d",
3464 nfs_printfhandle(&rp
->r_fh
);
3465 if (nfs_bio_do_stop
)
3466 debug_enter("nfs_bio");
3469 error
= nfswrite(bp
->b_vp
, bp
->b_un
.b_addr
, offset
,
3471 if (error
== EACCES
) {
3472 mutex_enter(&rp
->r_statelock
);
3474 if (rp
->r_cred
!= NULL
)
3481 mutex_exit(&rp
->r_statelock
);
3484 mutex_exit(&rp
->r_statelock
);
3486 bp
->b_error
= error
;
3487 if (error
&& error
!= EINTR
) {
3489 * Don't print EDQUOT errors on the console.
3490 * Don't print asynchronous EACCES errors.
3491 * Don't print EFBIG errors.
3492 * Print all other write errors.
3494 if (error
!= EDQUOT
&& error
!= EFBIG
&&
3496 !(bp
->b_flags
& B_ASYNC
)))
3497 nfs_write_error(bp
->b_vp
, error
, cred
);
3499 * Update r_error and r_flags as appropriate.
3500 * If the error was ESTALE, then mark the
3501 * rnode as not being writeable and save
3502 * the error status. Otherwise, save any
3503 * errors which occur from asynchronous
3504 * page invalidations. Any errors occurring
3505 * from other operations should be saved
3508 mutex_enter(&rp
->r_statelock
);
3509 if (error
== ESTALE
) {
3510 rp
->r_flags
|= RSTALE
;
3512 rp
->r_error
= error
;
3513 } else if (!rp
->r_error
&&
3515 (B_INVAL
|B_FORCE
|B_ASYNC
)) ==
3516 (B_INVAL
|B_FORCE
|B_ASYNC
)) {
3517 rp
->r_error
= error
;
3519 mutex_exit(&rp
->r_statelock
);
3523 error
= rp
->r_error
;
3525 * A close may have cleared r_error, if so,
3526 * propagate ESTALE error return properly
3533 if (error
!= 0 && error
!= NFS_EOF
)
3534 bp
->b_flags
|= B_ERROR
;
3536 DTRACE_IO1(done
, struct buf
*, bp
);
3543 nfs_fid(vnode_t
*vp
, fid_t
*fidp
, caller_context_t
*ct
)
3550 if (fidp
->fid_len
< (sizeof (struct nfs_fid
) - sizeof (short))) {
3551 fidp
->fid_len
= sizeof (struct nfs_fid
) - sizeof (short);
3554 fp
= (struct nfs_fid
*)fidp
;
3556 fp
->nf_len
= sizeof (struct nfs_fid
) - sizeof (short);
3557 bcopy(rp
->r_fh
.fh_buf
, fp
->nf_data
, NFS_FHSIZE
);
3563 nfs_rwlock(vnode_t
*vp
, int write_lock
, caller_context_t
*ctp
)
3565 rnode_t
*rp
= VTOR(vp
);
3568 (void) nfs_rw_enter_sig(&rp
->r_rwlock
, RW_READER
, FALSE
);
3569 return (V_WRITELOCK_FALSE
);
3572 if ((rp
->r_flags
& RDIRECTIO
) || (VTOMI(vp
)->mi_flags
& MI_DIRECTIO
)) {
3573 (void) nfs_rw_enter_sig(&rp
->r_rwlock
, RW_READER
, FALSE
);
3574 if (rp
->r_mapcnt
== 0 && !vn_has_cached_data(vp
))
3575 return (V_WRITELOCK_FALSE
);
3576 nfs_rw_exit(&rp
->r_rwlock
);
3579 (void) nfs_rw_enter_sig(&rp
->r_rwlock
, RW_WRITER
, FALSE
);
3580 return (V_WRITELOCK_TRUE
);
3585 nfs_rwunlock(vnode_t
*vp
, int write_lock
, caller_context_t
*ctp
)
3587 rnode_t
*rp
= VTOR(vp
);
3589 nfs_rw_exit(&rp
->r_rwlock
);
3594 nfs_seek(vnode_t
*vp
, offset_t ooff
, offset_t
*noffp
, caller_context_t
*ct
)
3598 * Because we stuff the readdir cookie into the offset field
3599 * someone may attempt to do an lseek with the cookie which
3600 * we want to succeed.
3602 if (vp
->v_type
== VDIR
)
3604 if (*noffp
< 0 || *noffp
> MAXOFF32_T
)
3610 * number of NFS_MAXDATA blocks to read ahead
3611 * optimized for 100 base-T.
3613 static int nfs_nra
= 4;
3616 static int nfs_lostpage
= 0; /* number of times we lost original page */
3620 * Return all the pages from [off..off+len) in file
3624 nfs_getpage(vnode_t
*vp
, offset_t off
, size_t len
, uint_t
*protp
,
3625 page_t
*pl
[], size_t plsz
, struct seg
*seg
, caddr_t addr
,
3626 enum seg_rw rw
, cred_t
*cr
, caller_context_t
*ct
)
3632 if (vp
->v_flag
& VNOMAP
)
3635 ASSERT(off
<= MAXOFF32_T
);
3636 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
3642 * Now valididate that the caches are up to date.
3644 error
= nfs_validate_caches(vp
, cr
);
3651 mutex_enter(&rp
->r_statelock
);
3654 * Don't create dirty pages faster than they
3655 * can be cleaned so that the system doesn't
3656 * get imbalanced. If the async queue is
3657 * maxed out, then wait for it to drain before
3658 * creating more dirty pages. Also, wait for
3659 * any threads doing pagewalks in the vop_getattr
3660 * entry points so that they don't block for
3663 if (rw
== S_CREATE
) {
3664 while ((mi
->mi_max_threads
!= 0 &&
3665 rp
->r_awcount
> 2 * mi
->mi_max_threads
) ||
3667 cv_wait(&rp
->r_cv
, &rp
->r_statelock
);
3671 * If we are getting called as a side effect of an nfs_write()
3672 * operation the local file size might not be extended yet.
3673 * In this case we want to be able to return pages of zeroes.
3675 if (off
+ len
> rp
->r_size
+ PAGEOFFSET
&& seg
!= segkmap
) {
3676 mutex_exit(&rp
->r_statelock
);
3677 return (EFAULT
); /* beyond EOF */
3680 mutex_exit(&rp
->r_statelock
);
3682 error
= pvn_getpages(nfs_getapage
, vp
, off
, len
, protp
, pl
, plsz
,
3687 nfs_purge_caches(vp
, NFS_NOPURGE_DNLC
, cr
);
3690 PURGE_STALE_FH(error
, vp
, cr
);
3697 * Called from pvn_getpages to get a particular page.
3701 nfs_getapage(vnode_t
*vp
, uoff_t off
, size_t len
, uint_t
*protp
,
3702 page_t
*pl
[], size_t plsz
, struct seg
*seg
, caddr_t addr
,
3703 enum seg_rw rw
, cred_t
*cr
)
3717 int readahead_issued
= 0;
3718 int ra_window
; /* readahead window */
3721 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
3724 bsize
= MAX(vp
->v_vfsp
->vfs_bsize
, PAGESIZE
);
3736 blkoff
= lbn
* bsize
;
3739 * Queueing up the readahead before doing the synchronous read
3740 * results in a significant increase in read throughput because
3741 * of the increased parallelism between the async threads and
3742 * the process context.
3744 if ((off
& ((vp
->v_vfsp
->vfs_bsize
) - 1)) == 0 &&
3746 !(vp
->v_flag
& VNOCACHE
)) {
3747 mutex_enter(&rp
->r_statelock
);
3750 * Calculate the number of readaheads to do.
3751 * a) No readaheads at offset = 0.
3752 * b) Do maximum(nfs_nra) readaheads when the readahead
3754 * c) Do readaheads between 1 to (nfs_nra - 1) depending
3755 * upon how far the readahead window is open or close.
3756 * d) No readaheads if rp->r_nextr is not within the scope
3757 * of the readahead window (random i/o).
3762 else if (blkoff
== rp
->r_nextr
)
3763 readahead
= nfs_nra
;
3764 else if (rp
->r_nextr
> blkoff
&&
3765 ((ra_window
= (rp
->r_nextr
- blkoff
) / bsize
)
3767 readahead
= nfs_nra
- ra_window
;
3771 rablkoff
= rp
->r_nextr
;
3772 while (readahead
> 0 && rablkoff
+ bsize
< rp
->r_size
) {
3773 mutex_exit(&rp
->r_statelock
);
3774 if (nfs_async_readahead(vp
, rablkoff
+ bsize
,
3775 addr
+ (rablkoff
+ bsize
- off
), seg
, cr
,
3776 nfs_readahead
) < 0) {
3777 mutex_enter(&rp
->r_statelock
);
3783 * Indicate that we did a readahead so
3784 * readahead offset is not updated
3785 * by the synchronous read below.
3787 readahead_issued
= 1;
3788 mutex_enter(&rp
->r_statelock
);
3790 * set readahead offset to
3791 * offset of last async readahead
3794 rp
->r_nextr
= rablkoff
;
3796 mutex_exit(&rp
->r_statelock
);
3800 if ((pagefound
= page_exists(&vp
->v_object
, off
)) == NULL
) {
3802 (void) nfs_async_readahead(vp
, blkoff
, addr
, seg
, cr
,
3804 } else if (rw
== S_CREATE
) {
3806 * Block for this page is not allocated, or the offset
3807 * is beyond the current allocation size, or we're
3808 * allocating a swap slot and the page was not found,
3809 * so allocate it and return a zero page.
3811 if ((pp
= page_create_va(&vp
->v_object
, off
,
3812 PAGESIZE
, PG_WAIT
, seg
, addr
)) == NULL
)
3813 cmn_err(CE_PANIC
, "nfs_getapage: page_create");
3815 mutex_enter(&rp
->r_statelock
);
3816 rp
->r_nextr
= off
+ PAGESIZE
;
3817 mutex_exit(&rp
->r_statelock
);
3820 * Need to go to server to get a BLOCK, exception to
3821 * that being while reading at offset = 0 or doing
3822 * random i/o, in that case read only a PAGE.
3824 mutex_enter(&rp
->r_statelock
);
3825 if (blkoff
< rp
->r_size
&&
3826 blkoff
+ bsize
>= rp
->r_size
) {
3828 * If only a block or less is left in
3829 * the file, read all that is remaining.
3831 if (rp
->r_size
<= off
) {
3833 * Trying to access beyond EOF,
3834 * set up to get at least one page.
3836 blksize
= off
+ PAGESIZE
- blkoff
;
3838 blksize
= rp
->r_size
- blkoff
;
3839 } else if ((off
== 0) ||
3840 (off
!= rp
->r_nextr
&& !readahead_issued
)) {
3842 blkoff
= off
; /* block = page here */
3845 mutex_exit(&rp
->r_statelock
);
3847 pp
= pvn_read_kluster(vp
, off
, seg
, addr
, &io_off
,
3848 &io_len
, blkoff
, blksize
, 0);
3851 * Some other thread has entered the page,
3858 * Now round the request size up to page boundaries.
3859 * This ensures that the entire page will be
3860 * initialized to zeroes if EOF is encountered.
3862 io_len
= ptob(btopr(io_len
));
3864 bp
= pageio_setup(pp
, io_len
, vp
, B_READ
);
3868 * pageio_setup should have set b_addr to 0. This
3869 * is correct since we want to do I/O on a page
3870 * boundary. bp_mapin will use this addr to calculate
3871 * an offset, and then set b_addr to the kernel virtual
3872 * address it allocated for us.
3874 ASSERT(bp
->b_un
.b_addr
== 0);
3878 bp
->b_lblkno
= lbtodb(io_off
);
3880 bp
->b_offset
= (offset_t
)off
;
3884 * If doing a write beyond what we believe is EOF,
3885 * don't bother trying to read the pages from the
3886 * server, we'll just zero the pages here. We
3887 * don't check that the rw flag is S_WRITE here
3888 * because some implementations may attempt a
3889 * read access to the buffer before copying data.
3891 mutex_enter(&rp
->r_statelock
);
3892 if (io_off
>= rp
->r_size
&& seg
== segkmap
) {
3893 mutex_exit(&rp
->r_statelock
);
3894 bzero(bp
->b_un
.b_addr
, io_len
);
3896 mutex_exit(&rp
->r_statelock
);
3897 error
= nfs_bio(bp
, cr
);
3901 * Unmap the buffer before freeing it.
3906 if (error
== NFS_EOF
) {
3908 * If doing a write system call just return
3909 * zeroed pages, else user tried to get pages
3910 * beyond EOF, return error. We don't check
3911 * that the rw flag is S_WRITE here because
3912 * some implementations may attempt a read
3913 * access to the buffer before copying data.
3921 if (!readahead_issued
&& !error
) {
3922 mutex_enter(&rp
->r_statelock
);
3923 rp
->r_nextr
= io_off
+ io_len
;
3924 mutex_exit(&rp
->r_statelock
);
3935 pvn_read_done(pp
, B_ERROR
);
3940 se_t se
= (rw
== S_CREATE
? SE_EXCL
: SE_SHARED
);
3943 * Page exists in the cache, acquire the appropriate lock.
3944 * If this fails, start all over again.
3946 if ((pp
= page_lookup(&vp
->v_object
, off
, se
)) == NULL
) {
3958 pvn_plist_init(pp
, pl
, plsz
, off
, io_len
, rw
);
3964 nfs_readahead(vnode_t
*vp
, uoff_t blkoff
, caddr_t addr
, struct seg
*seg
,
3972 uint_t bsize
, blksize
;
3973 rnode_t
*rp
= VTOR(vp
);
3975 ASSERT(nfs_zone() == VTOMI(vp
)->mi_zone
);
3977 bsize
= MAX(vp
->v_vfsp
->vfs_bsize
, PAGESIZE
);
3979 mutex_enter(&rp
->r_statelock
);
3980 if (blkoff
< rp
->r_size
&& blkoff
+ bsize
> rp
->r_size
) {
3982 * If less than a block left in file read less
3985 blksize
= rp
->r_size
- blkoff
;
3988 mutex_exit(&rp
->r_statelock
);
3990 pp
= pvn_read_kluster(vp
, blkoff
, segkmap
, addr
,
3991 &io_off
, &io_len
, blkoff
, blksize
, 1);
3993 * The isra flag passed to the kluster function is 1, we may have
3994 * gotten a return value of NULL for a variety of reasons (# of free
3995 * pages < minfree, someone entered the page on the vnode etc). In all
3996 * cases, we want to punt on the readahead.
4002 * Now round the request size up to page boundaries.
4003 * This ensures that the entire page will be
4004 * initialized to zeroes if EOF is encountered.
4006 io_len
= ptob(btopr(io_len
));
4008 bp
= pageio_setup(pp
, io_len
, vp
, B_READ
);
4012 * pageio_setup should have set b_addr to 0. This is correct since
4013 * we want to do I/O on a page boundary. bp_mapin() will use this addr
4014 * to calculate an offset, and then set b_addr to the kernel virtual
4015 * address it allocated for us.
4017 ASSERT(bp
->b_un
.b_addr
== 0);
4021 bp
->b_lblkno
= lbtodb(io_off
);
4023 bp
->b_offset
= (offset_t
)blkoff
;
4027 * If doing a write beyond what we believe is EOF, don't bother trying
4028 * to read the pages from the server, we'll just zero the pages here.
4029 * We don't check that the rw flag is S_WRITE here because some
4030 * implementations may attempt a read access to the buffer before
4033 mutex_enter(&rp
->r_statelock
);
4034 if (io_off
>= rp
->r_size
&& seg
== segkmap
) {
4035 mutex_exit(&rp
->r_statelock
);
4036 bzero(bp
->b_un
.b_addr
, io_len
);
4039 mutex_exit(&rp
->r_statelock
);
4040 error
= nfs_bio(bp
, cr
);
4041 if (error
== NFS_EOF
)
4046 * Unmap the buffer before freeing it.
4051 pvn_read_done(pp
, error
? B_READ
| B_ERROR
: B_READ
);
4054 * In case of error set readahead offset
4055 * to the lowest offset.
4056 * pvn_read_done() calls VN_DISPOSE to destroy the pages
4058 if (error
&& rp
->r_nextr
> io_off
) {
4059 mutex_enter(&rp
->r_statelock
);
4060 if (rp
->r_nextr
> io_off
)
4061 rp
->r_nextr
= io_off
;
4062 mutex_exit(&rp
->r_statelock
);
4067 * Flags are composed of {B_INVAL, B_FREE, B_DONTNEED, B_FORCE}
4068 * If len == 0, do from off to EOF.
4070 * The normal cases should be len == 0 && off == 0 (entire vp list),
4071 * len == MAXBSIZE (from segmap_release actions), and len == PAGESIZE
4076 nfs_putpage(vnode_t
*vp
, offset_t off
, size_t len
, int flags
, cred_t
*cr
,
4077 caller_context_t
*ct
)
4085 * XXX - Why should this check be made here?
4087 if (vp
->v_flag
& VNOMAP
)
4090 if (len
== 0 && !(flags
& B_INVAL
) && vn_is_readonly(vp
))
4093 if (!(flags
& B_ASYNC
) && nfs_zone() != VTOMI(vp
)->mi_zone
)
4095 ASSERT(off
<= MAXOFF32_T
);
4098 mutex_enter(&rp
->r_statelock
);
4100 mutex_exit(&rp
->r_statelock
);
4101 error
= nfs_putpages(vp
, off
, len
, flags
, cr
);
4102 mutex_enter(&rp
->r_statelock
);
4104 cv_broadcast(&rp
->r_cv
);
4105 mutex_exit(&rp
->r_statelock
);
4111 * Write out a single page, possibly klustering adjacent dirty pages.
4114 nfs_putapage(vnode_t
*vp
, page_t
*pp
, uoff_t
*offp
, size_t *lenp
,
4115 int flags
, cred_t
*cr
)
4125 ASSERT(!vn_is_readonly(vp
));
4128 ASSERT((flags
& B_ASYNC
) || nfs_zone() == VTOMI(vp
)->mi_zone
);
4131 ASSERT(rp
->r_count
> 0);
4133 ASSERT(pp
->p_offset
<= MAXOFF32_T
);
4135 bsize
= MAX(vp
->v_vfsp
->vfs_bsize
, PAGESIZE
);
4136 lbn
= pp
->p_offset
/ bsize
;
4137 lbn_off
= lbn
* bsize
;
4140 * Find a kluster that fits in one block, or in
4141 * one page if pages are bigger than blocks. If
4142 * there is less file space allocated than a whole
4143 * page, we'll shorten the i/o request below.
4145 pp
= pvn_write_kluster(vp
, pp
, &io_off
, &io_len
, lbn_off
,
4146 roundup(bsize
, PAGESIZE
), flags
);
4149 * pvn_write_kluster shouldn't have returned a page with offset
4150 * behind the original page we were given. Verify that.
4152 ASSERT((pp
->p_offset
/ bsize
) >= lbn
);
4155 * Now pp will have the list of kept dirty pages marked for
4156 * write back. It will also handle invalidation and freeing
4157 * of pages that are not dirty. Check for page length rounding
4160 if (io_off
+ io_len
> lbn_off
+ bsize
) {
4161 ASSERT((io_off
+ io_len
) - (lbn_off
+ bsize
) < PAGESIZE
);
4162 io_len
= lbn_off
+ bsize
- io_off
;
4165 * The RMODINPROGRESS flag makes sure that nfs(3)_bio() sees a
4166 * consistent value of r_size. RMODINPROGRESS is set in writerp().
4167 * When RMODINPROGRESS is set it indicates that a uiomove() is in
4168 * progress and the r_size has not been made consistent with the
4169 * new size of the file. When the uiomove() completes the r_size is
4170 * updated and the RMODINPROGRESS flag is cleared.
4172 * The RMODINPROGRESS flag makes sure that nfs(3)_bio() sees a
4173 * consistent value of r_size. Without this handshaking, it is
4174 * possible that nfs(3)_bio() picks up the old value of r_size
4175 * before the uiomove() in writerp() completes. This will result
4176 * in the write through nfs(3)_bio() being dropped.
4178 * More precisely, there is a window between the time the uiomove()
4179 * completes and the time the r_size is updated. If a fop_putpage()
4180 * operation intervenes in this window, the page will be picked up,
4181 * because it is dirty (it will be unlocked, unless it was
4182 * pagecreate'd). When the page is picked up as dirty, the dirty
4183 * bit is reset (pvn_getdirty()). In nfs(3)write(), r_size is
4184 * checked. This will still be the old size. Therefore the page will
4185 * not be written out. When segmap_release() calls fop_putpage(),
4186 * the page will be found to be clean and the write will be dropped.
4188 if (rp
->r_flags
& RMODINPROGRESS
) {
4189 mutex_enter(&rp
->r_statelock
);
4190 if ((rp
->r_flags
& RMODINPROGRESS
) &&
4191 rp
->r_modaddr
+ MAXBSIZE
> io_off
&&
4192 rp
->r_modaddr
< io_off
+ io_len
) {
4195 * A write is in progress for this region of the file.
4196 * If we did not detect RMODINPROGRESS here then this
4197 * path through nfs_putapage() would eventually go to
4198 * nfs(3)_bio() and may not write out all of the data
4199 * in the pages. We end up losing data. So we decide
4200 * to set the modified bit on each page in the page
4201 * list and mark the rnode with RDIRTY. This write
4202 * will be restarted at some later time.
4205 while (plist
!= NULL
) {
4207 page_sub(&plist
, pp
);
4212 rp
->r_flags
|= RDIRTY
;
4213 mutex_exit(&rp
->r_statelock
);
4220 mutex_exit(&rp
->r_statelock
);
4223 if (flags
& B_ASYNC
) {
4224 error
= nfs_async_putapage(vp
, pp
, io_off
, io_len
, flags
, cr
,
4227 error
= nfs_sync_putapage(vp
, pp
, io_off
, io_len
, flags
, cr
);
4237 nfs_sync_putapage(vnode_t
*vp
, page_t
*pp
, uoff_t io_off
, size_t io_len
,
4238 int flags
, cred_t
*cr
)
4245 ASSERT(nfs_zone() == VTOMI(vp
)->mi_zone
);
4246 error
= nfs_rdwrlbn(vp
, pp
, io_off
, io_len
, flags
, cr
);
4250 if ((error
== ENOSPC
|| error
== EDQUOT
|| error
== EACCES
) &&
4251 (flags
& (B_INVAL
|B_FORCE
)) != (B_INVAL
|B_FORCE
)) {
4252 if (!(rp
->r_flags
& ROUTOFSPACE
)) {
4253 mutex_enter(&rp
->r_statelock
);
4254 rp
->r_flags
|= ROUTOFSPACE
;
4255 mutex_exit(&rp
->r_statelock
);
4258 pvn_write_done(pp
, flags
);
4260 * If this was not an async thread, then try again to
4261 * write out the pages, but this time, also destroy
4262 * them whether or not the write is successful. This
4263 * will prevent memory from filling up with these
4264 * pages and destroying them is the only alternative
4265 * if they can't be written out.
4267 * Don't do this if this is an async thread because
4268 * when the pages are unlocked in pvn_write_done,
4269 * some other thread could have come along, locked
4270 * them, and queued for an async thread. It would be
4271 * possible for all of the async threads to be tied
4272 * up waiting to lock the pages again and they would
4273 * all already be locked and waiting for an async
4274 * thread to handle them. Deadlock.
4276 if (!(flags
& B_ASYNC
)) {
4277 error
= nfs_putpage(vp
, io_off
, io_len
,
4278 B_INVAL
| B_FORCE
, cr
, NULL
);
4283 else if (rp
->r_flags
& ROUTOFSPACE
) {
4284 mutex_enter(&rp
->r_statelock
);
4285 rp
->r_flags
&= ~ROUTOFSPACE
;
4286 mutex_exit(&rp
->r_statelock
);
4288 pvn_write_done(pp
, flags
);
4296 nfs_map(vnode_t
*vp
, offset_t off
, struct as
*as
, caddr_t
*addrp
,
4297 size_t len
, uchar_t prot
, uchar_t maxprot
, uint_t flags
, cred_t
*cr
,
4298 caller_context_t
*ct
)
4300 struct segvn_crargs vn_a
;
4305 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
4308 if (vp
->v_flag
& VNOMAP
)
4311 if (off
> MAXOFF32_T
)
4314 if (off
< 0 || off
+ len
< 0)
4317 if (vp
->v_type
!= VREG
)
4321 * If there is cached data and if close-to-open consistency
4322 * checking is not turned off and if the file system is not
4323 * mounted readonly, then force an over the wire getattr.
4324 * Otherwise, just invoke nfsgetattr to get a copy of the
4325 * attributes. The attribute cache will be used unless it
4326 * is timed out and if it is, then an over the wire getattr
4329 va
.va_mask
= AT_ALL
;
4330 if (vn_has_cached_data(vp
) &&
4331 !(VTOMI(vp
)->mi_flags
& MI_NOCTO
) && !vn_is_readonly(vp
))
4332 error
= nfs_getattr_otw(vp
, &va
, cr
);
4334 error
= nfsgetattr(vp
, &va
, cr
);
4339 * Check to see if the vnode is currently marked as not cachable.
4340 * This means portions of the file are locked (through fop_frlock).
4341 * In this case the map request must be refused. We use
4342 * rp->r_lkserlock to avoid a race with concurrent lock requests.
4347 * Atomically increment r_inmap after acquiring r_rwlock. The
4348 * idea here is to acquire r_rwlock to block read/write and
4349 * not to protect r_inmap. r_inmap will inform nfs_read/write()
4350 * that we are in nfs_map(). Now, r_rwlock is acquired in order
4351 * and we can prevent the deadlock that would have occurred
4352 * when nfs_addmap() would have acquired it out of order.
4354 * Since we are not protecting r_inmap by any lock, we do not
4355 * hold any lock when we decrement it. We atomically decrement
4356 * r_inmap after we release r_lkserlock.
4359 if (nfs_rw_enter_sig(&rp
->r_rwlock
, RW_WRITER
, INTR(vp
)))
4361 atomic_inc_uint(&rp
->r_inmap
);
4362 nfs_rw_exit(&rp
->r_rwlock
);
4364 if (nfs_rw_enter_sig(&rp
->r_lkserlock
, RW_READER
, INTR(vp
))) {
4365 atomic_dec_uint(&rp
->r_inmap
);
4368 if (vp
->v_flag
& VNOCACHE
) {
4374 * Don't allow concurrent locks and mapping if mandatory locking is
4377 if ((flk_has_remote_locks(vp
) || lm_has_sleep(vp
)) &&
4378 MANDLOCK(vp
, va
.va_mode
)) {
4384 error
= choose_addr(as
, addrp
, len
, off
, ADDR_VACALIGN
, flags
);
4392 vn_a
.type
= (flags
& MAP_TYPE
);
4393 vn_a
.prot
= (uchar_t
)prot
;
4394 vn_a
.maxprot
= (uchar_t
)maxprot
;
4395 vn_a
.flags
= (flags
& ~MAP_TYPE
);
4399 vn_a
.lgrp_mem_policy_flags
= 0;
4401 error
= as_map(as
, *addrp
, len
, segvn_create
, &vn_a
);
4405 nfs_rw_exit(&rp
->r_lkserlock
);
4406 atomic_dec_uint(&rp
->r_inmap
);
4412 nfs_addmap(vnode_t
*vp
, offset_t off
, struct as
*as
, caddr_t addr
,
4413 size_t len
, uchar_t prot
, uchar_t maxprot
, uint_t flags
, cred_t
*cr
,
4414 caller_context_t
*ct
)
4418 if (vp
->v_flag
& VNOMAP
)
4420 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
4424 atomic_add_long((ulong_t
*)&rp
->r_mapcnt
, btopr(len
));
4431 nfs_frlock(vnode_t
*vp
, int cmd
, struct flock64
*bfp
, int flag
, offset_t offset
,
4432 struct flk_callback
*flk_cbp
, cred_t
*cr
, caller_context_t
*ct
)
4438 int error
= 0, intr
= INTR(vp
);
4440 /* check for valid cmd parameter */
4441 if (cmd
!= F_GETLK
&& cmd
!= F_SETLK
&& cmd
!= F_SETLKW
)
4443 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
4446 /* Verify l_type. */
4447 switch (bfp
->l_type
) {
4449 if (cmd
!= F_GETLK
&& !(flag
& FREAD
))
4453 if (cmd
!= F_GETLK
&& !(flag
& FWRITE
))
4464 /* check the validity of the lock range */
4465 if (rc
= flk_convert_lock_data(vp
, bfp
, &start
, &end
, offset
))
4467 if (rc
= flk_check_lock_data(start
, end
, MAXOFF32_T
))
4471 * If the filesystem is mounted using local locking, pass the
4472 * request off to the local locking code.
4474 if (VTOMI(vp
)->mi_flags
& MI_LLOCK
) {
4475 if (offset
> MAXOFF32_T
)
4477 if (cmd
== F_SETLK
|| cmd
== F_SETLKW
) {
4479 * For complete safety, we should be holding
4480 * r_lkserlock. However, we can't call
4481 * lm_safelock and then fs_frlock while
4482 * holding r_lkserlock, so just invoke
4483 * lm_safelock and expect that this will
4484 * catch enough of the cases.
4486 if (!lm_safelock(vp
, bfp
, cr
))
4489 return (fs_frlock(vp
, cmd
, bfp
, flag
, offset
, flk_cbp
, cr
, ct
));
4495 * Check whether the given lock request can proceed, given the
4496 * current file mappings.
4498 if (nfs_rw_enter_sig(&rp
->r_lkserlock
, RW_WRITER
, intr
))
4500 if (cmd
== F_SETLK
|| cmd
== F_SETLKW
) {
4501 if (!lm_safelock(vp
, bfp
, cr
)) {
4508 * Flush the cache after waiting for async I/O to finish. For new
4509 * locks, this is so that the process gets the latest bits from the
4510 * server. For unlocks, this is so that other clients see the
4511 * latest bits once the file has been unlocked. If currently dirty
4512 * pages can't be flushed, then don't allow a lock to be set. But
4513 * allow unlocks to succeed, to avoid having orphan locks on the
4516 if (cmd
!= F_GETLK
) {
4517 mutex_enter(&rp
->r_statelock
);
4518 while (rp
->r_count
> 0) {
4520 klwp_t
*lwp
= ttolwp(curthread
);
4524 if (cv_wait_sig(&rp
->r_cv
, &rp
->r_statelock
)
4534 cv_wait(&rp
->r_cv
, &rp
->r_statelock
);
4536 mutex_exit(&rp
->r_statelock
);
4539 error
= nfs_putpage(vp
, 0, 0, B_INVAL
, cr
, ct
);
4541 if (error
== ENOSPC
|| error
== EDQUOT
) {
4542 mutex_enter(&rp
->r_statelock
);
4544 rp
->r_error
= error
;
4545 mutex_exit(&rp
->r_statelock
);
4547 if (bfp
->l_type
!= F_UNLCK
) {
4554 lm_fh
.n_len
= sizeof (fhandle_t
);
4555 lm_fh
.n_bytes
= (char *)VTOFH(vp
);
4558 * Call the lock manager to do the real work of contacting
4559 * the server and obtaining the lock.
4561 rc
= lm_frlock(vp
, cmd
, bfp
, flag
, offset
, cr
, &lm_fh
, flk_cbp
);
4564 nfs_lockcompletion(vp
, cmd
);
4567 nfs_rw_exit(&rp
->r_lkserlock
);
4572 * Free storage space associated with the specified vnode. The portion
4573 * to be freed is specified by bfp->l_start and bfp->l_len (already
4574 * normalized to a "whence" of 0).
4576 * This is an experimental facility whose continued existence is not
4577 * guaranteed. Currently, we only support the special case
4578 * of l_len == 0, meaning free to end of file.
4582 nfs_space(vnode_t
*vp
, int cmd
, struct flock64
*bfp
, int flag
,
4583 offset_t offset
, cred_t
*cr
, caller_context_t
*ct
)
4587 ASSERT(vp
->v_type
== VREG
);
4588 if (cmd
!= F_FREESP
)
4591 if (offset
> MAXOFF32_T
)
4594 if ((bfp
->l_start
> MAXOFF32_T
) || (bfp
->l_end
> MAXOFF32_T
) ||
4595 (bfp
->l_len
> MAXOFF32_T
))
4598 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
4601 error
= convoff(vp
, bfp
, 0, offset
);
4603 ASSERT(bfp
->l_start
>= 0);
4604 if (bfp
->l_len
== 0) {
4608 * ftruncate should not change the ctime and
4609 * mtime if we truncate the file to its
4612 va
.va_mask
= AT_SIZE
;
4613 error
= nfsgetattr(vp
, &va
, cr
);
4614 if (error
|| va
.va_size
== bfp
->l_start
)
4616 va
.va_mask
= AT_SIZE
;
4617 va
.va_size
= bfp
->l_start
;
4618 error
= nfssetattr(vp
, &va
, 0, cr
);
4620 if (error
== 0 && bfp
->l_start
== 0)
4621 vnevent_truncate(vp
, ct
);
4631 nfs_realvp(vnode_t
*vp
, vnode_t
**vpp
, caller_context_t
*ct
)
4638 * Setup and add an address space callback to do the work of the delmap call.
4639 * The callback will (and must be) deleted in the actual callback function.
4641 * This is done in order to take care of the problem that we have with holding
4642 * the address space's a_lock for a long period of time (e.g. if the NFS server
4643 * is down). Callbacks will be executed in the address space code while the
4644 * a_lock is not held. Holding the address space's a_lock causes things such
4645 * as ps and fork to hang because they are trying to acquire this lock as well.
4649 nfs_delmap(vnode_t
*vp
, offset_t off
, struct as
*as
, caddr_t addr
,
4650 size_t len
, uint_t prot
, uint_t maxprot
, uint_t flags
, cred_t
*cr
,
4651 caller_context_t
*ct
)
4656 nfs_delmap_args_t
*dmapp
;
4657 nfs_delmapcall_t
*delmap_call
;
4659 if (vp
->v_flag
& VNOMAP
)
4662 * A process may not change zones if it has NFS pages mmap'ed
4663 * in, so we can't legitimately get here from the wrong zone.
4665 ASSERT(nfs_zone() == VTOMI(vp
)->mi_zone
);
4670 * The way that the address space of this process deletes its mapping
4671 * of this file is via the following call chains:
4672 * - as_free()->segop_unmap()/segvn_unmap()->fop_delmap()/nfs_delmap()
4673 * - as_unmap()->segop_unmap()/segvn_unmap()->fop_delmap()/nfs_delmap()
4675 * With the use of address space callbacks we are allowed to drop the
4676 * address space lock, a_lock, while executing the NFS operations that
4677 * need to go over the wire. Returning EAGAIN to the caller of this
4678 * function is what drives the execution of the callback that we add
4679 * below. The callback will be executed by the address space code
4680 * after dropping the a_lock. When the callback is finished, since
4681 * we dropped the a_lock, it must be re-acquired and segvn_unmap()
4682 * is called again on the same segment to finish the rest of the work
4683 * that needs to happen during unmapping.
4685 * This action of calling back into the segment driver causes
4686 * nfs_delmap() to get called again, but since the callback was
4687 * already executed at this point, it already did the work and there
4688 * is nothing left for us to do.
4691 * - The first time nfs_delmap is called by the current thread is when
4692 * we add the caller associated with this delmap to the delmap caller
4693 * list, add the callback, and return EAGAIN.
4694 * - The second time in this call chain when nfs_delmap is called we
4695 * will find this caller in the delmap caller list and realize there
4696 * is no more work to do thus removing this caller from the list and
4697 * returning the error that was set in the callback execution.
4699 caller_found
= nfs_find_and_delete_delmapcall(rp
, &error
);
4702 * 'error' is from the actual delmap operations. To avoid
4703 * hangs, we need to handle the return of EAGAIN differently
4704 * since this is what drives the callback execution.
4705 * In this case, we don't want to return EAGAIN and do the
4706 * callback execution because there are none to execute.
4708 if (error
== EAGAIN
)
4714 /* current caller was not in the list */
4715 delmap_call
= nfs_init_delmapcall();
4717 mutex_enter(&rp
->r_statelock
);
4718 list_insert_tail(&rp
->r_indelmap
, delmap_call
);
4719 mutex_exit(&rp
->r_statelock
);
4721 dmapp
= kmem_alloc(sizeof (nfs_delmap_args_t
), KM_SLEEP
);
4728 dmapp
->maxprot
= maxprot
;
4729 dmapp
->flags
= flags
;
4731 dmapp
->caller
= delmap_call
;
4733 error
= as_add_callback(as
, nfs_delmap_callback
, dmapp
,
4734 AS_UNMAP_EVENT
, addr
, len
, KM_SLEEP
);
4736 return (error
? error
: EAGAIN
);
4740 * Remove some pages from an mmap'd vnode. Just update the
4741 * count of pages. If doing close-to-open, then flush all
4742 * of the pages associated with this file. Otherwise, start
4743 * an asynchronous page flush to write out any dirty pages.
4744 * This will also associate a credential with the rnode which
4745 * can be used to write the pages.
4749 nfs_delmap_callback(struct as
*as
, void *arg
, uint_t event
)
4754 nfs_delmap_args_t
*dmapp
= (nfs_delmap_args_t
*)arg
;
4756 rp
= VTOR(dmapp
->vp
);
4757 mi
= VTOMI(dmapp
->vp
);
4759 atomic_add_long((ulong_t
*)&rp
->r_mapcnt
, -btopr(dmapp
->len
));
4760 ASSERT(rp
->r_mapcnt
>= 0);
4763 * Initiate a page flush if there are pages, the file system
4764 * was not mounted readonly, the segment was mapped shared, and
4765 * the pages themselves were writeable.
4767 if (vn_has_cached_data(dmapp
->vp
) && !vn_is_readonly(dmapp
->vp
) &&
4768 dmapp
->flags
== MAP_SHARED
&& (dmapp
->maxprot
& PROT_WRITE
)) {
4769 mutex_enter(&rp
->r_statelock
);
4770 rp
->r_flags
|= RDIRTY
;
4771 mutex_exit(&rp
->r_statelock
);
4773 * If this is a cross-zone access a sync putpage won't work, so
4774 * the best we can do is try an async putpage. That seems
4775 * better than something more draconian such as discarding the
4778 if ((mi
->mi_flags
& MI_NOCTO
) ||
4779 nfs_zone() != mi
->mi_zone
)
4780 error
= nfs_putpage(dmapp
->vp
, dmapp
->off
, dmapp
->len
,
4781 B_ASYNC
, dmapp
->cr
, NULL
);
4783 error
= nfs_putpage(dmapp
->vp
, dmapp
->off
, dmapp
->len
,
4784 0, dmapp
->cr
, NULL
);
4786 mutex_enter(&rp
->r_statelock
);
4787 error
= rp
->r_error
;
4789 mutex_exit(&rp
->r_statelock
);
4794 if ((rp
->r_flags
& RDIRECTIO
) || (mi
->mi_flags
& MI_DIRECTIO
))
4795 (void) nfs_putpage(dmapp
->vp
, dmapp
->off
, dmapp
->len
,
4796 B_INVAL
, dmapp
->cr
, NULL
);
4798 dmapp
->caller
->error
= error
;
4799 (void) as_delete_callback(as
, arg
);
4800 kmem_free(dmapp
, sizeof (nfs_delmap_args_t
));
4805 nfs_pathconf(vnode_t
*vp
, int cmd
, ulong_t
*valp
, cred_t
*cr
,
4806 caller_context_t
*ct
)
4810 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
4813 * This looks a little weird because it's written in a general
4814 * manner but we make little use of cases. If cntl() ever gets
4815 * widely used, the outer switch will make more sense.
4821 * Large file spec - need to base answer new query with
4822 * hardcoded constant based on the protocol.
4824 case _PC_FILESIZEBITS
:
4831 case _PC_SYMLINK_MAX
:
4832 case _PC_CHOWN_RESTRICTED
:
4833 case _PC_NO_TRUNC
: {
4837 if ((mi
= VTOMI(vp
)) == NULL
|| (pc
= mi
->mi_pathconf
) == NULL
)
4839 error
= _PC_ISSET(cmd
, pc
->pc_mask
); /* error or bool */
4842 *valp
= pc
->pc_link_max
;
4845 *valp
= pc
->pc_name_max
;
4848 case _PC_SYMLINK_MAX
:
4849 *valp
= pc
->pc_path_max
;
4851 case _PC_CHOWN_RESTRICTED
:
4853 * if we got here, error is really a boolean which
4854 * indicates whether cmd is set or not.
4856 *valp
= error
? 1 : 0; /* see above */
4861 * if we got here, error is really a boolean which
4862 * indicates whether cmd is set or not.
4864 *valp
= error
? 1 : 0; /* see above */
4868 return (error
? EINVAL
: 0);
4871 case _PC_XATTR_EXISTS
:
4873 if (vp
->v_vfsp
->vfs_flag
& VFS_XATTR
) {
4876 mntinfo_t
*mi
= VTOMI(vp
);
4878 if (!(mi
->mi_flags
& MI_EXTATTR
))
4882 if (nfs_rw_enter_sig(&rp
->r_rwlock
, RW_READER
,
4886 error
= nfslookup_dnlc(vp
, XATTR_DIR_NAME
, &avp
, cr
);
4887 if (error
|| avp
== NULL
)
4888 error
= acl_getxattrdir2(vp
, &avp
, 0, cr
, 0);
4890 nfs_rw_exit(&rp
->r_rwlock
);
4892 if (error
== 0 && avp
!= NULL
) {
4893 error
= do_xattr_exists_check(avp
, valp
, cr
);
4897 return (error
? EINVAL
: 0);
4899 case _PC_ACL_ENABLED
:
4900 *valp
= _ACL_ACLENT_ENABLED
;
4909 * Called by async thread to do synchronous pageio. Do the i/o, wait
4910 * for it to complete, and cleanup the page list when done.
4913 nfs_sync_pageio(vnode_t
*vp
, page_t
*pp
, uoff_t io_off
, size_t io_len
,
4914 int flags
, cred_t
*cr
)
4918 ASSERT(nfs_zone() == VTOMI(vp
)->mi_zone
);
4919 error
= nfs_rdwrlbn(vp
, pp
, io_off
, io_len
, flags
, cr
);
4921 pvn_read_done(pp
, (error
? B_ERROR
: 0) | flags
);
4923 pvn_write_done(pp
, (error
? B_ERROR
: 0) | flags
);
4929 nfs_pageio(vnode_t
*vp
, page_t
*pp
, uoff_t io_off
, size_t io_len
,
4930 int flags
, cred_t
*cr
, caller_context_t
*ct
)
4938 if (io_off
> MAXOFF32_T
)
4940 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
4943 mutex_enter(&rp
->r_statelock
);
4945 mutex_exit(&rp
->r_statelock
);
4947 if (flags
& B_ASYNC
) {
4948 error
= nfs_async_pageio(vp
, pp
, io_off
, io_len
, flags
, cr
,
4951 error
= nfs_rdwrlbn(vp
, pp
, io_off
, io_len
, flags
, cr
);
4952 mutex_enter(&rp
->r_statelock
);
4954 cv_broadcast(&rp
->r_cv
);
4955 mutex_exit(&rp
->r_statelock
);
4961 nfs_setsecattr(vnode_t
*vp
, vsecattr_t
*vsecattr
, int flag
, cred_t
*cr
,
4962 caller_context_t
*ct
)
4969 if (nfs_zone() != mi
->mi_zone
)
4971 if (mi
->mi_flags
& MI_ACL
) {
4972 error
= acl_setacl2(vp
, vsecattr
, flag
, cr
);
4973 if (mi
->mi_flags
& MI_ACL
)
4982 nfs_getsecattr(vnode_t
*vp
, vsecattr_t
*vsecattr
, int flag
, cred_t
*cr
,
4983 caller_context_t
*ct
)
4990 if (nfs_zone() != mi
->mi_zone
)
4992 if (mi
->mi_flags
& MI_ACL
) {
4993 error
= acl_getacl2(vp
, vsecattr
, flag
, cr
);
4994 if (mi
->mi_flags
& MI_ACL
)
4998 return (fs_fab_acl(vp
, vsecattr
, flag
, cr
, ct
));
5003 nfs_shrlock(vnode_t
*vp
, int cmd
, struct shrlock
*shr
, int flag
, cred_t
*cr
,
5004 caller_context_t
*ct
)
5007 struct shrlock nshr
;
5008 struct nfs_owner nfs_owner
;
5011 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
5015 * check for valid cmd parameter
5017 if (cmd
!= F_SHARE
&& cmd
!= F_UNSHARE
&& cmd
!= F_HASREMOTELOCKS
)
5021 * Check access permissions
5023 if (cmd
== F_SHARE
&&
5024 (((shr
->s_access
& F_RDACC
) && !(flag
& FREAD
)) ||
5025 ((shr
->s_access
& F_WRACC
) && !(flag
& FWRITE
))))
5029 * If the filesystem is mounted using local locking, pass the
5030 * request off to the local share code.
5032 if (VTOMI(vp
)->mi_flags
& MI_LLOCK
)
5033 return (fs_shrlock(vp
, cmd
, shr
, flag
, cr
, ct
));
5038 lm_fh
.n_len
= sizeof (fhandle_t
);
5039 lm_fh
.n_bytes
= (char *)VTOFH(vp
);
5042 * If passed an owner that is too large to fit in an
5043 * nfs_owner it is likely a recursive call from the
5044 * lock manager client and pass it straight through. If
5045 * it is not a nfs_owner then simply return an error.
5047 if (shr
->s_own_len
> sizeof (nfs_owner
.lowner
)) {
5048 if (((struct nfs_owner
*)shr
->s_owner
)->magic
!=
5052 if (error
= lm_shrlock(vp
, cmd
, shr
, flag
, &lm_fh
)) {
5053 error
= set_errno(error
);
5058 * Remote share reservations owner is a combination of
5059 * a magic number, hostname, and the local owner
5061 bzero(&nfs_owner
, sizeof (nfs_owner
));
5062 nfs_owner
.magic
= NFS_OWNER_MAGIC
;
5063 (void) strncpy(nfs_owner
.hname
, uts_nodename(),
5064 sizeof (nfs_owner
.hname
));
5065 bcopy(shr
->s_owner
, nfs_owner
.lowner
, shr
->s_own_len
);
5066 nshr
.s_access
= shr
->s_access
;
5067 nshr
.s_deny
= shr
->s_deny
;
5069 nshr
.s_pid
= ttoproc(curthread
)->p_pid
;
5070 nshr
.s_own_len
= sizeof (nfs_owner
);
5071 nshr
.s_owner
= (caddr_t
)&nfs_owner
;
5073 if (error
= lm_shrlock(vp
, cmd
, &nshr
, flag
, &lm_fh
)) {
5074 error
= set_errno(error
);
5079 case F_HASREMOTELOCKS
:
5081 * NFS client can't store remote locks itself