2010-09-20 10:54:06 +04:00
|
|
|
/* $NetBSD: ld.c,v 1.68 2010/09/20 06:54:06 kiyohara Exp $ */
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Andrew Doran and Charles M. Hannum.
|
|
|
|
*
|
|
|
|
* 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 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
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2000-11-08 22:20:33 +03:00
|
|
|
* Disk driver for use by RAID controllers.
|
2000-10-19 18:06:02 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-13 08:32:49 +03:00
|
|
|
#include <sys/cdefs.h>
|
2010-09-20 10:54:06 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ld.c,v 1.68 2010/09/20 06:54:06 kiyohara Exp $");
|
2001-11-13 08:32:49 +03:00
|
|
|
|
2000-10-19 18:06:02 +04:00
|
|
|
#include "rnd.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/buf.h>
|
2004-10-28 11:07:35 +04:00
|
|
|
#include <sys/bufq.h>
|
2000-10-19 18:06:02 +04:00
|
|
|
#include <sys/endian.h>
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#include <sys/dkio.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/fcntl.h>
|
2000-12-03 16:03:30 +03:00
|
|
|
#include <sys/vnode.h>
|
2000-10-19 18:06:02 +04:00
|
|
|
#include <sys/syslog.h>
|
2007-02-10 00:55:00 +03:00
|
|
|
#include <sys/mutex.h>
|
2000-10-19 18:06:02 +04:00
|
|
|
#if NRND > 0
|
|
|
|
#include <sys/rnd.h>
|
|
|
|
#endif
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
#include <dev/ldvar.h>
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2007-02-08 06:19:42 +03:00
|
|
|
#include <prop/proplib.h>
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
static void ldgetdefaultlabel(struct ld_softc *, struct disklabel *);
|
|
|
|
static void ldgetdisklabel(struct ld_softc *);
|
|
|
|
static void ldminphys(struct buf *bp);
|
2010-08-19 21:59:10 +04:00
|
|
|
static bool ld_suspend(device_t, const pmf_qual_t *);
|
2008-03-09 22:15:01 +03:00
|
|
|
static bool ld_shutdown(device_t, int);
|
2007-02-10 00:55:00 +03:00
|
|
|
static void ldstart(struct ld_softc *, struct buf *);
|
2007-02-08 06:19:42 +03:00
|
|
|
static void ld_set_properties(struct ld_softc *);
|
2009-05-07 13:11:42 +04:00
|
|
|
static void ld_config_interrupts (device_t);
|
2009-07-24 01:38:33 +04:00
|
|
|
static int ldlastclose(device_t);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
extern struct cfdriver ld_cd;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2004-08-30 04:34:41 +04:00
|
|
|
static dev_type_open(ldopen);
|
|
|
|
static dev_type_close(ldclose);
|
|
|
|
static dev_type_read(ldread);
|
|
|
|
static dev_type_write(ldwrite);
|
|
|
|
static dev_type_ioctl(ldioctl);
|
|
|
|
static dev_type_strategy(ldstrategy);
|
|
|
|
static dev_type_dump(lddump);
|
|
|
|
static dev_type_size(ldsize);
|
2002-09-06 17:18:43 +04:00
|
|
|
|
|
|
|
const struct bdevsw ld_bdevsw = {
|
|
|
|
ldopen, ldclose, ldstrategy, ldioctl, lddump, ldsize, D_DISK
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct cdevsw ld_cdevsw = {
|
|
|
|
ldopen, ldclose, ldread, ldwrite, ldioctl,
|
2002-10-23 13:10:23 +04:00
|
|
|
nostop, notty, nopoll, nommap, nokqfilter, D_DISK
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
2004-09-25 08:28:08 +04:00
|
|
|
static struct dkdriver lddkdriver = { ldstrategy, ldminphys };
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
void
|
2000-11-26 20:44:02 +03:00
|
|
|
ldattach(struct ld_softc *sc)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2005-05-30 08:44:52 +04:00
|
|
|
char tbuf[9];
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2007-12-05 10:06:50 +03:00
|
|
|
mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_VM);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2001-02-04 20:15:37 +03:00
|
|
|
if ((sc->sc_flags & LDF_ENABLED) == 0) {
|
2008-09-09 16:45:39 +04:00
|
|
|
aprint_normal_dev(sc->sc_dv, "disabled\n");
|
2001-02-04 20:15:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-10-19 18:06:02 +04:00
|
|
|
/* Initialise and attach the disk structure. */
|
2008-09-09 16:45:39 +04:00
|
|
|
disk_init(&sc->sc_dk, device_xname(sc->sc_dv), &lddkdriver);
|
2000-10-19 18:06:02 +04:00
|
|
|
disk_attach(&sc->sc_dk);
|
|
|
|
|
|
|
|
if (sc->sc_maxxfer > MAXPHYS)
|
|
|
|
sc->sc_maxxfer = MAXPHYS;
|
|
|
|
|
2003-01-27 05:43:30 +03:00
|
|
|
/* Build synthetic geometry if necessary. */
|
|
|
|
if (sc->sc_nheads == 0 || sc->sc_nsectors == 0 ||
|
|
|
|
sc->sc_ncylinders == 0) {
|
2004-07-20 19:44:20 +04:00
|
|
|
uint64_t ncyl;
|
|
|
|
|
2003-01-27 05:43:30 +03:00
|
|
|
if (sc->sc_secperunit <= 528 * 2048) /* 528MB */
|
|
|
|
sc->sc_nheads = 16;
|
|
|
|
else if (sc->sc_secperunit <= 1024 * 2048) /* 1GB */
|
|
|
|
sc->sc_nheads = 32;
|
|
|
|
else if (sc->sc_secperunit <= 21504 * 2048) /* 21GB */
|
|
|
|
sc->sc_nheads = 64;
|
|
|
|
else if (sc->sc_secperunit <= 43008 * 2048) /* 42GB */
|
|
|
|
sc->sc_nheads = 128;
|
|
|
|
else
|
|
|
|
sc->sc_nheads = 255;
|
|
|
|
|
|
|
|
sc->sc_nsectors = 63;
|
2004-07-20 19:44:20 +04:00
|
|
|
sc->sc_ncylinders = INT_MAX;
|
2005-02-27 03:26:58 +03:00
|
|
|
ncyl = sc->sc_secperunit /
|
2003-01-27 05:43:30 +03:00
|
|
|
(sc->sc_nheads * sc->sc_nsectors);
|
2004-07-20 19:44:20 +04:00
|
|
|
if (ncyl < INT_MAX)
|
|
|
|
sc->sc_ncylinders = (int)ncyl;
|
2003-01-27 05:43:30 +03:00
|
|
|
}
|
2001-06-10 14:48:42 +04:00
|
|
|
|
2005-05-30 08:44:52 +04:00
|
|
|
format_bytes(tbuf, sizeof(tbuf), sc->sc_secperunit *
|
2000-10-19 18:06:02 +04:00
|
|
|
sc->sc_secsize);
|
2008-09-09 16:45:39 +04:00
|
|
|
aprint_normal_dev(sc->sc_dv, "%s, %d cyl, %d head, %d sec, "
|
|
|
|
"%d bytes/sect x %"PRIu64" sectors\n",
|
2008-04-09 09:47:19 +04:00
|
|
|
tbuf, sc->sc_ncylinders, sc->sc_nheads,
|
2000-10-19 18:06:02 +04:00
|
|
|
sc->sc_nsectors, sc->sc_secsize, sc->sc_secperunit);
|
2010-09-20 10:54:06 +04:00
|
|
|
sc->sc_disksize512 = sc->sc_secperunit * sc->sc_secsize / DEV_BSIZE;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2007-02-08 06:19:42 +03:00
|
|
|
ld_set_properties(sc);
|
|
|
|
|
2000-10-19 18:06:02 +04:00
|
|
|
#if NRND > 0
|
|
|
|
/* Attach the device into the rnd source list. */
|
2008-09-09 16:45:39 +04:00
|
|
|
rnd_attach_source(&sc->sc_rnd_source, device_xname(sc->sc_dv),
|
2000-10-19 18:06:02 +04:00
|
|
|
RND_TYPE_DISK, 0);
|
|
|
|
#endif
|
|
|
|
|
2008-03-09 22:15:01 +03:00
|
|
|
/* Register with PMF */
|
2010-08-19 21:59:10 +04:00
|
|
|
if (!pmf_device_register1(sc->sc_dv, ld_suspend, NULL, ld_shutdown))
|
2008-09-09 16:45:39 +04:00
|
|
|
aprint_error_dev(sc->sc_dv,
|
2008-03-09 22:15:01 +03:00
|
|
|
"couldn't establish power handler\n");
|
|
|
|
|
2005-10-15 21:29:10 +04:00
|
|
|
bufq_alloc(&sc->sc_bufq, BUFQ_DISK_DEFAULT_STRAT, BUFQ_SORT_RAWBLOCK);
|
2004-09-25 08:28:08 +04:00
|
|
|
|
|
|
|
/* Discover wedges on this disk. */
|
2008-09-09 16:45:39 +04:00
|
|
|
config_interrupts(sc->sc_dv, ld_config_interrupts);
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
2001-01-04 00:01:28 +03:00
|
|
|
int
|
2005-05-30 08:44:52 +04:00
|
|
|
ldadjqparam(struct ld_softc *sc, int xmax)
|
2001-01-04 00:01:28 +03:00
|
|
|
{
|
2003-06-13 06:32:27 +04:00
|
|
|
int s;
|
2001-02-04 20:15:37 +03:00
|
|
|
|
|
|
|
s = splbio();
|
2005-05-30 08:44:52 +04:00
|
|
|
sc->sc_maxqueuecnt = xmax;
|
2001-02-04 20:15:37 +03:00
|
|
|
splx(s);
|
|
|
|
|
2003-06-13 06:32:27 +04:00
|
|
|
return (0);
|
2001-02-04 20:15:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbegindetach(struct ld_softc *sc, int flags)
|
|
|
|
{
|
2003-06-13 06:32:27 +04:00
|
|
|
int s, rv = 0;
|
2001-02-04 20:15:37 +03:00
|
|
|
|
|
|
|
if ((sc->sc_flags & LDF_ENABLED) == 0)
|
|
|
|
return (0);
|
2001-01-04 00:01:28 +03:00
|
|
|
|
2009-07-24 01:38:33 +04:00
|
|
|
rv = disk_begindetach(&sc->sc_dk, ldlastclose, sc->sc_dv, flags);
|
|
|
|
|
|
|
|
if (rv != 0)
|
|
|
|
return rv;
|
2001-01-04 00:01:28 +03:00
|
|
|
|
|
|
|
s = splbio();
|
2003-06-13 06:32:27 +04:00
|
|
|
sc->sc_maxqueuecnt = 0;
|
2001-02-04 20:15:37 +03:00
|
|
|
sc->sc_flags |= LDF_DETACH;
|
2003-06-13 06:32:27 +04:00
|
|
|
while (sc->sc_queuecnt > 0) {
|
|
|
|
sc->sc_flags |= LDF_DRAIN;
|
|
|
|
rv = tsleep(&sc->sc_queuecnt, PRIBIO, "lddrn", 0);
|
|
|
|
if (rv)
|
|
|
|
break;
|
|
|
|
}
|
2001-01-04 00:01:28 +03:00
|
|
|
splx(s);
|
2001-02-04 20:15:37 +03:00
|
|
|
|
|
|
|
return (rv);
|
2001-01-04 00:01:28 +03:00
|
|
|
}
|
|
|
|
|
2000-12-03 16:03:30 +03:00
|
|
|
void
|
2001-02-04 20:15:37 +03:00
|
|
|
ldenddetach(struct ld_softc *sc)
|
2000-12-03 16:03:30 +03:00
|
|
|
{
|
2002-05-08 19:49:07 +04:00
|
|
|
int s, bmaj, cmaj, i, mn;
|
2000-12-03 16:03:30 +03:00
|
|
|
|
2001-02-04 20:15:37 +03:00
|
|
|
if ((sc->sc_flags & LDF_ENABLED) == 0)
|
|
|
|
return;
|
|
|
|
|
2000-12-03 16:03:30 +03:00
|
|
|
/* Wait for commands queued with the hardware to complete. */
|
|
|
|
if (sc->sc_queuecnt != 0)
|
2001-02-04 20:15:37 +03:00
|
|
|
if (tsleep(&sc->sc_queuecnt, PRIBIO, "lddtch", 30 * hz))
|
2008-09-09 16:45:39 +04:00
|
|
|
printf("%s: not drained\n", device_xname(sc->sc_dv));
|
2000-12-03 16:03:30 +03:00
|
|
|
|
|
|
|
/* Locate the major numbers. */
|
2002-09-06 17:18:43 +04:00
|
|
|
bmaj = bdevsw_lookup_major(&ld_bdevsw);
|
|
|
|
cmaj = cdevsw_lookup_major(&ld_cdevsw);
|
2000-12-03 16:03:30 +03:00
|
|
|
|
|
|
|
/* Kill off any queued buffers. */
|
|
|
|
s = splbio();
|
2005-10-15 21:29:10 +04:00
|
|
|
bufq_drain(sc->sc_bufq);
|
2000-12-03 16:03:30 +03:00
|
|
|
splx(s);
|
|
|
|
|
2005-10-15 21:29:10 +04:00
|
|
|
bufq_free(sc->sc_bufq);
|
2005-03-31 15:28:53 +04:00
|
|
|
|
2000-12-03 16:03:30 +03:00
|
|
|
/* Nuke the vnodes for any open instances. */
|
2002-05-08 19:49:07 +04:00
|
|
|
for (i = 0; i < MAXPARTITIONS; i++) {
|
2008-09-09 16:45:39 +04:00
|
|
|
mn = DISKMINOR(device_unit(sc->sc_dv), i);
|
2002-05-08 19:49:07 +04:00
|
|
|
vdevgone(bmaj, mn, mn, VBLK);
|
|
|
|
vdevgone(cmaj, mn, mn, VCHR);
|
|
|
|
}
|
|
|
|
|
2004-09-25 08:28:08 +04:00
|
|
|
/* Delete all of our wedges. */
|
|
|
|
dkwedge_delall(&sc->sc_dk);
|
|
|
|
|
2000-12-03 16:03:30 +03:00
|
|
|
/* Detach from the disk list. */
|
|
|
|
disk_detach(&sc->sc_dk);
|
2007-10-08 20:41:05 +04:00
|
|
|
disk_destroy(&sc->sc_dk);
|
2000-12-03 16:03:30 +03:00
|
|
|
|
|
|
|
#if NRND > 0
|
|
|
|
/* Unhook the entropy source. */
|
|
|
|
rnd_detach_source(&sc->sc_rnd_source);
|
|
|
|
#endif
|
|
|
|
|
2008-03-09 22:18:25 +03:00
|
|
|
/* Deregister with PMF */
|
2008-09-09 16:45:39 +04:00
|
|
|
pmf_device_deregister(sc->sc_dv);
|
2008-03-09 22:18:25 +03:00
|
|
|
|
2003-06-13 06:32:27 +04:00
|
|
|
/*
|
|
|
|
* XXX We can't really flush the cache here, beceause the
|
|
|
|
* XXX device may already be non-existent from the controller's
|
|
|
|
* XXX perspective.
|
|
|
|
*/
|
|
|
|
#if 0
|
2000-12-03 16:03:30 +03:00
|
|
|
/* Flush the device's cache. */
|
|
|
|
if (sc->sc_flush != NULL)
|
2008-08-11 10:43:37 +04:00
|
|
|
if ((*sc->sc_flush)(sc, 0) != 0)
|
2008-04-09 09:47:19 +04:00
|
|
|
aprint_error_dev(&sc->sc_dv, "unable to flush cache\n");
|
2003-06-13 06:32:27 +04:00
|
|
|
#endif
|
2008-08-01 20:09:45 +04:00
|
|
|
mutex_destroy(&sc->sc_mutex);
|
2000-12-03 16:03:30 +03:00
|
|
|
}
|
|
|
|
|
2010-08-19 21:59:10 +04:00
|
|
|
/* ARGSUSED */
|
|
|
|
static bool
|
|
|
|
ld_suspend(device_t dev, const pmf_qual_t *qual)
|
|
|
|
{
|
|
|
|
return ld_shutdown(dev, 0);
|
|
|
|
}
|
|
|
|
|
2001-04-30 06:44:53 +04:00
|
|
|
/* ARGSUSED */
|
2008-03-09 22:15:01 +03:00
|
|
|
static bool
|
|
|
|
ld_shutdown(device_t dev, int flags)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2008-03-09 22:15:01 +03:00
|
|
|
struct ld_softc *sc = device_private(dev);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2008-08-11 10:43:37 +04:00
|
|
|
if (sc->sc_flush != NULL && (*sc->sc_flush)(sc, LDFL_POLL) != 0) {
|
2008-03-09 22:15:01 +03:00
|
|
|
printf("%s: unable to flush cache\n", device_xname(dev));
|
|
|
|
return false;
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
2008-03-09 22:15:01 +03:00
|
|
|
|
|
|
|
return true;
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
2001-04-30 06:44:53 +04:00
|
|
|
/* ARGSUSED */
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
ldopen(dev_t dev, int flags, int fmt, struct lwp *l)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_softc *sc;
|
2004-09-25 08:28:08 +04:00
|
|
|
int error, unit, part;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
unit = DISKUNIT(dev);
|
2008-06-11 16:41:22 +04:00
|
|
|
if ((sc = device_lookup_private(&ld_cd, unit)) == NULL)
|
2000-10-19 18:06:02 +04:00
|
|
|
return (ENXIO);
|
2000-11-26 20:44:02 +03:00
|
|
|
if ((sc->sc_flags & LDF_ENABLED) == 0)
|
2000-10-19 18:06:02 +04:00
|
|
|
return (ENODEV);
|
|
|
|
part = DISKPART(dev);
|
2004-09-25 08:28:08 +04:00
|
|
|
|
2007-07-21 23:51:47 +04:00
|
|
|
mutex_enter(&sc->sc_dk.dk_openlock);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2003-05-17 20:11:52 +04:00
|
|
|
if (sc->sc_dk.dk_openmask == 0) {
|
|
|
|
/* Load the partition info if not already loaded. */
|
|
|
|
if ((sc->sc_flags & LDF_VLABEL) == 0)
|
|
|
|
ldgetdisklabel(sc);
|
|
|
|
}
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
/* Check that the partition exists. */
|
|
|
|
if (part != RAW_PART && (part >= sc->sc_dk.dk_label->d_npartitions ||
|
|
|
|
sc->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) {
|
2004-09-25 08:28:08 +04:00
|
|
|
error = ENXIO;
|
|
|
|
goto bad1;
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure only one open at a time. */
|
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
sc->sc_dk.dk_copenmask |= (1 << part);
|
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
sc->sc_dk.dk_bopenmask |= (1 << part);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sc->sc_dk.dk_openmask =
|
|
|
|
sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
|
|
|
|
|
2007-07-21 23:51:47 +04:00
|
|
|
error = 0;
|
2004-09-25 08:28:08 +04:00
|
|
|
bad1:
|
2007-07-21 23:51:47 +04:00
|
|
|
mutex_exit(&sc->sc_dk.dk_openlock);
|
2004-09-25 08:28:08 +04:00
|
|
|
return (error);
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
2009-07-24 01:38:33 +04:00
|
|
|
static int
|
|
|
|
ldlastclose(device_t self)
|
|
|
|
{
|
|
|
|
struct ld_softc *sc = device_private(self);
|
|
|
|
|
|
|
|
if (sc->sc_flush != NULL && (*sc->sc_flush)(sc, 0) != 0)
|
|
|
|
aprint_error_dev(self, "unable to flush cache\n");
|
|
|
|
if ((sc->sc_flags & LDF_KLABEL) == 0)
|
|
|
|
sc->sc_flags &= ~LDF_VLABEL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-04-30 06:44:53 +04:00
|
|
|
/* ARGSUSED */
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
ldclose(dev_t dev, int flags, int fmt, struct lwp *l)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_softc *sc;
|
2007-07-21 23:51:47 +04:00
|
|
|
int part, unit;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
unit = DISKUNIT(dev);
|
|
|
|
part = DISKPART(dev);
|
2008-06-11 16:41:22 +04:00
|
|
|
sc = device_lookup_private(&ld_cd, unit);
|
2004-09-25 08:28:08 +04:00
|
|
|
|
2007-07-21 23:51:47 +04:00
|
|
|
mutex_enter(&sc->sc_dk.dk_openlock);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
sc->sc_dk.dk_copenmask &= ~(1 << part);
|
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
sc->sc_dk.dk_bopenmask &= ~(1 << part);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sc->sc_dk.dk_openmask =
|
|
|
|
sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
|
|
|
|
|
2009-07-24 01:38:33 +04:00
|
|
|
if (sc->sc_dk.dk_openmask == 0)
|
|
|
|
ldlastclose(sc->sc_dv);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2007-07-21 23:51:47 +04:00
|
|
|
mutex_exit(&sc->sc_dk.dk_openlock);
|
2000-10-19 18:06:02 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-04-30 06:44:53 +04:00
|
|
|
/* ARGSUSED */
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
ldread(dev_t dev, struct uio *uio, int ioflag)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
return (physio(ldstrategy, NULL, dev, B_READ, ldminphys, uio));
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
2001-04-30 06:44:53 +04:00
|
|
|
/* ARGSUSED */
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
ldwrite(dev_t dev, struct uio *uio, int ioflag)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
return (physio(ldstrategy, NULL, dev, B_WRITE, ldminphys, uio));
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
2001-04-30 06:44:53 +04:00
|
|
|
/* ARGSUSED */
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2007-03-04 08:59:00 +03:00
|
|
|
ldioctl(dev_t dev, u_long cmd, void *addr, int32_t flag, struct lwp *l)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_softc *sc;
|
2007-11-12 22:01:07 +03:00
|
|
|
int part, unit, error;
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
2001-01-08 09:57:21 +03:00
|
|
|
struct disklabel newlabel;
|
2001-01-07 21:09:01 +03:00
|
|
|
#endif
|
2001-01-08 09:57:21 +03:00
|
|
|
struct disklabel *lp;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
unit = DISKUNIT(dev);
|
|
|
|
part = DISKPART(dev);
|
2008-06-11 16:41:22 +04:00
|
|
|
sc = device_lookup_private(&ld_cd, unit);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2007-02-08 06:19:42 +03:00
|
|
|
error = disk_ioctl(&sc->sc_dk, cmd, addr, flag, l);
|
|
|
|
if (error != EPASSTHROUGH)
|
|
|
|
return (error);
|
|
|
|
|
2007-04-30 21:23:09 +04:00
|
|
|
error = 0;
|
2000-10-19 18:06:02 +04:00
|
|
|
switch (cmd) {
|
|
|
|
case DIOCGDINFO:
|
|
|
|
memcpy(addr, sc->sc_dk.dk_label, sizeof(struct disklabel));
|
|
|
|
return (0);
|
|
|
|
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCGDINFO:
|
|
|
|
newlabel = *(sc->sc_dk.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(addr, &newlabel, sizeof(struct olddisklabel));
|
|
|
|
return (0);
|
|
|
|
#endif
|
|
|
|
|
2000-10-19 18:06:02 +04:00
|
|
|
case DIOCGPART:
|
|
|
|
((struct partinfo *)addr)->disklab = sc->sc_dk.dk_label;
|
|
|
|
((struct partinfo *)addr)->part =
|
|
|
|
&sc->sc_dk.dk_label->d_partitions[part];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIOCWDINFO:
|
|
|
|
case DIOCSDINFO:
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCWDINFO:
|
|
|
|
case ODIOCSDINFO:
|
|
|
|
|
|
|
|
if (cmd == ODIOCSDINFO || cmd == ODIOCWDINFO) {
|
|
|
|
memset(&newlabel, 0, sizeof newlabel);
|
|
|
|
memcpy(&newlabel, addr, sizeof (struct olddisklabel));
|
|
|
|
lp = &newlabel;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
lp = (struct disklabel *)addr;
|
|
|
|
|
2000-10-19 18:06:02 +04:00
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EBADF);
|
|
|
|
|
2007-07-21 23:51:47 +04:00
|
|
|
mutex_enter(&sc->sc_dk.dk_openlock);
|
2000-11-26 20:44:02 +03:00
|
|
|
sc->sc_flags |= LDF_LABELLING;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
error = setdisklabel(sc->sc_dk.dk_label,
|
2001-01-07 21:09:01 +03:00
|
|
|
lp, /*sc->sc_dk.dk_openmask : */0,
|
2000-10-19 18:06:02 +04:00
|
|
|
sc->sc_dk.dk_cpulabel);
|
2001-01-07 21:09:01 +03:00
|
|
|
if (error == 0 && (cmd == DIOCWDINFO
|
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
|| cmd == ODIOCWDINFO
|
|
|
|
#endif
|
|
|
|
))
|
2000-10-19 18:06:02 +04:00
|
|
|
error = writedisklabel(
|
2005-02-27 03:26:58 +03:00
|
|
|
MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART),
|
|
|
|
ldstrategy, sc->sc_dk.dk_label,
|
2000-10-19 18:06:02 +04:00
|
|
|
sc->sc_dk.dk_cpulabel);
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
sc->sc_flags &= ~LDF_LABELLING;
|
2007-07-21 23:51:47 +04:00
|
|
|
mutex_exit(&sc->sc_dk.dk_openlock);
|
2000-10-19 18:06:02 +04:00
|
|
|
break;
|
|
|
|
|
2003-05-17 20:11:52 +04:00
|
|
|
case DIOCKLABEL:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EBADF);
|
|
|
|
if (*(int *)addr)
|
|
|
|
sc->sc_flags |= LDF_KLABEL;
|
|
|
|
else
|
|
|
|
sc->sc_flags &= ~LDF_KLABEL;
|
|
|
|
break;
|
|
|
|
|
2000-10-19 18:06:02 +04:00
|
|
|
case DIOCWLABEL:
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EBADF);
|
|
|
|
if (*(int *)addr)
|
2000-11-26 20:44:02 +03:00
|
|
|
sc->sc_flags |= LDF_WLABEL;
|
2000-10-19 18:06:02 +04:00
|
|
|
else
|
2000-11-26 20:44:02 +03:00
|
|
|
sc->sc_flags &= ~LDF_WLABEL;
|
2000-10-19 18:06:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DIOCGDEFLABEL:
|
2000-11-26 20:44:02 +03:00
|
|
|
ldgetdefaultlabel(sc, (struct disklabel *)addr);
|
2000-10-19 18:06:02 +04:00
|
|
|
break;
|
|
|
|
|
2001-01-07 21:09:01 +03:00
|
|
|
#ifdef __HAVE_OLD_DISKLABEL
|
|
|
|
case ODIOCGDEFLABEL:
|
|
|
|
ldgetdefaultlabel(sc, &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(addr, &newlabel, sizeof (struct olddisklabel));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2004-10-27 02:46:13 +04:00
|
|
|
case DIOCCACHESYNC:
|
|
|
|
/*
|
|
|
|
* XXX Do we really need to care about having a writable
|
|
|
|
* file descriptor here?
|
|
|
|
*/
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
error = EBADF;
|
|
|
|
else if (sc->sc_flush)
|
2008-08-11 10:43:37 +04:00
|
|
|
error = (*sc->sc_flush)(sc, 0);
|
2004-10-27 02:46:13 +04:00
|
|
|
else
|
|
|
|
error = 0; /* XXX Error out instead? */
|
|
|
|
break;
|
|
|
|
|
2004-09-25 08:28:08 +04:00
|
|
|
case DIOCAWEDGE:
|
|
|
|
{
|
|
|
|
struct dkwedge_info *dkw = (void *) addr;
|
|
|
|
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EBADF);
|
|
|
|
|
|
|
|
/* If the ioctl happens here, the parent is us. */
|
2008-09-09 16:45:39 +04:00
|
|
|
strlcpy(dkw->dkw_parent, device_xname(sc->sc_dv),
|
2008-04-09 09:47:19 +04:00
|
|
|
sizeof(dkw->dkw_parent));
|
2004-09-25 08:28:08 +04:00
|
|
|
return (dkwedge_add(dkw));
|
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2004-09-25 08:28:08 +04:00
|
|
|
case DIOCDWEDGE:
|
|
|
|
{
|
|
|
|
struct dkwedge_info *dkw = (void *) addr;
|
|
|
|
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EBADF);
|
|
|
|
|
|
|
|
/* If the ioctl happens here, the parent is us. */
|
2008-09-09 16:45:39 +04:00
|
|
|
strlcpy(dkw->dkw_parent, device_xname(sc->sc_dv),
|
2008-04-09 09:47:19 +04:00
|
|
|
sizeof(dkw->dkw_parent));
|
2004-09-25 08:28:08 +04:00
|
|
|
return (dkwedge_del(dkw));
|
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
|
2004-09-25 08:28:08 +04:00
|
|
|
case DIOCLWEDGES:
|
|
|
|
{
|
|
|
|
struct dkwedge_list *dkwl = (void *) addr;
|
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
return (dkwedge_list(&sc->sc_dk, dkwl, l));
|
2004-09-25 08:28:08 +04:00
|
|
|
}
|
2007-11-12 17:45:23 +03:00
|
|
|
case DIOCGSTRATEGY:
|
|
|
|
{
|
|
|
|
struct disk_strategy *dks = (void *)addr;
|
|
|
|
|
2007-11-12 22:01:07 +03:00
|
|
|
mutex_enter(&sc->sc_mutex);
|
2007-11-12 17:45:23 +03:00
|
|
|
strlcpy(dks->dks_name, bufq_getstrategyname(sc->sc_bufq),
|
|
|
|
sizeof(dks->dks_name));
|
2007-11-12 22:01:07 +03:00
|
|
|
mutex_exit(&sc->sc_mutex);
|
2007-11-12 17:45:23 +03:00
|
|
|
dks->dks_paramlen = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case DIOCSSTRATEGY:
|
|
|
|
{
|
|
|
|
struct disk_strategy *dks = (void *)addr;
|
|
|
|
struct bufq_state *new, *old;
|
2004-09-25 08:28:08 +04:00
|
|
|
|
2007-11-12 17:45:23 +03:00
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return EPERM;
|
|
|
|
|
|
|
|
if (dks->dks_param != NULL)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
dks->dks_name[sizeof(dks->dks_name) - 1] = 0; /* ensure term */
|
|
|
|
error = bufq_alloc(&new, dks->dks_name,
|
|
|
|
BUFQ_EXACT|BUFQ_SORT_RAWBLOCK);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
2007-11-12 22:01:07 +03:00
|
|
|
mutex_enter(&sc->sc_mutex);
|
2007-11-12 17:45:23 +03:00
|
|
|
old = sc->sc_bufq;
|
|
|
|
bufq_move(new, old);
|
|
|
|
sc->sc_bufq = new;
|
2007-11-12 22:01:07 +03:00
|
|
|
mutex_exit(&sc->sc_mutex);
|
2007-11-12 17:45:23 +03:00
|
|
|
bufq_free(old);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2000-10-19 18:06:02 +04:00
|
|
|
default:
|
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2004-08-30 04:34:41 +04:00
|
|
|
static void
|
2000-11-26 20:44:02 +03:00
|
|
|
ldstrategy(struct buf *bp)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_softc *sc;
|
2003-06-08 03:37:24 +04:00
|
|
|
struct disklabel *lp;
|
|
|
|
daddr_t blkno;
|
|
|
|
int s, part;
|
2000-11-08 22:20:33 +03:00
|
|
|
|
2008-06-11 16:41:22 +04:00
|
|
|
sc = device_lookup_private(&ld_cd, DISKUNIT(bp->b_dev));
|
2003-06-08 03:37:24 +04:00
|
|
|
part = DISKPART(bp->b_dev);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2001-02-04 20:15:37 +03:00
|
|
|
if ((sc->sc_flags & LDF_DETACH) != 0) {
|
2000-12-03 16:03:30 +03:00
|
|
|
bp->b_error = EIO;
|
2007-07-29 16:50:17 +04:00
|
|
|
goto done;
|
2000-12-03 16:03:30 +03:00
|
|
|
}
|
|
|
|
|
2000-10-19 18:06:02 +04:00
|
|
|
lp = sc->sc_dk.dk_label;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The transfer must be a whole number of blocks and the offset must
|
|
|
|
* not be negative.
|
|
|
|
*/
|
|
|
|
if ((bp->b_bcount % lp->d_secsize) != 0 || bp->b_blkno < 0) {
|
2003-06-08 03:37:24 +04:00
|
|
|
bp->b_error = EINVAL;
|
2007-07-29 16:50:17 +04:00
|
|
|
goto done;
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
2003-06-08 03:37:24 +04:00
|
|
|
/* If it's a null transfer, return immediately. */
|
|
|
|
if (bp->b_bcount == 0)
|
|
|
|
goto done;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do bounds checking and adjust the transfer. If error, process.
|
|
|
|
* If past the end of partition, just return.
|
|
|
|
*/
|
2010-09-20 10:54:06 +04:00
|
|
|
if (part == RAW_PART) {
|
|
|
|
if (bounds_check_with_mediasize(bp, DEV_BSIZE,
|
|
|
|
sc->sc_disksize512) <= 0)
|
|
|
|
goto done;
|
|
|
|
} else {
|
|
|
|
if (bounds_check_with_label(&sc->sc_dk, bp,
|
|
|
|
(sc->sc_flags & (LDF_WLABEL | LDF_LABELLING)) != 0) <= 0)
|
|
|
|
goto done;
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-06-08 03:37:24 +04:00
|
|
|
* Convert the block number to absolute and put it in terms
|
|
|
|
* of the device's logical block size.
|
2000-10-19 18:06:02 +04:00
|
|
|
*/
|
2003-06-08 03:37:24 +04:00
|
|
|
if (lp->d_secsize == DEV_BSIZE)
|
|
|
|
blkno = bp->b_blkno;
|
|
|
|
else if (lp->d_secsize > DEV_BSIZE)
|
|
|
|
blkno = bp->b_blkno / (lp->d_secsize / DEV_BSIZE);
|
2000-10-19 18:06:02 +04:00
|
|
|
else
|
2003-06-08 03:37:24 +04:00
|
|
|
blkno = bp->b_blkno * (DEV_BSIZE / lp->d_secsize);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2001-09-06 04:47:56 +04:00
|
|
|
if (part != RAW_PART)
|
2003-06-08 03:37:24 +04:00
|
|
|
blkno += lp->d_partitions[part].p_offset;
|
|
|
|
|
|
|
|
bp->b_rawblkno = blkno;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
s = splbio();
|
2007-02-10 00:55:00 +03:00
|
|
|
ldstart(sc, bp);
|
2000-10-19 18:06:02 +04:00
|
|
|
splx(s);
|
2003-06-08 03:37:24 +04:00
|
|
|
return;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2003-06-08 03:37:24 +04:00
|
|
|
done:
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
biodone(bp);
|
|
|
|
}
|
2000-11-26 19:16:04 +03:00
|
|
|
|
2003-06-08 03:37:24 +04:00
|
|
|
static void
|
2007-02-10 00:55:00 +03:00
|
|
|
ldstart(struct ld_softc *sc, struct buf *bp)
|
2003-06-08 03:37:24 +04:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&sc->sc_mutex);
|
|
|
|
|
|
|
|
if (bp != NULL)
|
2009-01-13 16:33:58 +03:00
|
|
|
bufq_put(sc->sc_bufq, bp);
|
2007-02-10 00:55:00 +03:00
|
|
|
|
2003-06-08 03:37:24 +04:00
|
|
|
while (sc->sc_queuecnt < sc->sc_maxqueuecnt) {
|
|
|
|
/* See if there is work to do. */
|
2009-01-13 16:33:58 +03:00
|
|
|
if ((bp = bufq_peek(sc->sc_bufq)) == NULL)
|
2003-06-08 03:37:24 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
disk_busy(&sc->sc_dk);
|
|
|
|
sc->sc_queuecnt++;
|
|
|
|
|
|
|
|
if (__predict_true((error = (*sc->sc_start)(sc, bp)) == 0)) {
|
|
|
|
/*
|
|
|
|
* The back-end is running the job; remove it from
|
|
|
|
* the queue.
|
|
|
|
*/
|
2009-01-13 16:33:58 +03:00
|
|
|
(void) bufq_get(sc->sc_bufq);
|
2003-06-08 03:37:24 +04:00
|
|
|
} else {
|
|
|
|
disk_unbusy(&sc->sc_dk, 0, (bp->b_flags & B_READ));
|
|
|
|
sc->sc_queuecnt--;
|
|
|
|
if (error == EAGAIN) {
|
|
|
|
/*
|
|
|
|
* Temporary resource shortage in the
|
|
|
|
* back-end; just defer the job until
|
|
|
|
* later.
|
|
|
|
*
|
|
|
|
* XXX We might consider a watchdog timer
|
|
|
|
* XXX to make sure we are kicked into action.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
} else {
|
2009-01-13 16:33:58 +03:00
|
|
|
(void) bufq_get(sc->sc_bufq);
|
2003-06-08 03:37:24 +04:00
|
|
|
bp->b_error = error;
|
|
|
|
bp->b_resid = bp->b_bcount;
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_exit(&sc->sc_mutex);
|
2003-06-08 03:37:24 +04:00
|
|
|
biodone(bp);
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&sc->sc_mutex);
|
2003-06-08 03:37:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
|
|
|
|
mutex_exit(&sc->sc_mutex);
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-11-26 20:44:02 +03:00
|
|
|
lddone(struct ld_softc *sc, struct buf *bp)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
|
|
|
|
2007-07-29 16:50:17 +04:00
|
|
|
if (bp->b_error != 0) {
|
2000-11-26 20:44:02 +03:00
|
|
|
diskerr(bp, "ld", "error", LOG_PRINTF, 0, sc->sc_dk.dk_label);
|
2000-10-19 18:06:02 +04:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2002-11-01 14:31:50 +03:00
|
|
|
disk_unbusy(&sc->sc_dk, bp->b_bcount - bp->b_resid,
|
|
|
|
(bp->b_flags & B_READ));
|
2000-10-19 18:06:02 +04:00
|
|
|
#if NRND > 0
|
|
|
|
rnd_add_uint32(&sc->sc_rnd_source, bp->b_rawblkno);
|
|
|
|
#endif
|
|
|
|
biodone(bp);
|
2000-11-08 22:20:33 +03:00
|
|
|
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_enter(&sc->sc_mutex);
|
2001-02-04 20:15:37 +03:00
|
|
|
if (--sc->sc_queuecnt <= sc->sc_maxqueuecnt) {
|
2003-06-13 06:32:27 +04:00
|
|
|
if ((sc->sc_flags & LDF_DRAIN) != 0) {
|
|
|
|
sc->sc_flags &= ~LDF_DRAIN;
|
2001-02-04 20:15:37 +03:00
|
|
|
wakeup(&sc->sc_queuecnt);
|
2003-06-13 06:32:27 +04:00
|
|
|
}
|
2007-02-10 00:55:00 +03:00
|
|
|
mutex_exit(&sc->sc_mutex);
|
|
|
|
ldstart(sc, NULL);
|
|
|
|
} else
|
|
|
|
mutex_exit(&sc->sc_mutex);
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2000-11-26 20:44:02 +03:00
|
|
|
ldsize(dev_t dev)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_softc *sc;
|
2000-10-19 18:06:02 +04:00
|
|
|
int part, unit, omask, size;
|
|
|
|
|
|
|
|
unit = DISKUNIT(dev);
|
2008-06-11 16:41:22 +04:00
|
|
|
if ((sc = device_lookup_private(&ld_cd, unit)) == NULL)
|
2000-10-19 18:06:02 +04:00
|
|
|
return (ENODEV);
|
2000-11-26 20:44:02 +03:00
|
|
|
if ((sc->sc_flags & LDF_ENABLED) == 0)
|
2000-10-19 18:06:02 +04:00
|
|
|
return (ENODEV);
|
|
|
|
part = DISKPART(dev);
|
|
|
|
|
|
|
|
omask = sc->sc_dk.dk_openmask & (1 << part);
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
if (omask == 0 && ldopen(dev, 0, S_IFBLK, NULL) != 0)
|
2000-10-19 18:06:02 +04:00
|
|
|
return (-1);
|
|
|
|
else if (sc->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP)
|
|
|
|
size = -1;
|
|
|
|
else
|
|
|
|
size = sc->sc_dk.dk_label->d_partitions[part].p_size *
|
|
|
|
(sc->sc_dk.dk_label->d_secsize / DEV_BSIZE);
|
2000-11-26 20:44:02 +03:00
|
|
|
if (omask == 0 && ldclose(dev, 0, S_IFBLK, NULL) != 0)
|
2000-10-19 18:06:02 +04:00
|
|
|
return (-1);
|
|
|
|
|
|
|
|
return (size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load the label information from the specified device.
|
|
|
|
*/
|
|
|
|
static void
|
2000-11-26 20:44:02 +03:00
|
|
|
ldgetdisklabel(struct ld_softc *sc)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
|
|
|
const char *errstring;
|
|
|
|
|
2000-11-26 20:44:02 +03:00
|
|
|
ldgetdefaultlabel(sc, sc->sc_dk.dk_label);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
/* Call the generic disklabel extraction routine. */
|
2008-09-09 16:45:39 +04:00
|
|
|
errstring = readdisklabel(MAKEDISKDEV(0, device_unit(sc->sc_dv),
|
2006-03-28 21:38:24 +04:00
|
|
|
RAW_PART), ldstrategy, sc->sc_dk.dk_label, sc->sc_dk.dk_cpulabel);
|
2000-10-19 18:06:02 +04:00
|
|
|
if (errstring != NULL)
|
2008-09-09 16:45:39 +04:00
|
|
|
printf("%s: %s\n", device_xname(sc->sc_dv), errstring);
|
2003-05-17 20:11:52 +04:00
|
|
|
|
|
|
|
/* In-core label now valid. */
|
|
|
|
sc->sc_flags |= LDF_VLABEL;
|
2000-10-19 18:06:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct a ficticious label.
|
|
|
|
*/
|
|
|
|
static void
|
2000-11-26 20:44:02 +03:00
|
|
|
ldgetdefaultlabel(struct ld_softc *sc, struct disklabel *lp)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
memset(lp, 0, sizeof(struct disklabel));
|
|
|
|
|
|
|
|
lp->d_secsize = sc->sc_secsize;
|
|
|
|
lp->d_ntracks = sc->sc_nheads;
|
|
|
|
lp->d_nsectors = sc->sc_nsectors;
|
|
|
|
lp->d_ncylinders = sc->sc_ncylinders;
|
|
|
|
lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
|
2000-11-26 20:44:02 +03:00
|
|
|
lp->d_type = DTYPE_LD;
|
2003-05-16 19:34:25 +04:00
|
|
|
strlcpy(lp->d_typename, "unknown", sizeof(lp->d_typename));
|
|
|
|
strlcpy(lp->d_packname, "fictitious", sizeof(lp->d_packname));
|
2000-10-19 18:06:02 +04:00
|
|
|
lp->d_secperunit = sc->sc_secperunit;
|
|
|
|
lp->d_rpm = 7200;
|
|
|
|
lp->d_interleave = 1;
|
|
|
|
lp->d_flags = 0;
|
|
|
|
|
|
|
|
lp->d_partitions[RAW_PART].p_offset = 0;
|
|
|
|
lp->d_partitions[RAW_PART].p_size =
|
|
|
|
lp->d_secperunit * (lp->d_secsize / DEV_BSIZE);
|
|
|
|
lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED;
|
|
|
|
lp->d_npartitions = RAW_PART + 1;
|
|
|
|
|
|
|
|
lp->d_magic = DISKMAGIC;
|
|
|
|
lp->d_magic2 = DISKMAGIC;
|
|
|
|
lp->d_checksum = dkcksum(lp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take a dump.
|
|
|
|
*/
|
2004-08-30 04:34:41 +04:00
|
|
|
static int
|
2007-03-04 08:59:00 +03:00
|
|
|
lddump(dev_t dev, daddr_t blkno, void *vav, size_t size)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2007-03-04 08:59:00 +03:00
|
|
|
char *va = vav;
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_softc *sc;
|
2000-10-19 18:06:02 +04:00
|
|
|
struct disklabel *lp;
|
|
|
|
int unit, part, nsects, sectoff, towrt, nblk, maxblkcnt, rv;
|
|
|
|
static int dumping;
|
|
|
|
|
|
|
|
unit = DISKUNIT(dev);
|
2008-06-11 16:41:22 +04:00
|
|
|
if ((sc = device_lookup_private(&ld_cd, unit)) == NULL)
|
2000-10-19 18:06:02 +04:00
|
|
|
return (ENXIO);
|
2000-11-26 20:44:02 +03:00
|
|
|
if ((sc->sc_flags & LDF_ENABLED) == 0)
|
2000-10-19 18:06:02 +04:00
|
|
|
return (ENODEV);
|
2001-01-04 00:01:28 +03:00
|
|
|
if (sc->sc_dump == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
/* Check if recursive dump; if so, punt. */
|
|
|
|
if (dumping)
|
|
|
|
return (EFAULT);
|
|
|
|
dumping = 1;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
/* Convert to disk sectors. Request must be a multiple of size. */
|
2001-01-04 00:01:28 +03:00
|
|
|
part = DISKPART(dev);
|
2000-10-19 18:06:02 +04:00
|
|
|
lp = sc->sc_dk.dk_label;
|
|
|
|
if ((size % lp->d_secsize) != 0)
|
|
|
|
return (EFAULT);
|
|
|
|
towrt = size / lp->d_secsize;
|
|
|
|
blkno = dbtob(blkno) / lp->d_secsize; /* blkno in DEV_BSIZE units */
|
|
|
|
|
|
|
|
nsects = lp->d_partitions[part].p_size;
|
|
|
|
sectoff = lp->d_partitions[part].p_offset;
|
|
|
|
|
|
|
|
/* Check transfer bounds against partition size. */
|
|
|
|
if ((blkno < 0) || ((blkno + towrt) > nsects))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/* Offset block number to start of partition. */
|
|
|
|
blkno += sectoff;
|
|
|
|
|
|
|
|
/* Start dumping and return when done. */
|
2001-01-04 00:01:28 +03:00
|
|
|
maxblkcnt = sc->sc_maxxfer / sc->sc_secsize - 1;
|
2000-10-19 18:06:02 +04:00
|
|
|
while (towrt > 0) {
|
2001-01-04 00:01:28 +03:00
|
|
|
nblk = min(maxblkcnt, towrt);
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
if ((rv = (*sc->sc_dump)(sc, va, blkno, nblk)) != 0)
|
|
|
|
return (rv);
|
|
|
|
|
|
|
|
towrt -= nblk;
|
|
|
|
blkno += nblk;
|
|
|
|
va += nblk * sc->sc_secsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
dumping = 0;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjust the size of a transfer.
|
|
|
|
*/
|
|
|
|
static void
|
2000-11-26 20:44:02 +03:00
|
|
|
ldminphys(struct buf *bp)
|
2000-10-19 18:06:02 +04:00
|
|
|
{
|
2000-11-26 20:44:02 +03:00
|
|
|
struct ld_softc *sc;
|
2000-10-19 18:06:02 +04:00
|
|
|
|
2008-06-11 16:41:22 +04:00
|
|
|
sc = device_lookup_private(&ld_cd, DISKUNIT(bp->b_dev));
|
2000-10-19 18:06:02 +04:00
|
|
|
|
|
|
|
if (bp->b_bcount > sc->sc_maxxfer)
|
|
|
|
bp->b_bcount = sc->sc_maxxfer;
|
|
|
|
minphys(bp);
|
|
|
|
}
|
2007-02-08 06:19:42 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
ld_set_properties(struct ld_softc *ld)
|
|
|
|
{
|
|
|
|
prop_dictionary_t disk_info, odisk_info, geom;
|
|
|
|
|
|
|
|
disk_info = prop_dictionary_create();
|
|
|
|
|
|
|
|
geom = prop_dictionary_create();
|
|
|
|
|
|
|
|
prop_dictionary_set_uint64(geom, "sectors-per-unit",
|
|
|
|
ld->sc_secperunit);
|
|
|
|
|
|
|
|
prop_dictionary_set_uint32(geom, "sector-size",
|
|
|
|
ld->sc_secsize);
|
|
|
|
|
|
|
|
prop_dictionary_set_uint16(geom, "sectors-per-track",
|
|
|
|
ld->sc_nsectors);
|
|
|
|
|
|
|
|
prop_dictionary_set_uint16(geom, "tracks-per-cylinder",
|
|
|
|
ld->sc_nheads);
|
|
|
|
|
|
|
|
prop_dictionary_set_uint64(geom, "cylinders-per-unit",
|
|
|
|
ld->sc_ncylinders);
|
|
|
|
|
|
|
|
prop_dictionary_set(disk_info, "geometry", geom);
|
|
|
|
prop_object_release(geom);
|
|
|
|
|
2008-09-09 16:45:39 +04:00
|
|
|
prop_dictionary_set(device_properties(ld->sc_dv),
|
2007-02-08 06:19:42 +03:00
|
|
|
"disk-info", disk_info);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't release disk_info here; we keep a reference to it.
|
|
|
|
* disk_detach() will release it when we go away.
|
|
|
|
*/
|
|
|
|
|
|
|
|
odisk_info = ld->sc_dk.dk_info;
|
|
|
|
ld->sc_dk.dk_info = disk_info;
|
|
|
|
if (odisk_info)
|
|
|
|
prop_object_release(odisk_info);
|
|
|
|
}
|
2007-02-23 01:28:32 +03:00
|
|
|
|
|
|
|
static void
|
2009-05-07 13:11:42 +04:00
|
|
|
ld_config_interrupts(device_t d)
|
2007-02-23 01:28:32 +03:00
|
|
|
{
|
2008-07-06 18:07:44 +04:00
|
|
|
struct ld_softc *sc = device_private(d);
|
2007-02-23 01:28:32 +03:00
|
|
|
dkwedge_discover(&sc->sc_dk);
|
|
|
|
}
|