Home | History | Annotate | Line # | Download | only in genfs
genfs_vnops.c revision 1.13
      1  1.13  wrstuden /*	$NetBSD: genfs_vnops.c,v 1.13 1999/08/03 20:19:19 wrstuden Exp $	*/
      2   1.6      fvdl 
      3   1.6      fvdl /*
      4   1.6      fvdl  * Copyright (c) 1982, 1986, 1989, 1993
      5   1.6      fvdl  *	The Regents of the University of California.  All rights reserved.
      6   1.6      fvdl  *
      7   1.6      fvdl  * Redistribution and use in source and binary forms, with or without
      8   1.6      fvdl  * modification, are permitted provided that the following conditions
      9   1.6      fvdl  * are met:
     10   1.6      fvdl  * 1. Redistributions of source code must retain the above copyright
     11   1.6      fvdl  *    notice, this list of conditions and the following disclaimer.
     12   1.6      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.6      fvdl  *    notice, this list of conditions and the following disclaimer in the
     14   1.6      fvdl  *    documentation and/or other materials provided with the distribution.
     15   1.6      fvdl  * 3. All advertising materials mentioning features or use of this software
     16   1.6      fvdl  *    must display the following acknowledgement:
     17   1.6      fvdl  *	This product includes software developed by the University of
     18   1.6      fvdl  *	California, Berkeley and its contributors.
     19   1.6      fvdl  * 4. Neither the name of the University nor the names of its contributors
     20   1.6      fvdl  *    may be used to endorse or promote products derived from this software
     21   1.6      fvdl  *    without specific prior written permission.
     22   1.6      fvdl  *
     23   1.6      fvdl  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.6      fvdl  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.6      fvdl  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.6      fvdl  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.6      fvdl  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.6      fvdl  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.6      fvdl  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.6      fvdl  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.6      fvdl  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.6      fvdl  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.6      fvdl  * SUCH DAMAGE.
     34   1.6      fvdl  *
     35   1.6      fvdl  */
     36   1.5     perry 
     37   1.8   thorpej #include "opt_nfsserver.h"
     38   1.8   thorpej 
     39   1.1   mycroft #include <sys/param.h>
     40   1.1   mycroft #include <sys/systm.h>
     41   1.6      fvdl #include <sys/proc.h>
     42   1.1   mycroft #include <sys/kernel.h>
     43   1.1   mycroft #include <sys/mount.h>
     44   1.1   mycroft #include <sys/namei.h>
     45   1.1   mycroft #include <sys/vnode.h>
     46  1.13  wrstuden #include <sys/fcntl.h>
     47   1.1   mycroft #include <sys/malloc.h>
     48   1.3   mycroft #include <sys/poll.h>
     49   1.1   mycroft 
     50   1.1   mycroft #include <miscfs/genfs/genfs.h>
     51   1.6      fvdl #include <miscfs/specfs/specdev.h>
     52   1.1   mycroft 
     53   1.8   thorpej #ifdef NFSSERVER
     54   1.8   thorpej #include <nfs/rpcv2.h>
     55   1.8   thorpej #include <nfs/nfsproto.h>
     56   1.8   thorpej #include <nfs/nfs.h>
     57   1.8   thorpej #include <nfs/nqnfs.h>
     58   1.8   thorpej #include <nfs/nfs_var.h>
     59   1.8   thorpej #endif
     60   1.8   thorpej 
     61   1.1   mycroft int
     62   1.3   mycroft genfs_poll(v)
     63   1.1   mycroft 	void *v;
     64   1.1   mycroft {
     65   1.3   mycroft 	struct vop_poll_args /* {
     66   1.1   mycroft 		struct vnode *a_vp;
     67   1.3   mycroft 		int a_events;
     68   1.1   mycroft 		struct proc *a_p;
     69   1.1   mycroft 	} */ *ap = v;
     70   1.1   mycroft 
     71   1.3   mycroft 	return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
     72   1.1   mycroft }
     73   1.1   mycroft 
     74   1.1   mycroft int
     75   1.1   mycroft genfs_fsync(v)
     76   1.1   mycroft 	void *v;
     77   1.1   mycroft {
     78   1.1   mycroft 	struct vop_fsync_args /* {
     79   1.1   mycroft 		struct vnode *a_vp;
     80   1.1   mycroft 		struct ucred *a_cred;
     81   1.7    kleink 		int a_flags;
     82   1.1   mycroft 		struct proc *a_p;
     83   1.1   mycroft 	} */ *ap = v;
     84   1.1   mycroft 	register struct vnode *vp = ap->a_vp;
     85  1.11   mycroft 	int wait;
     86   1.1   mycroft 
     87  1.11   mycroft 	wait = (ap->a_flags & FSYNC_WAIT) != 0;
     88  1.11   mycroft 	vflushbuf(vp, wait);
     89  1.11   mycroft 	if ((ap->a_flags & FSYNC_DATAONLY) != 0)
     90   1.7    kleink 		return (0);
     91  1.11   mycroft 	else
     92  1.11   mycroft 		return (VOP_UPDATE(ap->a_vp, NULL, NULL, wait));
     93   1.1   mycroft }
     94   1.1   mycroft 
     95   1.1   mycroft int
     96   1.4    kleink genfs_seek(v)
     97   1.4    kleink 	void *v;
     98   1.4    kleink {
     99   1.4    kleink 	struct vop_seek_args /* {
    100   1.4    kleink 		struct vnode *a_vp;
    101   1.4    kleink 		off_t a_oldoff;
    102   1.4    kleink 		off_t a_newoff;
    103   1.4    kleink 		struct ucred *a_ucred;
    104   1.4    kleink 	} */ *ap = v;
    105   1.4    kleink 
    106   1.4    kleink 	if (ap->a_newoff < 0)
    107   1.4    kleink 		return (EINVAL);
    108   1.4    kleink 
    109   1.4    kleink 	return (0);
    110   1.4    kleink }
    111   1.4    kleink 
    112   1.4    kleink int
    113   1.1   mycroft genfs_abortop(v)
    114   1.1   mycroft 	void *v;
    115   1.1   mycroft {
    116   1.1   mycroft 	struct vop_abortop_args /* {
    117   1.1   mycroft 		struct vnode *a_dvp;
    118   1.1   mycroft 		struct componentname *a_cnp;
    119   1.1   mycroft 	} */ *ap = v;
    120   1.1   mycroft 
    121   1.1   mycroft 	if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
    122   1.1   mycroft 		FREE(ap->a_cnp->cn_pnbuf, M_NAMEI);
    123   1.1   mycroft 	return (0);
    124  1.13  wrstuden }
    125  1.13  wrstuden 
    126  1.13  wrstuden int
    127  1.13  wrstuden genfs_fcntl(v)
    128  1.13  wrstuden 	void *v;
    129  1.13  wrstuden {
    130  1.13  wrstuden 	struct vop_fcntl_args /* {
    131  1.13  wrstuden 		struct vnode *a_vp;
    132  1.13  wrstuden 		u_int a_command;
    133  1.13  wrstuden 		caddr_t a_data;
    134  1.13  wrstuden 		int a_fflag;
    135  1.13  wrstuden 		struct ucred *a_cred;
    136  1.13  wrstuden 		struct proc *a_p;
    137  1.13  wrstuden 	} */ *ap = v;
    138  1.13  wrstuden 
    139  1.13  wrstuden 	if (ap->a_command == F_SETFL)
    140  1.13  wrstuden 		return (0);
    141  1.13  wrstuden 	else
    142  1.13  wrstuden 		return (EOPNOTSUPP);
    143   1.1   mycroft }
    144   1.1   mycroft 
    145   1.1   mycroft /*ARGSUSED*/
    146   1.1   mycroft int
    147   1.1   mycroft genfs_badop(v)
    148   1.1   mycroft 	void *v;
    149   1.1   mycroft {
    150   1.1   mycroft 
    151   1.1   mycroft 	panic("genfs: bad op");
    152   1.1   mycroft }
    153   1.1   mycroft 
    154   1.1   mycroft /*ARGSUSED*/
    155   1.1   mycroft int
    156   1.1   mycroft genfs_nullop(v)
    157   1.1   mycroft 	void *v;
    158   1.1   mycroft {
    159   1.1   mycroft 
    160   1.1   mycroft 	return (0);
    161  1.10    kleink }
    162  1.10    kleink 
    163  1.10    kleink /*ARGSUSED*/
    164  1.10    kleink int
    165  1.10    kleink genfs_einval(v)
    166  1.10    kleink 	void *v;
    167  1.10    kleink {
    168  1.10    kleink 
    169  1.10    kleink 	return (EINVAL);
    170   1.1   mycroft }
    171   1.1   mycroft 
    172   1.1   mycroft /*ARGSUSED*/
    173   1.1   mycroft int
    174   1.1   mycroft genfs_eopnotsupp(v)
    175   1.1   mycroft 	void *v;
    176   1.1   mycroft {
    177   1.1   mycroft 
    178   1.1   mycroft 	return (EOPNOTSUPP);
    179   1.1   mycroft }
    180   1.1   mycroft 
    181  1.12  wrstuden /*
    182  1.12  wrstuden  * Called when an fs doesn't support a particular vop but the vop needs to
    183  1.12  wrstuden  * vrele, vput, or vunlock passed in vnodes.
    184  1.12  wrstuden  */
    185  1.12  wrstuden int
    186  1.12  wrstuden genfs_eopnotsupp_rele(v)
    187  1.12  wrstuden 	void *v;
    188  1.12  wrstuden {
    189  1.12  wrstuden 	struct vop_generic_args /*
    190  1.12  wrstuden 		struct vnodeop_desc *a_desc;
    191  1.12  wrstuden 		/ * other random data follows, presumably * /
    192  1.12  wrstuden 	} */ *ap = v;
    193  1.12  wrstuden 	struct vnodeop_desc *desc = ap->a_desc;
    194  1.12  wrstuden 	struct vnode *vp;
    195  1.12  wrstuden 	int flags, i, j, offset;
    196  1.12  wrstuden 
    197  1.12  wrstuden 	flags = desc->vdesc_flags;
    198  1.12  wrstuden 	for (i = 0; i < VDESC_MAX_VPS; flags >>=1, i++) {
    199  1.12  wrstuden 		if ((offset = desc->vdesc_vp_offsets[i]) == VDESC_NO_OFFSET)
    200  1.12  wrstuden 			break;	/* stop at end of list */
    201  1.12  wrstuden 		if ((j = flags & VDESC_VP0_WILLPUT)) {
    202  1.12  wrstuden 			vp = *VOPARG_OFFSETTO(struct vnode**,offset,ap);
    203  1.12  wrstuden 			switch (j) {
    204  1.12  wrstuden 			case VDESC_VP0_WILLPUT:
    205  1.12  wrstuden 				vput(vp);
    206  1.12  wrstuden 				break;
    207  1.12  wrstuden 			case VDESC_VP0_WILLUNLOCK:
    208  1.12  wrstuden 				VOP_UNLOCK(vp, 0);
    209  1.12  wrstuden 				break;
    210  1.12  wrstuden 			case VDESC_VP0_WILLRELE:
    211  1.12  wrstuden 				vrele(vp);
    212  1.12  wrstuden 				break;
    213  1.12  wrstuden 			}
    214  1.12  wrstuden 		}
    215  1.12  wrstuden 	}
    216  1.12  wrstuden 
    217  1.12  wrstuden 	return (EOPNOTSUPP);
    218  1.12  wrstuden }
    219  1.12  wrstuden 
    220   1.1   mycroft /*ARGSUSED*/
    221   1.1   mycroft int
    222   1.1   mycroft genfs_ebadf(v)
    223   1.1   mycroft 	void *v;
    224   1.1   mycroft {
    225   1.1   mycroft 
    226   1.1   mycroft 	return (EBADF);
    227   1.9  matthias }
    228   1.9  matthias 
    229   1.9  matthias /* ARGSUSED */
    230   1.9  matthias int
    231   1.9  matthias genfs_enoioctl(v)
    232   1.9  matthias 	void *v;
    233   1.9  matthias {
    234   1.9  matthias 
    235   1.9  matthias 	return (ENOTTY);
    236   1.6      fvdl }
    237   1.6      fvdl 
    238   1.6      fvdl 
    239   1.6      fvdl /*
    240   1.6      fvdl  * Eliminate all activity associated with  the requested vnode
    241   1.6      fvdl  * and with all vnodes aliased to the requested vnode.
    242   1.6      fvdl  */
    243   1.6      fvdl int
    244   1.6      fvdl genfs_revoke(v)
    245   1.6      fvdl 	void *v;
    246   1.6      fvdl {
    247   1.6      fvdl 	struct vop_revoke_args /* {
    248   1.6      fvdl 		struct vnode *a_vp;
    249   1.6      fvdl 		int a_flags;
    250   1.6      fvdl 	} */ *ap = v;
    251   1.6      fvdl 	struct vnode *vp, *vq;
    252   1.6      fvdl 	struct proc *p = curproc;	/* XXX */
    253   1.6      fvdl 
    254   1.6      fvdl #ifdef DIAGNOSTIC
    255   1.6      fvdl 	if ((ap->a_flags & REVOKEALL) == 0)
    256   1.6      fvdl 		panic("genfs_revoke: not revokeall");
    257   1.6      fvdl #endif
    258   1.6      fvdl 
    259   1.6      fvdl 	vp = ap->a_vp;
    260   1.6      fvdl 	simple_lock(&vp->v_interlock);
    261   1.6      fvdl 
    262   1.6      fvdl 	if (vp->v_flag & VALIASED) {
    263   1.6      fvdl 		/*
    264   1.6      fvdl 		 * If a vgone (or vclean) is already in progress,
    265   1.6      fvdl 		 * wait until it is done and return.
    266   1.6      fvdl 		 */
    267   1.6      fvdl 		if (vp->v_flag & VXLOCK) {
    268   1.6      fvdl 			vp->v_flag |= VXWANT;
    269   1.6      fvdl 			simple_unlock(&vp->v_interlock);
    270   1.6      fvdl 			tsleep((caddr_t)vp, PINOD, "vop_revokeall", 0);
    271   1.6      fvdl 			return (0);
    272   1.6      fvdl 		}
    273   1.6      fvdl 		/*
    274   1.6      fvdl 		 * Ensure that vp will not be vgone'd while we
    275   1.6      fvdl 		 * are eliminating its aliases.
    276   1.6      fvdl 		 */
    277   1.6      fvdl 		vp->v_flag |= VXLOCK;
    278   1.6      fvdl 		simple_unlock(&vp->v_interlock);
    279   1.6      fvdl 		while (vp->v_flag & VALIASED) {
    280   1.6      fvdl 			simple_lock(&spechash_slock);
    281   1.6      fvdl 			for (vq = *vp->v_hashchain; vq; vq = vq->v_specnext) {
    282   1.6      fvdl 				if (vq->v_rdev != vp->v_rdev ||
    283   1.6      fvdl 				    vq->v_type != vp->v_type || vp == vq)
    284   1.6      fvdl 					continue;
    285   1.6      fvdl 				simple_unlock(&spechash_slock);
    286   1.6      fvdl 				vgone(vq);
    287   1.6      fvdl 				break;
    288   1.6      fvdl 			}
    289   1.6      fvdl 			if (vq == NULLVP)
    290   1.6      fvdl 				simple_unlock(&spechash_slock);
    291   1.6      fvdl 		}
    292   1.6      fvdl 		/*
    293   1.6      fvdl 		 * Remove the lock so that vgone below will
    294   1.6      fvdl 		 * really eliminate the vnode after which time
    295   1.6      fvdl 		 * vgone will awaken any sleepers.
    296   1.6      fvdl 		 */
    297   1.6      fvdl 		simple_lock(&vp->v_interlock);
    298   1.6      fvdl 		vp->v_flag &= ~VXLOCK;
    299   1.6      fvdl 	}
    300   1.6      fvdl 	vgonel(vp, p);
    301   1.6      fvdl 	return (0);
    302   1.6      fvdl }
    303   1.6      fvdl 
    304   1.6      fvdl /*
    305  1.12  wrstuden  * Lock the node.
    306   1.6      fvdl  */
    307   1.6      fvdl int
    308  1.12  wrstuden genfs_lock(v)
    309   1.6      fvdl 	void *v;
    310   1.6      fvdl {
    311   1.6      fvdl 	struct vop_lock_args /* {
    312   1.6      fvdl 		struct vnode *a_vp;
    313   1.6      fvdl 		int a_flags;
    314   1.6      fvdl 		struct proc *a_p;
    315   1.6      fvdl 	} */ *ap = v;
    316   1.6      fvdl 	struct vnode *vp = ap->a_vp;
    317   1.6      fvdl 
    318  1.12  wrstuden 	return (lockmgr(&vp->v_lock, ap->a_flags, &vp->v_interlock));
    319   1.6      fvdl }
    320   1.6      fvdl 
    321   1.6      fvdl /*
    322  1.12  wrstuden  * Unlock the node.
    323   1.6      fvdl  */
    324   1.6      fvdl int
    325  1.12  wrstuden genfs_unlock(v)
    326   1.6      fvdl 	void *v;
    327   1.6      fvdl {
    328   1.6      fvdl 	struct vop_unlock_args /* {
    329   1.6      fvdl 		struct vnode *a_vp;
    330   1.6      fvdl 		int a_flags;
    331   1.6      fvdl 		struct proc *a_p;
    332   1.6      fvdl 	} */ *ap = v;
    333   1.6      fvdl 	struct vnode *vp = ap->a_vp;
    334   1.6      fvdl 
    335  1.12  wrstuden 	return (lockmgr(&vp->v_lock, ap->a_flags | LK_RELEASE,
    336  1.12  wrstuden 		&vp->v_interlock));
    337   1.6      fvdl }
    338   1.6      fvdl 
    339   1.6      fvdl /*
    340  1.12  wrstuden  * Return whether or not the node is locked.
    341   1.6      fvdl  */
    342   1.6      fvdl int
    343  1.12  wrstuden genfs_islocked(v)
    344   1.6      fvdl 	void *v;
    345   1.6      fvdl {
    346   1.6      fvdl 	struct vop_islocked_args /* {
    347   1.6      fvdl 		struct vnode *a_vp;
    348   1.6      fvdl 	} */ *ap = v;
    349   1.6      fvdl 	struct vnode *vp = ap->a_vp;
    350   1.6      fvdl 
    351  1.12  wrstuden 	return (lockstatus(&vp->v_lock));
    352  1.12  wrstuden }
    353  1.12  wrstuden 
    354  1.12  wrstuden /*
    355  1.12  wrstuden  * Stubs to use when there is no locking to be done on the underlying object.
    356  1.12  wrstuden  */
    357  1.12  wrstuden int
    358  1.12  wrstuden genfs_nolock(v)
    359  1.12  wrstuden 	void *v;
    360  1.12  wrstuden {
    361  1.12  wrstuden 	struct vop_lock_args /* {
    362  1.12  wrstuden 		struct vnode *a_vp;
    363  1.12  wrstuden 		int a_flags;
    364  1.12  wrstuden 		struct proc *a_p;
    365  1.12  wrstuden 	} */ *ap = v;
    366  1.12  wrstuden 
    367  1.12  wrstuden 	/*
    368  1.12  wrstuden 	 * Since we are not using the lock manager, we must clear
    369  1.12  wrstuden 	 * the interlock here.
    370  1.12  wrstuden 	 */
    371  1.12  wrstuden 	if (ap->a_flags & LK_INTERLOCK)
    372  1.12  wrstuden 		simple_unlock(&ap->a_vp->v_interlock);
    373  1.12  wrstuden 	return (0);
    374  1.12  wrstuden }
    375  1.12  wrstuden 
    376  1.12  wrstuden int
    377  1.12  wrstuden genfs_nounlock(v)
    378  1.12  wrstuden 	void *v;
    379  1.12  wrstuden {
    380  1.12  wrstuden 	return (0);
    381  1.12  wrstuden }
    382  1.12  wrstuden 
    383  1.12  wrstuden int
    384  1.12  wrstuden genfs_noislocked(v)
    385  1.12  wrstuden 	void *v;
    386  1.12  wrstuden {
    387  1.12  wrstuden 	return (0);
    388   1.8   thorpej }
    389   1.8   thorpej 
    390   1.8   thorpej /*
    391   1.8   thorpej  * Local lease check for NFS servers.  Just set up args and let
    392   1.8   thorpej  * nqsrv_getlease() do the rest.  If NFSSERVER is not in the kernel,
    393   1.8   thorpej  * this is a null operation.
    394   1.8   thorpej  */
    395   1.8   thorpej int
    396   1.8   thorpej genfs_lease_check(v)
    397   1.8   thorpej 	void *v;
    398   1.8   thorpej {
    399   1.8   thorpej #ifdef NFSSERVER
    400   1.8   thorpej 	struct vop_lease_args /* {
    401   1.8   thorpej 		struct vnode *a_vp;
    402   1.8   thorpej 		struct proc *a_p;
    403   1.8   thorpej 		struct ucred *a_cred;
    404   1.8   thorpej 		int a_flag;
    405   1.8   thorpej 	} */ *ap = v;
    406   1.8   thorpej 	u_int32_t duration = 0;
    407   1.8   thorpej 	int cache;
    408   1.8   thorpej 	u_quad_t frev;
    409   1.8   thorpej 
    410   1.8   thorpej 	(void) nqsrv_getlease(ap->a_vp, &duration, ND_CHECK | ap->a_flag,
    411   1.8   thorpej 	    NQLOCALSLP, ap->a_p, (struct mbuf *)0, &cache, &frev, ap->a_cred);
    412   1.8   thorpej 	return (0);
    413   1.8   thorpej #else
    414   1.8   thorpej 	return (0);
    415   1.8   thorpej #endif /* NFSSERVER */
    416   1.1   mycroft }
    417