2002-11-16 11:10:48 +03:00
|
|
|
/* $NetBSD: vnd.c,v 1.89 2002/11/16 08:10:48 mrg Exp $ */
|
1997-06-24 01:03:55 +04:00
|
|
|
|
|
|
|
/*-
|
1998-07-31 06:24:26 +04:00
|
|
|
* Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
|
1997-06-24 01:03:55 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe.
|
|
|
|
*
|
|
|
|
* 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 NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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
|
1997-10-09 12:03:42 +04:00
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
1997-06-24 01:03:55 +04:00
|
|
|
* 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-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
|
|
|
*
|
1998-03-01 05:20:01 +03:00
|
|
|
* @(#)vn.c 8.9 (Berkeley) 5/14/95
|
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?
|
|
|
|
*/
|
|
|
|
|
2001-11-13 08:32:49 +03:00
|
|
|
#include <sys/cdefs.h>
|
2002-11-16 11:10:48 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.89 2002/11/16 08:10:48 mrg Exp $");
|
2001-11-13 08:32:49 +03:00
|
|
|
|
2001-10-22 20:43:55 +04:00
|
|
|
#if defined(_KERNEL_OPT)
|
1998-02-19 03:47:02 +03:00
|
|
|
#include "fs_nfs.h"
|
2001-10-22 20:43:55 +04:00
|
|
|
#endif
|
1998-02-19 03:47:02 +03:00
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
#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>
|
|
|
|
|
1997-06-24 01:03:55 +04:00
|
|
|
#include <dev/vndvar.h>
|
|
|
|
|
|
|
|
#if defined(VNDDEBUG) && !defined(DEBUG)
|
|
|
|
#define DEBUG
|
|
|
|
#endif
|
1993-12-21 07:17:02 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
int dovndcluster = 1;
|
1997-06-24 01:03:55 +04:00
|
|
|
#define VDB_FOLLOW 0x01
|
|
|
|
#define VDB_INIT 0x02
|
|
|
|
#define VDB_IO 0x04
|
|
|
|
#define VDB_LABEL 0x08
|
1995-01-25 07:45:38 +03:00
|
|
|
int vnddebug = 0x00;
|
1993-12-21 07:17:02 +03:00
|
|
|
#endif
|
|
|
|
|
1995-02-27 22:31:00 +03:00
|
|
|
#define vndunit(x) DISKUNIT(x)
|
|
|
|
|
1997-05-25 23:37:36 +04:00
|
|
|
struct vndxfer {
|
|
|
|
struct buf *vx_bp; /* Pointer to parent buffer */
|
|
|
|
int vx_error;
|
|
|
|
int vx_pending; /* # of pending aux buffers */
|
1997-12-02 16:54:48 +03:00
|
|
|
int vx_flags;
|
|
|
|
#define VX_BUSY 1
|
1997-05-25 23:37:36 +04:00
|
|
|
};
|
|
|
|
|
1995-02-27 22:31:00 +03:00
|
|
|
struct vndbuf {
|
|
|
|
struct buf vb_buf;
|
1997-05-25 23:37:36 +04:00
|
|
|
struct vndxfer *vb_xfer;
|
1995-02-27 22:31:00 +03:00
|
|
|
};
|
1993-12-21 07:17:02 +03:00
|
|
|
|
1998-11-13 01:39:57 +03:00
|
|
|
#define VND_GETXFER(vnd) pool_get(&(vnd)->sc_vxpool, PR_NOWAIT)
|
1998-07-31 06:24:26 +04:00
|
|
|
#define VND_PUTXFER(vnd, vx) pool_put(&(vnd)->sc_vxpool, (vx))
|
|
|
|
|
1998-11-13 01:39:57 +03:00
|
|
|
#define VND_GETBUF(vnd) pool_get(&(vnd)->sc_vbpool, PR_NOWAIT)
|
1998-07-31 06:24:26 +04:00
|
|
|
#define VND_PUTBUF(vnd, vb) pool_put(&(vnd)->sc_vbpool, (vb))
|
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;
|
|
|
|
|
1997-06-24 01:03:55 +04:00
|
|
|
#define VNDLABELDEV(dev) \
|
|
|
|
(MAKEDISKDEV(major((dev)), vndunit((dev)), RAW_PART))
|
|
|
|
|
2002-11-16 11:10:48 +03:00
|
|
|
/* called by main() at boot time (XXX: and the LKM driver) */
|
1995-11-06 23:28:09 +03:00
|
|
|
void vndattach __P((int));
|
2002-11-16 11:10:48 +03:00
|
|
|
int vnddetach __P((void));
|
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
|
|
|
|
1997-10-09 03:05:22 +04:00
|
|
|
void vndgetdefaultlabel __P((struct vnd_softc *, struct disklabel *));
|
1997-06-24 01:03:55 +04:00
|
|
|
void vndgetdisklabel __P((dev_t));
|
|
|
|
|
1995-11-06 23:28:09 +03:00
|
|
|
static int vndlock __P((struct vnd_softc *));
|
|
|
|
static void vndunlock __P((struct vnd_softc *));
|
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_open(vndopen);
|
|
|
|
dev_type_close(vndclose);
|
|
|
|
dev_type_read(vndread);
|
|
|
|
dev_type_write(vndwrite);
|
|
|
|
dev_type_ioctl(vndioctl);
|
|
|
|
dev_type_strategy(vndstrategy);
|
|
|
|
dev_type_dump(vnddump);
|
|
|
|
dev_type_size(vndsize);
|
|
|
|
|
|
|
|
const struct bdevsw vnd_bdevsw = {
|
|
|
|
vndopen, vndclose, vndstrategy, vndioctl, vnddump, vndsize, D_DISK
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct cdevsw vnd_cdevsw = {
|
|
|
|
vndopen, vndclose, vndread, vndwrite, vndioctl,
|
2002-10-23 13:10:23 +04:00
|
|
|
nostop, notty, nopoll, nommap, nokqfilter, D_DISK
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
2002-11-16 11:10:48 +03:00
|
|
|
int vndattached = 0;
|
|
|
|
|
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;
|
|
|
|
{
|
2000-01-22 02:39:55 +03:00
|
|
|
int i;
|
1993-12-21 07:17:02 +03:00
|
|
|
char *mem;
|
|
|
|
|
2002-11-16 11:10:48 +03:00
|
|
|
if (vndattached)
|
|
|
|
return;
|
|
|
|
vndattached = 1;
|
1993-12-21 07:17:02 +03:00
|
|
|
if (num <= 0)
|
|
|
|
return;
|
2000-01-22 02:39:55 +03:00
|
|
|
i = num * sizeof(struct vnd_softc);
|
2002-01-13 22:28:06 +03:00
|
|
|
mem = malloc(i, M_DEVBUF, M_NOWAIT|M_ZERO);
|
1993-12-21 07:17:02 +03:00
|
|
|
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;
|
|
|
|
}
|
1995-01-25 07:45:38 +03:00
|
|
|
vnd_softc = (struct vnd_softc *)mem;
|
1993-12-21 07:17:02 +03:00
|
|
|
numvnd = num;
|
2000-01-22 02:39:55 +03:00
|
|
|
|
|
|
|
for (i = 0; i < numvnd; i++)
|
2002-07-21 19:32:17 +04:00
|
|
|
bufq_alloc(&vnd_softc[i].sc_tab,
|
|
|
|
BUFQ_DISKSORT|BUFQ_SORT_RAWBLOCK);
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
|
|
|
|
2002-11-16 11:10:48 +03:00
|
|
|
int
|
2002-01-04 09:31:08 +03:00
|
|
|
vnddetach()
|
|
|
|
{
|
2002-07-21 19:32:17 +04:00
|
|
|
int i;
|
|
|
|
|
2002-11-16 11:10:48 +03:00
|
|
|
/* First check we aren't in use. */
|
|
|
|
for (i = 0; i < numvnd; i++)
|
|
|
|
if (vnd_softc[i].sc_flags & VNF_INITED)
|
|
|
|
return (EBUSY);
|
|
|
|
|
2002-07-21 19:32:17 +04:00
|
|
|
for (i = 0; i < numvnd; i++)
|
|
|
|
bufq_free(&vnd_softc[i].sc_tab);
|
2002-01-04 09:31:08 +03:00
|
|
|
|
|
|
|
free(vnd_softc, M_DEVBUF);
|
2002-11-16 11:10:48 +03:00
|
|
|
vndattached = 0;
|
|
|
|
|
|
|
|
return (0);
|
2002-01-04 09:31:08 +03:00
|
|
|
}
|
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
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;
|
1997-06-24 01:03:55 +04:00
|
|
|
struct disklabel *lp;
|
1993-12-21 07:17:02 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnddebug & VDB_FOLLOW)
|
1997-08-04 14:00:11 +04:00
|
|
|
printf("vndopen(0x%x, 0x%x, 0x%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);
|
|
|
|
|
1997-06-24 01:03:55 +04:00
|
|
|
lp = sc->sc_dkdev.dk_label;
|
|
|
|
|
1995-11-06 23:28:09 +03:00
|
|
|
part = DISKPART(dev);
|
|
|
|
pmask = (1 << part);
|
|
|
|
|
1997-06-24 01:03:55 +04:00
|
|
|
/*
|
|
|
|
* If we're initialized, check to see if there are any other
|
|
|
|
* open partitions. If not, then it's safe to update the
|
|
|
|
* in-core disklabel.
|
|
|
|
*/
|
|
|
|
if ((sc->sc_flags & VNF_INITED) && (sc->sc_dkdev.dk_openmask == 0))
|
|
|
|
vndgetdisklabel(dev);
|
|
|
|
|
|
|
|
/* Check that the partitions exists. */
|
|
|
|
if (part != RAW_PART) {
|
|
|
|
if (((sc->sc_flags & VNF_INITED) == 0) ||
|
|
|
|
((part >= lp->d_npartitions) ||
|
|
|
|
(lp->d_partitions[part].p_fstype == FS_UNUSED))) {
|
|
|
|
error = ENXIO;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-11-06 23:28:09 +03:00
|
|
|
/* 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;
|
|
|
|
|
1997-06-24 01:03:55 +04:00
|
|
|
done:
|
1995-11-06 23:28:09 +03:00
|
|
|
vndunlock(sc);
|
1997-06-24 01:03:55 +04:00
|
|
|
return (error);
|
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)
|
1997-08-04 14:00:11 +04:00
|
|
|
printf("vndclose(0x%x, 0x%x, 0x%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.
|
|
|
|
*/
|
1994-05-11 08:26:17 +04:00
|
|
|
void
|
1995-01-25 07:45:38 +03:00
|
|
|
vndstrategy(bp)
|
2000-03-30 16:41:09 +04:00
|
|
|
struct buf *bp;
|
1993-12-21 07:17:02 +03:00
|
|
|
{
|
1995-01-25 07:45:38 +03:00
|
|
|
int unit = vndunit(bp->b_dev);
|
1997-05-26 02:27:16 +04:00
|
|
|
struct vnd_softc *vnd = &vnd_softc[unit];
|
1997-05-25 23:37:36 +04:00
|
|
|
struct vndxfer *vnx;
|
2000-09-12 12:03:24 +04:00
|
|
|
int s, bsize, resid;
|
|
|
|
off_t bn;
|
1997-05-26 02:27:16 +04:00
|
|
|
caddr_t addr;
|
1997-06-24 01:03:55 +04:00
|
|
|
int sz, flags, error, wlabel;
|
|
|
|
struct disklabel *lp;
|
|
|
|
struct partition *pp;
|
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;
|
1997-06-24 01:03:55 +04:00
|
|
|
goto done;
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
1997-06-24 01:03:55 +04:00
|
|
|
|
|
|
|
/* If it's a nil transfer, wake up the top half now. */
|
|
|
|
if (bp->b_bcount == 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
lp = vnd->sc_dkdev.dk_label;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The transfer must be a whole number of blocks.
|
|
|
|
*/
|
|
|
|
if ((bp->b_bcount % lp->d_secsize) != 0) {
|
|
|
|
bp->b_error = EINVAL;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do bounds checking and adjust transfer. If there's an error,
|
|
|
|
* the bounds check will flag that for us.
|
|
|
|
*/
|
|
|
|
wlabel = vnd->sc_flags & (VNF_WLABEL|VNF_LABELLING);
|
|
|
|
if (DISKPART(bp->b_dev) != RAW_PART)
|
|
|
|
if (bounds_check_with_label(bp, lp, wlabel) <= 0)
|
|
|
|
goto done;
|
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
bp->b_resid = bp->b_bcount;
|
1997-06-24 01:03:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Put the block number in terms of the logical blocksize
|
|
|
|
* of the "device".
|
|
|
|
*/
|
|
|
|
bn = bp->b_blkno / (lp->d_secsize / DEV_BSIZE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate the partition-relative block number to an absolute.
|
|
|
|
*/
|
|
|
|
if (DISKPART(bp->b_dev) != RAW_PART) {
|
|
|
|
pp = &vnd->sc_dkdev.dk_label->d_partitions[DISKPART(bp->b_dev)];
|
|
|
|
bn += pp->p_offset;
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
1997-06-24 01:03:55 +04:00
|
|
|
|
|
|
|
/* ...and convert to a byte offset within the file. */
|
|
|
|
bn *= lp->d_secsize;
|
|
|
|
|
2001-09-30 16:32:09 +04:00
|
|
|
if (vnd->sc_vp->v_mount == NULL) {
|
|
|
|
bp->b_error = ENXIO;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
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;
|
2000-08-19 14:44:02 +04:00
|
|
|
flags = (bp->b_flags & (B_READ|B_ASYNC)) | B_CALL;
|
1997-05-25 23:37:36 +04:00
|
|
|
|
|
|
|
/* Allocate a header for this transfer and link it to the buffer */
|
1999-04-22 02:14:15 +04:00
|
|
|
s = splbio();
|
1998-07-31 06:24:26 +04:00
|
|
|
vnx = VND_GETXFER(vnd);
|
1999-04-22 02:14:15 +04:00
|
|
|
splx(s);
|
1997-12-02 16:54:48 +03:00
|
|
|
vnx->vx_flags = VX_BUSY;
|
1997-05-25 23:37:36 +04:00
|
|
|
vnx->vx_error = 0;
|
|
|
|
vnx->vx_pending = 0;
|
|
|
|
vnx->vx_bp = bp;
|
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
for (resid = bp->b_resid; resid; resid -= sz) {
|
1997-12-02 16:54:48 +03:00
|
|
|
struct vndbuf *nbp;
|
1993-12-21 07:17:02 +03:00
|
|
|
struct vnode *vp;
|
|
|
|
daddr_t nbn;
|
1998-03-12 19:51:41 +03:00
|
|
|
int off, nra;
|
1993-12-21 07:17:02 +03:00
|
|
|
|
1994-04-20 09:01:22 +04:00
|
|
|
nra = 0;
|
1998-03-12 19:51:41 +03:00
|
|
|
vn_lock(vnd->sc_vp, LK_EXCLUSIVE | LK_RETRY | LK_CANRECURSE);
|
1995-01-25 07:45:38 +03:00
|
|
|
error = VOP_BMAP(vnd->sc_vp, bn / bsize, &vp, &nbn, &nra);
|
1998-03-12 19:51:41 +03:00
|
|
|
VOP_UNLOCK(vnd->sc_vp, 0);
|
1997-05-26 02:27:16 +04:00
|
|
|
|
1994-04-20 09:01:22 +04:00
|
|
|
if (error == 0 && (long)nbn == -1)
|
|
|
|
error = EIO;
|
1997-05-25 23:37:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If there was an error or a hole in the file...punt.
|
|
|
|
* Note that we may have to wait for any operations
|
|
|
|
* that we have already fired off before releasing
|
|
|
|
* the buffer.
|
|
|
|
*
|
|
|
|
* XXX we could deal with holes here but it would be
|
|
|
|
* a hassle (in the write case).
|
|
|
|
*/
|
1997-06-08 19:59:41 +04:00
|
|
|
if (error) {
|
1997-06-08 19:55:34 +04:00
|
|
|
s = splbio();
|
1997-12-02 16:54:48 +03:00
|
|
|
vnx->vx_error = error;
|
|
|
|
goto out;
|
1997-05-25 23:37:36 +04:00
|
|
|
}
|
|
|
|
|
1994-04-20 09:01:22 +04:00
|
|
|
#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)
|
2000-09-12 12:03:24 +04:00
|
|
|
printf("vndstrategy: vp %p/%p bn 0x%qx/0x%x sz 0x%x\n",
|
|
|
|
vnd->sc_vp, vp, (long long)bn, nbn, sz);
|
1993-12-21 07:17:02 +03:00
|
|
|
#endif
|
1994-04-20 09:01:22 +04:00
|
|
|
|
1999-04-22 02:14:15 +04:00
|
|
|
s = splbio();
|
1998-07-31 06:24:26 +04:00
|
|
|
nbp = VND_GETBUF(vnd);
|
1999-04-22 02:14:15 +04:00
|
|
|
splx(s);
|
1995-02-27 22:31:00 +03:00
|
|
|
nbp->vb_buf.b_flags = flags;
|
|
|
|
nbp->vb_buf.b_bcount = sz;
|
2002-05-02 20:25:23 +04:00
|
|
|
nbp->vb_buf.b_bufsize = round_page((ulong)addr + sz)
|
|
|
|
- trunc_page((ulong) addr);
|
1995-02-27 22:31:00 +03:00
|
|
|
nbp->vb_buf.b_error = 0;
|
|
|
|
nbp->vb_buf.b_data = addr;
|
2000-02-07 23:16:47 +03:00
|
|
|
nbp->vb_buf.b_blkno = nbp->vb_buf.b_rawblkno = nbn + btodb(off);
|
1995-02-27 22:31:00 +03:00
|
|
|
nbp->vb_buf.b_proc = bp->b_proc;
|
|
|
|
nbp->vb_buf.b_iodone = vndiodone;
|
1997-12-02 16:54:48 +03:00
|
|
|
nbp->vb_buf.b_vp = NULLVP;
|
1999-11-17 12:34:03 +03:00
|
|
|
LIST_INIT(&nbp->vb_buf.b_dep);
|
1995-02-27 22:31:00 +03:00
|
|
|
|
1997-05-25 23:37:36 +04:00
|
|
|
nbp->vb_xfer = vnx;
|
1995-02-27 22:31:00 +03:00
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
/*
|
|
|
|
* Just sort by block number
|
|
|
|
*/
|
|
|
|
s = splbio();
|
1997-12-02 16:54:48 +03:00
|
|
|
if (vnx->vx_error != 0) {
|
1998-07-31 06:24:26 +04:00
|
|
|
VND_PUTBUF(vnd, nbp);
|
1997-12-02 16:54:48 +03:00
|
|
|
goto out;
|
|
|
|
}
|
1997-06-08 19:55:34 +04:00
|
|
|
vnx->vx_pending++;
|
1997-12-02 16:54:48 +03:00
|
|
|
bgetvp(vp, &nbp->vb_buf);
|
2002-07-20 15:28:07 +04:00
|
|
|
BUFQ_PUT(&vnd->sc_tab, &nbp->vb_buf);
|
1997-12-02 16:54:48 +03:00
|
|
|
vndstart(vnd);
|
1993-12-21 07:17:02 +03:00
|
|
|
splx(s);
|
|
|
|
bn += sz;
|
|
|
|
addr += sz;
|
|
|
|
}
|
1997-12-02 16:54:48 +03:00
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
|
|
|
|
out: /* Arrive here at splbio */
|
|
|
|
vnx->vx_flags &= ~VX_BUSY;
|
|
|
|
if (vnx->vx_pending == 0) {
|
|
|
|
if (vnx->vx_error != 0) {
|
|
|
|
bp->b_error = vnx->vx_error;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
}
|
1998-07-31 06:24:26 +04:00
|
|
|
VND_PUTXFER(vnd, vnx);
|
1997-12-02 16:54:48 +03:00
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
splx(s);
|
1997-06-24 01:03:55 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
done:
|
|
|
|
biodone(bp);
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
2000-03-30 16:41:09 +04:00
|
|
|
struct vnd_softc *vnd;
|
1993-12-21 07:17:02 +03:00
|
|
|
{
|
1997-12-02 16:54:48 +03:00
|
|
|
struct buf *bp;
|
1993-12-21 07:17:02 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Dequeue now since lower level strategy routine might
|
|
|
|
* queue using same links
|
|
|
|
*/
|
1997-12-02 16:54:48 +03:00
|
|
|
|
|
|
|
if ((vnd->sc_flags & VNF_BUSY) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vnd->sc_flags |= VNF_BUSY;
|
|
|
|
|
2000-01-22 02:39:55 +03:00
|
|
|
while (vnd->sc_active < vnd->sc_maxactive) {
|
2002-07-20 15:28:07 +04:00
|
|
|
bp = BUFQ_GET(&vnd->sc_tab);
|
1997-12-02 16:54:48 +03:00
|
|
|
if (bp == NULL)
|
|
|
|
break;
|
2000-01-22 02:39:55 +03:00
|
|
|
vnd->sc_active++;
|
1993-12-21 07:17:02 +03:00
|
|
|
#ifdef DEBUG
|
1997-12-02 16:54:48 +03:00
|
|
|
if (vnddebug & VDB_IO)
|
2000-08-19 14:44:02 +04:00
|
|
|
printf("vndstart(%ld): bp %p vp %p blkno 0x%x"
|
2000-08-20 15:51:52 +04:00
|
|
|
" flags %lx addr %p cnt 0x%lx\n",
|
1997-12-02 16:54:48 +03:00
|
|
|
(long) (vnd-vnd_softc), bp, bp->b_vp, bp->b_blkno,
|
2000-08-19 14:44:02 +04:00
|
|
|
bp->b_flags, bp->b_data, bp->b_bcount);
|
1993-12-21 07:17:02 +03:00
|
|
|
#endif
|
1996-01-08 01:01:38 +03:00
|
|
|
|
1997-12-02 16:54:48 +03:00
|
|
|
/* Instrumentation. */
|
|
|
|
disk_busy(&vnd->sc_dkdev);
|
1996-01-08 01:01:38 +03:00
|
|
|
|
1997-12-02 16:54:48 +03:00
|
|
|
if ((bp->b_flags & B_READ) == 0)
|
|
|
|
bp->b_vp->v_numoutput++;
|
|
|
|
VOP_STRATEGY(bp);
|
|
|
|
}
|
|
|
|
vnd->sc_flags &= ~VNF_BUSY;
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1996-02-10 03:11:44 +03:00
|
|
|
vndiodone(bp)
|
|
|
|
struct buf *bp;
|
1993-12-21 07:17:02 +03:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct vndbuf *vbp = (struct vndbuf *) bp;
|
|
|
|
struct vndxfer *vnx = (struct vndxfer *)vbp->vb_xfer;
|
|
|
|
struct buf *pbp = vnx->vx_bp;
|
|
|
|
struct vnd_softc *vnd = &vnd_softc[vndunit(pbp->b_dev)];
|
1997-05-25 23:37:36 +04:00
|
|
|
int s, resid;
|
1993-12-21 07:17:02 +03:00
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnddebug & VDB_IO)
|
1997-08-04 14:00:11 +04:00
|
|
|
printf("vndiodone(%ld): vbp %p vp %p blkno 0x%x addr %p cnt 0x%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
|
|
|
|
1997-05-25 23:37:36 +04:00
|
|
|
resid = vbp->vb_buf.b_bcount - vbp->vb_buf.b_resid;
|
|
|
|
pbp->b_resid -= resid;
|
2002-11-01 14:31:50 +03:00
|
|
|
disk_unbusy(&vnd->sc_dkdev, resid, (pbp->b_flags & B_READ));
|
1997-05-25 23:37:36 +04:00
|
|
|
vnx->vx_pending--;
|
|
|
|
|
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
|
1997-05-25 23:37:36 +04:00
|
|
|
vnx->vx_error = vbp->vb_buf.b_error;
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
1997-12-02 16:54:48 +03:00
|
|
|
|
|
|
|
if (vbp->vb_buf.b_vp != NULLVP)
|
|
|
|
brelvp(&vbp->vb_buf);
|
|
|
|
|
1998-07-31 06:24:26 +04:00
|
|
|
VND_PUTBUF(vnd, vbp);
|
1997-05-25 23:37:36 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wrap up this transaction if it has run to completion or, in
|
|
|
|
* case of an error, when all auxiliary buffers have returned.
|
|
|
|
*/
|
1997-12-02 16:54:48 +03:00
|
|
|
if (vnx->vx_error != 0) {
|
|
|
|
pbp->b_flags |= B_ERROR;
|
|
|
|
pbp->b_error = vnx->vx_error;
|
|
|
|
if ((vnx->vx_flags & VX_BUSY) == 0 && vnx->vx_pending == 0) {
|
1997-05-25 23:37:36 +04:00
|
|
|
|
1997-12-02 16:54:48 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (vnddebug & VDB_IO)
|
|
|
|
printf("vndiodone: pbp %p iodone: error %d\n",
|
|
|
|
pbp, vnx->vx_error);
|
|
|
|
#endif
|
1998-07-31 06:24:26 +04:00
|
|
|
VND_PUTXFER(vnd, vnx);
|
1997-12-02 16:54:48 +03:00
|
|
|
biodone(pbp);
|
1997-05-25 23:37:36 +04:00
|
|
|
}
|
1997-12-02 16:54:48 +03:00
|
|
|
} else if (pbp->b_resid == 0) {
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (vnx->vx_pending != 0)
|
1997-12-31 05:46:51 +03:00
|
|
|
panic("vndiodone: vnx pending: %d", vnx->vx_pending);
|
1997-12-02 16:54:48 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((vnx->vx_flags & VX_BUSY) == 0) {
|
1993-12-21 07:17:02 +03:00
|
|
|
#ifdef DEBUG
|
1997-12-02 16:54:48 +03:00
|
|
|
if (vnddebug & VDB_IO)
|
|
|
|
printf("vndiodone: pbp %p iodone\n", pbp);
|
1993-12-21 07:17:02 +03:00
|
|
|
#endif
|
1998-07-31 06:24:26 +04:00
|
|
|
VND_PUTXFER(vnd, vnx);
|
1997-12-02 16:54:48 +03:00
|
|
|
biodone(pbp);
|
|
|
|
}
|
1993-12-21 07:17:02 +03:00
|
|
|
}
|
1997-05-25 23:37:36 +04:00
|
|
|
|
2000-01-22 02:39:55 +03:00
|
|
|
vnd->sc_active--;
|
1997-12-02 16:54:48 +03:00
|
|
|
vndstart(vnd);
|
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)
|
1997-08-04 14:00:11 +04:00
|
|
|
printf("vndread(0x%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)
|
1997-08-04 14:00:11 +04:00
|
|
|
printf("vndwrite(0x%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);
|
2000-03-30 16:41:09 +04:00
|
|
|
struct vnd_softc *vnd;
|
1995-01-25 07:45:38 +03:00
|
|
|
struct vnd_ioctl *vio;
|
1993-12-21 07:17:02 +03:00
|
|
|
struct vattr vattr;
|
|
|
|
struct nameidata nd;
|
1997-03-13 01:31:37 +03:00
|
|
|
int error, part, pmask;
|
1997-06-24 01:03:55 +04:00
|
|
|
size_t geomsize;
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
struct disklabel newlabel;
|
|
|
|
#endif
|
1993-12-21 07:17:02 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1995-01-25 07:45:38 +03:00
|
|
|
if (vnddebug & VDB_FOLLOW)
|
1997-08-04 14:00:11 +04:00
|
|
|
printf("vndioctl(0x%x, 0x%lx, %p, 0x%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;
|
1997-06-26 08:16:31 +04:00
|
|
|
|
|
|
|
/* Must be open for writes for these commands... */
|
|
|
|
switch (cmd) {
|
|
|
|
case VNDIOCSET:
|
|
|
|
case VNDIOCCLR:
|
|
|
|
case DIOCSDINFO:
|
|
|
|
case DIOCWDINFO:
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCSDINFO:
|
|
|
|
case ODIOCWDINFO:
|
|
|
|
#endif
|
1997-06-26 08:16:31 +04:00
|
|
|
case DIOCWLABEL:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EBADF);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be initialized for these... */
|
1993-12-21 07:17:02 +03:00
|
|
|
switch (cmd) {
|
1997-06-26 08:16:31 +04:00
|
|
|
case VNDIOCCLR:
|
1997-06-26 20:28:34 +04:00
|
|
|
case DIOCGDINFO:
|
1997-06-26 08:16:31 +04:00
|
|
|
case DIOCSDINFO:
|
|
|
|
case DIOCWDINFO:
|
|
|
|
case DIOCGPART:
|
|
|
|
case DIOCWLABEL:
|
1997-10-09 03:05:22 +04:00
|
|
|
case DIOCGDEFLABEL:
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCGDINFO:
|
|
|
|
case ODIOCSDINFO:
|
|
|
|
case ODIOCWDINFO:
|
|
|
|
case ODIOCGDEFLABEL:
|
|
|
|
#endif
|
1997-06-26 08:16:31 +04:00
|
|
|
if ((vnd->sc_flags & VNF_INITED) == 0)
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
1993-12-21 07:17:02 +03:00
|
|
|
|
1997-06-26 08:16:31 +04: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);
|
2002-07-26 10:16:32 +04:00
|
|
|
if ((error = vn_open(&nd, FREAD|FWRITE, 0)) != 0)
|
|
|
|
goto unlock_and_exit;
|
1996-02-10 03:11:44 +03:00
|
|
|
error = VOP_GETATTR(nd.ni_vp, &vattr, p->p_ucred, p);
|
1998-03-01 05:20:01 +03:00
|
|
|
VOP_UNLOCK(nd.ni_vp, 0);
|
2002-07-26 10:16:32 +04:00
|
|
|
if (error)
|
|
|
|
goto close_and_exit;
|
1995-01-25 07:45:38 +03:00
|
|
|
vnd->sc_vp = nd.ni_vp;
|
|
|
|
vnd->sc_size = btodb(vattr.va_size); /* note truncation */
|
1997-06-24 01:03:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Use pseudo-geometry specified. If none was provided,
|
|
|
|
* use "standard" Adaptec fictitious geometry.
|
|
|
|
*/
|
|
|
|
if (vio->vnd_flags & VNDIOF_HASGEOM) {
|
|
|
|
|
2001-07-07 21:04:01 +04:00
|
|
|
memcpy(&vnd->sc_geom, &vio->vnd_geom,
|
1997-06-24 01:03:55 +04:00
|
|
|
sizeof(vio->vnd_geom));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanity-check the sector size.
|
|
|
|
* XXX Don't allow secsize < DEV_BSIZE. Should
|
|
|
|
* XXX we?
|
|
|
|
*/
|
|
|
|
if (vnd->sc_geom.vng_secsize < DEV_BSIZE ||
|
|
|
|
(vnd->sc_geom.vng_secsize % DEV_BSIZE) != 0) {
|
2002-07-26 10:16:32 +04:00
|
|
|
error = EINVAL;
|
|
|
|
goto close_and_exit;
|
1997-06-24 01:03:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the size (in DEV_BSIZE blocks) specified
|
|
|
|
* by the geometry.
|
|
|
|
*/
|
|
|
|
geomsize = (vnd->sc_geom.vng_nsectors *
|
|
|
|
vnd->sc_geom.vng_ntracks *
|
|
|
|
vnd->sc_geom.vng_ncylinders) *
|
|
|
|
(vnd->sc_geom.vng_secsize / DEV_BSIZE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanity-check the size against the specified
|
|
|
|
* geometry.
|
|
|
|
*/
|
|
|
|
if (vnd->sc_size < geomsize) {
|
2002-07-26 10:16:32 +04:00
|
|
|
error = EINVAL;
|
|
|
|
goto close_and_exit;
|
1997-06-24 01:03:55 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Size must be at least 2048 DEV_BSIZE blocks
|
|
|
|
* (1M) in order to use this geometry.
|
|
|
|
*/
|
1997-08-26 22:12:58 +04:00
|
|
|
if (vnd->sc_size < (32 * 64)) {
|
2002-07-26 10:16:32 +04:00
|
|
|
error = EINVAL;
|
|
|
|
goto close_and_exit;
|
1997-08-26 22:12:58 +04:00
|
|
|
}
|
1997-06-24 01:03:55 +04:00
|
|
|
|
|
|
|
vnd->sc_geom.vng_secsize = DEV_BSIZE;
|
|
|
|
vnd->sc_geom.vng_nsectors = 32;
|
|
|
|
vnd->sc_geom.vng_ntracks = 64;
|
|
|
|
vnd->sc_geom.vng_ncylinders = vnd->sc_size / (64 * 32);
|
|
|
|
}
|
|
|
|
|
2002-07-26 10:16:32 +04:00
|
|
|
if ((error = vndsetcred(vnd, p->p_ucred)) != 0)
|
|
|
|
goto close_and_exit;
|
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)
|
1997-08-04 14:00:11 +04:00
|
|
|
printf("vndioctl: SET vp %p size 0x%lx %d/%d/%d/%d\n",
|
1997-06-24 01:03:55 +04:00
|
|
|
vnd->sc_vp, (unsigned long) vnd->sc_size,
|
|
|
|
vnd->sc_geom.vng_secsize,
|
|
|
|
vnd->sc_geom.vng_nsectors,
|
|
|
|
vnd->sc_geom.vng_ntracks,
|
|
|
|
vnd->sc_geom.vng_ncylinders);
|
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. */
|
2001-07-07 21:04:01 +04:00
|
|
|
memset(vnd->sc_xname, 0, 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);
|
|
|
|
|
1998-07-31 06:24:26 +04:00
|
|
|
/* Initialize the xfer and buffer pools. */
|
|
|
|
pool_init(&vnd->sc_vxpool, sizeof(struct vndxfer), 0,
|
2002-03-08 23:48:27 +03:00
|
|
|
0, 0, "vndxpl", NULL);
|
1998-07-31 06:24:26 +04:00
|
|
|
pool_init(&vnd->sc_vbpool, sizeof(struct vndbuf), 0,
|
2002-03-08 23:48:27 +03:00
|
|
|
0, 0, "vndbpl", NULL);
|
1998-07-31 06:24:26 +04:00
|
|
|
|
1997-06-24 01:03:55 +04:00
|
|
|
/* Try and read the disklabel. */
|
|
|
|
vndgetdisklabel(dev);
|
|
|
|
|
1995-11-06 23:28:09 +03:00
|
|
|
vndunlock(vnd);
|
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
break;
|
|
|
|
|
2002-07-26 10:16:32 +04:00
|
|
|
close_and_exit:
|
|
|
|
(void) vn_close(nd.ni_vp, FREAD|FWRITE, p->p_ucred, p);
|
|
|
|
unlock_and_exit:
|
|
|
|
vndunlock(vnd);
|
|
|
|
return (error);
|
|
|
|
|
1995-01-25 07:45:38 +03:00
|
|
|
case VNDIOCCLR:
|
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
|
|
|
|
1998-07-31 06:24:26 +04:00
|
|
|
/* Destroy the xfer and buffer pools. */
|
|
|
|
pool_destroy(&vnd->sc_vxpool);
|
|
|
|
pool_destroy(&vnd->sc_vbpool);
|
|
|
|
|
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
|
|
|
vndunlock(vnd);
|
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
break;
|
|
|
|
|
2002-06-21 23:09:29 +04:00
|
|
|
case VNDIOCGET: {
|
|
|
|
struct vnd_user *vnu;
|
|
|
|
struct vattr va;
|
|
|
|
|
|
|
|
vnu = (struct vnd_user *)data;
|
|
|
|
|
|
|
|
if (vnu->vnu_unit == -1)
|
|
|
|
vnu->vnu_unit = unit;
|
|
|
|
if (vnu->vnu_unit >= numvnd)
|
|
|
|
return (ENXIO);
|
|
|
|
if (vnu->vnu_unit < 0)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
vnd = &vnd_softc[vnu->vnu_unit];
|
|
|
|
|
|
|
|
if (vnd->sc_flags & VNF_INITED) {
|
|
|
|
error = VOP_GETATTR(vnd->sc_vp, &va, p->p_ucred, p);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
vnu->vnu_dev = va.va_fsid;
|
|
|
|
vnu->vnu_ino = va.va_fileid;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* unused is not an error */
|
|
|
|
vnu->vnu_dev = 0;
|
|
|
|
vnu->vnu_ino = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1997-06-24 01:03:55 +04:00
|
|
|
case DIOCGDINFO:
|
|
|
|
*(struct disklabel *)data = *(vnd->sc_dkdev.dk_label);
|
|
|
|
break;
|
|
|
|
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCGDINFO:
|
|
|
|
newlabel = *(vnd->sc_dkdev.dk_label);
|
|
|
|
if (newlabel.d_npartitions > OLDMAXPARTITIONS)
|
2001-01-08 05:03:45 +03:00
|
|
|
return ENOTTY;
|
2001-01-07 21:09:01 +03:00
|
|
|
memcpy(data, &newlabel, sizeof (struct olddisklabel));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
1997-06-24 01:03:55 +04:00
|
|
|
case DIOCGPART:
|
|
|
|
((struct partinfo *)data)->disklab = vnd->sc_dkdev.dk_label;
|
|
|
|
((struct partinfo *)data)->part =
|
|
|
|
&vnd->sc_dkdev.dk_label->d_partitions[DISKPART(dev)];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIOCWDINFO:
|
|
|
|
case DIOCSDINFO:
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCWDINFO:
|
|
|
|
case ODIOCSDINFO:
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
struct disklabel *lp;
|
|
|
|
|
1997-06-24 01:03:55 +04:00
|
|
|
if ((error = vndlock(vnd)) != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
vnd->sc_flags |= VNF_LABELLING;
|
|
|
|
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
if (cmd == ODIOCSDINFO || cmd == ODIOCWDINFO) {
|
|
|
|
memset(&newlabel, 0, sizeof newlabel);
|
|
|
|
memcpy(&newlabel, data, sizeof (struct olddisklabel));
|
|
|
|
lp = &newlabel;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
lp = (struct disklabel *)data;
|
|
|
|
|
1997-06-24 01:03:55 +04:00
|
|
|
error = setdisklabel(vnd->sc_dkdev.dk_label,
|
2001-01-07 21:09:01 +03:00
|
|
|
lp, 0, vnd->sc_dkdev.dk_cpulabel);
|
1997-06-24 01:03:55 +04:00
|
|
|
if (error == 0) {
|
2001-01-07 21:09:01 +03:00
|
|
|
if (cmd == DIOCWDINFO
|
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
|| cmd == ODIOCWDINFO
|
|
|
|
#endif
|
|
|
|
)
|
1997-06-24 01:03:55 +04:00
|
|
|
error = writedisklabel(VNDLABELDEV(dev),
|
|
|
|
vndstrategy, vnd->sc_dkdev.dk_label,
|
|
|
|
vnd->sc_dkdev.dk_cpulabel);
|
|
|
|
}
|
|
|
|
|
|
|
|
vnd->sc_flags &= ~VNF_LABELLING;
|
|
|
|
|
|
|
|
vndunlock(vnd);
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
break;
|
2001-01-07 21:09:01 +03:00
|
|
|
}
|
1997-06-24 01:03:55 +04:00
|
|
|
|
|
|
|
case DIOCWLABEL:
|
|
|
|
if (*(int *)data != 0)
|
|
|
|
vnd->sc_flags |= VNF_WLABEL;
|
|
|
|
else
|
|
|
|
vnd->sc_flags &= ~VNF_WLABEL;
|
|
|
|
break;
|
1995-11-06 23:28:09 +03:00
|
|
|
|
1997-10-09 03:05:22 +04:00
|
|
|
case DIOCGDEFLABEL:
|
|
|
|
vndgetdefaultlabel(vnd, (struct disklabel *)data);
|
|
|
|
break;
|
|
|
|
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCGDEFLABEL:
|
|
|
|
vndgetdefaultlabel(vnd, &newlabel);
|
|
|
|
if (newlabel.d_npartitions > OLDMAXPARTITIONS)
|
2001-01-08 05:03:45 +03:00
|
|
|
return ENOTTY;
|
2001-01-07 21:09:01 +03:00
|
|
|
memcpy(data, &newlabel, sizeof (struct olddisklabel));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
1993-12-21 07:17:02 +03:00
|
|
|
default:
|
1997-06-24 01:03:55 +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)
|
2000-03-30 16:41:09 +04:00
|
|
|
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;
|
1998-03-01 05:20:01 +03:00
|
|
|
vn_lock(vnd->sc_vp, LK_EXCLUSIVE | LK_RETRY);
|
1995-01-25 07:45:38 +03:00
|
|
|
error = VOP_READ(vnd->sc_vp, &auio, 0, vnd->sc_cred);
|
1998-01-27 02:30:44 +03:00
|
|
|
if (error == 0) {
|
|
|
|
/*
|
|
|
|
* Because vnd does all IO directly through the vnode
|
1998-03-01 05:20:01 +03:00
|
|
|
* we need to flush (at least) the buffer from the above
|
1998-01-27 02:30:44 +03:00
|
|
|
* VOP_READ from the buffer cache to prevent cache
|
|
|
|
* incoherencies. Also, be careful to write dirty
|
|
|
|
* buffers back to stable storage.
|
|
|
|
*/
|
|
|
|
error = vinvalbuf(vnd->sc_vp, V_SAVE, vnd->sc_cred,
|
1998-03-01 05:20:01 +03:00
|
|
|
curproc, 0, 0);
|
1998-01-27 02:30:44 +03:00
|
|
|
}
|
1998-03-01 05:20:01 +03:00
|
|
|
VOP_UNLOCK(vnd->sc_vp, 0);
|
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)
|
2000-03-30 16:41:09 +04:00
|
|
|
struct vnd_softc *vnd;
|
1993-12-21 07:17:02 +03:00
|
|
|
struct vnode *vp;
|
|
|
|
{
|
1997-01-31 08:18:51 +03:00
|
|
|
#ifdef NFS
|
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
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
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)
|
2000-03-30 16:41:09 +04:00
|
|
|
struct vnd_softc *vnd;
|
1993-12-21 07:17:02 +03:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
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;
|
|
|
|
{
|
1997-06-24 01:03:55 +04:00
|
|
|
struct vnd_softc *sc;
|
|
|
|
struct disklabel *lp;
|
|
|
|
int part, unit, omask;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
unit = vndunit(dev);
|
|
|
|
if (unit >= numvnd)
|
|
|
|
return (-1);
|
|
|
|
sc = &vnd_softc[unit];
|
|
|
|
|
|
|
|
if ((sc->sc_flags & VNF_INITED) == 0)
|
|
|
|
return (-1);
|
1993-12-21 07:17:02 +03:00
|
|
|
|
1997-06-24 01:03:55 +04:00
|
|
|
part = DISKPART(dev);
|
|
|
|
omask = sc->sc_dkdev.dk_openmask & (1 << part);
|
|
|
|
lp = sc->sc_dkdev.dk_label;
|
|
|
|
|
|
|
|
if (omask == 0 && vndopen(dev, 0, S_IFBLK, curproc))
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
if (lp->d_partitions[part].p_fstype != FS_SWAP)
|
|
|
|
size = -1;
|
|
|
|
else
|
|
|
|
size = lp->d_partitions[part].p_size *
|
|
|
|
(lp->d_secsize / DEV_BSIZE);
|
|
|
|
|
|
|
|
if (omask == 0 && vndclose(dev, 0, S_IFBLK, curproc))
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
return (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
|
|
|
|
1997-06-24 01:03:55 +04:00
|
|
|
void
|
1997-10-09 03:05:22 +04:00
|
|
|
vndgetdefaultlabel(sc, lp)
|
|
|
|
struct vnd_softc *sc;
|
|
|
|
struct disklabel *lp;
|
1997-06-24 01:03:55 +04:00
|
|
|
{
|
|
|
|
struct vndgeom *vng = &sc->sc_geom;
|
|
|
|
struct partition *pp;
|
|
|
|
|
2001-07-07 21:04:01 +04:00
|
|
|
memset(lp, 0, sizeof(*lp));
|
1997-06-24 01:03:55 +04:00
|
|
|
|
|
|
|
lp->d_secperunit = sc->sc_size / (vng->vng_secsize / DEV_BSIZE);
|
|
|
|
lp->d_secsize = vng->vng_secsize;
|
|
|
|
lp->d_nsectors = vng->vng_nsectors;
|
|
|
|
lp->d_ntracks = vng->vng_ntracks;
|
|
|
|
lp->d_ncylinders = vng->vng_ncylinders;
|
|
|
|
lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
|
|
|
|
|
|
|
|
strncpy(lp->d_typename, "vnd", sizeof(lp->d_typename));
|
|
|
|
lp->d_type = DTYPE_VND;
|
|
|
|
strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname));
|
|
|
|
lp->d_rpm = 3600;
|
|
|
|
lp->d_interleave = 1;
|
|
|
|
lp->d_flags = 0;
|
|
|
|
|
|
|
|
pp = &lp->d_partitions[RAW_PART];
|
|
|
|
pp->p_offset = 0;
|
|
|
|
pp->p_size = lp->d_secperunit;
|
|
|
|
pp->p_fstype = FS_UNUSED;
|
|
|
|
lp->d_npartitions = RAW_PART + 1;
|
|
|
|
|
|
|
|
lp->d_magic = DISKMAGIC;
|
|
|
|
lp->d_magic2 = DISKMAGIC;
|
|
|
|
lp->d_checksum = dkcksum(lp);
|
1997-10-09 03:05:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the disklabel from a vnd. If one is not present, create a fake one.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vndgetdisklabel(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
|
|
|
struct vnd_softc *sc = &vnd_softc[vndunit(dev)];
|
|
|
|
char *errstring;
|
|
|
|
struct disklabel *lp = sc->sc_dkdev.dk_label;
|
|
|
|
struct cpu_disklabel *clp = sc->sc_dkdev.dk_cpulabel;
|
|
|
|
int i;
|
|
|
|
|
2001-07-07 21:04:01 +04:00
|
|
|
memset(clp, 0, sizeof(*clp));
|
1997-10-09 03:05:22 +04:00
|
|
|
|
|
|
|
vndgetdefaultlabel(sc, lp);
|
1997-06-24 01:03:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the generic disklabel extraction routine.
|
|
|
|
*/
|
|
|
|
errstring = readdisklabel(VNDLABELDEV(dev), vndstrategy, lp, clp);
|
|
|
|
if (errstring) {
|
|
|
|
/*
|
|
|
|
* Lack of disklabel is common, but we print the warning
|
|
|
|
* anyway, since it might contain other useful information.
|
|
|
|
*/
|
|
|
|
printf("%s: %s\n", sc->sc_xname, errstring);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For historical reasons, if there's no disklabel
|
|
|
|
* present, all partitions must be FS_BSDFFS and
|
|
|
|
* occupy the entire disk.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < MAXPARTITIONS; i++) {
|
1997-12-31 05:38:24 +03:00
|
|
|
/*
|
|
|
|
* Don't wipe out port specific hack (such as
|
|
|
|
* dos partition hack of i386 port).
|
|
|
|
*/
|
|
|
|
if (lp->d_partitions[i].p_fstype != FS_UNUSED)
|
|
|
|
continue;
|
|
|
|
|
1997-06-24 01:03:55 +04:00
|
|
|
lp->d_partitions[i].p_size = lp->d_secperunit;
|
|
|
|
lp->d_partitions[i].p_offset = 0;
|
|
|
|
lp->d_partitions[i].p_fstype = FS_BSDFFS;
|
|
|
|
}
|
|
|
|
|
|
|
|
strncpy(lp->d_packname, "default label",
|
|
|
|
sizeof(lp->d_packname));
|
1997-10-09 03:05:22 +04:00
|
|
|
|
|
|
|
lp->d_checksum = dkcksum(lp);
|
1997-06-24 01:03:55 +04: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);
|
|
|
|
}
|
|
|
|
}
|