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) {
292 va
.va_mask
= VATTR_ALL
;
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
= VATTR_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
) &&
1098 ((vap
->va_mask
& ~(VATTR_SIZE
| VATTR_FSID
| VATTR_RDEV
)) == 0)) {
1099 mutex_enter(&rp
->r_statelock
);
1100 if (vap
->va_mask
& VATTR_SIZE
)
1101 vap
->va_size
= rp
->r_size
;
1102 if (vap
->va_mask
& VATTR_FSID
)
1103 vap
->va_fsid
= rp
->r_attr
.va_fsid
;
1104 if (vap
->va_mask
& VATTR_RDEV
)
1105 vap
->va_rdev
= rp
->r_attr
.va_rdev
;
1106 mutex_exit(&rp
->r_statelock
);
1111 * Only need to flush pages if asking for the mtime
1112 * and if there any dirty pages or any outstanding
1113 * asynchronous (write) requests for this file.
1115 if (vap
->va_mask
& VATTR_MTIME
) {
1116 if (vn_has_cached_data(vp
) &&
1117 ((rp
->r_flags
& RDIRTY
) || rp
->r_awcount
> 0)) {
1118 mutex_enter(&rp
->r_statelock
);
1120 mutex_exit(&rp
->r_statelock
);
1121 error
= nfs_putpage(vp
, 0, 0, 0, cr
, ct
);
1122 mutex_enter(&rp
->r_statelock
);
1123 if (error
&& (error
== ENOSPC
|| error
== EDQUOT
)) {
1125 rp
->r_error
= error
;
1127 if (--rp
->r_gcount
== 0)
1128 cv_broadcast(&rp
->r_cv
);
1129 mutex_exit(&rp
->r_statelock
);
1133 return (nfsgetattr(vp
, vap
, cr
));
1138 nfs_setattr(vnode_t
*vp
, struct vattr
*vap
, int flags
, cred_t
*cr
,
1139 caller_context_t
*ct
)
1145 mask
= vap
->va_mask
;
1147 if (mask
& VATTR_NOSET
)
1150 if ((mask
& VATTR_SIZE
) &&
1151 vap
->va_type
== VREG
&&
1152 vap
->va_size
> MAXOFF32_T
)
1155 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
1158 va
.va_mask
= VATTR_UID
| VATTR_MODE
;
1160 error
= nfsgetattr(vp
, &va
, cr
);
1164 error
= secpolicy_vnode_setattr(cr
, vp
, vap
, &va
, flags
, nfs_accessx
,
1170 error
= nfssetattr(vp
, vap
, flags
, cr
);
1172 if (error
== 0 && (mask
& VATTR_SIZE
) && vap
->va_size
== 0)
1173 vnevent_truncate(vp
, ct
);
1179 nfssetattr(vnode_t
*vp
, struct vattr
*vap
, int flags
, cred_t
*cr
)
1183 struct nfssaargs args
;
1184 struct nfsattrstat ns
;
1193 mask
= vap
->va_mask
;
1195 ASSERT(nfs_zone() == VTOMI(vp
)->mi_zone
);
1200 * Only need to flush pages if there are any pages and
1201 * if the file is marked as dirty in some fashion. The
1202 * file must be flushed so that we can accurately
1203 * determine the size of the file and the cached data
1204 * after the SETATTR returns. A file is considered to
1205 * be dirty if it is either marked with RDIRTY, has
1206 * outstanding i/o's active, or is mmap'd. In this
1207 * last case, we can't tell whether there are dirty
1208 * pages, so we flush just to be sure.
1210 if (vn_has_cached_data(vp
) &&
1211 ((rp
->r_flags
& RDIRTY
) ||
1213 rp
->r_mapcnt
> 0)) {
1214 ASSERT(vp
->v_type
!= VCHR
);
1215 error
= nfs_putpage(vp
, 0, 0, 0, cr
, NULL
);
1216 if (error
&& (error
== ENOSPC
|| error
== EDQUOT
)) {
1217 mutex_enter(&rp
->r_statelock
);
1219 rp
->r_error
= error
;
1220 mutex_exit(&rp
->r_statelock
);
1225 * If the system call was utime(2) or utimes(2) and the
1226 * application did not specify the times, then set the
1227 * mtime nanosecond field to 1 billion. This will get
1228 * translated from 1 billion nanoseconds to 1 million
1229 * microseconds in the over the wire request. The
1230 * server will use 1 million in the microsecond field
1231 * to tell whether both the mtime and atime should be
1232 * set to the server's current time.
1234 * This is an overload of the protocol and should be
1235 * documented in the NFS Version 2 protocol specification.
1237 if ((mask
& VATTR_MTIME
) && !(flags
& ATTR_UTIME
)) {
1238 vap
->va_mtime
.tv_nsec
= 1000000000;
1239 if (NFS_TIME_T_OK(vap
->va_mtime
.tv_sec
) &&
1240 NFS_TIME_T_OK(vap
->va_atime
.tv_sec
)) {
1241 error
= vattr_to_sattr(vap
, &args
.saa_sa
);
1244 * Use server times. vap time values will not be used.
1245 * To ensure no time overflow, make sure vap has
1246 * valid values, but retain the original values.
1248 timestruc_t mtime
= vap
->va_mtime
;
1249 timestruc_t atime
= vap
->va_atime
;
1252 now
= gethrestime_sec();
1253 if (NFS_TIME_T_OK(now
)) {
1254 /* Just in case server does not know of this */
1255 vap
->va_mtime
.tv_sec
= now
;
1256 vap
->va_atime
.tv_sec
= now
;
1258 vap
->va_mtime
.tv_sec
= 0;
1259 vap
->va_atime
.tv_sec
= 0;
1261 error
= vattr_to_sattr(vap
, &args
.saa_sa
);
1262 /* set vap times back on */
1263 vap
->va_mtime
= mtime
;
1264 vap
->va_atime
= atime
;
1267 /* Either do not set times or use the client specified times */
1268 error
= vattr_to_sattr(vap
, &args
.saa_sa
);
1271 /* req time field(s) overflow - return immediately */
1274 args
.saa_fh
= *VTOFH(vp
);
1276 va
.va_mask
= VATTR_MODE
;
1277 error
= nfsgetattr(vp
, &va
, cr
);
1288 error
= rfs2call(mi
, RFS_SETATTR
,
1289 xdr_saargs
, (caddr_t
)&args
,
1290 xdr_attrstat
, (caddr_t
)&ns
, cr
,
1291 &douprintf
, &ns
.ns_status
, 0, NULL
);
1294 * Purge the access cache and ACL cache if changing either the
1295 * owner of the file, the group owner, or the mode. These may
1296 * change the access permissions of the file, so purge old
1297 * information and start over again.
1299 if ((mask
& (VATTR_UID
| VATTR_GID
| VATTR_MODE
)) && (mi
->mi_flags
& MI_ACL
)) {
1300 (void) nfs_access_purge_rp(rp
);
1301 if (rp
->r_secattr
!= NULL
) {
1302 mutex_enter(&rp
->r_statelock
);
1303 vsp
= rp
->r_secattr
;
1304 rp
->r_secattr
= NULL
;
1305 mutex_exit(&rp
->r_statelock
);
1312 error
= geterrno(ns
.ns_status
);
1315 * If changing the size of the file, invalidate
1316 * any local cached data which is no longer part
1317 * of the file. We also possibly invalidate the
1318 * last page in the file. We could use
1319 * pvn_vpzero(), but this would mark the page as
1320 * modified and require it to be written back to
1321 * the server for no particularly good reason.
1322 * This way, if we access it, then we bring it
1323 * back in. A read should be cheaper than a
1326 if (mask
& VATTR_SIZE
) {
1327 nfs_invalidate_pages(vp
,
1328 (vap
->va_size
& PAGEMASK
), cr
);
1330 (void) nfs_cache_fattr(vp
, &ns
.ns_attr
, &va
, t
, cr
);
1332 * If NFS_ACL is supported on the server, then the
1333 * attributes returned by server may have minimal
1334 * permissions sometimes denying access to users having
1335 * proper access. To get the proper attributes, mark
1336 * the attributes as expired so that they will be
1337 * regotten via the NFS_ACL GETATTR2 procedure.
1339 if (mi
->mi_flags
& MI_ACL
) {
1340 PURGE_ATTRCACHE(vp
);
1343 * This next check attempts to deal with NFS
1344 * servers which can not handle increasing
1345 * the size of the file via setattr. Most
1346 * of these servers do not return an error,
1347 * but do not change the size of the file.
1348 * Hence, this check and then attempt to set
1349 * the file size by writing 1 byte at the
1350 * offset of the end of the file that we need.
1352 if ((mask
& VATTR_SIZE
) &&
1353 ns
.ns_attr
.na_size
< (uint32_t)vap
->va_size
) {
1356 error
= nfswrite(vp
, &zb
,
1357 vap
->va_size
- sizeof (zb
),
1361 * Some servers will change the mode to clear the setuid
1362 * and setgid bits when changing the uid or gid. The
1363 * client needs to compensate appropriately.
1365 if (mask
& (VATTR_UID
| VATTR_GID
)) {
1368 va
.va_mask
= VATTR_MODE
;
1369 terror
= nfsgetattr(vp
, &va
, cr
);
1371 (((mask
& VATTR_MODE
) &&
1372 va
.va_mode
!= vap
->va_mode
) ||
1373 (!(mask
& VATTR_MODE
) &&
1374 va
.va_mode
!= omode
))) {
1375 va
.va_mask
= VATTR_MODE
;
1376 if (mask
& VATTR_MODE
)
1377 va
.va_mode
= vap
->va_mode
;
1380 (void) nfssetattr(vp
, &va
, 0, cr
);
1384 PURGE_ATTRCACHE(vp
);
1385 PURGE_STALE_FH(error
, vp
, cr
);
1388 PURGE_ATTRCACHE(vp
);
1395 nfs_accessx(void *vp
, int mode
, cred_t
*cr
)
1397 ASSERT(nfs_zone() == VTOMI((vnode_t
*)vp
)->mi_zone
);
1398 return (nfs_access(vp
, mode
, 0, cr
, NULL
));
1403 nfs_access(vnode_t
*vp
, int mode
, int flags
, cred_t
*cr
, caller_context_t
*ct
)
1412 if (nfs_zone() != mi
->mi_zone
)
1414 if (mi
->mi_flags
& MI_ACL
) {
1415 error
= acl_access2(vp
, mode
, flags
, cr
);
1416 if (mi
->mi_flags
& MI_ACL
)
1420 va
.va_mask
= VATTR_MODE
| VATTR_UID
| VATTR_GID
;
1421 error
= nfsgetattr(vp
, &va
, cr
);
1426 * Disallow write attempts on read-only
1427 * file systems, unless the file is a
1430 if ((mode
& VWRITE
) && vn_is_readonly(vp
) && !IS_DEVVP(vp
))
1434 * Disallow attempts to access mandatory lock files.
1436 if ((mode
& (VWRITE
| VREAD
| VEXEC
)) &&
1437 MANDLOCK(vp
, va
.va_mode
))
1441 * Access check is based on only
1442 * one of owner, group, public.
1443 * If not owner, then check group.
1444 * If not a member of the group,
1445 * then check public access.
1447 if (crgetuid(cr
) != va
.va_uid
) {
1449 if (!groupmember(va
.va_gid
, cr
))
1453 return (secpolicy_vnode_access2(cr
, vp
, va
.va_uid
,
1454 va
.va_mode
<< shift
, mode
));
1457 static int nfs_do_symlink_cache
= 1;
1461 nfs_readlink(vnode_t
*vp
, struct uio
*uiop
, cred_t
*cr
, caller_context_t
*ct
)
1464 struct nfsrdlnres rl
;
1470 * We want to be consistent with UFS semantics so we will return
1471 * EINVAL instead of ENXIO. This violates the XNFS spec and
1472 * the RFC 1094, which are wrong any way. BUGID 1138002.
1474 if (vp
->v_type
!= VLNK
)
1477 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
1481 if (nfs_do_symlink_cache
&& rp
->r_symlink
.contents
!= NULL
) {
1482 error
= nfs_validate_caches(vp
, cr
);
1485 mutex_enter(&rp
->r_statelock
);
1486 if (rp
->r_symlink
.contents
!= NULL
) {
1487 error
= uiomove(rp
->r_symlink
.contents
,
1488 rp
->r_symlink
.len
, UIO_READ
, uiop
);
1489 mutex_exit(&rp
->r_statelock
);
1492 mutex_exit(&rp
->r_statelock
);
1496 rl
.rl_data
= kmem_alloc(NFS_MAXPATHLEN
, KM_SLEEP
);
1499 fi
.fhp
= NULL
; /* no need to update, filehandle not copied */
1500 fi
.copyproc
= nfscopyfh
;
1501 fi
.lookupproc
= nfslookup
;
1502 fi
.xattrdirproc
= acl_getxattrdir2
;
1506 error
= rfs2call(VTOMI(vp
), RFS_READLINK
,
1507 xdr_readlink
, (caddr_t
)VTOFH(vp
),
1508 xdr_rdlnres
, (caddr_t
)&rl
, cr
,
1509 &douprintf
, &rl
.rl_status
, 0, &fi
);
1513 kmem_free((void *)rl
.rl_data
, NFS_MAXPATHLEN
);
1517 error
= geterrno(rl
.rl_status
);
1519 error
= uiomove(rl
.rl_data
, (int)rl
.rl_count
, UIO_READ
, uiop
);
1520 if (nfs_do_symlink_cache
&& rp
->r_symlink
.contents
== NULL
) {
1521 mutex_enter(&rp
->r_statelock
);
1522 if (rp
->r_symlink
.contents
== NULL
) {
1523 rp
->r_symlink
.contents
= rl
.rl_data
;
1524 rp
->r_symlink
.len
= (int)rl
.rl_count
;
1525 rp
->r_symlink
.size
= NFS_MAXPATHLEN
;
1526 mutex_exit(&rp
->r_statelock
);
1528 mutex_exit(&rp
->r_statelock
);
1530 kmem_free((void *)rl
.rl_data
,
1535 kmem_free((void *)rl
.rl_data
, NFS_MAXPATHLEN
);
1538 PURGE_STALE_FH(error
, vp
, cr
);
1540 kmem_free((void *)rl
.rl_data
, NFS_MAXPATHLEN
);
1544 * Conform to UFS semantics (see comment above)
1546 return (error
== ENXIO
? EINVAL
: error
);
1550 * Flush local dirty pages to stable storage on the server.
1552 * If FNODSYNC is specified, then there is nothing to do because
1553 * metadata changes are not cached on the client before being
1554 * sent to the server.
1558 nfs_fsync(vnode_t
*vp
, int syncflag
, cred_t
*cr
, caller_context_t
*ct
)
1562 if ((syncflag
& FNODSYNC
) || IS_SWAPVP(vp
))
1565 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
1568 error
= nfs_putpage(vp
, 0, 0, 0, cr
, ct
);
1570 error
= VTOR(vp
)->r_error
;
1576 * Weirdness: if the file was removed or the target of a rename
1577 * operation while it was open, it got renamed instead. Here we
1578 * remove the renamed file.
1582 nfs_inactive(vnode_t
*vp
, cred_t
*cr
, caller_context_t
*ct
)
1586 ASSERT(vp
!= DNLC_NO_VNODE
);
1589 * If this is coming from the wrong zone, we let someone in the right
1590 * zone take care of it asynchronously. We can get here due to
1591 * VN_RELE() being called from pageout() or fsflush(). This call may
1592 * potentially turn into an expensive no-op if, for instance, v_count
1593 * gets incremented in the meantime, but it's still correct.
1595 if (nfs_zone() != VTOMI(vp
)->mi_zone
) {
1596 nfs_async_inactive(vp
, cr
, nfs_inactive
);
1602 if (rp
->r_unldvp
!= NULL
) {
1604 * Save the vnode pointer for the directory where the
1605 * unlinked-open file got renamed, then set it to NULL
1606 * to prevent another thread from getting here before
1607 * we're done with the remove. While we have the
1608 * statelock, make local copies of the pertinent rnode
1609 * fields. If we weren't to do this in an atomic way, the
1610 * the unl* fields could become inconsistent with respect
1611 * to each other due to a race condition between this
1612 * code and nfs_remove(). See bug report 1034328.
1614 mutex_enter(&rp
->r_statelock
);
1615 if (rp
->r_unldvp
!= NULL
) {
1619 struct nfsdiropargs da
;
1620 enum nfsstat status
;
1624 unldvp
= rp
->r_unldvp
;
1625 rp
->r_unldvp
= NULL
;
1626 unlname
= rp
->r_unlname
;
1627 rp
->r_unlname
= NULL
;
1628 unlcred
= rp
->r_unlcred
;
1629 rp
->r_unlcred
= NULL
;
1630 mutex_exit(&rp
->r_statelock
);
1633 * If there are any dirty pages left, then flush
1634 * them. This is unfortunate because they just
1635 * may get thrown away during the remove operation,
1636 * but we have to do this for correctness.
1638 if (vn_has_cached_data(vp
) &&
1639 ((rp
->r_flags
& RDIRTY
) || rp
->r_count
> 0)) {
1640 ASSERT(vp
->v_type
!= VCHR
);
1641 error
= nfs_putpage(vp
, 0, 0, 0,
1644 mutex_enter(&rp
->r_statelock
);
1646 rp
->r_error
= error
;
1647 mutex_exit(&rp
->r_statelock
);
1652 * Do the remove operation on the renamed file
1654 setdiropargs(&da
, unlname
, unldvp
);
1658 (void) rfs2call(VTOMI(unldvp
), RFS_REMOVE
,
1659 xdr_diropargs
, (caddr_t
)&da
,
1660 xdr_enum
, (caddr_t
)&status
, unlcred
,
1661 &douprintf
, &status
, 0, NULL
);
1663 if (HAVE_RDDIR_CACHE(VTOR(unldvp
)))
1664 nfs_purge_rddir_cache(unldvp
);
1665 PURGE_ATTRCACHE(unldvp
);
1668 * Release stuff held for the remove
1671 kmem_free(unlname
, MAXNAMELEN
);
1675 mutex_exit(&rp
->r_statelock
);
1682 * Remote file system operations having to do with directory manipulation.
1687 nfs_lookup(vnode_t
*dvp
, char *nm
, vnode_t
**vpp
, struct pathname
*pnp
,
1688 int flags
, vnode_t
*rdir
, cred_t
*cr
, caller_context_t
*ct
,
1689 int *direntflags
, pathname_t
*realpnp
)
1693 vnode_t
*avp
= NULL
;
1696 if (nfs_zone() != VTOMI(dvp
)->mi_zone
)
1702 * Are we looking up extended attributes? If so, "dvp" is
1703 * the file or directory for which we want attributes, and
1704 * we need a lookup of the hidden attribute directory
1705 * before we lookup the rest of the path.
1707 if (flags
& LOOKUP_XATTR
) {
1708 bool_t cflag
= ((flags
& CREATE_XATTR_DIR
) != 0);
1712 if (!(mi
->mi_flags
& MI_EXTATTR
))
1715 if (nfs_rw_enter_sig(&drp
->r_rwlock
, RW_READER
, INTR(dvp
)))
1718 (void) nfslookup_dnlc(dvp
, XATTR_DIR_NAME
, &avp
, cr
);
1720 error
= acl_getxattrdir2(dvp
, &avp
, cflag
, cr
, 0);
1724 nfs_rw_exit(&drp
->r_rwlock
);
1727 if (mi
->mi_flags
& MI_EXTATTR
)
1735 if (nfs_rw_enter_sig(&drp
->r_rwlock
, RW_READER
, INTR(dvp
))) {
1740 error
= nfslookup(dvp
, nm
, vpp
, pnp
, flags
, rdir
, cr
, 0);
1742 nfs_rw_exit(&drp
->r_rwlock
);
1745 * If vnode is a device, create special vnode.
1747 if (!error
&& IS_DEVVP(*vpp
)) {
1749 *vpp
= specvp(vp
, vp
->v_rdev
, vp
->v_type
, cr
);
1760 static int nfs_lookup_neg_cache
= 1;
1763 static int nfs_lookup_dnlc_hits
= 0;
1764 static int nfs_lookup_dnlc_misses
= 0;
1765 static int nfs_lookup_dnlc_neg_hits
= 0;
1766 static int nfs_lookup_dnlc_disappears
= 0;
1767 static int nfs_lookup_dnlc_lookups
= 0;
1772 nfslookup(vnode_t
*dvp
, char *nm
, vnode_t
**vpp
, struct pathname
*pnp
,
1773 int flags
, vnode_t
*rdir
, cred_t
*cr
, int rfscall_flags
)
1777 ASSERT(nfs_zone() == VTOMI(dvp
)->mi_zone
);
1780 * If lookup is for "", just return dvp. Don't need
1781 * to send it over the wire, look it up in the dnlc,
1782 * or perform any access checks.
1791 * Can't do lookups in non-directories.
1793 if (dvp
->v_type
!= VDIR
)
1797 * If we're called with RFSCALL_SOFT, it's important that
1798 * the only rfscall is one we make directly; if we permit
1799 * an access call because we're looking up "." or validating
1800 * a dnlc hit, we'll deadlock because that rfscall will not
1801 * have the RFSCALL_SOFT set.
1803 if (rfscall_flags
& RFSCALL_SOFT
)
1807 * If lookup is for ".", just return dvp. Don't need
1808 * to send it over the wire or look it up in the dnlc,
1809 * just need to check access.
1811 if (strcmp(nm
, ".") == 0) {
1812 error
= nfs_access(dvp
, VEXEC
, 0, cr
, NULL
);
1821 * Lookup this name in the DNLC. If there was a valid entry,
1822 * then return the results of the lookup.
1824 error
= nfslookup_dnlc(dvp
, nm
, vpp
, cr
);
1825 if (error
|| *vpp
!= NULL
)
1829 error
= nfslookup_otw(dvp
, nm
, vpp
, cr
, rfscall_flags
);
1835 nfslookup_dnlc(vnode_t
*dvp
, char *nm
, vnode_t
**vpp
, cred_t
*cr
)
1840 ASSERT(*nm
!= '\0');
1841 ASSERT(nfs_zone() == VTOMI(dvp
)->mi_zone
);
1844 * Lookup this name in the DNLC. If successful, then validate
1845 * the caches and then recheck the DNLC. The DNLC is rechecked
1846 * just in case this entry got invalidated during the call
1847 * to nfs_validate_caches.
1849 * An assumption is being made that it is safe to say that a
1850 * file exists which may not on the server. Any operations to
1851 * the server will fail with ESTALE.
1854 nfs_lookup_dnlc_lookups
++;
1856 vp
= dnlc_lookup(dvp
, nm
);
1859 if (vp
== DNLC_NO_VNODE
&& !vn_is_readonly(dvp
)) {
1860 PURGE_ATTRCACHE(dvp
);
1862 error
= nfs_validate_caches(dvp
, cr
);
1865 vp
= dnlc_lookup(dvp
, nm
);
1867 error
= nfs_access(dvp
, VEXEC
, 0, cr
, NULL
);
1872 if (vp
== DNLC_NO_VNODE
) {
1875 nfs_lookup_dnlc_neg_hits
++;
1881 nfs_lookup_dnlc_hits
++;
1886 nfs_lookup_dnlc_disappears
++;
1891 nfs_lookup_dnlc_misses
++;
1900 nfslookup_otw(vnode_t
*dvp
, char *nm
, vnode_t
**vpp
, cred_t
*cr
,
1904 struct nfsdiropargs da
;
1905 struct nfsdiropres dr
;
1910 ASSERT(*nm
!= '\0');
1911 ASSERT(dvp
->v_type
== VDIR
);
1912 ASSERT(nfs_zone() == VTOMI(dvp
)->mi_zone
);
1914 setdiropargs(&da
, nm
, dvp
);
1917 fi
.fhp
= NULL
; /* no need to update, filehandle not copied */
1918 fi
.copyproc
= nfscopyfh
;
1919 fi
.lookupproc
= nfslookup
;
1920 fi
.xattrdirproc
= acl_getxattrdir2
;
1926 error
= rfs2call(VTOMI(dvp
), RFS_LOOKUP
,
1927 xdr_diropargs
, (caddr_t
)&da
,
1928 xdr_diropres
, (caddr_t
)&dr
, cr
,
1929 &douprintf
, &dr
.dr_status
, rfscall_flags
, &fi
);
1932 error
= geterrno(dr
.dr_status
);
1934 *vpp
= makenfsnode(&dr
.dr_fhandle
, &dr
.dr_attr
,
1935 dvp
->v_vfsp
, t
, cr
, VTOR(dvp
)->r_path
, nm
);
1937 * If NFS_ACL is supported on the server, then the
1938 * attributes returned by server may have minimal
1939 * permissions sometimes denying access to users having
1940 * proper access. To get the proper attributes, mark
1941 * the attributes as expired so that they will be
1942 * regotten via the NFS_ACL GETATTR2 procedure.
1944 if (VTOMI(*vpp
)->mi_flags
& MI_ACL
) {
1945 PURGE_ATTRCACHE(*vpp
);
1947 if (!(rfscall_flags
& RFSCALL_SOFT
))
1948 dnlc_update(dvp
, nm
, *vpp
);
1950 PURGE_STALE_FH(error
, dvp
, cr
);
1951 if (error
== ENOENT
&& nfs_lookup_neg_cache
)
1952 dnlc_enter(dvp
, nm
, DNLC_NO_VNODE
);
1961 nfs_create(vnode_t
*dvp
, char *nm
, struct vattr
*va
, enum vcexcl exclusive
,
1962 int mode
, vnode_t
**vpp
, cred_t
*cr
, int lfaware
, caller_context_t
*ct
,
1966 struct nfscreatargs args
;
1967 struct nfsdiropres dr
;
1978 if (nfs_zone() != VTOMI(dvp
)->mi_zone
)
1980 if (nfs_rw_enter_sig(&drp
->r_rwlock
, RW_WRITER
, INTR(dvp
)))
1984 * We make a copy of the attributes because the caller does not
1985 * expect us to change what va points to.
1990 * If the pathname is "", just use dvp. Don't need
1991 * to send it over the wire, look it up in the dnlc,
1992 * or perform any access checks.
1999 * If the pathname is ".", just use dvp. Don't need
2000 * to send it over the wire or look it up in the dnlc,
2001 * just need to check access.
2003 } else if (strcmp(nm
, ".") == 0) {
2004 error
= nfs_access(dvp
, VEXEC
, 0, cr
, ct
);
2006 nfs_rw_exit(&drp
->r_rwlock
);
2012 * We need to go over the wire, just to be sure whether the
2013 * file exists or not. Using the DNLC can be dangerous in
2014 * this case when making a decision regarding existence.
2017 error
= nfslookup_otw(dvp
, nm
, &vp
, cr
, 0);
2020 if (exclusive
== EXCL
)
2022 else if (vp
->v_type
== VDIR
&& (mode
& VWRITE
))
2026 * If vnode is a device, create special vnode.
2030 vp
= specvp(vp
, vp
->v_rdev
, vp
->v_type
, cr
);
2033 if (!(error
= fop_access(vp
, mode
, 0, cr
, ct
))) {
2034 if ((vattr
.va_mask
& VATTR_SIZE
) &&
2035 vp
->v_type
== VREG
) {
2036 vattr
.va_mask
= VATTR_SIZE
;
2037 error
= nfssetattr(vp
, &vattr
, 0, cr
);
2041 * Existing file was truncated;
2042 * emit a create event.
2044 vnevent_create(vp
, ct
);
2049 nfs_rw_exit(&drp
->r_rwlock
);
2058 ASSERT(vattr
.va_mask
& VATTR_TYPE
);
2059 if (vattr
.va_type
== VREG
) {
2060 ASSERT(vattr
.va_mask
& VATTR_MODE
);
2061 if (MANDMODE(vattr
.va_mode
)) {
2062 nfs_rw_exit(&drp
->r_rwlock
);
2067 dnlc_remove(dvp
, nm
);
2069 setdiropargs(&args
.ca_da
, nm
, dvp
);
2072 * Decide what the group-id of the created file should be.
2073 * Set it in attribute list as advisory...then do a setattr
2074 * if the server didn't get it right the first time.
2076 error
= setdirgid(dvp
, &vattr
.va_gid
, cr
);
2078 nfs_rw_exit(&drp
->r_rwlock
);
2081 vattr
.va_mask
|= VATTR_GID
;
2084 * This is a completely gross hack to make mknod
2085 * work over the wire until we can wack the protocol
2087 #define IFCHR 0020000 /* character special */
2088 #define IFBLK 0060000 /* block special */
2089 #define IFSOCK 0140000 /* socket */
2092 * dev_t is uint_t in 5.x and short in 4.x. Both 4.x
2093 * supports 8 bit majors. 5.x supports 14 bit majors. 5.x supports 18
2094 * bits in the minor number where 4.x supports 8 bits. If the 5.x
2095 * minor/major numbers <= 8 bits long, compress the device
2096 * number before sending it. Otherwise, the 4.x server will not
2097 * create the device with the correct device number and nothing can be
2100 if (vattr
.va_type
== VCHR
|| vattr
.va_type
== VBLK
) {
2101 dev_t d
= vattr
.va_rdev
;
2104 if (vattr
.va_type
== VCHR
)
2105 vattr
.va_mode
|= IFCHR
;
2107 vattr
.va_mode
|= IFBLK
;
2109 (void) cmpldev(&dev32
, d
);
2110 if (dev32
& ~((SO4_MAXMAJ
<< L_BITSMINOR32
) | SO4_MAXMIN
))
2111 vattr
.va_size
= (uoff_t
)dev32
;
2113 vattr
.va_size
= (uoff_t
)nfsv2_cmpdev(d
);
2115 vattr
.va_mask
|= VATTR_MODE
|VATTR_SIZE
;
2116 } else if (vattr
.va_type
== VFIFO
) {
2117 vattr
.va_mode
|= IFCHR
; /* xtra kludge for namedpipe */
2118 vattr
.va_size
= (uoff_t
)NFS_FIFO_DEV
; /* blech */
2119 vattr
.va_mask
|= VATTR_MODE
|VATTR_SIZE
;
2120 } else if (vattr
.va_type
== VSOCK
) {
2121 vattr
.va_mode
|= IFSOCK
;
2123 * To avoid triggering bugs in the servers set VATTR_SIZE
2124 * (all other RFS_CREATE calls set this).
2127 vattr
.va_mask
|= VATTR_MODE
|VATTR_SIZE
;
2130 args
.ca_sa
= &args
.ca_sa_buf
;
2131 error
= vattr_to_sattr(&vattr
, args
.ca_sa
);
2133 /* req time field(s) overflow - return immediately */
2134 nfs_rw_exit(&drp
->r_rwlock
);
2142 error
= rfs2call(VTOMI(dvp
), RFS_CREATE
,
2143 xdr_creatargs
, (caddr_t
)&args
,
2144 xdr_diropres
, (caddr_t
)&dr
, cr
,
2145 &douprintf
, &dr
.dr_status
, 0, NULL
);
2147 PURGE_ATTRCACHE(dvp
); /* mod time changed */
2150 error
= geterrno(dr
.dr_status
);
2152 if (HAVE_RDDIR_CACHE(drp
))
2153 nfs_purge_rddir_cache(dvp
);
2154 vp
= makenfsnode(&dr
.dr_fhandle
, &dr
.dr_attr
,
2155 dvp
->v_vfsp
, t
, cr
, NULL
, NULL
);
2157 * If NFS_ACL is supported on the server, then the
2158 * attributes returned by server may have minimal
2159 * permissions sometimes denying access to users having
2160 * proper access. To get the proper attributes, mark
2161 * the attributes as expired so that they will be
2162 * regotten via the NFS_ACL GETATTR2 procedure.
2164 if (VTOMI(vp
)->mi_flags
& MI_ACL
) {
2165 PURGE_ATTRCACHE(vp
);
2167 dnlc_update(dvp
, nm
, vp
);
2169 if (vattr
.va_size
== 0) {
2170 mutex_enter(&rp
->r_statelock
);
2172 mutex_exit(&rp
->r_statelock
);
2173 if (vn_has_cached_data(vp
)) {
2174 ASSERT(vp
->v_type
!= VCHR
);
2175 nfs_invalidate_pages(vp
,
2181 * Make sure the gid was set correctly.
2182 * If not, try to set it (but don't lose
2183 * any sleep over it).
2185 if (vattr
.va_gid
!= rp
->r_attr
.va_gid
) {
2186 vattr
.va_mask
= VATTR_GID
;
2187 (void) nfssetattr(vp
, &vattr
, 0, cr
);
2191 * If vnode is a device create special vnode
2194 *vpp
= specvp(vp
, vp
->v_rdev
, vp
->v_type
, cr
);
2199 PURGE_STALE_FH(error
, dvp
, cr
);
2203 nfs_rw_exit(&drp
->r_rwlock
);
2209 * Weirdness: if the vnode to be removed is open
2210 * we rename it instead of removing it and nfs_inactive
2211 * will remove the new name.
2215 nfs_remove(vnode_t
*dvp
, char *nm
, cred_t
*cr
, caller_context_t
*ct
, int flags
)
2218 struct nfsdiropargs da
;
2219 enum nfsstat status
;
2226 if (nfs_zone() != VTOMI(dvp
)->mi_zone
)
2229 if (nfs_rw_enter_sig(&drp
->r_rwlock
, RW_WRITER
, INTR(dvp
)))
2232 error
= nfslookup(dvp
, nm
, &vp
, NULL
, 0, NULL
, cr
, 0);
2234 nfs_rw_exit(&drp
->r_rwlock
);
2238 if (vp
->v_type
== VDIR
&& secpolicy_fs_linkdir(cr
, dvp
->v_vfsp
)) {
2240 nfs_rw_exit(&drp
->r_rwlock
);
2245 * First just remove the entry from the name cache, as it
2246 * is most likely the only entry for this vp.
2248 dnlc_remove(dvp
, nm
);
2251 * If the file has a v_count > 1 then there may be more than one
2252 * entry in the name cache due multiple links or an open file,
2253 * but we don't have the real reference count so flush all
2256 if (vp
->v_count
> 1)
2260 * Now we have the real reference count on the vnode
2263 mutex_enter(&rp
->r_statelock
);
2264 if (vp
->v_count
> 1 &&
2265 (rp
->r_unldvp
== NULL
|| strcmp(nm
, rp
->r_unlname
) == 0)) {
2266 mutex_exit(&rp
->r_statelock
);
2267 tmpname
= newname();
2268 error
= nfsrename(dvp
, nm
, dvp
, tmpname
, cr
, ct
);
2270 kmem_free(tmpname
, MAXNAMELEN
);
2272 mutex_enter(&rp
->r_statelock
);
2273 if (rp
->r_unldvp
== NULL
) {
2276 if (rp
->r_unlcred
!= NULL
)
2277 crfree(rp
->r_unlcred
);
2280 rp
->r_unlname
= tmpname
;
2282 kmem_free(rp
->r_unlname
, MAXNAMELEN
);
2283 rp
->r_unlname
= tmpname
;
2285 mutex_exit(&rp
->r_statelock
);
2288 mutex_exit(&rp
->r_statelock
);
2290 * We need to flush any dirty pages which happen to
2291 * be hanging around before removing the file. This
2292 * shouldn't happen very often and mostly on file
2293 * systems mounted "nocto".
2295 if (vn_has_cached_data(vp
) &&
2296 ((rp
->r_flags
& RDIRTY
) || rp
->r_count
> 0)) {
2297 error
= nfs_putpage(vp
, 0, 0, 0, cr
, ct
);
2298 if (error
&& (error
== ENOSPC
|| error
== EDQUOT
)) {
2299 mutex_enter(&rp
->r_statelock
);
2301 rp
->r_error
= error
;
2302 mutex_exit(&rp
->r_statelock
);
2306 setdiropargs(&da
, nm
, dvp
);
2310 error
= rfs2call(VTOMI(dvp
), RFS_REMOVE
,
2311 xdr_diropargs
, (caddr_t
)&da
,
2312 xdr_enum
, (caddr_t
)&status
, cr
,
2313 &douprintf
, &status
, 0, NULL
);
2316 * The xattr dir may be gone after last attr is removed,
2317 * so flush it from dnlc.
2319 if (dvp
->v_flag
& V_XATTRDIR
)
2322 PURGE_ATTRCACHE(dvp
); /* mod time changed */
2323 PURGE_ATTRCACHE(vp
); /* link count changed */
2326 error
= geterrno(status
);
2328 if (HAVE_RDDIR_CACHE(drp
))
2329 nfs_purge_rddir_cache(dvp
);
2331 PURGE_STALE_FH(error
, dvp
, cr
);
2337 vnevent_remove(vp
, dvp
, nm
, ct
);
2341 nfs_rw_exit(&drp
->r_rwlock
);
2348 nfs_link(vnode_t
*tdvp
, vnode_t
*svp
, char *tnm
, cred_t
*cr
,
2349 caller_context_t
*ct
, int flags
)
2352 struct nfslinkargs args
;
2353 enum nfsstat status
;
2358 if (nfs_zone() != VTOMI(tdvp
)->mi_zone
)
2360 if (fop_realvp(svp
, &realvp
, ct
) == 0)
2363 args
.la_from
= VTOFH(svp
);
2364 setdiropargs(&args
.la_to
, tnm
, tdvp
);
2367 if (nfs_rw_enter_sig(&tdrp
->r_rwlock
, RW_WRITER
, INTR(tdvp
)))
2370 dnlc_remove(tdvp
, tnm
);
2374 error
= rfs2call(VTOMI(svp
), RFS_LINK
,
2375 xdr_linkargs
, (caddr_t
)&args
,
2376 xdr_enum
, (caddr_t
)&status
, cr
,
2377 &douprintf
, &status
, 0, NULL
);
2379 PURGE_ATTRCACHE(tdvp
); /* mod time changed */
2380 PURGE_ATTRCACHE(svp
); /* link count changed */
2383 error
= geterrno(status
);
2385 if (HAVE_RDDIR_CACHE(tdrp
))
2386 nfs_purge_rddir_cache(tdvp
);
2390 nfs_rw_exit(&tdrp
->r_rwlock
);
2394 * Notify the source file of this link operation.
2396 vnevent_link(svp
, ct
);
2403 nfs_rename(vnode_t
*odvp
, char *onm
, vnode_t
*ndvp
, char *nnm
, cred_t
*cr
,
2404 caller_context_t
*ct
, int flags
)
2408 if (nfs_zone() != VTOMI(odvp
)->mi_zone
)
2410 if (fop_realvp(ndvp
, &realvp
, ct
) == 0)
2413 return (nfsrename(odvp
, onm
, ndvp
, nnm
, cr
, ct
));
2417 * nfsrename does the real work of renaming in NFS Version 2.
2420 nfsrename(vnode_t
*odvp
, char *onm
, vnode_t
*ndvp
, char *nnm
, cred_t
*cr
,
2421 caller_context_t
*ct
)
2424 enum nfsstat status
;
2425 struct nfsrnmargs args
;
2427 vnode_t
*nvp
= NULL
;
2428 vnode_t
*ovp
= NULL
;
2434 ASSERT(nfs_zone() == VTOMI(odvp
)->mi_zone
);
2435 if (strcmp(onm
, ".") == 0 || strcmp(onm
, "..") == 0 ||
2436 strcmp(nnm
, ".") == 0 || strcmp(nnm
, "..") == 0)
2441 if ((intptr_t)odrp
< (intptr_t)ndrp
) {
2442 if (nfs_rw_enter_sig(&odrp
->r_rwlock
, RW_WRITER
, INTR(odvp
)))
2444 if (nfs_rw_enter_sig(&ndrp
->r_rwlock
, RW_WRITER
, INTR(ndvp
))) {
2445 nfs_rw_exit(&odrp
->r_rwlock
);
2449 if (nfs_rw_enter_sig(&ndrp
->r_rwlock
, RW_WRITER
, INTR(ndvp
)))
2451 if (nfs_rw_enter_sig(&odrp
->r_rwlock
, RW_WRITER
, INTR(odvp
))) {
2452 nfs_rw_exit(&ndrp
->r_rwlock
);
2458 * Lookup the target file. If it exists, it needs to be
2459 * checked to see whether it is a mount point and whether
2460 * it is active (open).
2462 error
= nfslookup(ndvp
, nnm
, &nvp
, NULL
, 0, NULL
, cr
, 0);
2465 * If this file has been mounted on, then just
2466 * return busy because renaming to it would remove
2467 * the mounted file system from the name space.
2469 if (vn_mountedvfs(nvp
) != NULL
) {
2471 nfs_rw_exit(&odrp
->r_rwlock
);
2472 nfs_rw_exit(&ndrp
->r_rwlock
);
2477 * Purge the name cache of all references to this vnode
2478 * so that we can check the reference count to infer
2479 * whether it is active or not.
2482 * First just remove the entry from the name cache, as it
2483 * is most likely the only entry for this vp.
2485 dnlc_remove(ndvp
, nnm
);
2487 * If the file has a v_count > 1 then there may be more
2488 * than one entry in the name cache due multiple links
2489 * or an open file, but we don't have the real reference
2490 * count so flush all possible entries.
2492 if (nvp
->v_count
> 1)
2496 * If the vnode is active and is not a directory,
2497 * arrange to rename it to a
2498 * temporary file so that it will continue to be
2499 * accessible. This implements the "unlink-open-file"
2500 * semantics for the target of a rename operation.
2501 * Before doing this though, make sure that the
2502 * source and target files are not already the same.
2504 if (nvp
->v_count
> 1 && nvp
->v_type
!= VDIR
) {
2506 * Lookup the source name.
2508 error
= nfslookup(odvp
, onm
, &ovp
, NULL
, 0, NULL
,
2512 * The source name *should* already exist.
2516 nfs_rw_exit(&odrp
->r_rwlock
);
2517 nfs_rw_exit(&ndrp
->r_rwlock
);
2522 * Compare the two vnodes. If they are the same,
2523 * just release all held vnodes and return success.
2528 nfs_rw_exit(&odrp
->r_rwlock
);
2529 nfs_rw_exit(&ndrp
->r_rwlock
);
2534 * Can't mix and match directories and non-
2535 * directories in rename operations. We already
2536 * know that the target is not a directory. If
2537 * the source is a directory, return an error.
2539 if (ovp
->v_type
== VDIR
) {
2542 nfs_rw_exit(&odrp
->r_rwlock
);
2543 nfs_rw_exit(&ndrp
->r_rwlock
);
2548 * The target file exists, is not the same as
2549 * the source file, and is active. Link it
2550 * to a temporary filename to avoid having
2551 * the server removing the file completely.
2553 tmpname
= newname();
2554 error
= nfs_link(ndvp
, nvp
, tmpname
, cr
, NULL
, 0);
2555 if (error
== EOPNOTSUPP
) {
2556 error
= nfs_rename(ndvp
, nnm
, ndvp
, tmpname
,
2560 kmem_free(tmpname
, MAXNAMELEN
);
2563 nfs_rw_exit(&odrp
->r_rwlock
);
2564 nfs_rw_exit(&ndrp
->r_rwlock
);
2568 mutex_enter(&rp
->r_statelock
);
2569 if (rp
->r_unldvp
== NULL
) {
2571 rp
->r_unldvp
= ndvp
;
2572 if (rp
->r_unlcred
!= NULL
)
2573 crfree(rp
->r_unlcred
);
2576 rp
->r_unlname
= tmpname
;
2578 kmem_free(rp
->r_unlname
, MAXNAMELEN
);
2579 rp
->r_unlname
= tmpname
;
2581 mutex_exit(&rp
->r_statelock
);
2587 * When renaming directories to be a subdirectory of a
2588 * different parent, the dnlc entry for ".." will no
2589 * longer be valid, so it must be removed.
2591 * We do a lookup here to determine whether we are renaming
2592 * a directory and we need to check if we are renaming
2593 * an unlinked file. This might have already been done
2594 * in previous code, so we check ovp == NULL to avoid
2598 error
= nfslookup(odvp
, onm
, &ovp
, NULL
, 0, NULL
, cr
, 0);
2601 * The source name *should* already exist.
2604 nfs_rw_exit(&odrp
->r_rwlock
);
2605 nfs_rw_exit(&ndrp
->r_rwlock
);
2611 ASSERT(ovp
!= NULL
);
2614 dnlc_remove(odvp
, onm
);
2615 dnlc_remove(ndvp
, nnm
);
2617 setdiropargs(&args
.rna_from
, onm
, odvp
);
2618 setdiropargs(&args
.rna_to
, nnm
, ndvp
);
2622 error
= rfs2call(VTOMI(odvp
), RFS_RENAME
,
2623 xdr_rnmargs
, (caddr_t
)&args
,
2624 xdr_enum
, (caddr_t
)&status
, cr
,
2625 &douprintf
, &status
, 0, NULL
);
2627 PURGE_ATTRCACHE(odvp
); /* mod time changed */
2628 PURGE_ATTRCACHE(ndvp
); /* mod time changed */
2631 error
= geterrno(status
);
2633 if (HAVE_RDDIR_CACHE(odrp
))
2634 nfs_purge_rddir_cache(odvp
);
2635 if (HAVE_RDDIR_CACHE(ndrp
))
2636 nfs_purge_rddir_cache(ndvp
);
2638 * when renaming directories to be a subdirectory of a
2639 * different parent, the dnlc entry for ".." will no
2640 * longer be valid, so it must be removed
2644 if (ovp
->v_type
== VDIR
) {
2645 dnlc_remove(ovp
, "..");
2646 if (HAVE_RDDIR_CACHE(rp
))
2647 nfs_purge_rddir_cache(ovp
);
2652 * If we are renaming the unlinked file, update the
2653 * r_unldvp and r_unlname as needed.
2655 mutex_enter(&rp
->r_statelock
);
2656 if (rp
->r_unldvp
!= NULL
) {
2657 if (strcmp(rp
->r_unlname
, onm
) == 0) {
2658 (void) strncpy(rp
->r_unlname
,
2660 rp
->r_unlname
[MAXNAMELEN
- 1] = '\0';
2662 if (ndvp
!= rp
->r_unldvp
) {
2663 VN_RELE(rp
->r_unldvp
);
2664 rp
->r_unldvp
= ndvp
;
2669 mutex_exit(&rp
->r_statelock
);
2672 * System V defines rename to return EEXIST, not
2673 * ENOTEMPTY if the target directory is not empty.
2674 * Over the wire, the error is NFSERR_ENOTEMPTY
2675 * which geterrno maps to ENOTEMPTY.
2677 if (error
== ENOTEMPTY
)
2684 vnevent_rename_dest(nvp
, ndvp
, nnm
, ct
);
2687 vnevent_rename_dest_dir(ndvp
, ct
);
2689 ASSERT(ovp
!= NULL
);
2690 vnevent_rename_src(ovp
, odvp
, onm
, ct
);
2698 nfs_rw_exit(&odrp
->r_rwlock
);
2699 nfs_rw_exit(&ndrp
->r_rwlock
);
2706 nfs_mkdir(vnode_t
*dvp
, char *nm
, struct vattr
*va
, vnode_t
**vpp
, cred_t
*cr
,
2707 caller_context_t
*ct
, int flags
, vsecattr_t
*vsecp
)
2710 struct nfscreatargs args
;
2711 struct nfsdiropres dr
;
2716 if (nfs_zone() != VTOMI(dvp
)->mi_zone
)
2719 setdiropargs(&args
.ca_da
, nm
, dvp
);
2722 * Decide what the group-id and set-gid bit of the created directory
2723 * should be. May have to do a setattr to get the gid right.
2725 error
= setdirgid(dvp
, &va
->va_gid
, cr
);
2728 error
= setdirmode(dvp
, &va
->va_mode
, cr
);
2731 va
->va_mask
|= VATTR_MODE
|VATTR_GID
;
2733 args
.ca_sa
= &args
.ca_sa_buf
;
2734 error
= vattr_to_sattr(va
, args
.ca_sa
);
2736 /* req time field(s) overflow - return immediately */
2741 if (nfs_rw_enter_sig(&drp
->r_rwlock
, RW_WRITER
, INTR(dvp
)))
2744 dnlc_remove(dvp
, nm
);
2750 error
= rfs2call(VTOMI(dvp
), RFS_MKDIR
,
2751 xdr_creatargs
, (caddr_t
)&args
,
2752 xdr_diropres
, (caddr_t
)&dr
, cr
,
2753 &douprintf
, &dr
.dr_status
, 0, NULL
);
2755 PURGE_ATTRCACHE(dvp
); /* mod time changed */
2758 error
= geterrno(dr
.dr_status
);
2760 if (HAVE_RDDIR_CACHE(drp
))
2761 nfs_purge_rddir_cache(dvp
);
2763 * The attributes returned by RFS_MKDIR can not
2764 * be depended upon, so mark the attribute cache
2765 * as purged. A subsequent GETATTR will get the
2766 * correct attributes from the server.
2768 *vpp
= makenfsnode(&dr
.dr_fhandle
, &dr
.dr_attr
,
2769 dvp
->v_vfsp
, t
, cr
, NULL
, NULL
);
2770 PURGE_ATTRCACHE(*vpp
);
2771 dnlc_update(dvp
, nm
, *vpp
);
2774 * Make sure the gid was set correctly.
2775 * If not, try to set it (but don't lose
2776 * any sleep over it).
2778 if (va
->va_gid
!= VTOR(*vpp
)->r_attr
.va_gid
) {
2779 va
->va_mask
= VATTR_GID
;
2780 (void) nfssetattr(*vpp
, va
, 0, cr
);
2783 PURGE_STALE_FH(error
, dvp
, cr
);
2787 nfs_rw_exit(&drp
->r_rwlock
);
2794 nfs_rmdir(vnode_t
*dvp
, char *nm
, vnode_t
*cdir
, cred_t
*cr
,
2795 caller_context_t
*ct
, int flags
)
2798 enum nfsstat status
;
2799 struct nfsdiropargs da
;
2804 if (nfs_zone() != VTOMI(dvp
)->mi_zone
)
2807 if (nfs_rw_enter_sig(&drp
->r_rwlock
, RW_WRITER
, INTR(dvp
)))
2811 * Attempt to prevent a rmdir(".") from succeeding.
2813 error
= nfslookup(dvp
, nm
, &vp
, NULL
, 0, NULL
, cr
, 0);
2815 nfs_rw_exit(&drp
->r_rwlock
);
2821 nfs_rw_exit(&drp
->r_rwlock
);
2825 setdiropargs(&da
, nm
, dvp
);
2828 * First just remove the entry from the name cache, as it
2829 * is most likely an entry for this vp.
2831 dnlc_remove(dvp
, nm
);
2834 * If there vnode reference count is greater than one, then
2835 * there may be additional references in the DNLC which will
2836 * need to be purged. First, trying removing the entry for
2837 * the parent directory and see if that removes the additional
2838 * reference(s). If that doesn't do it, then use dnlc_purge_vp
2839 * to completely remove any references to the directory which
2840 * might still exist in the DNLC.
2842 if (vp
->v_count
> 1) {
2843 dnlc_remove(vp
, "..");
2844 if (vp
->v_count
> 1)
2850 error
= rfs2call(VTOMI(dvp
), RFS_RMDIR
,
2851 xdr_diropargs
, (caddr_t
)&da
,
2852 xdr_enum
, (caddr_t
)&status
, cr
,
2853 &douprintf
, &status
, 0, NULL
);
2855 PURGE_ATTRCACHE(dvp
); /* mod time changed */
2859 nfs_rw_exit(&drp
->r_rwlock
);
2863 error
= geterrno(status
);
2865 if (HAVE_RDDIR_CACHE(drp
))
2866 nfs_purge_rddir_cache(dvp
);
2867 if (HAVE_RDDIR_CACHE(VTOR(vp
)))
2868 nfs_purge_rddir_cache(vp
);
2870 PURGE_STALE_FH(error
, dvp
, cr
);
2872 * System V defines rmdir to return EEXIST, not
2873 * ENOTEMPTY if the directory is not empty. Over
2874 * the wire, the error is NFSERR_ENOTEMPTY which
2875 * geterrno maps to ENOTEMPTY.
2877 if (error
== ENOTEMPTY
)
2882 vnevent_rmdir(vp
, dvp
, nm
, ct
);
2886 nfs_rw_exit(&drp
->r_rwlock
);
2893 nfs_symlink(vnode_t
*dvp
, char *lnm
, struct vattr
*tva
, char *tnm
, cred_t
*cr
,
2894 caller_context_t
*ct
, int flags
)
2897 struct nfsslargs args
;
2898 enum nfsstat status
;
2902 if (nfs_zone() != VTOMI(dvp
)->mi_zone
)
2904 setdiropargs(&args
.sla_from
, lnm
, dvp
);
2905 args
.sla_sa
= &args
.sla_sa_buf
;
2906 error
= vattr_to_sattr(tva
, args
.sla_sa
);
2908 /* req time field(s) overflow - return immediately */
2914 if (nfs_rw_enter_sig(&drp
->r_rwlock
, RW_WRITER
, INTR(dvp
)))
2917 dnlc_remove(dvp
, lnm
);
2921 error
= rfs2call(VTOMI(dvp
), RFS_SYMLINK
,
2922 xdr_slargs
, (caddr_t
)&args
,
2923 xdr_enum
, (caddr_t
)&status
, cr
,
2924 &douprintf
, &status
, 0, NULL
);
2926 PURGE_ATTRCACHE(dvp
); /* mod time changed */
2929 error
= geterrno(status
);
2931 if (HAVE_RDDIR_CACHE(drp
))
2932 nfs_purge_rddir_cache(dvp
);
2934 PURGE_STALE_FH(error
, dvp
, cr
);
2938 nfs_rw_exit(&drp
->r_rwlock
);
2944 static int nfs_readdir_cache_hits
= 0;
2945 static int nfs_readdir_cache_shorts
= 0;
2946 static int nfs_readdir_cache_waits
= 0;
2947 static int nfs_readdir_cache_misses
= 0;
2948 static int nfs_readdir_readahead
= 0;
2951 static int nfs_shrinkreaddir
= 0;
2954 * Read directory entries.
2955 * There are some weird things to look out for here. The uio_offset
2956 * field is either 0 or it is the offset returned from a previous
2957 * readdir. It is an opaque value used by the server to find the
2958 * correct directory block to read. The count field is the number
2959 * of blocks to read on the server. This is advisory only, the server
2960 * may return only one block's worth of entries. Entries may be compressed
2965 nfs_readdir(vnode_t
*vp
, struct uio
*uiop
, cred_t
*cr
, int *eofp
,
2966 caller_context_t
*ct
, int flags
)
2982 ASSERT(nfs_rw_lock_held(&rp
->r_rwlock
, RW_READER
));
2983 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
2986 * Make sure that the directory cache is valid.
2988 if (HAVE_RDDIR_CACHE(rp
)) {
2989 if (nfs_disable_rddir_cache
) {
2991 * Setting nfs_disable_rddir_cache in /etc/system
2992 * allows interoperability with servers that do not
2993 * properly update the attributes of directories.
2994 * Any cached information gets purged before an
2995 * access is made to it.
2997 nfs_purge_rddir_cache(vp
);
2999 error
= nfs_validate_caches(vp
, cr
);
3006 * UGLINESS: SunOS 3.2 servers apparently cannot always handle an
3007 * RFS_READDIR request with rda_count set to more than 0x400. So
3008 * we reduce the request size here purely for compatibility.
3010 * In general, this is no longer required. However, if a server
3011 * is discovered which can not handle requests larger than 1024,
3012 * nfs_shrinkreaddir can be set to 1 to enable this backwards
3015 * In any case, the request size is limited to NFS_MAXDATA bytes.
3017 count
= MIN(uiop
->uio_iov
->iov_len
,
3018 nfs_shrinkreaddir
? 0x400 : NFS_MAXDATA
);
3026 * Short circuit last readdir which always returns 0 bytes.
3027 * This can be done after the directory has been read through
3028 * completely at least once. This will set r_direof which
3029 * can be used to find the value of the last cookie.
3031 mutex_enter(&rp
->r_statelock
);
3032 if (rp
->r_direof
!= NULL
&&
3033 uiop
->uio_offset
== rp
->r_direof
->nfs_ncookie
) {
3034 mutex_exit(&rp
->r_statelock
);
3036 nfs_readdir_cache_shorts
++;
3041 rddir_cache_rele(nrdc
);
3045 * Look for a cache entry. Cache entries are identified
3046 * by the NFS cookie value and the byte count requested.
3048 srdc
.nfs_cookie
= uiop
->uio_offset
;
3049 srdc
.buflen
= count
;
3050 rdc
= avl_find(&rp
->r_dir
, &srdc
, &where
);
3052 rddir_cache_hold(rdc
);
3054 * If the cache entry is in the process of being
3055 * filled in, wait until this completes. The
3056 * RDDIRWAIT bit is set to indicate that someone
3057 * is waiting and then the thread currently
3058 * filling the entry is done, it should do a
3059 * cv_broadcast to wakeup all of the threads
3060 * waiting for it to finish.
3062 if (rdc
->flags
& RDDIR
) {
3063 nfs_rw_exit(&rp
->r_rwlock
);
3064 rdc
->flags
|= RDDIRWAIT
;
3066 nfs_readdir_cache_waits
++;
3068 if (!cv_wait_sig(&rdc
->cv
, &rp
->r_statelock
)) {
3070 * We got interrupted, probably
3071 * the user typed ^C or an alarm
3072 * fired. We free the new entry
3073 * if we allocated one.
3075 mutex_exit(&rp
->r_statelock
);
3076 (void) nfs_rw_enter_sig(&rp
->r_rwlock
,
3078 rddir_cache_rele(rdc
);
3080 rddir_cache_rele(nrdc
);
3083 mutex_exit(&rp
->r_statelock
);
3084 (void) nfs_rw_enter_sig(&rp
->r_rwlock
,
3086 rddir_cache_rele(rdc
);
3090 * Check to see if a readdir is required to
3091 * fill the entry. If so, mark this entry
3092 * as being filled, remove our reference,
3093 * and branch to the code to fill the entry.
3095 if (rdc
->flags
& RDDIRREQ
) {
3096 rdc
->flags
&= ~RDDIRREQ
;
3097 rdc
->flags
|= RDDIR
;
3099 rddir_cache_rele(nrdc
);
3101 mutex_exit(&rp
->r_statelock
);
3106 nfs_readdir_cache_hits
++;
3109 * If an error occurred while attempting
3110 * to fill the cache entry, just return it.
3114 mutex_exit(&rp
->r_statelock
);
3115 rddir_cache_rele(rdc
);
3117 rddir_cache_rele(nrdc
);
3122 * The cache entry is complete and good,
3123 * copyout the dirent structs to the calling
3126 error
= uiomove(rdc
->entries
, rdc
->entlen
, UIO_READ
, uiop
);
3129 * If no error occurred during the copyout,
3130 * update the offset in the uio struct to
3131 * contain the value of the next cookie
3132 * and set the eof value appropriately.
3135 uiop
->uio_offset
= rdc
->nfs_ncookie
;
3141 * Decide whether to do readahead. Don't if
3142 * have already read to the end of directory.
3146 mutex_exit(&rp
->r_statelock
);
3147 rddir_cache_rele(rdc
);
3149 rddir_cache_rele(nrdc
);
3154 * Check to see whether we found an entry
3155 * for the readahead. If so, we don't need
3156 * to do anything further, so free the new
3157 * entry if one was allocated. Otherwise,
3158 * allocate a new entry, add it to the cache,
3159 * and then initiate an asynchronous readdir
3160 * operation to fill it.
3162 srdc
.nfs_cookie
= rdc
->nfs_ncookie
;
3163 srdc
.buflen
= count
;
3164 rrdc
= avl_find(&rp
->r_dir
, &srdc
, &where
);
3167 rddir_cache_rele(nrdc
);
3172 rrdc
= rddir_cache_alloc(KM_NOSLEEP
);
3175 rrdc
->nfs_cookie
= rdc
->nfs_ncookie
;
3176 rrdc
->buflen
= count
;
3177 avl_insert(&rp
->r_dir
, rrdc
, where
);
3178 rddir_cache_hold(rrdc
);
3179 mutex_exit(&rp
->r_statelock
);
3180 rddir_cache_rele(rdc
);
3182 nfs_readdir_readahead
++;
3184 nfs_async_readdir(vp
, rrdc
, cr
, nfsreaddir
);
3189 mutex_exit(&rp
->r_statelock
);
3190 rddir_cache_rele(rdc
);
3195 * Didn't find an entry in the cache. Construct a new empty
3196 * entry and link it into the cache. Other processes attempting
3197 * to access this entry will need to wait until it is filled in.
3199 * Since kmem_alloc may block, another pass through the cache
3200 * will need to be taken to make sure that another process
3201 * hasn't already added an entry to the cache for this request.
3204 mutex_exit(&rp
->r_statelock
);
3205 nrdc
= rddir_cache_alloc(KM_SLEEP
);
3206 nrdc
->nfs_cookie
= uiop
->uio_offset
;
3207 nrdc
->buflen
= count
;
3212 * Add this entry to the cache.
3214 avl_insert(&rp
->r_dir
, nrdc
, where
);
3215 rddir_cache_hold(nrdc
);
3216 mutex_exit(&rp
->r_statelock
);
3221 nfs_readdir_cache_misses
++;
3226 error
= nfsreaddir(vp
, nrdc
, cr
);
3229 * If this operation failed, just return the error which occurred.
3235 * Since the RPC operation will have taken sometime and blocked
3236 * this process, another pass through the cache will need to be
3237 * taken to find the correct cache entry. It is possible that
3238 * the correct cache entry will not be there (although one was
3239 * added) because the directory changed during the RPC operation
3240 * and the readdir cache was flushed. In this case, just start
3241 * over. It is hoped that this will not happen too often... :-)
3249 nfsreaddir(vnode_t
*vp
, rddir_cache
*rdc
, cred_t
*cr
)
3252 struct nfsrddirargs rda
;
3253 struct nfsrddirres rd
;
3258 failinfo_t fi
, *fip
;
3260 ASSERT(nfs_zone() == VTOMI(vp
)->mi_zone
);
3261 count
= rdc
->buflen
;
3266 rda
.rda_fh
= *VTOFH(vp
);
3267 rda
.rda_offset
= rdc
->nfs_cookie
;
3270 * NFS client failover support
3271 * suppress failover unless we have a zero cookie
3273 if (rdc
->nfs_cookie
== (off_t
)0) {
3275 fi
.fhp
= (caddr_t
)&rda
.rda_fh
;
3276 fi
.copyproc
= nfscopyfh
;
3277 fi
.lookupproc
= nfslookup
;
3278 fi
.xattrdirproc
= acl_getxattrdir2
;
3284 rd
.rd_entries
= kmem_alloc(rdc
->buflen
, KM_SLEEP
);
3286 rd
.rd_offset
= rda
.rda_offset
;
3290 if (mi
->mi_io_kstats
) {
3291 mutex_enter(&mi
->mi_lock
);
3292 kstat_runq_enter(KSTAT_IO_PTR(mi
->mi_io_kstats
));
3293 mutex_exit(&mi
->mi_lock
);
3297 rda
.rda_count
= MIN(count
, mi
->mi_curread
);
3298 error
= rfs2call(mi
, RFS_READDIR
,
3299 xdr_rddirargs
, (caddr_t
)&rda
,
3300 xdr_getrddirres
, (caddr_t
)&rd
, cr
,
3301 &douprintf
, &rd
.rd_status
, 0, fip
);
3302 } while (error
== ENFS_TRYAGAIN
);
3304 if (mi
->mi_io_kstats
) {
3305 mutex_enter(&mi
->mi_lock
);
3306 kstat_runq_exit(KSTAT_IO_PTR(mi
->mi_io_kstats
));
3307 mutex_exit(&mi
->mi_lock
);
3311 * Since we are actually doing a READDIR RPC, we must have
3312 * exclusive access to the cache entry being filled. Thus,
3313 * it is safe to update all fields except for the flags
3314 * field. The r_statelock in the rnode must be held to
3315 * prevent two different threads from simultaneously
3316 * attempting to update the flags field. This can happen
3317 * if we are turning off RDDIR and the other thread is
3318 * trying to set RDDIRWAIT.
3320 ASSERT(rdc
->flags
& RDDIR
);
3322 error
= geterrno(rd
.rd_status
);
3324 rdc
->nfs_ncookie
= rd
.rd_offset
;
3325 rdc
->eof
= rd
.rd_eof
? 1 : 0;
3326 rdc
->entlen
= rd
.rd_size
;
3327 ASSERT(rdc
->entlen
<= rdc
->buflen
);
3329 rdc
->entries
= rddir_cache_buf_alloc(rdc
->buflen
,
3332 rdc
->entries
= kmem_alloc(rdc
->buflen
, KM_SLEEP
);
3334 bcopy(rd
.rd_entries
, rdc
->entries
, rdc
->entlen
);
3336 if (mi
->mi_io_kstats
) {
3337 mutex_enter(&mi
->mi_lock
);
3338 KSTAT_IO_PTR(mi
->mi_io_kstats
)->reads
++;
3339 KSTAT_IO_PTR(mi
->mi_io_kstats
)->nread
+=
3341 mutex_exit(&mi
->mi_lock
);
3344 PURGE_STALE_FH(error
, vp
, cr
);
3348 rdc
->entries
= NULL
;
3351 kmem_free(rd
.rd_entries
, rdc
->buflen
);
3353 mutex_enter(&rp
->r_statelock
);
3354 rdc
->flags
&= ~RDDIR
;
3355 if (rdc
->flags
& RDDIRWAIT
) {
3356 rdc
->flags
&= ~RDDIRWAIT
;
3357 cv_broadcast(&rdc
->cv
);
3360 rdc
->flags
|= RDDIRREQ
;
3361 mutex_exit(&rp
->r_statelock
);
3363 rddir_cache_rele(rdc
);
3369 static int nfs_bio_do_stop
= 0;
3373 nfs_bio(struct buf
*bp
, cred_t
*cr
)
3375 rnode_t
*rp
= VTOR(bp
->b_vp
);
3381 DTRACE_IO1(start
, struct buf
*, bp
);
3383 ASSERT(nfs_zone() == VTOMI(bp
->b_vp
)->mi_zone
);
3384 offset
= dbtob(bp
->b_blkno
);
3386 if (bp
->b_flags
& B_READ
) {
3387 mutex_enter(&rp
->r_statelock
);
3388 if (rp
->r_cred
!= NULL
) {
3397 mutex_exit(&rp
->r_statelock
);
3399 error
= bp
->b_error
= nfsread(bp
->b_vp
, bp
->b_un
.b_addr
,
3400 offset
, bp
->b_bcount
, &bp
->b_resid
, cred
);
3406 * Didn't get it all because we hit EOF,
3407 * zero all the memory beyond the EOF.
3409 /* bzero(rdaddr + */
3410 bzero(bp
->b_un
.b_addr
+
3411 bp
->b_bcount
- bp
->b_resid
, bp
->b_resid
);
3413 mutex_enter(&rp
->r_statelock
);
3414 if (bp
->b_resid
== bp
->b_bcount
&&
3415 offset
>= rp
->r_size
) {
3417 * We didn't read anything at all as we are
3418 * past EOF. Return an error indicator back
3419 * but don't destroy the pages (yet).
3423 mutex_exit(&rp
->r_statelock
);
3424 } else if (error
== EACCES
) {
3425 mutex_enter(&rp
->r_statelock
);
3427 if (rp
->r_cred
!= NULL
)
3433 mutex_exit(&rp
->r_statelock
);
3436 mutex_exit(&rp
->r_statelock
);
3439 if (!(rp
->r_flags
& RSTALE
)) {
3440 mutex_enter(&rp
->r_statelock
);
3441 if (rp
->r_cred
!= NULL
) {
3450 mutex_exit(&rp
->r_statelock
);
3452 mutex_enter(&rp
->r_statelock
);
3453 count
= MIN(bp
->b_bcount
, rp
->r_size
- offset
);
3454 mutex_exit(&rp
->r_statelock
);
3456 cmn_err(CE_PANIC
, "nfs_bio: write count < 0");
3459 zcmn_err(getzoneid(), CE_WARN
,
3460 "nfs_bio: zero length write at %d",
3462 nfs_printfhandle(&rp
->r_fh
);
3463 if (nfs_bio_do_stop
)
3464 debug_enter("nfs_bio");
3467 error
= nfswrite(bp
->b_vp
, bp
->b_un
.b_addr
, offset
,
3469 if (error
== EACCES
) {
3470 mutex_enter(&rp
->r_statelock
);
3472 if (rp
->r_cred
!= NULL
)
3479 mutex_exit(&rp
->r_statelock
);
3482 mutex_exit(&rp
->r_statelock
);
3484 bp
->b_error
= error
;
3485 if (error
&& error
!= EINTR
) {
3487 * Don't print EDQUOT errors on the console.
3488 * Don't print asynchronous EACCES errors.
3489 * Don't print EFBIG errors.
3490 * Print all other write errors.
3492 if (error
!= EDQUOT
&& error
!= EFBIG
&&
3494 !(bp
->b_flags
& B_ASYNC
)))
3495 nfs_write_error(bp
->b_vp
, error
, cred
);
3497 * Update r_error and r_flags as appropriate.
3498 * If the error was ESTALE, then mark the
3499 * rnode as not being writeable and save
3500 * the error status. Otherwise, save any
3501 * errors which occur from asynchronous
3502 * page invalidations. Any errors occurring
3503 * from other operations should be saved
3506 mutex_enter(&rp
->r_statelock
);
3507 if (error
== ESTALE
) {
3508 rp
->r_flags
|= RSTALE
;
3510 rp
->r_error
= error
;
3511 } else if (!rp
->r_error
&&
3513 (B_INVAL
|B_FORCE
|B_ASYNC
)) ==
3514 (B_INVAL
|B_FORCE
|B_ASYNC
)) {
3515 rp
->r_error
= error
;
3517 mutex_exit(&rp
->r_statelock
);
3521 error
= rp
->r_error
;
3523 * A close may have cleared r_error, if so,
3524 * propagate ESTALE error return properly
3531 if (error
!= 0 && error
!= NFS_EOF
)
3532 bp
->b_flags
|= B_ERROR
;
3534 DTRACE_IO1(done
, struct buf
*, bp
);
3541 nfs_fid(vnode_t
*vp
, fid_t
*fidp
, caller_context_t
*ct
)
3548 if (fidp
->fid_len
< (sizeof (struct nfs_fid
) - sizeof (short))) {
3549 fidp
->fid_len
= sizeof (struct nfs_fid
) - sizeof (short);
3552 fp
= (struct nfs_fid
*)fidp
;
3554 fp
->nf_len
= sizeof (struct nfs_fid
) - sizeof (short);
3555 bcopy(rp
->r_fh
.fh_buf
, fp
->nf_data
, NFS_FHSIZE
);
3561 nfs_rwlock(vnode_t
*vp
, int write_lock
, caller_context_t
*ctp
)
3563 rnode_t
*rp
= VTOR(vp
);
3566 (void) nfs_rw_enter_sig(&rp
->r_rwlock
, RW_READER
, FALSE
);
3567 return (V_WRITELOCK_FALSE
);
3570 if ((rp
->r_flags
& RDIRECTIO
) || (VTOMI(vp
)->mi_flags
& MI_DIRECTIO
)) {
3571 (void) nfs_rw_enter_sig(&rp
->r_rwlock
, RW_READER
, FALSE
);
3572 if (rp
->r_mapcnt
== 0 && !vn_has_cached_data(vp
))
3573 return (V_WRITELOCK_FALSE
);
3574 nfs_rw_exit(&rp
->r_rwlock
);
3577 (void) nfs_rw_enter_sig(&rp
->r_rwlock
, RW_WRITER
, FALSE
);
3578 return (V_WRITELOCK_TRUE
);
3583 nfs_rwunlock(vnode_t
*vp
, int write_lock
, caller_context_t
*ctp
)
3585 rnode_t
*rp
= VTOR(vp
);
3587 nfs_rw_exit(&rp
->r_rwlock
);
3592 nfs_seek(vnode_t
*vp
, offset_t ooff
, offset_t
*noffp
, caller_context_t
*ct
)
3596 * Because we stuff the readdir cookie into the offset field
3597 * someone may attempt to do an lseek with the cookie which
3598 * we want to succeed.
3600 if (vp
->v_type
== VDIR
)
3602 if (*noffp
< 0 || *noffp
> MAXOFF32_T
)
3608 * number of NFS_MAXDATA blocks to read ahead
3609 * optimized for 100 base-T.
3611 static int nfs_nra
= 4;
3614 static int nfs_lostpage
= 0; /* number of times we lost original page */
3618 * Return all the pages from [off..off+len) in file
3622 nfs_getpage(vnode_t
*vp
, offset_t off
, size_t len
, uint_t
*protp
,
3623 page_t
*pl
[], size_t plsz
, struct seg
*seg
, caddr_t addr
,
3624 enum seg_rw rw
, cred_t
*cr
, caller_context_t
*ct
)
3630 if (vp
->v_flag
& VNOMAP
)
3633 ASSERT(off
<= MAXOFF32_T
);
3634 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
3640 * Now valididate that the caches are up to date.
3642 error
= nfs_validate_caches(vp
, cr
);
3649 mutex_enter(&rp
->r_statelock
);
3652 * Don't create dirty pages faster than they
3653 * can be cleaned so that the system doesn't
3654 * get imbalanced. If the async queue is
3655 * maxed out, then wait for it to drain before
3656 * creating more dirty pages. Also, wait for
3657 * any threads doing pagewalks in the vop_getattr
3658 * entry points so that they don't block for
3661 if (rw
== S_CREATE
) {
3662 while ((mi
->mi_max_threads
!= 0 &&
3663 rp
->r_awcount
> 2 * mi
->mi_max_threads
) ||
3665 cv_wait(&rp
->r_cv
, &rp
->r_statelock
);
3669 * If we are getting called as a side effect of an nfs_write()
3670 * operation the local file size might not be extended yet.
3671 * In this case we want to be able to return pages of zeroes.
3673 if (off
+ len
> rp
->r_size
+ PAGEOFFSET
&& seg
!= segkmap
) {
3674 mutex_exit(&rp
->r_statelock
);
3675 return (EFAULT
); /* beyond EOF */
3678 mutex_exit(&rp
->r_statelock
);
3680 error
= pvn_getpages(nfs_getapage
, vp
, off
, len
, protp
, pl
, plsz
,
3685 nfs_purge_caches(vp
, NFS_NOPURGE_DNLC
, cr
);
3688 PURGE_STALE_FH(error
, vp
, cr
);
3695 * Called from pvn_getpages to get a particular page.
3699 nfs_getapage(vnode_t
*vp
, uoff_t off
, size_t len
, uint_t
*protp
,
3700 page_t
*pl
[], size_t plsz
, struct seg
*seg
, caddr_t addr
,
3701 enum seg_rw rw
, cred_t
*cr
)
3715 int readahead_issued
= 0;
3716 int ra_window
; /* readahead window */
3719 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
3722 bsize
= MAX(vp
->v_vfsp
->vfs_bsize
, PAGESIZE
);
3734 blkoff
= lbn
* bsize
;
3737 * Queueing up the readahead before doing the synchronous read
3738 * results in a significant increase in read throughput because
3739 * of the increased parallelism between the async threads and
3740 * the process context.
3742 if ((off
& ((vp
->v_vfsp
->vfs_bsize
) - 1)) == 0 &&
3744 !(vp
->v_flag
& VNOCACHE
)) {
3745 mutex_enter(&rp
->r_statelock
);
3748 * Calculate the number of readaheads to do.
3749 * a) No readaheads at offset = 0.
3750 * b) Do maximum(nfs_nra) readaheads when the readahead
3752 * c) Do readaheads between 1 to (nfs_nra - 1) depending
3753 * upon how far the readahead window is open or close.
3754 * d) No readaheads if rp->r_nextr is not within the scope
3755 * of the readahead window (random i/o).
3760 else if (blkoff
== rp
->r_nextr
)
3761 readahead
= nfs_nra
;
3762 else if (rp
->r_nextr
> blkoff
&&
3763 ((ra_window
= (rp
->r_nextr
- blkoff
) / bsize
)
3765 readahead
= nfs_nra
- ra_window
;
3769 rablkoff
= rp
->r_nextr
;
3770 while (readahead
> 0 && rablkoff
+ bsize
< rp
->r_size
) {
3771 mutex_exit(&rp
->r_statelock
);
3772 if (nfs_async_readahead(vp
, rablkoff
+ bsize
,
3773 addr
+ (rablkoff
+ bsize
- off
), seg
, cr
,
3774 nfs_readahead
) < 0) {
3775 mutex_enter(&rp
->r_statelock
);
3781 * Indicate that we did a readahead so
3782 * readahead offset is not updated
3783 * by the synchronous read below.
3785 readahead_issued
= 1;
3786 mutex_enter(&rp
->r_statelock
);
3788 * set readahead offset to
3789 * offset of last async readahead
3792 rp
->r_nextr
= rablkoff
;
3794 mutex_exit(&rp
->r_statelock
);
3798 if ((pagefound
= page_exists(&vp
->v_object
, off
)) == NULL
) {
3800 (void) nfs_async_readahead(vp
, blkoff
, addr
, seg
, cr
,
3802 } else if (rw
== S_CREATE
) {
3804 * Block for this page is not allocated, or the offset
3805 * is beyond the current allocation size, or we're
3806 * allocating a swap slot and the page was not found,
3807 * so allocate it and return a zero page.
3809 if ((pp
= page_create_va(&vp
->v_object
, off
,
3810 PAGESIZE
, PG_WAIT
, seg
, addr
)) == NULL
)
3811 cmn_err(CE_PANIC
, "nfs_getapage: page_create");
3813 mutex_enter(&rp
->r_statelock
);
3814 rp
->r_nextr
= off
+ PAGESIZE
;
3815 mutex_exit(&rp
->r_statelock
);
3818 * Need to go to server to get a BLOCK, exception to
3819 * that being while reading at offset = 0 or doing
3820 * random i/o, in that case read only a PAGE.
3822 mutex_enter(&rp
->r_statelock
);
3823 if (blkoff
< rp
->r_size
&&
3824 blkoff
+ bsize
>= rp
->r_size
) {
3826 * If only a block or less is left in
3827 * the file, read all that is remaining.
3829 if (rp
->r_size
<= off
) {
3831 * Trying to access beyond EOF,
3832 * set up to get at least one page.
3834 blksize
= off
+ PAGESIZE
- blkoff
;
3836 blksize
= rp
->r_size
- blkoff
;
3837 } else if ((off
== 0) ||
3838 (off
!= rp
->r_nextr
&& !readahead_issued
)) {
3840 blkoff
= off
; /* block = page here */
3843 mutex_exit(&rp
->r_statelock
);
3845 pp
= pvn_read_kluster(vp
, off
, seg
, addr
, &io_off
,
3846 &io_len
, blkoff
, blksize
, 0);
3849 * Some other thread has entered the page,
3856 * Now round the request size up to page boundaries.
3857 * This ensures that the entire page will be
3858 * initialized to zeroes if EOF is encountered.
3860 io_len
= ptob(btopr(io_len
));
3862 bp
= pageio_setup(pp
, io_len
, vp
, B_READ
);
3866 * pageio_setup should have set b_addr to 0. This
3867 * is correct since we want to do I/O on a page
3868 * boundary. bp_mapin will use this addr to calculate
3869 * an offset, and then set b_addr to the kernel virtual
3870 * address it allocated for us.
3872 ASSERT(bp
->b_un
.b_addr
== 0);
3876 bp
->b_lblkno
= lbtodb(io_off
);
3878 bp
->b_offset
= (offset_t
)off
;
3882 * If doing a write beyond what we believe is EOF,
3883 * don't bother trying to read the pages from the
3884 * server, we'll just zero the pages here. We
3885 * don't check that the rw flag is S_WRITE here
3886 * because some implementations may attempt a
3887 * read access to the buffer before copying data.
3889 mutex_enter(&rp
->r_statelock
);
3890 if (io_off
>= rp
->r_size
&& seg
== segkmap
) {
3891 mutex_exit(&rp
->r_statelock
);
3892 bzero(bp
->b_un
.b_addr
, io_len
);
3894 mutex_exit(&rp
->r_statelock
);
3895 error
= nfs_bio(bp
, cr
);
3899 * Unmap the buffer before freeing it.
3904 if (error
== NFS_EOF
) {
3906 * If doing a write system call just return
3907 * zeroed pages, else user tried to get pages
3908 * beyond EOF, return error. We don't check
3909 * that the rw flag is S_WRITE here because
3910 * some implementations may attempt a read
3911 * access to the buffer before copying data.
3919 if (!readahead_issued
&& !error
) {
3920 mutex_enter(&rp
->r_statelock
);
3921 rp
->r_nextr
= io_off
+ io_len
;
3922 mutex_exit(&rp
->r_statelock
);
3933 pvn_read_done(pp
, B_ERROR
);
3938 se_t se
= (rw
== S_CREATE
? SE_EXCL
: SE_SHARED
);
3941 * Page exists in the cache, acquire the appropriate lock.
3942 * If this fails, start all over again.
3944 if ((pp
= page_lookup(&vp
->v_object
, off
, se
)) == NULL
) {
3956 pvn_plist_init(pp
, pl
, plsz
, off
, io_len
, rw
);
3962 nfs_readahead(vnode_t
*vp
, uoff_t blkoff
, caddr_t addr
, struct seg
*seg
,
3970 uint_t bsize
, blksize
;
3971 rnode_t
*rp
= VTOR(vp
);
3973 ASSERT(nfs_zone() == VTOMI(vp
)->mi_zone
);
3975 bsize
= MAX(vp
->v_vfsp
->vfs_bsize
, PAGESIZE
);
3977 mutex_enter(&rp
->r_statelock
);
3978 if (blkoff
< rp
->r_size
&& blkoff
+ bsize
> rp
->r_size
) {
3980 * If less than a block left in file read less
3983 blksize
= rp
->r_size
- blkoff
;
3986 mutex_exit(&rp
->r_statelock
);
3988 pp
= pvn_read_kluster(vp
, blkoff
, segkmap
, addr
,
3989 &io_off
, &io_len
, blkoff
, blksize
, 1);
3991 * The isra flag passed to the kluster function is 1, we may have
3992 * gotten a return value of NULL for a variety of reasons (# of free
3993 * pages < minfree, someone entered the page on the vnode etc). In all
3994 * cases, we want to punt on the readahead.
4000 * Now round the request size up to page boundaries.
4001 * This ensures that the entire page will be
4002 * initialized to zeroes if EOF is encountered.
4004 io_len
= ptob(btopr(io_len
));
4006 bp
= pageio_setup(pp
, io_len
, vp
, B_READ
);
4010 * pageio_setup should have set b_addr to 0. This is correct since
4011 * we want to do I/O on a page boundary. bp_mapin() will use this addr
4012 * to calculate an offset, and then set b_addr to the kernel virtual
4013 * address it allocated for us.
4015 ASSERT(bp
->b_un
.b_addr
== 0);
4019 bp
->b_lblkno
= lbtodb(io_off
);
4021 bp
->b_offset
= (offset_t
)blkoff
;
4025 * If doing a write beyond what we believe is EOF, don't bother trying
4026 * to read the pages from the server, we'll just zero the pages here.
4027 * We don't check that the rw flag is S_WRITE here because some
4028 * implementations may attempt a read access to the buffer before
4031 mutex_enter(&rp
->r_statelock
);
4032 if (io_off
>= rp
->r_size
&& seg
== segkmap
) {
4033 mutex_exit(&rp
->r_statelock
);
4034 bzero(bp
->b_un
.b_addr
, io_len
);
4037 mutex_exit(&rp
->r_statelock
);
4038 error
= nfs_bio(bp
, cr
);
4039 if (error
== NFS_EOF
)
4044 * Unmap the buffer before freeing it.
4049 pvn_read_done(pp
, error
? B_READ
| B_ERROR
: B_READ
);
4052 * In case of error set readahead offset
4053 * to the lowest offset.
4054 * pvn_read_done() calls VN_DISPOSE to destroy the pages
4056 if (error
&& rp
->r_nextr
> io_off
) {
4057 mutex_enter(&rp
->r_statelock
);
4058 if (rp
->r_nextr
> io_off
)
4059 rp
->r_nextr
= io_off
;
4060 mutex_exit(&rp
->r_statelock
);
4065 * Flags are composed of {B_INVAL, B_FREE, B_DONTNEED, B_FORCE}
4066 * If len == 0, do from off to EOF.
4068 * The normal cases should be len == 0 && off == 0 (entire vp list),
4069 * len == MAXBSIZE (from segmap_release actions), and len == PAGESIZE
4074 nfs_putpage(vnode_t
*vp
, offset_t off
, size_t len
, int flags
, cred_t
*cr
,
4075 caller_context_t
*ct
)
4083 * XXX - Why should this check be made here?
4085 if (vp
->v_flag
& VNOMAP
)
4088 if (len
== 0 && !(flags
& B_INVAL
) && vn_is_readonly(vp
))
4091 if (!(flags
& B_ASYNC
) && nfs_zone() != VTOMI(vp
)->mi_zone
)
4093 ASSERT(off
<= MAXOFF32_T
);
4096 mutex_enter(&rp
->r_statelock
);
4098 mutex_exit(&rp
->r_statelock
);
4099 error
= nfs_putpages(vp
, off
, len
, flags
, cr
);
4100 mutex_enter(&rp
->r_statelock
);
4102 cv_broadcast(&rp
->r_cv
);
4103 mutex_exit(&rp
->r_statelock
);
4109 * Write out a single page, possibly klustering adjacent dirty pages.
4112 nfs_putapage(vnode_t
*vp
, page_t
*pp
, uoff_t
*offp
, size_t *lenp
,
4113 int flags
, cred_t
*cr
)
4123 ASSERT(!vn_is_readonly(vp
));
4126 ASSERT((flags
& B_ASYNC
) || nfs_zone() == VTOMI(vp
)->mi_zone
);
4129 ASSERT(rp
->r_count
> 0);
4131 ASSERT(pp
->p_offset
<= MAXOFF32_T
);
4133 bsize
= MAX(vp
->v_vfsp
->vfs_bsize
, PAGESIZE
);
4134 lbn
= pp
->p_offset
/ bsize
;
4135 lbn_off
= lbn
* bsize
;
4138 * Find a kluster that fits in one block, or in
4139 * one page if pages are bigger than blocks. If
4140 * there is less file space allocated than a whole
4141 * page, we'll shorten the i/o request below.
4143 pp
= pvn_write_kluster(vp
, pp
, &io_off
, &io_len
, lbn_off
,
4144 roundup(bsize
, PAGESIZE
), flags
);
4147 * pvn_write_kluster shouldn't have returned a page with offset
4148 * behind the original page we were given. Verify that.
4150 ASSERT((pp
->p_offset
/ bsize
) >= lbn
);
4153 * Now pp will have the list of kept dirty pages marked for
4154 * write back. It will also handle invalidation and freeing
4155 * of pages that are not dirty. Check for page length rounding
4158 if (io_off
+ io_len
> lbn_off
+ bsize
) {
4159 ASSERT((io_off
+ io_len
) - (lbn_off
+ bsize
) < PAGESIZE
);
4160 io_len
= lbn_off
+ bsize
- io_off
;
4163 * The RMODINPROGRESS flag makes sure that nfs(3)_bio() sees a
4164 * consistent value of r_size. RMODINPROGRESS is set in writerp().
4165 * When RMODINPROGRESS is set it indicates that a uiomove() is in
4166 * progress and the r_size has not been made consistent with the
4167 * new size of the file. When the uiomove() completes the r_size is
4168 * updated and the RMODINPROGRESS flag is cleared.
4170 * The RMODINPROGRESS flag makes sure that nfs(3)_bio() sees a
4171 * consistent value of r_size. Without this handshaking, it is
4172 * possible that nfs(3)_bio() picks up the old value of r_size
4173 * before the uiomove() in writerp() completes. This will result
4174 * in the write through nfs(3)_bio() being dropped.
4176 * More precisely, there is a window between the time the uiomove()
4177 * completes and the time the r_size is updated. If a fop_putpage()
4178 * operation intervenes in this window, the page will be picked up,
4179 * because it is dirty (it will be unlocked, unless it was
4180 * pagecreate'd). When the page is picked up as dirty, the dirty
4181 * bit is reset (pvn_getdirty()). In nfs(3)write(), r_size is
4182 * checked. This will still be the old size. Therefore the page will
4183 * not be written out. When segmap_release() calls fop_putpage(),
4184 * the page will be found to be clean and the write will be dropped.
4186 if (rp
->r_flags
& RMODINPROGRESS
) {
4187 mutex_enter(&rp
->r_statelock
);
4188 if ((rp
->r_flags
& RMODINPROGRESS
) &&
4189 rp
->r_modaddr
+ MAXBSIZE
> io_off
&&
4190 rp
->r_modaddr
< io_off
+ io_len
) {
4193 * A write is in progress for this region of the file.
4194 * If we did not detect RMODINPROGRESS here then this
4195 * path through nfs_putapage() would eventually go to
4196 * nfs(3)_bio() and may not write out all of the data
4197 * in the pages. We end up losing data. So we decide
4198 * to set the modified bit on each page in the page
4199 * list and mark the rnode with RDIRTY. This write
4200 * will be restarted at some later time.
4203 while (plist
!= NULL
) {
4205 page_sub(&plist
, pp
);
4210 rp
->r_flags
|= RDIRTY
;
4211 mutex_exit(&rp
->r_statelock
);
4218 mutex_exit(&rp
->r_statelock
);
4221 if (flags
& B_ASYNC
) {
4222 error
= nfs_async_putapage(vp
, pp
, io_off
, io_len
, flags
, cr
,
4225 error
= nfs_sync_putapage(vp
, pp
, io_off
, io_len
, flags
, cr
);
4235 nfs_sync_putapage(vnode_t
*vp
, page_t
*pp
, uoff_t io_off
, size_t io_len
,
4236 int flags
, cred_t
*cr
)
4243 ASSERT(nfs_zone() == VTOMI(vp
)->mi_zone
);
4244 error
= nfs_rdwrlbn(vp
, pp
, io_off
, io_len
, flags
, cr
);
4248 if ((error
== ENOSPC
|| error
== EDQUOT
|| error
== EACCES
) &&
4249 (flags
& (B_INVAL
|B_FORCE
)) != (B_INVAL
|B_FORCE
)) {
4250 if (!(rp
->r_flags
& ROUTOFSPACE
)) {
4251 mutex_enter(&rp
->r_statelock
);
4252 rp
->r_flags
|= ROUTOFSPACE
;
4253 mutex_exit(&rp
->r_statelock
);
4256 pvn_write_done(pp
, flags
);
4258 * If this was not an async thread, then try again to
4259 * write out the pages, but this time, also destroy
4260 * them whether or not the write is successful. This
4261 * will prevent memory from filling up with these
4262 * pages and destroying them is the only alternative
4263 * if they can't be written out.
4265 * Don't do this if this is an async thread because
4266 * when the pages are unlocked in pvn_write_done,
4267 * some other thread could have come along, locked
4268 * them, and queued for an async thread. It would be
4269 * possible for all of the async threads to be tied
4270 * up waiting to lock the pages again and they would
4271 * all already be locked and waiting for an async
4272 * thread to handle them. Deadlock.
4274 if (!(flags
& B_ASYNC
)) {
4275 error
= nfs_putpage(vp
, io_off
, io_len
,
4276 B_INVAL
| B_FORCE
, cr
, NULL
);
4281 else if (rp
->r_flags
& ROUTOFSPACE
) {
4282 mutex_enter(&rp
->r_statelock
);
4283 rp
->r_flags
&= ~ROUTOFSPACE
;
4284 mutex_exit(&rp
->r_statelock
);
4286 pvn_write_done(pp
, flags
);
4294 nfs_map(vnode_t
*vp
, offset_t off
, struct as
*as
, caddr_t
*addrp
,
4295 size_t len
, uchar_t prot
, uchar_t maxprot
, uint_t flags
, cred_t
*cr
,
4296 caller_context_t
*ct
)
4298 struct segvn_crargs vn_a
;
4303 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
4306 if (vp
->v_flag
& VNOMAP
)
4309 if (off
> MAXOFF32_T
)
4312 if (off
< 0 || off
+ len
< 0)
4315 if (vp
->v_type
!= VREG
)
4319 * If there is cached data and if close-to-open consistency
4320 * checking is not turned off and if the file system is not
4321 * mounted readonly, then force an over the wire getattr.
4322 * Otherwise, just invoke nfsgetattr to get a copy of the
4323 * attributes. The attribute cache will be used unless it
4324 * is timed out and if it is, then an over the wire getattr
4327 va
.va_mask
= VATTR_ALL
;
4328 if (vn_has_cached_data(vp
) &&
4329 !(VTOMI(vp
)->mi_flags
& MI_NOCTO
) && !vn_is_readonly(vp
))
4330 error
= nfs_getattr_otw(vp
, &va
, cr
);
4332 error
= nfsgetattr(vp
, &va
, cr
);
4337 * Check to see if the vnode is currently marked as not cachable.
4338 * This means portions of the file are locked (through fop_frlock).
4339 * In this case the map request must be refused. We use
4340 * rp->r_lkserlock to avoid a race with concurrent lock requests.
4345 * Atomically increment r_inmap after acquiring r_rwlock. The
4346 * idea here is to acquire r_rwlock to block read/write and
4347 * not to protect r_inmap. r_inmap will inform nfs_read/write()
4348 * that we are in nfs_map(). Now, r_rwlock is acquired in order
4349 * and we can prevent the deadlock that would have occurred
4350 * when nfs_addmap() would have acquired it out of order.
4352 * Since we are not protecting r_inmap by any lock, we do not
4353 * hold any lock when we decrement it. We atomically decrement
4354 * r_inmap after we release r_lkserlock.
4357 if (nfs_rw_enter_sig(&rp
->r_rwlock
, RW_WRITER
, INTR(vp
)))
4359 atomic_inc_uint(&rp
->r_inmap
);
4360 nfs_rw_exit(&rp
->r_rwlock
);
4362 if (nfs_rw_enter_sig(&rp
->r_lkserlock
, RW_READER
, INTR(vp
))) {
4363 atomic_dec_uint(&rp
->r_inmap
);
4366 if (vp
->v_flag
& VNOCACHE
) {
4372 * Don't allow concurrent locks and mapping if mandatory locking is
4375 if ((flk_has_remote_locks(vp
) || lm_has_sleep(vp
)) &&
4376 MANDLOCK(vp
, va
.va_mode
)) {
4382 error
= choose_addr(as
, addrp
, len
, off
, ADDR_VACALIGN
, flags
);
4390 vn_a
.type
= (flags
& MAP_TYPE
);
4391 vn_a
.prot
= (uchar_t
)prot
;
4392 vn_a
.maxprot
= (uchar_t
)maxprot
;
4393 vn_a
.flags
= (flags
& ~MAP_TYPE
);
4397 vn_a
.lgrp_mem_policy_flags
= 0;
4399 error
= as_map(as
, *addrp
, len
, segvn_create
, &vn_a
);
4403 nfs_rw_exit(&rp
->r_lkserlock
);
4404 atomic_dec_uint(&rp
->r_inmap
);
4410 nfs_addmap(vnode_t
*vp
, offset_t off
, struct as
*as
, caddr_t addr
,
4411 size_t len
, uchar_t prot
, uchar_t maxprot
, uint_t flags
, cred_t
*cr
,
4412 caller_context_t
*ct
)
4416 if (vp
->v_flag
& VNOMAP
)
4418 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
4422 atomic_add_long((ulong_t
*)&rp
->r_mapcnt
, btopr(len
));
4429 nfs_frlock(vnode_t
*vp
, int cmd
, struct flock64
*bfp
, int flag
, offset_t offset
,
4430 struct flk_callback
*flk_cbp
, cred_t
*cr
, caller_context_t
*ct
)
4436 int error
= 0, intr
= INTR(vp
);
4438 /* check for valid cmd parameter */
4439 if (cmd
!= F_GETLK
&& cmd
!= F_SETLK
&& cmd
!= F_SETLKW
)
4441 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
4444 /* Verify l_type. */
4445 switch (bfp
->l_type
) {
4447 if (cmd
!= F_GETLK
&& !(flag
& FREAD
))
4451 if (cmd
!= F_GETLK
&& !(flag
& FWRITE
))
4462 /* check the validity of the lock range */
4463 if (rc
= flk_convert_lock_data(vp
, bfp
, &start
, &end
, offset
))
4465 if (rc
= flk_check_lock_data(start
, end
, MAXOFF32_T
))
4469 * If the filesystem is mounted using local locking, pass the
4470 * request off to the local locking code.
4472 if (VTOMI(vp
)->mi_flags
& MI_LLOCK
) {
4473 if (offset
> MAXOFF32_T
)
4475 if (cmd
== F_SETLK
|| cmd
== F_SETLKW
) {
4477 * For complete safety, we should be holding
4478 * r_lkserlock. However, we can't call
4479 * lm_safelock and then fs_frlock while
4480 * holding r_lkserlock, so just invoke
4481 * lm_safelock and expect that this will
4482 * catch enough of the cases.
4484 if (!lm_safelock(vp
, bfp
, cr
))
4487 return (fs_frlock(vp
, cmd
, bfp
, flag
, offset
, flk_cbp
, cr
, ct
));
4493 * Check whether the given lock request can proceed, given the
4494 * current file mappings.
4496 if (nfs_rw_enter_sig(&rp
->r_lkserlock
, RW_WRITER
, intr
))
4498 if (cmd
== F_SETLK
|| cmd
== F_SETLKW
) {
4499 if (!lm_safelock(vp
, bfp
, cr
)) {
4506 * Flush the cache after waiting for async I/O to finish. For new
4507 * locks, this is so that the process gets the latest bits from the
4508 * server. For unlocks, this is so that other clients see the
4509 * latest bits once the file has been unlocked. If currently dirty
4510 * pages can't be flushed, then don't allow a lock to be set. But
4511 * allow unlocks to succeed, to avoid having orphan locks on the
4514 if (cmd
!= F_GETLK
) {
4515 mutex_enter(&rp
->r_statelock
);
4516 while (rp
->r_count
> 0) {
4518 klwp_t
*lwp
= ttolwp(curthread
);
4522 if (cv_wait_sig(&rp
->r_cv
, &rp
->r_statelock
)
4532 cv_wait(&rp
->r_cv
, &rp
->r_statelock
);
4534 mutex_exit(&rp
->r_statelock
);
4537 error
= nfs_putpage(vp
, 0, 0, B_INVAL
, cr
, ct
);
4539 if (error
== ENOSPC
|| error
== EDQUOT
) {
4540 mutex_enter(&rp
->r_statelock
);
4542 rp
->r_error
= error
;
4543 mutex_exit(&rp
->r_statelock
);
4545 if (bfp
->l_type
!= F_UNLCK
) {
4552 lm_fh
.n_len
= sizeof (fhandle_t
);
4553 lm_fh
.n_bytes
= (char *)VTOFH(vp
);
4556 * Call the lock manager to do the real work of contacting
4557 * the server and obtaining the lock.
4559 rc
= lm_frlock(vp
, cmd
, bfp
, flag
, offset
, cr
, &lm_fh
, flk_cbp
);
4562 nfs_lockcompletion(vp
, cmd
);
4565 nfs_rw_exit(&rp
->r_lkserlock
);
4570 * Free storage space associated with the specified vnode. The portion
4571 * to be freed is specified by bfp->l_start and bfp->l_len (already
4572 * normalized to a "whence" of 0).
4574 * This is an experimental facility whose continued existence is not
4575 * guaranteed. Currently, we only support the special case
4576 * of l_len == 0, meaning free to end of file.
4580 nfs_space(vnode_t
*vp
, int cmd
, struct flock64
*bfp
, int flag
,
4581 offset_t offset
, cred_t
*cr
, caller_context_t
*ct
)
4585 ASSERT(vp
->v_type
== VREG
);
4586 if (cmd
!= F_FREESP
)
4589 if (offset
> MAXOFF32_T
)
4592 if ((bfp
->l_start
> MAXOFF32_T
) || (bfp
->l_end
> MAXOFF32_T
) ||
4593 (bfp
->l_len
> MAXOFF32_T
))
4596 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
4599 error
= convoff(vp
, bfp
, 0, offset
);
4601 ASSERT(bfp
->l_start
>= 0);
4602 if (bfp
->l_len
== 0) {
4606 * ftruncate should not change the ctime and
4607 * mtime if we truncate the file to its
4610 va
.va_mask
= VATTR_SIZE
;
4611 error
= nfsgetattr(vp
, &va
, cr
);
4612 if (error
|| va
.va_size
== bfp
->l_start
)
4614 va
.va_mask
= VATTR_SIZE
;
4615 va
.va_size
= bfp
->l_start
;
4616 error
= nfssetattr(vp
, &va
, 0, cr
);
4618 if (error
== 0 && bfp
->l_start
== 0)
4619 vnevent_truncate(vp
, ct
);
4629 nfs_realvp(vnode_t
*vp
, vnode_t
**vpp
, caller_context_t
*ct
)
4636 * Setup and add an address space callback to do the work of the delmap call.
4637 * The callback will (and must be) deleted in the actual callback function.
4639 * This is done in order to take care of the problem that we have with holding
4640 * the address space's a_lock for a long period of time (e.g. if the NFS server
4641 * is down). Callbacks will be executed in the address space code while the
4642 * a_lock is not held. Holding the address space's a_lock causes things such
4643 * as ps and fork to hang because they are trying to acquire this lock as well.
4647 nfs_delmap(vnode_t
*vp
, offset_t off
, struct as
*as
, caddr_t addr
,
4648 size_t len
, uint_t prot
, uint_t maxprot
, uint_t flags
, cred_t
*cr
,
4649 caller_context_t
*ct
)
4654 nfs_delmap_args_t
*dmapp
;
4655 nfs_delmapcall_t
*delmap_call
;
4657 if (vp
->v_flag
& VNOMAP
)
4660 * A process may not change zones if it has NFS pages mmap'ed
4661 * in, so we can't legitimately get here from the wrong zone.
4663 ASSERT(nfs_zone() == VTOMI(vp
)->mi_zone
);
4668 * The way that the address space of this process deletes its mapping
4669 * of this file is via the following call chains:
4670 * - as_free()->segop_unmap()/segvn_unmap()->fop_delmap()/nfs_delmap()
4671 * - as_unmap()->segop_unmap()/segvn_unmap()->fop_delmap()/nfs_delmap()
4673 * With the use of address space callbacks we are allowed to drop the
4674 * address space lock, a_lock, while executing the NFS operations that
4675 * need to go over the wire. Returning EAGAIN to the caller of this
4676 * function is what drives the execution of the callback that we add
4677 * below. The callback will be executed by the address space code
4678 * after dropping the a_lock. When the callback is finished, since
4679 * we dropped the a_lock, it must be re-acquired and segvn_unmap()
4680 * is called again on the same segment to finish the rest of the work
4681 * that needs to happen during unmapping.
4683 * This action of calling back into the segment driver causes
4684 * nfs_delmap() to get called again, but since the callback was
4685 * already executed at this point, it already did the work and there
4686 * is nothing left for us to do.
4689 * - The first time nfs_delmap is called by the current thread is when
4690 * we add the caller associated with this delmap to the delmap caller
4691 * list, add the callback, and return EAGAIN.
4692 * - The second time in this call chain when nfs_delmap is called we
4693 * will find this caller in the delmap caller list and realize there
4694 * is no more work to do thus removing this caller from the list and
4695 * returning the error that was set in the callback execution.
4697 caller_found
= nfs_find_and_delete_delmapcall(rp
, &error
);
4700 * 'error' is from the actual delmap operations. To avoid
4701 * hangs, we need to handle the return of EAGAIN differently
4702 * since this is what drives the callback execution.
4703 * In this case, we don't want to return EAGAIN and do the
4704 * callback execution because there are none to execute.
4706 if (error
== EAGAIN
)
4712 /* current caller was not in the list */
4713 delmap_call
= nfs_init_delmapcall();
4715 mutex_enter(&rp
->r_statelock
);
4716 list_insert_tail(&rp
->r_indelmap
, delmap_call
);
4717 mutex_exit(&rp
->r_statelock
);
4719 dmapp
= kmem_alloc(sizeof (nfs_delmap_args_t
), KM_SLEEP
);
4726 dmapp
->maxprot
= maxprot
;
4727 dmapp
->flags
= flags
;
4729 dmapp
->caller
= delmap_call
;
4731 error
= as_add_callback(as
, nfs_delmap_callback
, dmapp
,
4732 AS_UNMAP_EVENT
, addr
, len
, KM_SLEEP
);
4734 return (error
? error
: EAGAIN
);
4738 * Remove some pages from an mmap'd vnode. Just update the
4739 * count of pages. If doing close-to-open, then flush all
4740 * of the pages associated with this file. Otherwise, start
4741 * an asynchronous page flush to write out any dirty pages.
4742 * This will also associate a credential with the rnode which
4743 * can be used to write the pages.
4747 nfs_delmap_callback(struct as
*as
, void *arg
, uint_t event
)
4752 nfs_delmap_args_t
*dmapp
= (nfs_delmap_args_t
*)arg
;
4754 rp
= VTOR(dmapp
->vp
);
4755 mi
= VTOMI(dmapp
->vp
);
4757 atomic_add_long((ulong_t
*)&rp
->r_mapcnt
, -btopr(dmapp
->len
));
4758 ASSERT(rp
->r_mapcnt
>= 0);
4761 * Initiate a page flush if there are pages, the file system
4762 * was not mounted readonly, the segment was mapped shared, and
4763 * the pages themselves were writeable.
4765 if (vn_has_cached_data(dmapp
->vp
) && !vn_is_readonly(dmapp
->vp
) &&
4766 dmapp
->flags
== MAP_SHARED
&& (dmapp
->maxprot
& PROT_WRITE
)) {
4767 mutex_enter(&rp
->r_statelock
);
4768 rp
->r_flags
|= RDIRTY
;
4769 mutex_exit(&rp
->r_statelock
);
4771 * If this is a cross-zone access a sync putpage won't work, so
4772 * the best we can do is try an async putpage. That seems
4773 * better than something more draconian such as discarding the
4776 if ((mi
->mi_flags
& MI_NOCTO
) ||
4777 nfs_zone() != mi
->mi_zone
)
4778 error
= nfs_putpage(dmapp
->vp
, dmapp
->off
, dmapp
->len
,
4779 B_ASYNC
, dmapp
->cr
, NULL
);
4781 error
= nfs_putpage(dmapp
->vp
, dmapp
->off
, dmapp
->len
,
4782 0, dmapp
->cr
, NULL
);
4784 mutex_enter(&rp
->r_statelock
);
4785 error
= rp
->r_error
;
4787 mutex_exit(&rp
->r_statelock
);
4792 if ((rp
->r_flags
& RDIRECTIO
) || (mi
->mi_flags
& MI_DIRECTIO
))
4793 (void) nfs_putpage(dmapp
->vp
, dmapp
->off
, dmapp
->len
,
4794 B_INVAL
, dmapp
->cr
, NULL
);
4796 dmapp
->caller
->error
= error
;
4797 (void) as_delete_callback(as
, arg
);
4798 kmem_free(dmapp
, sizeof (nfs_delmap_args_t
));
4803 nfs_pathconf(vnode_t
*vp
, int cmd
, ulong_t
*valp
, cred_t
*cr
,
4804 caller_context_t
*ct
)
4808 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
4811 * This looks a little weird because it's written in a general
4812 * manner but we make little use of cases. If cntl() ever gets
4813 * widely used, the outer switch will make more sense.
4819 * Large file spec - need to base answer new query with
4820 * hardcoded constant based on the protocol.
4822 case _PC_FILESIZEBITS
:
4829 case _PC_SYMLINK_MAX
:
4830 case _PC_CHOWN_RESTRICTED
:
4831 case _PC_NO_TRUNC
: {
4835 if ((mi
= VTOMI(vp
)) == NULL
|| (pc
= mi
->mi_pathconf
) == NULL
)
4837 error
= _PC_ISSET(cmd
, pc
->pc_mask
); /* error or bool */
4840 *valp
= pc
->pc_link_max
;
4843 *valp
= pc
->pc_name_max
;
4846 case _PC_SYMLINK_MAX
:
4847 *valp
= pc
->pc_path_max
;
4849 case _PC_CHOWN_RESTRICTED
:
4851 * if we got here, error is really a boolean which
4852 * indicates whether cmd is set or not.
4854 *valp
= error
? 1 : 0; /* see above */
4859 * if we got here, error is really a boolean which
4860 * indicates whether cmd is set or not.
4862 *valp
= error
? 1 : 0; /* see above */
4866 return (error
? EINVAL
: 0);
4869 case _PC_XATTR_EXISTS
:
4871 if (vp
->v_vfsp
->vfs_flag
& VFS_XATTR
) {
4874 mntinfo_t
*mi
= VTOMI(vp
);
4876 if (!(mi
->mi_flags
& MI_EXTATTR
))
4880 if (nfs_rw_enter_sig(&rp
->r_rwlock
, RW_READER
,
4884 error
= nfslookup_dnlc(vp
, XATTR_DIR_NAME
, &avp
, cr
);
4885 if (error
|| avp
== NULL
)
4886 error
= acl_getxattrdir2(vp
, &avp
, 0, cr
, 0);
4888 nfs_rw_exit(&rp
->r_rwlock
);
4890 if (error
== 0 && avp
!= NULL
) {
4891 error
= do_xattr_exists_check(avp
, valp
, cr
);
4895 return (error
? EINVAL
: 0);
4897 case _PC_ACL_ENABLED
:
4898 *valp
= _ACL_ACLENT_ENABLED
;
4907 * Called by async thread to do synchronous pageio. Do the i/o, wait
4908 * for it to complete, and cleanup the page list when done.
4911 nfs_sync_pageio(vnode_t
*vp
, page_t
*pp
, uoff_t io_off
, size_t io_len
,
4912 int flags
, cred_t
*cr
)
4916 ASSERT(nfs_zone() == VTOMI(vp
)->mi_zone
);
4917 error
= nfs_rdwrlbn(vp
, pp
, io_off
, io_len
, flags
, cr
);
4919 pvn_read_done(pp
, (error
? B_ERROR
: 0) | flags
);
4921 pvn_write_done(pp
, (error
? B_ERROR
: 0) | flags
);
4927 nfs_pageio(vnode_t
*vp
, page_t
*pp
, uoff_t io_off
, size_t io_len
,
4928 int flags
, cred_t
*cr
, caller_context_t
*ct
)
4936 if (io_off
> MAXOFF32_T
)
4938 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
4941 mutex_enter(&rp
->r_statelock
);
4943 mutex_exit(&rp
->r_statelock
);
4945 if (flags
& B_ASYNC
) {
4946 error
= nfs_async_pageio(vp
, pp
, io_off
, io_len
, flags
, cr
,
4949 error
= nfs_rdwrlbn(vp
, pp
, io_off
, io_len
, flags
, cr
);
4950 mutex_enter(&rp
->r_statelock
);
4952 cv_broadcast(&rp
->r_cv
);
4953 mutex_exit(&rp
->r_statelock
);
4959 nfs_setsecattr(vnode_t
*vp
, vsecattr_t
*vsecattr
, int flag
, cred_t
*cr
,
4960 caller_context_t
*ct
)
4967 if (nfs_zone() != mi
->mi_zone
)
4969 if (mi
->mi_flags
& MI_ACL
) {
4970 error
= acl_setacl2(vp
, vsecattr
, flag
, cr
);
4971 if (mi
->mi_flags
& MI_ACL
)
4980 nfs_getsecattr(vnode_t
*vp
, vsecattr_t
*vsecattr
, int flag
, cred_t
*cr
,
4981 caller_context_t
*ct
)
4988 if (nfs_zone() != mi
->mi_zone
)
4990 if (mi
->mi_flags
& MI_ACL
) {
4991 error
= acl_getacl2(vp
, vsecattr
, flag
, cr
);
4992 if (mi
->mi_flags
& MI_ACL
)
4996 return (fs_fab_acl(vp
, vsecattr
, flag
, cr
, ct
));
5001 nfs_shrlock(vnode_t
*vp
, int cmd
, struct shrlock
*shr
, int flag
, cred_t
*cr
,
5002 caller_context_t
*ct
)
5005 struct shrlock nshr
;
5006 struct nfs_owner nfs_owner
;
5009 if (nfs_zone() != VTOMI(vp
)->mi_zone
)
5013 * check for valid cmd parameter
5015 if (cmd
!= F_SHARE
&& cmd
!= F_UNSHARE
&& cmd
!= F_HASREMOTELOCKS
)
5019 * Check access permissions
5021 if (cmd
== F_SHARE
&&
5022 (((shr
->s_access
& F_RDACC
) && !(flag
& FREAD
)) ||
5023 ((shr
->s_access
& F_WRACC
) && !(flag
& FWRITE
))))
5027 * If the filesystem is mounted using local locking, pass the
5028 * request off to the local share code.
5030 if (VTOMI(vp
)->mi_flags
& MI_LLOCK
)
5031 return (fs_shrlock(vp
, cmd
, shr
, flag
, cr
, ct
));
5036 lm_fh
.n_len
= sizeof (fhandle_t
);
5037 lm_fh
.n_bytes
= (char *)VTOFH(vp
);
5040 * If passed an owner that is too large to fit in an
5041 * nfs_owner it is likely a recursive call from the
5042 * lock manager client and pass it straight through. If
5043 * it is not a nfs_owner then simply return an error.
5045 if (shr
->s_own_len
> sizeof (nfs_owner
.lowner
)) {
5046 if (((struct nfs_owner
*)shr
->s_owner
)->magic
!=
5050 if (error
= lm_shrlock(vp
, cmd
, shr
, flag
, &lm_fh
)) {
5051 error
= set_errno(error
);
5056 * Remote share reservations owner is a combination of
5057 * a magic number, hostname, and the local owner
5059 bzero(&nfs_owner
, sizeof (nfs_owner
));
5060 nfs_owner
.magic
= NFS_OWNER_MAGIC
;
5061 (void) strncpy(nfs_owner
.hname
, uts_nodename(),
5062 sizeof (nfs_owner
.hname
));
5063 bcopy(shr
->s_owner
, nfs_owner
.lowner
, shr
->s_own_len
);
5064 nshr
.s_access
= shr
->s_access
;
5065 nshr
.s_deny
= shr
->s_deny
;
5067 nshr
.s_pid
= ttoproc(curthread
)->p_pid
;
5068 nshr
.s_own_len
= sizeof (nfs_owner
);
5069 nshr
.s_owner
= (caddr_t
)&nfs_owner
;
5071 if (error
= lm_shrlock(vp
, cmd
, &nshr
, flag
, &lm_fh
)) {
5072 error
= set_errno(error
);
5077 case F_HASREMOTELOCKS
:
5079 * NFS client can't store remote locks itself