/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*
* Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T.
* All rights reserved.
*/
/*
* Copyright (c) 2013, Joyent, Inc. All rights reserved.
* Copyright 2015 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/vfs_opreg.h>
#include <sys/pathname.h>
#include <sys/sysmacros.h>
#include <sys/pathconf.h>
#include <nfs/nfs_clnt.h>
cred_t *);
caller_context_t *);
cred_t *);
int, cred_t *);
int, cred_t *);
/*
* Error flags used to pass information about certain special errors
* which need to be handled specially.
*/
/*
* These are the vnode ops routines which implement the vnode interface to
* the networked file system. These routines just take their parameters,
* make them look networkish by putting the right info into interface structs,
* and then calling the appropriate remote routine(s) to do the work.
*
* Note on directory name lookup cacheing: If we detect a stale fhandle,
* we purge the directory cache relative to that vnode. This way, the
* more details on rnode locking.
*/
caller_context_t *);
caller_context_t *);
caller_context_t *);
caller_context_t *);
caller_context_t *);
caller_context_t *);
static int nfs_accessx(void *, int, cred_t *);
caller_context_t *);
int *, pathname_t *);
vsecattr_t *);
int);
caller_context_t *, int);
caller_context_t *, int);
caller_context_t *, int);
cred_t *, caller_context_t *, int);
caller_context_t *, int);
caller_context_t *);
cred_t *, caller_context_t *);
caller_context_t *);
cred_t *, caller_context_t *);
caller_context_t *);
caller_context_t *);
caller_context_t *);
};
/*
* XXX: This is referenced in modstubs.s
*/
struct vnodeops *
nfs_getvnodeops(void)
{
return (nfs_vnodeops);
}
/* ARGSUSED */
static int
{
int error;
return (EIO);
}
/*
* If there is no cached data or if close-to-open
* consistency checking is turned off, we can avoid
* the over the wire getattr. Otherwise, if the
* file system is mounted readonly, then just verify
* the caches are up to date using the normal mechanism.
* Else, if the file is not mmap'd, then just mark
* the attributes as timed out. They will be refreshed
* and the caches validated prior to being used.
* Else, the file system is mounted writeable so
* force an over the wire GETATTR in order to ensure
* that all cached data is valid.
*/
if (vn_is_readonly(vp))
error = 0;
} else {
}
} else
error = 0;
return (error);
}
/* ARGSUSED */
static int
{
int error;
/*
* zone_enter(2) prevents processes from changing zones with NFS files
* open; if we happen to get here from the wrong zone we can't do
* anything over the wire.
*/
/*
* We could attempt to clean up locks, except we're sure
* that the current process didn't acquire any locks on
* the file: any attempt to lock a file belong to another zone
* will fail, and one can't lock an NFS file and then change
* zones, as that fails too.
*
* Returning an error here is the sane thing to do. A
* subsequent call to VN_RELE() which translates to a
* nfs_inactive() will clean up state: if the zone of the
* vnode's origin is still alive and kicking, an async worker
* thread will handle the request (from the correct zone), and
* everything (minus the final nfs_getattr_otw() call) should
* be OK. If the zone is going away nfs_async_inactive() will
* throw away cached pages inline.
*/
return (EIO);
}
/*
* If we are using local locking for this filesystem, then
* release all of the SYSV style record locks. Otherwise,
* we are doing network locking and we need to release all
* of the network locks. All of the locks held by this
* process on this file are released no matter what the
* incoming reference count is.
*/
} else
if (count > 1)
return (0);
/*
* If the file has been `unlinked', then purge the
* DNLC so that this vnode will get reycled quicker
* and the .nfs* file on the server will get removed.
*/
/*
* If the file was open for write and there are pages,
* then if the file system was mounted using the "no-close-
* to-open" semantics, then start an asynchronous flush
* of the all of the pages in the file.
* else the file system was not mounted using the "no-close-
* to-open" semantics, then do a synchronous flush and
* commit of all of the dirty and uncommitted pages.
*
* The asynchronous flush of the pages in the "nocto" path
* mostly just associates a cred pointer with the rnode so
* writes which happen later will have a better chance of
* working. It also starts the data being written to the
* server, but without unnecessarily delaying the application.
*/
error = 0;
} else
if (!error) {
}
} else {
}
/*
* If RWRITEATTR is set, then issue an over the wire GETATTR to
* refresh the attribute cache with a set of attributes which
* weren't returned from a WRITE. This will enable the close-
* to-open processing to work.
*/
return (error);
}
/* ARGSUSED */
static int
{
int on;
size_t n;
int error;
return (EIO);
return (EISDIR);
return (0);
return (EFBIG);
if (uiop->uio_loffset < 0 ||
return (EINVAL);
/*
* Bypass VM if caching has been disabled (e.g., locking) or if
* using client-side direct I/O and the file is not mmap'd and
* there are no cached pages.
*/
!vn_has_cached_data(vp))) {
/*
* Let's try to do read in as large a chunk as we can
* For V3, this is 32K and for V2, this is 8K.
*/
do {
if (!error) {
n -= resid;
}
return (error);
}
error = 0;
do {
if (error)
break;
return (EINTR);
}
}
if (diff <= 0)
break;
if (diff < n)
if (vpm_enable) {
/*
* Copy data.
*/
} else {
1, S_READ);
}
if (!error) {
/*
* If read a whole block or read to eof,
* won't need this buffer again soon.
*/
flags = SM_DONTNEED;
else
flags = 0;
if (vpm_enable) {
} else {
}
} else {
if (vpm_enable) {
} else {
}
}
return (error);
}
/* ARGSUSED */
static int
{
int remainder;
size_t n;
int on;
int error;
int resid;
return (EIO);
return (EISDIR);
return (0);
/*
* Must serialize if appending.
*/
return (EINTR);
}
if (error)
return (error);
}
return (EFBIG);
return (EINVAL);
limit = MAXOFF32_T;
} else {
}
/*
* Check to make sure that the process will not exceed
* its limit on file size. It is okay to write up to
* the limit, but not beyond. Thus, the write which
* reaches the limit will be short and the next write
* will return an error.
*/
remainder = 0;
mutex_enter(&p->p_lock);
p->p_rctls, p, RCA_UNSAFE_SIGINFO);
mutex_exit(&p->p_lock);
return (EFBIG);
}
}
return (EINTR);
/*
* Bypass VM if caching has been disabled (e.g., locking) or if
* using client-side direct I/O and the file is not mmap'd and
* there are no cached pages.
*/
!vn_has_cached_data(vp))) {
int count;
/*
* A close may have cleared r_error, if so,
* propagate ESTALE error return properly
*/
if (error == 0)
goto bottom;
}
do {
if (!error) {
}
goto bottom;
}
do {
/*
* A close may have cleared r_error, if so,
* propagate ESTALE error return properly
*/
if (error == 0)
break;
}
/*
* Don't create dirty pages faster than they
* can be cleaned so that the system doesn't
* get imbalanced. If the async queue is
* maxed out, then wait for it to drain before
* creating more dirty pages. Also, wait for
* any threads doing pagewalks in the vop_getattr
* entry points so that they don't block for
* long periods.
*/
while ((mi->mi_max_threads != 0 &&
lwp->lwp_nostop++;
lwp->lwp_nostop--;
goto bottom;
}
lwp->lwp_nostop--;
} else
}
/*
* Touch the page and fault it in if it is not in core
* before segmap_getmapflt or vpm_data_copy can lock it.
* This is to avoid the deadlock if the buffer is mapped
* to the same file through mmap which we want to write.
*/
uio_prefaultpages((long)n, uiop);
if (vpm_enable) {
/*
* It will use kpm mappings, so no need to
* pass an address.
*/
} else {
if (segmap_kpm) {
int pagecreate;
} else {
n, 0, S_READ);
}
}
if (!error) {
/*
* Have written a whole block.
* Start an asynchronous write
* and mark the buffer to
* indicate that it won't be
* needed again soon.
*/
} else
flags = 0;
}
if (vpm_enable) {
} else {
}
} else {
if (vpm_enable) {
} else {
}
/*
* In the event that we got an access error while
* faulting in a page for a write-only file just
* force a write.
*/
goto nfs_fwrite;
}
if (error) {
} else
return (error);
}
/*
* Flags are composed of {B_ASYNC, B_INVAL, B_FREE, B_DONTNEED}
*/
static int
{
int error;
/*
* pageio_setup should have set b_addr to 0. This
* is correct since we want to do I/O on a page
* boundary. bp_mapin will use this addr to calculate
* an offset, and then set b_addr to the kernel virtual
* address it allocated for us.
*/
return (error);
}
/*
* Write to file. Writes to remote server in largest size
* chunks that the server can handle. Write is synchronous.
*/
static int
{
int error;
int tsize;
int douprintf;
douprintf = 1;
do {
if (mi->mi_io_kstats) {
}
do {
} while (error == ENFS_TRYAGAIN);
if (mi->mi_io_kstats) {
}
if (!error) {
/*
* Can't check for stale fhandle and purge caches
* here because pages are held by nfs_getpage.
* Just mark the attribute cache as timed out
* and set RWRITEATTR to indicate that the file
* was modified with a WRITE operation.
*/
if (!error) {
if (mi->mi_io_kstats) {
writes++;
}
}
}
return (error);
}
/*
* Read from a file. Reads data in largest chunks our interface can handle.
*/
static int
{
int tsize;
int error;
int douprintf;
hrtime_t t;
douprintf = 1;
do {
if (mi->mi_io_kstats) {
}
do {
t = gethrtime();
} while (error == ENFS_TRYAGAIN);
if (mi->mi_io_kstats) {
}
if (!error) {
if (!error) {
if (mi->mi_io_kstats) {
}
}
}
if (!error) {
/*
* Since no error occurred, we have the current
* attributes and we need to do a cache check and then
* potentially update the cached attributes. We can't
* use the normal attribute check and cache mechanisms
* because they might cause a cache flush which would
* deadlock. Instead, we just check the cache to see
* if the attributes have changed. If it is, then we
* just mark the attributes as out of date. The next
* time that the attributes are checked, they will be
* out of date, new attributes will be fetched, and
* the page cache will be flushed. If the attributes
* weren't changed, then we just update the cached
* attributes with these attributes.
*/
/*
* If NFS_ACL is supported on the server, then the
* attributes returned by server may have minimal
* permissions sometimes denying access to users having
* proper access. To get the proper attributes, mark
* the attributes as expired so that they will be
* regotten via the NFS_ACL GETATTR2 procedure.
*/
} else {
}
}
}
return (error);
}
/* ARGSUSED */
static int
{
return (EIO);
switch (cmd) {
case _FIODIRECTIO:
default:
return (ENOTTY);
}
}
/* ARGSUSED */
static int
{
int error;
return (EIO);
/*
* If it has been specified that the return value will
* just be used as a hint, and we are only being asked
* for size, fsid or rdevid, then return the client's
* notion of these values without checking to make sure
* that the attribute cache is up to date.
* The whole point is to avoid an over the wire GETATTR
* call.
*/
return (0);
}
}
/*
* Only need to flush pages if asking for the mtime
* and if there any dirty pages or any outstanding
* asynchronous (write) requests for this file.
*/
if (vn_has_cached_data(vp) &&
}
}
}
}
/*ARGSUSED4*/
static int
{
int error;
return (EINVAL);
return (EFBIG);
return (EIO);
if (error)
return (error);
vp);
if (error)
return (error);
return (error);
}
static int
{
int error;
int douprintf;
hrtime_t t;
/*
* Only need to flush pages if there are any pages and
* if the file is marked as dirty in some fashion. The
* file must be flushed so that we can accurately
* determine the size of the file and the cached data
* after the SETATTR returns. A file is considered to
* be dirty if it is either marked with RDIRTY, has
* outstanding i/o's active, or is mmap'd. In this
* last case, we can't tell whether there are dirty
* pages, so we flush just to be sure.
*/
if (vn_has_cached_data(vp) &&
}
}
/*
* If the system call was utime(2) or utimes(2) and the
* application did not specify the times, then set the
* mtime nanosecond field to 1 billion. This will get
* translated from 1 billion nanoseconds to 1 million
* microseconds in the over the wire request. The
* server will use 1 million in the microsecond field
* to tell whether both the mtime and atime should be
* set to the server's current time.
*
* This is an overload of the protocol and should be
* documented in the NFS Version 2 protocol specification.
*/
} else {
/*
* Use server times. vap time values will not be used.
* To ensure no time overflow, make sure vap has
* valid values, but retain the original values.
*/
now = gethrestime_sec();
if (NFS_TIME_T_OK(now)) {
/* Just in case server does not know of this */
} else {
}
/* set vap times back on */
}
} else {
/* Either do not set times or use the client specified times */
}
if (error) {
/* req time field(s) overflow - return immediately */
return (error);
}
if (error)
return (error);
douprintf = 1;
t = gethrtime();
/*
* Purge the access cache and ACL cache if changing either the
* owner of the file, the group owner, or the mode. These may
* change the access permissions of the file, so purge old
* information and start over again.
*/
(void) nfs_access_purge_rp(rp);
}
}
if (!error) {
if (!error) {
/*
* If changing the size of the file, invalidate
* any local cached data which is no longer part
* of the file. We also possibly invalidate the
* last page in the file. We could use
* pvn_vpzero(), but this would mark the page as
* modified and require it to be written back to
* the server for no particularly good reason.
* This way, if we access it, then we bring it
* back in. A read should be cheaper than a
* write.
*/
}
/*
* If NFS_ACL is supported on the server, then the
* attributes returned by server may have minimal
* permissions sometimes denying access to users having
* proper access. To get the proper attributes, mark
* the attributes as expired so that they will be
* regotten via the NFS_ACL GETATTR2 procedure.
*/
}
/*
* This next check attempts to deal with NFS
* servers which can not handle increasing
* the size of the file via setattr. Most
* of these servers do not return an error,
* but do not change the size of the file.
* Hence, this check and then attempt to set
* the file size by writing 1 byte at the
* offset of the end of the file that we need.
*/
}
/*
* Some servers will change the mode to clear the setuid
* and setgid bits when changing the uid or gid. The
* client needs to compensate appropriately.
*/
int terror;
if (!terror &&
else
}
}
} else {
}
} else {
}
return (error);
}
static int
{
}
/* ARGSUSED */
static int
{
int error;
int shift = 0;
return (EIO);
return (error);
}
if (error)
return (error);
/*
* Disallow write attempts on read-only
* file systems, unless the file is a
* device node.
*/
return (EROFS);
/*
* Disallow attempts to access mandatory lock files.
*/
return (EACCES);
/*
* Access check is based on only
* one of owner, group, public.
* If not owner, then check group.
* If not a member of the group,
* then check public access.
*/
shift += 3;
shift += 3;
}
}
/* ARGSUSED */
static int
{
int error;
int douprintf;
/*
* We want to be consistent with UFS semantics so we will return
* EINVAL instead of ENXIO. This violates the XNFS spec and
* the RFC 1094, which are wrong any way. BUGID 1138002.
*/
return (EINVAL);
return (EIO);
if (error)
return (error);
return (error);
}
}
douprintf = 1;
if (error) {
return (error);
}
if (!error) {
} else {
}
} else {
}
} else {
}
/*
* Conform to UFS semantics (see comment above)
*/
}
/*
* Flush local dirty pages to stable storage on the server.
*
* If FNODSYNC is specified, then there is nothing to do because
* metadata changes are not cached on the client before being
* sent to the server.
*/
/* ARGSUSED */
static int
{
int error;
return (0);
return (EIO);
if (!error)
return (error);
}
/*
* Weirdness: if the file was removed or the target of a rename
* operation while it was open, it got renamed instead. Here we
* remove the renamed file.
*/
/* ARGSUSED */
static void
{
/*
* If this is coming from the wrong zone, we let someone in the right
* zone take care of it asynchronously. We can get here due to
* VN_RELE() being called from pageout() or fsflush(). This call may
* potentially turn into an expensive no-op if, for instance, v_count
* gets incremented in the meantime, but it's still correct.
*/
return;
}
redo:
/*
* Save the vnode pointer for the directory where the
* unlinked-open file got renamed, then set it to NULL
* to prevent another thread from getting here before
* we're done with the remove. While we have the
* statelock, make local copies of the pertinent rnode
* fields. If we weren't to do this in an atomic way, the
* the unl* fields could become inconsistent with respect
* to each other due to a race condition between this
* code and nfs_remove(). See bug report 1034328.
*/
char *unlname;
int douprintf;
int error;
/*
* If there are any dirty pages left, then flush
* them. This is unfortunate because they just
* may get thrown away during the remove operation,
* but we have to do this for correctness.
*/
if (vn_has_cached_data(vp) &&
if (error) {
}
}
/*
* Do the remove operation on the renamed file
*/
douprintf = 1;
/*
* Release stuff held for the remove
*/
goto redo;
}
}
}
/*
* Remote file system operations having to do with directory manipulation.
*/
/* ARGSUSED */
static int
{
int error;
return (EPERM);
/*
* Are we looking up extended attributes? If so, "dvp" is
* the file or directory for which we want attributes, and
* we need a lookup of the hidden attribute directory
* before we lookup the rest of the path.
*/
if (flags & LOOKUP_XATTR) {
return (EINVAL);
return (EINTR);
else
error = 0;
if (error) {
return (error);
return (EINVAL);
}
}
goto out;
}
/*
* If vnode is a device, create special vnode.
*/
}
out:
return (error);
}
#ifdef DEBUG
static int nfs_lookup_dnlc_hits = 0;
static int nfs_lookup_dnlc_misses = 0;
static int nfs_lookup_dnlc_neg_hits = 0;
static int nfs_lookup_dnlc_disappears = 0;
static int nfs_lookup_dnlc_lookups = 0;
#endif
/* ARGSUSED */
int
{
int error;
/*
* If lookup is for "", just return dvp. Don't need
* to send it over the wire, look it up in the dnlc,
* or perform any access checks.
*/
if (*nm == '\0') {
return (0);
}
/*
* Can't do lookups in non-directories.
*/
return (ENOTDIR);
/*
* If we're called with RFSCALL_SOFT, it's important that
* the only rfscall is one we make directly; if we permit
* an access call because we're looking up "." or validating
* a dnlc hit, we'll deadlock because that rfscall will not
* have the RFSCALL_SOFT set.
*/
if (rfscall_flags & RFSCALL_SOFT)
goto callit;
/*
* If lookup is for ".", just return dvp. Don't need
* to send it over the wire or look it up in the dnlc,
* just need to check access.
*/
if (error)
return (error);
return (0);
}
/*
* Lookup this name in the DNLC. If there was a valid entry,
* then return the results of the lookup.
*/
return (error);
return (error);
}
static int
{
int error;
/*
* Lookup this name in the DNLC. If successful, then validate
* the caches and then recheck the DNLC. The DNLC is rechecked
* just in case this entry got invalidated during the call
* to nfs_validate_caches.
*
* An assumption is being made that it is safe to say that a
* file exists which may not on the server. Any operations to
* the server will fail with ESTALE.
*/
#ifdef DEBUG
#endif
}
if (error)
return (error);
if (error) {
return (error);
}
if (vp == DNLC_NO_VNODE) {
#ifdef DEBUG
#endif
return (ENOENT);
}
#ifdef DEBUG
#endif
return (0);
}
#ifdef DEBUG
#endif
}
#ifdef DEBUG
else
#endif
return (0);
}
static int
int rfscall_flags)
{
int error;
int douprintf;
hrtime_t t;
douprintf = 1;
t = gethrtime();
if (!error) {
if (!error) {
/*
* If NFS_ACL is supported on the server, then the
* attributes returned by server may have minimal
* permissions sometimes denying access to users having
* proper access. To get the proper attributes, mark
* the attributes as expired so that they will be
* regotten via the NFS_ACL GETATTR2 procedure.
*/
}
if (!(rfscall_flags & RFSCALL_SOFT))
} else {
}
}
return (error);
}
/* ARGSUSED */
static int
{
int error;
int douprintf;
hrtime_t t;
return (EPERM);
return (EINTR);
/*
* We make a copy of the attributes because the caller does not
* expect us to change what va points to.
*/
/*
* If the pathname is "", just use dvp. Don't need
* to send it over the wire, look it up in the dnlc,
* or perform any access checks.
*/
if (*nm == '\0') {
error = 0;
/*
* If the pathname is ".", just use dvp. Don't need
* to send it over the wire or look it up in the dnlc,
* just need to check access.
*/
if (error) {
return (error);
}
/*
* We need to go over the wire, just to be sure whether the
* file exists or not. Using the DNLC can be dangerous in
* this case when making a decision regarding existence.
*/
} else {
}
if (!error) {
else {
/*
* If vnode is a device, create special vnode.
*/
}
if (!error) {
/*
* Existing file was truncated;
* emit a create event.
*/
}
}
}
}
if (error) {
} else {
}
return (error);
}
return (EACCES);
}
}
/*
* Decide what the group-id of the created file should be.
* Set it in attribute list as advisory...then do a setattr
* if the server didn't get it right the first time.
*/
if (error) {
return (error);
}
/*
* This is a completely gross hack to make mknod
* work over the wire until we can wack the protocol
*/
/*
* dev_t is uint_t in 5.x and short in 4.x. Both 4.x
* supports 8 bit majors. 5.x supports 14 bit majors. 5.x supports 18
* bits in the minor number where 4.x supports 8 bits. If the 5.x
* number before sending it. Otherwise, the 4.x server will not
* create the device with the correct device number and nothing can be
* done about this.
*/
else
else
/*
* To avoid triggering bugs in the servers set AT_SIZE
* (all other RFS_CREATE calls set this).
*/
}
if (error) {
/* req time field(s) overflow - return immediately */
return (error);
}
douprintf = 1;
t = gethrtime();
if (!error) {
if (!error) {
if (HAVE_RDDIR_CACHE(drp))
/*
* If NFS_ACL is supported on the server, then the
* attributes returned by server may have minimal
* permissions sometimes denying access to users having
* proper access. To get the proper attributes, mark
* the attributes as expired so that they will be
* regotten via the NFS_ACL GETATTR2 procedure.
*/
}
if (vn_has_cached_data(vp)) {
(u_offset_t)0, cr);
}
}
/*
* Make sure the gid was set correctly.
* If not, try to set it (but don't lose
* any sleep over it).
*/
}
/*
* If vnode is a device create special vnode
*/
} else
} else {
}
}
return (error);
}
/*
* Weirdness: if the vnode to be removed is open
* we rename it instead of removing it and nfs_inactive
* will remove the new name.
*/
/* ARGSUSED */
static int
{
int error;
char *tmpname;
int douprintf;
return (EPERM);
return (EINTR);
if (error) {
return (error);
}
return (EPERM);
}
/*
* First just remove the entry from the name cache, as it
* is most likely the only entry for this vp.
*/
/*
* If the file has a v_count > 1 then there may be more than one
* entry in the name cache due multiple links or an open file,
* but we don't have the real reference count so flush all
* possible entries.
*/
/*
* Now we have the real reference count on the vnode
*/
if (error)
else {
} else {
}
}
} else {
/*
* We need to flush any dirty pages which happen to
* be hanging around before removing the file. This
* shouldn't happen very often and mostly on file
* systems mounted "nocto".
*/
if (vn_has_cached_data(vp) &&
}
}
douprintf = 1;
/*
* The xattr dir may be gone after last attr is removed,
* so flush it from dnlc.
*/
if (!error) {
if (!error) {
if (HAVE_RDDIR_CACHE(drp))
} else {
}
}
}
if (error == 0) {
}
return (error);
}
/* ARGSUSED */
static int
{
int error;
int douprintf;
return (EPERM);
return (EINTR);
douprintf = 1;
if (!error) {
if (!error) {
if (HAVE_RDDIR_CACHE(tdrp))
}
}
if (!error) {
/*
* Notify the source file of this link operation.
*/
}
return (error);
}
/* ARGSUSED */
static int
{
return (EPERM);
}
/*
* nfsrename does the real work of renaming in NFS Version 2.
*/
static int
{
int error;
int douprintf;
char *tmpname;
return (EINVAL);
return (EINTR);
return (EINTR);
}
} else {
return (EINTR);
return (EINTR);
}
}
/*
* Lookup the target file. If it exists, it needs to be
* checked to see whether it is a mount point and whether
* it is active (open).
*/
if (!error) {
/*
* If this file has been mounted on, then just
* return busy because renaming to it would remove
* the mounted file system from the name space.
*/
return (EBUSY);
}
/*
* Purge the name cache of all references to this vnode
* so that we can check the reference count to infer
* whether it is active or not.
*/
/*
* First just remove the entry from the name cache, as it
* is most likely the only entry for this vp.
*/
/*
* If the file has a v_count > 1 then there may be more
* than one entry in the name cache due multiple links
* or an open file, but we don't have the real reference
* count so flush all possible entries.
*/
/*
* If the vnode is active and is not a directory,
* arrange to rename it to a
* temporary file so that it will continue to be
* accessible. This implements the "unlink-open-file"
* semantics for the target of a rename operation.
* Before doing this though, make sure that the
* source and target files are not already the same.
*/
/*
* Lookup the source name.
*/
cr, 0);
/*
* The source name *should* already exist.
*/
if (error) {
return (error);
}
/*
* Compare the two vnodes. If they are the same,
* just release all held vnodes and return success.
*/
return (0);
}
/*
* Can't mix and match directories and non-
* directories in rename operations. We already
* know that the target is not a directory. If
* the source is a directory, return an error.
*/
return (ENOTDIR);
}
/*
* The target file exists, is not the same as
* the source file, and is active. Link it
* to a temporary filename to avoid having
* the server removing the file completely.
*/
if (error == EOPNOTSUPP) {
}
if (error) {
return (error);
}
} else {
}
}
}
/*
* When renaming directories to be a subdirectory of a
* different parent, the dnlc entry for ".." will no
* longer be valid, so it must be removed.
*
* We do a lookup here to determine whether we are renaming
* a directory and we need to check if we are renaming
* an unlinked file. This might have already been done
* in previous code, so we check ovp == NULL to avoid
* doing it twice.
*/
/*
* The source name *should* already exist.
*/
if (error) {
if (nvp) {
}
return (error);
}
}
douprintf = 1;
if (!error) {
if (!error) {
if (HAVE_RDDIR_CACHE(odrp))
if (HAVE_RDDIR_CACHE(ndrp))
/*
* when renaming directories to be a subdirectory of a
* different parent, the dnlc entry for ".." will no
* longer be valid, so it must be removed
*/
if (HAVE_RDDIR_CACHE(rp))
}
}
/*
* If we are renaming the unlinked file, update the
* r_unldvp and r_unlname as needed.
*/
nnm, MAXNAMELEN);
}
}
}
} else {
/*
* System V defines rename to return EEXIST, not
* ENOTEMPTY if the target directory is not empty.
* Over the wire, the error is NFSERR_ENOTEMPTY
* which geterrno maps to ENOTEMPTY.
*/
}
}
if (error == 0) {
if (nvp)
}
if (nvp) {
}
return (error);
}
/* ARGSUSED */
static int
{
int error;
int douprintf;
hrtime_t t;
return (EPERM);
/*
* Decide what the group-id and set-gid bit of the created directory
* should be. May have to do a setattr to get the gid right.
*/
if (error)
return (error);
if (error)
return (error);
if (error) {
/* req time field(s) overflow - return immediately */
return (error);
}
return (EINTR);
douprintf = 1;
t = gethrtime();
if (!error) {
if (!error) {
if (HAVE_RDDIR_CACHE(drp))
/*
* The attributes returned by RFS_MKDIR can not
* be depended upon, so mark the attribute cache
* as purged. A subsequent GETATTR will get the
* correct attributes from the server.
*/
/*
* Make sure the gid was set correctly.
* If not, try to set it (but don't lose
* any sleep over it).
*/
}
} else {
}
}
return (error);
}
/* ARGSUSED */
static int
{
int error;
int douprintf;
return (EPERM);
return (EINTR);
/*
* Attempt to prevent a rmdir(".") from succeeding.
*/
if (error) {
return (error);
}
return (EINVAL);
}
/*
* First just remove the entry from the name cache, as it
* is most likely an entry for this vp.
*/
/*
* If there vnode reference count is greater than one, then
* there may be additional references in the DNLC which will
* need to be purged. First, trying removing the entry for
* the parent directory and see if that removes the additional
* reference(s). If that doesn't do it, then use dnlc_purge_vp
* to completely remove any references to the directory which
* might still exist in the DNLC.
*/
}
douprintf = 1;
if (error) {
return (error);
}
if (!error) {
if (HAVE_RDDIR_CACHE(drp))
} else {
/*
* System V defines rmdir to return EEXIST, not
* ENOTEMPTY if the directory is not empty. Over
* the wire, the error is NFSERR_ENOTEMPTY which
* geterrno maps to ENOTEMPTY.
*/
}
if (error == 0) {
}
return (error);
}
/* ARGSUSED */
static int
{
int error;
int douprintf;
return (EPERM);
if (error) {
/* req time field(s) overflow - return immediately */
return (error);
}
return (EINTR);
douprintf = 1;
if (!error) {
if (!error) {
if (HAVE_RDDIR_CACHE(drp))
} else {
}
}
return (error);
}
#ifdef DEBUG
static int nfs_readdir_cache_hits = 0;
static int nfs_readdir_cache_shorts = 0;
static int nfs_readdir_cache_waits = 0;
static int nfs_readdir_cache_misses = 0;
static int nfs_readdir_readahead = 0;
#endif
static int nfs_shrinkreaddir = 0;
/*
* Read directory entries.
* There are some weird things to look out for here. The uio_offset
* field is either 0 or it is the offset returned from a previous
* readdir. It is an opaque value used by the server to find the
* correct directory block to read. The count field is the number
* of blocks to read on the server. This is advisory only, the server
* may return only one block's worth of entries. Entries may be compressed
* on the server.
*/
/* ARGSUSED */
static int
{
int error;
#ifdef DEBUG
int missed;
#endif
return (EIO);
/*
* Make sure that the directory cache is valid.
*/
if (HAVE_RDDIR_CACHE(rp)) {
if (nfs_disable_rddir_cache) {
/*
* allows interoperability with servers that do not
* properly update the attributes of directories.
* Any cached information gets purged before an
* access is made to it.
*/
} else {
if (error)
return (error);
}
}
/*
* UGLINESS: SunOS 3.2 servers apparently cannot always handle an
* RFS_READDIR request with rda_count set to more than 0x400. So
* we reduce the request size here purely for compatibility.
*
* In general, this is no longer required. However, if a server
* is discovered which can not handle requests larger than 1024,
* nfs_shrinkreaddir can be set to 1 to enable this backwards
* compatibility.
*
* In any case, the request size is limited to NFS_MAXDATA bytes.
*/
#ifdef DEBUG
missed = 0;
#endif
top:
/*
* Short circuit last readdir which always returns 0 bytes.
* This can be done after the directory has been read through
* completely at least once. This will set r_direof which
* can be used to find the value of the last cookie.
*/
#ifdef DEBUG
#endif
if (eofp)
*eofp = 1;
return (0);
}
/*
* Look for a cache entry. Cache entries are identified
* by the NFS cookie value and the byte count requested.
*/
/*
* If the cache entry is in the process of being
* filled in, wait until this completes. The
* RDDIRWAIT bit is set to indicate that someone
* is waiting and then the thread currently
* filling the entry is done, it should do a
* cv_broadcast to wakeup all of the threads
* waiting for it to finish.
*/
#ifdef DEBUG
#endif
/*
* We got interrupted, probably
* the user typed ^C or an alarm
* fired. We free the new entry
* if we allocated one.
*/
return (EINTR);
}
goto top;
}
/*
* Check to see if a readdir is required to
* fill the entry. If so, mark this entry
* as being filled, remove our reference,
* and branch to the code to fill the entry.
*/
goto bottom;
}
#ifdef DEBUG
if (!missed)
#endif
/*
* If an error occurred while attempting
* to fill the cache entry, just return it.
*/
return (error);
}
/*
* The cache entry is complete and good,
* copyout the dirent structs to the calling
* thread.
*/
/*
* If no error occurred during the copyout,
* update the offset in the uio struct to
* contain the value of the next cookie
* and set the eof value appropriately.
*/
if (!error) {
if (eofp)
}
/*
* Decide whether to do readahead. Don't if
* have already read to the end of directory.
*/
return (error);
}
/*
* Check to see whether we found an entry
* for the readahead. If so, we don't need
* to do anything further, so free the new
* entry if one was allocated. Otherwise,
* allocate a new entry, add it to the cache,
* and then initiate an asynchronous readdir
* operation to fill it.
*/
} else {
else {
}
#ifdef DEBUG
#endif
return (error);
}
}
return (error);
}
/*
* Didn't find an entry in the cache. Construct a new empty
* entry and link it into the cache. Other processes attempting
* to access this entry will need to wait until it is filled in.
*
* Since kmem_alloc may block, another pass through the cache
* will need to be taken to make sure that another process
* hasn't already added an entry to the cache for this request.
*/
goto top;
}
/*
* Add this entry to the cache.
*/
#ifdef DEBUG
missed = 1;
#endif
/*
* Do the readdir.
*/
/*
* If this operation failed, just return the error which occurred.
*/
if (error != 0)
return (error);
/*
* Since the RPC operation will have taken sometime and blocked
* this process, another pass through the cache will need to be
* taken to find the correct cache entry. It is possible that
* the correct cache entry will not be there (although one was
* added) because the directory changed during the RPC operation
* and the readdir cache was flushed. In this case, just start
* over. It is hoped that this will not happen too often... :-)
*/
goto top;
/* NOTREACHED */
}
static int
{
int error;
int douprintf;
/*
* NFS client failover support
* suppress failover unless we have a zero cookie
*/
} else {
}
douprintf = 1;
if (mi->mi_io_kstats) {
}
do {
} while (error == ENFS_TRYAGAIN);
if (mi->mi_io_kstats) {
}
/*
* Since we are actually doing a READDIR RPC, we must have
* exclusive access to the cache entry being filled. Thus,
* it is safe to update all fields except for the flags
* field. The r_statelock in the rnode must be held to
* prevent two different threads from simultaneously
* attempting to update the flags field. This can happen
* if we are turning off RDDIR and the other thread is
* trying to set RDDIRWAIT.
*/
if (!error) {
if (!error) {
#ifdef DEBUG
KM_SLEEP);
#else
#endif
if (mi->mi_io_kstats) {
}
} else {
}
}
if (error) {
}
}
if (error)
return (error);
}
#ifdef DEBUG
static int nfs_bio_do_stop = 0;
#endif
static int
{
int count;
int error;
} else {
}
if (!error) {
/*
* Didn't get it all because we hit EOF,
* zero all the memory beyond the EOF.
*/
/* bzero(rdaddr + */
}
/*
* We didn't read anything at all as we are
* past EOF. Return an error indicator back
* but don't destroy the pages (yet).
*/
}
goto read_again;
}
}
} else {
} else {
}
if (count < 0)
#ifdef DEBUG
if (count == 0) {
"nfs_bio: zero length write at %d",
offset);
if (nfs_bio_do_stop)
debug_enter("nfs_bio");
}
#endif
goto write_again;
}
}
/*
* Don't print EDQUOT errors on the console.
* Don't print asynchronous EACCES errors.
* Don't print EFBIG errors.
* Print all other write errors.
*/
/*
* Update r_error and r_flags as appropriate.
* If the error was ESTALE, then mark the
* rnode as not being writeable and save
* the error status. Otherwise, save any
* errors which occur from asynchronous
* page invalidations. Any errors occurring
* from other operations should be saved
* by the caller.
*/
}
}
} else {
/*
* A close may have cleared r_error, if so,
* propagate ESTALE error return properly
*/
if (error == 0)
}
}
return (error);
}
/* ARGSUSED */
static int
{
return (ENOSPC);
}
return (0);
}
/* ARGSUSED2 */
static int
{
if (!write_lock) {
return (V_WRITELOCK_FALSE);
}
return (V_WRITELOCK_FALSE);
}
return (V_WRITELOCK_TRUE);
}
/* ARGSUSED */
static void
{
}
/* ARGSUSED */
static int
{
/*
* Because we stuff the readdir cookie into the offset field
* someone may attempt to do an lseek with the cookie which
* we want to succeed.
*/
return (0);
return (EINVAL);
return (0);
}
/*
* number of NFS_MAXDATA blocks to read ahead
* optimized for 100 base-T.
*/
#ifdef DEBUG
#endif
/*
* Return all the pages from [off..off+len) in file
*/
/* ARGSUSED */
static int
{
int error;
return (ENOSYS);
return (EIO);
/*
* Now valididate that the caches are up to date.
*/
if (error)
return (error);
/*
* Don't create dirty pages faster than they
* can be cleaned so that the system doesn't
* get imbalanced. If the async queue is
* maxed out, then wait for it to drain before
* creating more dirty pages. Also, wait for
* any threads doing pagewalks in the vop_getattr
* entry points so that they don't block for
* long periods.
*/
while ((mi->mi_max_threads != 0 &&
}
/*
* If we are getting called as a side effect of an nfs_write()
* operation the local file size might not be extended yet.
* In this case we want to be able to return pages of zeroes.
*/
return (EFAULT); /* beyond EOF */
}
switch (error) {
case NFS_EOF:
goto retry;
case ESTALE:
}
return (error);
}
/*
* Called from pvn_getpages to get a particular page.
*/
/* ARGSUSED */
static int
{
int error;
int readahead;
int readahead_issued = 0;
return (EIO);
error = 0;
/*
* Queueing up the readahead before doing the synchronous read
* results in a significant increase in read throughput because
* of the increased parallelism between the async threads and
* the process context.
*/
/*
* Calculate the number of readaheads to do.
* a) No readaheads at offset = 0.
* b) Do maximum(nfs_nra) readaheads when the readahead
* window is closed.
* c) Do readaheads between 1 to (nfs_nra - 1) depending
* upon how far the readahead window is open or close.
* d) No readaheads if rp->r_nextr is not within the scope
* of the readahead window (random i/o).
*/
if (off == 0)
readahead = 0;
<= (nfs_nra - 1)))
else
readahead = 0;
nfs_readahead) < 0) {
break;
}
readahead--;
/*
* Indicate that we did a readahead so
* readahead offset is not updated
* by the synchronous read below.
*/
readahead_issued = 1;
/*
* set readahead offset to
* offset of last async readahead
* request.
*/
}
}
/*
* Block for this page is not allocated, or the offset
* is beyond the current allocation size, or we're
* allocating a swap slot and the page was not found,
* so allocate it and return a zero page.
*/
} else {
/*
* Need to go to server to get a BLOCK, exception to
* that being while reading at offset = 0 or doing
* random i/o, in that case read only a PAGE.
*/
/*
* If only a block or less is left in
* the file, read all that is remaining.
*/
/*
* Trying to access beyond EOF,
* set up to get at least one page.
*/
} else
} else if ((off == 0) ||
} else
/*
* Some other thread has entered the page,
* so just use it.
*/
goto again;
/*
* Now round the request size up to page boundaries.
* This ensures that the entire page will be
* initialized to zeroes if EOF is encountered.
*/
/*
* pageio_setup should have set b_addr to 0. This
* is correct since we want to do I/O on a page
* boundary. bp_mapin will use this addr to calculate
* an offset, and then set b_addr to the kernel virtual
* address it allocated for us.
*/
/*
* If doing a write beyond what we believe is EOF,
* don't bother trying to read the pages from the
* server, we'll just zero the pages here. We
* don't check that the rw flag is S_WRITE here
* because some implementations may attempt a
* read access to the buffer before copying data.
*/
} else {
}
/*
* Unmap the buffer before freeing it.
*/
/*
* If doing a write system call just return
* zeroed pages, else user tried to get pages
* beyond EOF, return error. We don't check
* that the rw flag is S_WRITE here because
* some implementations may attempt a read
* access to the buffer before copying data.
*/
error = 0;
else
}
if (!readahead_issued && !error) {
}
}
}
out:
return (error);
if (error) {
return (error);
}
if (pagefound) {
/*
* Page exists in the cache, acquire the appropriate lock.
* If this fails, start all over again.
*/
#ifdef DEBUG
nfs_lostpage++;
#endif
goto reread;
}
return (0);
}
return (error);
}
static void
{
int error;
/*
* If less than a block left in file read less
* than a block.
*/
} else
/*
* The isra flag passed to the kluster function is 1, we may have
* gotten a return value of NULL for a variety of reasons (# of free
* pages < minfree, someone entered the page on the vnode etc). In all
* cases, we want to punt on the readahead.
*/
return;
/*
* Now round the request size up to page boundaries.
* This ensures that the entire page will be
* initialized to zeroes if EOF is encountered.
*/
/*
* pageio_setup should have set b_addr to 0. This is correct since
* we want to do I/O on a page boundary. bp_mapin() will use this addr
* to calculate an offset, and then set b_addr to the kernel virtual
* address it allocated for us.
*/
/*
* If doing a write beyond what we believe is EOF, don't bother trying
* to read the pages from the server, we'll just zero the pages here.
* We don't check that the rw flag is S_WRITE here because some
* implementations may attempt a read access to the buffer before
* copying data.
*/
error = 0;
} else {
error = 0;
}
/*
* Unmap the buffer before freeing it.
*/
/*
* In case of error set readahead offset
* to the lowest offset.
* pvn_read_done() calls VN_DISPOSE to destroy the pages
*/
}
}
/*
* Flags are composed of {B_INVAL, B_FREE, B_DONTNEED, B_FORCE}
* If len == 0, do from off to EOF.
*
* The normal cases should be len == 0 && off == 0 (entire vp list),
* len == MAXBSIZE (from segmap_release actions), and len == PAGESIZE
* (from pageout).
*/
/* ARGSUSED */
static int
{
int error;
/*
* XXX - Why should this check be made here?
*/
return (ENOSYS);
return (0);
return (EIO);
return (error);
}
/*
* Write out a single page, possibly klustering adjacent dirty pages.
*/
int
{
int error;
/*
* Find a kluster that fits in one block, or in
* one page if pages are bigger than blocks. If
* there is less file space allocated than a whole
* page, we'll shorten the i/o request below.
*/
/*
* pvn_write_kluster shouldn't have returned a page with offset
* behind the original page we were given. Verify that.
*/
/*
* Now pp will have the list of kept dirty pages marked for
* write back. It will also handle invalidation and freeing
* of pages that are not dirty. Check for page length rounding
* problems.
*/
}
/*
* The RMODINPROGRESS flag makes sure that nfs(3)_bio() sees a
* consistent value of r_size. RMODINPROGRESS is set in writerp().
* When RMODINPROGRESS is set it indicates that a uiomove() is in
* progress and the r_size has not been made consistent with the
* new size of the file. When the uiomove() completes the r_size is
* updated and the RMODINPROGRESS flag is cleared.
*
* The RMODINPROGRESS flag makes sure that nfs(3)_bio() sees a
* consistent value of r_size. Without this handshaking, it is
* possible that nfs(3)_bio() picks up the old value of r_size
* before the uiomove() in writerp() completes. This will result
* in the write through nfs(3)_bio() being dropped.
*
* More precisely, there is a window between the time the uiomove()
* completes and the time the r_size is updated. If a VOP_PUTPAGE()
* operation intervenes in this window, the page will be picked up,
* because it is dirty (it will be unlocked, unless it was
* pagecreate'd). When the page is picked up as dirty, the dirty
* bit is reset (pvn_getdirty()). In nfs(3)write(), r_size is
* checked. This will still be the old size. Therefore the page will
* not be written out. When segmap_release() calls VOP_PUTPAGE(),
* the page will be found to be clean and the write will be dropped.
*/
/*
* A write is in progress for this region of the file.
* If we did not detect RMODINPROGRESS here then this
* path through nfs_putapage() would eventually go to
* nfs(3)_bio() and may not write out all of the data
* in the pages. We end up losing data. So we decide
* to set the modified bit on each page in the page
* list and mark the rnode with RDIRTY. This write
* will be restarted at some later time.
*/
hat_setmod(pp);
}
if (offp)
if (lenp)
return (0);
}
}
} else
if (offp)
if (lenp)
return (error);
}
static int
{
int error;
}
/*
* If this was not an async thread, then try again to
* write out the pages, but this time, also destroy
* them whether or not the write is successful. This
* will prevent memory from filling up with these
* pages and destroying them is the only alternative
* if they can't be written out.
*
* Don't do this if this is an async thread because
* when the pages are unlocked in pvn_write_done,
* some other thread could have come along, locked
* them, and queued for an async thread. It would be
* possible for all of the async threads to be tied
* up waiting to lock the pages again and they would
* all already be locked and waiting for an async
* thread to handle them. Deadlock.
*/
}
} else {
if (error)
}
}
return (error);
}
/* ARGSUSED */
static int
{
int error;
return (EIO);
return (ENOSYS);
if (off > MAXOFF32_T)
return (EFBIG);
return (ENXIO);
return (ENODEV);
/*
* If there is cached data and if close-to-open consistency
* checking is not turned off and if the file system is not
* mounted readonly, then force an over the wire getattr.
* Otherwise, just invoke nfsgetattr to get a copy of the
* attributes. The attribute cache will be used unless it
* is timed out and if it is, then an over the wire getattr
* will be issued.
*/
if (vn_has_cached_data(vp) &&
else
if (error)
return (error);
/*
* Check to see if the vnode is currently marked as not cachable.
* This means portions of the file are locked (through VOP_FRLOCK).
* In this case the map request must be refused. We use
* rp->r_lkserlock to avoid a race with concurrent lock requests.
*/
/*
* Atomically increment r_inmap after acquiring r_rwlock. The
* that we are in nfs_map(). Now, r_rwlock is acquired in order
* and we can prevent the deadlock that would have occurred
* when nfs_addmap() would have acquired it out of order.
*
* Since we are not protecting r_inmap by any lock, we do not
* hold any lock when we decrement it. We atomically decrement
* r_inmap after we release r_lkserlock.
*/
return (EINTR);
return (EINTR);
}
goto done;
}
/*
* Don't allow concurrent locks and mapping if mandatory locking is
* enabled.
*/
goto done;
}
if (error != 0) {
goto done;
}
done:
return (error);
}
/* ARGSUSED */
static int
{
return (ENOSYS);
return (EIO);
return (0);
}
/* ARGSUSED */
static int
{
int rc;
/* check for valid cmd parameter */
return (EINVAL);
return (EIO);
/* Verify l_type. */
case F_RDLCK:
return (EBADF);
break;
case F_WRLCK:
return (EBADF);
break;
case F_UNLCK:
intr = 0;
break;
default:
return (EINVAL);
}
/* check the validity of the lock range */
return (rc);
return (rc);
/*
* If the filesystem is mounted using local locking, pass the
* request off to the local locking code.
*/
if (offset > MAXOFF32_T)
return (EFBIG);
/*
* For complete safety, we should be holding
* r_lkserlock. However, we can't call
* lm_safelock and then fs_frlock while
* holding r_lkserlock, so just invoke
* lm_safelock and expect that this will
* catch enough of the cases.
*/
return (EAGAIN);
}
}
/*
* Check whether the given lock request can proceed, given the
* current file mappings.
*/
return (EINTR);
goto done;
}
}
/*
* Flush the cache after waiting for async I/O to finish. For new
* locks, this is so that the process gets the latest bits from the
* server. For unlocks, this is so that other clients see the
* latest bits once the file has been unlocked. If currently dirty
* pages can't be flushed, then don't allow a lock to be set. But
* allow unlocks to succeed, to avoid having orphan locks on the
* server.
*/
if (intr) {
lwp->lwp_nostop++;
== 0) {
lwp->lwp_nostop--;
break;
}
lwp->lwp_nostop--;
} else
}
if (rc != 0)
goto done;
if (error) {
}
goto done;
}
}
}
/*
* Call the lock manager to do the real work of contacting
* the server and obtaining the lock.
*/
if (rc == 0)
done:
return (rc);
}
/*
* Free storage space associated with the specified vnode. The portion
* to be freed is specified by bfp->l_start and bfp->l_len (already
* normalized to a "whence" of 0).
*
* This is an experimental facility whose continued existence is not
* guaranteed. Currently, we only support the special case
* of l_len == 0, meaning free to end of file.
*/
/* ARGSUSED */
static int
{
int error;
return (EINVAL);
if (offset > MAXOFF32_T)
return (EFBIG);
return (EFBIG);
return (EIO);
if (!error) {
/*
* ftruncate should not change the ctime and
* mtime if we truncate the file to its
* previous size.
*/
return (error);
} else
}
return (error);
}
/* ARGSUSED */
static int
{
return (EINVAL);
}
/*
* Setup and add an address space callback to do the work of the delmap call.
* The callback will (and must be) deleted in the actual callback function.
*
* This is done in order to take care of the problem that we have with holding
* the address space's a_lock for a long period of time (e.g. if the NFS server
* is down). Callbacks will be executed in the address space code while the
* a_lock is not held. Holding the address space's a_lock causes things such
* as ps and fork to hang because they are trying to acquire this lock as well.
*/
/* ARGSUSED */
static int
{
int caller_found;
int error;
return (ENOSYS);
/*
* A process may not change zones if it has NFS pages mmap'ed
* in, so we can't legitimately get here from the wrong zone.
*/
/*
* The way that the address space of this process deletes its mapping
* of this file is via the following call chains:
* - as_free()->SEGOP_UNMAP()/segvn_unmap()->VOP_DELMAP()/nfs_delmap()
* - as_unmap()->SEGOP_UNMAP()/segvn_unmap()->VOP_DELMAP()/nfs_delmap()
*
* With the use of address space callbacks we are allowed to drop the
* address space lock, a_lock, while executing the NFS operations that
* need to go over the wire. Returning EAGAIN to the caller of this
* function is what drives the execution of the callback that we add
* below. The callback will be executed by the address space code
* after dropping the a_lock. When the callback is finished, since
* we dropped the a_lock, it must be re-acquired and segvn_unmap()
* is called again on the same segment to finish the rest of the work
* that needs to happen during unmapping.
*
* This action of calling back into the segment driver causes
* nfs_delmap() to get called again, but since the callback was
* already executed at this point, it already did the work and there
* is nothing left for us to do.
*
* To Summarize:
* - The first time nfs_delmap is called by the current thread is when
* we add the caller associated with this delmap to the delmap caller
* list, add the callback, and return EAGAIN.
* - The second time in this call chain when nfs_delmap is called we
* will find this caller in the delmap caller list and realize there
* is no more work to do thus removing this caller from the list and
* returning the error that was set in the callback execution.
*/
if (caller_found) {
/*
* 'error' is from the actual delmap operations. To avoid
* hangs, we need to handle the return of EAGAIN differently
* since this is what drives the callback execution.
* In this case, we don't want to return EAGAIN and do the
* callback execution because there are none to execute.
*/
return (0);
else
return (error);
}
/* current caller was not in the list */
}
/*
* Remove some pages from an mmap'd vnode. Just update the
* count of pages. If doing close-to-open, then flush all
* of the pages associated with this file. Otherwise, start
* an asynchronous page flush to write out any dirty pages.
* This will also associate a credential with the rnode which
* can be used to write the pages.
*/
/* ARGSUSED */
static void
{
int error;
/*
* Initiate a page flush if there are pages, the file system
* was not mounted readonly, the segment was mapped shared, and
* the pages themselves were writeable.
*/
/*
* If this is a cross-zone access a sync putpage won't work, so
* the best we can do is try an async putpage. That seems
* better than something more draconian such as discarding the
* dirty pages.
*/
else
if (!error) {
}
} else
error = 0;
}
/* ARGSUSED */
static int
{
int error = 0;
return (EIO);
/*
* This looks a little weird because it's written in a general
* manner but we make little use of cases. If cntl() ever gets
* widely used, the outer switch will make more sense.
*/
switch (cmd) {
/*
* Large file spec - need to base answer new query with
* hardcoded constant based on the protocol.
*/
case _PC_FILESIZEBITS:
*valp = 32;
return (0);
case _PC_LINK_MAX:
case _PC_NAME_MAX:
case _PC_PATH_MAX:
case _PC_SYMLINK_MAX:
case _PC_CHOWN_RESTRICTED:
case _PC_NO_TRUNC: {
return (EINVAL);
switch (cmd) {
case _PC_LINK_MAX:
break;
case _PC_NAME_MAX:
break;
case _PC_PATH_MAX:
case _PC_SYMLINK_MAX:
break;
case _PC_CHOWN_RESTRICTED:
/*
* if we got here, error is really a boolean which
* indicates whether cmd is set or not.
*/
error = 0;
break;
case _PC_NO_TRUNC:
/*
* if we got here, error is really a boolean which
* indicates whether cmd is set or not.
*/
error = 0;
break;
}
}
case _PC_XATTR_EXISTS:
*valp = 0;
return (0);
return (EINTR);
}
}
case _PC_ACL_ENABLED:
return (0);
default:
return (EINVAL);
}
}
/*
* Called by async thread to do synchronous pageio. Do the i/o, wait
* for it to complete, and cleanup the page list when done.
*/
static int
{
int error;
else
return (error);
}
/* ARGSUSED */
static int
{
int error;
return (EINVAL);
if (io_off > MAXOFF32_T)
return (EFBIG);
return (EIO);
} else
return (error);
}
/* ARGSUSED */
static int
{
int error;
return (EIO);
return (error);
}
return (ENOSYS);
}
/* ARGSUSED */
static int
{
int error;
return (EIO);
return (error);
}
}
/* ARGSUSED */
static int
{
int error;
return (EIO);
/*
* check for valid cmd parameter
*/
return (EINVAL);
/*
* Check access permissions
*/
return (EBADF);
/*
* If the filesystem is mounted using local locking, pass the
* request off to the local share code.
*/
switch (cmd) {
case F_SHARE:
case F_UNSHARE:
/*
* If passed an owner that is too large to fit in an
* nfs_owner it is likely a recursive call from the
* lock manager client and pass it straight through. If
* it is not a nfs_owner then simply return an error.
*/
return (EINVAL);
}
return (error);
}
/*
* Remote share reservations owner is a combination of
* a magic number, hostname, and the local owner
*/
}
break;
case F_HASREMOTELOCKS:
/*
* NFS client can't store remote locks itself
*/
error = 0;
break;
default:
break;
}
return (error);
}