specvnops.c revision 0dee76a02c909ef7d86455424e4750bc87dcf532
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/sysmacros.h>
#include <sys/devpolicy.h>
#include <sys/pathname.h>
#include <sys/autoconf.h>
struct caller_context *);
struct caller_context *);
caller_context_t *);
struct flk_callback *, struct cred *);
struct cred *);
int);
cred_t *);
}
}
struct vnodeops *spec_vnodeops;
const fs_operation_def_t spec_vnodeops_template[] = {
};
/*
* Return address of spec_vnodeops
*/
struct vnodeops *
spec_getvnodeops(void)
{
return (spec_vnodeops);
}
/*
* Acquire the serial lock on the common snode.
*/
} \
/*
* Acquire the serial lock on the common snode checking for a signal.
* cv_wait_sig is used to allow signals to pull us out.
* Return 1 if locked, 0 if interrupted
*/
static int
{
/* interrupted */
return (0);
}
}
return (1);
}
/*
* Unlock the serial lock on the common snode
*/
#define UNLOCK_CSP_LOCK_HELD(csp) \
#define UNLOCK_CSP(csp) \
/*
*/
/*
* Compute and return the size. If the size in the common snode is valid then
* return it. If not valid then get the size from the driver and set size in
* the common snode. If the device has not been attached then we don't ask for
* an update from the driver- for non-streams SSIZEVALID stays unset until the
* device is attached. A stat of a mknod outside /devices (non-devfs) may
* report UNKNOWN_SIZE because the device may not be attached yet (SDIPSET not
* established in mknod until open time). An stat in /devices will report the
* size correctly. Specfs should always call SPEC_SIZE instead of referring
* directly to s_size to initialize/retrieve the size of a device.
*
* XXX There is an inconsistency between block and raw - "unknown" is
* UNKNOWN_SIZE for VBLK and 0 for VCHR(raw).
*/
static u_offset_t
{
int plen;
/* return cached value */
}
/* VOP_GETATTR of mknod has not had devcnt restriction applied */
/* return non-cached UNKNOWN_SIZE */
}
/* establish cached zero size for streams */
if (STREAMSTAB(maj)) {
return (0);
}
/*
* Return non-cached UNKNOWN_SIZE if not open.
*
* NB: This check is bogus, calling prop_op(9E) should be gated by
* attach, not open. Not having this check however opens up a new
* context under which a driver's prop_op(9E) could be called. Calling
* prop_op(9E) in this new context has been shown to expose latent
* driver bugs (insufficient NULL pointer checks that lead to panic).
* We are keeping this open check for now to avoid these panics.
*/
}
/* Return non-cached UNKNOWN_SIZE if not attached. */
}
/*
* Established cached size obtained from the attached driver. Since we
* know the devinfo node, for efficiency we use cdev_prop_op directly
* instead of [cb]dev_[Ss]size.
*/
size = 0;
&plen) != DDI_PROP_SUCCESS) {
}
} else {
size = UNKNOWN_SIZE;
&plen) != DDI_PROP_SUCCESS) {
}
if (size != UNKNOWN_SIZE) {
/* convert from block size to byte size */
else
size = UNKNOWN_SIZE;
}
}
return (size);
}
/*
* This function deal with vnode substitution in the case of
* device cloning.
*/
static int
{
int qassociate_used = 0;
/*
* Check for cloning across different drivers.
* We only support this under the system provided clone driver
*/
"unsupported clone open maj = %u, newmaj = %u",
return (ENXIO);
}
/* old */
/* new */
/*
* Clones inherit fsid, realvp, and dip.
* XXX realvp inherit is not occurring, does fstat of clone work?
*/
if (sysclone) {
} else {
}
/*
* If we cloned to an opened newdev that already has called
* spec_assoc_vp_with_devi (SDIPSET set) then the association is
* already established.
*/
/*
* Establish s_dip association for newdev.
*
* If we trusted the getinfo(9E) DDI_INFO_DEVT2INSTANCE
* implementation of all cloning drivers (SCLONE and SELFCLONE)
* we would always use e_ddi_hold_devi_by_dev(). We know that
* many drivers have had (still have?) problems with
* DDI_INFO_DEVT2INSTANCE, so we try to minimize reliance by
* detecting drivers that use QASSOCIATE (by looking down the
* stream) and setting their s_dip association to NULL.
*/
qassociate_used = 0;
if (stp) {
qassociate_used = 1;
break;
}
}
}
if (dip || qassociate_used) {
} else {
/* derive association from newdev */
if (dip)
}
}
/* deal with stream stuff */
}
/* substitute the vnode */
return (0);
}
static int
{
return (ENXIO);
/*
* If the VFS_NODEVICES bit was set for the mount,
* do not allow opens of special devices.
*/
return (ENXIO);
/*
* If we are opening a node that has not had spec_assoc_vp_with_devi
* called against it (mknod outside /devices or a non-dacf makespecvp
* node) then SDIPSET will not be set. In this case we call an
* interface which will reconstruct the path and lookup (drive attach)
* through devfs (e_ddi_hold_devi_by_dev -> e_ddi_hold_devi_by_path ->
* devfs_lookupname). For support of broken drivers that don't call
* ddi_create_minor_node for all minor nodes in their instance space,
* After finding and attaching the dip we associate it with the
* common specfs vnode (s_dip), which sets SDIPSET. A DL_DETACH_REQ
* to style-2 stream driver may set s_dip to NULL with SDIPSET set.
*
* NOTE: Although e_ddi_hold_devi_by_dev takes a dev_t argument, its
* need to return a dip.
*/
/* try to attach, return error if we fail */
return (ENXIO);
/* associate dip with the common snode s_dip */
}
#ifdef DEBUG
#endif /* DEBUG */
return (error);
if (STREAMSTAB(maj))
goto streams_open;
/* non streams open */
/* deal with clone case */
/*
* bail on clone failure, further processing
* results in undefined behaviors.
*/
if (error != 0)
return (error);
}
if (error == 0) {
/* successful open needs a close later */
/*
* Invalidate possible cached "unknown" size
* established by a VOP_GETATTR while open was in
* progress, and the driver might fail prop_op(9E).
*/
}
return (0);
}
/*
* Open failed. If we missed a close operation because
* we were trying to get the device open and it is the
* last in progress open that is failing then call close.
*
* NOTE: Only non-streams open has this race condition.
*/
/* See comment in spec_close() */
} else {
}
return (error);
return (ENXIO);
}
/*
* Lock common snode to prevent any new clone opens
* on this stream while one is in progress.
* This is necessary since the stream currently
* associated with the clone device will not be part
* of it after the clone open completes.
* Unfortunately we don't know in advance if this is
* a clone device so we have to lock all opens.
*
* If we fail, it's because of an interrupt.
*/
if (LOCK_CSP_SIG(csp) == 0) {
return (EINTR);
}
/* deal with the clone case */
/*
* bail on clone failure, further processing
* results in undefined behaviors.
*/
if (error != 0)
return (error);
} else if (error == 0) {
}
if (error == 0) {
/* STREAMS devices don't have a size */
/*
* try to allocate it as a controlling terminal
*/
}
return (0);
}
/*
* Deal with stropen failure.
*
* sd_flag in the stream head cannot change since the
* common snode is locked before the call to stropen().
*/
/*
* Open failed part way through.
*/
} else {
}
return (error);
}
/*ARGSUSED2*/
static int
int flag,
int count,
{
int error = 0;
int sysclone;
/* this only applies to closes of devices from userland */
}
if (count > 1)
return (0);
/*
* on this common snode. Clone opens are held up until after
* we have closed this device so the streams linkage is maintained
*/
/*
* Invalidate size on each close.
*
* XXX We do this on each close because we don't have interfaces that
* allow a driver to invalidate the size. Since clearing this on each
*/
/*
* Only call the close routine when the last open reference through
* any [s, v]node goes away. This can be checked by looking at
* s_count on the common vnode.
*/
/* we don't need a close */
/*
* A cloning driver may open-clone to the same dev_t that we
* are closing before spec_inactive destroys the common snode.
* If this occurs the s_dip association needs to be reevaluated.
* We clear SDIPSET to force reevaluation in this case. When
* reevaluation occurs (by spec_clone after open), if the
* devinfo association has changed then the old association
* will be released as the new association is established by
* spec_assoc_vp_with_devi().
*/
/*
* Decrement the devops held in clnopen()
*/
if (sysclone) {
}
}
return (error);
}
/*ARGSUSED2*/
static int
int ioflag,
struct caller_context *ct)
{
int error;
size_t n;
}
return (0);
/*
* Plain old character devices that set D_U64BIT can have
* unrestricted offsets.
*/
return (EINVAL);
}
/*
* Block device.
*/
error = 0;
do {
if (diff <= 0)
break;
if (diff < n)
int flags = 0;
/*
* If we read a whole block, we won't need this
* buffer again soon.
*/
} else {
if (bdevsize == UNKNOWN_SIZE) {
error = 0;
break;
}
}
return (error);
}
/*ARGSUSED*/
static int
int ioflag,
struct caller_context *ct)
{
int error;
size_t n;
}
/*
* Plain old character devices that set D_U64BIT can have
* unrestricted offsets.
*/
return (EINVAL);
}
return (0);
error = 0;
do {
int pagecreate;
int newpage;
pagecreate = 0;
if (diff <= 0) {
break;
}
if (diff < n)
/*
* Check to see if we can skip reading in the page
* and just allocate the memory. We can do this
* if we are going to rewrite the entire mapping
* or if we are going to write to end of the device
* from the beginning of the mapping.
*/
pagecreate = 1;
/*
* segmap_pagecreate() returns 1 if it calls
* page_create_va() to allocate any pages.
*/
newpage = 0;
if (pagecreate)
n, 0);
if (pagecreate &&
uiop->uio_loffset <
/*
* We created pages w/o initializing them completely,
* thus we need to zero the part that wasn't set up.
* This can happen if we write to the end of the device
* or if we had some sort of error during the uiomove.
*/
long nzero;
panic("spec_write: nmoved bogus");
/*NOTREACHED*/
}
panic("spec_write: nzero bogus");
/*NOTREACHED*/
}
}
/*
* Unlock the pages which have been allocated by
* page_create_va() in segmap_pagecreate().
*/
if (newpage)
if (error == 0) {
int flags = 0;
/*
* Force write back for synchronous write cases.
*/
/*
* Have written a whole block.
* Start an asynchronous write and
* mark the buffer to indicate that
* it won't be needed again soon.
* Push swap files here, since it
* won't happen anywhere else.
*/
}
} else
return (error);
}
static int
int *rvalp)
{
int error;
return (ENOTTY);
} else {
}
return (error);
}
static int
{
int error;
/* With ATTR_COMM we will not get attributes from realvp */
}
static int snode_shift = 0;
/*
* Calculate the amount of bitshift to a snode pointer which
* will still keep it unique. See below.
*/
if (snode_shift == 0)
ASSERT(snode_shift > 0);
/*
* No real vnode behind this one. Fill in the fields
* from the snode.
*
* This code should be refined to return only the
* attributes asked for instead of all of them.
*/
/*
* If the va_nodeid is > MAX_USHORT, then i386 stats might
* fail. So we shift down the snode pointer to try and get
* the most uniqueness into 16-bits.
*/
0xFFFF;
/*
* va_nblocks is the number of 512 byte blocks used to store
* the mknod for the device, not the number of blocks on the
* device itself. This is typically zero since the mknod is
* represented directly in the inode itself.
*/
vap->va_nblocks = 0;
} else {
if (error != 0)
return (error);
}
/* set the size from the snode */
return (0);
}
static int
int flags,
{
int error;
/*
* 1135080: O_TRUNC should have no effect on
* named pipes and terminal devices.
*/
return (0);
}
error = 0; /* no real vnode to update */
else
if (error == 0) {
/*
* If times were changed, update snode.
*/
}
}
return (error);
}
static int
{
else
return (0); /* Allow all access. */
}
/*
* This can be called if creat or an open with O_CREAT is done on the root
* of a lofs mount where the mounted entity is a special file.
*/
/*ARGSUSED*/
static int
{
int error;
return (error);
return (0);
}
return (EEXIST);
}
/*
* In order to sync out the snode times without multi-client problems,
* make sure the times written out are never earlier than the times
* already set in the vnode.
*/
static int
{
/* If times didn't change, don't flush anything. */
return (0);
}
/*
* If no real vnode to update, don't flush anything.
*/
return (0);
else {
}
else {
}
}
return (0);
}
/*ARGSUSED*/
static void
{
/*
* If no one has reclaimed the vnode, remove from the
* cache now.
*/
panic("spec_inactive: Bad v_count");
/*NOTREACHED*/
}
/*
* Drop the temporary hold by vn_rele now
*/
return;
}
/* We are the sole owner of sp now */
if (rvp) {
/*
* If the snode times changed, then update the times
* associated with the "realvp".
*/
/*
* The user may not own the device, but we
* want to update the attributes anyway.
*/
else {
}
else {
}
}
}
}
vn_invalid(vp);
/* if we are sharing another file systems vfs, release it */
/* if we have a realvp, release the realvp */
if (rvp)
/* if we have a common, release the common */
/*
* if we have a hold on a devinfo node (established by
* spec_assoc_vp_with_devi), release the hold
*/
/*
* If we have an associated device policy, release it.
*/
/*
* and we just destroyed the last specfs node associated with the
* device, then the devinfo node reference count should now be
* zero. We can't check this because there may be other holds
* on the node from non file system sources: ddi_hold_devi_by_instance
* for example.
*/
}
static int
{
else
return (EINVAL);
}
/*ARGSUSED1*/
static int
{
return (0);
else
return (EINVAL);
}
static int
int cmd,
int flag,
struct flk_callback *flk_cbp,
{
/*
* If file is being mapped, disallow frlock.
*/
return (EAGAIN);
}
static int
{
}
return (0);
}
/*
* Return all the pages from [off..off + len] in block
* or character device.
*/
static int
{
int err;
/*
* XXX Given the above assertion, this might not do
* what is wanted here.
*/
return (ENOSYS);
"specfs getpage:vp %p off %llx len %ld snode %p",
case VBLK:
return (EFAULT); /* beyond EOF */
else
break;
case VCHR:
"Check any non-ON consolidation drivers");
err = 0;
break;
default:
/*NOTREACHED*/
}
return (err);
}
int spec_ra = 1;
int spec_lostpage; /* number of times we lost original page */
/*ARGSUSED2*/
static int
{
err = 0;
dora = 1;
else
dora = 0;
if (size == UNKNOWN_SIZE) {
dora = 0;
} else {
}
/*
* We're allocating a swap slot and it's
* associated page was not found, so allocate
* and return it.
*/
panic("spec_getapage: page_create");
/*NOTREACHED*/
}
} else {
/*
* Need to really do disk I/O to get the page(s).
*/
if (size == UNKNOWN_SIZE) {
} else {
else
blksz =
}
/*
* Make sure the page didn't sneek into the
* cache while we blocked in pvn_read_kluster.
*/
goto again;
/*
* Zero part of page which we are not
* going to be reading from disk now.
*/
if (xlen != 0)
}
}
/*
* If we are past EOF then don't bother trying
* with read-ahead.
*/
else {
else
}
/*
* Zero part of page which we are not
* going to be reading from disk now.
*/
if (xlen != 0)
}
}
return (err);
if (err) {
return (err);
}
}
if (pagefound) {
/*
* Page exists in the cache, acquire the appropriate
* lock. If this fails, start all over again.
*/
goto reread;
}
return (0);
}
return (0);
}
/*
* Flags are composed of {B_INVAL, B_DIRTY B_FREE, B_DONTNEED, B_FORCE}.
* If len == 0, do from off to EOF.
*
* The normal cases should be len == 0 & off == 0 (entire vp list),
* len == MAXBSIZE (from segmap_release actions), and len == PAGESIZE
* (from pageout).
*/
int
int flags,
{
int err = 0;
return (ENOSYS);
return (0);
"specfs putpage:vp %p off %llx len %ld snode %p",
if (len == 0) {
/*
* Search the entire vp list for pages >= off.
*/
} else {
/*
* Loop over all offsets in the range [off...off + len]
* looking for pages to deal with. We set limits so
* that we kluster to klustsize boundaries.
*/
/*
* If we are not invalidating, synchronously
* freeing or writing pages use the routine
* page_lookup_nowait() to prevent reclaiming
* them from the free list.
*/
} else {
}
else {
if (err != 0)
break;
/*
* "io_off" and "io_len" are returned as
* the range of pages we actually wrote.
* This allows us to skip ahead more quickly
* since several pages may've been dealt
* with by this iteration of the loop.
*/
}
}
}
return (err);
}
/*
* Write out a single page, possibly klustering adjacent
* dirty pages.
*/
/*ARGSUSED5*/
static int
int flags,
{
int err = 0;
/*
* Destroy read ahead value since we are really going to write.
*/
else
/*
* Find a kluster that fits in one contiguous chunk.
*/
/*
* Check for page length rounding problems
* XXX - Is this necessary?
*/
}
/*
* Wait for i/o to complete if the request is not B_ASYNC.
*/
}
if (offp)
if (lenp)
"specfs putapage:vp %p offp %p snode %p err %d",
return (err);
}
/*
* Flags are composed of {B_ASYNC, B_INVAL, B_FREE, B_DONTNEED}
*/
static struct buf *
int flags)
{
(void) bdev_strategy(bp);
else
return (bp);
}
static int
short events,
int anyyet,
short *reventsp,
{
int error;
else {
} else {
}
}
return (error);
}
/*
* This routine is called through the cdevsw[] table to handle
* traditional mmap'able devices that support a d_mmap function.
*/
/*ARGSUSED8*/
int
{
struct segdev_crargs dev_a;
size_t i;
int error;
return (ENODEV);
"specfs segmap:dev %x as %p len %lx prot %x",
/*
* Character devices that support the d_mmap
* interface can only be mmap'ed shared.
*/
return (EINVAL);
/*
* Check to ensure that the entire range is
* legal and we are not trying to map in
* more than the device will let us.
*/
return (ENXIO);
}
/*
* Pick an address w/o worrying about
* any vac alignment constraints.
*/
return (ENOMEM);
}
} else {
/*
* User-specified address; blow away any previous mappings.
*/
}
return (error);
}
int
{
int error = 0;
int map_flag;
/*
* Character device: let the device driver
* pick the appropriate segment driver.
*
* 4.x compat.: allow 'NULL' cb_segmap => spec_segmap
* Kindness: allow 'nulldev' cb_segmap => spec_segmap
*/
/*
* Use old mmap framework if the driver has both mmap
* and devmap entry points. This is to prevent the
* system from calling invalid devmap entry point
* for some drivers that might have put garbage in the
* devmap entry point.
*/
/*
* If driver provides devmap entry point in
* cb_ops but not xx_segmap(9E), call
* devmap_setup with default settings
* (NULL) for callback_ops and driver
* callback private data
*/
return (ENODEV);
return (error);
} else
} else
}
static int
{
int error = 0;
return (ENOSYS);
/*
* If file is locked, fail mapping attempt.
*/
if (vn_has_flocks(vp))
return (EAGAIN);
struct segvn_crargs vn_a;
/*
* Block device, use segvn mapping to the underlying commonvp
* for pages.
*/
return (ENXIO);
return (ENXIO);
return (ENOMEM);
}
} else {
/*
* User-specified address; blow away any
* previous mappings.
*/
}
} else
return (ENODEV);
return (error);
}
/*ARGSUSED1*/
static int
{
int error = 0;
/*
* XXX Given the above assertion, this might not
* be a particularly sensible thing to test.
*/
return (ENOSYS);
return (error);
}
/*ARGSUSED1*/
static int
{
long mcnt;
/* segdev passes us the common vp */
/*
* XXX Given the above assertion, this might not
* be a particularly sensible thing to test..
*/
return (ENOSYS);
if (mcnt == 0) {
/*
* Call the close routine when the last reference of any
* kind through any [s, v]node goes away. The s_dip hold
* on the devinfo node is released when the vnode is
* destroyed.
*/
/* See comment in spec_close() */
} else
}
return (0);
}
static int
{
}
/*
* Flags are composed of:
* {B_ASYNC, B_INVAL, B_FREE, B_DONTNEED, B_READ, B_WRITE}
* If B_ASYNC is not set i/o is waited for.
*/
/*ARGSUSED5*/
static int
int flags,
{
int err = 0;
return (EINVAL);
/*
* Wait for i/o to complete if the request is not B_ASYNC.
*/
}
return (err);
}
/*
* Set ACL on underlying vnode if one exists, or return ENOSYS otherwise.
*/
int
{
int error;
/*
* The acl(2) system calls VOP_RWLOCK on the file before setting an
* ACL, but since specfs does not serialize reads and writes, this
* VOP does not do anything. However, some backing file systems may
* expect the lock to be held before setting an ACL, so it is taken
* here privately to avoid serializing specfs reads and writes.
*/
return (error);
} else
return (fs_nosys());
}
/*
* Get ACL from underlying vnode if one exists, or fabricate it from
* the permissions returned by spec_getattr() otherwise.
*/
int
{
else
}
int
{
else
}