2019-08-29 19:20:48 +03:00
|
|
|
/* $NetBSD: md.c,v 1.82 2019/08/29 16:20:48 hannken Exp $ */
|
1995-10-09 02:30:57 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Gordon W. Ross, Leo Weppelman.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1996-12-29 02:09:26 +03:00
|
|
|
* This implements a general-purpose memory-disk.
|
1997-05-24 03:44:34 +04:00
|
|
|
* See md.h for notes on the config types.
|
1995-10-09 02:30:57 +03:00
|
|
|
*
|
|
|
|
* Note that this driver provides the same functionality
|
|
|
|
* as the MFS filesystem hack, but this is better because
|
|
|
|
* you can use this for any filesystem type you'd like!
|
|
|
|
*
|
|
|
|
* Credit for most of the kmem ramdisk code goes to:
|
|
|
|
* Leo Weppelman (atari) and Phil Nelson (pc532)
|
1996-12-29 02:09:26 +03:00
|
|
|
* Credit for the ideas behind the "user space memory" code goes
|
1995-10-09 02:30:57 +03:00
|
|
|
* to the authors of the MFS implementation.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 08:32:49 +03:00
|
|
|
#include <sys/cdefs.h>
|
2019-08-29 19:20:48 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: md.c,v 1.82 2019/08/29 16:20:48 hannken Exp $");
|
2001-11-13 08:32:49 +03:00
|
|
|
|
2010-11-23 00:10:10 +03:00
|
|
|
#ifdef _KERNEL_OPT
|
1999-02-07 12:34:58 +03:00
|
|
|
#include "opt_md.h"
|
2010-11-23 00:10:10 +03:00
|
|
|
#else
|
|
|
|
#define MEMORY_DISK_SERVER 1
|
|
|
|
#endif
|
1998-02-10 17:08:44 +03:00
|
|
|
|
1995-10-09 02:30:57 +03:00
|
|
|
#include <sys/param.h>
|
1996-03-23 02:02:02 +03:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
1995-10-09 02:30:57 +03:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/buf.h>
|
2004-10-28 11:07:35 +04:00
|
|
|
#include <sys/bufq.h>
|
1995-10-09 02:30:57 +03:00
|
|
|
#include <sys/device.h>
|
1996-01-08 01:01:38 +03:00
|
|
|
#include <sys/disk.h>
|
2009-07-28 21:55:27 +04:00
|
|
|
#include <sys/stat.h>
|
1996-04-12 12:30:09 +04:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/conf.h>
|
1997-08-01 23:38:30 +04:00
|
|
|
#include <sys/disklabel.h>
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2000-06-26 18:20:25 +04:00
|
|
|
#include <uvm/uvm_extern.h>
|
1995-10-09 02:30:57 +03:00
|
|
|
|
1996-12-29 02:09:26 +03:00
|
|
|
#include <dev/md.h>
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2015-08-20 17:40:16 +03:00
|
|
|
#include "ioconf.h"
|
1995-10-09 02:30:57 +03:00
|
|
|
/*
|
2007-07-15 12:40:22 +04:00
|
|
|
* The user-space functionality is included by default.
|
1996-12-29 02:09:26 +03:00
|
|
|
* Use `options MEMORY_DISK_SERVER=0' to turn it off.
|
1995-10-09 02:30:57 +03:00
|
|
|
*/
|
1996-12-29 02:09:26 +03:00
|
|
|
#ifndef MEMORY_DISK_SERVER
|
2007-07-15 12:40:22 +04:00
|
|
|
#error MEMORY_DISK_SERVER should be defined by opt_md.h
|
2002-12-11 19:24:38 +03:00
|
|
|
#endif /* MEMORY_DISK_SERVER */
|
1995-10-09 02:30:57 +03:00
|
|
|
|
|
|
|
/*
|
2000-01-21 15:14:53 +03:00
|
|
|
* We should use the raw partition for ioctl.
|
1995-10-09 02:30:57 +03:00
|
|
|
*/
|
2000-01-21 15:14:53 +03:00
|
|
|
#define MD_UNIT(unit) DISKUNIT(unit)
|
1995-10-09 02:30:57 +03:00
|
|
|
|
|
|
|
/* autoconfig stuff... */
|
|
|
|
|
1996-12-29 02:09:26 +03:00
|
|
|
struct md_softc {
|
2010-11-11 14:07:06 +03:00
|
|
|
device_t sc_dev; /* Self. */
|
1996-01-08 01:01:38 +03:00
|
|
|
struct disk sc_dkdev; /* hook for generic disk handling */
|
1996-12-29 02:09:26 +03:00
|
|
|
struct md_conf sc_md;
|
2010-11-23 12:30:43 +03:00
|
|
|
kmutex_t sc_lock; /* Protect self. */
|
2010-11-25 11:53:30 +03:00
|
|
|
kcondvar_t sc_cv; /* Wait here for work. */
|
2005-10-15 21:29:10 +04:00
|
|
|
struct bufq_state *sc_buflist;
|
1995-10-09 02:30:57 +03:00
|
|
|
};
|
1996-12-29 02:09:26 +03:00
|
|
|
/* shorthand for fields in sc_md: */
|
|
|
|
#define sc_addr sc_md.md_addr
|
|
|
|
#define sc_size sc_md.md_size
|
|
|
|
#define sc_type sc_md.md_type
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2008-06-13 23:55:26 +04:00
|
|
|
static void md_attach(device_t, device_t, void *);
|
2009-05-20 00:25:41 +04:00
|
|
|
static int md_detach(device_t, int);
|
2004-08-30 04:34:41 +04:00
|
|
|
|
|
|
|
static dev_type_open(mdopen);
|
|
|
|
static dev_type_close(mdclose);
|
|
|
|
static dev_type_read(mdread);
|
|
|
|
static dev_type_write(mdwrite);
|
|
|
|
static dev_type_ioctl(mdioctl);
|
|
|
|
static dev_type_strategy(mdstrategy);
|
|
|
|
static dev_type_size(mdsize);
|
2002-09-06 17:18:43 +04:00
|
|
|
|
|
|
|
const struct bdevsw md_bdevsw = {
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_open = mdopen,
|
|
|
|
.d_close = mdclose,
|
|
|
|
.d_strategy = mdstrategy,
|
|
|
|
.d_ioctl = mdioctl,
|
|
|
|
.d_dump = nodump,
|
|
|
|
.d_psize = mdsize,
|
2014-07-25 12:02:18 +04:00
|
|
|
.d_discard = nodiscard,
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_flag = D_DISK | D_MPSAFE
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
const struct cdevsw md_cdevsw = {
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_open = mdopen,
|
|
|
|
.d_close = mdclose,
|
|
|
|
.d_read = mdread,
|
|
|
|
.d_write = mdwrite,
|
|
|
|
.d_ioctl = mdioctl,
|
|
|
|
.d_stop = nostop,
|
|
|
|
.d_tty = notty,
|
|
|
|
.d_poll = nopoll,
|
|
|
|
.d_mmap = nommap,
|
|
|
|
.d_kqfilter = nokqfilter,
|
2014-07-25 12:10:31 +04:00
|
|
|
.d_discard = nodiscard,
|
2014-03-16 09:20:22 +04:00
|
|
|
.d_flag = D_DISK
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
2015-04-26 18:15:19 +03:00
|
|
|
static struct dkdriver mddkdriver = {
|
2019-08-29 19:20:48 +03:00
|
|
|
.d_strategy = mdstrategy,
|
|
|
|
.d_minphys = minphys
|
2015-04-26 18:15:19 +03:00
|
|
|
};
|
1996-01-08 01:01:38 +03:00
|
|
|
|
2009-05-20 00:25:41 +04:00
|
|
|
CFATTACH_DECL3_NEW(md, sizeof(struct md_softc),
|
|
|
|
0, md_attach, md_detach, NULL, NULL, NULL, DVF_DETACH_SHUTDOWN);
|
1996-03-23 02:02:02 +03:00
|
|
|
|
2010-11-11 14:07:06 +03:00
|
|
|
static kmutex_t md_device_lock; /* Protect unit creation / deletion. */
|
2009-05-04 20:20:41 +04:00
|
|
|
extern size_t md_root_size;
|
|
|
|
|
2010-11-11 14:07:06 +03:00
|
|
|
static void md_set_disklabel(struct md_softc *);
|
|
|
|
|
1996-03-23 02:02:02 +03:00
|
|
|
/*
|
|
|
|
* This is called if we are configured as a pseudo-device
|
|
|
|
*/
|
|
|
|
void
|
2004-08-30 04:34:41 +04:00
|
|
|
mdattach(int n)
|
1995-10-09 02:30:57 +03:00
|
|
|
{
|
1996-03-23 02:02:02 +03:00
|
|
|
|
2010-11-11 14:07:06 +03:00
|
|
|
mutex_init(&md_device_lock, MUTEX_DEFAULT, IPL_NONE);
|
|
|
|
if (config_cfattach_attach(md_cd.cd_name, &md_ca)) {
|
|
|
|
aprint_error("%s: cfattach_attach failed\n", md_cd.cd_name);
|
1996-03-23 02:02:02 +03:00
|
|
|
return;
|
|
|
|
}
|
1995-10-09 02:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-20 00:25:41 +04:00
|
|
|
md_attach(device_t parent, device_t self, void *aux)
|
1995-10-09 02:30:57 +03:00
|
|
|
{
|
2008-06-13 23:55:26 +04:00
|
|
|
struct md_softc *sc = device_private(self);
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2010-11-11 14:07:06 +03:00
|
|
|
sc->sc_dev = self;
|
2010-11-25 11:53:30 +03:00
|
|
|
sc->sc_type = MD_UNCONFIGURED;
|
2010-11-23 12:30:43 +03:00
|
|
|
mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
|
|
|
|
cv_init(&sc->sc_cv, "mdidle");
|
2005-10-15 21:29:10 +04:00
|
|
|
bufq_alloc(&sc->sc_buflist, "fcfs", 0);
|
2000-01-22 02:39:55 +03:00
|
|
|
|
1995-10-09 02:30:57 +03:00
|
|
|
/* XXX - Could accept aux info here to set the config. */
|
1996-12-29 02:09:26 +03:00
|
|
|
#ifdef MEMORY_DISK_HOOKS
|
1995-10-09 02:30:57 +03:00
|
|
|
/*
|
|
|
|
* This external function might setup a pre-loaded disk.
|
1996-12-29 02:09:26 +03:00
|
|
|
* All it would need to do is setup the md_conf struct.
|
2001-02-08 16:11:31 +03:00
|
|
|
* See sys/dev/md_root.c for an example.
|
1995-10-09 02:30:57 +03:00
|
|
|
*/
|
2008-06-13 23:55:26 +04:00
|
|
|
md_attach_hook(device_unit(self), &sc->sc_md);
|
1995-10-09 02:30:57 +03:00
|
|
|
#endif
|
1996-01-08 01:01:38 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize and attach the disk structure.
|
|
|
|
*/
|
2008-06-13 23:55:26 +04:00
|
|
|
disk_init(&sc->sc_dkdev, device_xname(self), &mddkdriver);
|
1996-01-08 01:01:38 +03:00
|
|
|
disk_attach(&sc->sc_dkdev);
|
2008-06-14 00:05:06 +04:00
|
|
|
|
2010-11-11 14:07:06 +03:00
|
|
|
if (sc->sc_type != MD_UNCONFIGURED)
|
|
|
|
md_set_disklabel(sc);
|
|
|
|
|
2008-06-14 00:05:06 +04:00
|
|
|
if (!pmf_device_register(self, NULL, NULL))
|
|
|
|
aprint_error_dev(self, "couldn't establish power handler\n");
|
1995-10-09 02:30:57 +03:00
|
|
|
}
|
2009-05-20 00:25:41 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
md_detach(device_t self, int flags)
|
|
|
|
{
|
|
|
|
struct md_softc *sc = device_private(self);
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
mutex_enter(&sc->sc_dkdev.dk_openlock);
|
2010-11-25 11:53:30 +03:00
|
|
|
if (sc->sc_dkdev.dk_openmask == 0 && sc->sc_type == MD_UNCONFIGURED)
|
2009-05-20 00:25:41 +04:00
|
|
|
; /* nothing to do */
|
|
|
|
else if ((flags & DETACH_FORCE) == 0)
|
|
|
|
rc = EBUSY;
|
|
|
|
mutex_exit(&sc->sc_dkdev.dk_openlock);
|
|
|
|
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
pmf_device_deregister(self);
|
|
|
|
disk_detach(&sc->sc_dkdev);
|
|
|
|
disk_destroy(&sc->sc_dkdev);
|
|
|
|
bufq_free(sc->sc_buflist);
|
2010-11-23 12:30:43 +03:00
|
|
|
mutex_destroy(&sc->sc_lock);
|
|
|
|
cv_destroy(&sc->sc_cv);
|
2009-05-20 00:25:41 +04:00
|
|
|
return 0;
|
|
|
|
}
|
1995-10-09 02:30:57 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* operational routines:
|
|
|
|
* open, close, read, write, strategy,
|
|
|
|
* ioctl, dump, size
|
|
|
|
*/
|
|
|
|
|
1996-12-29 02:09:26 +03:00
|
|
|
#if MEMORY_DISK_SERVER
|
2004-08-30 04:34:41 +04:00
|
|
|
static int md_server_loop(struct md_softc *sc);
|
|
|
|
static int md_ioctl_server(struct md_softc *sc, struct md_conf *umd,
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l);
|
2002-12-11 19:24:38 +03:00
|
|
|
#endif /* MEMORY_DISK_SERVER */
|
2004-08-30 04:34:41 +04:00
|
|
|
static int md_ioctl_kalloc(struct md_softc *sc, struct md_conf *umd,
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l);
|
1996-12-29 02:09:26 +03:00
|
|
|
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2000-01-21 15:14:53 +03:00
|
|
|
mdsize(dev_t dev)
|
1995-10-09 02:30:57 +03:00
|
|
|
{
|
1996-12-29 02:09:26 +03:00
|
|
|
struct md_softc *sc;
|
2010-11-23 12:30:43 +03:00
|
|
|
int res;
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2008-06-13 23:55:26 +04:00
|
|
|
sc = device_lookup_private(&md_cd, MD_UNIT(dev));
|
1995-10-09 02:30:57 +03:00
|
|
|
if (sc == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2010-11-23 12:30:43 +03:00
|
|
|
mutex_enter(&sc->sc_lock);
|
1996-12-29 02:09:26 +03:00
|
|
|
if (sc->sc_type == MD_UNCONFIGURED)
|
2010-11-23 12:30:43 +03:00
|
|
|
res = 0;
|
|
|
|
else
|
|
|
|
res = sc->sc_size >> DEV_BSHIFT;
|
|
|
|
mutex_exit(&sc->sc_lock);
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2010-11-23 12:30:43 +03:00
|
|
|
return res;
|
1995-10-09 02:30:57 +03:00
|
|
|
}
|
|
|
|
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
mdopen(dev_t dev, int flag, int fmt, struct lwp *l)
|
1995-10-09 02:30:57 +03:00
|
|
|
{
|
2000-01-21 15:14:53 +03:00
|
|
|
int unit;
|
2009-07-28 21:55:27 +04:00
|
|
|
int part = DISKPART(dev);
|
|
|
|
int pmask = 1 << part;
|
2010-11-11 14:07:06 +03:00
|
|
|
cfdata_t cf;
|
1996-12-29 02:09:26 +03:00
|
|
|
struct md_softc *sc;
|
2009-07-28 21:55:27 +04:00
|
|
|
struct disk *dk;
|
2012-06-30 14:52:31 +04:00
|
|
|
#ifdef MEMORY_DISK_HOOKS
|
|
|
|
bool configured;
|
|
|
|
#endif
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2010-11-11 14:07:06 +03:00
|
|
|
mutex_enter(&md_device_lock);
|
2000-01-21 15:14:53 +03:00
|
|
|
unit = MD_UNIT(dev);
|
2008-06-11 14:38:44 +04:00
|
|
|
sc = device_lookup_private(&md_cd, unit);
|
2010-11-11 14:07:06 +03:00
|
|
|
if (sc == NULL) {
|
|
|
|
if (part != RAW_PART) {
|
|
|
|
mutex_exit(&md_device_lock);
|
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
cf = malloc(sizeof(*cf), M_DEVBUF, M_WAITOK);
|
|
|
|
cf->cf_name = md_cd.cd_name;
|
|
|
|
cf->cf_atname = md_cd.cd_name;
|
|
|
|
cf->cf_unit = unit;
|
|
|
|
cf->cf_fstate = FSTATE_STAR;
|
|
|
|
sc = device_private(config_attach_pseudo(cf));
|
|
|
|
if (sc == NULL) {
|
|
|
|
mutex_exit(&md_device_lock);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2009-07-28 21:55:27 +04:00
|
|
|
dk = &sc->sc_dkdev;
|
|
|
|
|
1995-10-09 02:30:57 +03:00
|
|
|
/*
|
2000-01-21 15:14:53 +03:00
|
|
|
* The raw partition is used for ioctl to configure.
|
1995-10-09 02:30:57 +03:00
|
|
|
*/
|
2009-07-28 21:55:27 +04:00
|
|
|
if (part == RAW_PART)
|
|
|
|
goto ok;
|
1995-10-09 02:30:57 +03:00
|
|
|
|
1996-12-29 02:09:26 +03:00
|
|
|
#ifdef MEMORY_DISK_HOOKS
|
1995-10-09 02:30:57 +03:00
|
|
|
/* Call the open hook to allow loading the device. */
|
2012-06-30 14:52:31 +04:00
|
|
|
configured = (sc->sc_type != MD_UNCONFIGURED);
|
1996-12-29 02:09:26 +03:00
|
|
|
md_open_hook(unit, &sc->sc_md);
|
2012-06-30 14:52:31 +04:00
|
|
|
/* initialize disklabel if the device is configured in open hook */
|
|
|
|
if (!configured && sc->sc_type != MD_UNCONFIGURED)
|
|
|
|
md_set_disklabel(sc);
|
1995-10-09 02:30:57 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a normal, "slave" device, so
|
2000-01-21 15:14:53 +03:00
|
|
|
* enforce initialized.
|
1995-10-09 02:30:57 +03:00
|
|
|
*/
|
2010-11-11 14:07:06 +03:00
|
|
|
if (sc->sc_type == MD_UNCONFIGURED) {
|
|
|
|
mutex_exit(&md_device_lock);
|
1995-10-09 02:30:57 +03:00
|
|
|
return ENXIO;
|
2010-11-11 14:07:06 +03:00
|
|
|
}
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2009-07-28 21:55:27 +04:00
|
|
|
ok:
|
|
|
|
/* XXX duplicates code in dk_open(). Call dk_open(), instead? */
|
|
|
|
mutex_enter(&dk->dk_openlock);
|
|
|
|
/* Mark our unit as open. */
|
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
dk->dk_copenmask |= pmask;
|
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
dk->dk_bopenmask |= pmask;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dk->dk_openmask = dk->dk_copenmask | dk->dk_bopenmask;
|
|
|
|
|
|
|
|
mutex_exit(&dk->dk_openlock);
|
2010-11-11 14:07:06 +03:00
|
|
|
mutex_exit(&md_device_lock);
|
1995-10-09 02:30:57 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
mdclose(dev_t dev, int flag, int fmt, struct lwp *l)
|
1995-10-09 02:30:57 +03:00
|
|
|
{
|
2009-07-28 21:55:27 +04:00
|
|
|
int part = DISKPART(dev);
|
|
|
|
int pmask = 1 << part;
|
2010-11-11 14:07:06 +03:00
|
|
|
int error;
|
|
|
|
cfdata_t cf;
|
2009-07-28 21:55:27 +04:00
|
|
|
struct md_softc *sc;
|
|
|
|
struct disk *dk;
|
|
|
|
|
|
|
|
sc = device_lookup_private(&md_cd, MD_UNIT(dev));
|
|
|
|
if (sc == NULL)
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
dk = &sc->sc_dkdev;
|
|
|
|
|
|
|
|
mutex_enter(&dk->dk_openlock);
|
|
|
|
|
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
dk->dk_copenmask &= ~pmask;
|
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
dk->dk_bopenmask &= ~pmask;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dk->dk_openmask = dk->dk_copenmask | dk->dk_bopenmask;
|
2014-03-13 14:22:35 +04:00
|
|
|
if (dk->dk_openmask != 0) {
|
|
|
|
mutex_exit(&dk->dk_openlock);
|
|
|
|
return 0;
|
|
|
|
}
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2009-07-28 21:55:27 +04:00
|
|
|
mutex_exit(&dk->dk_openlock);
|
2010-11-11 14:07:06 +03:00
|
|
|
|
|
|
|
mutex_enter(&md_device_lock);
|
|
|
|
cf = device_cfdata(sc->sc_dev);
|
|
|
|
error = config_detach(sc->sc_dev, DETACH_QUIET);
|
|
|
|
if (! error)
|
|
|
|
free(cf, M_DEVBUF);
|
|
|
|
mutex_exit(&md_device_lock);
|
|
|
|
return error;
|
1995-10-09 02:30:57 +03:00
|
|
|
}
|
|
|
|
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
mdread(dev_t dev, struct uio *uio, int flags)
|
1995-10-09 02:30:57 +03:00
|
|
|
{
|
2000-01-21 15:14:53 +03:00
|
|
|
struct md_softc *sc;
|
|
|
|
|
2008-06-13 23:55:26 +04:00
|
|
|
sc = device_lookup_private(&md_cd, MD_UNIT(dev));
|
2000-01-21 15:14:53 +03:00
|
|
|
|
2010-01-21 05:14:42 +03:00
|
|
|
if (sc == NULL || sc->sc_type == MD_UNCONFIGURED)
|
2000-01-21 15:14:53 +03:00
|
|
|
return ENXIO;
|
|
|
|
|
1996-12-29 02:09:26 +03:00
|
|
|
return (physio(mdstrategy, NULL, dev, B_READ, minphys, uio));
|
1995-10-09 02:30:57 +03:00
|
|
|
}
|
|
|
|
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
mdwrite(dev_t dev, struct uio *uio, int flags)
|
1995-10-09 02:30:57 +03:00
|
|
|
{
|
2000-01-21 15:14:53 +03:00
|
|
|
struct md_softc *sc;
|
|
|
|
|
2008-06-13 23:55:26 +04:00
|
|
|
sc = device_lookup_private(&md_cd, MD_UNIT(dev));
|
2000-01-21 15:14:53 +03:00
|
|
|
|
2010-01-21 05:14:42 +03:00
|
|
|
if (sc == NULL || sc->sc_type == MD_UNCONFIGURED)
|
2000-01-21 15:14:53 +03:00
|
|
|
return ENXIO;
|
|
|
|
|
1996-12-29 02:09:26 +03:00
|
|
|
return (physio(mdstrategy, NULL, dev, B_WRITE, minphys, uio));
|
1995-10-09 02:30:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle I/O requests, either directly, or
|
|
|
|
* by passing them to the server process.
|
|
|
|
*/
|
2004-08-30 04:34:41 +04:00
|
|
|
static void
|
|
|
|
mdstrategy(struct buf *bp)
|
1995-10-09 02:30:57 +03:00
|
|
|
{
|
1996-12-29 02:09:26 +03:00
|
|
|
struct md_softc *sc;
|
2007-03-04 08:59:00 +03:00
|
|
|
void * addr;
|
2000-01-21 15:14:53 +03:00
|
|
|
size_t off, xfer;
|
2010-11-11 14:07:06 +03:00
|
|
|
bool is_read;
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2008-06-13 23:55:26 +04:00
|
|
|
sc = device_lookup_private(&md_cd, MD_UNIT(bp->b_dev));
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2010-01-21 05:14:42 +03:00
|
|
|
if (sc == NULL || sc->sc_type == MD_UNCONFIGURED) {
|
2000-01-21 15:14:53 +03:00
|
|
|
bp->b_error = ENXIO;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2016-07-27 04:09:44 +03:00
|
|
|
mutex_enter(&sc->sc_lock);
|
|
|
|
|
1995-10-09 02:30:57 +03:00
|
|
|
switch (sc->sc_type) {
|
1996-12-29 02:09:26 +03:00
|
|
|
#if MEMORY_DISK_SERVER
|
|
|
|
case MD_UMEM_SERVER:
|
1995-10-09 02:30:57 +03:00
|
|
|
/* Just add this job to the server's queue. */
|
2009-01-13 16:33:58 +03:00
|
|
|
bufq_put(sc->sc_buflist, bp);
|
2010-11-23 12:30:43 +03:00
|
|
|
cv_signal(&sc->sc_cv);
|
|
|
|
mutex_exit(&sc->sc_lock);
|
2002-07-20 15:28:07 +04:00
|
|
|
/* see md_server_loop() */
|
1995-10-09 02:30:57 +03:00
|
|
|
/* no biodone in this case */
|
|
|
|
return;
|
1996-12-29 02:09:26 +03:00
|
|
|
#endif /* MEMORY_DISK_SERVER */
|
1995-10-09 02:30:57 +03:00
|
|
|
|
1996-12-29 02:09:26 +03:00
|
|
|
case MD_KMEM_FIXED:
|
|
|
|
case MD_KMEM_ALLOCATED:
|
1995-10-09 02:30:57 +03:00
|
|
|
/* These are in kernel space. Access directly. */
|
2010-11-11 14:07:06 +03:00
|
|
|
is_read = ((bp->b_flags & B_READ) == B_READ);
|
1995-10-09 02:30:57 +03:00
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
off = (bp->b_blkno << DEV_BSHIFT);
|
|
|
|
if (off >= sc->sc_size) {
|
2010-11-11 14:07:06 +03:00
|
|
|
if (is_read)
|
1995-10-09 02:30:57 +03:00
|
|
|
break; /* EOF */
|
|
|
|
goto set_eio;
|
|
|
|
}
|
|
|
|
xfer = bp->b_resid;
|
|
|
|
if (xfer > (sc->sc_size - off))
|
|
|
|
xfer = (sc->sc_size - off);
|
2007-03-04 08:59:00 +03:00
|
|
|
addr = (char *)sc->sc_addr + off;
|
2010-11-11 14:07:06 +03:00
|
|
|
disk_busy(&sc->sc_dkdev);
|
|
|
|
if (is_read)
|
2001-07-07 21:04:01 +04:00
|
|
|
memcpy(bp->b_data, addr, xfer);
|
1995-10-09 02:30:57 +03:00
|
|
|
else
|
2001-07-07 21:04:01 +04:00
|
|
|
memcpy(addr, bp->b_data, xfer);
|
2010-11-11 14:07:06 +03:00
|
|
|
disk_unbusy(&sc->sc_dkdev, xfer, is_read);
|
1995-10-09 02:30:57 +03:00
|
|
|
bp->b_resid -= xfer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
set_eio:
|
|
|
|
bp->b_error = EIO;
|
|
|
|
break;
|
|
|
|
}
|
2016-07-27 08:14:40 +03:00
|
|
|
mutex_exit(&sc->sc_lock);
|
2010-11-23 12:30:43 +03:00
|
|
|
|
2010-11-25 11:53:30 +03:00
|
|
|
done:
|
|
|
|
|
|
|
|
biodone(bp);
|
1995-10-09 02:30:57 +03:00
|
|
|
}
|
|
|
|
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2007-03-04 08:59:00 +03:00
|
|
|
mdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
|
1995-10-09 02:30:57 +03:00
|
|
|
{
|
2000-01-21 15:14:53 +03:00
|
|
|
struct md_softc *sc;
|
|
|
|
struct md_conf *umd;
|
2010-11-23 12:30:43 +03:00
|
|
|
int error;
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2010-01-21 05:14:42 +03:00
|
|
|
if ((sc = device_lookup_private(&md_cd, MD_UNIT(dev))) == NULL)
|
|
|
|
return ENXIO;
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2010-11-11 14:07:06 +03:00
|
|
|
if (sc->sc_type != MD_UNCONFIGURED) {
|
2014-12-31 22:52:04 +03:00
|
|
|
error = disk_ioctl(&sc->sc_dkdev, dev, cmd, data, flag, l);
|
|
|
|
if (error != EPASSTHROUGH) {
|
2019-05-26 13:22:07 +03:00
|
|
|
return error;
|
2010-11-11 14:07:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-21 15:14:53 +03:00
|
|
|
/* If this is not the raw partition, punt! */
|
2010-11-23 12:30:43 +03:00
|
|
|
if (DISKPART(dev) != RAW_PART) {
|
1995-10-09 02:30:57 +03:00
|
|
|
return ENOTTY;
|
2010-11-23 12:30:43 +03:00
|
|
|
}
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2019-05-26 13:22:07 +03:00
|
|
|
mutex_enter(&sc->sc_lock);
|
1996-12-29 02:09:26 +03:00
|
|
|
umd = (struct md_conf *)data;
|
2010-11-23 12:30:43 +03:00
|
|
|
error = EINVAL;
|
1995-10-09 02:30:57 +03:00
|
|
|
switch (cmd) {
|
1996-12-29 02:09:26 +03:00
|
|
|
case MD_GETCONF:
|
|
|
|
*umd = sc->sc_md;
|
2010-11-23 12:30:43 +03:00
|
|
|
error = 0;
|
|
|
|
break;
|
1995-10-09 02:30:57 +03:00
|
|
|
|
1996-12-29 02:09:26 +03:00
|
|
|
case MD_SETCONF:
|
1995-10-09 02:30:57 +03:00
|
|
|
/* Can only set it once. */
|
1996-12-29 02:09:26 +03:00
|
|
|
if (sc->sc_type != MD_UNCONFIGURED)
|
1995-10-09 02:30:57 +03:00
|
|
|
break;
|
1996-12-29 02:09:26 +03:00
|
|
|
switch (umd->md_type) {
|
|
|
|
case MD_KMEM_ALLOCATED:
|
2010-11-23 12:30:43 +03:00
|
|
|
error = md_ioctl_kalloc(sc, umd, l);
|
|
|
|
break;
|
1996-12-29 02:09:26 +03:00
|
|
|
#if MEMORY_DISK_SERVER
|
|
|
|
case MD_UMEM_SERVER:
|
2010-11-23 12:30:43 +03:00
|
|
|
error = md_ioctl_server(sc, umd, l);
|
|
|
|
break;
|
2002-12-11 19:24:38 +03:00
|
|
|
#endif /* MEMORY_DISK_SERVER */
|
1995-10-09 02:30:57 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-11-23 12:30:43 +03:00
|
|
|
mutex_exit(&sc->sc_lock);
|
|
|
|
return error;
|
1995-10-09 02:30:57 +03:00
|
|
|
}
|
|
|
|
|
2010-11-11 14:07:06 +03:00
|
|
|
static void
|
|
|
|
md_set_disklabel(struct md_softc *sc)
|
|
|
|
{
|
2016-01-04 19:24:52 +03:00
|
|
|
struct disk_geom *dg = &sc->sc_dkdev.dk_geom;
|
2010-11-11 14:07:06 +03:00
|
|
|
struct disklabel *lp = sc->sc_dkdev.dk_label;
|
|
|
|
struct partition *pp;
|
|
|
|
|
|
|
|
memset(lp, 0, sizeof(*lp));
|
|
|
|
|
|
|
|
lp->d_secsize = DEV_BSIZE;
|
|
|
|
lp->d_secperunit = sc->sc_size / DEV_BSIZE;
|
|
|
|
if (lp->d_secperunit >= (32*64)) {
|
|
|
|
lp->d_nsectors = 32;
|
|
|
|
lp->d_ntracks = 64;
|
|
|
|
lp->d_ncylinders = lp->d_secperunit / (32*64);
|
|
|
|
} else {
|
|
|
|
lp->d_nsectors = 1;
|
|
|
|
lp->d_ntracks = 1;
|
|
|
|
lp->d_ncylinders = lp->d_secperunit;
|
|
|
|
}
|
|
|
|
lp->d_secpercyl = lp->d_ntracks*lp->d_nsectors;
|
|
|
|
|
|
|
|
strncpy(lp->d_typename, md_cd.cd_name, sizeof(lp->d_typename));
|
2015-01-02 22:42:05 +03:00
|
|
|
lp->d_type = DKTYPE_MD;
|
2010-11-11 14:07:06 +03:00
|
|
|
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[0];
|
|
|
|
pp->p_offset = 0;
|
|
|
|
pp->p_size = lp->d_secperunit;
|
|
|
|
pp->p_fstype = FS_BSDFFS;
|
|
|
|
|
|
|
|
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);
|
2016-01-04 19:24:52 +03:00
|
|
|
|
|
|
|
memset(dg, 0, sizeof(*dg));
|
|
|
|
|
|
|
|
dg->dg_secsize = lp->d_secsize;
|
|
|
|
dg->dg_secperunit = lp->d_secperunit;
|
|
|
|
dg->dg_nsectors = lp->d_nsectors;
|
|
|
|
dg->dg_ntracks = lp->d_ntracks = 64;;
|
|
|
|
dg->dg_ncylinders = lp->d_ncylinders;
|
|
|
|
|
|
|
|
disk_set_info(sc->sc_dev, &sc->sc_dkdev, NULL);
|
2010-11-11 14:07:06 +03:00
|
|
|
}
|
|
|
|
|
1995-10-09 02:30:57 +03:00
|
|
|
/*
|
1996-12-29 02:09:26 +03:00
|
|
|
* Handle ioctl MD_SETCONF for (sc_type == MD_KMEM_ALLOCATED)
|
1995-10-09 02:30:57 +03:00
|
|
|
* Just allocate some kernel memory and return.
|
|
|
|
*/
|
1996-04-12 12:30:09 +04:00
|
|
|
static int
|
2006-10-12 05:30:41 +04:00
|
|
|
md_ioctl_kalloc(struct md_softc *sc, struct md_conf *umd,
|
2006-11-16 04:32:37 +03:00
|
|
|
struct lwp *l)
|
1995-10-09 02:30:57 +03:00
|
|
|
{
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t addr;
|
2000-01-21 15:14:53 +03:00
|
|
|
vsize_t size;
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2010-11-25 11:53:30 +03:00
|
|
|
mutex_exit(&sc->sc_lock);
|
2010-11-23 12:30:43 +03:00
|
|
|
|
1995-10-09 02:30:57 +03:00
|
|
|
/* Sanity check the size. */
|
1996-12-29 02:09:26 +03:00
|
|
|
size = umd->md_size;
|
2005-04-01 15:59:21 +04:00
|
|
|
addr = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_WIRED|UVM_KMF_ZERO);
|
2010-11-25 11:53:30 +03:00
|
|
|
|
|
|
|
mutex_enter(&sc->sc_lock);
|
|
|
|
|
1995-10-09 02:30:57 +03:00
|
|
|
if (!addr)
|
|
|
|
return ENOMEM;
|
|
|
|
|
2010-11-25 11:53:30 +03:00
|
|
|
/* If another thread beat us to configure this unit: fail. */
|
|
|
|
if (sc->sc_type != MD_UNCONFIGURED) {
|
|
|
|
uvm_km_free(kernel_map, addr, size, UVM_KMF_WIRED);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
1995-10-09 02:30:57 +03:00
|
|
|
/* This unit is now configured. */
|
2007-03-04 08:59:00 +03:00
|
|
|
sc->sc_addr = (void *)addr; /* kernel space */
|
1995-10-09 02:30:57 +03:00
|
|
|
sc->sc_size = (size_t)size;
|
1996-12-29 02:09:26 +03:00
|
|
|
sc->sc_type = MD_KMEM_ALLOCATED;
|
2010-11-11 14:07:06 +03:00
|
|
|
md_set_disklabel(sc);
|
1995-10-09 02:30:57 +03:00
|
|
|
return 0;
|
2005-02-27 03:26:58 +03:00
|
|
|
}
|
1995-10-09 02:30:57 +03:00
|
|
|
|
1996-12-29 02:09:26 +03:00
|
|
|
#if MEMORY_DISK_SERVER
|
1995-10-09 02:30:57 +03:00
|
|
|
|
|
|
|
/*
|
1996-12-29 02:09:26 +03:00
|
|
|
* Handle ioctl MD_SETCONF for (sc_type == MD_UMEM_SERVER)
|
1995-10-09 02:30:57 +03:00
|
|
|
* Set config, then become the I/O server for this unit.
|
|
|
|
*/
|
1996-04-12 12:30:09 +04:00
|
|
|
static int
|
2006-10-12 05:30:41 +04:00
|
|
|
md_ioctl_server(struct md_softc *sc, struct md_conf *umd,
|
2006-11-16 04:32:37 +03:00
|
|
|
struct lwp *l)
|
1995-10-09 02:30:57 +03:00
|
|
|
{
|
1998-08-13 06:10:37 +04:00
|
|
|
vaddr_t end;
|
1995-10-09 02:30:57 +03:00
|
|
|
int error;
|
|
|
|
|
2010-11-23 12:30:43 +03:00
|
|
|
KASSERT(mutex_owned(&sc->sc_lock));
|
|
|
|
|
1995-10-09 02:30:57 +03:00
|
|
|
/* Sanity check addr, size. */
|
2007-03-04 08:59:00 +03:00
|
|
|
end = (vaddr_t) ((char *)umd->md_addr + umd->md_size);
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2018-03-03 22:26:12 +03:00
|
|
|
if (
|
|
|
|
#ifndef _RUMPKERNEL
|
|
|
|
/*
|
|
|
|
* On some architectures (e.g. powerpc) rump kernel provides
|
|
|
|
* "safe" low defaults which make this test fail since malloc
|
|
|
|
* does return higher addresses than the "safe" default.
|
|
|
|
*/
|
|
|
|
(end >= VM_MAXUSER_ADDRESS) ||
|
|
|
|
#endif
|
|
|
|
(end < ((vaddr_t) umd->md_addr)))
|
1995-10-09 02:30:57 +03:00
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
/* This unit is now configured. */
|
1996-12-29 02:09:26 +03:00
|
|
|
sc->sc_addr = umd->md_addr; /* user space */
|
|
|
|
sc->sc_size = umd->md_size;
|
|
|
|
sc->sc_type = MD_UMEM_SERVER;
|
2010-11-11 14:07:06 +03:00
|
|
|
md_set_disklabel(sc);
|
1995-10-09 02:30:57 +03:00
|
|
|
|
|
|
|
/* Become the server daemon */
|
1996-12-29 02:09:26 +03:00
|
|
|
error = md_server_loop(sc);
|
1995-10-09 02:30:57 +03:00
|
|
|
|
|
|
|
/* This server is now going away! */
|
1996-12-29 02:09:26 +03:00
|
|
|
sc->sc_type = MD_UNCONFIGURED;
|
1995-10-09 02:30:57 +03:00
|
|
|
sc->sc_addr = 0;
|
|
|
|
sc->sc_size = 0;
|
|
|
|
|
|
|
|
return (error);
|
2005-02-27 03:26:58 +03:00
|
|
|
}
|
1995-10-09 02:30:57 +03:00
|
|
|
|
|
|
|
static int
|
2004-08-30 04:34:41 +04:00
|
|
|
md_server_loop(struct md_softc *sc)
|
1995-10-09 02:30:57 +03:00
|
|
|
{
|
|
|
|
struct buf *bp;
|
2007-03-04 08:59:00 +03:00
|
|
|
void *addr; /* user space address */
|
2000-01-21 15:14:53 +03:00
|
|
|
size_t off; /* offset into "device" */
|
|
|
|
size_t xfer; /* amount to transfer */
|
1995-10-09 02:30:57 +03:00
|
|
|
int error;
|
2010-11-11 14:07:06 +03:00
|
|
|
bool is_read;
|
1995-10-09 02:30:57 +03:00
|
|
|
|
2010-11-23 12:30:43 +03:00
|
|
|
KASSERT(mutex_owned(&sc->sc_lock));
|
|
|
|
|
1995-10-09 02:30:57 +03:00
|
|
|
for (;;) {
|
|
|
|
/* Wait for some work to arrive. */
|
2009-01-13 16:33:58 +03:00
|
|
|
while ((bp = bufq_get(sc->sc_buflist)) == NULL) {
|
2010-11-23 12:30:43 +03:00
|
|
|
error = cv_wait_sig(&sc->sc_cv, &sc->sc_lock);
|
1995-10-09 02:30:57 +03:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do the transfer to/from user space. */
|
2010-11-23 12:30:43 +03:00
|
|
|
mutex_exit(&sc->sc_lock);
|
1995-10-09 02:30:57 +03:00
|
|
|
error = 0;
|
2010-11-11 14:07:06 +03:00
|
|
|
is_read = ((bp->b_flags & B_READ) == B_READ);
|
1995-10-09 02:30:57 +03:00
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
off = (bp->b_blkno << DEV_BSHIFT);
|
|
|
|
if (off >= sc->sc_size) {
|
2010-11-11 14:07:06 +03:00
|
|
|
if (is_read)
|
1995-10-09 02:30:57 +03:00
|
|
|
goto done; /* EOF (not an error) */
|
|
|
|
error = EIO;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
xfer = bp->b_resid;
|
|
|
|
if (xfer > (sc->sc_size - off))
|
|
|
|
xfer = (sc->sc_size - off);
|
2007-03-04 08:59:00 +03:00
|
|
|
addr = (char *)sc->sc_addr + off;
|
2010-11-11 14:07:06 +03:00
|
|
|
disk_busy(&sc->sc_dkdev);
|
|
|
|
if (is_read)
|
1995-10-09 02:30:57 +03:00
|
|
|
error = copyin(addr, bp->b_data, xfer);
|
|
|
|
else
|
|
|
|
error = copyout(bp->b_data, addr, xfer);
|
2010-11-11 14:07:06 +03:00
|
|
|
disk_unbusy(&sc->sc_dkdev, (error ? 0 : xfer), is_read);
|
1995-10-09 02:30:57 +03:00
|
|
|
if (!error)
|
|
|
|
bp->b_resid -= xfer;
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (error) {
|
|
|
|
bp->b_error = error;
|
|
|
|
}
|
|
|
|
biodone(bp);
|
2010-11-23 12:30:43 +03:00
|
|
|
mutex_enter(&sc->sc_lock);
|
1995-10-09 02:30:57 +03:00
|
|
|
}
|
|
|
|
}
|
1996-12-29 02:09:26 +03:00
|
|
|
#endif /* MEMORY_DISK_SERVER */
|