- use the raw partition for ioctl; `control device' is gone.
- remove `sc_flags' member from md_softc - add check code whether the md device is configured in mdread/mdwrite
This commit is contained in:
parent
7d6a332830
commit
a914ad6061
150
sys/dev/md.c
150
sys/dev/md.c
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: md.c,v 1.20 1999/03/24 05:51:20 mrg Exp $ */
|
/* $NetBSD: md.c,v 1.21 2000/01/21 12:14:53 tsutsui Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1995 Gordon W. Ross, Leo Weppelman.
|
* Copyright (c) 1995 Gordon W. Ross, Leo Weppelman.
|
||||||
|
@ -73,16 +73,10 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XXX: the "control" unit is (base unit + 16).
|
* We should use the raw partition for ioctl.
|
||||||
* We should just use the cdev as the "control", but
|
|
||||||
* that interferes with the security stuff preventing
|
|
||||||
* simulatneous use of raw and block devices.
|
|
||||||
*
|
|
||||||
* XXX Assumption: 16 memory-disks are enough!
|
|
||||||
*/
|
*/
|
||||||
#define MD_MAX_UNITS 0x10
|
#define MD_MAX_UNITS 0x10
|
||||||
#define MD_IS_CTRL(unit) (unit & 0x10)
|
#define MD_UNIT(unit) DISKUNIT(unit)
|
||||||
#define MD_UNIT(unit) (unit & 0xF)
|
|
||||||
|
|
||||||
/* autoconfig stuff... */
|
/* autoconfig stuff... */
|
||||||
|
|
||||||
|
@ -91,15 +85,11 @@ struct md_softc {
|
||||||
struct disk sc_dkdev; /* hook for generic disk handling */
|
struct disk sc_dkdev; /* hook for generic disk handling */
|
||||||
struct md_conf sc_md;
|
struct md_conf sc_md;
|
||||||
struct buf *sc_buflist;
|
struct buf *sc_buflist;
|
||||||
int sc_flags;
|
|
||||||
};
|
};
|
||||||
/* shorthand for fields in sc_md: */
|
/* shorthand for fields in sc_md: */
|
||||||
#define sc_addr sc_md.md_addr
|
#define sc_addr sc_md.md_addr
|
||||||
#define sc_size sc_md.md_size
|
#define sc_size sc_md.md_size
|
||||||
#define sc_type sc_md.md_type
|
#define sc_type sc_md.md_type
|
||||||
/* flags */
|
|
||||||
#define MD_ISOPEN 0x01
|
|
||||||
#define MD_SERVED 0x02
|
|
||||||
|
|
||||||
void mdattach __P((int));
|
void mdattach __P((int));
|
||||||
static void md_attach __P((struct device *, struct device *, void *));
|
static void md_attach __P((struct device *, struct device *, void *));
|
||||||
|
@ -197,7 +187,8 @@ dev_type_ioctl(mdioctl);
|
||||||
dev_type_size(mdsize);
|
dev_type_size(mdsize);
|
||||||
dev_type_dump(mddump);
|
dev_type_dump(mddump);
|
||||||
|
|
||||||
int mddump(dev, blkno, va, size)
|
int
|
||||||
|
mddump(dev, blkno, va, size)
|
||||||
dev_t dev;
|
dev_t dev;
|
||||||
daddr_t blkno;
|
daddr_t blkno;
|
||||||
caddr_t va;
|
caddr_t va;
|
||||||
|
@ -206,13 +197,13 @@ int mddump(dev, blkno, va, size)
|
||||||
return ENODEV;
|
return ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mdsize(dev_t dev)
|
int
|
||||||
|
mdsize(dev_t dev)
|
||||||
{
|
{
|
||||||
int unit;
|
int unit;
|
||||||
struct md_softc *sc;
|
struct md_softc *sc;
|
||||||
|
|
||||||
/* Disallow control units. */
|
unit = MD_UNIT(dev);
|
||||||
unit = DISKUNIT(dev);
|
|
||||||
if (unit >= ramdisk_ndevs)
|
if (unit >= ramdisk_ndevs)
|
||||||
return 0;
|
return 0;
|
||||||
sc = ramdisk_devs[unit];
|
sc = ramdisk_devs[unit];
|
||||||
|
@ -227,15 +218,14 @@ int mdsize(dev_t dev)
|
||||||
|
|
||||||
int
|
int
|
||||||
mdopen(dev, flag, fmt, proc)
|
mdopen(dev, flag, fmt, proc)
|
||||||
dev_t dev;
|
dev_t dev;
|
||||||
int flag, fmt;
|
int flag, fmt;
|
||||||
struct proc *proc;
|
struct proc *proc;
|
||||||
{
|
{
|
||||||
int md, unit;
|
int unit;
|
||||||
struct md_softc *sc;
|
struct md_softc *sc;
|
||||||
|
|
||||||
md = DISKUNIT(dev);
|
unit = MD_UNIT(dev);
|
||||||
unit = MD_UNIT(md);
|
|
||||||
if (unit >= ramdisk_ndevs)
|
if (unit >= ramdisk_ndevs)
|
||||||
return ENXIO;
|
return ENXIO;
|
||||||
sc = ramdisk_devs[unit];
|
sc = ramdisk_devs[unit];
|
||||||
|
@ -243,10 +233,9 @@ mdopen(dev, flag, fmt, proc)
|
||||||
return ENXIO;
|
return ENXIO;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The control device is not exclusive, and can
|
* The raw partition is used for ioctl to configure.
|
||||||
* open uninitialized units (so you can setconf).
|
|
||||||
*/
|
*/
|
||||||
if (MD_IS_CTRL(md))
|
if (DISKPART(dev) == RAW_PART)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#ifdef MEMORY_DISK_HOOKS
|
#ifdef MEMORY_DISK_HOOKS
|
||||||
|
@ -256,53 +245,71 @@ mdopen(dev, flag, fmt, proc)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is a normal, "slave" device, so
|
* This is a normal, "slave" device, so
|
||||||
* enforce initialized, exclusive open.
|
* enforce initialized.
|
||||||
*/
|
*/
|
||||||
if (sc->sc_type == MD_UNCONFIGURED)
|
if (sc->sc_type == MD_UNCONFIGURED)
|
||||||
return ENXIO;
|
return ENXIO;
|
||||||
if (sc->sc_flags & MD_ISOPEN)
|
|
||||||
return EBUSY;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
mdclose(dev, flag, fmt, proc)
|
mdclose(dev, flag, fmt, proc)
|
||||||
dev_t dev;
|
dev_t dev;
|
||||||
int flag, fmt;
|
int flag, fmt;
|
||||||
struct proc *proc;
|
struct proc *proc;
|
||||||
{
|
{
|
||||||
int md, unit;
|
int unit;
|
||||||
struct md_softc *sc;
|
|
||||||
|
|
||||||
md = DISKUNIT(dev);
|
unit = MD_UNIT(dev);
|
||||||
unit = MD_UNIT(md);
|
|
||||||
sc = ramdisk_devs[unit];
|
|
||||||
|
|
||||||
if (MD_IS_CTRL(md))
|
if (unit >= ramdisk_ndevs)
|
||||||
return 0;
|
return ENXIO;
|
||||||
|
|
||||||
/* Normal device. */
|
|
||||||
sc->sc_flags = 0;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
mdread(dev, uio, flags)
|
mdread(dev, uio, flags)
|
||||||
dev_t dev;
|
dev_t dev;
|
||||||
struct uio *uio;
|
struct uio *uio;
|
||||||
int flags;
|
int flags;
|
||||||
{
|
{
|
||||||
|
int unit;
|
||||||
|
struct md_softc *sc;
|
||||||
|
|
||||||
|
unit = MD_UNIT(dev);
|
||||||
|
|
||||||
|
if (unit >= ramdisk_ndevs)
|
||||||
|
return ENXIO;
|
||||||
|
|
||||||
|
sc = ramdisk_devs[unit];
|
||||||
|
|
||||||
|
if (sc->sc_type == MD_UNCONFIGURED)
|
||||||
|
return ENXIO;
|
||||||
|
|
||||||
return (physio(mdstrategy, NULL, dev, B_READ, minphys, uio));
|
return (physio(mdstrategy, NULL, dev, B_READ, minphys, uio));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
mdwrite(dev, uio, flags)
|
mdwrite(dev, uio, flags)
|
||||||
dev_t dev;
|
dev_t dev;
|
||||||
struct uio *uio;
|
struct uio *uio;
|
||||||
int flags;
|
int flags;
|
||||||
{
|
{
|
||||||
|
int unit;
|
||||||
|
struct md_softc *sc;
|
||||||
|
|
||||||
|
unit = MD_UNIT(dev);
|
||||||
|
|
||||||
|
if (unit >= ramdisk_ndevs)
|
||||||
|
return ENXIO;
|
||||||
|
|
||||||
|
sc = ramdisk_devs[unit];
|
||||||
|
|
||||||
|
if (sc->sc_type == MD_UNCONFIGURED)
|
||||||
|
return ENXIO;
|
||||||
|
|
||||||
return (physio(mdstrategy, NULL, dev, B_WRITE, minphys, uio));
|
return (physio(mdstrategy, NULL, dev, B_WRITE, minphys, uio));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,15 +321,20 @@ void
|
||||||
mdstrategy(bp)
|
mdstrategy(bp)
|
||||||
struct buf *bp;
|
struct buf *bp;
|
||||||
{
|
{
|
||||||
int md, unit;
|
int unit;
|
||||||
struct md_softc *sc;
|
struct md_softc *sc;
|
||||||
caddr_t addr;
|
caddr_t addr;
|
||||||
size_t off, xfer;
|
size_t off, xfer;
|
||||||
|
|
||||||
md = DISKUNIT(bp->b_dev);
|
unit = MD_UNIT(bp->b_dev);
|
||||||
unit = MD_UNIT(md);
|
|
||||||
sc = ramdisk_devs[unit];
|
sc = ramdisk_devs[unit];
|
||||||
|
|
||||||
|
if (sc->sc_type == MD_UNCONFIGURED) {
|
||||||
|
bp->b_error = ENXIO;
|
||||||
|
bp->b_flags |= B_ERROR;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
switch (sc->sc_type) {
|
switch (sc->sc_type) {
|
||||||
#if MEMORY_DISK_SERVER
|
#if MEMORY_DISK_SERVER
|
||||||
case MD_UMEM_SERVER:
|
case MD_UMEM_SERVER:
|
||||||
|
@ -366,27 +378,27 @@ mdstrategy(bp)
|
||||||
bp->b_flags |= B_ERROR;
|
bp->b_flags |= B_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
done:
|
||||||
biodone(bp);
|
biodone(bp);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
mdioctl(dev, cmd, data, flag, proc)
|
mdioctl(dev, cmd, data, flag, proc)
|
||||||
dev_t dev;
|
dev_t dev;
|
||||||
u_long cmd;
|
u_long cmd;
|
||||||
int flag;
|
int flag;
|
||||||
caddr_t data;
|
caddr_t data;
|
||||||
struct proc *proc;
|
struct proc *proc;
|
||||||
{
|
{
|
||||||
int md, unit;
|
int unit;
|
||||||
struct md_softc *sc;
|
struct md_softc *sc;
|
||||||
struct md_conf *umd;
|
struct md_conf *umd;
|
||||||
|
|
||||||
md = DISKUNIT(dev);
|
unit = MD_UNIT(dev);
|
||||||
unit = MD_UNIT(md);
|
|
||||||
sc = ramdisk_devs[unit];
|
sc = ramdisk_devs[unit];
|
||||||
|
|
||||||
/* If this is not the control device, punt! */
|
/* If this is not the raw partition, punt! */
|
||||||
if (MD_IS_CTRL(md) == 0)
|
if (DISKPART(dev) != RAW_PART)
|
||||||
return ENOTTY;
|
return ENOTTY;
|
||||||
|
|
||||||
umd = (struct md_conf *)data;
|
umd = (struct md_conf *)data;
|
||||||
|
@ -422,10 +434,10 @@ static int
|
||||||
md_ioctl_kalloc(sc, umd, proc)
|
md_ioctl_kalloc(sc, umd, proc)
|
||||||
struct md_softc *sc;
|
struct md_softc *sc;
|
||||||
struct md_conf *umd;
|
struct md_conf *umd;
|
||||||
struct proc *proc;
|
struct proc *proc;
|
||||||
{
|
{
|
||||||
vaddr_t addr;
|
vaddr_t addr;
|
||||||
vsize_t size;
|
vsize_t size;
|
||||||
|
|
||||||
/* Sanity check the size. */
|
/* Sanity check the size. */
|
||||||
size = umd->md_size;
|
size = umd->md_size;
|
||||||
|
@ -450,7 +462,7 @@ static int
|
||||||
md_ioctl_server(sc, umd, proc)
|
md_ioctl_server(sc, umd, proc)
|
||||||
struct md_softc *sc;
|
struct md_softc *sc;
|
||||||
struct md_conf *umd;
|
struct md_conf *umd;
|
||||||
struct proc *proc;
|
struct proc *proc;
|
||||||
{
|
{
|
||||||
vaddr_t end;
|
vaddr_t end;
|
||||||
int error;
|
int error;
|
||||||
|
@ -478,7 +490,7 @@ md_ioctl_server(sc, umd, proc)
|
||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
int md_sleep_pri = PWAIT | PCATCH;
|
int md_sleep_pri = PWAIT | PCATCH;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
md_server_loop(sc)
|
md_server_loop(sc)
|
||||||
|
@ -486,8 +498,8 @@ md_server_loop(sc)
|
||||||
{
|
{
|
||||||
struct buf *bp;
|
struct buf *bp;
|
||||||
caddr_t addr; /* user space address */
|
caddr_t addr; /* user space address */
|
||||||
size_t off; /* offset into "device" */
|
size_t off; /* offset into "device" */
|
||||||
size_t xfer; /* amount to transfer */
|
size_t xfer; /* amount to transfer */
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: md.h,v 1.5 1996/12/28 23:09:27 pk Exp $ */
|
/* $NetBSD: md.h,v 1.6 2000/01/21 12:14:53 tsutsui Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1995 Gordon W. Ross
|
* Copyright (c) 1995 Gordon W. Ross
|
||||||
|
@ -66,13 +66,13 @@ struct md_conf {
|
||||||
/*
|
/*
|
||||||
* Small, wired-down chunk of kernel memory obtained from
|
* Small, wired-down chunk of kernel memory obtained from
|
||||||
* kmem_alloc(). The allocation is performed by an ioctl
|
* kmem_alloc(). The allocation is performed by an ioctl
|
||||||
* call on the "control" unit (regular unit + 16)
|
* call on the raw partition.
|
||||||
*/
|
*/
|
||||||
#define MD_UMEM_SERVER 3
|
#define MD_UMEM_SERVER 3
|
||||||
/*
|
/*
|
||||||
* Indirect access to user-space of a user-level server.
|
* Indirect access to user-space of a user-level server.
|
||||||
* (Like the MFS hack, but better! 8^) Device operates
|
* (Like the MFS hack, but better! 8^) Device operates
|
||||||
* only while the server has the control device open and
|
* only while the server has the raw partition open and
|
||||||
* continues to service I/O requests. The process that
|
* continues to service I/O requests. The process that
|
||||||
* does this setconf will become the I/O server. This
|
* does this setconf will become the I/O server. This
|
||||||
* configuration type can be disabled using:
|
* configuration type can be disabled using:
|
||||||
|
|
Loading…
Reference in New Issue