fs_subr.c revision 7b3700d1667b1178db936c8f0864fe50a502417e
/*
* 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) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Generic vnode operations.
*/
#include <acl/acl_common.h>
/*
* Tunable to limit the number of retry to recover from STALE error.
*/
int fs_estale_retry = 5;
/*
* The associated operation is not supported by the file system.
*/
int
fs_nosys()
{
return (ENOSYS);
}
/*
* The associated operation is invalid (on this vnode).
*/
int
fs_inval()
{
return (EINVAL);
}
/*
* The associated operation is valid only for directories.
*/
int
{
return (ENOTDIR);
}
/*
* Free the file system specific resources. For the file systems that
* do not support the forced unmount, it will be a nop function.
*/
/*ARGSUSED*/
void
{
}
/* ARGSUSED */
int
{
return (ENOSYS);
}
/* ARGSUSED */
int
{
return (ENOSYS);
}
/* ARGSUSED */
int
register short events,
int anyyet,
register short *reventsp,
{
return (ENOSYS);
}
/*
* The file system has nothing to sync to disk. However, the
* VFS_SYNC operation must not fail.
*/
/* ARGSUSED */
int
{
return (0);
}
/*
*/
/* ARGSUSED */
int
{
return (-1);
}
/* ARGSUSED */
void
{
}
/*
* Compare two vnodes.
*/
int
{
}
/*
* No-op seek operation.
*/
/* ARGSUSED */
int
{
}
/*
* File and record locking.
*/
/* ARGSUSED */
int
{
int frcmd;
int nlmid;
int error = 0;
int serialize = 0;
switch (cmd) {
case F_GETLK:
case F_O_GETLK:
if (flag & F_REMOTELOCK) {
break;
}
if (flag & F_PXFSLOCK) {
break;
}
frcmd = 0;
break;
case F_SETLK_NBMAND:
/*
* Are NBMAND locks allowed on this file?
*/
goto done;
}
goto done;
}
/*FALLTHROUGH*/
case F_SETLK:
/*
* Check whether there is an NBMAND share reservation that
* conflicts with the lock request.
*/
if (nbl_need_check(vp)) {
serialize = 1;
goto done;
}
}
if (flag & F_REMOTELOCK) {
break;
}
if (flag & F_PXFSLOCK) {
break;
}
if (cmd == F_SETLK_NBMAND &&
/* would check here for conflict with mapped region */
}
break;
case F_SETLKW:
/*
* If there is an NBMAND share reservation that conflicts
* with the lock request, block until the conflicting share
* reservation goes away.
*/
if (nbl_need_check(vp)) {
serialize = 1;
if (error != 0)
goto done;
}
}
if (flag & F_REMOTELOCK) {
break;
}
if (flag & F_PXFSLOCK) {
break;
}
break;
case F_HASREMOTELOCKS:
if (nlmid != 0) { /* booted as a cluster */
} else { /* not booted as a cluster */
}
goto done;
default:
goto done;
}
/*
* If this is a blocking lock request and we're serializing lock
* requests, modify the callback list to leave the critical region
* while we're waiting for the lock.
*/
}
done:
if (serialize)
return (error);
}
/*
* Callback when a lock request blocks and we are serializing requests. If
* before sleeping, leave the critical region. If after wakeup, reenter
* the critical region.
*/
static callb_cpr_t *
{
if (when == FLK_BEFORE_SLEEP)
else {
}
return (NULL);
}
/*
* Allow any flags.
*/
/* ARGSUSED */
int
{
return (0);
}
/*
* Return the answer requested to poll() for non-device files.
* Only POLLIN, POLLRDNORM, and POLLOUT are recognized.
*/
/* ARGSUSED */
int
register short events,
int anyyet,
register short *reventsp,
{
*reventsp = 0;
if (events & POLLRDNORM)
*reventsp |= POLLRDNORM;
if (events & POLLRDBAND)
*reventsp |= POLLRDBAND;
if (events & POLLWRBAND)
*reventsp |= POLLWRBAND;
return (0);
}
/*
* POSIX pathconf() support.
*/
/* ARGSUSED */
int
{
register int error = 0;
switch (cmd) {
case _PC_LINK_MAX:
break;
case _PC_MAX_CANON:
break;
case _PC_MAX_INPUT:
break;
case _PC_NAME_MAX:
break;
break;
case _PC_PATH_MAX:
case _PC_SYMLINK_MAX:
val = MAXPATHLEN;
break;
case _PC_PIPE_BUF:
break;
case _PC_NO_TRUNC:
else
break;
case _PC_VDISABLE:
break;
case _PC_CHOWN_RESTRICTED:
if (rstchown)
else
break;
case _PC_FILESIZEBITS:
/*
* If ever we come here it means that underlying file system
* does not recognise the command and therefore this
* configurable limit cannot be determined. We return -1
* and don't change errno.
*/
break;
case _PC_ACL_ENABLED:
val = 0;
break;
default:
break;
}
if (error == 0)
return (error);
}
/*
* Dispose of a page.
*/
/* ARGSUSED */
void
{
else
}
/* ARGSUSED */
void
{
}
/*
* fabricate acls for file systems that do not support acls.
*/
/* ARGSUSED */
int
int flag;
{
int error;
vsecattr->vsa_aclcnt = 0;
return (error);
if (error || acl_flavor == 0)
if (acl_flavor == _ACL_ACLENT_ENABLED) {
KM_SLEEP);
aclentp++;
aclentp++;
aclentp++;
} else if (acl_flavor == _ACL_ACE_ENABLED) {
KM_SLEEP);
} else
return (EINVAL);
return (0);
}
/*
* Common code for implementing DOS share reservations
*/
/* ARGSUSED4 */
int
{
int error;
/*
* Make sure that the file was opened with permissions appropriate
* for the request, and make sure the caller isn't trying to sneak
* in an NBMAND request.
*/
return (EBADF);
return (EINVAL);
}
if (cmd == F_SHARE_NBMAND) {
/* must have write permission to deny read access */
return (EBADF);
/* make sure nbmand is allowed on the file */
return (EINVAL);
}
return (EINVAL);
}
}
switch (cmd) {
case F_SHARE_NBMAND:
/*FALLTHROUGH*/
case F_SHARE:
break;
case F_UNSHARE:
break;
case F_HASREMOTELOCKS:
/*
* We are overloading this command to refer to remote
* shares as well as remote locks, despite its name.
*/
error = 0;
break;
default:
break;
}
return (error);
}
/*ARGSUSED1*/
int
{
return (ENOTSUP);
}
/*ARGSUSED1*/
int
{
return (0);
}
/*
* return 1 for non-trivial ACL.
*
* NB: It is not necessary for the caller to VOP_RWLOCK since
* we only issue VOP_GETSECATTR.
*
* Returns 0 == trivial
* 1 == NOT Trivial
* <0 could not determine.
*/
int
{
int error;
int isnontrivial;
/* determine the forms of ACLs maintained */
/* clear bits we don't understand and establish default acl_style */
if (error || (acl_styles == 0))
vsecattr.vsa_aclcnt = 0;
vsecattr.vsa_dfaclcnt = 0;
while (acl_styles) {
/* select one of the styles as current flavor */
acl_flavor = 0;
if (acl_styles & _ACL_ACLENT_ENABLED) {
} else if (acl_styles & _ACL_ACE_ENABLED) {
}
if (error == 0)
break;
/* that flavor failed */
acl_styles &= ~acl_flavor;
}
/* if all styles fail then assume trivial */
if (acl_styles == 0)
return (0);
/* process the flavor that worked */
isnontrivial = 0;
if (acl_flavor & _ACL_ACLENT_ENABLED) {
isnontrivial = 1;
}
if (acl_flavor & _ACL_ACE_ENABLED) {
/* ACE has no vsecattr.vsa_dfaclcnt */
}
return (isnontrivial);
}
/*
* Check whether we need a retry to recover from STALE error.
*/
int
{
if (retry_count < fs_estale_retry)
return (1);
else
return (0);
}