/*
* 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 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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 <sys/systeminfo.h>
#include <rpc/rpc_rdma.h>
#include <nfs/nfs_clnt.h>
cred_t *);
stable_how *);
static int nfs3_accessx(void *, int, cred_t *);
caller_context_t *);
cred_t *);
int, cred_t *);
int, cred_t *);
static void nfs3_set_mod(vnode_t *);
static void nfs3_get_commit(vnode_t *);
cred_t *);
cred_t *);
/*
* Error flags used to pass information about certain special errors
* which need to be handled specially.
*/
/* ALIGN64 aligns the given buffer and adjust buffer size to 64 bit */
if (x) { \
x = sizeof (uint64_t) - (x); \
sz -= (x); \
ptr += (x); \
}
/*
* 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 *);
caller_context_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 *);
caller_context_t *);
/* no separate nfs3_dump */
};
/*
* XXX: This is referenced in modstubs.s
*/
struct vnodeops *
nfs3_getvnodeops(void)
{
return (nfs3_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
* nfs3_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 commit and final nfs3_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 tsize;
int error;
int douprintf;
char *sv_hostname;
douprintf = 1;
do {
if (mi->mi_io_kstats) {
}
do {
} while (error == ENFS_TRYAGAIN);
if (mi->mi_io_kstats) {
}
if (error)
return (error);
if (error)
return (error);
"nfs3_directio_read: server %s returned incorrect amount",
return (EIO);
}
if (mi->mi_io_kstats) {
}
return (0);
}
/* ARGSUSED */
static int
{
int on;
size_t n;
int error = 0;
return (EIO);
return (EISDIR);
return (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))) {
}
do {
if (error)
break;
return (EINTR);
}
}
if (diff <= 0)
break;
if (diff < n)
if (vpm_enable) {
/*
* Copy data.
*/
} else {
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 (EISDIR);
return (EIO);
return (0);
/*
* Must serialize if appending.
*/
return (EINTR);
}
if (error)
return (error);
}
return (EINVAL);
limit = MAXOFFSET_T;
/*
* 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 {
else
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 nfs3_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.
*/
/*
* Calculate the desired level of stability to write data
* on the server and then mark all of the pages to reflect
* this.
*/
} else {
fsdata = C_NOCOMMIT;
}
do {
/*
* If the server wrote pages in a more stable fashion than
* was requested, then clear all of the marks in the pages
* indicating that COMMIT operations were required.
*/
do {
}
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 {
else
if (mi->mi_io_kstats) {
}
do {
} while (error == ENFS_TRYAGAIN);
if (mi->mi_io_kstats) {
}
if (error)
return (error);
if (!error) {
"nfs3write: server %s wrote %u, "
"requested was %u",
return (EIO);
}
"nfs3write: server %s did not commit to stable storage",
return (EIO);
}
}
if (mi->mi_io_kstats) {
}
/*
* If the data was written UNSTABLE,
* then might as well stop because
* the whole block will have to get
* rewritten anyway.
*/
break;
}
}
} else {
}
/*
* Mark the attribute cache as timed out and
* set RWRITEATTR to indicate that the file
* was modified with a WRITE operation and
* that the attributes can not be trusted.
*/
}
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 {
else
t = gethrtime();
} while (error == ENFS_TRYAGAIN);
if (mi->mi_io_kstats) {
}
if (error)
return (error);
if (error)
return (error);
"nfs3read: server %s returned incorrect amount",
return (EIO);
}
if (mi->mi_io_kstats) {
}
} else {
}
}
return (0);
}
/* 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 (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 intent is for the server to set the times,
* there is no point in have the mask indicating set mtime or
* atime, because the vap values may be junk, and so result
* in an overflow error. Remove these flags from the vap mask
* before calling in this case, and restore them afterwards.
*/
/* Use server times, so don't set the args time fields */
}
}
} 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);
} else
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) {
return (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.
*/
}
/*
* 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 {
/*
* If we got back a "not synchronized" error, then
* we need to retry with a new guard value. The
* guard value used is the change time. If the
* server returned post_op_attr, then we can just
* retry because we have the latest attributes.
* Otherwise, we issue a GETATTR to get the latest
* attributes and then retry. If we couldn't get
* the attributes this way either, then we give
* up because we can't complete the operation as
* required.
*/
goto tryagain;
}
}
return (error);
}
static int
{
}
/* ARGSUSED */
static int
{
int error;
int douprintf;
hrtime_t t;
acc = 0;
return (EIO);
acc |= ACCESS3_READ;
return (EROFS);
acc |= ACCESS3_DELETE;
}
acc |= ACCESS3_LOOKUP;
else
acc |= ACCESS3_EXECUTE;
}
} else {
}
/*
* ncr and ncrfree both initially
* point to the memory area returned
* by crnetadjust();
* ncrfree not NULL when exiting means
* that we need to release it
*/
if (cacc == NFS_ACCESS_ALLOWED) {
return (0);
}
if (cacc == NFS_ACCESS_DENIED) {
/*
* If the cred can be adjusted, try again
* with the new cred.
*/
goto tryagain;
}
return (EACCES);
}
}
douprintf = 1;
t = gethrtime();
if (error) {
return (error);
}
if (!error) {
/*
* we just cached results with cred; if cred is the
* adjusted credentials from crnetadjust, we do not want
* to release them before exiting: hence setting ncrfree
* to NULL
*/
/*
* If the cred can be adjusted, try again
* with the new cred.
*/
goto tryagain;
}
}
} else {
}
return (error);
}
/* ARGSUSED */
static int
{
int error;
int douprintf;
int len;
hrtime_t t;
/*
* Can't readlink anything other than a symbolic link.
*/
return (EINVAL);
return (EIO);
if (error)
return (error);
return (error);
}
}
douprintf = 1;
t = gethrtime();
if (error) {
return (error);
}
if (!error) {
cr);
} else {
}
} else {
}
} else {
}
/*
* The over the wire error for attempting to readlink something
* other than a symbolic link is ENXIO. However, we need to
* return EINVAL instead of ENXIO, so we map it here.
*/
}
/*
* 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;
hrtime_t t;
/*
* 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;
t = gethrtime();
if (error) {
} else {
if (!error) {
} else {
}
}
/*
* 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 nfs3_lookup_dnlc_hits = 0;
static int nfs3_lookup_dnlc_misses = 0;
static int nfs3_lookup_dnlc_neg_hits = 0;
static int nfs3_lookup_dnlc_disappears = 0;
static int nfs3_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 nfs3_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)
return (error);
if (error) {
return (error);
}
} else {
if (error) {
return (error);
}
}
}
if (!(rfscall_flags & RFSCALL_SOFT))
return (error);
}
#ifdef DEBUG
static int nfs3_create_misses = 0;
#endif
/* ARGSUSED */
static int
{
int error;
return (EPERM);
return (EINTR);
top:
/*
* 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.
*/
}
/*
* Check here for large file handled
* by LF-unaware process (as
* ufs_create() does)
*/
}
if (!error) {
/*
* Existing file was truncated;
* emit a create event.
*/
}
}
}
}
if (error) {
} else {
}
return (error);
}
/*
* Decide what the group-id of the created file should be.
* Set it in attribute list as advisory...
*/
if (error) {
return (error);
}
return (EACCES);
}
lfaware);
/*
* If this is not an exclusive create, then the CREATE
* request will be made with the GUARDED mode set. This
* means that the server will return EEXIST if the file
* exists. The file could exist because of a retransmitted
* request. In this case, we recover by starting over and
* checking to see whether the file exists. This second
* time through it should and a CREATE request will not be
* sent.
*
* This handles the problem of a dangling CREATE request
* which contains attributes which indicate that the file
* should be truncated. This retransmitted request could
* possibly truncate valid data in the file if not caught
* by the duplicate request mechanism on the server or if
* not caught by other means. The scenario is:
*
* Client transmits CREATE request with size = 0
* Client times out, retransmits request.
* Response to the first request arrives from the server
* and the client proceeds on.
* Client writes data to the file.
* The server now processes retransmitted CREATE request
* and truncates file.
*
* The use of the GUARDED CREATE request prevents this from
* happening because the retransmitted CREATE would fail
* with EEXIST and would not truncate the file.
*/
#ifdef DEBUG
#endif
goto top;
}
return (error);
}
return (error);
}
/* ARGSUSED */
static int
{
int error;
int douprintf;
hrtime_t t;
/*
* Construct the create verifier. This verifier needs
* to be unique between different clients. It also needs
* to vary for each exclusive create request generated
* from the client to the server.
*
* The first attempt is made to use the hostid and a
* unique number on the client. If the hostid has not
* been set, the high resolution time that the exclusive
* create request is being made is used. This will work
* unless two different clients, both with the hostid
* not set, attempt an exclusive create request on the
* same file, at exactly the same clock time. The
* chances of this happening seem small enough to be
* reasonable.
*/
else {
gethrestime(&now);
}
/*
* Since the server will use this value for the mtime,
* make sure that it can't overflow. Zero out the MSB.
* The actual value does not matter here, only its uniqeness.
*/
} else {
/*
* Issue the non-exclusive create in guarded mode. This
* may result in some false EEXIST responses for
* retransmitted requests, but these will be handled at
* a higher level. By using GUARDED, duplicate requests
* to do file truncation and possible access problems
* can be avoided.
*/
if (error) {
/* req time field(s) overflow - return immediately */
return (error);
}
}
douprintf = 1;
t = gethrtime();
if (error) {
return (error);
}
if (!error) {
/*
* On exclusive create the times need to be explicitly
* set to clear any potential verifier that may be stored
* in one of these fields (see comment below). This
* is done here to cover the case where no post op attrs
* were returned or a 'invalid' time was returned in
* the attributes.
*/
if (error)
return (error);
} else {
} else {
/*
* On an exclusive create, it is possible
* that attributes were returned but those
* postop attributes failed to decode
* properly. If this is the case,
* then most likely the atime or mtime
* were invalid for our client; this
* is caused by the server storing the
* create verifier in one of the time
* fields(most likely mtime).
* So... we are going to setattr just the
*/
if (error =
/*
* Setting the times failed.
* Remove the file and return
* the error.
*/
(void) nfs3_remove(dvp,
return (error);
}
}
/*
* This handles the non-exclusive case
* and the exclusive case where no post op
* attrs were returned.
*/
if (error) {
return (error);
}
}
}
}
/*
* Check here for large file handled by
* LF-unaware process (as ufs_create() does)
*/
return (EOVERFLOW);
}
}
/*
* If doing an exclusive create, then generate
* a SETATTR to set the initial attributes.
* Try to set the mtime and the atime to the
* server's current time. It is somewhat
* expected that these fields will be used to
* store the exclusive create cookie. If not,
* server implementors will need to know that
* a SETATTR will follow an exclusive create
* and the cookie should be destroyed if
* appropriate. This work may have been done
* earlier in this function if post op attrs
* were not available.
*
* The AT_GID and AT_SIZE bits are turned off
* so that the SETATTR request will not attempt
* to process these. The gid will be set
* separately if appropriate. The size is turned
* off because it is assumed that a new file will
* be created empty and if the file wasn't empty,
* then the exclusive create will have failed
* because the file must have existed already.
* Therefore, no truncate operation is needed.
*/
if (error) {
/*
* Couldn't correct the attributes of
* the newly created file and the
* attributes are wrong. Remove the
* file and return an error to the
* application.
*/
return (error);
}
}
/*
* If the gid on the file isn't right, then
* generate a SETATTR to attempt to change
* it. This may or may not work, depending
* upon the server's semantics for allowing
* file ownership changes.
*/
}
/*
* If vnode is a device create special vnode
*/
} else
} else {
}
return (error);
}
/*
* after successful exclusive create. This function exists to avoid
* may be 'invalid' in client's view and therefore can not be trusted.
*/
static int
{
int error;
int douprintf;
hrtime_t t;
/* save the caller's mask so that it can be reset later */
/* Use the mask to initialize the arguments */
douprintf = 1;
t = gethrtime();
if (error) {
return (error);
}
if (!error) {
/*
* It is important to pick up the attributes.
* Since this is the exclusive create path, the
* attributes on the initial create were ignored
* and we need these to have the correct info.
*/
/*
* the bits.
*/
} else {
}
return (error);
}
/* ARGSUSED */
static int
{
int error;
int douprintf;
hrtime_t t;
case VCHR:
case VBLK:
if (error) {
/* req time field(s) overflow - return immediately */
return (error);
}
break;
case VFIFO:
case VSOCK:
if (error) {
/* req time field(s) overflow - return immediately */
return (error);
}
break;
default:
return (EINVAL);
}
douprintf = 1;
t = gethrtime();
if (error) {
return (error);
}
if (!error) {
if (error)
return (error);
} else {
} else {
if (error) {
return (error);
}
}
}
}
}
/*
* 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;
hrtime_t t;
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;
t = gethrtime();
/*
* The xattr dir may be gone after last attr is removed,
* so flush it from dnlc.
*/
if (error) {
} else {
if (!error) {
cr);
if (HAVE_RDDIR_CACHE(drp))
} else {
t, cr);
}
}
}
if (error == 0) {
}
return (error);
}
/* ARGSUSED */
static int
{
int error;
int douprintf;
hrtime_t t;
return (EPERM);
return (EOPNOTSUPP);
return (EINTR);
douprintf = 1;
t = gethrtime();
if (error) {
return (error);
}
if (!error) {
if (HAVE_RDDIR_CACHE(tdrp))
} else {
cr);
if (error == EOPNOTSUPP) {
}
}
if (!error) {
/*
* Notify the source file of this link operation.
*/
}
return (error);
}
/* ARGSUSED */
static int
{
return (EPERM);
}
/*
* nfs3rename does the real work of renaming in NFS Version 3.
*/
static int
{
int error;
int douprintf;
char *tmpname;
hrtime_t t;
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;
t = gethrtime();
if (error) {
if (nvp) {
}
return (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.
*/
}
}
}
} else {
cr);
}
/*
* 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) {
return (error);
}
if (!error) {
if (HAVE_RDDIR_CACHE(drp))
if (error) {
return (error);
}
} else {
} else {
if (error) {
return (error);
}
}
}
}
}
} else {
}
return (error);
}
/* ARGSUSED */
static int
{
int error;
int douprintf;
hrtime_t t;
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;
t = gethrtime();
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;
char *contents;
hrtime_t t;
return (EPERM);
return (EOPNOTSUPP);
if (error) {
/* req time field(s) overflow - return immediately */
return (error);
}
return (EINTR);
douprintf = 1;
t = gethrtime();
if (error) {
return (error);
}
if (!error) {
if (HAVE_RDDIR_CACHE(drp))
} else {
}
if (nfs3_do_symlink_cache &&
} else {
}
}
}
}
} else {
if (error == EOPNOTSUPP) {
}
}
return (error);
}
#ifdef DEBUG
static int nfs3_readdir_cache_hits = 0;
static int nfs3_readdir_cache_shorts = 0;
static int nfs3_readdir_cache_waits = 0;
static int nfs3_readdir_cache_misses = 0;
static int nfs3_readdir_readahead = 0;
#endif
static int nfs3_shrinkreaddir = 0;
/*
* Read directory entries.
* There are some weird things to look out for here. The uio_loffset
* 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
int doreadahead;
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);
}
}
/*
* It is possible that some servers may not be able to correctly
* handle a large READDIR or READDIRPLUS request due to bugs in
* their implementation. In order to continue to interoperate
* with them, this workaround is provided to limit the maximum
* size of a READDIRPLUS request to 1024. In any case, the request
* size is limited to MAXBSIZE.
*/
#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. There is nothing more to read.
*
* Don't if the application is not doing
* lookups in the directory. The readahead
* is only effective if the application can
* be doing work while an async thread is
* handling the over the wire request.
*/
doreadahead = FALSE;
doreadahead = FALSE;
else
doreadahead = TRUE;
if (!doreadahead) {
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. This routine decides whether to use
* READDIR or READDIRPLUS.
*/
/*
* 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;
/*
* Issue the proper request.
*
* If the server does not support READDIRPLUS, then use READDIR.
*
* Otherwise --
* Issue a READDIRPLUS if reading to fill an empty cache or if
* an application has performed a lookup in the directory which
* required an over the wire lookup. The use of READDIRPLUS
* will help to (re)populate the DNLC.
*/
}
} else
}
if (error)
return (error);
}
static void
{
int error;
int douprintf;
hrtime_t t;
/*
* NFS client failover support
* suppress failover unless we have a zero cookie
*/
}
#ifdef DEBUG
#else
#endif
douprintf = 1;
if (mi->mi_io_kstats) {
}
t = gethrtime();
if (mi->mi_io_kstats) {
}
if (error)
goto err;
if (error) {
goto err;
}
if (mi->mi_io_kstats) {
}
return;
err:
}
/*
* Read directory entries.
* There are some weird things to look out for here. The uio_loffset
* 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.
*/
static void
{
int error;
int douprintf;
/*
* NFS client failover support
* suppress failover unless we have a zero cookie
*/
}
#ifdef DEBUG
#else
#endif
douprintf = 1;
if (mi->mi_io_kstats) {
}
if (mi->mi_io_kstats) {
}
if (error) {
goto err;
}
if (error) {
if (error == EOPNOTSUPP) {
}
goto err;
}
if (mi->mi_io_kstats) {
}
return;
err:
}
#ifdef DEBUG
static int nfs3_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) {
"nfs3_bio: zero length write at %lld",
offset);
if (nfs3_bio_do_stop)
debug_enter("nfs3_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 (EIO);
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);
if (*noffp < 0)
return (EINVAL);
return (0);
}
/*
* number of nfs3_bsize blocks to read ahead.
*/
#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(nfs3_nra) readaheads when the readahead
* window is closed.
* c) Do readaheads between 1 to (nfs3_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;
<= (nfs3_nra - 1)))
else
readahead = 0;
nfs3_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.
*/
do {
/*
* 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
#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.
*/
do {
/*
* 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);
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 nfs3getattr 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 nfs3_map(). Now, r_rwlock is acquired in order
* and we can prevent the deadlock that would have occurred
* when nfs3_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;
return (EIO);
/* check for valid cmd parameter */
return (EINVAL);
/* 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.
*/
/*
* 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++;
&rp->r_statelock) == 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);
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()/nfs3_delmap()
* - as_unmap()->SEGOP_UNMAP()/segvn_unmap()->VOP_DELMAP()/nfs3_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
* nfs3_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 nfs3_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 nfs3_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 and
* commit 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 and potential commit 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;
}
static int nfs3_pathconf_disable_cache = 0;
#ifdef DEBUG
static int nfs3_pathconf_cache_hits = 0;
static int nfs3_pathconf_cache_misses = 0;
#endif
/* ARGSUSED */
static int
{
int error;
int douprintf;
hrtime_t t;
return (EIO);
/*
* Large file spec - need to base answer on info stored
* on original FSINFO response.
*/
if (cmd == _PC_FILESIZEBITS) {
unsigned long long ll;
long l = 1;
if (ll == 0) {
*valp = 0;
return (0);
}
if (ll & 0xffffffff00000000) {
}
if (ll & 0xffff0000) {
}
if (ll & 0xff00) {
}
if (ll & 0xf0) {
}
if (ll & 0xc) {
}
if (ll & 0x2)
l += 2;
else if (ll & 0x1)
l += 1;
*valp = l;
return (0);
}
if (cmd == _PC_ACL_ENABLED) {
return (0);
}
if (cmd == _PC_XATTR_EXISTS) {
error = 0;
*valp = 0;
int error = 0;
return (0);
return (EINTR);
error = 0;
*valp = 0;
}
}
return (error);
}
}
error = 0;
switch (cmd) {
case _PC_LINK_MAX:
break;
case _PC_NAME_MAX:
break;
case _PC_PATH_MAX:
case _PC_SYMLINK_MAX:
*valp = MAXPATHLEN;
break;
case _PC_CHOWN_RESTRICTED:
break;
case _PC_NO_TRUNC:
break;
default:
break;
}
#ifdef DEBUG
#endif
return (error);
}
}
#ifdef DEBUG
#endif
douprintf = 1;
t = gethrtime();
if (error)
return (error);
if (!error) {
if (!nfs3_pathconf_disable_cache) {
}
}
switch (cmd) {
case _PC_LINK_MAX:
break;
case _PC_NAME_MAX:
break;
case _PC_PATH_MAX:
case _PC_SYMLINK_MAX:
*valp = MAXPATHLEN;
break;
case _PC_CHOWN_RESTRICTED:
break;
case _PC_NO_TRUNC:
break;
default:
return (EINVAL);
}
} else {
}
return (error);
}
/*
* 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);
return (EIO);
} else
return (error);
}
/* ARGSUSED */
static void
{
int error;
/*
* We should get called with fl equal to either B_FREE or
* B_INVAL. Any other value is illegal.
*
* The page that we are either supposed to free or destroy
* should be exclusive locked and its io lock should not
* be held.
*/
/*
* If the page doesn't need to be committed or we shouldn't
* even bother attempting to commit it, then just make sure
* that the p_fsdata byte is clear and then either free or
* destroy the page as appropriate.
*/
else
return;
}
/*
* If there is a page invalidation operation going on, then
* if this is one of the pages being destroyed, then just
* clear the p_fsdata byte and then either free or destroy
* the page as appropriate.
*/
else
return;
}
/*
* If we are freeing this page and someone else is already
* waiting to do a commit, then just unlock the page and
* return. That other thread will take care of commiting
* this page. The page can be freed sometime after the
* commit has finished. Otherwise, if the page is marked
* as delay commit, then we may be getting called from
* pvn_write_done, one page at a time. This could result
* in one commit per page, so we end up doing lots of small
* commits instead of fewer larger commits. This is bad,
* we want do as few commits as possible.
*/
return;
}
return;
}
}
/*
* Check to see if there is a signal which would prevent an
* attempt to commit the pages from being successful. If so,
* then don't bother with all of the work to gather pages and
* generate the unsuccessful RPC. Just return from here and
* let the page be committed at some later time.
*/
return;
}
/*
* We are starting to need to commit pages, so let's try
* to commit as many as possible at once to reduce the
* overhead.
*
* Set the `commit inprogress' state bit. We must
* first wait until any current one finishes. Then
* we initialize the c_pages list with this page.
*/
}
/*
* Gather together all other pages which can be committed.
* They will all be chained off r_commit.c_pages.
*/
/*
* Clear the `commit inprogress' status and disconnect
* the list of pages to be committed from the rnode.
* At this same time, we also save the starting offset
* and length of data to be committed on the server.
*/
return;
}
/*
* Actually generate the COMMIT3 over the wire operation.
*/
/*
* If we got an error during the commit, just unlock all
* of the pages. The pages will get retransmitted to the
* server during a putpage operation.
*/
if (error) {
}
return;
}
/*
* We've tried as hard as we can to commit the data to stable
* storage on the server. We release the rest of the pages
* and clear the commit required state. They will be put
* onto the tail of the cachelist if they are nolonger
* mapped.
*/
}
/*
* It is possible that nfs3_commit didn't return error but
* some other thread has modified the page we are going
* In this case we need to rewrite the page. Do an explicit check
* be rewritten so unlock the page and return.
*/
return;
}
/*
* Now, as appropriate, either free or destroy the page
* that we were called with.
*/
else
}
static int
{
int error;
int douprintf;
} else {
}
douprintf = 1;
if (error)
return (error);
if (!error) {
return (0);
}
} else {
goto doitagain;
}
}
/*
* Can't do a PURGE_STALE_FH here because this
* can cause a deadlock. nfs3_commit can
* be called from nfs3_dispose which can be called
* indirectly via pvn_vplist_dirty. PURGE_STALE_FH
* can call back to pvn_vplist_dirty.
*/
} else {
}
}
return (error);
}
static void
{
}
/*
* This routine is used to gather together a page list of the pages
* which are to be committed on the server. This routine must not
* be called if the calling thread holds any locked pages.
*
* The calling thread must have set RCOMMIT. This bit is used to
* serialize access to the commit structure in the rnode. As long
* as the thread has set RCOMMIT, then it can manipulate the commit
* structure without requiring any other locks.
*/
static void
{
/*
* If there are no pages associated with this vnode, then
* just return.
*/
return;
}
/*
* Step through all of the pages associated with this vnode
* looking for pages which need to be committed.
*/
do {
/* Skip marker pages. */
continue;
/*
* If this page does not need to be committed or is
* modified, then just skip it.
*/
continue;
/*
* Attempt to lock the page. If we can't, then
* someone else is messing with it and we will
* just skip it.
*/
continue;
/*
* If this page does not need to be committed or is
* modified, then just skip it. Recheck now that
* the page is locked.
*/
continue;
}
(void *)pp);
}
/*
* The page needs to be committed and we locked it.
* Update the base and length parameters and add it
* to r_pages.
*/
}
}
/*
* This routine is used to gather together a page list of the pages
* which are to be committed on the server. This routine must not
* be called if the calling thread holds any locked pages.
*
* The calling thread must have set RCOMMIT. This bit is used to
* serialize access to the commit structure in the rnode. As long
* as the thread has set RCOMMIT, then it can manipulate the commit
* structure without requiring any other locks.
*/
static void
{
/*
* If there are no pages associated with this vnode, then
* just return.
*/
return;
/*
* Calculate the ending offset.
*/
/*
* Lookup each page by vp, offset.
*/
continue;
/*
* If this page does not need to be committed or is
* modified, then just skip it.
*/
continue;
}
/*
* The page needs to be committed and we locked it.
* Update the base and length parameters and add it
* to r_pages.
*/
} else {
}
}
}
static int
{
int error;
/*
* Flush the data portion of the file and then commit any
* portions which need to be committed. This may need to
* be done twice if the server has changed state since
* data was last written. The data will need to be
* rewritten to the server and then a new commit done.
*
* In fact, this may need to be done several times if the
* server is having problems and crashing while we are
* attempting to do this.
*/
top:
/*
* Do a flush based on the poff and plen arguments. This
* will asynchronously write out any modified pages in the
* range specified by (poff, plen). This starts all of the
* i/o operations which will be waited for in the next
* call to nfs3_putpage
*/
error = 0;
/*
* Do a flush based on the poff and plen arguments. This
* will synchronously write out any modified pages in the
* range specified by (poff, plen) and wait until all of
* the asynchronous i/o's in that range are done as well.
*/
if (!error)
if (error)
return (error);
goto top;
}
/*
* Now commit any pages which might need to be committed.
* If the error, NFS_VERF_MISMATCH, is returned, then
* start over with the flush operation.
*/
if (error == NFS_VERF_MISMATCH)
goto top;
return (error);
}
static int
{
return (EIO);
/*
* Set the `commit inprogress' state bit. We must
* first wait until any current one finishes.
*/
}
/*
* Gather together all of the pages which need to be
* committed.
*/
if (plen == 0)
else
/*
* Clear the `commit inprogress' bit and disconnect the
* page list which was gathered together in nfs3_get_commit.
*/
/*
* If any pages need to be committed, commit them and
* then unlock them so that they can be freed some
* time later.
*/
/*
* No error occurred during the flush portion
* of this operation, so now attempt to commit
* the data to stable storage on the server.
*
* This will unlock all of the pages on the list.
*/
}
return (0);
}
static int
{
int error;
/*
* If we got an error, then just unlock all of the pages
* on the list.
*/
if (error) {
}
return (error);
}
/*
* We've tried as hard as we can to commit the data to stable
* storage on the server. We just unlock the pages and clear
* the commit required state. They will get freed later.
*/
}
return (error);
}
static void
{
}
/* 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);
}