1996-10-13 05:37:04 +04:00
|
|
|
/* $NetBSD: vnd.c,v 1.30 1996/10/13 01:37:08 christos Exp $ */
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1988 University of Utah.
|
|
|
|
* Copyright (c) 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* the Systems Programming Group of the University of Utah Computer
|
|
|
|
* Science Department.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1994-04-20 09:01:22 +04:00
|
|
|
* from: Utah $Hdr: vn.c 1.13 94/04/02$
|
1993-12-21 07:17:02 +03:00
|
|
|
*
|
1994-04-20 09:01:22 +04:00
|
|
|
* @(#)vn.c 8.6 (Berkeley) 4/1/94
|
1993-12-21 07:17:02 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Vnode disk driver.
|
|
|
|
*
|
|
|
|
* Block/character interface to a vnode. Allows one to treat a file
|
|
|
|
* as a disk (e.g. build a filesystem in it, mount it, etc.).
|
|
|
|
*
|
|
|
|
* NOTE 1: This uses the VOP_BMAP/VOP_STRATEGY interface to the vnode
|
|
|
|
* instead of a simple VOP_RDWR. We do this to avoid distorting the
|
|
|
|
* local buffer cache.
|
|
|
|
*
|
|
|
|
* NOTE 2: There is a security issue involved with this driver.
|
|
|
|
* Once mounted all access to the contents of the "mapped" file via
|
|
|
|
* the special file is controlled by the permissions on the special
|
|
|
|
* file, the protection of the mapped file is ignored (effectively,
|
|
|
|
* by using root credentials in all transactions).
|
|
|
|
*
|
|
|
|
* NOTE 3: Doesn't interact with leases, should it?
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/ioctl.h>
|
1994-12-24 17:05:51 +03:00
|
|
|
#include <sys/disklabel.h>
|
1995-11-06 23:28:09 +03:00
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#include <sys/stat.h>
|
1993-12-21 07:17:02 +03:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/uio.h>
|
1996-03-31 03:05:46 +04:00
|
|
|
#include <sys/conf.h>
|
1993-12-21 07:17:02 +03:00
|
|
|
|
|
|
|
#include <miscfs/specfs/specdev.h>
|
|
|
|
|
1995-01-25 07:45:38 +03:00
|
|
|
#include <dev/vndioctl.h>
|
1993-12-21 07:17:02 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
int dovndcluster = 1;
|
|
|
|
int vnddebug = 0x00;
|
1993-12-21 07:17:02 +03:00
|
|
|
#define VDB_FOLLOW 0x01
|
|
|
|
#define VDB_INIT 0x02
|
|
|
|
#define VDB_IO 0x04
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define b_cylin b_resid
|
|
|
|
|
1995-02-27 22:31:00 +03:00
|
|
|
#define vndunit(x) DISKUNIT(x)
|
|
|
|
|
|
|
|
struct vndbuf {
|
|
|
|
struct buf vb_buf;
|
|
|
|
struct buf *vb_obp;
|
|
|
|
};
|
1993-12-21 07:17:02 +03:00
|
|
|
|
1995-01-25 07:45:38 +03:00
|
|
|
#define getvndbuf() \
|
1995-02-27 22:31:00 +03:00
|
|
|
((struct vndbuf *)malloc(sizeof(struct vndbuf), M_DEVBUF, M_WAITOK))
|
|
|
|
#define putvndbuf(vbp) \
|
|
|
|
free((caddr_t)(vbp), M_DEVBUF)
|
1993-12-21 07:17:02 +03:00
|
|
|
|
1995-01-25 07:45:38 +03:00
|
|
|
struct vnd_softc {
|
1993-12-21 07:17:02 +03:00
|
|
|
int sc_flags; /* flags */
|
1995-01-25 07:45:38 +03:00
|
|
|
size_t sc_size; /* size of vnd */
|
1993-12-21 07:17:02 +03:00
|
|
|
struct vnode *sc_vp; /* vnode */
|
|
|
|
struct ucred *sc_cred; /* credentials */
|
|
|
|
int sc_maxactive; /* max # of active requests */
|
|
|
|
struct buf sc_tab; /* transfer queue */
|
1996-01-08 01:01:38 +03:00
|
|
|
char sc_xname[8]; /* XXX external name */
|
|
|
|
struct disk sc_dkdev; /* generic disk device info */
|
1993-12-21 07:17:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/* sc_flags */
|
|
|
|
#define VNF_ALIVE 0x01
|
|
|
|
#define VNF_INITED 0x02
|
1995-11-06 23:28:09 +03:00
|
|
|
#define VNF_WANTED 0x40
|
|
|
|
#define VNF_LOCKED 0x80
|
1993-12-21 07:17:02 +03:00
|
|
|
|
1995-01-25 07:45:38 +03:00
|
|
|
struct vnd_softc *vnd_softc;
|
1995-11-06 23:28:09 +03:00
|
|
|
int numvnd = 0;
|
|
|
|
|
|
|
|
/* called by main() at boot time */
|
|
|
|
void vndattach __P((int));
|
1993-12-21 07:17:02 +03:00
|
|
|
|
1995-01-25 07:45:38 +03:00
|
|
|
void vndclear __P((struct vnd_softc *));
|
|
|
|
void vndstart __P((struct vnd_softc *));
|
|
|
|
int vndsetcred __P((struct vnd_softc *, struct ucred *));
|
|
|
|
void vndthrottle __P((struct vnd_softc *, struct vnode *));
|
1996-02-10 03:11:44 +03:00
|
|
|
void vndiodone __P((struct buf *));
|
|
|
|
void vndshutdown __P((void));
|
1994-12-24 17:05:51 +03:00
|
|
|
|
1995-11-06 23:28:09 +03:00
|
|
|
static int vndlock __P((struct vnd_softc *));
|
|
|
|
static void vndunlock __P((struct vnd_softc *));
|
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
void
|
1995-01-25 07:45:38 +03:00
|
|
|
vndattach(num)
|
1993-12-21 07:17:02 +03:00
|
|
|
int num;
|
|
|
|
{
|
|
|
|
char *mem;
|
|
|
|
register u_long size;
|
|
|
|
|
|
|
|
if (num <= 0)
|
|
|
|
return;
|
1995-01-25 07:45:38 +03:00
|
|
|
size = num * sizeof(struct vnd_softc);
|
1993-12-21 07:17:02 +03:00
|
|
|
mem = malloc(size, M_DEVBUF, M_NOWAIT);
|
|
|
|
if (mem == NULL) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("WARNING: no memory for vnode disks\n");
|
1993-12-21 07:17:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
bzero(mem, size);
|
1995-01-25 07:45:38 +03:00
|
|
|
vnd_softc = (struct vnd_softc *)mem;
|
1993-12-21 07:17:02 +03:00
|
|
|
numvnd = num;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1995-01-25 07:45:38 +03:00
|
|
|
vndopen(dev, flags, mode, p)
|
1993-12-21 07:17:02 +03:00
|
|
|
dev_t dev;
|
|
|
|
int flags, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1995-01-25 07:45:38 +03:00
|
|
|
int unit = vndunit(dev);
|
1995-11-06 23:28:09 +03:00
|
|
|
struct vnd_softc *sc;
|
|
|
|
int error = 0, part, pmask;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX Should support disklabels.
|
|
|
|
*/
|
1993-12-21 07:17:02 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnddebug & VDB_FOLLOW)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("vndopen(%x, %x, %x, %p)\n", dev, flags, mode, p);
|
1993-12-21 07:17:02 +03:00
|
|
|
#endif
|
|
|
|
if (unit >= numvnd)
|
1995-11-06 23:28:09 +03:00
|
|
|
return (ENXIO);
|
|
|
|
sc = &vnd_softc[unit];
|
|
|
|
|
1996-02-10 03:11:44 +03:00
|
|
|
if ((error = vndlock(sc)) != 0)
|
1995-11-06 23:28:09 +03:00
|
|
|
return (error);
|
|
|
|
|
|
|
|
part = DISKPART(dev);
|
|
|
|
pmask = (1 << part);
|
|
|
|
|
|
|
|
/* Prevent our unit from being unconfigured while open. */
|
|
|
|
switch (mode) {
|
|
|
|
case S_IFCHR:
|
|
|
|
sc->sc_dkdev.dk_copenmask |= pmask;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_IFBLK:
|
|
|
|
sc->sc_dkdev.dk_bopenmask |= pmask;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sc->sc_dkdev.dk_openmask =
|
|
|
|
sc->sc_dkdev.dk_copenmask | sc->sc_dkdev.dk_bopenmask;
|
|
|
|
|
|
|
|
vndunlock(sc);
|
|
|
|
return (0);
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
|
|
|
|
1994-02-27 11:41:11 +03:00
|
|
|
int
|
1995-01-25 07:45:38 +03:00
|
|
|
vndclose(dev, flags, mode, p)
|
1994-02-27 11:41:11 +03:00
|
|
|
dev_t dev;
|
|
|
|
int flags, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1995-11-06 23:28:09 +03:00
|
|
|
int unit = vndunit(dev);
|
|
|
|
struct vnd_softc *sc;
|
|
|
|
int error = 0, part;
|
|
|
|
|
1994-02-27 11:41:11 +03:00
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnddebug & VDB_FOLLOW)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("vndclose(%x, %x, %x, %p)\n", dev, flags, mode, p);
|
1994-02-27 11:41:11 +03:00
|
|
|
#endif
|
1995-11-06 23:28:09 +03:00
|
|
|
|
|
|
|
if (unit >= numvnd)
|
|
|
|
return (ENXIO);
|
|
|
|
sc = &vnd_softc[unit];
|
|
|
|
|
1996-02-10 03:11:44 +03:00
|
|
|
if ((error = vndlock(sc)) != 0)
|
1995-11-06 23:28:09 +03:00
|
|
|
return (error);
|
|
|
|
|
|
|
|
part = DISKPART(dev);
|
|
|
|
|
|
|
|
/* ...that much closer to allowing unconfiguration... */
|
|
|
|
switch (mode) {
|
|
|
|
case S_IFCHR:
|
|
|
|
sc->sc_dkdev.dk_copenmask &= ~(1 << part);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_IFBLK:
|
|
|
|
sc->sc_dkdev.dk_bopenmask &= ~(1 << part);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sc->sc_dkdev.dk_openmask =
|
|
|
|
sc->sc_dkdev.dk_copenmask | sc->sc_dkdev.dk_bopenmask;
|
|
|
|
|
|
|
|
vndunlock(sc);
|
|
|
|
return (0);
|
1994-02-27 11:41:11 +03:00
|
|
|
}
|
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
/*
|
|
|
|
* Break the request into bsize pieces and submit using VOP_BMAP/VOP_STRATEGY.
|
|
|
|
* Note that this driver can only be used for swapping over NFS on the hp
|
|
|
|
* since nfs_strategy on the vax cannot handle u-areas and page tables.
|
|
|
|
*/
|
1994-05-11 08:26:17 +04:00
|
|
|
void
|
1995-01-25 07:45:38 +03:00
|
|
|
vndstrategy(bp)
|
1993-12-21 07:17:02 +03:00
|
|
|
register struct buf *bp;
|
|
|
|
{
|
1995-01-25 07:45:38 +03:00
|
|
|
int unit = vndunit(bp->b_dev);
|
|
|
|
register struct vnd_softc *vnd = &vnd_softc[unit];
|
1995-02-27 22:31:00 +03:00
|
|
|
register struct vndbuf *nbp;
|
1993-12-21 07:17:02 +03:00
|
|
|
register int bn, bsize, resid;
|
|
|
|
register caddr_t addr;
|
1994-04-20 09:01:22 +04:00
|
|
|
int sz, flags, error;
|
1993-12-21 07:17:02 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnddebug & VDB_FOLLOW)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("vndstrategy(%p): unit %d\n", bp, unit);
|
1993-12-21 07:17:02 +03:00
|
|
|
#endif
|
1995-01-25 07:45:38 +03:00
|
|
|
if ((vnd->sc_flags & VNF_INITED) == 0) {
|
1993-12-21 07:17:02 +03:00
|
|
|
bp->b_error = ENXIO;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
biodone(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bn = bp->b_blkno;
|
|
|
|
sz = howmany(bp->b_bcount, DEV_BSIZE);
|
|
|
|
bp->b_resid = bp->b_bcount;
|
1995-01-25 07:45:38 +03:00
|
|
|
if (bn < 0 || bn + sz > vnd->sc_size) {
|
|
|
|
if (bn != vnd->sc_size) {
|
1993-12-21 07:17:02 +03:00
|
|
|
bp->b_error = EINVAL;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
}
|
|
|
|
biodone(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bn = dbtob(bn);
|
1995-01-25 07:45:38 +03:00
|
|
|
bsize = vnd->sc_vp->v_mount->mnt_stat.f_iosize;
|
1994-04-20 09:01:22 +04:00
|
|
|
addr = bp->b_data;
|
1993-12-21 07:17:02 +03:00
|
|
|
flags = bp->b_flags | B_CALL;
|
|
|
|
for (resid = bp->b_resid; resid; resid -= sz) {
|
|
|
|
struct vnode *vp;
|
|
|
|
daddr_t nbn;
|
1994-04-20 09:01:22 +04:00
|
|
|
int off, s, nra;
|
1993-12-21 07:17:02 +03:00
|
|
|
|
1994-04-20 09:01:22 +04:00
|
|
|
nra = 0;
|
1995-10-05 09:20:57 +03:00
|
|
|
VOP_LOCK(vnd->sc_vp);
|
1995-01-25 07:45:38 +03:00
|
|
|
error = VOP_BMAP(vnd->sc_vp, bn / bsize, &vp, &nbn, &nra);
|
1995-10-05 09:20:57 +03:00
|
|
|
VOP_UNLOCK(vnd->sc_vp);
|
1994-04-20 09:01:22 +04:00
|
|
|
if (error == 0 && (long)nbn == -1)
|
|
|
|
error = EIO;
|
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
if (!dovndcluster)
|
1994-04-20 09:01:22 +04:00
|
|
|
nra = 0;
|
1993-12-21 07:17:02 +03:00
|
|
|
#endif
|
1994-04-20 09:01:22 +04:00
|
|
|
|
1996-02-10 03:11:44 +03:00
|
|
|
if ((off = bn % bsize) != 0)
|
1994-04-20 09:01:22 +04:00
|
|
|
sz = bsize - off;
|
|
|
|
else
|
|
|
|
sz = (1 + nra) * bsize;
|
|
|
|
if (resid < sz)
|
|
|
|
sz = resid;
|
1993-12-21 07:17:02 +03:00
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnddebug & VDB_IO)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("vndstrategy: vp %p/%p bn %x/%x sz %x\n",
|
1996-10-11 02:25:05 +04:00
|
|
|
vnd->sc_vp, vp, bn, nbn, sz);
|
1993-12-21 07:17:02 +03:00
|
|
|
#endif
|
1994-04-20 09:01:22 +04:00
|
|
|
|
1995-01-25 07:45:38 +03:00
|
|
|
nbp = getvndbuf();
|
1995-02-27 22:31:00 +03:00
|
|
|
nbp->vb_buf.b_flags = flags;
|
|
|
|
nbp->vb_buf.b_bcount = sz;
|
|
|
|
nbp->vb_buf.b_bufsize = bp->b_bufsize;
|
|
|
|
nbp->vb_buf.b_error = 0;
|
1993-12-21 07:17:02 +03:00
|
|
|
if (vp->v_type == VBLK || vp->v_type == VCHR)
|
1995-02-27 22:31:00 +03:00
|
|
|
nbp->vb_buf.b_dev = vp->v_rdev;
|
1993-12-21 07:17:02 +03:00
|
|
|
else
|
1995-02-27 22:31:00 +03:00
|
|
|
nbp->vb_buf.b_dev = NODEV;
|
|
|
|
nbp->vb_buf.b_data = addr;
|
|
|
|
nbp->vb_buf.b_blkno = nbn + btodb(off);
|
|
|
|
nbp->vb_buf.b_proc = bp->b_proc;
|
|
|
|
nbp->vb_buf.b_iodone = vndiodone;
|
|
|
|
nbp->vb_buf.b_vp = vp;
|
|
|
|
nbp->vb_buf.b_rcred = vnd->sc_cred; /* XXX crdup? */
|
|
|
|
nbp->vb_buf.b_wcred = vnd->sc_cred; /* XXX crdup? */
|
|
|
|
nbp->vb_buf.b_dirtyoff = bp->b_dirtyoff;
|
|
|
|
nbp->vb_buf.b_dirtyend = bp->b_dirtyend;
|
|
|
|
nbp->vb_buf.b_validoff = bp->b_validoff;
|
|
|
|
nbp->vb_buf.b_validend = bp->b_validend;
|
|
|
|
|
|
|
|
/* save a reference to the old buffer */
|
|
|
|
nbp->vb_obp = bp;
|
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
/*
|
1994-04-20 09:01:22 +04:00
|
|
|
* If there was an error or a hole in the file...punt.
|
1993-12-21 07:17:02 +03:00
|
|
|
* Note that we deal with this after the nbp allocation.
|
|
|
|
* This ensures that we properly clean up any operations
|
|
|
|
* that we have already fired off.
|
|
|
|
*
|
1994-04-20 09:01:22 +04:00
|
|
|
* XXX we could deal with holes here but it would be
|
1993-12-21 07:17:02 +03:00
|
|
|
* a hassle (in the write case).
|
|
|
|
*/
|
1994-04-20 09:01:22 +04:00
|
|
|
if (error) {
|
1995-02-27 22:31:00 +03:00
|
|
|
nbp->vb_buf.b_error = error;
|
|
|
|
nbp->vb_buf.b_flags |= B_ERROR;
|
1993-12-21 07:17:02 +03:00
|
|
|
bp->b_resid -= (resid - sz);
|
1995-02-27 22:31:00 +03:00
|
|
|
biodone(&nbp->vb_buf);
|
1993-12-21 07:17:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Just sort by block number
|
|
|
|
*/
|
1995-02-27 22:31:00 +03:00
|
|
|
nbp->vb_buf.b_cylin = nbp->vb_buf.b_blkno;
|
1993-12-21 07:17:02 +03:00
|
|
|
s = splbio();
|
1995-02-27 22:31:00 +03:00
|
|
|
disksort(&vnd->sc_tab, &nbp->vb_buf);
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnd->sc_tab.b_active < vnd->sc_maxactive) {
|
|
|
|
vnd->sc_tab.b_active++;
|
|
|
|
vndstart(vnd);
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
bn += sz;
|
|
|
|
addr += sz;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Feed requests sequentially.
|
|
|
|
* We do it this way to keep from flooding NFS servers if we are connected
|
|
|
|
* to an NFS file. This places the burden on the client rather than the
|
|
|
|
* server.
|
|
|
|
*/
|
1994-12-24 17:05:51 +03:00
|
|
|
void
|
1995-01-25 07:45:38 +03:00
|
|
|
vndstart(vnd)
|
|
|
|
register struct vnd_softc *vnd;
|
1993-12-21 07:17:02 +03:00
|
|
|
{
|
|
|
|
register struct buf *bp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dequeue now since lower level strategy routine might
|
|
|
|
* queue using same links
|
|
|
|
*/
|
1995-01-25 07:45:38 +03:00
|
|
|
bp = vnd->sc_tab.b_actf;
|
|
|
|
vnd->sc_tab.b_actf = bp->b_actf;
|
1993-12-21 07:17:02 +03:00
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnddebug & VDB_IO)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("vndstart(%ld): bp %p vp %p blkno %x addr %p cnt %lx\n",
|
1996-09-25 06:22:10 +04:00
|
|
|
(long) (vnd-vnd_softc), bp, bp->b_vp, bp->b_blkno,
|
|
|
|
bp->b_data, bp->b_bcount);
|
1993-12-21 07:17:02 +03:00
|
|
|
#endif
|
1996-01-08 01:01:38 +03:00
|
|
|
|
|
|
|
/* Instrumentation. */
|
|
|
|
disk_busy(&vnd->sc_dkdev);
|
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
if ((bp->b_flags & B_READ) == 0)
|
|
|
|
bp->b_vp->v_numoutput++;
|
|
|
|
VOP_STRATEGY(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1996-02-10 03:11:44 +03:00
|
|
|
vndiodone(bp)
|
|
|
|
struct buf *bp;
|
1993-12-21 07:17:02 +03:00
|
|
|
{
|
1996-02-10 03:11:44 +03:00
|
|
|
register struct vndbuf *vbp = (struct vndbuf *) bp;
|
1995-02-27 22:31:00 +03:00
|
|
|
register struct buf *pbp = vbp->vb_obp;
|
1995-01-25 07:45:38 +03:00
|
|
|
register struct vnd_softc *vnd = &vnd_softc[vndunit(pbp->b_dev)];
|
1993-12-21 07:17:02 +03:00
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnddebug & VDB_IO)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("vndiodone(%ld): vbp %p vp %p blkno %x addr %p cnt %lx\n",
|
1996-09-25 06:22:10 +04:00
|
|
|
(long) (vnd-vnd_softc), vbp, vbp->vb_buf.b_vp,
|
|
|
|
vbp->vb_buf.b_blkno, vbp->vb_buf.b_data,
|
|
|
|
vbp->vb_buf.b_bcount);
|
1993-12-21 07:17:02 +03:00
|
|
|
#endif
|
1996-01-08 01:01:38 +03:00
|
|
|
|
1995-02-27 22:31:00 +03:00
|
|
|
if (vbp->vb_buf.b_error) {
|
1993-12-21 07:17:02 +03:00
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnddebug & VDB_IO)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("vndiodone: vbp %p error %d\n", vbp,
|
1995-02-27 22:31:00 +03:00
|
|
|
vbp->vb_buf.b_error);
|
1993-12-21 07:17:02 +03:00
|
|
|
#endif
|
|
|
|
pbp->b_flags |= B_ERROR;
|
1995-02-27 22:31:00 +03:00
|
|
|
pbp->b_error = biowait(&vbp->vb_buf);
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
1995-02-27 22:31:00 +03:00
|
|
|
pbp->b_resid -= vbp->vb_buf.b_bcount;
|
|
|
|
putvndbuf(vbp);
|
1996-01-08 01:01:38 +03:00
|
|
|
disk_unbusy(&vnd->sc_dkdev, (pbp->b_bcount - pbp->b_resid));
|
1993-12-21 07:17:02 +03:00
|
|
|
if (pbp->b_resid == 0) {
|
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnddebug & VDB_IO)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("vndiodone: pbp %p iodone\n", pbp);
|
1993-12-21 07:17:02 +03:00
|
|
|
#endif
|
|
|
|
biodone(pbp);
|
|
|
|
}
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnd->sc_tab.b_actf)
|
|
|
|
vndstart(vnd);
|
1993-12-21 07:17:02 +03:00
|
|
|
else
|
1995-01-25 07:45:38 +03:00
|
|
|
vnd->sc_tab.b_active--;
|
1993-12-21 07:17:02 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1995-11-06 23:28:09 +03:00
|
|
|
/* ARGSUSED */
|
1995-07-04 11:15:28 +04:00
|
|
|
int
|
1995-11-06 23:28:09 +03:00
|
|
|
vndread(dev, uio, flags)
|
1995-07-04 11:15:28 +04:00
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1995-11-06 23:28:09 +03:00
|
|
|
int flags;
|
1995-07-04 11:15:28 +04:00
|
|
|
{
|
1995-11-06 23:28:09 +03:00
|
|
|
int unit = vndunit(dev);
|
|
|
|
struct vnd_softc *sc;
|
1995-07-04 11:15:28 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (vnddebug & VDB_FOLLOW)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("vndread(%x, %p)\n", dev, uio);
|
1995-07-04 11:15:28 +04:00
|
|
|
#endif
|
1995-11-06 23:28:09 +03:00
|
|
|
|
|
|
|
if (unit >= numvnd)
|
|
|
|
return (ENXIO);
|
|
|
|
sc = &vnd_softc[unit];
|
|
|
|
|
|
|
|
if ((sc->sc_flags & VNF_INITED) == 0)
|
|
|
|
return (ENXIO);
|
|
|
|
|
1995-07-04 11:15:28 +04:00
|
|
|
return (physio(vndstrategy, NULL, dev, B_READ, minphys, uio));
|
|
|
|
}
|
|
|
|
|
1995-11-06 23:28:09 +03:00
|
|
|
/* ARGSUSED */
|
1995-07-04 11:15:28 +04:00
|
|
|
int
|
1995-11-06 23:28:09 +03:00
|
|
|
vndwrite(dev, uio, flags)
|
1995-07-04 11:15:28 +04:00
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1995-11-06 23:28:09 +03:00
|
|
|
int flags;
|
1995-07-04 11:15:28 +04:00
|
|
|
{
|
1995-11-06 23:28:09 +03:00
|
|
|
int unit = vndunit(dev);
|
|
|
|
struct vnd_softc *sc;
|
1995-07-04 11:15:28 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (vnddebug & VDB_FOLLOW)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("vndwrite(%x, %p)\n", dev, uio);
|
1995-07-04 11:15:28 +04:00
|
|
|
#endif
|
1995-11-06 23:28:09 +03:00
|
|
|
|
|
|
|
if (unit >= numvnd)
|
|
|
|
return (ENXIO);
|
|
|
|
sc = &vnd_softc[unit];
|
|
|
|
|
|
|
|
if ((sc->sc_flags & VNF_INITED) == 0)
|
|
|
|
return (ENXIO);
|
|
|
|
|
1995-07-04 11:15:28 +04:00
|
|
|
return (physio(vndstrategy, NULL, dev, B_WRITE, minphys, uio));
|
|
|
|
}
|
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
/* ARGSUSED */
|
1994-12-24 17:05:51 +03:00
|
|
|
int
|
1995-01-25 07:45:38 +03:00
|
|
|
vndioctl(dev, cmd, data, flag, p)
|
1993-12-21 07:17:02 +03:00
|
|
|
dev_t dev;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1995-01-25 07:45:38 +03:00
|
|
|
int unit = vndunit(dev);
|
|
|
|
register struct vnd_softc *vnd;
|
|
|
|
struct vnd_ioctl *vio;
|
1993-12-21 07:17:02 +03:00
|
|
|
struct vattr vattr;
|
|
|
|
struct nameidata nd;
|
1995-11-06 23:28:09 +03:00
|
|
|
int error, part, pmask, s;
|
1993-12-21 07:17:02 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnddebug & VDB_FOLLOW)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("vndioctl(%x, %lx, %p, %x, %p): unit %d\n",
|
1994-04-20 09:01:22 +04:00
|
|
|
dev, cmd, data, flag, p, unit);
|
1993-12-21 07:17:02 +03:00
|
|
|
#endif
|
|
|
|
error = suser(p->p_ucred, &p->p_acflag);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
if (unit >= numvnd)
|
|
|
|
return (ENXIO);
|
|
|
|
|
1995-01-25 07:45:38 +03:00
|
|
|
vnd = &vnd_softc[unit];
|
|
|
|
vio = (struct vnd_ioctl *)data;
|
1993-12-21 07:17:02 +03:00
|
|
|
switch (cmd) {
|
|
|
|
|
1995-01-25 07:45:38 +03:00
|
|
|
case VNDIOCSET:
|
|
|
|
if (vnd->sc_flags & VNF_INITED)
|
1995-11-06 23:28:09 +03:00
|
|
|
return (EBUSY);
|
|
|
|
|
1996-02-10 03:11:44 +03:00
|
|
|
if ((error = vndlock(vnd)) != 0)
|
1995-11-06 23:28:09 +03:00
|
|
|
return (error);
|
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
/*
|
|
|
|
* Always open for read and write.
|
|
|
|
* This is probably bogus, but it lets vn_open()
|
|
|
|
* weed out directories, sockets, etc. so we don't
|
|
|
|
* have to worry about them.
|
|
|
|
*/
|
1995-01-25 07:45:38 +03:00
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, vio->vnd_file, p);
|
1996-02-10 03:11:44 +03:00
|
|
|
if ((error = vn_open(&nd, FREAD|FWRITE, 0)) != 0) {
|
1995-11-06 23:28:09 +03:00
|
|
|
vndunlock(vnd);
|
1993-12-21 07:17:02 +03:00
|
|
|
return(error);
|
1995-11-06 23:28:09 +03:00
|
|
|
}
|
1996-02-10 03:11:44 +03:00
|
|
|
error = VOP_GETATTR(nd.ni_vp, &vattr, p->p_ucred, p);
|
|
|
|
if (error) {
|
1993-12-21 07:17:02 +03:00
|
|
|
VOP_UNLOCK(nd.ni_vp);
|
|
|
|
(void) vn_close(nd.ni_vp, FREAD|FWRITE, p->p_ucred, p);
|
1995-11-06 23:28:09 +03:00
|
|
|
vndunlock(vnd);
|
1993-12-21 07:17:02 +03:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
VOP_UNLOCK(nd.ni_vp);
|
1995-01-25 07:45:38 +03:00
|
|
|
vnd->sc_vp = nd.ni_vp;
|
|
|
|
vnd->sc_size = btodb(vattr.va_size); /* note truncation */
|
1996-02-10 03:11:44 +03:00
|
|
|
if ((error = vndsetcred(vnd, p->p_ucred)) != 0) {
|
1994-04-20 09:01:22 +04:00
|
|
|
(void) vn_close(nd.ni_vp, FREAD|FWRITE, p->p_ucred, p);
|
1995-11-06 23:28:09 +03:00
|
|
|
vndunlock(vnd);
|
1993-12-21 07:17:02 +03:00
|
|
|
return(error);
|
|
|
|
}
|
1995-01-25 07:45:38 +03:00
|
|
|
vndthrottle(vnd, vnd->sc_vp);
|
|
|
|
vio->vnd_size = dbtob(vnd->sc_size);
|
|
|
|
vnd->sc_flags |= VNF_INITED;
|
1993-12-21 07:17:02 +03:00
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnddebug & VDB_INIT)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("vndioctl: SET vp %p size %lx\n",
|
1996-09-25 06:22:10 +04:00
|
|
|
vnd->sc_vp, (unsigned long) vnd->sc_size);
|
1993-12-21 07:17:02 +03:00
|
|
|
#endif
|
1995-11-06 23:28:09 +03:00
|
|
|
|
1996-01-08 01:01:38 +03:00
|
|
|
/* Attach the disk. */
|
|
|
|
bzero(vnd->sc_xname, sizeof(vnd->sc_xname)); /* XXX */
|
1996-10-13 05:37:04 +04:00
|
|
|
sprintf(vnd->sc_xname, "vnd%d", unit); /* XXX */
|
1996-01-08 01:01:38 +03:00
|
|
|
vnd->sc_dkdev.dk_name = vnd->sc_xname;
|
|
|
|
disk_attach(&vnd->sc_dkdev);
|
|
|
|
|
1995-11-06 23:28:09 +03:00
|
|
|
vndunlock(vnd);
|
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
break;
|
|
|
|
|
1995-01-25 07:45:38 +03:00
|
|
|
case VNDIOCCLR:
|
|
|
|
if ((vnd->sc_flags & VNF_INITED) == 0)
|
1995-11-06 23:28:09 +03:00
|
|
|
return (ENXIO);
|
|
|
|
|
1996-02-10 03:11:44 +03:00
|
|
|
if ((error = vndlock(vnd)) != 0)
|
1995-11-06 23:28:09 +03:00
|
|
|
return (error);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't unconfigure if any other partitions are open
|
|
|
|
* or if both the character and block flavors of this
|
|
|
|
* partition are open.
|
|
|
|
*/
|
|
|
|
part = DISKPART(dev);
|
|
|
|
pmask = (1 << part);
|
|
|
|
if ((vnd->sc_dkdev.dk_openmask & ~pmask) ||
|
|
|
|
((vnd->sc_dkdev.dk_bopenmask & pmask) &&
|
|
|
|
(vnd->sc_dkdev.dk_copenmask & pmask))) {
|
|
|
|
vndunlock(vnd);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
|
1995-01-25 07:45:38 +03:00
|
|
|
vndclear(vnd);
|
1993-12-21 07:17:02 +03:00
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnddebug & VDB_INIT)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("vndioctl: CLRed\n");
|
1993-12-21 07:17:02 +03:00
|
|
|
#endif
|
1995-11-06 23:28:09 +03:00
|
|
|
|
1996-01-08 01:01:38 +03:00
|
|
|
/* Detatch the disk. */
|
1996-02-10 03:11:44 +03:00
|
|
|
disk_detach(&vnd->sc_dkdev);
|
1996-01-08 01:01:38 +03:00
|
|
|
|
1995-11-06 23:28:09 +03:00
|
|
|
/* This must be atomic. */
|
|
|
|
s = splhigh();
|
|
|
|
vndunlock(vnd);
|
|
|
|
bzero(vnd, sizeof(struct vnd_softc));
|
|
|
|
splx(s);
|
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
break;
|
|
|
|
|
1995-11-06 23:28:09 +03:00
|
|
|
/*
|
|
|
|
* XXX Should support disklabels.
|
|
|
|
*/
|
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
default:
|
1994-08-24 20:49:16 +04:00
|
|
|
return(ENOTTY);
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
1995-11-06 23:28:09 +03:00
|
|
|
|
|
|
|
return (0);
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Duplicate the current processes' credentials. Since we are called only
|
|
|
|
* as the result of a SET ioctl and only root can do that, any future access
|
|
|
|
* to this "disk" is essentially as root. Note that credentials may change
|
|
|
|
* if some other uid can write directly to the mapped file (NFS).
|
|
|
|
*/
|
1994-12-24 17:05:51 +03:00
|
|
|
int
|
1995-01-25 07:45:38 +03:00
|
|
|
vndsetcred(vnd, cred)
|
|
|
|
register struct vnd_softc *vnd;
|
1993-12-21 07:17:02 +03:00
|
|
|
struct ucred *cred;
|
|
|
|
{
|
|
|
|
struct uio auio;
|
|
|
|
struct iovec aiov;
|
1994-04-20 09:01:22 +04:00
|
|
|
char *tmpbuf;
|
|
|
|
int error;
|
1993-12-21 07:17:02 +03:00
|
|
|
|
1995-01-25 07:45:38 +03:00
|
|
|
vnd->sc_cred = crdup(cred);
|
1994-04-20 09:01:22 +04:00
|
|
|
tmpbuf = malloc(DEV_BSIZE, M_TEMP, M_WAITOK);
|
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
/* XXX: Horrible kludge to establish credentials for NFS */
|
|
|
|
aiov.iov_base = tmpbuf;
|
1995-01-25 07:45:38 +03:00
|
|
|
aiov.iov_len = min(DEV_BSIZE, dbtob(vnd->sc_size));
|
1993-12-21 07:17:02 +03:00
|
|
|
auio.uio_iov = &aiov;
|
|
|
|
auio.uio_iovcnt = 1;
|
|
|
|
auio.uio_offset = 0;
|
|
|
|
auio.uio_rw = UIO_READ;
|
|
|
|
auio.uio_segflg = UIO_SYSSPACE;
|
|
|
|
auio.uio_resid = aiov.iov_len;
|
1995-10-05 09:20:57 +03:00
|
|
|
VOP_LOCK(vnd->sc_vp);
|
1995-01-25 07:45:38 +03:00
|
|
|
error = VOP_READ(vnd->sc_vp, &auio, 0, vnd->sc_cred);
|
1995-10-05 09:20:57 +03:00
|
|
|
VOP_UNLOCK(vnd->sc_vp);
|
1994-04-20 09:01:22 +04:00
|
|
|
|
|
|
|
free(tmpbuf, M_TEMP);
|
|
|
|
return (error);
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set maxactive based on FS type
|
|
|
|
*/
|
1994-12-24 17:05:51 +03:00
|
|
|
void
|
1995-01-25 07:45:38 +03:00
|
|
|
vndthrottle(vnd, vp)
|
|
|
|
register struct vnd_softc *vnd;
|
1993-12-21 07:17:02 +03:00
|
|
|
struct vnode *vp;
|
|
|
|
{
|
|
|
|
#ifdef NFSCLIENT
|
1996-02-10 03:11:44 +03:00
|
|
|
extern int (**nfsv2_vnodeop_p) __P((void *));
|
1994-04-20 09:01:22 +04:00
|
|
|
|
1993-12-21 08:24:31 +03:00
|
|
|
if (vp->v_op == nfsv2_vnodeop_p)
|
1995-01-25 07:45:38 +03:00
|
|
|
vnd->sc_maxactive = 2;
|
1993-12-21 07:17:02 +03:00
|
|
|
else
|
|
|
|
#endif
|
1995-01-25 07:45:38 +03:00
|
|
|
vnd->sc_maxactive = 8;
|
1993-12-21 07:17:02 +03:00
|
|
|
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnd->sc_maxactive < 1)
|
|
|
|
vnd->sc_maxactive = 1;
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
|
|
|
|
1994-12-24 17:05:51 +03:00
|
|
|
void
|
1995-01-25 07:45:38 +03:00
|
|
|
vndshutdown()
|
1993-12-21 07:17:02 +03:00
|
|
|
{
|
1995-01-25 07:45:38 +03:00
|
|
|
register struct vnd_softc *vnd;
|
1993-12-21 07:17:02 +03:00
|
|
|
|
1995-01-25 07:45:38 +03:00
|
|
|
for (vnd = &vnd_softc[0]; vnd < &vnd_softc[numvnd]; vnd++)
|
|
|
|
if (vnd->sc_flags & VNF_INITED)
|
|
|
|
vndclear(vnd);
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
|
|
|
|
1994-12-24 17:05:51 +03:00
|
|
|
void
|
1995-01-25 07:45:38 +03:00
|
|
|
vndclear(vnd)
|
|
|
|
register struct vnd_softc *vnd;
|
1993-12-21 07:17:02 +03:00
|
|
|
{
|
1995-01-25 07:45:38 +03:00
|
|
|
register struct vnode *vp = vnd->sc_vp;
|
1993-12-21 07:17:02 +03:00
|
|
|
struct proc *p = curproc; /* XXX */
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnddebug & VDB_FOLLOW)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("vndclear(%p): vp %p\n", vnd, vp);
|
1993-12-21 07:17:02 +03:00
|
|
|
#endif
|
1995-01-25 07:45:38 +03:00
|
|
|
vnd->sc_flags &= ~VNF_INITED;
|
1993-12-21 07:17:02 +03:00
|
|
|
if (vp == (struct vnode *)0)
|
1995-01-25 07:45:38 +03:00
|
|
|
panic("vndioctl: null vp");
|
|
|
|
(void) vn_close(vp, FREAD|FWRITE, vnd->sc_cred, p);
|
|
|
|
crfree(vnd->sc_cred);
|
|
|
|
vnd->sc_vp = (struct vnode *)0;
|
|
|
|
vnd->sc_cred = (struct ucred *)0;
|
|
|
|
vnd->sc_size = 0;
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
|
|
|
|
1994-12-24 17:05:51 +03:00
|
|
|
int
|
1995-01-25 07:45:38 +03:00
|
|
|
vndsize(dev)
|
1993-12-21 07:17:02 +03:00
|
|
|
dev_t dev;
|
|
|
|
{
|
1995-01-25 07:45:38 +03:00
|
|
|
int unit = vndunit(dev);
|
|
|
|
register struct vnd_softc *vnd = &vnd_softc[unit];
|
1993-12-21 07:17:02 +03:00
|
|
|
|
1995-01-25 07:45:38 +03:00
|
|
|
if (unit >= numvnd || (vnd->sc_flags & VNF_INITED) == 0)
|
1993-12-21 07:17:02 +03:00
|
|
|
return(-1);
|
1995-01-25 07:45:38 +03:00
|
|
|
return(vnd->sc_size);
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
|
|
|
|
1994-12-24 17:05:51 +03:00
|
|
|
int
|
1995-06-26 09:34:44 +04:00
|
|
|
vnddump(dev, blkno, va, size)
|
1994-12-24 17:05:51 +03:00
|
|
|
dev_t dev;
|
1995-06-26 09:34:44 +04:00
|
|
|
daddr_t blkno;
|
|
|
|
caddr_t va;
|
|
|
|
size_t size;
|
1993-12-21 07:17:02 +03:00
|
|
|
{
|
1994-12-24 17:05:51 +03:00
|
|
|
|
1995-06-26 09:34:44 +04:00
|
|
|
/* Not implemented. */
|
|
|
|
return ENXIO;
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
1995-11-06 23:28:09 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait interruptibly for an exclusive lock.
|
|
|
|
*
|
|
|
|
* XXX
|
|
|
|
* Several drivers do this; it should be abstracted and made MP-safe.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
vndlock(sc)
|
|
|
|
struct vnd_softc *sc;
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
while ((sc->sc_flags & VNF_LOCKED) != 0) {
|
|
|
|
sc->sc_flags |= VNF_WANTED;
|
|
|
|
if ((error = tsleep(sc, PRIBIO | PCATCH, "vndlck", 0)) != 0)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
sc->sc_flags |= VNF_LOCKED;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlock and wake up any waiters.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
vndunlock(sc)
|
|
|
|
struct vnd_softc *sc;
|
|
|
|
{
|
|
|
|
|
|
|
|
sc->sc_flags &= ~VNF_LOCKED;
|
|
|
|
if ((sc->sc_flags & VNF_WANTED) != 0) {
|
|
|
|
sc->sc_flags &= ~VNF_WANTED;
|
|
|
|
wakeup(sc);
|
|
|
|
}
|
|
|
|
}
|