/*
* 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) 2016 STRATO AG. All rights reserved.
*/
/*
* Copyright 2015 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright 1983,1984,1985,1986,1987,1988,1989 AT&T.
* All Rights Reserved
*/
/*
* Copyright (c) 2013, Joyent, 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 <nfs/nfs_clnt.h>
#include <nfs/nfs4_kprot.h>
#include <nfs/nfs4_clnt.h>
#include <sys/int_fmtio.h>
typedef struct {
typedef enum nfs4_acl_op {
char *, dirattr_info_t *);
nfs4_open_stream_t *, int *, int *, nfs4_close_type_t,
nfs4_error_t *, int *);
cred_t *);
stable_how4 *);
vsecattr_t *);
cred_t *, int, int, enum createmode4, int);
caller_context_t *);
cred_t *);
int, cred_t *);
int, cred_t *);
static void nfs4_set_mod(vnode_t *);
static void nfs4_get_commit(vnode_t *);
cred_t *);
cred_t *);
cred_t *, nfs4_lock_owner_t *);
static void nfs4_free_delmapcall(nfs4_delmapcall_t *);
static nfs4_delmapcall_t *nfs4_init_delmapcall();
static int nfs4_find_and_delete_delmapcall(rnode4_t *, int *);
/*
* Routines that implement the setting of v4 args for the misc. ops
*/
static void nfs4args_lock_free(nfs_argop4 *);
static void nfs4args_lockt_free(nfs_argop4 *);
static void nfs4args_setattr_free(nfs_argop4 *);
bitmap4);
static void nfs4args_verify_free(nfs_argop4 *);
WRITE4args **, nfs4_stateid_types_t *);
/*
* These are the vnode ops functions that implement the vnode interface to
* the networked file system. See more comments below at nfs4_vnodeops.
*/
caller_context_t *);
caller_context_t *);
caller_context_t *);
caller_context_t *);
caller_context_t *);
caller_context_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 *);
cred_t *, caller_context_t *);
caller_context_t *);
caller_context_t *);
/*
* These vnode ops are required to be called from outside this source file,
* e.g. by ephemeral mount stub vnode ops, and so may not be declared
* as static.
*/
caller_context_t *);
caller_context_t *, int *, pathname_t *);
caller_context_t *);
caller_context_t *);
caller_context_t *);
/*
* Used for nfs4_commit_vp() to indicate if we should
* wait on pending writes.
*/
#define NFS4_WRITE_NOWAIT 0
/*
* Error flags used to pass information about certain special errors
* which need to be handled specially.
*/
/*
* Flags used to differentiate between which operation drove the
* potential CLOSE OTW. (see nfs4_close_otw_if_necessary)
*/
/* ALIGN64 aligns the given buffer and adjust buffer size to 64 bit */
if (x) { \
x = sizeof (uint64_t) - (x); \
sz -= (x); \
ptr += (x); \
}
#ifdef DEBUG
int nfs4_client_attr_debug = 0;
int nfs4_client_state_debug = 0;
int nfs4_client_shadow_debug = 0;
int nfs4_client_lock_debug = 0;
int nfs4_seqid_sync = 0;
int nfs4_client_map_debug = 0;
static int nfs4_pageio_debug = 0;
int nfs4_client_inactive_debug = 0;
int nfs4_client_recov_debug = 0;
int nfs4_client_failover_debug = 0;
int nfs4_client_call_debug = 0;
int nfs4_client_lookup_debug = 0;
int nfs4_client_zone_debug = 0;
int nfs4_lost_rqst_debug = 0;
int nfs4_rdattrerr_debug = 0;
int nfs4_open_stream_debug = 0;
static int nfs4_create_misses = 0;
static int nfs4_readdir_cache_shorts = 0;
static int nfs4_readdir_readahead = 0;
static int nfs4_bio_do_stop = 0;
int nfs4_mmap_debug = 0;
static int nfs4_pathconf_cache_hits = 0;
static int nfs4_pathconf_cache_misses = 0;
int nfs4close_all_cnt;
int nfs4close_one_debug = 0;
int nfs4close_notw_debug = 0;
int denied_to_flk_debug = 0;
void *lockt_denied_debug;
#endif
/*
* How long to wait before trying again if OPEN_CONFIRM gets ETIMEDOUT
* or NFS4ERR_RESOURCE.
*/
/*
* number of pages to read ahead
* optimized for 100 base-T.
*/
static int nfs4_pathconf_disable_cache = 0;
/*
* 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.
*/
/* no separate nfs4_dump */
};
/*
* The following are subroutines and definitions to set args or get res
* for the different nfsv4 ops
*/
void
{
int i;
for (i = 0; i < arglen; i++) {
}
}
}
static void
{
}
}
}
static void
{
}
}
static void
{
/*
* The stateid is set to 0 if client is not modifying the size
* and otherwise to whatever nfs4_get_stateid() returns.
*
* want to change this in the future (by OPENing the file). See
* bug # 4474852.
*/
} else {
sizeof (stateid4));
}
if (*error)
}
static void
{
}
static int
{
int error = 0;
switch (op) {
case OP_VERIFY:
break;
case OP_NVERIFY:
break;
default:
return (EINVAL);
}
if (!error)
if (error)
return (error);
}
static void
{
case OP_VERIFY:
break;
case OP_NVERIFY:
break;
default:
break;
}
}
static void
{
}
void
{
}
}
}
/*
* XXX: This is referenced in modstubs.s
*/
struct vnodeops *
nfs4_getvnodeops(void)
{
return (nfs4_vnodeops);
}
/*
* The OPEN operation opens a regular file.
*/
/*ARGSUSED3*/
static int
{
int error;
int just_been_created;
return (EIO);
/*
* Check to see if opening something besides a regular file;
* if so skip the OTW call
*/
return (error);
}
/*
* XXX - would like a check right here to know if the file is
* executable or not, so as to skip OTW
*/
return (error);
return (EINTR);
return (error);
}
/*
* See if this file has just been CREATEd.
* If so, clear the flag and update the dnlc, which was previously
* skipped in nfs4_create.
* XXX need better serilization on this.
* XXX move this into the nf4open_otw call, after we have
* XXX acquired the open owner seqid sync.
*/
if (rp->created_v4) {
rp->created_v4 = 0;
/* This is needed so we don't bump the open ref count */
just_been_created = 1;
} else {
just_been_created = 0;
}
/*
* FWRITE (to drive successful setattr(size=0) after open)
*/
/* release the hold from vtodv */
/* exchange the shadow for the master vnode, if needed */
return (error);
}
/*
* See if there's a "lost open" request to be saved and recovered.
*/
static void
{
char *srccfp;
lost_rqstp->lr_op = 0;
return;
}
"nfs4open_save_lost_rqst: error %d", error));
/*
* The vp (if it is not NULL) and dvp are held and rele'd via
* the recovery code. See nfs4_save_lost_rqst.
*/
} else {
}
}
struct nfs4_excl_time {
};
/*
*
* ARGSUSED
*/
static int
{
int argoplist_size;
int created_osp;
hrtime_t t;
int acc = 0;
int fh_differs = 0;
/*
* Make sure we properly deal with setting the right gid on
* a newly created file to reflect the parent's setgid bit
*/
setgid_flag = 0;
if (create_flag && in_va) {
/*
* If there is grpid mount flag used or
* the parent's directory has the setgid bit set
* _and_ the client was able to get a valid mapping
* for the parent dir's owner_group, we want to
* append NVERIFY(owner_group == dva.va_gid) and
* SETATTR to the CREATE compound.
*/
setgid_flag = 1;
}
}
/*
* Normal/non-create compound:
* PUTFH(dfh) + OPEN(create) + GETFH + GETATTR(new)
*
* Open(create) compound no setgid:
* PUTFH(dfh) + SAVEFH + OPEN(create) + GETFH + GETATTR(new) +
* RESTOREFH + GETATTR
*
* Open(create) setgid:
* PUTFH(dfh) + OPEN(create) + GETFH + GETATTR(new) +
* SAVEFH + PUTFH(dfh) + GETATTR(dvp) + RESTOREFH +
* NVERIFY(grp) + SETATTR
*/
if (setgid_flag) {
numops = 10;
idx_open = 1;
idx_fattr = 3;
} else if (create_flag) {
numops = 7;
idx_open = 2;
idx_fattr = 4;
} else {
numops = 4;
idx_open = 1;
idx_fattr = 3;
}
(void *)cr));
if (create_flag) {
/*
* We are to create a file. Initialize the passed in vnode
* pointer.
*/
} else {
/*
* Check to see if the client owns a read delegation and is
* trying to open for write. If so, then return the delegation
* to avoid the server doing a cb_recall and returning DELAY.
* NB - we don't use the statev4_lock here because we'd have
* to drop the lock anyway and the result would be stale.
*/
/*
* If the file has a delegation, then do an access check up
* front. This avoids having to an access check later after
* we've already done start_op, which could deadlock.
*/
}
}
recov_state.rs_flags = 0;
fh_differs = 0;
nfs4_error_zinit(&e);
if (e.error) {
return (e.error);
}
/* putfh directory fh */
/* name of file */
if (create_flag) {
/* CREATE a file */
if (createmode == EXCLUSIVE4) {
if (did_excl_setup == FALSE) {
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.
*/
}
/* Now copy over verifier to OPEN4args. */
} else {
int v_error;
/* GUARDED4 or UNCHECKED4 */
if (v_error) {
return (v_error);
}
}
} else {
/* NO CREATE */
}
} else {
/* XXX should we just fail here? */
}
/*
* This increments oop's ref count or creates a temporary 'just_created'
* open owner that will become valid when this OPEN/OPEN_CONFIRM call
* completes.
*/
/* See if a permanent or just created open owner exists */
if (!oop) {
/*
* This open owner does not exist so create a temporary
* just created one.
*/
}
/* this length never changes, do alloc before seqid sync */
}
goto recov_retry;
}
/* Check to see if we need to do the OTW call */
if (!create_flag) {
/*
* The OTW open is not necessary. Either
* the open can succeed without it (eg.
* delegation, error == 0) or the open
* must fail due to an access failure
* (error != 0). In either case, tidy
* up and return.
*/
return (e.error);
}
}
open_args->share_access = 0;
/*
*/
/* getattr */
if (setgid_flag) {
/*
* For setgid case, we need to:
* 4:savefh(new) 5:putfh(dir) 6:getattr(dir) 7:restorefh(new)
*/
/*
* nverify
*/
supp_attrs))) {
/*
* setattr
*
* We _know_ we're not messing with AT_SIZE or
* AT_XTIME, so no need for stateid or flags.
* Also we specify NULL rp since we're only
* interested in setting owner_group attributes.
*/
supp_attrs, &e.error, 0);
if (e.error)
}
if (e.error) {
/*
* XXX - Revisit the last argument to nfs4_end_op()
* once 5020486 is fixed.
*/
return (e.error);
}
} else if (create_flag) {
}
"nfs4open_otw: %s call, nm %s, rp %s",
t = gethrtime();
if (needrecov) {
}
if (bsep)
/* give up if we keep getting BAD_SEQID */
if (num_bseqid_retry == 0)
}
if (setgid_flag) {
}
if (!e.error)
}
return (e.error);
}
goto recov_retry;
}
/*
* Will check and update lease after checking the rflag for
* OPEN_CONFIRM in the successful OPEN call.
*/
/*
* XXX what if we're crossing mount points from server1:/drp
*/
/* Signal our end of use of the open seqid */
/*
* This will destroy the open owner if it was just created,
* and no one else has put a reference on it.
*/
if (setgid_flag) {
}
/*
* If the reply is NFS4ERR_ACCESS, it may be because
* we are root (no root net access). If the real uid
* is not root, then retry with the real uid instead.
*/
}
goto recov_retry;
}
return (e.error);
}
#ifdef DEBUG
/*
* verify attrset bitmap
*/
if (create_flag &&
/* make sure attrset returned is what we asked for */
/* XXX Ignore this 'error' for now */
/* EMPTY */;
}
#endif
}
/*
* The open stateid has been updated on the server but not
* on the client yet. There is a path: makenfs4node->nfs4_attr_cache->
* flush_pages->VOP_PUTPAGE->...->nfs4write where we will issue an OTW
* WRITE call. That, however, will use the old stateid, so go ahead
* and upate the open stateid now, before any call to makenfs4node.
*/
if (vpi) {
if (tmp_osp) {
}
/*
* We must determine if the file handle given by the otw open
* is the same as the file handle which was passed in with
* *vpp. This case can be reached if the file we are trying
* to open has been removed and another file has been created
* having the same file name. The passed in vnode is released
* later.
*/
}
if (create_flag || fh_differs) {
int rnode_err = 0;
if (e.error)
/*
* For the newly created vp case, make sure the rnode
* isn't bad before using it.
*/
if (rnode_err) {
if (setgid_flag) {
}
return (EIO);
}
} else {
}
/*
* It seems odd to get a full set of attrs and then not update
* the object's attrcache in the non-create case. Create case uses
* the attrs since makenfs4node checks to see if the attrs need to
* be updated (and then updates them). The non-create case should
* update attrs also.
*/
}
nfs4_error_zinit(&e);
/* This does not do recovery for vp explicitly. */
if (setgid_flag) {
}
if (create_flag || fh_differs) {
/* rele the makenfs4node */
}
}
if (retry_open == TRUE) {
"nfs4open_otw: retry the open since OPEN "
"CONFIRM failed with error %d stat %d",
(CE_NOTE, "nfs4open_otw: switch "
"createmode from GUARDED4 to "
"UNCHECKED4"));
}
goto recov_retry;
}
if (!e.error) {
e.stat == NFS4ERR_BADOWNER)
}
return (e.error);
}
}
if (create_flag)
/* Doesn't matter if 'oo_just_created' already was set as this */
if (oop->oo_cred_otw)
/* returns with 'os_sync_lock' held */
if (!osp) {
"nfs4open_otw: failed to create an open stream"));
"signal our end of use of the open seqid"));
if (setgid_flag) {
}
if (create_flag || fh_differs)
return (EINVAL);
}
osp->os_share_acc_read++;
/*
* Need to reset this bitfield for the possible case where we were
* going to OTW CLOSE the file, got a non-recoverable error, and before
* we could retry the CLOSE, OPENed the file again.
*/
osp->os_final_close = 0;
osp->os_force_close = 0;
#ifdef DEBUG
if (osp->os_failed_reopen)
" clearing os_failed_reopen for osp %p, cr %p, rp %s",
#endif
osp->os_failed_reopen = 0;
}
/* get rid of our reference to find oop */
/* accept delegation, if any */
if (createmode == EXCLUSIVE4 &&
" EXCLUSIVE4: sending a SETATTR"));
/*
* 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.
*
* 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 (e.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.
*/
/* XXX will this take care of client state ? */
"nfs4open_otw: EXCLUSIVE4: error %d on SETATTR:"
" remove file", e.error));
/*
* Since we've reled the vnode and removed
* the file we now need to return the error.
* At this point we don't want to update the
* dircaches, call nfs4_waitfor_purge_complete
* or set vpp to vp so we need to skip these
* as well.
*/
goto skip_update_dircaches;
}
}
/*
* If we created or found the correct vnode, due to create_flag or
* fh_differs being set, then update directory cache attribute, readdir
* and dnlc caches.
*/
if (create_flag || fh_differs) {
/*
* Make sure getattr succeeded before using results.
* note: op 7 is getattr(dir) for both flavors of
* open(create).
*/
dinfo.di_time_call = t;
} else {
}
dinfop);
}
/*
* If the page cache for this file was flushed from actions
* above, it was done asynchronously and if that is true,
* there is a need to wait here for it to complete. This must
*/
(void) nfs4_waitfor_purge_complete(vp);
/*
* It is implicit that we are in the open case (create_flag == 0) since
* fh_differs can only be set to a non-zero value in the open case.
*/
/*
* Be sure to set *vpp to the correct value before returning.
*/
if (setgid_flag) {
}
if (ncr)
return (e.error);
}
/*
* Reopen an open instance. cf. nfs4open_otw().
*
* Errors are returned by the nfs4_error_t parameter.
* - ep->error contains an errno value or zero.
* - if it is zero, ep->stat is set to an NFS status code, if any.
* If the file could not be reopened, but the caller should continue, the
* file is marked dead and no error values are returned. If the caller
* should stop recovering open files and start over, either the ep->error
* value or ep->stat will indicate an error (either something that requires
* recovery or EAGAIN). Note that some recovery (e.g., expired volatile
* filehandles) may be handled silently by this routine.
* - if it is EINTR, ETIMEDOUT, or NFS4_FRC_UNMT_ERR, recovery for lost state
* will be started, so the caller should not do it.
*
* Gotos:
* - kill_file : reopen failed in such a fashion to constitute marking the
* file dead and setting the open stream's 'os_failed_reopen' as 1. This
* is for cases where recovery is not possible.
* - failed_reopen : same as above, except that the file has already been
* marked dead, so no need to do it again.
* - bailout : reopen failed but we are able to recover and retry the reopen -
* either within this function immediately or via the calling function.
*/
void
{
int fh_different;
hrtime_t t;
/* this is the cred used to find the open owner */
failed_msg = "Couldn't reopen: no cred";
goto kill_file;
}
/* use this cred for OTW operations */
top:
/* File system has been unmounted, quit */
failed_msg = "Couldn't reopen: file system has been unmounted";
goto kill_file;
}
failed_msg = "can't reopen: no open owner";
goto kill_file;
}
goto bailout;
}
/*
* If the rnode has a delegation and the delegation has been
* recovered and the server didn't request a recall and the caller
* didn't specifically ask for CLAIM_PREVIOUS (nfs4frlock during
* recovery) and the rnode hasn't been marked dead, then install
* the delegation stateid in the open stream. Otherwise, proceed
* with a CLAIM_PREVIOUS or CLAIM_NULL OPEN.
*/
!rp->r_deleg_return_pending &&
!rp->r_deleg_needs_recall &&
goto bailout;
}
/*
* If the file failed recovery, just quit. This failure need not
* affect other reopens, so don't return an error.
*/
goto failed_reopen;
}
/*
* argop is empty here
*
* PUTFH, OPEN, GETATTR
*/
"nfs4_reopen: file is type %d, id %s",
if (claim != CLAIM_PREVIOUS) {
/*
* if this is a file mount then
* use the mntinfo parentfh
*/
} else {
/* putfh fh to reopen */
}
if (claim == CLAIM_NULL) {
"failed for vp 0x%p for CLAIM_NULL with %m",
(void *)vp);
failed_msg = "Couldn't reopen: vtoname failed for "
"CLAIM_NULL";
/* nothing allocated yet */
goto kill_file;
}
} else if (claim == CLAIM_PREVIOUS) {
/*
* We have two cases to deal with here:
* 1) We're being called to reopen files in order to satisfy
* a lock operation request which requires us to explicitly
* reopen files which were opened under a delegation. If
* we're in recovery, we *must* use CLAIM_PREVIOUS. In
* that case, frc_use_claim_previous is TRUE and we must
* use the rnode's current delegation type (r_deleg_type).
* 2) We're reopening files during some form of recovery.
* In this case, frc_use_claim_previous is FALSE and we
* use the delegation type appropriate for recovery
* (r_deleg_needs_recovery).
*/
rp->r_deleg_type :
} else if (claim == CLAIM_DELEGATE_CUR) {
"failed for vp 0x%p for CLAIM_DELEGATE_CUR "
"with %m", (void *)vp);
failed_msg = "Couldn't reopen: vtoname failed for "
"CLAIM_DELEGATE_CUR";
/* nothing allocated yet */
goto kill_file;
}
}
open_args->share_access = 0;
open_args->share_deny = 0;
if (osp->os_share_deny_read)
if (osp->os_share_deny_write)
/* Construct the getfh part of the compound */
/* Construct the getattr part of the compound */
t = gethrtime();
if (!is_recov && !frc_use_claim_previous &&
goto bailout;
}
goto top;
}
goto bailout;
failed_msg = "Couldn't reopen: rpc error";
goto kill_file;
}
if (nfs4_need_to_bump_seqid(&res))
case NFS4_OK:
rp->r_delay_interval = 0;
}
break;
case NFS4ERR_BAD_SEQID:
goto kill_file;
case NFS4ERR_NO_GRACE:
if (claim == CLAIM_PREVIOUS) {
/*
* Retry as a plain open. We don't need to worry about
* checking the changeinfo: it is acceptable for a
* client to re-open a file and continue processing
* (in the absence of locks).
*/
"nfs4_reopen: CLAIM_PREVIOUS: NFS4ERR_NO_GRACE; "
"will retry as CLAIM_NULL"));
claim = CLAIM_NULL;
goto top;
}
"Couldn't reopen: tried reclaim outside grace period. ";
goto kill_file;
case NFS4ERR_GRACE:
goto bailout;
goto top;
case NFS4ERR_DELAY:
goto bailout;
goto top;
case NFS4ERR_FHEXPIRED:
/* recover filehandle and retry */
goto top;
failed_msg = "Couldn't reopen: recovery aborted";
goto kill_file;
case NFS4ERR_RESOURCE:
case NFS4ERR_STALE_CLIENTID:
case NFS4ERR_WRONGSEC:
case NFS4ERR_EXPIRED:
/*
* Do not mark the file dead and let the calling
* function initiate recovery.
*/
goto bailout;
case NFS4ERR_ACCESS:
goto top;
}
/* fall through */
default:
"nfs4_reopen: r_server 0x%p, mi_curr_serv 0x%p, rnode %s",
failed_msg = "Couldn't reopen: NFSv4 error";
goto kill_file;
}
/*
* Check if the path we reopened really is the same
* file. We could end up in a situation where the file
* was removed and a new file created with the same name.
*/
if (fh_different) {
/* Oops, we don't have the same file */
failed_msg = "Couldn't reopen: Persistent "
"file handle changed";
else
failed_msg = "Couldn't reopen: Volatile "
"(no expire on open) file handle changed";
goto kill_file;
} else {
/*
* We have volatile file handles that don't compare.
* If the fids are the same then we assume that the
* file handle expired but the rnode still refers to
* the same file object.
*
* First check that we have fids or not.
* If we don't we have a dumb server so we will
* just assume every thing is ok for now.
*/
/*
* We have fids, but they don't
* compare. So kill the file.
*/
"Couldn't reopen: file handle changed"
" due to mismatched fids";
(void) xdr_free(xdr_COMPOUND4res_clnt,
goto kill_file;
} else {
/*
* We have volatile file handles that refers
* to the same file (at least they have the
* same fid) or we don't have fids so we
* can't tell. :(. We'll be a kind and accepting
* client so we'll update the rnode's file
* handle with the otw handle.
*
* We need to drop mi->mi_fh_lock since
* sh4_update acquires it. Since there is
* only one recovery thread there is no
* race.
*/
}
}
} else {
}
/*
* If the server wanted an OPEN_CONFIRM but that fails, just start
* over. Presumably if there is a persistent error it will show up
* when we resend the OPEN.
*/
goto top;
}
}
osp->os_delegation = 0;
/*
* Need to reset this bitfield for the possible case where we were
* going to OTW CLOSE the file, got a non-recoverable error, and before
* we could retry the CLOSE, OPENed the file again.
*/
osp->os_final_close = 0;
osp->os_force_close = 0;
/* accept delegation, if any */
return;
"nfs4_reopen: setting os_failed_reopen for osp %p, cr %p, rp %s",
}
}
/* for . and .. OPENs */
/* ARGSUSED */
static int
{
/*
* If close-to-open consistency checking is turned off or
* if there is no cached data, we can avoid
* the over the wire getattr. Otherwise, force a
* call to the server to get fresh attributes and to
* check caches. This is required for close-to-open
* consistency.
*/
return (0);
}
/*
* CLOSE a file
*/
/* ARGSUSED */
static int
{
int error = 0;
int r_error = 0;
int n4error = 0;
/*
* Remove client state for this (lockowner, file) pair.
* Issue otw v4 call to have the server do the same.
*/
/*
* 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
* nfs4_inactive() will clean up state: if the zone of the
* vnode's origin is still alive and kicking, the inactive
* thread will handle the request (from the correct zone), and
* everything (minus the OTW close call) should be OK. If the
* zone is going away nfs4_async_inactive() will throw away
* delegations, open streams and 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 (e.error) {
} else {
}
return (e.error);
}
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,
* do a synchronous flush and commit of all of the
* dirty and uncommitted pages.
*/
/*
* If this file type is one for which no explicit 'open' was
* done, then bail now (ie. no need for protocol 'close'). If
* otherwise, return any errors that may've been reported via
* the rnode.
*/
/*
* The sync putpage commit may have failed above, but since
* we're working w/a regular file, we need to do the protocol
* 'close' (nfs4close_one will figure out if an otw close is
* needed or not). Report any errors _after_ doing the protocol
* 'close'.
*/
/*
* Error reporting prio (Hi -> Lo)
*
* i) nfs4_putpage_commit (error)
* ii) rnode's (r_error)
* iii) nfs4close_one (n4error)
*/
}
/*
* Initialize *lost_rqstp.
*/
static void
{
lost_rqstp->lr_op = 0;
return;
}
"nfs4close_save_lost_rqst: error %d", error));
/*
* The vp is held and rele'd via the recovery code.
* See nfs4_save_lost_rqst.
*/
}
/*
* Assumes you already have the open seqid sync grabbed as well as the
* 'os_sync_lock'. Note: this will release the open seqid sync and
* 'os_sync_lock' if client recovery starts. Calling functions have to
* be prepared to handle this.
*
* 'recov' is returned as 1 if the CLOSE operation detected client recovery
* was needed and was started, and that the calling function should retry
* this function; otherwise it is returned as 0.
*
* Errors are returned via the nfs4_error_t parameter.
*/
static void
{
hrtime_t t;
/* Only set this to 1 if recovery is started */
*recov = 0;
/* do the OTW call to close the file */
if (close_type == CLOSE_RESEND)
else if (close_type == CLOSE_AFTER_RESEND)
else
/* putfh target fh */
rnode4info(rp)));
t = gethrtime();
}
/*
* if there was an error and no recovery is to be done
* then then set up the file to flush its cache if
* needed for the next caller.
*/
return;
}
if (needrecov) {
if (close_type != CLOSE_RESEND)
"nfs4close_otw: initiating recovery. error %d "
/*
* Drop the 'os_sync_lock' here so we don't hit
* a potential recursive mutex_enter via an
* 'open_stream_hold()'.
*/
*have_sync_lockp = 0;
(close_type != CLOSE_RESEND &&
/* drop open seq sync, and let the calling function regrab it */
*did_start_seqid_syncp = 0;
if (bsep)
/*
* For signals, the caller wants to quit, so don't say to
* retry. For forced unmount, if it's a user thread, it
* wants to quit. If it's a recovery thread, the retry
* will happen higher-up on the call stack. Either way,
* don't say to retry.
*/
close_type != CLOSE_RESEND &&
*recov = 1;
else
*recov = 0;
return;
}
return;
}
rp->created_v4 = 0;
/*
* This removes the reference obtained at OPEN; ie, when the
* open stream structure was created.
*
* We don't have to worry about calling 'open_stream_rele'
* since we our currently holding a reference to the open
* stream which means the count cannot go to 0 with this
* decrement.
*/
osp->os_ref_count--;
/*
* Avoid a deadlock with the r_serial thread waiting for
* os_sync_lock in nfs4_get_otw_cred_by_osp() which might be
* held by us. We will wait in nfs4_attr_cache() for the
* completion of the r_serial thread.
*/
*have_sync_lockp = 0;
}
}
/* ARGSUSED */
static int
{
uint_t n;
int error;
return (EISDIR);
return (EIO);
return (0);
return (EINVAL);
else
error = 0;
if (error)
return (error);
/*
* 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.
*/
}
error = 0;
do {
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);
else
error = 0;
if (error)
return (error);
/*
* 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);
}
}
/* update the change attribute, if we have a write delegation */
rp->r_deleg_change++;
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.
*/
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) {
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 nfs4_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.
*/
else
else
fsdata = C_NOCOMMIT;
do {
return (error);
}
/*
*/
static int
{
int reopen_needed;
if (!oop)
return (EIO);
/* returns with 'os_sync_lock' held */
if (!osp) {
return (EIO);
}
if (osp->os_failed_reopen) {
return (EIO);
}
/*
* Determine whether a reopen is needed. If this
* is a delegation open stream, then the os_delegation bit
* should be set.
*/
if (reopen_needed) {
return (EIO);
}
}
return (0);
}
/*
* Write to file. Writes to remote server in largest size
* chunks that the server can handle. Write is synchronous.
*/
static int
{
int tsize;
int recov;
*stab_comm = FILE_SYNC4;
recov_state.rs_flags = 0;
/* Is curthread the recovery thread? */
if (!recov) {
&recov_state, NULL);
if (e.error)
return (e.error);
}
/* 0. putfh target fh */
/* 1. write */
do {
if (mi->mi_io_kstats) {
}
else
if (mi->mi_io_kstats) {
}
if (!recov) {
return (e.error);
}
} else {
if (e.error)
return (e.error);
}
/*
* Do handling of OLD_STATEID outside
* of the normal recovery framework.
*
* If write receives a BAD stateid error while using a
* delegation stateid, retry using the open stateid (if it
* exists). If it doesn't have an open stateid, reopen the
* file first, then retry.
*/
if (!recov)
goto recov_retry;
if (!recov)
&recov_state, needrecov);
(void) xdr_free(xdr_COMPOUND4res_clnt,
return (EIO);
}
if (!recov)
&recov_state, needrecov);
/* hold needed for nfs4delegreturn_thread */
NFS4_DR_DISCARD), FALSE);
goto recov_retry;
}
if (needrecov) {
"nfs4write: client got error %d, res.status %d"
abort = nfs4_start_recovery(&e,
if (!e.error) {
(void) xdr_free(xdr_COMPOUND4res_clnt,
}
goto recov_retry;
return (e.error);
}
if (!recov)
return (e.error);
}
"nfs4write: server wrote %u, requested was %u",
if (!recov)
return (EIO);
}
(void) xdr_free(xdr_COMPOUND4res_clnt,
"nfs4write: server %s did not commit "
"to stable storage",
if (!recov)
return (EIO);
}
}
if (mi->mi_io_kstats) {
}
}
} else {
}
} while (count);
if (!recov)
return (e.error);
}
/*
* Read from a file. Reads data in largest chunks our interface can handle.
*/
static int
{
int tsize;
int doqueue;
int data_len;
doqueue = 1;
recov_state.rs_flags = 0;
&recov_state, NULL);
if (e.error)
return (e.error);
/* putfh target fh */
/* read */
do {
if (mi->mi_io_kstats) {
}
"nfs4read: %s call, rp %s",
rnode4info(rp)));
else
rargs->res_maxsize = 0;
if (uiop)
else
#ifdef DEBUG
if (nfs4read_error_inject) {
}
#endif
if (mi->mi_io_kstats) {
}
&recov_state, needrecov);
return (e.error);
}
/*
* Do proper retry for OLD and BAD stateid errors outside
* of the normal recovery framework. There are two differences
* between async and sync reads. The first is that we allow
* retry on BAD_STATEID for async reads, but not sync reads.
* The second is that we mark the file dead for a failed
* attempt with a special stateid for sync reads, but just
* return EIO for async reads.
*
* If a sync read receives a BAD stateid error while using a
* delegation stateid, retry using the open stateid (if it
* exists). If it doesn't have an open stateid, reopen the
* file first, then retry.
*/
&recov_state, needrecov);
(void) xdr_free(xdr_COMPOUND4res_clnt,
return (EIO);
}
goto recov_retry;
&recov_state, needrecov);
goto recov_retry;
&recov_state, needrecov);
(void) xdr_free(xdr_COMPOUND4res_clnt,
return (EIO);
}
&recov_state, needrecov);
/* hold needed for nfs4delegreturn_thread */
NFS4_DR_DISCARD), FALSE);
goto recov_retry;
}
if (needrecov) {
"nfs4read: initiating recovery\n"));
abort = nfs4_start_recovery(&e,
&recov_state, needrecov);
/*
* Do not retry if we got OLD_STATEID using a special
* stateid. This avoids looping with a broken server.
*/
/*
* Need to retry all possible stateids in
* case the recovery error wasn't stateid
* related or the stateids have become
* stale (server reboot).
*/
(void) xdr_free(xdr_COMPOUND4res_clnt,
goto recov_retry;
}
if (!e.error) {
(void) xdr_free(xdr_COMPOUND4res_clnt,
}
return (e.error);
}
&recov_state, needrecov);
return (e.error);
}
if (base)
if (mi->mi_io_kstats) {
}
return (e.error);
}
/* ARGSUSED */
static int
{
return (EIO);
switch (cmd) {
case _FIODIRECTIO:
default:
return (ENOTTY);
}
}
/* ARGSUSED */
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 (nfs4_has_pages(vp)) {
error =
}
}
} else {
}
}
}
}
int
{
/*
* If these are the only two bits cleared
* on the server then return 0 (OK) else
* return 1 (BAD).
*/
if (on_client == from_server)
return (0);
else
return (1);
}
/*ARGSUSED4*/
static int
{
int error;
return (EINVAL);
return (EIO);
/*
* Don't call secpolicy_vnode_setattr, the client cannot
* use its cached attributes to make security decisions
* Always just let the server to the checking.
* If we provide the ability to remove basic priviledges
* to setattr (e.g. basic without chmod) then we will
* need to add a check here before calling the server.
*/
return (error);
}
/*
* To replace the "guarded" version 3 setattr, we use two types of compound
* setattr requests:
* 1. The "normal" setattr, used when the size of the file isn't being
* changed - { Putfh <fh>; Setattr; Getattr }/
* 2. If the size is changed, precede Setattr with: Getattr; Verify
* with only ctime as the argument. If the server ctime differs from
* what is cached on the client, the verify will fail, but we would
* already have the ctime from the preceding getattr, so just set it
* and retry. Thus the compound here is - { Putfh <fh>; Getattr; Verify;
* Setattr; Getattr }.
*
* The vsecattr_t * input parameter will be non-NULL if ACLs are being set in
* this setattr and NULL if they are not.
*/
static int
{
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 R4DIRTY, 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 (nfs4_has_pages(vp) &&
}
}
/*
* Verification setattr compound for non-deleg AT_SIZE:
* { Putfh; Getattr; Verify; Setattr; Getattr }
* Set ctime local here (outside the do_again label)
* so that subsequent retries (after failed VERIFY)
* will use ctime from GETATTR results (from failed
* verify compound) as VERIFY arg.
* If file has delegation, then VERIFY(time_metadata)
* is of little added value, so don't bother.
*/
numops = 5;
}
}
recov_state.rs_flags = 0;
if (e.error)
return (e.error);
/* putfh target fh */
if (numops == 5) {
/*
* We only care about the ctime, but need to get mtime
* and size for proper cache update.
*/
/* getattr */
/* verify - set later in loop */
verify_argop = 2;
}
/* setattr */
if (e.error) {
/* req time field(s) overflow - return immediately */
return (e.error);
}
/* getattr */
/*
* If we are setting the ACL (indicated only by vsap != NULL), request
* the ACL in this getattr. The ACL returned from this getattr will be
* used in updating the ACL cache.
*/
/*
* setattr iterates if the object size is set and the cached ctime
* does not match the file ctime. In that case, verify the ctime first.
*/
do {
if (verify_argop != -1) {
/*
* Verify that the ctime match before doing setattr.
*/
if (e.error) {
/* req time field(s) overflow - return */
break;
}
}
doqueue = 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) nfs4_access_purge_rp(rp);
}
}
/*
* If res.array_len == numops, then everything succeeded,
* except for possibly the final getattr. If only the
* last getattr failed, give up, and don't try recovery.
*/
if (! e.error)
break;
}
/*
* if either rpc call failed or completely succeeded - done
*/
if (e.error) {
if (!needrecov) {
break;
}
}
/*
* Do proper retry for OLD_STATEID outside of the normal
* recovery framework.
*/
if (verify_argop != -1) {
verify_argop = -1;
}
goto recov_retry;
}
if (needrecov) {
abort = nfs4_start_recovery(&e,
/*
* Do not retry if we failed with OLD_STATEID using
* a special stateid. This is done to avoid looping
* with a broken server.
*/
if (!e.error) {
(void) xdr_free(xdr_COMPOUND4res_clnt,
}
if (verify_argop != -1) {
verify_argop = -1;
}
/*
* Need to retry all possible stateids in
* case the recovery error wasn't stateid
* related or the stateids have become
* stale (server reboot).
*/
goto recov_retry;
}
return (e.error);
}
/*
* Need to call nfs4_end_op before nfs4getattr to
* avoid potential nfs4_start_op deadlock. See RFE
* 4777612. Calls to nfs4_invalidate_pages() and
* nfs4_purge_stale_fh() might also generate over the
* wire calls which my cause nfs4_start_op() deadlock.
*/
/*
* Check to update lease.
*/
break;
}
/*
* Check if verify failed to see if try again
*/
/*
* can't continue...
*/
} else {
/*
* When the verify request fails, the client ctime is
* not in sync with the server. This is the same as
* the version 3 "not synchronized" error, and we
* handle it in a similar manner (XXX do we need to???).
* Use the ctime returned in the first getattr for
* the input to the next verify.
* If we couldn't get the attributes, then we give up
* because we can't complete the operation as required.
*/
}
if (e.error) {
} else {
/*
* retry with a new verify value
*/
}
if (!e.error) {
if (verify_argop != -1) {
verify_argop = -1;
}
goto do_again;
}
} while (!e.error);
if (e.error) {
/*
* If we are here, rfs4call has an irrecoverable error - return
*/
if (verify_argop != -1) {
verify_argop = -1;
}
if (resp)
return (e.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.
*/
}
/* either no error or one of the postop getattr failed */
/*
* XXX Perform a simplified version of wcc checking. Instead of
* have another getattr to get pre-op, just purge cache if
* any of the ops prior to and including the getattr failed.
* If the getattr succeeded then update the attrcache accordingly.
*/
/*
* Last getattr
*/
}
/*
* In certain cases, nfs4_update_attrcache() will purge the attrcache,
* rather than filling it. See the function itself for details.
*/
} else {
/*
* The ACL was supposed to be set and to be
* returned in the last getattr of this
* compound, but for some reason the getattr
* result doesn't contain the ACL. In this
* case, purge the ACL cache.
*/
}
}
}
}
/*
* Set the size, rather than relying on getting it updated
* via a GETATTR. With delegations the client tries to
* suppress GETATTR calls.
*/
}
/*
* Can free up request args and res
*/
if (verify_argop != -1) {
verify_argop = -1;
}
/*
* 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.
*/
do_setattr = 0;
if (!terror &&
/*
* We asked the mode to be changed and what
* we just got from the server in getattr is
* not what we wanted it to be, so set it now.
*/
do_setattr = 1;
} else {
/*
* We did not ask the mode to be changed,
* Check to see that the server just cleared
* I_SUID and I_GUID from it. If not then
*/
do_setattr = 1;
}
}
if (do_setattr)
}
}
return (e.error);
}
/* ARGSUSED */
static int
{
int doqueue;
int num_ops;
int rpc_error;
hrtime_t t;
return (EIO);
acc = 0;
acc |= ACCESS4_READ;
return (EROFS);
acc |= ACCESS4_DELETE;
}
acc |= ACCESS4_LOOKUP;
else
acc |= ACCESS4_EXECUTE;
}
if (e.error)
return (e.error);
}
else
recov_state.rs_flags = 0;
/*
* 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 == NFS4_ACCESS_ALLOWED) {
return (0);
}
if (cacc == NFS4_ACCESS_DENIED) {
/*
* If the cred can be adjusted, try again
* with the new cred.
*/
goto tryagain;
}
return (EACCES);
}
/*
* Don't take with r_statev4_lock here. r_deleg_type could
* change as soon as lock is released. Since it is an int,
* there is no atomicity issue.
*/
&recov_state, NULL)) {
return (e.error);
}
/* putfh target fh */
/* access */
/* getattr */
if (do_getattr) {
}
doqueue = 1;
t = gethrtime();
if (needrecov) {
"nfs4_access: initiating recovery\n"));
if (!e.error)
(void) xdr_free(xdr_COMPOUND4res_clnt,
goto recov_retry;
}
}
if (e.error)
goto out;
/*
* This might generate over the wire calls throught
* nfs4_invalidate_pages. Hence we need to call nfs4_end_op()
* here to avoid a deadlock.
*/
goto out;
}
if (do_getattr) {
resop++; /* getattr res */
}
if (!e.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
*/
/* XXX check the supported bits too? */
/*
* The following code implements the semantic
* that a setuid root program has *at least* the
* permissions of the user that is running the
* program. See rfs3call() for more portions
* of the implementation of this functionality.
*/
/* XXX-LP */
(void) xdr_free(xdr_COMPOUND4res_clnt,
goto tryagain;
}
}
}
out:
if (!rpc_error)
return (e.error);
}
/* ARGSUSED */
static int
{
int doqueue;
char *linkdata;
hrtime_t t;
return (EIO);
/*
* Can't readlink anything other than a symbolic link.
*/
return (EINVAL);
if (e.error)
return (e.error);
return (e.error);
}
}
recov_state.rs_flags = 0;
if (e.error) {
return (e.error);
}
/* 0. putfh symlink fh */
/* 1. readlink */
/* 2. getattr */
doqueue = 1;
t = gethrtime();
if (needrecov) {
"nfs4_readlink: initiating recovery\n"));
if (!e.error)
(void) xdr_free(xdr_COMPOUND4res_clnt,
goto recov_retry;
}
}
if (e.error)
return (e.error);
/*
* There is an path in the code below which calls
* nfs4_purge_stale_fh(), which may generate otw calls through
* nfs4_invalidate_pages. Hence we need to call nfs4_end_op()
* here to avoid nfs4_start_op() deadlock.
*/
/*
* either Putfh or Link failed
*/
return (e.error);
}
/*
* treat symlink names as data
*/
/* len includes null byte, which we won't uiomove */
} else {
}
} else {
}
}
resop++; /* getattr res */
}
/*
* 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 */
void
{
return;
}
/*
* 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;
}
/*
* Some of the cleanup steps might require over-the-wire
* operations. Since VOP_INACTIVE can get called as a result of
* other over-the-wire operations (e.g., an attribute cache update
* can lead to a DNLC purge), doing those steps now would lead to a
* nested call to the recovery framework, which can deadlock. So
* do any over-the-wire cleanups asynchronously, in a separate
* thread.
*/
return;
}
return;
}
return;
}
}
/*
* nfs4_inactive_otw - nfs4_inactive, plus over-the-wire calls to free up
* various bits of state. The caller must not refer to vp after this call.
*/
void
{
char *unlname;
int doqueue;
#ifdef DEBUG
char *name;
#endif
#ifdef DEBUG
"release vnode %s", name));
#endif
if (e.error) {
/* Check to see if recovery failed */
recov_failed = TRUE;
if (!recov_failed) {
recov_failed = TRUE;
}
if (recov_failed) {
(CE_NOTE, "nfs4_inactive_otw: "
"close failed (recovery failure)"));
}
}
}
redo:
return;
}
/*
* 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.
*/
return;
}
/*
* 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 (nfs4_has_pages(vp) &&
if (e.error) {
}
}
recov_state.rs_flags = 0;
/*
* Do the remove operation on the renamed file
*/
/*
* Remove ops: putfh dir; remove
*/
if (e.error) {
/*
* Try again; this time around r_unldvp will be NULL, so we'll
* just call rp4_addfree() and return.
*/
goto redo;
}
/* putfh directory */
/* remove */
doqueue = 1;
#if 0 /* notyet */
/*
* Can't do this yet. We may be being called from
* dnlc_purge_XXX while that routine is holding a
* mutex lock to the nc_rele list. The calls to
* nfs3_cache_wcc_data may result in calls to
* dnlc_purge_XXX. This will result in a deadlock.
*/
if (e.error) {
/*
* This code is inactive right now
* but if made active there should
* be a nfs4_end_op() call before
* nfs4_purge_stale_fh to avoid start_op()
* deadlock. See BugId: 4948726
*/
} else {
/*
* Update directory cache attribute,
* readdir and dnlc caches.
*/
}
#else
#endif
if (!e.error)
(void) xdr_free(xdr_COMPOUND4res_clnt,
goto recov_retry_remove;
}
}
/*
* Release stuff held for the remove
*/
goto redo;
}
/*
* Remote file system operations having to do with directory manipulation.
*/
/* ARGSUSED3 */
int
{
int error;
return (EPERM);
/*
* if LOOKUP_XATTR, must replace dvp (object) with
* object's attrdir before continuing with lookup
*/
if (flags & LOOKUP_XATTR) {
if (error)
return (error);
/*
* If lookup is for "", just return dvp now. The attrdir
* has already been activated (from nfs4lookup_xattr), and
* the caller will RELE the original dvp -- not
* the attrdir. So, set vpp and return.
* Currently, when the LOOKUP_XATTR flag is
* passed to VOP_LOOKUP, the name is always empty, and
* pairs.
*
* If a non-empty name was provided, then it is the
* attribute name, and it will be looked up below.
*/
if (*nm == '\0') {
return (0);
}
/*
* The vfs layer never sends a name when asking for the
* attrdir, so we should never get here (unless of course
* name is passed at some time in future -- at which time
* we'll blow up here).
*/
ASSERT(0);
}
return (EINTR);
/*
* If vnode is a device, create special vnode.
*/
}
return (error);
}
/* ARGSUSED */
static int
{
int error;
return (EINVAL);
return (EINTR);
/*
* If the server doesn't support xattrs just return EINVAL
*/
return (EINVAL);
}
/*
* If there is a cached xattr directory entry,
* use it as long as the attributes are valid. If the
* attributes are not valid, take the simple approach and
* free the cached value and re-fetch a new value.
*
* We don't negative entry cache for now, if we did we
* would need to check if the file has changed on every
* lookup. But xattrs don't exist very often and failing
* an openattr is not much more expensive than and NVERIFY or GETATTR
* so do an openattr over the wire for now.
*/
if (ATTRCACHE4_VALID(dvp)) {
return (0);
}
}
return (error);
}
static 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 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 is no entry
* lookup over the wire.
*/
if (!skipdnlc)
/*
* We need to go over the wire to lookup the name.
*/
}
/*
* We hit on the dnlc
*/
if (*vpp != DNLC_NO_VNODE ||
/*
* But our attrs may not be valid.
*/
if (ATTRCACHE4_VALID(dvp)) {
if (error) {
return (error);
}
/*
* If after the purge completes, check to make sure
* our attrs are still valid.
*/
if (ATTRCACHE4_VALID(dvp)) {
/*
* If we waited for a purge we may have
* lost our vnode so look it up again.
*/
return (nfs4lookupnew_otw(dvp,
/*
* The access cache should almost always hit
*/
if (error) {
return (error);
}
if (*vpp == DNLC_NO_VNODE) {
return (ENOENT);
}
return (0);
}
}
}
/*
* We may have gotten here we have one of the following cases:
* 1) vpp != DNLC_NO_VNODE, our attrs have timed out so we
* need to validate them.
* 2) vpp == DNLC_NO_VNODE, a negative entry that we always
* must validate.
*
* Go to the server and check if the directory has changed, if
* it hasn't we are done and can use the dnlc entry.
*/
}
/*
* Go to the server and check if the directory has changed, if
* it hasn't we are done and can use the dnlc entry. If it
* has changed we get a new copy of its attributes and check
* the access for VEXEC, then relookup the filename and
* get its filehandle and attributes.
*
* PUTFH dfh NVERIFY GETATTR ACCESS LOOKUP GETFH GETATTR
* if the NVERIFY failed we must
* purge the caches
* cache new attributes (will set r_time_attr_inval)
* cache new access
* recheck VEXEC access
* add name to dnlc, possibly negative
* if LOOKUP succeeded
* cache new attributes
* else
* set a new r_time_attr_inval for dvp
* check to make sure we have access
*
* The vpp returned is the vnode passed in if the directory is valid,
* a new vnode if successful lookup, or NULL on error.
*/
static int
{
int doqueue;
hrtime_t t;
int isdotdot;
isdotdot = 1;
} else {
/*
* If dvp were a stub, it should have triggered and caused
* a mount for us to get this far.
*/
isdotdot = 0;
}
recov_state.rs_flags = 0;
/* Save the original mount point security information */
&recov_state, NULL);
if (e.error) {
return (e.error);
}
/* PUTFH dfh NVERIFY GETATTR ACCESS LOOKUP GETFH GETATTR */
/* 0. putfh file */
/* 1. nverify the change info */
/* 2. getattr directory */
/* 3. access directory */
/* 4. lookup name */
if (isdotdot) {
} else {
}
/* 5. resulting file handle */
/* 6. resulting file attributes */
doqueue = 1;
t = gethrtime();
&recov_state, FALSE);
return (e.error);
}
/*
* For WRONGSEC of a non-dotdot case, send secinfo directly
* from this thread, do not go thru the recovery thread since
* we need the nm information.
*
* Not doing dotdot case because there is no specification
* for (PUTFH, SECINFO "..") yet.
*/
&recov_state, FALSE);
else
&recov_state, TRUE);
if (!e.error)
goto recov_retry;
return (e.error);
}
&recov_state, TRUE);
goto recov_retry;
}
}
/*
* If e.error isn't set, then reply has no ops (or we couldn't
* be here). The only legal way to reply without an op array
* is via NFS4ERR_MINOR_VERS_MISMATCH. An ops array should
* be in the reply for all other status values.
*
* For valid replies without an ops array, return ENOTSUP
* (geterrno4 xlation of VERS_MISMATCH). For illegal replies,
* return EIO -- don't trust status.
*/
if (e.error == 0)
return (e.error);
}
/*
* The NVERIFY "failed" so the directory has changed
* First make sure PUTFH succeeded and NVERIFY "failed"
* cleanly.
*/
goto exit;
}
/*
* We know the NVERIFY "failed" so we must:
* purge the caches (access and indirectly dnlc if needed)
*/
goto exit;
}
/*
* Install new cached attributes for the directory
*/
goto exit;
}
/*
* Now we know the directory is valid,
* cache new directory access
*/
/*
* recheck VEXEC access
*/
if (cacc != NFS4_ACCESS_ALLOWED) {
/*
* Directory permissions might have been revoked
*/
if (cacc == NFS4_ACCESS_DENIED) {
goto exit;
}
/*
* Somehow we must not have asked for enough
* so try a singleton ACCESS, should never happen.
*/
if (e.error) {
goto exit;
}
}
/*
* The lookup failed, probably no entry
*/
} else {
/*
* Might be some other error, so remove
* the dnlc entry to make sure we start all
* over again, next time.
*/
}
goto exit;
}
/*
* The file exists but we can't get its fh for
* some unknown reason. Remove it from the dnlc
* and error out to be safe.
*/
goto exit;
}
if (fhp->nfs_fh4_len == 0) {
/*
* The file exists but a bogus fh
* some unknown reason. Remove it from the dnlc
* and error out to be safe.
*/
goto exit;
}
/*
* Make the new rnode
*/
if (isdotdot) {
if (e.error) {
goto exit;
}
/*
* XXX if nfs4_make_dotdot uses an existing rnode
* XXX it doesn't update the attributes.
* XXX for now just save them again to save an OTW
*/
} else {
/*
* If v_type == VNON, then garp was NULL because
* the last op in the compound failed and makenfs4node
* could not find the vnode for sfhp. It created
* a new vnode, so we have nothing to purge here.
*/
/*
* N.B. We've already called nfs4_end_fop above.
*/
if (e.error) {
goto exit;
}
}
}
if (!nrp->created_v4) {
} else
} else {
e.error = 0;
/*
* Because the NVERIFY "succeeded" we know that the
* directory attributes are still valid
* so update r_time_attr_inval
*/
}
/*
* Even though we have a valid directory attr cache
* and dnlc entry, we may not have access.
* This should almost always hit the cache.
*/
if (e.error) {
}
if (*vpp == DNLC_NO_VNODE) {
}
}
exit:
return (e.error);
}
/*
* We need to go over the wire to lookup the name, but
* while we are there verify the directory has not
* changed but if it has, get new attributes and check access
*
* PUTFH dfh SAVEFH LOOKUP nm GETFH GETATTR RESTOREFH
* NVERIFY GETATTR ACCESS
*
* With the results:
* if the NVERIFY failed we must purge the caches, add new attributes,
* and cache new access.
* set a new r_time_attr_inval
* add name to dnlc, possibly negative
* if LOOKUP succeeded
* cache new attributes
*/
static int
{
int doqueue;
hrtime_t t;
int isdotdot;
isdotdot = 1;
} else {
/*
* If dvp were a stub, it should have triggered and caused
* a mount for us to get this far.
*/
isdotdot = 0;
}
recov_state.rs_flags = 0;
/* Save the original mount point security information */
&recov_state, NULL);
if (e.error) {
return (e.error);
}
/* PUTFH SAVEFH LOOKUP GETFH GETATTR RESTOREFH NVERIFY GETATTR ACCESS */
/* 0. putfh file */
/* 1. savefh for the nverify */
/* 2. lookup name */
if (isdotdot) {
} else {
}
/* 3. resulting file handle */
/* 4. resulting file attributes */
/* 5. restorefh back the directory for the nverify */
/* 6. nverify the change info */
/* 7. getattr directory */
/* 8. access directory */
doqueue = 1;
t = gethrtime();
&recov_state, FALSE);
return (e.error);
}
/*
* For WRONGSEC of a non-dotdot case, send secinfo directly
* from this thread, do not go thru the recovery thread since
* we need the nm information.
*
* Not doing dotdot case because there is no specification
* for (PUTFH, SECINFO "..") yet.
*/
&recov_state, FALSE);
else
&recov_state, TRUE);
if (!e.error)
goto recov_retry;
return (e.error);
}
&recov_state, TRUE);
goto recov_retry;
}
}
/*
* If e.error isn't set, then reply has no ops (or we couldn't
* be here). The only legal way to reply without an op array
* is via NFS4ERR_MINOR_VERS_MISMATCH. An ops array should
* be in the reply for all other status values.
*
* For valid replies without an ops array, return ENOTSUP
* (geterrno4 xlation of VERS_MISMATCH). For illegal replies,
* return EIO -- don't trust status.
*/
if (e.error == 0)
return (e.error);
}
/*
* The PUTFH and SAVEFH may have failed.
*/
goto exit;
}
/*
* Check if the file exists, if it does delay entering
* into the dnlc until after we update the directory
* attributes so we don't cause it to get purged immediately.
*/
/*
* The lookup failed, probably no entry
*/
goto exit;
}
/*
* The file exists but we can't get its fh for
* some unknown reason. Error out to be safe.
*/
goto exit;
}
if (fhp->nfs_fh4_len == 0) {
/*
* The file exists but a bogus fh
* some unknown reason. Error out to be safe.
*/
goto exit;
}
goto exit;
}
/*
* The RESTOREFH may have failed
*/
goto exit;
}
/*
* First make sure the NVERIFY failed as we expected,
* if it didn't then be conservative and error out
* as we can't trust the directory.
*/
goto exit;
}
/*
* We know the NVERIFY "failed" so the directory has changed,
* so we must:
* purge the caches (access and indirectly dnlc if needed)
*/
goto exit;
}
goto exit;
}
/*
* Now we know the directory is valid,
* cache new directory access
*/
/*
* recheck VEXEC access
*/
if (cacc != NFS4_ACCESS_ALLOWED) {
/*
* Directory permissions might have been revoked
*/
if (cacc == NFS4_ACCESS_DENIED) {
goto exit;
}
/*
* Somehow we must not have asked for enough
* so try a singleton ACCESS should never happen
*/
if (e.error) {
goto exit;
}
}
} else {
e.error = 0;
/*
* Because the NVERIFY "succeeded" we know that the
* directory attributes are still valid
* so update r_time_attr_inval
*/
}
/*
* Even though we have a valid directory attr cache,
* we may not have access.
* This should almost always hit the cache.
*/
if (e.error) {
goto exit;
}
}
/*
* Now we have successfully completed the lookup, if the
* directory has changed we now have the valid attributes.
* We also know we have directory access.
* Create the new rnode and insert it in the dnlc.
*/
if (isdotdot) {
if (e.error) {
goto exit;
}
/*
* XXX if nfs4_make_dotdot uses an existing rnode
* XXX it doesn't update the attributes.
* XXX for now just save them again to save an OTW
*/
} else {
}
if (!nrp->created_v4) {
} else
exit:
return (e.error);
}
#ifdef DEBUG
void
{
char *s;
for (i = 0; i < argcnt; i++) {
case OP_CPUTFH:
case OP_PUTFH:
break;
case OP_PUTROOTFH:
break;
case OP_CLOOKUP:
break;
case OP_LOOKUP:
break;
case OP_LOOKUPP:
break;
case OP_GETFH:
break;
case OP_GETATTR:
break;
case OP_OPENATTR:
break;
default:
break;
}
}
}
#endif
/*
* nfs4lookup_setup - constructs a multi-lookup compound request.
*
* may be created:
*
* Note: Getfh is not be needed because filehandle attr is mandatory, but it
* is faster, for now.
*
* l4_getattrs indicates the type of compound requested.
*
* LKP4_NO_ATTRIBUTE - no attributes (used by secinfo):
*
* compound { Put*fh; Lookup {nm1}; Lookup {nm2}; ... Lookup {nmn} }
*
* total number of ops is n + 1.
*
* LKP4_LAST_NAMED_ATTR - multi-component path for a named
* before the last component, and only get attributes
* for the last component. Note that the second-to-last
* pathname component is XATTR_RPATH, which does NOT go
* over-the-wire as a lookup.
*
* compound { Put*fh; Lookup {nm1}; Lookup {nm2}; ... Lookup {nmn-2};
* Openattr; Getfh; Getattr; Lookup {nmn}; Getfh; Getattr }
*
* and total number of ops is n + 5.
*
* LKP4_LAST_ATTRDIR - multi-component path for the hidden named
* attribute directory: create lookups plus an OPENATTR
* replacing the last lookup. Note that the last pathname
* component is XATTR_RPATH, which does NOT go over-the-wire
* as a lookup.
*
* compound { Put*fh; Lookup {nm1}; Lookup {nm2}; ... Getfh; Getattr;
* Openattr; Getfh; Getattr }
*
* and total number of ops is n + 5.
*
* LKP4_ALL_ATTRIBUTES - create lookups and get attributes for intermediate
* nodes too.
*
* compound { Put*fh; Lookup {nm1}; Getfh; Getattr;
* Lookup {nm2}; ... Lookup {nmn}; Getfh; Getattr }
*
* and total number of ops is 3*n + 1.
*
* All cases: returns the index in the arg array of the final LOOKUP op, or
* -1 if no LOOKUPs were used.
*/
int
{
int n = 1; /* number of components */
char c = '\0', *s, *p;
int argoplist_size;
/* set lookuparg response result to 0 */
/* skip leading "/" or "." e.g. ".//./" if there is */
for (; ; nm++) {
break;
/* ".." is counted as 1 component */
break;
}
/*
* Find n = number of components - nm must be null terminated
* Skip "." components.
*/
if (*nm != '\0')
if ((*s == '/') && (*(s + 1) != '/') &&
(*(s + 1) != '\0') &&
!(*(s + 1) == '.' && (*(s + 2) == '/' ||
*(s + 2) == '\0')))
n++;
}
else
n = 0;
/*
* nga is number of components that need Getfh+Getattr
*/
switch (l4_getattrs) {
case LKP4_NO_ATTRIBUTES:
nga = 0;
break;
case LKP4_ALL_ATTRIBUTES:
nga = n;
/*
* Always have at least 1 getfh, getattr pair
*/
if (nga == 0)
nga++;
break;
case LKP4_LAST_ATTRDIR:
case LKP4_LAST_NAMED_ATTR:
nga = n+1;
break;
}
/*
* If change to use the filehandle attr instead of getfh
* the following line can be deleted.
*/
nga *= 2;
/*
* calculate number of ops in request as
* header + trailer + lookups + getattrs
*/
/*
* each component. Skip "." components.
*/
for (s = nm; *s != '\0'; s = p) {
/*
* Set up a pathname struct for each component if needed
*/
while (*s == '/')
s++;
if (*s == '\0')
break;
for (p = s; (*p != '/') && (*p != '\0'); p++)
;
c = *p;
*p = '\0';
if (s[0] == '.' && s[1] == '\0') {
*p = c;
continue;
}
if (l4_getattrs == LKP4_LAST_ATTRDIR &&
strcmp(s, XATTR_RPATH) == 0) {
/* getfh XXX may not be needed in future */
argop++;
argcnt++;
/* getattr */
lookupargp->mi;
argop++;
argcnt++;
/* openattr */
} else if (l4_getattrs == LKP4_LAST_NAMED_ATTR &&
strcmp(s, XATTR_RPATH) == 0) {
/* openattr */
argop++;
argcnt++;
/* getfh XXX may not be needed in future */
argop++;
argcnt++;
/* getattr */
lookupargp->mi;
argop++;
argcnt++;
*p = c;
continue;
} else if (s[0] == '.' && s[1] == '.' && s[2] == '\0') {
/* lookupp */
} else {
/* lookup */
(void) str_to_utf8(s,
}
lookup_idx = argcnt;
argop++;
argcnt++;
*p = c;
if (l4_getattrs == LKP4_ALL_ATTRIBUTES) {
/* getfh XXX may not be needed in future */
argop++;
argcnt++;
/* getattr */
lookupargp->mi;
argop++;
argcnt++;
}
}
if ((l4_getattrs != LKP4_NO_ATTRIBUTES) &&
if (needgetfh) {
/* stick in a post-lookup getfh */
argcnt++;
argop++;
}
/* post-lookup getattr */
argcnt++;
}
#ifdef DEBUG
#endif
return (lookup_idx);
}
static int
{
hrtime_t t;
nfs4_error_t e;
int needrecov = 0;
recov_state.rs_flags = 0;
/* COMPOUND: putfh, openattr, getfh, getattr */
if (e.error)
return (e.error);
/* putfh */
/* openattr */
/* getfh */
/* getattr */
rnode4info(drp)));
t = gethrtime();
if (needrecov) {
"nfs4openattr: initiating recovery\n"));
abort = nfs4_start_recovery(&e,
if (!e.error) {
}
goto recov_retry;
return (e.error);
}
if (e.error) {
return (e.error);
}
/*
* If OTW errro is NOTSUPP, then it should be
* translated to EINVAL. All Solaris file system
* implementations return EINVAL to the syscall layer
* when the attrdir cannot be created due to an
* implementation restriction or noxattr mount option.
*/
if (drp->r_xattr_dir)
} else {
}
if (e.error) {
return (e.error);
}
}
return (ENOENT);
}
if (e.error)
if (drp->r_xattr_dir)
/*
* Invalidate pathconf4 cache because r_xattr_dir is no longer
* NULL. xattrs could be created at any time, and we have no
* it happens.
*/
return (0);
}
/* ARGSUSED */
static int
{
int error;
int truncating = 0;
return (EPERM);
return (EINVAL);
}
/* . and .. have special meaning in the protocol, reject them. */
return (EISDIR);
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 "", then dvp is the root vnode of
* a remote file mounted over a local directory.
* All that needs to be done is access
* checking and truncation. Note that we avoid doing
* open w/ create because the parent directory might
* be in pseudo-fs and the open would fail.
*/
if (*nm == '\0') {
error = 0;
must_trunc = TRUE;
} else {
/*
* 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.
*/
}
if (exclusive)
else
/*
* error would be set if the file does not exist on the
* server, so lets go create it.
*/
if (error) {
goto create_otw;
}
/*
* File does exist on the server
*/
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 is set then we need to return */
if (error) {
return (error);
}
if (must_trunc) {
NULL);
} else {
/*
* we know we have a regular file that already
* exists and we may end up truncating the file
* as a result of the open_otw, so flush out
* any dirty pages for this file first.
*/
if (nfs4_has_pages(vp) &&
&rp->r_statelock);
&rp->r_statelock);
}
}
truncating = 1;
goto create_otw;
}
}
}
}
if (error) {
} else {
}
if (must_trunc) {
/*
* existing file got truncated, notify.
*/
}
}
return (error);
/*
* If not a regular file let nfs4mknod() handle it.
*/
return (error);
}
/*
* It _is_ a regular file.
*/
return (EACCES);
}
/*
* If this happens to be a mknod of a regular file, then flags will
* have neither FREAD or FWRITE. However, we must set at least one
* for the call to nfs4open_otw. If it's open(O_CREAT) driving
* nfs4_create, then either FREAD, FWRITE, or FRDWR has already been
* set (based on openmode specified by app).
*/
/* if create was successful, throw away the file's pages */
cr);
/* release the lookup hold */
}
/*
* validate that we opened a regular file. This handles a misbehaving
* server that returns an incorrect FH.
*/
}
/*
* 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;
}
/*
* existing file got truncated, notify.
*/
}
return (error);
}
/*
* Create compound (for mkdir, mknod, symlink):
* { Putfh <dfh>; Create; Getfh; Getattr }
* It's okay if setattr failed to set gid - this is not considered
* an error, but purge attrs in that case.
*/
static int
{
int doqueue;
hrtime_t t;
/*
* Make sure we properly deal with setting the right gid
* on a new directory to reflect the parent's setgid bit
*/
setgid_flag = 0;
/*
* If the parent's directory has the setgid bit set
* _and_ the client was able to get a valid mapping
* for the parent dir's owner_group, we want to
* append NVERIFY(owner_group == dva.va_gid) and
* SETTATTR to the CREATE compound.
*/
setgid_flag = 1;
}
}
}
}
/*
* Create ops:
* 0:putfh(dir) 1:savefh(dir) 2:create 3:getfh(new) 4:getattr(new)
* 5:restorefh(dir) 6:getattr(dir)
*
* if (setgid)
* 0:putfh(dir) 1:create 2:getfh(new) 3:getattr(new)
* 4:savefh(new) 5:putfh(dir) 6:getattr(dir) 7:restorefh(new)
* 8:nverify 9:setattr
*/
if (setgid_flag) {
numops = 10;
idx_create = 1;
idx_fattr = 3;
} else {
numops = 7;
idx_create = 2;
idx_fattr = 4;
}
return (EINTR);
}
recov_state.rs_flags = 0;
else
return (e.error);
}
need_end_op = TRUE;
/* 0: putfh directory */
/* 1/2: Create object */
/*
* symlink, treat name as data
*/
(char *)data;
}
}
return (e.error);
}
/* 2/3: getfh fh of created object */
/* 3/4: getattr of new object */
if (setgid_flag) {
/*
* nverify
*
* XXX - Revisit the last argument to nfs4_end_op()
* once 5020486 is fixed.
*/
supp_attrs)) {
return (e.error);
}
/*
* setattr
*
* We _know_ we're not messing with AT_SIZE or AT_XTIME,
* so no need for stateid or flags. Also we specify NULL
* rp since we're only interested in setting owner_group
* attributes.
*/
&e.error, 0);
if (e.error) {
return (e.error);
}
} else {
}
doqueue = 1;
t = gethrtime();
if (e.error) {
if (!needrecov)
goto out;
}
if (needrecov) {
need_end_op = FALSE;
if (setgid_flag) {
}
goto recov_retry;
}
}
/*
* This check is left over from when create was implemented
* using a setattr op (instead of createattrs). If the
*
* It might be better to get rid of the GETFH also, and just
* Then if any of the operations failed, we could return the
* error now, and remove much of the error code below.
*/
/*
* Either Putfh, Create or Getfh failed.
*/
/*
* nfs4_purge_stale_fh() may generate otw calls through
* nfs4_invalidate_pages. Hence the need to call
* nfs4_end_op() here to avoid nfs4_start_op() deadlock.
*/
need_end_op = FALSE;
goto out;
}
}
if (e.error) {
/*
* Need to call nfs4_end_op before nfs4getattr to avoid
* potential nfs4_start_op deadlock. See RFE 4777612.
*/
need_end_op = FALSE;
if (e.error) {
goto out;
}
}
e.error = 0;
} else {
}
/*
* If compound succeeded, then update dir attrs
*/
dinfo.di_time_call = t;
} else
/* Update directory cache attribute, readdir and dnlc caches */
out:
if (setgid_flag) {
}
if (resp)
if (need_end_op)
return (e.error);
}
/* ARGSUSED */
static int
{
int error;
case VCHR:
case VBLK:
break;
case VFIFO:
break;
case VSOCK:
break;
default:
return (EINVAL);
}
if (error) {
return (error);
}
/*
* This might not be needed any more; special case to deal
* to set group correctly, not sure what hope setattr has.
*/
}
/*
* If vnode is a device create special vnode
*/
} else {
}
return (error);
}
/*
* Remove requires that the current fh be the target directory.
* After the operation, the current fh is unchanged.
* The compound op structure is:
* PUTFH(targetdir), REMOVE
*
* 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
{
char *tmpname;
int doqueue;
int needrecov = 0;
int isopen;
return (EPERM);
return (EINTR);
if (e.error) {
return (e.error);
}
return (EISDIR);
}
/*
* First just remove the entry from the name cache, as it
* is most likely the only entry for this vp.
*/
/*
* For regular file types, check to see if the file is open by looking
* at the open streams.
* For all other types, check the reference count on the vnode. Since
* they are not opened OTW they never have an open stream.
*
* If the file is open, rename it to .nfsXXXX.
*/
/*
* 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.
*/
} else {
}
if (isopen &&
if (e.error)
else {
} else {
}
}
return (e.error);
}
/*
*/
/*
* We need to flush any dirty pages which happen to
* be hanging around before removing the file.
* This shouldn't happen very often since in NFSv4
* we should be close to open consistent.
*/
if (nfs4_has_pages(vp) &&
}
}
recov_state.rs_flags = 0;
/*
* Remove ops: putfh dir; remove
*/
if (e.error) {
return (e.error);
}
/* putfh directory */
/* remove */
/* getattr dir */
doqueue = 1;
if (e.error)
if (needrecov) {
if (!e.error)
(void) xdr_free(xdr_COMPOUND4res_clnt,
goto recov_retry;
}
}
/*
* Matching nfs4_end_op() for start_op() above.
* There is a path in the code below which calls
* nfs4_purge_stale_fh(), which may generate otw calls through
* nfs4_invalidate_pages. Hence we need to call nfs4_end_op()
* here to avoid nfs4_start_op() deadlock.
*/
if (!e.error) {
} else {
/* Update directory attr, readdir and dnlc caches */
&dinfo);
}
}
if (resp)
if (e.error == 0) {
}
return (e.error);
}
/*
* Link requires that the current fh be the target directory and the
* saved fh be the source fh. After the operation, the current fh is unchanged.
* Thus the compound op structure is:
* PUTFH(file), SAVEFH, PUTFH(targetdir), LINK, RESTOREFH,
* GETATTR(file)
*/
/* ARGSUSED */
static int
{
int doqueue;
hrtime_t t;
return (EPERM);
}
return (EOPNOTSUPP);
}
recov_state.rs_flags = 0;
return (EINTR);
/*
* Link ops: putfh fl; savefh; putfh tdir; link; getattr(dir);
* restorefh; getattr(fl)
*/
if (e.error) {
return (e.error);
}
/* 0. putfh file */
/* 1. save current fh to free up the space for the dir */
/* 2. putfh targetdir */
/* 3. link: current_fh is targetdir, saved_fh is source */
/* 4. Get attributes of dir */
/* 5. If link was successful, restore current vp to file */
/* 6. Get attributes of linked object */
doqueue = 1;
t = gethrtime();
goto out;
}
if (needrecov) {
if (!e.error)
(void) xdr_free(xdr_COMPOUND4res_clnt,
goto recov_retry;
} else {
if (e.error != 0) {
goto out;
}
/* fall through for res.status case */
}
}
/* If link succeeded, then don't return error */
/*
* Either Putfh, Savefh, Putfh dir, or Link failed
*/
if (e.error == EOPNOTSUPP) {
}
/* Remap EISDIR to EPERM for non-root user for SVVS */
/* XXX-LP */
goto out;
}
}
/* either no error or one of the postop getattr failed */
/*
* XXX - if LINK succeeded, but no attrs were returned for link
* file, purge its cache.
*
* XXX Perform a simplified version of wcc checking. Instead of
* have another getattr to get pre-op, just purge cache if
* any of the ops prior to and including the getattr failed.
* If the getattr succeeded then update the attrcache accordingly.
*/
/*
* update cache with link file postattrs.
* Note: at this point resop points to link res.
*/
/*
* Call makenfs4node to create the new shadow vp for tnm.
* We pass NULL attrs because we just cached attrs for
* the src object. All we're trying to accomplish is to
* to create the new shadow vnode.
*/
/* Update target cache attribute, readdir and dnlc caches */
dinfo.di_time_call = t;
if (!e.error) {
/*
* Notify the source file of this link operation.
*/
}
out:
if (resp)
return (e.error);
}
/* ARGSUSED */
static int
{
return (EPERM);
}
/*
* nfs4rename does the real work of renaming in NFS Version 4.
*
* A file handle is considered volatile for renaming purposes if either
* of the volatile bits are turned on. However, the compound may differ
* based on the likelihood of the filehandle to change during rename.
*/
static int
{
int error;
int did_link = 0;
return (EINVAL);
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) {
int isactive;
/*
* 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.
*/
if (vn_ismntpt(nvp)) {
return (EBUSY);
}
/*
* First just remove the entry from the name cache, as it
* is most likely the only entry for this vp.
*/
/*
* 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.
*/
} else {
}
/*
* 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.
*/
/*
* 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. We first
* try to Link it to a temporary filename to
* avoid having the server removing the file
* completely (which could cause data loss to
* the user's POV in the event the Rename fails
* -- see bug 1165874).
*/
/*
* The do_link and did_link booleans are
* introduced in the event we get NFS4ERR_FILE_OPEN
* returned for the Rename. Some servers can
* not Rename over an Open file, so they return
* this error. The client needs to Remove the
* newly created Link and do two Renames, just
* as if the server didn't support LINK.
*/
error = 0;
if (do_link) {
NULL, 0);
}
did_link = 0;
} else {
did_link = 1;
}
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);
}
}
/*
* Is the object being renamed a dir, and if so, is
* it being renamed to a child of itself? The underlying
* fs should ultimately return EINVAL for this case;
* however, buggy beta non-Solaris NFSv4 servers at
* interop testing events have allowed this behavior,
* and it caused our client to panic due to a recursive
* mutex_enter in fn_move.
*
* The tedious locking in fn_move could be changed to
* deal with this case, and the client could avoid the
* panic; however, the client would just confuse itself
* later and misbehave. A better way to handle the broken
* server is to detect this condition and return EINVAL
* without ever sending the the bogus rename to the server.
* We know the rename is invalid -- just fail it now.
*/
if (nvp) {
}
return (EINVAL);
}
/*
* If FH4_VOL_RENAME or FH4_VOLATILE_ANY bits are set, it is
* possible for the filehandle to change due to the rename.
* If neither of these bits is set, but FH4_VOL_MIGRATION is set,
* the fh will not change because of the rename, but we still need
* to update its rnode entry with the new name for
* an eventual fh change due to migration. The FH4_NOEXPIRE_ON_OPEN
* has no effect on these for now, but for future improvements,
* we might want to use it too to simplify handling of files
* that are open with that flag on. (XXX)
*/
if (NFS4_VOLATILE_FH(mi))
&stat);
else
&stat);
do_link = 0;
/*
* Before the 'link_call' code, we did a nfs4_lookup
* that puts a VN_HOLD on nvp. After the nfs4_link
* call we call VN_RELE to match that hold. We need
* to place an additional VN_HOLD here since we will
* be hitting that VN_RELE again.
*/
/* Undo the unlinked file naming stuff we just did */
/* rp->r_unlanme points to tmpname */
}
if (nvp) {
}
goto link_call;
}
if (error) {
if (nvp) {
}
return (error);
}
/*
* 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 we are renaming the unlinked file, update the
* r_unldvp and r_unlname as needed.
*/
}
}
}
/*
* Notify the rename vnevents to source vnode, and to the target
* vnode if it already existed.
*/
if (error == 0) {
/*
* Notify the vnode. Each links is represented by
* a different vnode, in nfsv4.
*/
if (nvp) {
}
/*
* if the source and destination directory are not the
* same notify the destination directory.
*/
}
}
if (nvp) {
}
return (error);
}
/*
* When the parent directory has changed, sv_dfh must be updated
*/
static void
{
}
/*
* nfs4rename_persistent does the otw portion of renaming in NFS Version 4,
* when it is known that the filehandle is persistent through rename.
*
* Rename requires that the current fh be the target directory and the
* saved fh be the source directory. After the operation, the current fh
* is unchanged.
* The compound op structure for persistent fh rename is:
* PUTFH(sourcdir), SAVEFH, PUTFH(targetdir), RENAME
* Rather than bother with the directory postop args, we'll simply
* update that a change occurred in the cache, so no post-op getattrs.
*/
static int
{
recov_state.rs_flags = 0;
/*
* Rename ops: putfh sdir; savefh; putfh tdir; rename; getattr tdir
*
*/
/* No need to Lookup the file, persistent fh */
if (e.error) {
return (e.error);
}
/* 0: putfh source directory */
/* 1: Save source fh to free up current for target */
/* 2: putfh targetdir */
/* 3: current_fh is targetdir, saved_fh is sourcedir */
/* 4: getattr (targetdir) */
/* 5: putfh (sourcedir) */
/* 6: getattr (sourcedir) */
}
doqueue = 1;
if (e.error) {
} else {
}
if (needrecov) {
if (!e.error)
(void) xdr_free(xdr_COMPOUND4res_clnt,
goto recov_retry;
}
}
if (!e.error) {
/*
* as long as OP_RENAME
*/
/*
* 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 geterrno4 maps to ENOTEMPTY.
*/
} else {
/*
* Update target attribute, readdir and dnlc
* caches.
*/
} else
/*
* Update source attribute, readdir and dnlc caches
*
*/
if (dinfop)
}
nnm);
}
}
if (resp)
return (e.error);
}
/*
* nfs4rename_volatile_fh does the otw part of renaming in NFS Version 4, when
* it is possible for the filehandle to change due to the rename.
*
* The compound req in this case includes a post-rename lookup and getattr
* to ensure that we have the correct fh and attributes for the object.
*
* Rename requires that the current fh be the target directory and the
* saved fh be the source directory. After the operation, the current fh
* is unchanged.
*
* We need the new filehandle (hence a LOOKUP and GETFH) so that we can
* update the filehandle for the renamed object. We also get the old
* filehandle for historical reasons; this should be taken out sometime.
* This results in a rather cumbersome compound...
*
* PUTFH(sourcdir), SAVEFH, LOOKUP(src), GETFH(old),
* PUTFH(targetdir), RENAME, LOOKUP(trgt), GETFH(new), GETATTR
*
*/
static int
{
int argoplist_size;
int doqueue;
hrtime_t t;
recov_state.rs_flags = 0;
/*
* There is a window between the RPC and updating the path and
* filehandle stored in the rnode. Lock out the FHEXPIRED recovery
* code, so that it doesn't try to use the old path during that
* window.
*/
lwp->lwp_nostop++;
lwp->lwp_nostop--;
return (EINTR);
}
lwp->lwp_nostop--;
}
/*
* Rename ops:
* PUTFH(sourcdir), SAVEFH, LOOKUP(src), GETFH(old),
* PUTFH(targetdir), RENAME, GETATTR(targetdir)
* LOOKUP(trgt), GETFH(new), GETATTR,
*
* if (odvp != ndvp)
* add putfh(sourcedir), getattr(sourcedir) }
*/
&recov_state, NULL);
if (e.error) {
return (e.error);
}
/* 0: putfh source directory */
/* 1: Save source fh to free up current for target */
/* 2: Lookup pre-rename fh of renamed object */
/* 3: getfh fh of renamed object (before rename) */
/* 4: putfh targetdir */
/* 5: current_fh is targetdir, saved_fh is sourcedir */
/* 6: getattr of target dir (post op attrs) */
/* 7: Lookup post-rename fh of renamed object */
/* 8: getfh fh of renamed object (after rename) */
/* 9: getattr of renamed object */
/*
* attrs for source dir also.
*/
/* 10: putfh (sourcedir) */
/* 11: getattr (sourcedir) */
}
doqueue = 1;
t = gethrtime();
if (e.error) {
if (!needrecov) {
&recov_state, needrecov);
goto out;
}
} else {
}
if (needrecov) {
&recov_state, needrecov);
if (!e.error)
(void) xdr_free(xdr_COMPOUND4res_clnt,
goto recov_retry;
} else {
if (e.error != 0) {
&recov_state, needrecov);
goto out;
}
/* fall through for res.status case */
}
}
/*
* If OP_RENAME (or any prev op) failed, then return an error.
* OP_RENAME is index 5, so if array len <= 6 we return an error.
*/
/*
* Error in an op other than last Getattr
*/
/*
* 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 geterrno4 maps to ENOTEMPTY.
*/
goto out;
}
/* rename results */
/* Update target attribute, readdir and dnlc caches */
dinfo.di_time_call = t;
} else
/* Update source cache attribute, readdir and dnlc caches */
/* Update source cache attribute, readdir and dnlc caches */
/*
* If dinfop is non-NULL, then compound succeded, so
* set di_garp to attrs for source dir. dinfop is only
* set to NULL when compound fails.
*/
if (dinfop)
dinfop);
}
/*
* Update the rnode with the new component name and args,
* and if the file handle changed, also update it with the new fh.
* This is only necessary if the target object has an rnode
* entry and there is no need to create one for it.
*/
/*
* Update the path and filehandle for the renamed object.
*/
resop++; /* getattr res */
}
out:
if (resp)
return (e.error);
}
/* ARGSUSED */
static int
{
int error;
return (EPERM);
/*
* As ".." has special meaning and rather than send a mkdir
* over the wire to just let the server freak out, we just
* short circuit it here and return EEXIST
*/
return (EEXIST);
/*
* Decision to get the right gid and setgid bit of the
* new directory is now made in call_nfs4_create_req.
*/
if (error)
return (error);
return (0);
}
/*
* rmdir is using the same remove v4 op as does remove.
* Remove requires that the current fh be the target directory.
* After the operation, the current fh is unchanged.
* The compound op structure is:
* PUTFH(targetdir), REMOVE
*/
/*ARGSUSED4*/
static int
{
int doqueue;
return (EPERM);
/*
* As ".." has special meaning and rather than send a rmdir
* over the wire to just let the server freak out, we just
* short circuit it here and return EEXIST
*/
return (EEXIST);
return (EINTR);
/*
* Attempt to prevent a rmdir(".") from succeeding.
*/
if (e.error) {
return (e.error);
}
return (EINVAL);
}
/*
* Since nfsv4 remove op works on both files and directories,
* check that the removed object is indeed a directory.
*/
return (ENOTDIR);
}
/*
* 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.
*/
}
recov_state.rs_flags = 0;
/*
* Rmdir ops: putfh dir; remove
*/
if (e.error) {
return (e.error);
}
need_end_op = TRUE;
/* putfh directory */
/* remove */
/* getattr (postop attrs for dir that contained removed dir) */
doqueue = 1;
if (e.error) {
}
if (needrecov) {
if (!e.error)
(void) xdr_free(xdr_COMPOUND4res_clnt,
need_end_op = FALSE;
goto recov_retry;
}
}
if (!e.error) {
/*
* Only return error if first 2 ops (OP_REMOVE or earlier)
* failed.
*/
need_end_op = FALSE;
/*
* System V defines rmdir to return EEXIST, not
* ENOTEMPTY if the directory is not empty. Over
* the wire, the error is NFSERR_ENOTEMPTY which
* geterrno4 maps to ENOTEMPTY.
*/
} else {
} else
/* Update dir attribute, readdir and dnlc caches */
dinfop);
/* destroy rddir cache for dir that was removed */
}
}
if (need_end_op)
if (resp)
if (e.error == 0) {
}
return (e.error);
}
/* ARGSUSED */
static int
{
int error;
char *contents;
return (EPERM);
return (EOPNOTSUPP);
if (error)
return (error);
} else {
}
}
}
return (error);
}
/*
* 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;
return (EIO);
/*
* Make sure that the directory cache is valid.
*/
if (nfs_disable_rddir_cache != 0) {
/*
* 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.
*/
}
if (error)
return (error);
}
/*
* 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 rdc is NULL then the lookup resulted in an unrecoverable error.
*/
return (EINTR);
}
/*
* Check to see if we need to fill this entry in.
*/
/*
* Do the readdir.
*/
/*
* Reacquire the lock, so that we can continue
*/
/*
* The entry is now complete
*/
}
/*
* If an error occurred while attempting
* to fill the cache entry, mark the entry invalid and
* just return the error.
*/
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 NFS 4 cookie
* and set the eof value appropriately.
*/
if (!error) {
if (eofp)
}
/*
* Decide whether to do readahead. Don't if we
* have already read to the end of directory.
*/
/*
* Make the entry the direof only if it is cached
*/
return (error);
}
/* Determine if a readdir readahead should be done */
return (error);
}
/*
* Now look for a readahead entry.
*
* 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.
*/
/*
* A readdir cache entry could not be obtained for the readahead. In
* this case we skip the readahead and return.
*/
return (error);
}
/*
* Check to see if we need to fill this entry in.
*/
#ifdef DEBUG
#endif
/*
* Do the readdir.
*/
return (error);
}
return (error);
}
static int
{
int error;
/*
* Obtain the readdir results for the caller.
*/
/*
* The entry is now complete
*/
if (error)
return (error);
}
/*
* 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.
*
* Generates the following compound request:
* 1. If readdir offset is zero and no dnlc entry for parent exists,
* must include a Lookupp as well. In this case, send:
* { Putfh <fh>; Readdir; Lookupp; Getfh; Getattr }
* 2. Otherwise just do: { Putfh <fh>; Readdir }
*
* Get complete attributes and filehandles for entries if this is the
* first read of the directory. Otherwise, just get fileid's.
*/
static void
{
int doqueue;
hrtime_t t;
/*
* If rp were a stub, it should have triggered and caused
* a mount for us to get this far.
*/
num_ops = 2;
/*
* Since nfsv4 readdir may not return entries for "." and "..",
* the client must recreate them:
* To find the correct nodeid, do the following:
* For current node, get nodeid from dnlc.
* - if current node is rootvp, set pnodeid to nodeid.
* - else if parent is in the dnlc, get its nodeid from there.
* - else add LOOKUPP+GETATTR to compound.
*/
} else {
/* parent in dnlc cache - no need for otw */
} else {
/*
* parent not in dnlc cache,
* do lookupp to get its id
*/
num_ops = 5;
pnodeid = 0; /* set later by getattr parent */
}
if (dvp)
}
}
recov_state.rs_flags = 0;
/* Save the original mount point security flavor */
&recov_state, NULL)) {
/*
* If readdir a node that is a stub for a crossed mount point,
* keep the original secinfo flavor for the current file
* system, not the crossed one.
*/
return;
}
/*
* Determine which attrs to request for dirents. This code
* must be protected by nfs4_start/end_fop because of r_server
* (which will change during failover recovery).
*
*/
/*
* Get all vattr attrs plus filehandle and rdattr_error
*/
}
} else {
/*
* Already read directory. Use readdir with
* no attrs (except for mounted_on_fileid) for updates.
*/
/*
* request mounted on fileid if supported, else request
* fileid. maybe we should verify that fileid is supported
* and request something else if not.
*/
}
/* putfh directory fh */
/*
* 1 and 2 are reserved for client "." and ".." entry offset.
* cookie 0 should be used over-the-wire to start reading at
* the beginning of the directory excluding "." and "..".
*/
if (rdc->nfs4_cookie == 0 ||
rargs->cookieverf = 0;
} else {
}
/*
* If count < than the minimum required, we return no entries
* and fail with EINVAL
*/
goto out;
}
/*
* Add lookupp and getattr for parent nodeid.
*/
/* getattr parent */
}
doqueue = 1;
if (mi->mi_io_kstats) {
}
/* capture the time of this call */
if (mi->mi_io_kstats) {
}
/*
* If RPC error occurred and it isn't an error that
* triggers recovery, then go ahead and fail now.
*/
goto out;
}
if (needrecov) {
"nfs4readdir: initiating recovery.\n"));
if (!e.error)
(void) xdr_free(xdr_COMPOUND4res_clnt,
}
goto recov_retry;
}
if (e.error != 0) {
goto out;
}
/* fall through for res.status case */
}
/*
* If compound failed first 2 ops (PUTFH+READDIR), then return
* failure here. Subsequent ops are for filling out dot-dot
* dirent, and if they fail, we still want to give the caller
* the dirents returned by (the successful) READDIR op, so we need
* to silently ignore failure for subsequent ops (LOOKUPP+GETATTR).
*
* One example where PUTFH+READDIR ops would succeed but
* LOOKUPP+GETATTR would fail would be a dir that has r perm
* but lacks x. In this case, a POSIX server's VOP_READDIR
* would succeed; however, VOP_LOOKUP(..) would fail since no
* x perm. We need to come up with a non-vendor-specific way
* for a POSIX server to return d_ino from dotdot's dirent if
* client only requests mounted_on_fileid, and just say the
* LOOKUPP succeeded and fill out the GETATTR. However, if
* client requested any mandatory attrs, server would be required
* to fail the GETATTR op because it can't call VOP_LOOKUP+VOP_GETATTR
* for dotdot.
*/
if (res_opcnt <= 2) {
}
/*
* If readdir a node that is a stub for a
* crossed mount point, keep the original
* secinfo flavor for the current file system,
* not the crossed one.
*/
return;
}
}
/*
* For "." and ".." entries
* e.g.
* seek(cookie=0) -> "." entry with d_off = 1
* seek(cookie=1) -> ".." entry with d_off = 2
*/
if (cookie == (nfs_cookie4) 0) {
}
}
/* LOOKUPP+GETATTR attemped */
resop++; /* lookupp */
resop++; /* getfh */
resop++; /* getattr of parent */
/*
* First, take care of finishing the
* readdir results.
*/
/*
* The d_ino of .. must be the inode number
* of the mounted filesystem.
*/
/*
* Next, create the ".." dnlc entry
*/
}
}
}
if (mi->mi_io_kstats) {
}
out:
/*
* If readdir a node that is a stub for a crossed mount point,
* keep the original secinfo flavor for the current file system,
* not the crossed one.
*/
}
static int
{
int count;
int error;
/*
* Releases the osp, if it is provided.
* Puts a hold on the cred_otw and the new osp (if found).
*/
&first_time, &last_time);
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 {
/*
* Releases the osp, if it is provided.
* Puts a hold on the cred_otw and the new
* osp (if found).
*/
&first_time, &last_time);
if (count < 0)
#ifdef DEBUG
if (count == 0) {
"nfs4_bio: zero length write at %lld",
offset);
"b_bcount=%ld, file size=%lld",
if (nfs4_bio_do_stop)
debug_enter("nfs4_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)
}
}
if (osp)
return (error);
}
/* ARGSUSED */
int
{
return (EREMOTE);
}
/* ARGSUSED2 */
int
{
if (!write_lock) {
return (V_WRITELOCK_FALSE);
}
return (V_WRITELOCK_FALSE);
}
return (V_WRITELOCK_TRUE);
}
/* ARGSUSED */
void
{
}
/* ARGSUSED */
static int
{
return (EIO);
/*
* 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);
}
/*
* Return all the pages from [off..off+len) in file
*/
/* ARGSUSED */
static int
{
int error;
return (EIO);
return (ENOSYS);
/*
* Now validate that the caches are up to date.
*/
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.
*/
(CE_NOTE, "getpage beyond EOF: off=%lld, "
"len=%llu, size=%llu, attrsize =%llu", off,
return (EFAULT); /* beyond EOF */
}
(CE_NOTE, "getpages error %d; off=%lld, len=%lld",
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(nfs4_nra) readaheads when the readahead
* window is closed.
* c) Do readaheads between 1 to (nfs4_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;
<= (nfs4_nra - 1)))
else
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
*/
/*
* If less than a block left in
* file read less than a block.
*/
/*
* 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) or
* len == MAXBSIZE (from segmap_release actions), and len == PAGESIZE
* (from pageout).
*/
/* ARGSUSED */
static int
{
int error;
return (EIO);
/*
* XXX - Why should this check be made here?
*/
return (ENOSYS);
return (0);
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 R4MODINPROGRESS flag makes sure that nfs4_bio() sees a
* consistent value of r_size. R4MODINPROGRESS is set in writerp4().
* When R4MODINPROGRESS 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 R4MODINPROGRESS flag is cleared.
*
* The R4MODINPROGRESS flag makes sure that nfs4_bio() sees a
* consistent value of r_size. Without this handshaking, it is
* possible that nfs4_bio() picks up the old value of r_size
* before the uiomove() in writerp4() completes. This will result
* in the write through nfs4_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 nfs4write(), 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 R4MODINPROGRESS here then this
* path through nfs_putapage() would eventually go to
* nfs4_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 R4DIRTY. 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);
}
#ifdef DEBUG
int nfs4_force_open_before_mmap = 0;
#endif
/* ARGSUSED */
static int
{
int error = 0;
return (EIO);
return (ENOSYS);
return (ENXIO);
return (ENODEV);
/*
* If the file is delegated to the client don't do anything.
* If the file is not delegated, then validate the data cache.
*/
if (error)
return (error);
} else {
}
/*
* 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 nfs4_map(). Now, r_rwlock is acquired in order
* and we can prevent the deadlock that would have occurred
* when nfs4_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.
*/
if (flk_has_remote_locks(vp)) {
if (error != 0)
goto done;
goto done;
}
}
/*
* It is possible that the rnode has a lost lock request that we
* are still trying to recover, and that the request conflicts with
* this map request.
*
* An alternative approach would be for nfs4_safemap() to consider
* queued lock requests when deciding whether to set or clear
* VNOCACHE. This would require the frlock code path to call
* nfs4_safemap() after enqueing a lost request.
*/
if (nfs4_map_lost_lock_conflict(vp)) {
goto done;
}
if (error != 0) {
goto done;
}
/*
* We need to retrieve the open stream
*/
/* returns with 'os_sync_lock' held */
}
#ifdef DEBUG
if (nfs4_force_open_before_mmap) {
goto done;
}
#endif
/* returns with 'os_sync_lock' held */
"nfs4_map: we tried to OPEN the file "
"but again no osp, so fail with EIO"));
goto done;
}
}
if (osp->os_failed_reopen) {
"nfs4_map: os_failed_reopen set on "
"osp %p, cr %p, rp %s", (void *)osp,
goto done;
}
}
done:
return (error);
}
/*
* We're most likely dealing with a kernel module that likes to READ
* officially OPEN the file to create the necessary client state
* for bookkeeping of os_mmap_read/write counts.
*
* Since VOP_MAP only passes in a pointer to the vnode rather than
* a double pointer, we can't handle the case where nfs4open_otw()
* returns a different vnode than the one passed into VOP_MAP (since
* VOP_DELMAP will not see the vnode nfs4open_otw used). In this case,
* we return NULL and let nfs4_map() fail. Note: the only case where
* this should happen is if the file got removed and replaced with the
* same name on the server (in addition to the fact that we're trying
* to VOP_MAP withouth VOP_OPENing the file in the first place).
*/
static int
{
int just_created;
int error;
return (error);
return (EINTR);
}
return (error);
}
if (rp->created_v4) {
rp->created_v4 = 0;
/* This is needed so we don't bump the open ref count */
just_created = 1;
} else {
just_created = 0;
}
if (error) {
return (error);
}
/*
* If nfs4open_otw() returned a different vnode then "undo"
* the open and return failure to the caller.
*/
nfs4_error_t e;
"open returned a different vnode"));
/*
* If there's an error, ignore it,
* and let VOP_INACTIVE handle it.
*/
CLOSE_NORM, 0, 0, 0);
return (EIO);
}
if (!oop) {
nfs4_error_t e;
"no open owner"));
/*
* If there's an error, ignore it,
* and let VOP_INACTIVE handle it.
*/
CLOSE_NORM, 0, 0, 0);
return (EIO);
}
return (0);
}
/*
* Please be aware that when this function is called, the address space write
* a_lock is held. Do not put over the wire calls in this function.
*/
/* ARGSUSED */
static int
{
int error = 0;
return (EIO);
return (ENOSYS);
/*
* Don't need to update the open stream first, since this
* mmap can't add any additional share access that isn't
* already contained in the open stream (for the case where we
* take into account os_mmap_read[write] counts).
*/
/*
* We need to retrieve the open stream and update the counts.
* If there is no open stream here, something is wrong.
*/
/* returns with 'os_sync_lock' held */
}
"nfs4_addmap: we should have an osp"
"but we don't, so fail with EIO"));
goto out;
}
/*
* Update the map count in the open stream.
* This is necessary in the case where we
* attempt to reopen. If the mmap doesn't add share
* access then we send an invalid reopen with
* access = NONE.
*
* We need to specifically check each PROT_* so a mmap
* call of (PROT_WRITE | PROT_EXEC) will ensure us both
* read and write access. A simple comparison of prot
* to ~PROT_WRITE to determine read access is insufficient
* since prot can be |= with PROT_USER, etc.
*/
/*
* Unless we're MAP_SHARED, no sense in adding os_mmap_write
*/
/*
* Ensure that os_mmap_read gets incremented, even if
* maxprot were to look like PROT_NONE.
*/
}
out:
/*
* If we got an error, then undo our
* incrementing of 'r_mapcnt'.
*/
if (error) {
}
return (error);
}
/* ARGSUSED */
static int
{
}
/* ARGSUSED */
static int
{
int rc;
nfs4_error_t e;
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
* nfs4_safelock and then fs_frlock while
* holding r_lkserlock, so just invoke
* nfs4_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 (EIO);
return (EINVAL);
if (!error) {
} else
}
return (error);
}
/* ARGSUSED */
int
{
}
return (0);
}
/*
* 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()/nfs4_delmap()
* - as_unmap()->SEGOP_UNMAP()/segvn_unmap()->VOP_DELMAP()/nfs4_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
* nfs4_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 nfs4_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 nfs4_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 */
}
static nfs4_delmapcall_t *
{
delmap_call->error = 0;
return (delmap_call);
}
static void
{
}
/*
* Searches for the current delmap caller (based on curthread) in the list of
* callers. If it is found, we remove it and free the delmap caller.
* Returns:
* 0 if the caller wasn't found
* 1 if the caller was found, removed and freed. *errp will be set
* to what the result of the delmap was.
*/
static int
{
/*
* If the list doesn't exist yet, we create it and return
* that the caller wasn't found. No list = no callers.
*/
/* The list does not exist */
return (0);
} else {
/* The list exists so search it */
delmap_call != NULL;
/* current caller is in the list */
return (1);
}
}
}
return (0);
}
/*
* 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
{
/*
* 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 (!e.error) {
}
} else
e.error = 0;
if (e.error) {
}
/* Check to see if we need to close the file */
/*
* Since it is possible that e.error == 0 and
* e.stat != NFS4_OK (and vice versa),
* we do the proper checking in order to get both
* e.error and e.stat reporting the correct info.
*/
if (e.error == 0)
}
}
}
static uint_t
{
uint_t l = 1;
if (ll == 0) {
return (0);
}
if (ll & 0xffffffff00000000) {
}
if (ll & 0xffff0000) {
}
if (ll & 0xff00) {
}
if (ll & 0xf0) {
}
if (ll & 0xc) {
}
if (ll & 0x2) {
l += 1;
}
return (l);
}
static int
{
int error;
LOOKUP_XATTR, cr)) == 0)
if (avp)
return (error);
}
/* ARGSUSED */
int
{
int error;
hrtime_t t;
return (EIO);
*valp = MAXPATHLEN;
return (0);
}
if (cmd == _PC_ACL_ENABLED) {
*valp = _ACL_ACE_ENABLED;
return (0);
}
if (cmd == _PC_XATTR_EXISTS) {
/*
* The existence of the xattr directory is not sufficient
* for determining whether generic user attributes exists.
* The attribute directory could only be a transient directory
* used for Solaris sysattr support. Do a small readdir
* to verify if the only entries are sysattrs or not.
*
* pc4_xattr_valid can be only be trusted when r_xattr_dir
* is NULL. Once the xadir vp exists, we can create xattrs,
* and we don't have any way to update the "base" object's
* pc4_xattr_exists from the xattr or xadir. Maybe FEM
* could help out.
*/
}
} else { /* OLD CODE */
if (ATTRCACHE4_VALID(vp)) {
error = 0;
switch (cmd) {
case _PC_FILESIZEBITS:
*valp =
break;
case _PC_LINK_MAX:
*valp =
break;
case _PC_NAME_MAX:
*valp =
break;
case _PC_CHOWN_RESTRICTED:
*valp =
break;
case _PC_NO_TRUNC:
*valp =
break;
default:
break;
}
#ifdef DEBUG
#endif
return (error);
}
}
}
#ifdef DEBUG
#endif
t = gethrtime();
if (error) {
return (error);
}
/* interpret the max filesize */
/* Store the attributes we just received */
switch (cmd) {
case _PC_FILESIZEBITS:
break;
case _PC_LINK_MAX:
break;
case _PC_NAME_MAX:
break;
case _PC_CHOWN_RESTRICTED:
break;
case _PC_NO_TRUNC:
break;
case _PC_XATTR_EXISTS:
return (error);
}
break;
default:
return (EINVAL);
}
return (0);
}
/*
* 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 (EIO);
return (EINVAL);
} 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 COMMIT op 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 just unlock 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 nfs4_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
}
/*
* Commit requires that the current fh be the file written to.
* The compound op structure is:
* PUTFH(file), COMMIT
*/
static int
{
int doqueue;
recov_state.rs_flags = 0;
/*
* Releases the osp, if a valid open stream is provided.
* Puts a hold on the cred_otw and the new osp (if found).
*/
&first_time, &last_time);
/*
* Commit ops: putfh file; commit
*/
&recov_state, NULL);
if (e.error) {
return (e.error);
}
/* putfh directory */
/* commit */
doqueue = 1;
goto get_commit_cred;
return (e.error);
}
if (needrecov) {
if (!e.error)
(void) xdr_free(xdr_COMPOUND4res_clnt,
goto recov_retry;
}
if (e.error) {
return (e.error);
}
/* fall through for res.status case */
}
goto get_commit_cred;
}
/*
* Can't do a nfs4_purge_stale_fh here because this
* can cause a deadlock. nfs4_commit can
* be called from nfs4_dispose which can be called
* indirectly via pvn_vplist_dirty. nfs4_purge_stale_fh
* can call back to pvn_vplist_dirty.
*/
} else {
}
} else {
return (0);
}
e.error = NFS_VERF_MISMATCH;
}
return (e.error);
}
static void
{
/* make sure we're looking at the master vnode, not a shadow */
}
/*
* This function is used to gather a page list of the pages which
* can be committed on the server.
*
* The calling thread must have set R4COMMIT. This bit is used to
* serialize access to the commit structure in the rnode. As long
* as the thread has set R4COMMIT, then it can manipulate the commit
* structure without requiring any other locks.
*
* When this function is called from nfs4_dispose() the page passed
* into nfs4_dispose() will be SE_EXCL locked, and so this function
* will skip it. This is not a problem since we initially add the
* page to the r_commit page list.
*
*/
static void
{
/* make sure we're looking at the master vnode, not a shadow */
/*
* 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;
/*
* First short-cut everything (without the page_lock)
* and see if this page does not need to be committed
* or is modified if so then we'll just skip it.
*/
continue;
/*
* Attempt to lock the page. If we can't, then
* someone else is messing with it or we have been
* called from nfs4_dispose and this is the page that
* nfs4_dispose was called with.. anyway just skip it.
*/
continue;
/*
* Lets check again now that we have the page lock.
*/
continue;
}
/* this had better not be a free page */
/*
* 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 R4COMMIT. This bit is used to
* serialize access to the commit structure in the rnode. As long
* as the thread has set R4COMMIT, then it can manipulate the commit
* structure without requiring any other locks.
*/
static void
{
/* make sure we're looking at the master vnode, not a shadow */
/*
* 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 {
}
}
}
/*
* Called from nfs4_close(), nfs4_fsync() and nfs4_delmap().
* Flushes and commits data to the server.
*/
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 synchronously 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 nfs4_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);
}
/*
* nfs4_commit_vp() will wait for other pending commits and
* will either commit the whole file or a range, plen dictates
* if we commit whole file. a value of zero indicates the whole
* file. Called from nfs4_putpage_commit() or nfs4_sync_putapage()
*/
static int
{
/*
* before we gather commitable pages make
* sure there are no outstanding async writes
*/
}
}
/*
* Set the `commit inprogress' state bit. We must
* first wait until any current one finishes.
*/
}
/*
* Gather 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 by nfs4_get_commit.
*/
/*
* If any pages need to be committed, commit them and
* then unlock them so that they can be freed some
* time later.
*/
return (0);
/*
* 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.
*/
}
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 = 0;
return (EIO);
/* if we have a delegation, return it */
if (error) /* EINVAL */
return (error);
/*
* These are aclent_t type entries.
*/
if (error)
return (error);
} else {
/*
* These are ace_t type entries.
*/
FALSE);
if (error)
return (error);
}
return (error);
}
return (ENOSYS);
}
/* ARGSUSED */
int
{
int error;
return (EIO);
/*
* vsecattr->vsa_mask holds the original acl request mask.
* This is needed when determining what to return.
* (See: nfs4_create_getsecattr_return())
*/
if (error) /* EINVAL */
return (error);
/*
* If this is a referral stub, don't try to go OTW for an ACL
*/
/*
* Check if the data is cached and the cache is valid. If it
* is we don't go over the wire.
*/
if (!error) { /* error == 0 - Success! */
return (error);
}
}
}
/*
* The getattr otw call will always get both the acl, in
* the form of a list of nfsace4's, and the number of acl
* entries; independent of the value of gar.n4g_va.va_mask.
*/
if (error) {
return (error);
}
/*
* No error was returned, but according to the response
* bitmap, neither was an acl.
*/
return (error);
}
/*
* Update the cache with the ACL.
*/
}
return (error);
}
return (error);
}
/*
* The function returns:
* - 0 (zero) if the passed in "acl_mask" is a valid request.
* - EINVAL if the passed in "acl_mask" is an invalid request.
*
* In the case of getting an acl (op == NFS4_ACL_GET) the mask is invalid if:
* - We have a mixture of ACE and ACL requests (e.g. VSA_ACL | VSA_ACE)
*
* In the case of setting an acl (op == NFS4_ACL_SET) the mask is invalid if:
* - We have a mixture of ACE and ACL requests (e.g. VSA_ACL | VSA_ACE)
* - We have a count field set without the corresponding acl field set. (e.g. -
* VSA_ACECNT is set, but VSA_ACE is not)
*/
static int
{
/* Shortcut the masks that are always valid. */
return (0);
return (0);
/*
* We can't have any VSA_ACL type stuff in the mask now.
*/
return (EINVAL);
if (op == NFS4_ACL_SET) {
return (EINVAL);
}
}
/*
* We can't have any VSA_ACE type stuff in the mask now.
*/
return (EINVAL);
if (op == NFS4_ACL_SET) {
return (EINVAL);
if ((acl_mask & VSA_DFACLCNT) &&
return (EINVAL);
}
}
return (0);
}
/*
* The theory behind creating the correct getsecattr return is simply this:
* "Don't return anything that the caller is not expecting to have to free."
*/
static int
{
int error = 0;
/* Save the mask since the translators modify it. */
if (error)
return (error);
/*
* If the caller only asked for the ace count (VSA_ACECNT)
* don't give them the full acl (VSA_ACE), free it.
*/
}
}
VSA_DFACLCNT)) {
if (error)
return (error);
/*
* If the caller only asked for the acl count (VSA_ACLCNT)
* the acl (VSA_ACL) or default acl (VSA_DFACL), free it.
*/
}
}
}
}
}
return (0);
}
/* ARGSUSED */
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:
/*
* This will be properly implemented later,
* see RFE: 4823948 .
*/
break;
case F_HASREMOTELOCKS:
/*
* NFS client can't store remote locks itself
*/
error = 0;
break;
default:
break;
}
return (error);
}
/*
* Common code called by directory ops to update the attrcache
*/
static int
{
int error = 0;
/* getattr not done or failed */
return (error);
}
if (garp) {
} else {
}
return (error);
}
/*
* Update directory caches for directory modification ops (link, rename, etc.)
* When dinfo is NULL, manage dircaches in the old way.
*/
static void
{
/* Purge rddir cache for dir since it changed */
/*
* If caller provided dinfo, then use it to manage dir caches.
*/
} else {
/*
* XXX don't update if the created_v4 flag is
* set
*/
(CE_NOTE, "nfs4_update_dircaches: "
"don't update dnlc: created_v4 flag"));
}
}
return;
}
/*
* Caller didn't provide dinfo, then check change_info4 to update DNLC.
* Since caller modified dir but didn't receive post-dirmod-op dir
* attrs, the dir's attrs must be purged.
*
* XXX but can't use rnode statelock because it'll deadlock in
* XXX dnlc_purge_vp, however, the risk is minimal even if a race
* XXX does occur.
*
* XXX We also may want to check that atomic is true in the
* XXX change_info struct. If it is not, the change_info may
* XXX reflect changes by more than one clients which means that
* XXX our cache may not be valid.
*/
/* no changes took place in the directory prior to our link */
} else {
/*
* XXX dont' update if the created_v4 flag
* is set
*/
"nfs4_update_dircaches: don't"
" update dnlc: created_v4 flag"));
}
}
} else {
/* Another client modified directory - purge its dnlc cache */
}
}
/*
* The OPEN_CONFIRM operation confirms the sequence number used in OPENing a
* file.
*
* The 'reopening_file' boolean should be set to TRUE if we are reopening this
* file (ie: client recovery) and otherwise set to FALSE.
*
* 'nfs4_start/end_op' should have been called by the proper (ie: not recovery
* initiated) calling functions.
*
* 'resend' is set to TRUE if this is a OPEN_CONFIRM issued as a result
* of resending a 'lost' open request.
*
* 'num_bseqid_retryp' makes sure we don't loop forever on a broken
* server that hands out BAD_SEQID on open confirm.
*
* Errors are returned via the nfs4_error_t parameter.
*/
void
{
int needrecov;
#if DEBUG
#endif
*retry_open = FALSE;
if (resend)
else
/* putfh target fh */
(*seqid) += 1;
}
return;
if (needrecov) {
if (reopening_file == FALSE) {
if (bsep) {
if (num_bseqid_retryp &&
--(*num_bseqid_retryp) == 0)
}
}
(void) xdr_free(xdr_COMPOUND4res_clnt,
goto recov_retry_confirm;
}
/* State may have changed so retry the entire OPEN op */
*retry_open = TRUE;
else
*retry_open = FALSE;
return;
}
return;
}
}
/*
* Return the credentials associated with a client state object. The
* caller is responsible for freeing the credentials.
*/
static cred_t *
{
/*
* It's ok to not lock the open stream and open owner to get
* the oo_cred since this is only written once (upon creation)
* and will not change.
*/
return (cr);
}
/*
* nfs4_find_sysid
*
* Find the sysid for the knetconfig associated with the given mi.
*/
static struct lm_sysid *
{
/*
* Switch from RDMA knconf to original mount knconf
*/
}
#ifdef DEBUG
/*
* Return a string version of the call type for easy reading.
*/
static char *
{
switch (ctype) {
case NFS4_LCK_CTYPE_NORM:
return ("NORMAL");
case NFS4_LCK_CTYPE_RECLAIM:
return ("RECLAIM");
case NFS4_LCK_CTYPE_RESEND:
return ("RESEND");
case NFS4_LCK_CTYPE_REINSTATE:
return ("REINSTATE");
default:
"type %d", ctype);
return ("");
}
}
#endif
/*
* Map the frlock cmd and lock type to the NFSv4 over-the-wire lock type
* Unlock requests don't have an over-the-wire locktype, so we just return
* something non-threatening.
*/
static nfs_lock_type4
{
switch (l_type) {
case F_UNLCK:
return (READ_LT);
case F_RDLCK:
return (READ_LT);
else
return (READW_LT);
case F_WRLCK:
return (WRITE_LT);
else
return (WRITEW_LT);
}
panic("flk_to_locktype");
/*NOTREACHED*/
}
/*
* Do some preliminary checks for nfs4frlock.
*/
static int
{
int error = 0;
/*
* If we are setting a lock, check that the file is opened
* with the correct mode.
*/
"nfs4frlock_validate_args: file was opened with "
"incorrect mode"));
return (EBADF);
}
}
/* Convert the offset. It may need to be restored before returning. */
"nfs4frlock_validate_args: convoff => error= %d\n",
error));
return (error);
}
return (error);
}
/*
* Set the flock64's lm_sysid for nfs4frlock.
*/
static int
{
/* Find the lm_sysid */
"nfs4frlock_get_sysid: no sysid, return ENOLCK"));
return (ENOLCK);
}
return (0);
}
/*
* Do the remaining preliminary setup for nfs4frlock.
*/
static void
{
/*
* set tick_delay to the base delay time.
* (NFS4_BASE_WAIT_TIME is in secs)
*/
/*
* If lock is relative to EOF, we need the newest length of the
* file. Therefore invalidate the ATTR_CACHE.
*/
recov_statep->rs_flags = 0;
}
/*
* Initialize and allocate the data structures necessary for
* the nfs4frlock call.
* Allocates argsp's op array, frees up the saved_rqstpp if there is one.
*/
static void
{
int argoplist_size;
*did_start_fop = FALSE;
*skip_get_err = FALSE;
lost_rqstp->lr_op = 0;
/* fill array with zero */
/* initialize in case of error; will get real value down below */
else
}
/*
* Call the nfs4_start_fop() for nfs4frlock, if necessary. Assign
* the proper nfs4_server_t for this instance of nfs4frlock.
* Returns 0 (success) or an errno value.
*/
static int
{
int error = 0;
if (ctype == NFS4_LCK_CTYPE_NORM) {
if (error)
return (error);
*did_start_fop = TRUE;
} else {
*did_start_fop = FALSE;
*startrecovp = FALSE;
}
if (!error) {
/* If the file failed recovery, just quit. */
}
}
return (error);
}
/*
* resend nfs4frlock call is initiated by the recovery framework.
* Acquires the lop and oop seqid synchronization.
*/
static void
{
int error;
(CE_NOTE,
"nfs4frlock_setup_resend_lock_args: have lost lock to resend"));
if (resend_rqstp->lr_oop) {
}
if (*ospp)
switch (resend_rqstp->lr_ctype) {
case NFS4_LCK_CTYPE_RESEND:
break;
case NFS4_LCK_CTYPE_REINSTATE:
break;
case NFS4_LCK_CTYPE_RECLAIM:
break;
default:
break;
}
} else {
if (locku_args->length == 0)
switch (resend_rqstp->lr_ctype) {
case NFS4_LCK_CTYPE_RESEND:
break;
case NFS4_LCK_CTYPE_REINSTATE:
break;
default:
break;
}
}
}
/*
* Setup the LOCKT4 arguments.
*/
static void
{
/*
* The locktype will be READ_LT unless it's
* a write lock. We do this because the Solaris
* system call allows the combination of
* F_UNLCK and F_GETLK* and so in that case the
* unlock is mapped to a read.
*/
else
/* set the lock owner4 args */
}
/*
* If the client is holding a delegation, and the open stream to be used
* with this lock request is a delegation open stream, then re-open the stream.
* Sets the nfs4_error_t to all zeros unless the open stream has already
* failed a reopen or we couldn't find the open stream. NFS4ERR_DELAY
* means the caller should retry (like a recovery retry).
*/
static void
{
if (dt != OPEN_DELEGATE_NONE) {
if (!oop) {
return;
}
/* returns with 'os_sync_lock' held */
if (!osp) {
return;
}
if (osp->os_failed_reopen) {
"nfs4frlock_check_deleg: os_failed_reopen set "
"for osp %p, cr %p, rp %s", (void *)osp,
return;
}
/*
* Determine whether a reopen is needed. If this
* is a delegation open stream, then send the open
* to the server to give visibility to the open owner.
* Even if it isn't a delegation open stream, we need
* to check if the previous open CLAIM_DELEGATE_CUR
* was sufficient.
*/
if (reopen_needed) {
/*
* Always use CLAIM_PREVIOUS after server reboot.
* The server will reject CLAIM_DELEGATE_CUR if
* it is used during the grace period.
*/
} else {
}
}
}
}
}
/*
* Setup the LOCKU4 arguments.
* Returns errors via the nfs4_error_t.
* NFS4_OK no problems. *go_otwp is TRUE if call should go
* over-the-wire. The caller must release the
* reference on *lopp.
* NFS4ERR_DELAY caller should retry (like recovery retry)
* (other) unrecoverable error.
*/
static void
{
return;
if (ctype == NFS4_LCK_CTYPE_REINSTATE)
else
/*
* XXX what should locku_args->locktype be?
* setting to ALWAYS be READ_LT so at least
* it is a valid locktype.
*/
/*
* Get the lock owner stateid. If no lock owner
* exists, return success.
*/
/*
* No lock owner so no locks to unlock.
* Return success. If there was a failed
* reclaim earlier, the lock might still be
* registered with the local locking code,
* so notify it of the unlock.
*
* If the lockowner is using a special stateid,
* then the original lock request (that created
* this lockowner) was never successful, so we
* have no lock to undo OTW.
*/
"nfs4frlock_setup_locku_args: LOCKU: no lock owner "
"(%ld) so return success", (long)pid));
if (ctype == NFS4_LCK_CTYPE_NORM)
/*
* Release our hold and NULL out so final_cleanup
* doesn't try to end a lock seqid sync we
* never started.
*/
if (is_spec) {
}
*skip_get_err = TRUE;
return;
}
return;
}
/* leave the ref count on lop, rele after RPC call */
}
/*
* Setup the LOCK4 arguments.
*
* Returns errors via the nfs4_error_t.
* NFS4_OK no problems
* NFS4ERR_DELAY caller should retry (like recovery retry)
* (other) unrecoverable error
*/
static void
{
return;
if (ctype == NFS4_LCK_CTYPE_NORM)
else if (ctype == NFS4_LCK_CTYPE_RECLAIM)
else
/*
* Get the lock owner. If no lock owner exists,
* create a 'temporary' one and grab the open seqid
* synchronization (which puts a hold on the open
* owner and open stream).
* This also grabs the lock seqid synchronization.
*/
goto out;
*lock_argsp = lock_args;
out:
}
/*
* After we get the reply from the server, record the proper information
* for possible resend lock requests.
*
* Allocates memory for the saved_rqstp if we have a lost lock to save.
*/
static void
{
"nfs4frlock_save_lost_rqst: set lo_pending_rqsts to 1 "
" for lop %p", (void *)lop));
}
lost_rqstp->lr_op = 0;
/*
* recovery purposes so that the lock request that was sent
* can be saved and re-issued later. Ditto for EIO from a forced
* unmount. This is done to have the client's local locking state
* match the v4 server's state; that is, the request was
* potentially received and accepted by the server but the client
* thinks it was not.
*/
"nfs4frlock_save_lost_rqst: got a lost %s lock for "
if (unlock)
else {
}
/*
* Objects are held and rele'd via the recovery code.
* See nfs4_save_lost_rqst.
*/
switch (ctype) {
case NFS4_LCK_CTYPE_NORM:
break;
case NFS4_LCK_CTYPE_REINSTATE:
break;
default:
break;
}
}
}
/*
* Update lop's seqid. Also update the seqid stored in a resend request,
* if any. (Some recovery errors increment the seqid, and we may have to
* send the resend request again.)
*/
static void
{
if (lock_args) {
else {
}
} else if (locku_args) {
}
}
/*
* Calls nfs4_end_fop, drops the seqid syncs, and frees up the
* Switches the *cred_otwp to base_cr.
*/
static void
{
if (*did_start_fop) {
*did_start_fop = FALSE;
}
if (!error)
if (lop) {
}
/* need to free up the reference on osp for lock args */
}
/* need to free up the reference on oop for lock args */
}
}
/*
* Function to process the client's recovery for nfs4frlock.
* Returns TRUE if we should retry the lock request; FALSE otherwise.
*
* Calls nfs4_end_fop, drops the seqid syncs, and frees up the
*
* Note: the rp's r_lkserlock is *not* dropped during this path.
*/
static bool_t
{
if (lock_args || locku_args)
(CE_NOTE, "nfs4frlock_recovery: initiating recovery\n"));
if (needrecov) {
if (lock_args) {
else
} else if (locku_args) {
} else {
seqid = 0;
}
}
if (bsep)
}
/*
* Return that we do not want to retry the request for 3 cases:
* 1. If we received EINTR or are bailing out because of a forced
* unmount, we came into this code path just for the sake of
* initiating recovery, we now need to return the error.
* 2. If we have aborted recovery.
* 3. We received NFS4ERR_BAD_SEQID.
*/
if (*did_start_fop == TRUE) {
*did_start_fop = FALSE;
}
}
}
/* need to free up the reference on osp for lock args */
}
/* need to free up the reference on oop for lock args */
}
return (retry);
}
/*
* Handles the successful reply from the server for nfs4frlock.
*/
static void
{
if (ctype == NFS4_LCK_CTYPE_NORM) {
/*
* We do not register lost locks locally in
* the 'resend' case since the user/application
* doesn't think we have the lock.
*/
}
}
}
/*
* Handle the DENIED reply from the server for nfs4frlock.
* Returns TRUE if we should retry the request; FALSE otherwise.
*
* Calls nfs4_end_fop, drops the seqid syncs, and frees up the
* drop and regrab the r_lkserlock.
*/
static bool_t
{
if (lock_args) {
int intr;
/*
* Blocking lock needs to sleep and retry from the request.
*
* Do not block and wait for 'resend' or 'reinstate'
* lock requests, just return the error.
*
* Note: reclaim requests have cmd == F_SETLK, not F_SETLKW.
*/
*did_start_fop = FALSE;
if (*respp)
(void) xdr_free(xdr_COMPOUND4res_clnt,
}
}
if (intr) {
return (FALSE);
}
/*
* Make sure we are still safe to lock with
* regards to mmapping.
*/
return (FALSE);
}
return (TRUE);
}
if (ctype == NFS4_LCK_CTYPE_NORM)
*skip_get_err = TRUE;
*whencep = 0;
return (FALSE);
} else if (lockt_args) {
"nfs4frlock_results_denied: OP_LOCKT DENIED"));
flk, lockt_args);
/* according to NLM code */
*errorp = 0;
*whencep = 0;
*skip_get_err = TRUE;
return (FALSE);
}
return (FALSE);
}
/*
* Handles all NFS4 errors besides NFS4_OK and NFS4ERR_DENIED for nfs4frlock.
*/
static void
{
case NFS4ERR_ACCESS:
case NFS4ERR_ADMIN_REVOKED:
case NFS4ERR_BADHANDLE:
case NFS4ERR_BAD_RANGE:
case NFS4ERR_BAD_SEQID:
case NFS4ERR_BAD_STATEID:
case NFS4ERR_BADXDR:
case NFS4ERR_DEADLOCK:
case NFS4ERR_DELAY:
case NFS4ERR_EXPIRED:
case NFS4ERR_FHEXPIRED:
case NFS4ERR_GRACE:
case NFS4ERR_INVAL:
case NFS4ERR_ISDIR:
case NFS4ERR_LEASE_MOVED:
case NFS4ERR_LOCK_NOTSUPP:
case NFS4ERR_LOCK_RANGE:
case NFS4ERR_MOVED:
case NFS4ERR_NOFILEHANDLE:
case NFS4ERR_NO_GRACE:
case NFS4ERR_OLD_STATEID:
case NFS4ERR_OPENMODE:
case NFS4ERR_RECLAIM_BAD:
case NFS4ERR_RECLAIM_CONFLICT:
case NFS4ERR_RESOURCE:
case NFS4ERR_SERVERFAULT:
case NFS4ERR_STALE:
case NFS4ERR_STALE_CLIENTID:
case NFS4ERR_STALE_STATEID:
return;
default:
"nfs4frlock_results_default: got unrecognizable "
*errorp = NFS4ERR_INVAL;
}
}
/*
* The lock request was successful, so update the client's state.
*/
static void
{
if (lock_args) {
/* update the stateid with server's response */
}
/*
* If the lock was the result of a resending a lost
* request, we've synched up the stateid and seqid
* with the server, but now the server might be out of sync
* with what the application thinks it has for locks.
* Clean that up here. It's unclear whether we should do
* this even if the filesystem has been forcibly unmounted.
* For most servers, it's probably wasted effort, but
* RFC3530 lets servers require that unlocks exactly match
* the locks that are held.
*/
if (resend_rqstp != NULL &&
} else {
}
} else if (locku_args) {
/* Update the stateid with the server's response */
} else if (lockt_args) {
/* Switch the lock type to express success, see fcntl */
}
}
/*
* Do final cleanup before exiting nfs4frlock.
* Calls nfs4_end_fop, drops the seqid syncs, and frees up the
*/
static void
{
int do_flush_pages = 0;
/*
* The client recovery code wants the raw status information,
* so don't map the NFS status code to an errno value for
* non-normal call types.
*/
if (ctype == NFS4_LCK_CTYPE_NORM) {
if (did_start_fop == TRUE)
/*
* We've established a new lock on the server, so invalidate
* the pages associated with the vnode to get the most up to
* date pages from the server after acquiring the lock. We
* want to be sure that the read operation gets the newest data.
* N.B.
* We used to do this in nfs4frlock_results_ok but that doesn't
* work since VOP_PUTPAGE can call nfs4_commit which calls
* nfs4_start_fop. We flush the pages below after calling
* nfs4_end_fop above
* The flush of the page cache must be done after
* nfs4_end_open_seqid_sync() to avoid a 4-way hang.
*/
do_flush_pages = 1;
}
if (argsp) {
if (resp)
}
/* free the reference on the lock owner */
}
/* need to free up the reference on osp for lock args */
/* need to free up the reference on oop for lock args */
}
if (do_flush_pages)
/*
* Record debug information in the event we get EINVAL.
*/
"%s operation failed with "
"EINVAL probably since the server, %s,"
" doesn't support POSIX style locking",
}
}
if (cred_otw)
}
/*
* This calls the server and the local locking code.
*
* Client locks are registerred locally by oring the sysid with
* LM_SYSID_CLIENT. The server registers locks locally using just the sysid.
* We need to distinguish between the two to avoid collision in case one
* machine is used as both client and server.
*
* Blocking lock requests will continually retry to acquire the lock
* forever.
*
* The ctype is defined as follows:
* NFS4_LCK_CTYPE_NORM: normal lock request.
*
* NFS4_LCK_CTYPE_RECLAIM: bypass the usual calls for synchronizing with client
* recovery, get the pid from flk instead of curproc, and don't reregister
* the lock locally.
*
* NFS4_LCK_CTYPE_RESEND: same as NFS4_LCK_CTYPE_RECLAIM, with the addition
* that we will use the information passed in via resend_rqstp to setup the
* lock', and is initiated by the recovery framework. A successful resend
* request can initiate one or more reinstate requests.
*
* NFS4_LCK_CTYPE_REINSTATE: same as NFS4_LCK_CTYPE_RESEND, except that it
* does not trigger additional reinstate requests. This lock call type is
* set for setting the v4 server's locking state back to match what the
* client's local locking state is in the event of a received 'lost lock'.
*
* Errors are returned via the nfs4_error_t parameter.
*/
void
{
short whence;
int frc_no_reclaim = 0;
#ifdef DEBUG
char *name;
#endif
#ifdef DEBUG
#endif
return;
return;
&did_start_fop, &recovonly);
goto out;
if (recovonly) {
/*
* Leave the request for the recovery system to deal with.
*/
(void) nfs4_start_recovery(ep,
}
goto out;
}
/* putfh directory fh */
/*
* Set up the over-the-wire arguments and get references to the
* open owner, etc.
*/
if (ctype == NFS4_LCK_CTYPE_RESEND ||
} else {
switch (cmd) {
case F_GETLK:
case F_O_GETLK:
break;
case F_SETLKW:
case F_SETLK:
&skip_get_err, &go_otw);
else
goto out;
case NFS4_OK:
break;
case NFS4ERR_DELAY:
/* recov thread never gets this error */
goto recov_retry;
default:
goto out;
}
break;
default:
"nfs4_frlock: invalid cmd %d", cmd));
goto out;
}
if (!go_otw)
goto out;
}
/* XXX should we use the local reclock as a cache ? */
/*
* Unregister the lock with the local locking code before
* contacting the server. This avoids a potential race where
* another process gets notified that it has been granted a lock
* before we can unregister ourselves locally.
*/
if (ctype == NFS4_LCK_CTYPE_NORM)
}
/*
* Send the server the lock request. Continually loop with a delay
* if get error NFS4ERR_DENIED (for blocking locks) or NFS4ERR_GRACE.
*/
(CE_NOTE,
rnode4info(rp)));
if (lock_args && frc_no_reclaim) {
"nfs4frlock: frc_no_reclaim: clearing reclaim"));
if (did_reclaimp)
*did_reclaimp = 0;
}
/*
* Do the OTW call.
*/
"nfs4frlock: needrecov %d", needrecov));
/*
* Check if one of these mutually exclusive error cases has
* happened:
* need to swap credentials due to access error
* recovery is needed
* different error (only known case is missing Kerberos ticket)
*/
goto recov_retry;
}
if (needrecov) {
/*
* LOCKT requests don't need to recover from lost
*/
goto out;
/*
* Do not attempt recovery for requests initiated by
* the recovery framework. Let the framework redrive them.
*/
if (ctype != NFS4_LCK_CTYPE_NORM)
goto out;
else {
}
if (retry) {
goto recov_retry;
}
goto out;
}
/*
* Bail out if have reached this point with ep->error set. Can
* happen if (ep->error == EACCES && !needrecov && cred_otw == cr).
* This happens if Kerberos ticket has expired or has been
* destroyed.
*/
goto out;
/*
* Process the reply.
*/
case NFS4_OK:
/*
* Have a successful lock operation, now update state.
*/
break;
case NFS4ERR_DENIED:
if (retry) {
goto recov_retry;
}
break;
/*
* If the server won't let us reclaim, fall-back to trying to lock
* the file from scratch. Code elsewhere will check the changeinfo
* to ensure the file hasn't been changed.
*/
case NFS4ERR_NO_GRACE:
"nfs4frlock: reclaim: NFS4ERR_NO_GRACE"));
frc_no_reclaim = 1;
/* clean up before retrying */
needrecov = 0;
goto recov_retry;
}
/* FALLTHROUGH */
default:
break;
}
out:
/*
* Process and cleanup from error. Make interrupted unlock
* requests look successful, since they will be handled by the
* client recovery code.
*/
}
/*
* nfs4_safelock:
*
* Return non-zero if the given lock request can be handled without
* violating the constraints on concurrent mapping and locking.
*/
static int
{
int error;
return (1); /* always safe if not mapped */
/*
* If the file is already mapped and there are locks, then they
* should be all safe locks. So adding or removing a lock is safe
* as long as the new request is safe (i.e., whole-file, meaning
* length and starting offset are both zero).
*/
"cannot lock a memory mapped file unless locking the "
return (0);
}
/* mandatory locking and mapping don't mix */
if (error != 0) {
"getattr error %d", error));
return (0); /* treat errors conservatively */
}
"cannot mandatory lock and mmap a file"));
return (0);
}
return (1);
}
/*
* Register the lock locally within Solaris.
* As the client, we "or" the sysid with LM_SYSID_CLIENT when
* recording locks locally.
*
* This should handle conflicts/cooperation with NFS v2/v3 since all locks
* are registered locally.
*/
void
{
int oldsysid;
int error;
#ifdef DEBUG
char *name;
#endif
#ifdef DEBUG
(CE_NOTE, "nfs4_register_lock_locally: %s: type %d, "
#endif
/* register the lock with local locking */
#ifdef DEBUG
if (error != 0) {
"nfs4_register_lock_locally: could not register with"
" local locking"));
"error %d, vp 0x%p, pid %d, sysid 0x%x",
"blocked by pid %d sysid 0x%x type %d "
}
#endif
}
/*
* nfs4_lockrelease:
*
* Release any locks on the given vnode that are held by the current
* process. Also removes the lock owner (if one exists) from the rnode's
* list.
*/
static int
{
/*
* If we have not locked anything then we can
* just return since we have no work to do.
*/
return (0);
}
/*
* We need to comprehend that another thread may
* kick off recovery and the lock_owner we have stashed
* in lop might be invalid so we should NOT cache it
* locally!
*/
recov_state.rs_flags = 0;
&recovonly);
if (error) {
return (error);
}
/*
* Check if the lock owner might have a lock (request was sent but
* no response was received). Also check if there are any remote
* locks on the file. (In theory we shouldn't have to make this
* second check if there's no lock owner, but for now we'll be
* conservative and do it anyway.) If either condition is true,
* send an unlock for the entire file to the server.
*
* Note that no explicit synchronization is needed here. At worst,
* flk_has_remote_locks() will return a false positive, in which case
* the unlock call wastes time but doesn't harm correctness.
*/
if (lop) {
}
"nfs4_lockrelease: possible orphan %d, remote locks %d, for "
(void *)lop));
if (ret != 0) {
/*
* If VOP_FRLOCK fails, make sure we unregister
* local locks before we continue.
*/
"nfs4_lockrelease: lock release error on vp"
}
}
recov_state.rs_flags = 0;
&recovonly);
if (error) {
return (error);
}
/*
* So, here we're going to need to retrieve the lock-owner
* again (in case recovery has done a switch-a-roo) and
* remove it because we can.
*/
if (lop) {
}
return (0);
}
/*
* Wait for 'tick_delay' clock ticks.
* Implement exponential backoff until hit the lease_time of this nfs4_server.
* NOTE: lock_lease_time is in seconds.
*
* XXX For future improvements, should implement a waiting queue scheme.
*/
static int
{
long milliseconds_delay;
/* wait tick_delay clock ticks or siginteruptus */
if (delay_sig(*tick_delay)) {
return (EINTR);
}
"reissue the lock request: blocked for %ld clock ticks: %ld "
/* get the lease time */
/* drv_hztousec converts ticks to microseconds */
}
return (0);
}
void
nfs4_vnops_init(void)
{
}
void
nfs4_vnops_fini(void)
{
}
/*
* Return a reference to the directory (parent) vnode for a given vnode,
* using the saved pathname information and the directory file handle. The
* caller is responsible for disposing of the reference.
* Returns zero or an errno value.
*
* Caller should set need_start_op to FALSE if it is the recovery
* thread, or if a start_fop has already been done. Otherwise, TRUE.
*/
int
{
int error;
return (0);
}
"shadow node is NULL"));
return (EINVAL);
}
"shadow node name or dfh val == NULL"));
return (EINVAL);
}
(int)need_start_op);
if (error != 0) {
"nfs4_make_dotdot returned %d", error));
return (error);
}
if (!dvp) {
"nfs4_make_dotdot returned a NULL dvp"));
return (EIO);
}
}
return (0);
}
/*
* Copy the (final) component name of vp to fnamep. maxlen is the maximum
* length that fnamep can accept, including the trailing null.
* Returns 0 if okay, returns an errno value if there was a problem.
*/
int
{
char *fn;
int err = 0;
/*
* If the file being opened has VROOT set, then this is
* a "file" mount. sv_name will not be interesting, so
* go back to the servinfo4 to get the original mount
* path and strip off all but the final edge. Otherwise
* just return the name from the shadow vnode.
*/
else
fn++;
} else {
}
if (err == 0)
else
err = ENAMETOOLONG;
else
return (err);
}
/*
* Bookkeeping for a close that doesn't need to go over the wire.
* *have_lockp is set to 0 if 'os_sync_lock' is released; otherwise
* it is left at 1.
*/
void
{
ASSERT(*have_lockp);
return;
}
/*
* This removes the reference obtained at OPEN; ie,
* when the open stream structure was created.
*
* We don't have to worry about calling 'open_stream_rele'
* since we our currently holding a reference to this
* open stream which means the count can not go to 0 with
* this decrement.
*/
osp->os_ref_count--;
*have_lockp = 0;
}
/*
* Close all remaining open streams on the rnode. These open streams
* could be here because:
* - The close attempted at either close or delmap failed
* - Some kernel entity did VOP_OPEN but never did VOP_CLOSE
* - Someone did mknod on a regular file but never opened it
*/
int
{
int error;
error = 0;
/*
* At this point, all we know is that the last time
* someone called vn_rele, the count was 1. Since then,
* the vnode could have been re-activated. We want to
* loop through the open streams and close each one, but
* we have to be careful since once we release the rnode
* hash bucket lock, someone else is free to come in and
* re-activate the rnode and add new open streams. The
* strategy is take the rnode hash bucket lock, verify that
* the count is still 1, grab the open stream off the
* head of the list and mark it invalid, then release the
* rnode hash bucket lock and proceed with that open stream.
* This is ok because nfs4close_one() will acquire the proper
* streams, and will ensure that if someone has reopened
* the open stream after we've dropped the hash bucket lock
* then we'll just simply return without destroying the
* open stream.
* Repeat until the list is empty.
*/
for (;;) {
/* make sure vnode hasn't been reactivated */
break;
}
/*
* Grabbing r_os_lock before releasing v_lock prevents
* reactivated (and os_force_close set to 0) before we
* had a chance to set os_force_close to 1.
*/
if (!osp) {
/* nothing left to CLOSE OTW, so return */
break;
}
/* the file can't still be mem mapped */
if (rp->created_v4)
rp->created_v4 = 0;
/*
* Grab a ref on this open stream; nfs4close_one
* will mark it as invalid
*/
osp->os_ref_count++;
/* Update error if it isn't already non-zero */
if (error == 0) {
if (e.error)
else if (e.stat)
}
#ifdef DEBUG
#endif
/* Release the ref on osp acquired above. */
/* Proceed to the next open stream, if any */
}
return (error);
}
/*
* nfs4close_one - close one open stream for a file if needed.
*
* "close_type" indicates which close path this is:
* CLOSE_NORM: close initiated via VOP_CLOSE.
* CLOSE_DELMAP: close initiated via VOP_DELMAP.
* CLOSE_FORCE: close initiated via VOP_INACTIVE. This path forces
* the close and release of client state for this open stream
* (unless someone else has the open stream open).
* CLOSE_RESEND: indicates the request is a replay of an earlier request
* (e.g., due to abort because of a signal).
* CLOSE_AFTER_RESEND: close initiated to "undo" a successful resent OPEN.
*
* CLOSE_RESEND and CLOSE_AFTER_RESEND will not attempt to retry after client
* recovery. Instead, the caller is expected to deal with retries.
*
* The caller can either pass in the osp ('provided_osp') or not.
*
* 'access_bits' represents the access we are closing/downgrading.
*
* 'len', 'prot', and 'mmap_flags' are used for CLOSE_DELMAP. 'len' is the
* number of bytes we are unmapping, 'maxprot' is the mmap protection, and
* 'mmap_flags' tells us the type of sharing (MAP_PRIVATE or MAP_SHARED).
*
* Errors are returned via the nfs4_error_t.
*/
void
{
int retry = 0;
int isrecov;
int force_close;
int close_failed = 0;
int did_dec_count = 0;
int did_start_op = 0;
int did_force_recovlock = 0;
int did_start_seqid_sync = 0;
int have_sync_lock = 0;
"lrp %p, close type %d len %ld prot %x mmap flags %x bits %x",
/*
* First get the open owner.
*/
if (!provided_osp) {
} else {
}
if (!oop) {
"nfs4close_one: no oop, rp %p, mi %p, cr %p, osp %p, "
(void *)provided_osp, close_type));
goto out;
}
close_failed = 0;
retry = 0;
did_start_op = 0;
did_force_recovlock = 0;
did_start_seqid_sync = 0;
have_sync_lock = 0;
recov_state.rs_flags = 0;
/*
* Second synchronize with recovery.
*/
if (!isrecov) {
&recov_state, &recovonly);
did_start_op = 1;
} else {
close_failed = 1;
/*
* If we couldn't get start_fop, but have to
* cleanup state, then at least acquire the
* mi_recovlock so we can synchronize with
* recovery.
*/
if (close_type == CLOSE_FORCE) {
did_force_recovlock = 1;
} else
goto out;
}
}
/*
* We cannot attempt to get the open seqid sync if nfs4_start_fop
* set 'recovonly' to TRUE since most likely this is due to
* reovery being active (MI4_RECOV_ACTIV). If recovery is active,
* nfs4_start_open_seqid_sync() will fail with EAGAIN asking us
* to retry, causing us to loop until recovery finishes. Plus we
* don't need protection over the open seqid since we're not going
* OTW, hence don't need to use the seqid.
*/
/* need to grab the open owner sync before 'os_sync_lock' */
if (did_start_op)
&recov_state, TRUE);
if (did_force_recovlock)
goto recov_retry;
}
did_start_seqid_sync = 1;
}
/*
* Third get an open stream and acquire 'os_sync_lock' to
* closing/destroying of an open stream.
*/
if (!provided_osp) {
/* returns with 'os_sync_lock' held */
if (!osp) {
goto out;
}
} else {
osp = provided_osp;
}
have_sync_lock = 1;
/*
* Fourth, do any special pre-OTW CLOSE processing
* based on the specific close type.
*/
!did_dec_count) {
osp->os_open_ref_count--;
did_dec_count = 1;
if (osp->os_open_ref_count == 0)
}
if (close_type == CLOSE_FORCE) {
/* see if somebody reopened the open stream. */
if (!osp->os_force_close) {
"nfs4close_one: skip CLOSE_FORCE as osp %p "
goto out;
}
osp->os_open_ref_count--;
did_dec_count = 1;
}
/*
* We can't depend on os_open_ref_count being 0 due to the
* way executables are opened (VN_RELE to match a VOP_OPEN).
*/
#ifdef NOTYET
#endif
if (osp->os_open_ref_count != 0) {
"nfs4close_one: should panic here on an "
"ASSERT(osp->os_open_ref_count == 0). Ignoring "
"since this is probably the exec problem."));
osp->os_open_ref_count = 0;
}
/*
* There is the possibility that nfs4close_one()
* for close_type == CLOSE_DELMAP couldn't find the
* open stream, thus couldn't decrement its os_mapcnt;
* therefore we can't use this ASSERT yet.
*/
#ifdef NOTYET
#endif
}
/* mirror the PROT_NONE check in nfs4_addmap() */
did_dec_count = 1;
}
if (recovonly) {
/* request should not already be in recovery queue */
have_sync_lock = 0;
close_failed = 1;
force_close = 0;
goto close_cleanup;
}
/*
* If a previous OTW call got NFS4ERR_BAD_SEQID, then
* we stopped operating on the open owner's <old oo_name, old seqid>
* space, which means we stopped operating on the open stream
* too. So don't go OTW (as the seqid is likely bad, and the
* stateid could be stale, potentially triggering a false
* setclientid), and just clean up the client's internal state.
*/
(CE_NOTE, "nfs4close_one: skip OTW close for osp %p "
close_failed = 1;
}
/* If the file failed recovery, just quit. */
close_failed = 1;
}
/*
* If the force close path failed to obtain start_fop
* then skip the OTW close and just remove the state.
*/
if (close_failed)
goto close_cleanup;
/*
* Fifth, check to see if there are still mapped pages or other
* opens using this open stream. If there are then we can't
* close yet but we can see if an OPEN_DOWNGRADE is necessary.
*/
if (osp->os_delegation) {
/*
* If this open stream was never OPENed OTW then we
* surely can't DOWNGRADE it (especially since the
* osp->open_stateid is really a delegation stateid
* when os_delegation is 1).
*/
if (access_bits & FREAD)
osp->os_share_acc_read--;
if (access_bits & FWRITE)
goto out;
}
vp, 0,
have_sync_lock = 0;
if (odg_cred_otw)
if (bsep)
goto out;
if (did_start_seqid_sync) {
did_start_seqid_sync = 0;
}
if (did_start_op)
&recov_state, FALSE);
if (did_force_recovlock)
goto recov_retry;
} else {
if (odg_cred_otw)
}
goto out;
}
/*
* If this open stream was created as the results of an open
* while holding a delegation, then just release it; no need
* to do an OTW close. Otherwise do a "normal" OTW close.
*/
if (osp->os_delegation) {
goto out;
}
/*
* If this stream is not valid, we're done.
*/
goto out;
}
/*
* Last open or mmap ref has vanished, need to do an OTW close.
* First check to see if a close is still necessary.
*/
if (osp->os_failed_reopen) {
"don't close OTW osp %p since reopen failed.",
(void *)osp));
/*
* Reopen of the open stream failed, hence the
* sending this OTW would incorrectly cause another
* round of recovery. In this case, we need to set
* the 'os_valid' bit to 0 so another thread doesn't
* come in and re-open this open stream before
* this "closing" thread cleans up state (decrementing
* the nfs4_server_t's state_ref_count and decrementing
* the os_ref_count).
*/
/*
* This removes the reference obtained at OPEN; ie,
* when the open stream structure was created.
*
* We don't have to worry about calling 'open_stream_rele'
* since we our currently holding a reference to this
* open stream which means the count can not go to 0 with
* this decrement.
*/
osp->os_ref_count--;
close_failed = 0;
goto close_cleanup;
}
/*
* Sixth, try the CLOSE OTW.
*/
/*
* Let the recovery thread be responsible for
* removing the state for CLOSE.
*/
close_failed = 1;
force_close = 0;
retry = 0;
}
/* See if we need to retry with a different cred */
retry = 1;
}
close_failed = 1;
if (have_sync_lock) {
have_sync_lock = 0;
}
if (did_start_seqid_sync) {
did_start_seqid_sync = 0;
}
if (did_start_op)
&recov_state, FALSE);
if (did_force_recovlock)
"nfs4close_one: need to retry the close "
"operation"));
goto recov_retry;
}
/*
* Seventh and lastly, process our results.
*/
if (close_failed && force_close) {
/*
* It's ok to drop and regrab the 'os_sync_lock' since
* nfs4close_notw() will recheck to make sure the
* "close"/removal of state should happen.
*/
if (!have_sync_lock) {
have_sync_lock = 1;
}
/*
* This is last call, remove the ref on the open
* stream created by open and clean everything up.
*/
osp->os_pending_close = 0;
}
if (!close_failed) {
if (have_sync_lock) {
osp->os_pending_close = 0;
have_sync_lock = 0;
} else {
osp->os_pending_close = 0;
}
} else {
}
}
out:
if (have_sync_lock)
if (did_start_op)
if (did_force_recovlock)
if (cred_otw)
if (osp)
if (oop) {
if (did_start_seqid_sync)
}
}
/*
* Convert information returned by the server in the LOCK4denied
* structure to the form required by fcntl.
*/
static void
{
#ifdef DEBUG
if (denied_to_flk_debug) {
debug_enter("lockt_denied");
}
#endif
/*
* If the blocking clientid matches our client id, then we can
* interpret the lockowner (since we built it). If not, then
* fabricate a sysid and pid. Note that the l_sysid field
* in *flk already has the local sysid.
*/
lo = (nfs4_lo_name_t *)
} else {
"denied_to_flk: bad lock owner length\n"));
}
} else {
"denied_to_flk: foreign clientid\n"));
/*
* Construct a new sysid which should be different from
* sysids of other systems.
*/
}
}
static pid_t
{
int i;
return (pid);
}
/*
* Given a lock pointer, returns the length of that lock.
* "end" is the last locked offset the "l_len" covers from
* the start of the lock.
*/
static off64_t
{
else
return (lock_end);
}
/*
* Given the end of a lock, it will return you the length "l_len" for that lock.
*/
static off64_t
{
lock_len = 0;
else
return (lock_len);
}
/*
* On given end for a lock it determines if it is the last locked offset
* or not, if so keeps it as is, else adds one to return the length for
* valid start.
*/
static off64_t
{
if (x == MAXEND)
return (x);
else
return (x + 1);
}
/*
* See if these two locks overlap, and if so return 1;
* otherwise, return 0.
*/
static int
{
return (1);
return (0);
}
/*
* Determine what the intersecting lock region is, and add that to the
* 'nl_llpp' locklist in increasing order (by l_start).
*/
static void
{
return;
"locks intersect"));
/* Find the starting point of the intersecting region */
else
/* Find the lenght of the intersecting region */
if (lost_flp_end < local_flp_end)
else
/*
* Prepare the flock structure for the intersection found and insert
* it into the new list in increasing l_start order. This list contains
* intersections of locks registered by the client with the local host
* and the lost lock.
* The lock type of this lock is the same as that of the local_flp.
*/
}
/* first on the list */
*nl_llpp = intersect_llp;
} else {
}
}
/*
* Our local locking current state is potentially different than
* what the NFSv4 server thinks we have due to a lost lock that was
* resent and then received. We need to reset our "NFSv4" locking
* state to match the current local locking state for this pid since
* that is what the user/application sees as what the world is.
*
* get confused about what the current local locking state "is" versus
* "was".
*
* If we are unable to fix up the locks, we send SIGLOST to the affected
* process. This is not done if the filesystem has been forcibly
* unmounted, in case the process has already exited and a new process
* exists with the same pid.
*/
static void
{
"nfs4_reinstitute_local_lock_state"));
/*
* Find active locks for this vp from the local locking code.
* Scan through this list and find out the locks that intersect with
* the lost lock. Once we find the lock that intersects, add the
* intersection area as a new lock to a new list "ri_llp". The lock
* type of the intersection region lock added to ri_llp is the same
* as that found in the active lock list, "list". The intersecting
* region locks are added to ri_llp in increasing l_start order.
*/
/*
*/
continue;
}
/*
* Now we have the list of intersections with the lost lock. These are
* locks to the server will re-establish aur current local locking state
* with the v4 server.
* If we get an error, send SIGLOST to the application for that lock.
*/
"nfs4_reinstitute_local_lock_state: need to issue "
/*
* No need to relock what we already have
*/
continue;
}
/*
* Now keeping the start of the lost lock as our reference parse the
* newly created ri_llp locklist to find the ranges that we have locked
* with the v4 server but not in the current local locking. We need
* to unlock these ranges.
* These ranges can also be reffered to as those ranges, where the lost
* lock does not overlap with the locks in the ri_llp but are locked
* since the server replied to the lost lock.
*/
continue;
}
"nfs4_reinstitute_local_lock_state: "
}
/*
* In the case where the lost lock ends after all intersecting locks,
* unlock the last part of the lost lock range.
*/
"nfs4_reinstitute_local_lock_state: UNLOCK end of the "
/*
* Is it an to-EOF lock? if so unlock till the end
*/
else
}
/* Free up our newly created locklist */
}
/*
* Now return back to the original calling nfs4frlock()
* and let us naturally drop our seqid syncs.
*/
}
/*
* Create a lost state record for the given lock reinstantiation request
* and push it onto the lost state queue.
*/
static void
{
}